tests implementing settingscontroller
This commit is contained in:
parent
f9fbfe0d4e
commit
6fc4744b56
@ -25,4 +25,12 @@
|
|||||||
<route>radio.page.index</route>
|
<route>radio.page.index</route>
|
||||||
</navigation>
|
</navigation>
|
||||||
</navigations>
|
</navigations>
|
||||||
|
<activity>
|
||||||
|
<settings>
|
||||||
|
<setting>OCA\Radio\Activity\Setting</setting>
|
||||||
|
</settings>
|
||||||
|
<providers>
|
||||||
|
<provider>OCA\Radio\Activity\Provider</provider>
|
||||||
|
</providers>
|
||||||
|
</activity>
|
||||||
</info>
|
</info>
|
||||||
|
@ -27,12 +27,17 @@ return [
|
|||||||
'radio_api' => ['url' => '/api/0.1/radio']
|
'radio_api' => ['url' => '/api/0.1/radio']
|
||||||
],
|
],
|
||||||
'routes' => [
|
'routes' => [
|
||||||
|
// Web page templates
|
||||||
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
||||||
['name' => 'page#index', 'url' => '/top', 'verb' => 'GET', 'postfix' => 'top'],
|
['name' => 'page#index', 'url' => '/top', 'verb' => 'GET', 'postfix' => 'top'],
|
||||||
['name' => 'page#index', 'url' => '/recent', 'verb' => 'GET', 'postfix' => 'recent'],
|
['name' => 'page#index', 'url' => '/recent', 'verb' => 'GET', 'postfix' => 'recent'],
|
||||||
['name' => 'page#index', 'url' => '/new', 'verb' => 'GET', 'postfix' => 'new'],
|
['name' => 'page#index', 'url' => '/new', 'verb' => 'GET', 'postfix' => 'new'],
|
||||||
['name' => 'page#index', 'url' => '/favorites', 'verb' => 'GET', 'postfix' => 'favorites'],
|
['name' => 'page#index', 'url' => '/favorites', 'verb' => 'GET', 'postfix' => 'favorites'],
|
||||||
['name' => 'page#index', 'url' => '/categories', 'verb' => 'GET', 'postfix' => 'categories'],
|
['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}',
|
['name' => 'radio_api#preflighted_cors', 'url' => '/api/0.1/{path}',
|
||||||
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']]
|
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']]
|
||||||
]
|
]
|
||||||
|
@ -8,6 +8,7 @@ use OCP\AppFramework\App;
|
|||||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||||
|
use OCP\IRequest;
|
||||||
|
|
||||||
class Application extends App implements IBootstrap {
|
class Application extends App implements IBootstrap {
|
||||||
|
|
||||||
@ -18,6 +19,11 @@ class Application extends App implements IBootstrap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function register(IRegistrationContext $context): void {
|
public function register(IRegistrationContext $context): void {
|
||||||
|
|
||||||
|
$context->registerService('request', static function ($c) {
|
||||||
|
return $c->get(IRequest::class);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(IBootContext $context): void {
|
public function boot(IBootContext $context): void {
|
||||||
|
@ -70,101 +70,33 @@ class SettingsController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get player volume config value
|
* set menu state
|
||||||
*
|
*
|
||||||
|
* @param string $menuState
|
||||||
* @return JSONResponse
|
* @return JSONResponse
|
||||||
*
|
*
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function getVolume(): JSONResponse {
|
public function setMenuState($menuState = ""): JSONResponse {
|
||||||
return $this->getSetting('volume', 'volume', 0.5);
|
$legalArguments = ['TOP', 'RECENT', 'NEW', 'FAVORITES', 'CATEGORIES'];
|
||||||
}
|
if (!in_array($menuState, $legalArguments)) {
|
||||||
|
|
||||||
/**
|
|
||||||
* 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)) {
|
|
||||||
return new JSONResponse(['status' => 'error'], Http::STATUS_BAD_REQUEST);
|
return new JSONResponse(['status' => 'error'], Http::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
return $this->setSetting(
|
return $this->setSetting(
|
||||||
'sorting',
|
'menuState',
|
||||||
$sorting
|
$menuState
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get view mode option config value
|
* get menu state
|
||||||
*
|
*
|
||||||
* @return JSONResponse
|
* @return JSONResponse
|
||||||
*
|
*
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function getViewMode(): JSONResponse {
|
public function getMenuState(): JSONResponse {
|
||||||
return $this->getSetting('viewMode', 'viewMode', 'grid');
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -76,12 +76,14 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.loadStations()
|
this.loadStations()
|
||||||
this.scroll()
|
this.scroll()
|
||||||
|
this.$store.dispatch('getMenuState')
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async onRoute() {
|
async onRoute() {
|
||||||
this.offset = 0
|
this.offset = 0
|
||||||
this.tableData = []
|
this.tableData = []
|
||||||
const route = this.$route
|
const route = this.$route
|
||||||
|
this.$store.dispatch('setMenuState', route.name)
|
||||||
switch (route.name) {
|
switch (route.name) {
|
||||||
case 'TOP':
|
case 'TOP':
|
||||||
this.loadStations()
|
this.loadStations()
|
||||||
|
25
src/store.js
25
src/store.js
@ -1,5 +1,9 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
|
import axios from '@nextcloud/axios'
|
||||||
|
import { generateUrl } from '@nextcloud/router'
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
@ -46,6 +50,21 @@ export default new Vuex.Store({
|
|||||||
setTitle(state, title) {
|
setTitle(state, title) {
|
||||||
state.player.title = 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: {
|
actions: {
|
||||||
isPlaying(context, playerState) {
|
isPlaying(context, playerState) {
|
||||||
@ -66,5 +85,11 @@ export default new Vuex.Store({
|
|||||||
setTitle(context, title) {
|
setTitle(context, title) {
|
||||||
context.commit('setTitle', title)
|
context.commit('setTitle', title)
|
||||||
},
|
},
|
||||||
|
setMenuState(context, menuState) {
|
||||||
|
context.commit('setMenuState', menuState)
|
||||||
|
},
|
||||||
|
getMenuState(context) {
|
||||||
|
context.commit('getMenuState')
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user