Initial Spark Install
This commit is contained in:
139
spark/resources/assets/js/settings/api/create-token.js
vendored
Normal file
139
spark/resources/assets/js/settings/api/create-token.js
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
};
|
103
spark/resources/assets/js/settings/api/tokens.js
vendored
Normal file
103
spark/resources/assets/js/settings/api/tokens.js
vendored
Normal 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');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user