refs #5063 deleted item checked in image, added front test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
271a6d898d
commit
afb14044cc
|
@ -140,7 +140,6 @@ module.exports = Self => {
|
||||||
|
|
||||||
const item = await model.findById(entityId, null, myOptions);
|
const item = await model.findById(entityId, null, myOptions);
|
||||||
if (item) {
|
if (item) {
|
||||||
if (collection.model == 'Item') fileName += '#';
|
|
||||||
await item.updateAttribute(
|
await item.updateAttribute(
|
||||||
collection.property,
|
collection.property,
|
||||||
fileName,
|
fileName,
|
||||||
|
|
|
@ -22,37 +22,22 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx) {
|
||||||
if (ctx.isNewInstance) await Self.availableId(ctx);
|
if (ctx.isNewInstance) await Self.availableId(ctx);
|
||||||
else {
|
|
||||||
const changes = ctx.data || ctx.instance;
|
|
||||||
const orgData = ctx.currentInstance;
|
|
||||||
|
|
||||||
const hasChanges = orgData && changes;
|
|
||||||
const image = changes.image || orgData.image;
|
|
||||||
const imageChanged = hasChanges && orgData.image != image;
|
|
||||||
|
|
||||||
if (imageChanged) {
|
|
||||||
try {
|
|
||||||
changes.image = changes.image.slice(0, -1);
|
|
||||||
if (orgData.isPhotoRequested == true) changes.isPhotoRequested = false;
|
|
||||||
} catch (e) {
|
|
||||||
throw new UserError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.availableId = async function(ctx) {
|
Self.availableId = async function(ctx) {
|
||||||
try {
|
if (ctx.isNewInstance) {
|
||||||
let query = `SELECT i1.id + 1 as id FROM vn.item i1
|
try {
|
||||||
|
let query = `SELECT i1.id + 1 as id FROM vn.item i1
|
||||||
LEFT JOIN vn.item i2 ON i1.id + 1 = i2.id
|
LEFT JOIN vn.item i2 ON i1.id + 1 = i2.id
|
||||||
WHERE i2.id IS NULL ORDER BY i1.id LIMIT 1`;
|
WHERE i2.id IS NULL ORDER BY i1.id LIMIT 1`;
|
||||||
|
|
||||||
let newId = await Self.rawSql(query);
|
let newId = await Self.rawSql(query);
|
||||||
|
|
||||||
ctx.instance.id = newId[0].id;
|
ctx.instance.id = newId[0].id;
|
||||||
return ctx.instance.id;
|
return ctx.instance.id;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new UserError(e);
|
throw new UserError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -91,6 +91,11 @@ class Controller extends Descriptor {
|
||||||
|
|
||||||
this.$.photo.setAttribute('src', newSrc);
|
this.$.photo.setAttribute('src', newSrc);
|
||||||
this.$.photo.setAttribute('zoom-image', newZoomSrc);
|
this.$.photo.setAttribute('zoom-image', newZoomSrc);
|
||||||
|
|
||||||
|
if (this.item.isPhotoRequested) {
|
||||||
|
this.$http.patch(`Items/${this.item.id}`, {isPhotoRequested: false})
|
||||||
|
.then(() => this.item.isPhotoRequested = false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getWarehouseName(warehouseFk) {
|
getWarehouseName(warehouseFk) {
|
||||||
|
|
|
@ -8,7 +8,8 @@ describe('vnItemDescriptor', () => {
|
||||||
id: 1,
|
id: 1,
|
||||||
itemType: {
|
itemType: {
|
||||||
warehouseFk: 1
|
warehouseFk: 1
|
||||||
}
|
},
|
||||||
|
isPhotoRequested: true
|
||||||
};
|
};
|
||||||
const stock = {
|
const stock = {
|
||||||
visible: 1,
|
visible: 1,
|
||||||
|
@ -43,4 +44,17 @@ describe('vnItemDescriptor', () => {
|
||||||
expect(controller.item).toEqual(item);
|
expect(controller.item).toEqual(item);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('onUploadResponse()', () => {
|
||||||
|
it(`should change isPhotoRequested when a new photo is uploaded`, () => {
|
||||||
|
$httpBackend.expectPATCH(`Items/${item.id}`).respond();
|
||||||
|
controller.$rootScope = {imagePath: () => {}};
|
||||||
|
controller.$.photo = {setAttribute: () => {}};
|
||||||
|
controller.item = item;
|
||||||
|
controller.onUploadResponse();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.item.isPhotoRequested).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue