Skip to content

Commit

Permalink
Fixed tabs and Language support
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed May 16, 2018
1 parent 6ada825 commit f330655
Show file tree
Hide file tree
Showing 9 changed files with 595 additions and 555 deletions.
181 changes: 88 additions & 93 deletions settings/js/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/src/.jshintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"esversion": 6
"esversion": 6
}
2 changes: 1 addition & 1 deletion settings/src/components/userList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default {
// revert form to original state
Object.assign(this.newUser, this.$options.data.call(this).newUser);
this.loading = false;
},
},
createUser() {
this.loading = true;
this.$store.dispatch('addUser', {
Expand Down
46 changes: 22 additions & 24 deletions settings/src/components/userList/userRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export default {
let userid = this.user.id;
let gid = group.id;
return this.$store.dispatch('addUserGroup', {userid, gid})
.then(() => this.loading.groups = false);
.then(() => this.loading.groups = false);
},
/**
Expand All @@ -357,7 +357,7 @@ export default {
let userid = this.user.id;
let gid = group.id;
return this.$store.dispatch('removeUserGroup', {userid, gid})
.then(() => this.loading.groups = false);
.then(() => this.loading.groups = false);
},
/**
Expand All @@ -371,7 +371,7 @@ export default {
let userid = this.user.id;
let gid = group.id;
return this.$store.dispatch('addUserSubAdmin', {userid, gid})
.then(() => this.loading.subadmins = false);
.then(() => this.loading.subadmins = false);
},
/**
Expand All @@ -385,12 +385,11 @@ export default {
let userid = this.user.id;
let gid = group.id;
return this.$store.dispatch('removeUserSubAdmin', {userid, gid})
.then(() => this.loading.subadmins = false);
.then(() => this.loading.subadmins = false);
},
/**
* Validate quota string to make sure it's a valid human file size
* Dispatch quota set request
*
* @param {string|Object} quota Quota in readable format '5 GB' or Object {id: '5 GB', label: '5GB'}
* @returns {string}
Expand All @@ -407,24 +406,6 @@ export default {
return quota;
},
/**
* Validate quota string to make sure it's a valid human file size
*
* @param {string|Object} quota Quota in readable format '5 GB' or Object {id: '5 GB', label: '5GB'}
* @returns {string}
*/
setUserLanguage(lang) {
this.loading.languages = true;
// ensure we only send the preset id
this.$store.dispatch('setUserData', {
userid: this.user.id,
key: 'language',
value: lang.code
}).then(() => this.loading.languages = false);
return lang;
},
/**
* Validate quota string to make sure it's a valid human file size
*
Expand All @@ -442,6 +423,23 @@ export default {
}
// if no valid doo not change
return false;
},
/**
* Dispatch language set request
*
* @param {Object} lang language object {code:'en', name:'English'}
* @returns {Object}
*/
setUserLanguage(lang) {
this.loading.languages = true;
// ensure we only send the preset id
this.$store.dispatch('setUserData', {
userid: this.user.id,
key: 'language',
value: lang.code
}).then(() => this.loading.languages = false);
return lang;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions settings/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Vue.prototype.OC = OC;
Vue.prototype.oc_userconfig = oc_userconfig;

const app = new Vue({
router,
store,
render: h => h(App)
router,
store,
render: h => h(App)
}).$mount('#content');

export { app, router, store };
12 changes: 6 additions & 6 deletions settings/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Vue.use(Router);
*/

export default new Router({
mode: 'history',
base: window.location.pathName,
routes: [{
path: '/settings/users',
component: Users
}]
mode: 'history',
base: window.location.pathName,
routes: [{
path: '/settings/users',
component: Users
}]
});
129 changes: 88 additions & 41 deletions settings/src/store/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,94 @@ const requestToken = document.getElementsByTagName('head')[0].getAttribute('data
const tokenHeaders = { headers: { requesttoken: requestToken } };

const sanitize = function(url) {
return url.replace(/\/$/, ''); // Remove last slash of url
}
return url.replace(/\/$/, ''); // Remove last slash of url
};

export default {
requireAdmin() {
return new Promise(function(resolve, reject) {
setTimeout(reject, 5000); // automatically reject 5s if not ok
function waitForpassword() {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
setTimeout(waitForpassword, 500);
return;
}
resolve();
}
waitForpassword();
OC.PasswordConfirmation.requirePasswordConfirmation();
}).catch((error) => console.log('Required password not entered'));
},
get(url) {
return axios.get(sanitize(url), tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
post(url, data) {
return axios.post(sanitize(url), data, tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
patch(url, data) {
return axios.patch(sanitize(url), data, tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
put(url, data) {
return axios.put(sanitize(url), data, tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
delete(url, data) {
return axios.delete(sanitize(url), { data: data, headers: tokenHeaders.headers })
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
}

/**
* This Promise is used to chain a request that require an admin password confirmation
* Since chaining Promise have a very precise behavior concerning catch and then,
* you'll need to be careful when using it.
* e.g
* // store
* action(context) {
* return api.requireAdmin().then((response) => {
* return api.get('url')
* .then((response) => {API success})
* .catch((error) => {API failure});
* }).catch((error) => {requireAdmin failure});
* }
* // vue
* this.$store.dispatch('action').then(() => {always executed})
*
* Since Promise.then().catch().then() will always execute the last then
* this.$store.dispatch('action').then will always be executed
*
* If you want requireAdmin failure to also catch the API request failure
* you will need to throw a new error in the api.get.catch()
*
* e.g
* api.requireAdmin().then((response) => {
* api.get('url')
* .then((response) => {API success})
* .catch((error) => {throw error;});
* }).catch((error) => {requireAdmin OR API failure});
*/
requireAdmin() {
return new Promise(function(resolve, reject) {
// TODO: migrate the OC.dialog to Vue and avoid this mess
// wait for password confirmation
let passwordTimeout;
let waitForpassword = function() {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
passwordTimeout = setTimeout(waitForpassword, 500);
return;
}
clearTimeout(passwordTimeout);
clearTimeout(promiseTimeout);
resolve();
};

// automatically reject after 5s if not resolved
let promiseTimeout = setTimeout(() => {
clearTimeout(passwordTimeout);
// close dialog
if (document.getElementsByClassName('oc-dialog-close').length>0) {
document.getElementsByClassName('oc-dialog-close')[0].click();
}
OC.Notification.showTemporary(t('settings', 'You did not enter the password in time'));
reject('Password request cancelled');
}, 7000);

// request password
OC.PasswordConfirmation.requirePasswordConfirmation();
waitForpassword();
});
},
get(url) {
return axios.get(sanitize(url), tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
post(url, data) {
return axios.post(sanitize(url), data, tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
patch(url, data) {
return axios.patch(sanitize(url), data, tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
put(url, data) {
return axios.put(sanitize(url), data, tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
delete(url, data) {
return axios.delete(sanitize(url), { data: data, headers: tokenHeaders.headers })
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
}
};
Loading

0 comments on commit f330655

Please sign in to comment.