e61da5a662
* Update transform role delete button to be ConfirmAction with dropdown * Set backend on fetched record so that it saves correctly * Update transformation after role transformations changed works * Clean up transform adapter * Add role to allowed_roles on added transformations and remove from removed transformations on role save, with flash message * Add backend to transform role model, and update serializer to add backend to paginated results * Clean up error message handling * Connect backend to transform roles list response * Capabilities on transform roles is correct * Fix cancel button on transform role edit location * Fix model path * Remove unnecessary tab param from controller * Add backend to transform model
67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
import ApplicationAdapter from '../application';
|
|
import { encodePath } from 'vault/utils/path-encoding-helpers';
|
|
|
|
export default ApplicationAdapter.extend({
|
|
namespace: 'v1',
|
|
|
|
pathForType(type) {
|
|
return type.replace('transform/', '');
|
|
},
|
|
|
|
createOrUpdate(store, type, snapshot) {
|
|
const serializer = store.serializerFor(type.modelName);
|
|
const data = serializer.serialize(snapshot);
|
|
const { id } = snapshot;
|
|
let url = this.url(snapshot.record.get('backend'), type.modelName, id);
|
|
|
|
return this.ajax(url, 'POST', { data });
|
|
},
|
|
|
|
createRecord() {
|
|
return this.createOrUpdate(...arguments);
|
|
},
|
|
|
|
updateRecord() {
|
|
return this.createOrUpdate(...arguments, 'update');
|
|
},
|
|
|
|
deleteRecord(store, type, snapshot) {
|
|
const { id } = snapshot;
|
|
return this.ajax(this.url(snapshot.record.get('backend'), type.modelName, id), 'DELETE');
|
|
},
|
|
|
|
url(backend, modelType, id) {
|
|
let type = this.pathForType(modelType);
|
|
let url = `/${this.namespace}/${encodePath(backend)}/${encodePath(type)}`;
|
|
if (id) {
|
|
return `${url}/${encodePath(id)}`;
|
|
}
|
|
return url + '?list=true';
|
|
},
|
|
|
|
fetchByQuery(query) {
|
|
const { backend, modelName, id } = query;
|
|
return this.ajax(this.url(backend, modelName, id), 'GET').then(resp => {
|
|
return {
|
|
...resp,
|
|
backend,
|
|
};
|
|
});
|
|
},
|
|
|
|
query(store, type, query) {
|
|
return this.fetchByQuery(query);
|
|
},
|
|
|
|
queryRecord(store, type, query) {
|
|
return this.ajax(this.url(query.backend, type.modelName, query.id), 'GET').then(result => {
|
|
return {
|
|
id: query.id,
|
|
...result,
|
|
};
|
|
});
|
|
},
|
|
|
|
// buildUrl(modelName, id, snapshot, requestType, query, returns) {},
|
|
});
|