refs #2051 perf: uploadFile after review
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
7b9e3b0985
commit
06bae44824
|
@ -54,7 +54,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, id, options) => {
|
Self.uploadFile = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
const {Dms, ClaimDms} = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
|
@ -66,56 +66,14 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const promises = [];
|
|
||||||
// const TempContainer = models.TempContainer;
|
|
||||||
// const ClaimContainer = models.ClaimContainer;
|
|
||||||
// const fileOptions = {};
|
|
||||||
// const args = ctx.args;
|
|
||||||
|
|
||||||
// let srcFile;
|
|
||||||
try {
|
try {
|
||||||
myOptions.model = 'ClaimDms';
|
const uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||||
myOptions.create = {claimFk: id};
|
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
|
||||||
|
|
||||||
// const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions);
|
const promises = uploadedFiles.map(dms => ClaimDms.create({
|
||||||
// if (!hasWriteRole)
|
claimFk: id,
|
||||||
// throw new UserError(`You don't have enough privileges`);
|
dmsFk: dms.id
|
||||||
|
}, myOptions));
|
||||||
// // Upload file to temporary path
|
await Promise.all(promises);
|
||||||
// const tempContainer = await TempContainer.container('dms');
|
|
||||||
// const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions);
|
|
||||||
// const files = Object.values(uploaded.files).map(file => {
|
|
||||||
// return file[0];
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const addedDms = [];
|
|
||||||
// for (const uploadedFile of files) {
|
|
||||||
// const newDms = await createDms(ctx, uploadedFile, myOptions);
|
|
||||||
// const pathHash = ClaimContainer.getHash(newDms.id);
|
|
||||||
|
|
||||||
// const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name);
|
|
||||||
// srcFile = path.join(file.client.root, file.container, file.name);
|
|
||||||
|
|
||||||
// const claimContainer = await ClaimContainer.container(pathHash);
|
|
||||||
// const dstFile = path.join(claimContainer.client.root, pathHash, newDms.file);
|
|
||||||
|
|
||||||
// await fs.move(srcFile, dstFile, {
|
|
||||||
// overwrite: true
|
|
||||||
// });
|
|
||||||
|
|
||||||
// addedDms.push(newDms);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// addedDms.forEach(dms => {
|
|
||||||
// const newClaimDms = models.ClaimDms.create({
|
|
||||||
// claimFk: id,
|
|
||||||
// dmsFk: dms.id
|
|
||||||
// }, myOptions);
|
|
||||||
|
|
||||||
// promises.push(newClaimDms);
|
|
||||||
// });
|
|
||||||
// const resolvedPromises = await Promise.all(promises);
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, id, options) => {
|
Self.uploadFile = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
const {Dms, ClientDms} = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
|
@ -67,21 +67,16 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const promises = [];
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
myOptions.model = 'ClientDms';
|
const uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||||
myOptions.create = {clientFk: id};
|
const promises = uploadedFiles.map(dms =>
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
ClientDms.create({
|
||||||
// uploadedFiles.forEach(dms => {
|
clientFk: id,
|
||||||
// const newClientDms = models.ClientDms.create({
|
dmsFk: dms.id
|
||||||
// clientFk: id,
|
}, myOptions)
|
||||||
// dmsFk: dms.id
|
|
||||||
// }, myOptions);
|
|
||||||
|
|
||||||
// promises.push(newClientDms);
|
);
|
||||||
// });
|
await Promise.all(promises);
|
||||||
// const resolvedPromises = await Promise.all(promises);
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, id, options) => {
|
Self.uploadFile = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
const {Dms, TicketDms} = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
|
@ -59,21 +59,15 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const promises = [];
|
|
||||||
try {
|
try {
|
||||||
myOptions.model = 'TicketDms';
|
const uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||||
myOptions.create = {ticketFk: id};
|
const promises = uploadedFiles.map(dms => TicketDms.create({
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
ticketFk: id,
|
||||||
/* uploadedFiles.forEach(dms => {
|
dmsFk: dms.id
|
||||||
const newTicketDms = models.TicketDms.create({
|
}, myOptions));
|
||||||
ticketFk: id,
|
|
||||||
dmsFk: dms.id
|
await Promise.all(promises);
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
promises.push(newTicketDms);
|
|
||||||
});
|
|
||||||
const resolvedPromises = await Promise.all(promises);
|
|
||||||
*/
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return uploadedFiles;
|
return uploadedFiles;
|
||||||
|
|
|
@ -30,9 +30,15 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const WorkerDms = await Self.findById(id, null, myOptions);
|
// const dms = await Self.app.models.Dms.findById(id, null, myOptions);
|
||||||
|
const WorkerDms = await Self.findOne({
|
||||||
|
where: {document: id}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
const targetDms = await Self.app.models.Dms.removeFile(ctx, WorkerDms.dmsFk, myOptions);
|
// const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions);
|
||||||
|
// const WorkerDms = await Self.findById(+targetDms.reference, null, myOptions);
|
||||||
|
|
||||||
|
const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions);
|
||||||
|
|
||||||
if (!targetDms || !WorkerDms)
|
if (!targetDms || !WorkerDms)
|
||||||
throw new UserError('Try again');
|
throw new UserError('Try again');
|
||||||
|
|
|
@ -47,10 +47,9 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, id) => {
|
Self.uploadFile = async(ctx, id) => {
|
||||||
const models = Self.app.models;
|
const {Dms, WorkerDms} = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
// const promises = [];
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -61,20 +60,14 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
myOptions.model = 'WorkerDms';
|
const uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||||
myOptions.create = {workerFk: id};
|
const promises = uploadedFiles.map(dms =>
|
||||||
|
WorkerDms.create({
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
|
||||||
/* uploadedFiles.forEach(dms => {
|
|
||||||
const newWorkerDms = models.WorkerDms.create({
|
|
||||||
workerFk: id,
|
workerFk: id,
|
||||||
dmsFk: dms.id
|
dmsFk: dms.id
|
||||||
}, options);
|
}, myOptions));
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
promises.push(newWorkerDms);
|
|
||||||
});
|
|
||||||
const resolvedPromises = await Promise.all(promises);
|
|
||||||
*/
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return uploadedFiles;
|
return uploadedFiles;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
import SectionDms from 'salix/components/section-dms';
|
import Section from 'salix/components/section';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller extends SectionDms {
|
class Controller extends Section {
|
||||||
get worker() {
|
get worker() {
|
||||||
return this._worker;
|
return this._worker;
|
||||||
}
|
}
|
||||||
|
@ -11,29 +11,39 @@ class Controller extends SectionDms {
|
||||||
this._worker = value;
|
this._worker = value;
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
this.getDms(this.$params.dmsId).then(handleDefaultParams);
|
this.setDefaultParams();
|
||||||
|
this.getAllowedContentTypes();
|
||||||
this.getAllowedContentTypes().then(data => this.allowedContentTypes = data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAllowedContentTypes() {
|
||||||
|
this.$http.get('DmsContainers/allowedContentTypes').then(res => {
|
||||||
|
const contentTypes = res.data.join(', ');
|
||||||
|
this.allowedContentTypes = contentTypes;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
get contentTypesInfo() {
|
get contentTypesInfo() {
|
||||||
return this.$t('ContentTypesInfo', {
|
return this.$t('ContentTypesInfo', {
|
||||||
allowedContentTypes: this.allowedContentTypes
|
allowedContentTypes: this.allowedContentTypes
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDefaultParams({data: dms}) {
|
setDefaultParams() {
|
||||||
this.dms = {
|
const path = `Dms/${this.$params.dmsId}`;
|
||||||
reference: dms.reference,
|
this.$http.get(path).then(res => {
|
||||||
warehouseId: dms.warehouseFk,
|
const dms = res.data && res.data;
|
||||||
companyId: dms.companyFk,
|
this.dms = {
|
||||||
dmsTypeId: dms.dmsTypeFk,
|
reference: dms.reference,
|
||||||
description: dms.description,
|
warehouseId: dms.warehouseFk,
|
||||||
hasFile: dms.hasFile,
|
companyId: dms.companyFk,
|
||||||
hasFileAttached: false,
|
dmsTypeId: dms.dmsTypeFk,
|
||||||
files: []
|
description: dms.description,
|
||||||
};
|
hasFile: dms.hasFile,
|
||||||
|
hasFileAttached: false,
|
||||||
|
files: []
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
|
|
Loading…
Reference in New Issue