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') => { Self.getUrl = async(appName = 'salix') => {
const {url} = await Self.app.models.Url.findOne({ const url = await Self.app.models.Url.findOne({
where: { where: {
appName, appName,
environment: process.env.NODE_ENV || 'development' 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 VALUES
('lilium', 'development', 'http://localhost:9000/#/'), ('lilium', 'development', 'http://localhost:9000/#/'),
('hedera', 'development', 'http://localhost:9090/'), ('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`) INSERT INTO `vn`.`report` (`id`, `name`, `paperSizeFk`, `method`)
VALUES VALUES

View File

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

View File

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

View File

@ -6,6 +6,45 @@ class Controller extends Component {
constructor($element, $, vnFile) { constructor($element, $, vnFile) {
super($element, $); super($element, $);
this.vnFile = vnFile; 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) { deleteDms(index) {