Fixed tabs and Language support

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-04-09 11:03:21 +02:00
parent 6ada8254c9
commit f33065523d
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
9 changed files with 599 additions and 559 deletions

File diff suppressed because one or more lines are too long

View File

@ -388,9 +388,8 @@ export default {
.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}
@ -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
*
@ -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;
}
}
}

View File

@ -5,22 +5,69 @@ const tokenHeaders = { headers: { requesttoken: requestToken } };
const sanitize = function(url) {
return url.replace(/\/$/, ''); // Remove last slash of url
}
};
export default {
/**
* 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) {
setTimeout(reject, 5000); // automatically reject 5s if not ok
function waitForpassword() {
// TODO: migrate the OC.dialog to Vue and avoid this mess
// wait for password confirmation
let passwordTimeout;
let waitForpassword = function() {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
setTimeout(waitForpassword, 500);
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();
}
waitForpassword();
OC.Notification.showTemporary(t('settings', 'You did not enter the password in time'));
reject('Password request cancelled');
}, 7000);
// request password
OC.PasswordConfirmation.requirePasswordConfirmation();
}).catch((error) => console.log('Required password not entered'));
waitForpassword();
});
},
get(url) {
return axios.get(sanitize(url), tokenHeaders)

View File

@ -227,8 +227,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`cloud/groups`, 2), {groupid: gid})
.then((response) => context.commit('addGroup', gid))
.catch((error) => context.commit('API_FAILURE', error));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/**
@ -242,8 +242,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`cloud/groups`, 2), {groupid: gid})
.then((response) => context.commit('removeGroup', gid))
.catch((error) => context.commit('API_FAILURE', error));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/**
@ -259,8 +259,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`cloud/users/${userid}/groups`, 2), { groupid: gid })
.then((response) => context.commit('addUserGroup', { userid, gid }))
.catch((error) => context.commit('API_FAILURE', error));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/**
@ -276,8 +276,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.delete(OC.linkToOCS(`cloud/users/${userid}/groups`, 2), { groupid: gid })
.then((response) => context.commit('removeUserGroup', { userid, gid }))
.catch((error) => context.commit('API_FAILURE', { userid, error }));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/**
@ -293,8 +293,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`cloud/users/${userid}/subadmins`, 2), { groupid: gid })
.then((response) => context.commit('addUserSubAdmin', { userid, gid }))
.catch((error) => context.commit('API_FAILURE', error));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/**
@ -310,8 +310,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.delete(OC.linkToOCS(`cloud/users/${userid}/subadmins`, 2), { groupid: gid })
.then((response) => context.commit('removeUserSubAdmin', { userid, gid }))
.catch((error) => context.commit('API_FAILURE', { userid, error }));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/**
@ -325,8 +325,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.delete(OC.linkToOCS(`cloud/users/${userid}`, 2))
.then((response) => context.commit('deleteUser', userid))
.catch((error) => context.commit('API_FAILURE', { userid, error }));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/**
@ -350,8 +350,8 @@ const actions = {
//let quotaDis = dispatch('setUserData', { userid, key: 'quota', value:quota });
//let subadminDis = dispatch('addUserSubAdmin', userid);
})
.catch((error) => context.commit('API_FAILURE', { userid, error }));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/**
@ -365,8 +365,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.get(OC.linkToOCS(`cloud/users/${userid}`, 2))
.then((response) => context.commit('addUserData', response))
.catch((error) => context.commit('API_FAILURE', { userid, error }));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/** Enable or disable user
@ -382,8 +382,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.put(OC.linkToOCS(`cloud/users/${userid}/${userStatus}`, 2))
.then((response) => context.commit('enableDisableUser', { userid, enabled }))
.catch((error) => context.commit('API_FAILURE', { userid, error }));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
},
/**
@ -409,8 +409,8 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.put(OC.linkToOCS(`cloud/users/${userid}`, 2), { key: key, value: value })
.then((response) => context.commit('setUserData', { userid, key, value }))
.catch((error) => context.commit('API_FAILURE', { userid, error }));
});
.catch((error) => {throw error;});
}).catch((error) => context.commit('API_FAILURE', { userid, error }));
}
}
return Promise.reject(new Error('Invalid request data'));