Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to deactivate tagger, further added smaller optimizations #20

Merged
merged 7 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ if config_env() == :prod do
port: String.to_integer(System.get_env("DATABASE_PORT", "5432")),
ssl: System.get_env("DATABASE_SSL", "true") == "true",
socket_options: maybe_ipv6,
ssl_opts: [verify: :verify_peer,
cacerts: :public_key.cacerts_get(),
versions: [:"tlsv1.3"],
depth: 3,
server_name_indication: String.to_charlist(System.get_env("DATABASE_HOST")),
customize_hostname_check: [
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
]
]
ssl_opts: [
verify: :verify_peer,
cacerts: :public_key.cacerts_get(),
versions: [:"tlsv1.3"],
depth: 3,
server_name_indication: String.to_charlist(System.get_env("DATABASE_HOST")),
customize_hostname_check: [
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
]
]

# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
Expand Down
1 change: 1 addition & 0 deletions frontend/compiled-lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"live.text.button.submit": "Text hinzufügen",
"live.text.loading": "Anfrage wird bearbeitet...",
"live.text.success": "Wörter hinzugefügt. Je nach Filter werden Wörter ausgeblendet.",
"live.text.toggler.tokenizerActive": "Grammatik eingegebener Wörter erkennen",
"sharemodal.title": "Teilen",
"start.buttons.feedback": "Feedback",
"start.buttons.live": "Text",
Expand Down
1 change: 1 addition & 0 deletions frontend/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"live.text.button.submit": "Add Text",
"live.text.loading": "Request is being processed...",
"live.text.success": "Words added. Depending on the chosen filter they might not be visible yet.",
"live.text.toggler.tokenizerActive": "Tag grammar cateogries of input",
"sharemodal.title": "Share",
"start.buttons.feedback": "Feedback",
"start.buttons.live": "Text",
Expand Down
30 changes: 3 additions & 27 deletions frontend/compiled-lang/lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"chart.buttons.share.feedback": "Share a link to your feedback chart to allow others to add new words.",
"close": "Close",
"download": "Download",
"feedback.admin.header": "Feedback Chart",
"feedback.admin.header.subline": "Collect feedback and display it in a chart",
"feedback.user.button.submit": "Submit Feedback",
"feedback.user.input.hint": "Please enter Feedback",
Expand All @@ -15,12 +14,12 @@
"filter.all": "All categories",
"languages.de": "German",
"languages.en": "English",
"live.admin.header": "Live Text Chart",
"live.admin.header.subline": "Enter text to count and categorize words",
"live.filter": "Filter",
"live.text.button.submit": "Add Text",
"live.text.loading": "Request is being processed...",
"live.text.success": "Words added. Depending on the chosen filter they might not be visible yet.",
"live.text.toggler.tokenizerActive": "Tag grammar cateogries of input",
"sharemodal.title": "Share",
"start.buttons.feedback": "Feedback",
"start.buttons.live": "Text",
Expand All @@ -32,35 +31,12 @@
"toolbar.buttons.clear": "Clear",
"toolbar.buttons.colors": "Colors",
"toolbar.buttons.danger": "Danger",
"toolbar.buttons.dropdown.filter.adjective": "Adjective",
"toolbar.buttons.dropdown.filter.adverb": "Adverb",
"toolbar.buttons.dropdown.filter.all": "All",
"toolbar.buttons.dropdown.filter.article": "Article",
"toolbar.buttons.dropdown.filter.conjuncture": "Conjuncture",
"toolbar.buttons.dropdown.filter.misc": "Misc",
"toolbar.buttons.dropdown.filter.none": "No filter",
"toolbar.buttons.dropdown.filter.noun": "Noun",
"toolbar.buttons.dropdown.filter.preposition": "Preposition",
"toolbar.buttons.dropdown.filter.pronoun": "Pronoun",
"toolbar.buttons.dropdown.filter.verb": "Verb",
"toolbar.buttons.dropdown.orientation.ninety": "Set rotation angle 90",
"toolbar.buttons.dropdown.orientation.zero": "Set rotation angle 0",
"toolbar.buttons.dropdown.theme.grammar": "Change to grammatical category",
"toolbar.buttons.dropdown.theme.grey": "Change to greyscale colors",
"toolbar.buttons.dropdown.theme.mix": "Change to fancy colors",
"toolbar.buttons.orientation": "Orientation",
"toolbar.buttons.settings": "Toggle Settings",
"toolbar.buttons.share": "Share",
"toolbar.settings.language": "Language",
"toolbar.settings.theme.adjective": "Adjective color",
"toolbar.settings.theme.adverb": "Adverb color",
"toolbar.settings.theme.article": "Article color",
"toolbar.settings.theme.conjuncture": "Conjuncture color",
"toolbar.settings.theme.hint": "Color is used when color filter is set on setting "grammatical category"",
"toolbar.settings.theme.misc": "Misc color",
"toolbar.settings.theme.noun": "Noun color",
"toolbar.settings.theme.preposition": "Preposition color",
"toolbar.settings.theme.pronoun": "Pronoun color",
"toolbar.settings.theme.verb": "Verb color",
"toolbar.settings.rotation": "Limit rotation angle to 0°",
"toolbar.settings.theme.explanation": "Please select a color for each grammar category",
"wordchart.empty": "This word chart is currently empty."
}
3 changes: 3 additions & 0 deletions frontend/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
"live.text.success": {
"defaultMessage": "Wörter hinzugefügt. Je nach Filter werden Wörter ausgeblendet."
},
"live.text.toggler.tokenizerActive": {
"defaultMessage": "Grammatik eingegebener Wörter erkennen"
},
"sharemodal.title": {
"defaultMessage": "Teilen"
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
"live.text.success": {
"defaultMessage": "Words added. Depending on the chosen filter they might not be visible yet."
},
"live.text.toggler.tokenizerActive": {
"defaultMessage": "Tag grammar cateogries of input"
},
"sharemodal.title": {
"defaultMessage": "Share"
},
Expand Down
86 changes: 7 additions & 79 deletions frontend/lang/lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"download": {
"defaultMessage": "Download"
},
"feedback.admin.header": {
"defaultMessage": "Feedback Chart"
},
"feedback.admin.header.subline": {
"defaultMessage": "Collect feedback and display it in a chart"
},
Expand Down Expand Up @@ -47,9 +44,6 @@
"languages.en": {
"defaultMessage": "English"
},
"live.admin.header": {
"defaultMessage": "Live Text Chart"
},
"live.admin.header.subline": {
"defaultMessage": "Enter text to count and categorize words"
},
Expand All @@ -65,6 +59,9 @@
"live.text.success": {
"defaultMessage": "Words added. Depending on the chosen filter they might not be visible yet."
},
"live.text.toggler.tokenizerActive": {
"defaultMessage": "Tag grammar cateogries of input"
},
"sharemodal.title": {
"defaultMessage": "Share"
},
Expand Down Expand Up @@ -98,45 +95,6 @@
"toolbar.buttons.danger": {
"defaultMessage": "Danger"
},
"toolbar.buttons.dropdown.filter.all": {
"defaultMessage": "All"
},
"toolbar.buttons.dropdown.filter.none": {
"defaultMessage": "No filter"
},
"toolbar.buttons.dropdown.filter.noun": {
"defaultMessage": "Noun"
},
"toolbar.buttons.dropdown.filter.verb": {
"defaultMessage": "Verb"
},
"toolbar.buttons.dropdown.filter.adjective": {
"defaultMessage": "Adjective"
},
"toolbar.buttons.dropdown.filter.adverb": {
"defaultMessage": "Adverb"
},
"toolbar.buttons.dropdown.filter.article": {
"defaultMessage": "Article"
},
"toolbar.buttons.dropdown.filter.preposition": {
"defaultMessage": "Preposition"
},
"toolbar.buttons.dropdown.filter.conjuncture": {
"defaultMessage": "Conjuncture"
},
"toolbar.buttons.dropdown.filter.pronoun": {
"defaultMessage": "Pronoun"
},
"toolbar.buttons.dropdown.filter.misc": {
"defaultMessage": "Misc"
},
"toolbar.buttons.dropdown.orientation.ninety": {
"defaultMessage": "Set rotation angle 90"
},
"toolbar.buttons.dropdown.orientation.zero": {
"defaultMessage": "Set rotation angle 0"
},
"toolbar.buttons.dropdown.theme.grammar": {
"defaultMessage": "Change to grammatical category"
},
Expand All @@ -146,47 +104,17 @@
"toolbar.buttons.dropdown.theme.mix": {
"defaultMessage": "Change to fancy colors"
},
"toolbar.buttons.orientation": {
"defaultMessage": "Orientation"
},
"toolbar.buttons.settings": {
"defaultMessage": "Toggle Settings"
},
"toolbar.buttons.share": {
"defaultMessage": "Share"
},
"toolbar.settings.language": {
"defaultMessage": "Language"
},
"toolbar.settings.theme.article": {
"defaultMessage": "Article color"
},
"toolbar.settings.theme.adjective": {
"defaultMessage": "Adjective color"
},
"toolbar.settings.theme.adverb": {
"defaultMessage": "Adverb color"
},
"toolbar.settings.theme.conjuncture": {
"defaultMessage": "Conjuncture color"
},
"toolbar.settings.theme.pronoun": {
"defaultMessage": "Pronoun color"
},
"toolbar.settings.theme.preposition": {
"defaultMessage": "Preposition color"
},
"toolbar.settings.theme.misc": {
"defaultMessage": "Misc color"
},
"toolbar.settings.theme.noun": {
"defaultMessage": "Noun color"
},
"toolbar.settings.theme.verb": {
"defaultMessage": "Verb color"
"toolbar.settings.rotation": {
"defaultMessage": "Limit rotation angle to 0°"
},
"toolbar.settings.theme.hint": {
"defaultMessage": "Color is used when color filter is set on setting "grammatical category""
"toolbar.settings.theme.explanation": {
"defaultMessage": "Please select a color for each grammar category"
},
"wordchart.empty": {
"defaultMessage": "This word chart is currently empty."
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/live-chart/TextInputForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('TestInputForm', () => {
fireEvent.change(element, { target: { value: 'Text' } })
fireEvent.click(screen.getByText(/Add Text/i))

expect(channel.push).toBeCalledWith('new_words', { words: 'Text', admin_url_id: 'adminId' })
expect(channel.push).toBeCalledWith('new_words', { words: 'Text', taggerActive: true })
})

test('pressing enter submits the form', () => {
Expand All @@ -57,6 +57,6 @@ describe('TestInputForm', () => {

fireEvent.change(element, { target: { value: 'Text' } })
fireEvent.keyPress(element, { key: 'Enter', charCode: 13 })
expect(channel.push).toBeCalledWith('new_words', { words: 'Text', admin_url_id: 'adminId' })
expect(channel.push).toBeCalledWith('new_words', { words: 'Text', taggerActive: true })
})
})
37 changes: 31 additions & 6 deletions frontend/src/live-chart/TextInputForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Form from 'react-bootstrap/Form'
import Button from 'react-bootstrap/Button'
import Alert from 'react-bootstrap/Alert'
import { WebsocketContext } from '../shared/PhoenixWebsocketProvider'
import { FormattedMessage } from 'react-intl'
import { FormattedMessage, useIntl } from 'react-intl'

const MAX_LENGTH = import.meta.env.VITE_NLP_WORD_TAGGER_MAX_INPUT !== undefined ? parseInt(import.meta.env.VITE_NLP_WORD_TAGGER_MAX_INPUT, 10) : 500

Expand All @@ -26,17 +26,23 @@ export interface Term {
}

function TextInputForm(): React.ReactElement {
const intl = useIntl()
const [inputText, setInputText] = useState<string>('')
const { channel, adminId } = useContext(WebsocketContext)
const { channel } = useContext(WebsocketContext)
const [waitingForChannelPush, setWaitingForChannelPush] = useState<boolean>(false)
const [completedChannelPush, setCompletedChannelPush] = useState<boolean>(false)
const [remainingTextInput, setRemainingTextInput] = useState<number>(MAX_LENGTH)
const [taggerActive, setTaggerActive] = useState<boolean>(true)

const handleChange = (text: string): void => {
setInputText(text)
setRemainingTextInput(text.length < MAX_LENGTH ? MAX_LENGTH - text.length : 0)
}

const handleToggleTaggerChange = (): void => {
setTaggerActive(!taggerActive)
}

const submit = (event: React.SyntheticEvent<HTMLFormElement>): void => {
if (channel === undefined) return

Expand All @@ -45,7 +51,7 @@ function TextInputForm(): React.ReactElement {

setWaitingForChannelPush(true)
setCompletedChannelPush(false)
channel.push('new_words', { words: inputText, admin_url_id: adminId })
channel.push('new_words', { words: inputText, taggerActive })
.receive('ok', () => {
setWaitingForChannelPush(false)
setCompletedChannelPush(true)
Expand Down Expand Up @@ -79,7 +85,7 @@ function TextInputForm(): React.ReactElement {
<Form.Control
as="textarea"
placeholder="Text"
maxLength={MAX_LENGTH}
maxLength={taggerActive ? MAX_LENGTH : undefined}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => { handleChange((e.target as HTMLTextAreaElement).value) }}
onKeyPress={(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter') {
Expand All @@ -94,10 +100,29 @@ function TextInputForm(): React.ReactElement {
data-testid="test-input-control-text"
/>
</Form.Group>
<Form.Check
type="switch"
checked={taggerActive}
onChange={(_e: React.ChangeEvent<HTMLInputElement>) => { handleToggleTaggerChange() }}
label={
intl.formatMessage(
{
id: 'live.text.toggler.tokenizerActive',
defaultMessage: 'Tag grammar cateogries of input'
}
)
}
/>
<div className="d-flex w-full">
<div className="flex-grow-1">{`${remainingTextInput} / ${MAX_LENGTH}`}</div>
{ taggerActive &&
<div className="flex-grow-1">{`${remainingTextInput} / ${MAX_LENGTH}`}</div>
}
{
!taggerActive &&
<div className="flex-grow-1"></div>
}
<div>
<Button type="submit" variant="primary" className="mt-1">
<Button type="submit" variant="secondary" className="mt-1 text-white">
<FormattedMessage
id="live.text.button.submit"
defaultMessage="Add Text"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/shared/colors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const themeGreyColors: string[] = ['#080808', '#242424', '#3a3a3a', '#4f4f4f', '#646464']
const themeMixedColors: string[] = ['#F75C03', '#D90368', '#820263', '#291720', '#04A777']

export const DEFAULT_COLOR = '#666666'
export const DEFAULT_COLOR = '#9E9E9E'

export enum ColorTheme {
Mixed,
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/shared/components/AdminOptionToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface AdminOptionToolbarProps {
id: string | undefined
adminId: string | undefined
language?: string | undefined
filterFromServer?: string[] | undefined
filterFromServer?: string[]
setWordFilter?: ((wordFilter: string[]) => void) | undefined
setColorThemeGrey?: () => void
setColorThemeFancy?: () => void
Expand Down Expand Up @@ -79,8 +79,12 @@ export function AdminOptionToolbar({ id, adminId, language, filterFromServer, se
}

const createCategoryFiltersForSmScreens = (): React.ReactNode[] => {
if (filterFromServer === undefined) return [<Dropdown.Item key={'filter-empty'}></Dropdown.Item>]

const normalizedFilterList = filterFromServer !== null && filterFromServer.length > 0 ? filterFromServer : ['all']

return ['all', ...ALL_CATEGORIES].map((categoryName: string, index: number) => {
return (<Dropdown.Item key={`filter-sm-category-id-${index}`} variant="" onClick={(event) => handleFilterClick(categoryName)}>
return (<Dropdown.Item key={`filter-sm-category-id-${index}`} active={normalizedFilterList.includes(categoryName)} variant="" onClick={(event) => handleFilterClick(categoryName)}>
<FormattedMessage
id={`toolbar.buttons.dropdown.filter.${categoryName}`}
defaultMessage={categoryName}
Expand Down
Loading
Loading