AI admin settings: Add save mechanism

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
pull/39567/head
Marcel Klehr 2 years ago committed by Julien Veyssier
parent 8ec1926aba
commit a840e8c6e5
No known key found for this signature in database
GPG Key ID: 4141FEE162030638
  1. 1
      apps/settings/appinfo/routes.php
  2. 66
      apps/settings/lib/Controller/AISettingsController.php
  3. 2
      apps/settings/lib/Settings/Admin/ArtificialIntelligence.php
  4. 45
      apps/settings/src/components/AdminAI.vue

@ -75,6 +75,7 @@ return [
['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST' , 'root' => ''],
['name' => 'TwoFactorSettings#index', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'GET' , 'root' => ''],
['name' => 'TwoFactorSettings#update', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'PUT' , 'root' => ''],
['name' => 'AISettings#update', 'url' => '/settings/api/admin/ai', 'verb' => 'PUT' , 'root' => ''],
['name' => 'Help#help', 'url' => '/settings/help/{mode}', 'verb' => 'GET', 'defaults' => ['mode' => ''] , 'root' => ''],

@ -1,14 +1,6 @@
<?php
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Daniel Kesselberg <mail@danielkesselberg.de>
* @author Joas Schilling <coding@schilljs.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @license AGPL-3.0
*
@ -36,70 +28,40 @@ use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Mail\IMailer;
use function GuzzleHttp\Promise\queue;
class AISettingsController extends Controller {
/** @var IL10N */
private $l10n;
/** @var IConfig */
private $config;
/** @var IUserSession */
private $userSession;
/** @var IMailer */
private $mailer;
/** @var IURLGenerator */
private $urlGenerator;
/**
* @param string $appName
* @param IRequest $request
* @param IL10N $l10n
* @param IConfig $config
* @param IUserSession $userSession
* @param IURLGenerator $urlGenerator,
* @param IMailer $mailer
*/
public function __construct($appName,
IRequest $request,
IL10N $l10n,
IConfig $config,
IUserSession $userSession,
IURLGenerator $urlGenerator,
IMailer $mailer) {
public function __construct(
$appName,
IRequest $request,
private IConfig $config,
) {
parent::__construct($appName, $request);
$this->l10n = $l10n;
$this->config = $config;
$this->userSession = $userSession;
$this->urlGenerator = $urlGenerator;
$this->mailer = $mailer;
}
/**
* Sets the email settings
*
* @PasswordConfirmationRequired
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\ArtificialIntelligence)
*
* @param array $settings
* @return DataResponse
*/
public function setAISettings($settings) {
$params = get_defined_vars();
$configs = [];
foreach ($params as $key => $value) {
$configs[$key] = empty($value) ? null : $value;
}
// Delete passwords from config in case no auth is specified
if ($params['mail_smtpauth'] !== 1) {
$configs['mail_smtpname'] = null;
$configs['mail_smtppassword'] = null;
public function update($settings) {
$keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.translation_provider_preferences'];
foreach ($keys as $key) {
if (!isset($settings[$key])) {
continue;
}
$this->config->setAppValue('core', $key, json_encode($settings[$key]));
}
$this->config->setSystemValues($configs);
$this->config->setAppValue('core', 'emailTestSuccessful', '0');
return new DataResponse();
}
}

@ -157,7 +157,7 @@ class ArtificialIntelligence implements IDelegatedSettings {
public function getAuthorizedAppConfig(): array {
return [
'core' => ['/ai_.*/'],
'core' => ['/ai..*/'],
];
}
}

@ -2,8 +2,10 @@
<div>
<NcSettingsSection :title="t('settings', 'Machine translation')"
:description="t('settings', 'Machine translation can be implemented by different apps. Here you can define the precedence of the machine translation apps you have installed at the moment.')">
<draggable v-model="settings['ai.translation_provider_preferences']">
<div v-for="(providerClass, i) in settings['ai.translation_provider_preferences']" :key="providerClass" class="draggable__item"><span class="draggable__number">{{i+1}}</span> {{ translationProviders.find(p => p.class === providerClass)?.name }}</div>
<draggable v-model="settings['ai.translation_provider_preferences']" @change="saveChanges">
<div v-for="(providerClass, i) in settings['ai.translation_provider_preferences']" :key="providerClass" class="draggable__item">
<span class="draggable__number">{{ i+1 }}</span> {{ translationProviders.find(p => p.class === providerClass)?.name }}
</div>
</draggable>
</NcSettingsSection>
<NcSettingsSection :title="t('settings', 'Speech-To-Text')"
@ -13,7 +15,8 @@
:checked.sync="settings['ai.stt_provider']"
:value="provider.class"
name="stt_provider"
type="radio">
type="radio"
@update:checked="saveChanges">
{{ provider.name }}
</NcCheckboxRadioSwitch>
</template>
@ -29,9 +32,16 @@
<h3>{{ t('settings', 'Task:') }} {{ getTaskType(type).name }}</h3>
<p>{{ getTaskType(type).description }}</p>
<p>&nbsp;</p>
<NcSelect v-model="settings['ai.textprocessing_provider_preferences'][type]" :clearable="false" :options="textProcessingProviders.filter(p => p.taskType === type).map(p => p.class)">
<template #option="{label}">{{ textProcessingProviders.find(p => p.class === label)?.name }}</template>
<template #selected-option="{label}">{{ textProcessingProviders.find(p => p.class === label)?.name }}</template>
<NcSelect v-model="settings['ai.textprocessing_provider_preferences'][type]"
:clearable="false"
:options="textProcessingProviders.filter(p => p.taskType === type).map(p => p.class)"
@change="saveChanges">
<template #option="{label}">
{{ textProcessingProviders.find(p => p.class === label)?.name }}
</template>
<template #selected-option="{label}">
{{ textProcessingProviders.find(p => p.class === label)?.name }}
</template>
</NcSelect>
<p>&nbsp;</p>
</template>
@ -74,24 +84,15 @@ export default {
}
},
methods: {
saveChanges() {
async saveChanges() {
this.loading = true
const data = {
enforced: this.enforced,
enforcedGroups: this.enforcedGroups,
excludedGroups: this.excludedGroups,
const data = this.settings
try {
await axios.put(generateUrl('/settings/api/admin/ai'), data)
} catch (err) {
console.error('could not save changes', err)
}
axios.put(generateUrl('/settings/api/admin/twofactorauth'), data)
.then(resp => resp.data)
.then(state => {
this.state = state
this.dirty = false
})
.catch(err => {
console.error('could not save changes', err)
})
.then(() => { this.loading = false })
this.loading = false
},
getTaskType(type) {
if (!Array.isArray(this.textProcessingTaskTypes)) {

Loading…
Cancel
Save