From 6fc4744b56c62315abd5e6304845a1dec64c4a30 Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Tue, 27 Oct 2020 13:43:30 +0100 Subject: [PATCH] tests implementing settingscontroller --- appinfo/info.xml | 8 +++ appinfo/routes.php | 5 ++ lib/AppInfo/Application.php | 6 ++ lib/Controller/SettingsController.php | 88 +++------------------------ src/components/Main.vue | 2 + src/store.js | 25 ++++++++ 6 files changed, 56 insertions(+), 78 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 0c3dd72..6a8902c 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -25,4 +25,12 @@ radio.page.index + + + OCA\Radio\Activity\Setting + + + OCA\Radio\Activity\Provider + + diff --git a/appinfo/routes.php b/appinfo/routes.php index 27d8690..2ee2191 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -27,12 +27,17 @@ return [ 'radio_api' => ['url' => '/api/0.1/radio'] ], 'routes' => [ + // Web page templates ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'page#index', 'url' => '/top', 'verb' => 'GET', 'postfix' => 'top'], ['name' => 'page#index', 'url' => '/recent', 'verb' => 'GET', 'postfix' => 'recent'], ['name' => 'page#index', 'url' => '/new', 'verb' => 'GET', 'postfix' => 'new'], ['name' => 'page#index', 'url' => '/favorites', 'verb' => 'GET', 'postfix' => 'favorites'], ['name' => 'page#index', 'url' => '/categories', 'verb' => 'GET', 'postfix' => 'categories'], + // Settings + ['name' => 'settings#set_menu_state', 'url' => '/settings/menuState', 'verb' => 'POST'], + ['name' => 'settings#get_menu_state', 'url' => '/settings/menuState', 'verb' => 'GET'], + // Api ['name' => 'radio_api#preflighted_cors', 'url' => '/api/0.1/{path}', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']] ] diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 4f9a252..57075e0 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -8,6 +8,7 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\IRequest; class Application extends App implements IBootstrap { @@ -18,6 +19,11 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { + + $context->registerService('request', static function ($c) { + return $c->get(IRequest::class); + }); + } public function boot(IBootContext $context): void { diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index d852879..036c597 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -70,101 +70,33 @@ class SettingsController extends ApiController { } /** - * get player volume config value + * set menu state * + * @param string $menuState * @return JSONResponse * * @NoAdminRequired */ - public function getVolume(): JSONResponse { - return $this->getSetting('volume', 'volume', 0.5); - } - - /** - * set player volume config value - * - * @param string $sorting - * @return JSONResponse - * - * @NoAdminRequired - */ - public function setSorting($sorting = ""): JSONResponse { - $legalArguments = ['title', 'added', 'clickcount', 'lastmodified', 'index']; - if (!in_array($sorting, $legalArguments)) { + public function setMenuState($menuState = ""): JSONResponse { + $legalArguments = ['TOP', 'RECENT', 'NEW', 'FAVORITES', 'CATEGORIES']; + if (!in_array($menuState, $legalArguments)) { return new JSONResponse(['status' => 'error'], Http::STATUS_BAD_REQUEST); } return $this->setSetting( - 'sorting', - $sorting + 'menuState', + $menuState ); } /** - * get view mode option config value + * get menu state * * @return JSONResponse * * @NoAdminRequired */ - public function getViewMode(): JSONResponse { - return $this->getSetting('viewMode', 'viewMode', 'grid'); + public function getMenuState(): JSONResponse { + return $this->getSetting('menuState', 'menuState', 'TOP'); } - /** - * set sorting option config value - * - * @param string $viewMode - * @return JSONResponse - * - * @NoAdminRequired - */ - public function setViewMode($viewMode = ""): JSONResponse { - $legalArguments = ['grid', 'list']; - if (!in_array($viewMode, $legalArguments)) { - return new JSONResponse(['status' => 'error'], Http::STATUS_BAD_REQUEST); - } - return $this->setSetting( - 'viewMode', - $viewMode - ); - } - - /** - * get per-user bookmarks limit - * - * @return JSONResponse - * - * @NoAdminRequired - */ - public function getLimit(): JSONResponse { - $limit = (int)$this->config->getAppValue('bookmarks', 'performance.maxBookmarksperAccount', 0); - return new JSONResponse(['limit' => $limit], Http::STATUS_OK); - } - - /** - * get user-defined archive path - * - * @return JSONResponse - * - * @NoAdminRequired - */ - public function getArchivePath(): JSONResponse { - return $this->getSetting( - 'archive.filePath', - 'archivePath', - $this->l->t('Bookmarks') - ); - } - - /** - * set user-defined archive path - * - * @param string $archivePath - * @return JSONResponse - * - * @NoAdminRequired - */ - public function setArchivePath(string $archivePath): JSONResponse { - return $this->setSetting('archive.filePath', $archivePath); - } } diff --git a/src/components/Main.vue b/src/components/Main.vue index 55876bd..a6c8e2d 100644 --- a/src/components/Main.vue +++ b/src/components/Main.vue @@ -76,12 +76,14 @@ export default { mounted() { this.loadStations() this.scroll() + this.$store.dispatch('getMenuState') }, methods: { async onRoute() { this.offset = 0 this.tableData = [] const route = this.$route + this.$store.dispatch('setMenuState', route.name) switch (route.name) { case 'TOP': this.loadStations() diff --git a/src/store.js b/src/store.js index 31e914a..b206d84 100644 --- a/src/store.js +++ b/src/store.js @@ -1,5 +1,9 @@ import Vue from 'vue' import Vuex from 'vuex' + +import axios from '@nextcloud/axios' +import { generateUrl } from '@nextcloud/router' + Vue.use(Vuex) export default new Vuex.Store({ @@ -46,6 +50,21 @@ export default new Vuex.Store({ setTitle(state, title) { state.player.title = title }, + setMenuState(state, menuState) { + axios.post(generateUrl('/apps/radio/settings/menuState'), { + menuState, + }) + }, + getMenuState(state, menuState) { + axios + .get(generateUrl('/apps/radio/settings/menuState')) + .then(async response => { + const { + data: { menuState: value }, + } = response + console.log(value) + }) + }, }, actions: { isPlaying(context, playerState) { @@ -66,5 +85,11 @@ export default new Vuex.Store({ setTitle(context, title) { context.commit('setTitle', title) }, + setMenuState(context, menuState) { + context.commit('setMenuState', menuState) + }, + getMenuState(context) { + context.commit('getMenuState') + }, }, })