new OC api and default quota fixes

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-04-19 10:30:09 +02:00
parent ff2c23d9e2
commit 0e5b0fcef0
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
5 changed files with 132 additions and 92 deletions

File diff suppressed because one or more lines are too long

View File

@ -95,19 +95,5 @@ export default {
return axios.delete(sanitize(url), { data: data, headers: tokenHeaders.headers })
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
// OCS API entry points
/**
*
* @param {string} app Application name
* @param {string} key Config key
* @param {string} [value=''] Value to set
* @returns{Promise}
*/
setAppConfig(app, key, value = '') {
return this.requireAdmin().then((response) => {
return this.post(OC.linkToOCS(`apps/provisioning_api/api/v1/config/apps/${app}/${key}`, 2), {value: value});
});
}
};

View File

@ -2,6 +2,7 @@ import Vue from 'vue';
import Vuex from 'vuex';
import users from './users';
import settings from './settings';
import oc from './oc';
Vue.use(Vuex)
@ -10,13 +11,15 @@ const debug = process.env.NODE_ENV !== 'production';
const mutations = {
API_FAILURE(state, error) {
console.log(state, error);
OC.Notification.showTemporary(t('settings','An error occured during the request. Unable to proceed.'));
}
};
export default new Vuex.Store({
modules: {
users,
settings
settings,
oc
},
strict: debug,

25
settings/src/store/oc.js Normal file
View File

@ -0,0 +1,25 @@
import api from './api';
const state = {};
const mutations = {};
const getters = {};
const actions = {
/**
* Set application config in database
*
* @param {Object} context
* @param {Object} options
* @param {string} options.app Application name
* @param {boolean} options.key Config key
* @param {boolean} options.value Value to set
* @returns{Promise}
*/
setAppConfig(context, {app, key, value}) {
return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`apps/provisioning_api/api/v1/config/apps/${app}/${key}`, 2), {value: value})
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { app, key, value, error }));;
}
};
export default {state, mutations, getters, actions};

View File

@ -69,6 +69,8 @@ export default {
return {
// default quota is unlimited
unlimitedQuota: {id:'default', label:t('settings', 'Unlimited')},
// temporary value used for multiselect change
selectedQuota: false,
showConfig: {
showStoragePath: false,
showUserBackend: false,
@ -110,9 +112,17 @@ export default {
* @returns {string}
*/
setDefaultQuota(quota = 'none') {
// ensure we only send the preset id
quota = quota.id ? quota.id : quota;
api.setAppConfig('files', 'default_quota', quota);
this.$store.dispatch('setAppConfig', {
app: 'files',
key: 'default_quota',
// ensure we only send the preset id
value: quota.id ? quota.id : quota
}).then(() => {
if (typeof quota !== 'object') {
quota = {id: quota, label: quota};
}
this.defaultQuota = quota;
});
},
/**
@ -190,12 +200,21 @@ export default {
return quotaPreset;
},
// mapping saved values to objects
defaultQuota() {
if (OC.Util.computerFileSize(this.settings.defaultQuota) > 0) {
// if value is valid, let's map the quotaOptions or return custom quota
return {id:this.settings.defaultQuota, label:this.settings.defaultQuota};
defaultQuota: {
get: function() {
if (this.selectedQuota !== false) {
return this.selectedQuota;
}
if (OC.Util.computerFileSize(this.settings.defaultQuota) > 0) {
// if value is valid, let's map the quotaOptions or return custom quota
return {id:this.settings.defaultQuota, label:this.settings.defaultQuota};
}
return this.unlimitedQuota; // unlimited
},
set: function(quota) {
this.selectedQuota = quota;
}
return this.unlimitedQuota; // unlimited
},
// BUILD APP NAVIGATION MENU OBJECT