Skip to content

Commit

Permalink
feat: save state in db
Browse files Browse the repository at this point in the history
Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
  • Loading branch information
janepie committed Dec 8, 2024
1 parent b5c0007 commit 5e999b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/settings/lib/Controller/AISettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
*/
#[AuthorizedAdminSetting(settings: ArtificialIntelligence::class)]
public function update($settings) {
$keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider'];
$keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences','ai.taskprocessing_type_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider'];
foreach ($keys as $key) {
if (!isset($settings[$key])) {
continue;
Expand Down
4 changes: 4 additions & 0 deletions apps/settings/lib/Settings/Admin/ArtificialIntelligence.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ public function getForm() {
}
}
$taskProcessingTaskTypes = [];
$taskProcessingTypeSettings = [];
foreach ($this->taskProcessingManager->getAvailableTaskTypes() as $taskTypeId => $taskTypeDefinition) {
$taskProcessingTaskTypes[] = [
'id' => $taskTypeId,
'name' => $taskTypeDefinition['name'],
'description' => $taskTypeDefinition['description'],
];
$taskProcessingTypeSettings[$taskTypeId] = true;
}

$this->initialState->provideInitialState('ai-stt-providers', $sttProviders);
Expand All @@ -135,6 +137,7 @@ public function getForm() {
'ai.textprocessing_provider_preferences' => $textProcessingSettings,
'ai.text2image_provider' => count($text2imageProviders) > 0 ? $text2imageProviders[0]['id'] : null,
'ai.taskprocessing_provider_preferences' => $taskProcessingSettings,
'ai.taskprocessing_type_preferences' => $taskProcessingTypeSettings,
];
foreach ($settings as $key => $defaultValue) {
$value = $defaultValue;
Expand All @@ -143,6 +146,7 @@ public function getForm() {
$value = json_decode($json, true);
switch ($key) {
case 'ai.taskprocessing_provider_preferences':
case 'ai.taskprocessing_type_preferences':
case 'ai.textprocessing_provider_preferences':
// fill $value with $defaultValue values
$value = array_merge($defaultValue, $value);
Expand Down
8 changes: 5 additions & 3 deletions apps/settings/src/components/AdminAI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
<h3>{{ t('settings', 'Task:') }} {{ type.name }}</h3>
<p>{{ type.description }}</p>
<NcCheckboxRadioSwitch type="switch"
v-model="taskEnabled" >
v-model="settings['ai.taskprocessing_type_preferences'][type.id]"
@update:modelValue="saveChanges" >
{{ t('settings', 'Enable') }}
</NcCheckboxRadioSwitch>
<NcSelect v-model="settings['ai.taskprocessing_provider_preferences'][type.id]"
class="provider-select"
:clearable="false"
:disabled="!taskEnabled"
:disabled="!type.enabled"
:options="taskProcessingProviders.filter(p => p.taskType === type.id).map(p => p.id)"
@input="saveChanges">
<template #option="{label}">
Expand Down Expand Up @@ -146,7 +147,6 @@ export default {
taskProcessingProviders: loadState('settings', 'ai-task-processing-providers'),
taskProcessingTaskTypes: loadState('settings', 'ai-task-processing-task-types'),
settings: loadState('settings', 'ai-settings'),
taskEnabled: true,
}
},
computed: {
Expand Down Expand Up @@ -189,6 +189,7 @@ export default {
this.saveChanges()
},
async saveChanges() {
console.warn(this.settings)
this.loading = true
await nextTick()
const data = { settings: this.settings }
Expand All @@ -198,6 +199,7 @@ export default {
console.error('could not save changes', err)
}
this.loading = false
console.warn('done')
},
getTextProcessingTaskType(type) {
if (!Array.isArray(this.textProcessingTaskTypes)) {
Expand Down

0 comments on commit 5e999b2

Please sign in to comment.