Initial Spark Install

This commit is contained in:
Deon George
2017-11-03 16:26:07 +11:00
commit b1a5807eb3
766 changed files with 128896 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
module.exports = {
props: ['availableAbilities'],
/**
* The component's data.
*/
data() {
return {
showingToken: null,
allAbilitiesAssigned: false,
form: new SparkForm({
name: '',
abilities: []
})
};
},
computed: {
copyCommandSupported() {
return document.queryCommandSupported('copy');
}
},
watch: {
/**
* Watch the available abilities for changes.
*/
availableAbilities() {
if (this.availableAbilities.length > 0) {
this.assignDefaultAbilities();
}
}
},
methods: {
/**
* Assign all of the default abilities.
*/
assignDefaultAbilities() {
var defaults = _.filter(this.availableAbilities, a => a.default);
this.form.abilities = _.pluck(defaults, 'value');
},
/**
* Enable all the available abilities for the given token.
*/
assignAllAbilities() {
this.allAbilitiesAssigned = true;
this.form.abilities = _.pluck(this.availableAbilities, 'value');
},
/**
* Remove all of the abilities from the token.
*/
removeAllAbilities() {
this.allAbilitiesAssigned = false;
this.form.abilities = [];
},
/**
* Toggle the given ability in the list of assigned abilities.
*/
toggleAbility(ability) {
if (this.abilityIsAssigned(ability)) {
this.form.abilities = _.reject(this.form.abilities, a => a == ability);
} else {
this.form.abilities.push(ability);
}
},
/**
* Determine if the given ability has been assigned to the token.
*/
abilityIsAssigned(ability) {
return _.contains(this.form.abilities, ability);
},
/**
* Create a new API token.
*/
create() {
Spark.post('/settings/api/token', this.form)
.then(response => {
this.showToken(response.token);
this.resetForm();
this.$parent.$emit('updateTokens');
});
},
/**
* Display the token to the user.
*/
showToken(token) {
this.showingToken = token;
$('#modal-show-token').modal('show');
},
/**
* Select the token and copy to Clipboard.
*/
selectToken() {
$('#api-token').select();
if (this.copyCommandSupported) {
document.execCommand("copy");
}
},
/**
* Reset the token form back to its default state.
*/
resetForm() {
this.form.name = '';
this.assignDefaultAbilities();
this.allAbilitiesAssigned = false;
}
}
};

View File

@@ -0,0 +1,103 @@
module.exports = {
props: ['tokens', 'availableAbilities'],
/**
* The component's data.
*/
data() {
return {
updatingToken: null,
deletingToken: null,
updateTokenForm: new SparkForm({
name: '',
abilities: []
}),
deleteTokenForm: new SparkForm({})
}
},
methods: {
/**
* Show the edit token modal.
*/
editToken(token) {
this.updatingToken = token;
this.initializeUpdateFormWith(token);
$('#modal-update-token').modal('show');
},
/**
* Initialize the edit form with the given token.
*/
initializeUpdateFormWith(token) {
this.updateTokenForm.name = token.name;
this.updateTokenForm.abilities = token.metadata.abilities;
},
/**
* Update the token being edited.
*/
updateToken() {
Spark.put(`/settings/api/token/${this.updatingToken.id}`, this.updateTokenForm)
.then(response => {
this.$parent.$emit('updateTokens');
$('#modal-update-token').modal('hide');
})
},
/**
* Toggle the ability on the current token being edited.
*/
toggleAbility(ability) {
if (this.abilityIsAssigned(ability)) {
this.updateTokenForm.abilities = _.reject(
this.updateTokenForm.abilities, a => a == ability
);
} else {
this.updateTokenForm.abilities.push(ability);
}
},
/**
* Determine if the ability has been assigned to the token being edited.
*/
abilityIsAssigned(ability) {
return _.contains(this.updateTokenForm.abilities, ability);
},
/**
* Get user confirmation that the token should be deleted.
*/
approveTokenDelete(token) {
this.deletingToken = token;
$('#modal-delete-token').modal('show');
},
/**
* Delete the specified token.
*/
deleteToken() {
Spark.delete(`/settings/api/token/${this.deletingToken.id}`, this.deleteTokenForm)
.then(() => {
this.$parent.$emit('updateTokens');
$('#modal-delete-token').modal('hide');
});
}
}
};