diff --git a/appinfo/info.xml b/appinfo/info.xml index 36341ab..d140c56 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -5,7 +5,7 @@ Integration of Moodle learning management system - 0.0.6 + 0.0.7 agpl Julien Veyssier Moodle @@ -24,6 +24,8 @@ + OCA\Moodle\Settings\Admin + OCA\Moodle\Settings\AdminSection OCA\Moodle\Settings\Personal OCA\Moodle\Settings\PersonalSection diff --git a/appinfo/routes.php b/appinfo/routes.php index b389b71..cb2b738 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -12,6 +12,7 @@ return [ 'routes' => [ ['name' => 'config#setConfig', 'url' => '/config', 'verb' => 'PUT'], + ['name' => 'config#setAdminConfig', 'url' => '/admin-config', 'verb' => 'PUT'], ['name' => 'moodleAPI#getNotifications', 'url' => '/notifications', 'verb' => 'GET'], ['name' => 'moodleAPI#getMoodleUrl', 'url' => '/url', 'verb' => 'GET'], ['name' => 'moodleAPI#getMoodleAvatar', 'url' => '/avatar', 'verb' => 'GET'], diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 34ff7db..c8fc292 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -11,6 +11,7 @@ namespace OCA\Moodle\AppInfo; use OCP\IContainer; +use OCP\IConfig; use OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; use OCP\AppFramework\Bootstrap\IRegistrationContext; @@ -41,13 +42,17 @@ class Application extends App implements IBootstrap { parent::__construct(self::APP_ID, $urlParams); $container = $this->getContainer(); + $this->config = $container->query(IConfig::class); } public function register(IRegistrationContext $context): void { $context->registerDashboardWidget(MoodleWidget::class); - $context->registerSearchProvider(MoodleSearchCoursesProvider::class); - $context->registerSearchProvider(MoodleSearchModulesProvider::class); - $context->registerSearchProvider(MoodleSearchUpcomingProvider::class); + + if ($this->config->getAppValue(self::APP_ID, 'search_disabled', '0') === '0') { + $context->registerSearchProvider(MoodleSearchCoursesProvider::class); + $context->registerSearchProvider(MoodleSearchModulesProvider::class); + $context->registerSearchProvider(MoodleSearchUpcomingProvider::class); + } } public function boot(IBootContext $context): void { diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index d65da9d..c5a10ad 100644 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -84,4 +84,18 @@ class ConfigController extends Controller { $response = new DataResponse(1); return $response; } + + /** + * set admin config values + * + * @param array $values + * @return DataResponse + */ + public function setAdminConfig(array $values): DataResponse { + foreach ($values as $key => $value) { + $this->config->setAppValue(Application::APP_ID, $key, $value); + } + $response = new DataResponse(1); + return $response; + } } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php new file mode 100644 index 0000000..a53d1cf --- /dev/null +++ b/lib/Settings/Admin.php @@ -0,0 +1,59 @@ +appName = $appName; + $this->urlGenerator = $urlGenerator; + $this->request = $request; + $this->l = $l; + $this->config = $config; + $this->initialStateService = $initialStateService; + $this->userId = $userId; + } + + /** + * @return TemplateResponse + */ + public function getForm(): TemplateResponse { + $searchDisabled = $this->config->getAppValue(Application::APP_ID, 'search_disabled', '0') === '1'; + + $adminConfig = [ + 'search_disabled' => $searchDisabled, + ]; + $this->initialStateService->provideInitialState($this->appName, 'admin-config', $adminConfig); + return new TemplateResponse(Application::APP_ID, 'adminSettings'); + } + + public function getSection(): string { + return 'connected-accounts'; + } + + public function getPriority(): int { + return 10; + } +} diff --git a/lib/Settings/AdminSection.php b/lib/Settings/AdminSection.php new file mode 100644 index 0000000..f0b8bc8 --- /dev/null +++ b/lib/Settings/AdminSection.php @@ -0,0 +1,60 @@ +appName = $appName; + $this->l = $l; + $this->urlGenerator = $urlGenerator; + } + + /** + * returns the ID of the section. It is supposed to be a lower case string + * + * @returns string + */ + public function getID(): string { + return 'connected-accounts'; //or a generic id if feasible + } + + /** + * returns the translated name as it should be displayed, e.g. 'LDAP / AD + * integration'. Use the L10N service to translate it. + * + * @return string + */ + public function getName(): string { + return $this->l->t('Connected accounts'); + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the settings navigation. The sections are arranged in ascending order of + * the priority values. It is required to return a value between 0 and 99. + */ + public function getPriority(): int { + return 80; + } + + /** + * @return ?string The relative path to a an icon describing the section + */ + public function getIcon(): ?string { + return $this->urlGenerator->imagePath('core', 'categories/integration.svg'); + } + +} \ No newline at end of file diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index f1e59c9..758a80e 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -49,6 +49,8 @@ class Personal implements ISettings { $userName = $this->config->getUserValue($this->userId, Application::APP_ID, 'user_name', ''); $checkSsl = $this->config->getUserValue($this->userId, Application::APP_ID, 'check_ssl', '1') === '1'; + $searchDisabled = $this->config->getAppValue(Application::APP_ID, 'search_disabled', '0') === '1'; + $userConfig = [ 'token' => $token, 'url' => $url, @@ -57,6 +59,7 @@ class Personal implements ISettings { 'search_upcoming_enabled' => ($searchUpcomingEnabled === '1'), 'user_name' => $userName, 'check_ssl' => $checkSsl, + 'search_disabled' => $searchDisabled, ]; $this->initialStateService->provideInitialState($this->appName, 'user-config', $userConfig); return new TemplateResponse(Application::APP_ID, 'personalSettings'); diff --git a/src/adminSettings.js b/src/adminSettings.js new file mode 100644 index 0000000..8c3570a --- /dev/null +++ b/src/adminSettings.js @@ -0,0 +1,25 @@ +/* jshint esversion: 6 */ + +/** + * Nextcloud - moodle + * + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Julien Veyssier + * @copyright Julien Veyssier 2021 + */ + +import Vue from 'vue' +import './bootstrap' +import AdminSettings from './components/AdminSettings' + +// eslint-disable-next-line +'use strict' + +// eslint-disable-next-line +new Vue({ + el: '#moodle_prefs', + render: h => h(AdminSettings), +}) diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue new file mode 100644 index 0000000..f981878 --- /dev/null +++ b/src/components/AdminSettings.vue @@ -0,0 +1,109 @@ + + + + + diff --git a/src/components/PersonalSettings.vue b/src/components/PersonalSettings.vue index 9cd7a85..2790387 100644 --- a/src/components/PersonalSettings.vue +++ b/src/components/PersonalSettings.vue @@ -72,7 +72,7 @@ @input="onCheckSslChange">
-
+
+ +
\ No newline at end of file diff --git a/webpack.js b/webpack.js index ceb1da4..26e394c 100644 --- a/webpack.js +++ b/webpack.js @@ -12,6 +12,7 @@ webpackConfig.stats = { webpackConfig.entry = { personalSettings: { import: path.join(__dirname, 'src', 'personalSettings.js'), filename: 'integration_moodle-personalSettings.js' }, + adminSettings: { import: path.join(__dirname, 'src', 'adminSettings.js'), filename: 'integration_moodle-adminSettings.js' }, dashboard: { import: path.join(__dirname, 'src', 'dashboard.js'), filename: 'integration_moodle-dashboard.js' }, }