Now load instance settings on page load
This commit is contained in:
parent
bb9a614aa7
commit
aa67be9063
|
@ -31,6 +31,9 @@ import Sidebar from '@/components/Sidebar'
|
|||
export default {
|
||||
name: 'app',
|
||||
components: { Sidebar }
|
||||
created () {
|
||||
this.$store.dispatch('instance/fetchSettings')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import createPersistedState from 'vuex-persistedstate'
|
|||
|
||||
import favorites from './favorites'
|
||||
import auth from './auth'
|
||||
import instance from './instance'
|
||||
import queue from './queue'
|
||||
import radios from './radios'
|
||||
import player from './player'
|
||||
|
@ -14,6 +15,7 @@ export default new Vuex.Store({
|
|||
modules: {
|
||||
auth,
|
||||
favorites,
|
||||
instance,
|
||||
queue,
|
||||
radios,
|
||||
player
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import axios from 'axios'
|
||||
import logger from '@/logging'
|
||||
import _ from 'lodash'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
settings: {
|
||||
raven: {
|
||||
front_enabled: {
|
||||
value: false
|
||||
},
|
||||
front_dsn: {
|
||||
value: null
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
settings: (state, value) => {
|
||||
_.merge(state.settings, value)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// Send a request to the login URL and save the returned JWT
|
||||
fetchSettings ({commit}) {
|
||||
return axios.get('instance/settings/').then(response => {
|
||||
logger.default.info('Successfully fetched instance settings')
|
||||
let sections = {}
|
||||
response.data.forEach(e => {
|
||||
sections[e.section] = {}
|
||||
})
|
||||
response.data.forEach(e => {
|
||||
sections[e.section][e.name] = e
|
||||
})
|
||||
commit('settings', sections)
|
||||
}, response => {
|
||||
logger.default.error('Error while fetching settings', response.data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
var sinon = require('sinon')
|
||||
import moxios from 'moxios'
|
||||
import store from '@/store/instance'
|
||||
import { testAction } from '../../utils'
|
||||
|
||||
describe('store/instance', () => {
|
||||
var sandbox
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.sandbox.create()
|
||||
moxios.install()
|
||||
})
|
||||
afterEach(function () {
|
||||
sandbox.restore()
|
||||
moxios.uninstall()
|
||||
})
|
||||
|
||||
describe('mutations', () => {
|
||||
it('settings', () => {
|
||||
const state = {settings: {raven: {front_dsn: {value: 'test'}}}}
|
||||
let settings = {raven: {front_enabled: {value: true}}}
|
||||
store.mutations.settings(state, settings)
|
||||
expect(state.settings).to.deep.equal({
|
||||
raven: {front_dsn: {value: 'test'}, front_enabled: {value: true}}
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('actions', () => {
|
||||
it('fetchSettings', (done) => {
|
||||
moxios.stubRequest('instance/settings/', {
|
||||
status: 200,
|
||||
response: [
|
||||
{
|
||||
section: 'raven',
|
||||
name: 'front_dsn',
|
||||
value: 'test'
|
||||
},
|
||||
{
|
||||
section: 'raven',
|
||||
name: 'front_enabled',
|
||||
value: false
|
||||
}
|
||||
]
|
||||
})
|
||||
testAction({
|
||||
action: store.actions.fetchSettings,
|
||||
payload: null,
|
||||
expectedMutations: [
|
||||
{
|
||||
type: 'settings',
|
||||
payload: {
|
||||
raven: {
|
||||
front_dsn: {
|
||||
section: 'raven',
|
||||
name: 'front_dsn',
|
||||
value: 'test'
|
||||
},
|
||||
front_enabled: {
|
||||
section: 'raven',
|
||||
name: 'front_enabled',
|
||||
value: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}, done)
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue