Skip to content

Commit 8d2c550

Browse files
committed
simplify the last target language management
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 51c5552 commit 8d2c550

File tree

4 files changed

+34
-44
lines changed

4 files changed

+34
-44
lines changed

lib/Listener/BeforeTemplateRenderedListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function handle(Event $event): void {
5353
$userAssistantEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'assistant_enabled', '1') === '1';
5454
$assistantEnabled = $adminAssistantEnabled && $userAssistantEnabled;
5555
$this->initialStateService->provideInitialState('assistant-enabled', $assistantEnabled);
56+
if ($assistantEnabled) {
57+
$lastTargetLanguage = $this->config->getUserValue($this->userId, Application::APP_ID, 'last_target_language', '');
58+
$this->initialStateService->provideInitialState('last-target-language', $lastTargetLanguage);
59+
}
5660
Util::addScript(Application::APP_ID, Application::APP_ID . '-main');
5761
}
5862
}

src/assistant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ async function getLastSelectedTaskType() {
275275
}
276276

277277
async function saveLastTargetLanguage(targetLanguage) {
278+
OCA.Assistant.last_target_language = targetLanguage
279+
278280
const { default: axios } = await import('@nextcloud/axios')
279281
const { generateUrl } = await import('@nextcloud/router')
280282

src/components/AssistantTextProcessingForm.vue

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,6 @@ export default {
347347
fileId,
348348
})
349349
},
350-
351-
async getLastTargetLanguage() {
352-
const { default: axios } = await import('@nextcloud/axios')
353-
const { generateUrl } = await import('@nextcloud/router')
354-
355-
const req = {
356-
params: {
357-
key: 'last_target_language',
358-
},
359-
}
360-
const url = generateUrl('/apps/assistant/config')
361-
return axios.get(url, req)
362-
},
363350
getTaskTypes() {
364351
this.loadingTaskTypes = true
365352
axios.get(generateOcsUrl('/apps/assistant/api/v1/task-types'))
@@ -379,37 +366,33 @@ export default {
379366
this.parseTextFileInputs(taskType)
380367
}
381368
382-
this.getLastTargetLanguage()
383-
.then((response) => {
384-
const defaultTargetLanguage = response.data
385-
// add placeholders
386-
taskTypes.forEach(tt => {
387-
if (tt.id === TEXT2TEXT_TASK_TYPE_ID && tt.inputShape.input) {
388-
tt.inputShape.input.placeholder = t('assistant', 'Generate a first draft for a blog post about privacy')
389-
} else if (tt.id === 'context_chat:context_chat' && tt.inputShape.prompt) {
390-
tt.inputShape.prompt.placeholder = t('assistant', 'What is the venue for the team retreat this quarter?')
391-
} else if (tt.id === 'core:text2text:summary' && tt.inputShape.input) {
392-
tt.inputShape.input.placeholder = t('assistant', 'Type or paste the text to summarize')
393-
} else if (tt.id === 'core:text2text:headline' && tt.inputShape.input) {
394-
tt.inputShape.input.placeholder = t('assistant', 'Type or paste the text to generate a headline for')
395-
} else if (tt.id === 'core:text2text:topics' && tt.inputShape.input) {
396-
tt.inputShape.input.placeholder = t('assistant', 'Type or paste the text to extract the topics from')
397-
} else if (tt.id === 'core:text2image' && tt.inputShape.input && tt.inputShape.numberOfImages) {
398-
tt.inputShape.input.placeholder = t('assistant', 'landscape trees forest peaceful')
399-
tt.inputShape.numberOfImages.placeholder = t('assistant', 'a number')
400-
} else if (tt.id === 'core:contextwrite' && tt.inputShape.source_input && tt.inputShape.style_input) {
401-
tt.inputShape.style_input.placeholder = t('assistant', 'Shakespeare or an example of the style')
402-
tt.inputShape.source_input.placeholder = t('assistant', 'A description of what you need or some original content')
403-
// set defaults for translate
404-
} else if (tt.id === 'core:text2text:translate') {
405-
if (defaultTargetLanguage) {
406-
tt.inputShapeDefaults.target_language = defaultTargetLanguage
407-
}
408-
tt.inputShapeDefaults.origin_language = 'detect_language'
409-
}
410-
})
411-
this.taskTypes = taskTypes
412-
})
369+
// add placeholders
370+
taskTypes.forEach(tt => {
371+
if (tt.id === TEXT2TEXT_TASK_TYPE_ID && tt.inputShape.input) {
372+
tt.inputShape.input.placeholder = t('assistant', 'Generate a first draft for a blog post about privacy')
373+
} else if (tt.id === 'context_chat:context_chat' && tt.inputShape.prompt) {
374+
tt.inputShape.prompt.placeholder = t('assistant', 'What is the venue for the team retreat this quarter?')
375+
} else if (tt.id === 'core:text2text:summary' && tt.inputShape.input) {
376+
tt.inputShape.input.placeholder = t('assistant', 'Type or paste the text to summarize')
377+
} else if (tt.id === 'core:text2text:headline' && tt.inputShape.input) {
378+
tt.inputShape.input.placeholder = t('assistant', 'Type or paste the text to generate a headline for')
379+
} else if (tt.id === 'core:text2text:topics' && tt.inputShape.input) {
380+
tt.inputShape.input.placeholder = t('assistant', 'Type or paste the text to extract the topics from')
381+
} else if (tt.id === 'core:text2image' && tt.inputShape.input && tt.inputShape.numberOfImages) {
382+
tt.inputShape.input.placeholder = t('assistant', 'landscape trees forest peaceful')
383+
tt.inputShape.numberOfImages.placeholder = t('assistant', 'a number')
384+
} else if (tt.id === 'core:contextwrite' && tt.inputShape.source_input && tt.inputShape.style_input) {
385+
tt.inputShape.style_input.placeholder = t('assistant', 'Shakespeare or an example of the style')
386+
tt.inputShape.source_input.placeholder = t('assistant', 'A description of what you need or some original content')
387+
} else if (tt.id === 'core:text2text:translate') {
388+
tt.inputShapeDefaults.origin_language = 'detect_language'
389+
const defaultTargetLanguage = OCA.Assistant.last_target_language
390+
if (defaultTargetLanguage) {
391+
tt.inputShapeDefaults.target_language = defaultTargetLanguage
392+
}
393+
}
394+
})
395+
this.taskTypes = taskTypes
413396
})
414397
.catch((error) => {
415398
console.error(error)

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function init() {
2626
subscribe('notifications:action:execute', handleNotification)
2727
if (loadState('assistant', 'assistant-enabled')) {
2828
addAssistantMenuEntry()
29+
OCA.Assistant.last_target_language = loadState('assistant', 'last-target-language')
2930
}
3031
}
3132
}

0 commit comments

Comments
 (0)