refs #4925 feat: añadido back para editar tags
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
a5ab5d613a
commit
3792a80ad5
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('Tag', 'onSubmit', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
|
@ -147,28 +147,17 @@ export default class CrudModel extends ModelProxy {
|
|||
this.moreRows = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves current changes on the server.
|
||||
*
|
||||
* @return {Promise} The save request promise
|
||||
*/
|
||||
save() {
|
||||
if (!this.isChanged)
|
||||
return this.$q.resolve();
|
||||
getChanges() {
|
||||
if (!this.isChanged) return null;
|
||||
|
||||
let deletes = [];
|
||||
let updates = [];
|
||||
let creates = [];
|
||||
let orgDeletes = [];
|
||||
let orgUpdates = [];
|
||||
let orgCreates = [];
|
||||
const deletes = [];
|
||||
const updates = [];
|
||||
const creates = [];
|
||||
|
||||
let pk = this.primaryKey;
|
||||
const pk = this.primaryKey;
|
||||
|
||||
for (let row of this.removed) {
|
||||
for (let row of this.removed)
|
||||
deletes.push(row.$orgRow[pk]);
|
||||
orgDeletes.push(row);
|
||||
}
|
||||
|
||||
for (let row of this.data) {
|
||||
if (row.$isNew) {
|
||||
|
@ -178,7 +167,6 @@ export default class CrudModel extends ModelProxy {
|
|||
data[prop] = row[prop];
|
||||
}
|
||||
creates.push(row);
|
||||
orgCreates.push(row);
|
||||
} else if (row.$oldData) {
|
||||
let data = {};
|
||||
for (let prop in row.$oldData)
|
||||
|
@ -187,7 +175,6 @@ export default class CrudModel extends ModelProxy {
|
|||
data,
|
||||
where: {[pk]: row.$orgRow[pk]}
|
||||
});
|
||||
orgUpdates.push(row);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,8 +185,20 @@ export default class CrudModel extends ModelProxy {
|
|||
changes[prop] = undefined;
|
||||
}
|
||||
|
||||
if (!changes)
|
||||
return this.$q.resolve();
|
||||
return changes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves current changes on the server.
|
||||
*
|
||||
* @return {Promise} The save request promise
|
||||
*/
|
||||
save() {
|
||||
const pk = this.primaryKey;
|
||||
const changes = this.getChanges();
|
||||
if (!changes) return this.$q.resolve();
|
||||
|
||||
const creates = changes.creates;
|
||||
|
||||
let url = this.saveUrl ? this.saveUrl : `${this._url}/crud`;
|
||||
return this.$http.post(url, changes)
|
||||
|
@ -207,8 +206,8 @@ export default class CrudModel extends ModelProxy {
|
|||
const created = res.data;
|
||||
|
||||
// Apply new data to created instances
|
||||
for (let i = 0; i < orgCreates.length; i++) {
|
||||
const row = orgCreates[i];
|
||||
for (let i = 0; i < creates.length; i++) {
|
||||
const row = creates[i];
|
||||
row[pk] = created[i][pk];
|
||||
|
||||
for (let prop in row) {
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
|
||||
module.exports = function(Self) {
|
||||
Self.remoteMethodCtx('onSubmit', {
|
||||
description: 'Creates client address updating default address',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'creates',
|
||||
type: ['object'],
|
||||
description: 'The itemTags records to create'
|
||||
}, {
|
||||
arg: 'deletes',
|
||||
type: ['number'],
|
||||
description: 'The itemTags ids to delete'
|
||||
}, {
|
||||
arg: 'updates',
|
||||
type: ['object'],
|
||||
description: 'The itemTags records to update'
|
||||
}, {
|
||||
arg: 'maxPriority',
|
||||
type: 'number',
|
||||
description: 'The maxPriority value'
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
root: true,
|
||||
type: 'object'
|
||||
},
|
||||
http: {
|
||||
verb: 'PATCH',
|
||||
path: '/onSubmit'
|
||||
}
|
||||
});
|
||||
|
||||
Self.onSubmit = async(ctx, options) => {
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const promises = [];
|
||||
|
||||
if (args.deletes) {
|
||||
for (const itemTagId of args.deletes) {
|
||||
const itemTagDeleted = await models.ItemTag.destroyById(itemTagId, myOptions);
|
||||
promises.push(itemTagDeleted);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.updates) {
|
||||
console.log('args.updates', args.updates);
|
||||
for (const row of args.updates) {
|
||||
if (row.data.priority) {
|
||||
const itemTag = await models.ItemTag.findById(row.where.id, null, myOptions);
|
||||
const itemTagUpdatedPriority = await itemTag.updateAttributes({
|
||||
priority: row.data.priority + args.maxPriority
|
||||
}, myOptions);
|
||||
promises.push(itemTagUpdatedPriority);
|
||||
}
|
||||
}
|
||||
for (const row of args.updates) {
|
||||
const itemTag = await models.ItemTag.findById(row.where.id, null, myOptions);
|
||||
const itemTagUpdated = await itemTag.updateAttributes(row.data, myOptions);
|
||||
promises.push(itemTagUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.creates) {
|
||||
for (const itemTag of args.creates) {
|
||||
const newItemTag = await models.ItemTag.create(itemTag, myOptions);
|
||||
promises.push(newItemTag);
|
||||
}
|
||||
}
|
||||
|
||||
const resolvedPromises = await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return resolvedPromises;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -4,8 +4,8 @@ module.exports = Self => {
|
|||
require('../methods/item-tag/filterItemTags')(Self);
|
||||
|
||||
Self.rewriteDbError(function(err) {
|
||||
if (err.code === 'ER_DUP_ENTRY')
|
||||
return new UserError(`The tag or priority can't be repeated for an item`);
|
||||
// if (err.code === 'ER_DUP_ENTRY')
|
||||
// return new UserError(`The tag or priority can't be repeated for an item`);
|
||||
if (err.code === 'ER_BAD_NULL_ERROR')
|
||||
return new UserError(`Tag value cannot be blank`);
|
||||
return err;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/tag/filterValue')(Self);
|
||||
require('../methods/tag/onSubmit')(Self);
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
data="tags"
|
||||
auto-load="true">
|
||||
</vn-crud-model>
|
||||
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
|
||||
<form name="form" class="vn-w-md">
|
||||
<vn-card class="vn-pa-lg">
|
||||
<vn-horizontal ng-repeat="itemTag in $ctrl.itemTags">
|
||||
<vn-autocomplete vn-two vn-id="tag" vn-focus
|
||||
|
@ -73,9 +73,10 @@
|
|||
</vn-one>
|
||||
</vn-card>
|
||||
<vn-button-bar>
|
||||
<vn-submit
|
||||
<vn-button
|
||||
ng-click="$ctrl.onSubmit()"
|
||||
disabled="!watcher.dataChanged()"
|
||||
label="Save">
|
||||
</vn-submit>
|
||||
</vn-button>
|
||||
</vn-button-bar>
|
||||
</form>
|
||||
</form>
|
||||
|
|
|
@ -29,8 +29,15 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
onSubmit() {
|
||||
this.$.watcher.check();
|
||||
this.$.model.save().then(() => {
|
||||
const changes = this.$.model.getChanges();
|
||||
console.log(changes);
|
||||
const data = {
|
||||
creates: changes.creates,
|
||||
deletes: changes.deletes,
|
||||
updates: changes.updates,
|
||||
maxPriority: this.getHighestPriority()
|
||||
};
|
||||
this.$http.patch(`Tags/onSubmit`, data).then(() => {
|
||||
this.$.watcher.notifySaved();
|
||||
this.$.watcher.updateOriginalData();
|
||||
this.card.reload();
|
||||
|
|
Loading…
Reference in New Issue