7199-devToTest_2316 #2287

Merged
alexm merged 169 commits from 7199-devToTest_2316 into test 2024-04-11 06:25:23 +00:00
5 changed files with 99 additions and 39 deletions
Showing only changes of commit c69a4e1c98 - Show all commits

View File

@ -19,12 +19,12 @@ module.exports = Self => {
}
});
Self.getUrl = async(appName = 'salix') => {
const {url} = await Self.app.models.Url.findOne({
const url = await Self.app.models.Url.findOne({
where: {
appName,
environment: process.env.NODE_ENV || 'development'
}
});
return url;
return url?.url;
};
};

View File

@ -2913,7 +2913,8 @@ INSERT INTO `salix`.`url` (`appName`, `environment`, `url`)
VALUES
('lilium', 'development', 'http://localhost:9000/#/'),
('hedera', 'development', 'http://localhost:9090/'),
('salix', 'development', 'http://localhost:5000/#!/');
('salix', 'development', 'http://localhost:5000/#!/'),
('docuware', 'development', 'http://docuware');
INSERT INTO `vn`.`report` (`id`, `name`, `paperSizeFk`, `method`)
VALUES

View File

@ -1,4 +1,5 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const {mergeFilters, mergeWhere} = require('vn-loopback/util/filter');
module.exports = Self => {
Self.remoteMethodCtx('filter', {
@ -33,28 +34,31 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
// Get ids alloweds
const account = await models.VnUser.findById(userId);
const stmt = new ParameterizedSQL(
`SELECT d.id dmsFk, d.reference, d.description, d.file, d.created, d.hardCopyNumber, d.hasFile
`SELECT d.id, d.id dmsFk
FROM workerDocument wd
JOIN dms d ON d.id = wd.document
JOIN dmsType dt ON dt.id = d.dmsTypeFk
LEFT JOIN account.roleRole rr ON rr.inheritsFrom = dt.readRoleFk AND rr.role = ?
`, [account.roleFk]
);
const oldWhere = filter.where;
const yourOwnDms = {and: [{isReadableByWorker: true}, {worker: userId}]};
const where = {
or: [yourOwnDms, {
role: {
neq: null
}
}]
};
stmt.merge(conn.makeSuffix(mergeWhere(filter.where, where)));
filter.where = {
and: [{
or: [yourOwnDms, {
role: {
neq: null
}
}]
}, oldWhere]};
stmt.merge(conn.makeSuffix(filter));
const workerDms = await conn.executeStmt(stmt);
// Get workerDms alloweds
const dmsIds = await conn.executeStmt(stmt);
const allowedIds = dmsIds.map(dms => dms.id);
const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}});
let workerDms = await models.WorkerDms.find(allowedFilter);
// Get docuware info
const docuware = await models.Docuware.findOne({
@ -63,28 +67,43 @@ module.exports = Self => {
});
const docuwareDmsType = docuware.dmsTypeFk;
let workerDocuware = [];
if (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType))) {
if (!filter.skip && (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType)))) {
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
const docuwareParse = {
'Filename': 'dmsFk',
'Tipo Documento': 'description',
'Stored on': 'created',
'Document ID': 'id'
'Document ID': 'id',
'URL': 'download',
'Stored by': 'name',
'Estado': 'state'
};
workerDocuware =
await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? [];
await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? [];
const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient';
for (document of workerDocuware) {
const docuwareId = document.id;
const defaultData = {
file: 'dw' + document.id + '.png',
isDocuware: true,
hardCopyNumber: null,
hasFile: false,
reference: worker.fi,
dmsFk: 'DW' + document.id
id: docuwareId,
workerFk: id,
dmsFk: docuwareId,
dms: {
id: docuwareId,
file: docuwareId + '.pdf',
isDocuware: true,
hasFile: false,
reference: worker.fi,
dmsFk: docuwareId,
url,
description: document.description + ' - ' + document.state,
download: document.download,
created: document.created,
dmsType: {name: 'Docuware'},
worker: {id: null, user: {name: document.name}},
}
};
document = Object.assign(document, defaultData);
Object.assign(document, defaultData);
}
}
return workerDms.concat(workerDocuware);

View File

@ -2,6 +2,7 @@
vn-id="model"
url="WorkerDms/{{$ctrl.$params.id}}/filter"
link="{worker: $ctrl.$params.id}"
filter="$ctrl.filter"
limit="20"
data="$ctrl.workerDms"
order="dmsFk DESC"
@ -28,37 +29,37 @@
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="document in $ctrl.workerDms">
<vn-td number shrink>{{::document.dmsFk}}</vn-td>
<vn-td number shrink>{{::document.id}}</vn-td>
<vn-td shrink number>
<span class="chip" title="{{::document.hardCopyNumber}}"
<span class="chip" title="{{::document.dms.hardCopyNumber}}"
ng-class="{'message': document.hardCopyNumber}">
{{::document.hardCopyNumber}}
{{::document.dms.hardCopyNumber}}
</span>
</vn-td>
<vn-td expand>
<span title="{{::document.reference}}">
{{::document.reference}}
<span title="{{::document.dms.reference}}">
{{::document.dms.reference}}
</span>
</vn-td>
<vn-td expand>
<span title="{{::document.description}}">
{{::document.description}}
<span title="{{::document.dms.description}}">
{{::document.dms.description}}
</span>
</vn-td>
<vn-td shrink>
<vn-check
ng-model="document.hasFile"
ng-model="document.dms.hasFile"
disabled="true">
</vn-check>
</vn-td>
<vn-td shrink>
<span title="{{'Download file' | translate}}" class="link"
ng-click="$ctrl.downloadFile(document.dmsFk, document.isDocuware)">
{{::document.file}}
ng-click="$ctrl.downloadFile(document.dmsFk, document.dms.isDocuware)">
{{::document.dms.file}}
</span>
</vn-td>
<vn-td shrink-datetime>
{{::document.created | date:'dd/MM/yyyy HH:mm'}}
{{::document.dms.created | date:'dd/MM/yyyy HH:mm'}}
</vn-td>
<vn-td shrink>
<vn-icon-button title="{{'Download file' | translate}}"
@ -66,7 +67,7 @@
ng-click="$ctrl.downloadFile(document.dmsFk, document.isDocuware)">
</vn-icon-button>
</vn-td>
<vn-td expand ng-if="::!document.isDocuware">
<vn-td expand ng-if="::!document.dms.isDocuware">
<vn-icon-button ui-sref="worker.card.dms.edit({dmsId: {{::document.dmsFk}}})"
icon="edit"
title="{{'Edit file' | translate}}">
@ -78,7 +79,7 @@
tabindex="-1">
</vn-icon-button>
</vn-td>
<vn-td expand ng-if="::document.isDocuware">
<vn-td expand ng-if="::document.dms.isDocuware">
<vn-icon-button
icon="open_in_new"
ng-click="$ctrl.openDocuware()"

View File

@ -6,6 +6,45 @@ class Controller extends Component {
constructor($element, $, vnFile) {
super($element, $);
this.vnFile = vnFile;
this.filter = {
include: {
relation: 'dms',
scope: {
fields: [
'dmsTypeFk',
'reference',
'hardCopyNumber',
'workerFk',
'description',
'hasFile',
'file',
'created',
'companyFk',
'warehouseFk',
],
include: [
{
relation: 'dmsType',
scope: {
fields: ['name'],
},
},
{
relation: 'worker',
scope: {
fields: ['id'],
include: {
relation: 'user',
scope: {
fields: ['name'],
},
},
},
},
],
},
},
};
}
deleteDms(index) {