Merge pull request '3683-feat(monito_clients): smart-table and filter by date' (#904) from 3683-monitor_clients into dev
gitea/salix/pipeline/head Build queued... Details

Reviewed-on: #904
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2022-03-23 11:24:51 +00:00
commit f74c80cf21
3 changed files with 147 additions and 84 deletions

View File

@ -40,7 +40,8 @@ module.exports = Self => {
IFNULL(sc.workerSubstitute, c.salesPersonFk) AS salesPersonFk, IFNULL(sc.workerSubstitute, c.salesPersonFk) AS salesPersonFk,
c.id AS clientFk, c.id AS clientFk,
c.name AS clientName, c.name AS clientName,
s.lastUpdate AS dated, TIME(v.stamp) AS hour,
DATE(v.stamp) AS dated,
wtc.workerFk wtc.workerFk
FROM hedera.userSession s FROM hedera.userSession s
JOIN hedera.visitUser v ON v.id = s.userVisitFk JOIN hedera.visitUser v ON v.id = s.userVisitFk

View File

@ -2,7 +2,8 @@
vn-id="model" vn-id="model"
url="SalesMonitors/clientsFilter" url="SalesMonitors/clientsFilter"
limit="6" limit="6"
order="dated DESC" filter="$ctrl.filter"
order="dated DESC, hour DESC"
auto-load="true"> auto-load="true">
</vn-crud-model> </vn-crud-model>
<vn-horizontal class="header"> <vn-horizontal class="header">
@ -15,87 +16,85 @@
vn-tooltip="Minimize/Maximize" vn-tooltip="Minimize/Maximize"
ng-click="$ctrl.main.toggle()"> ng-click="$ctrl.main.toggle()">
</vn-icon> </vn-icon>
<vn-icon
icon="refresh"
vn-tooltip="Refresh"
ng-click="model.refresh()">
</vn-icon>
</vn-none> </vn-none>
</vn-horizontal> </vn-horizontal>
<vn-card vn-id="card"> <vn-card vn-id="card">
<vn-table model="model" class="scrollable sm"> <smart-table
<vn-thead> model="model"
<vn-tr> options="$ctrl.smartTableOptions"
<vn-th field="dated">Hour</vn-th> expr-builder="$ctrl.exprBuilder(param, value)"
<vn-th field="salesPersonFk" class="expendable">Salesperson</vn-th> class="scrollable sm">
<vn-th field="clientFk">Client</vn-th> <slot-actions>
</vn-tr> <vn-horizontal>
</vn-thead> <vn-date-picker
<vn-tbody> class="vn-pa-xs"
<vn-tr ng-repeat="visit in model.data"> label="From"
<vn-td shrink-date> ng-model="$ctrl.dateFrom"
<span class="chip"> on-change="$ctrl.addFilterDate()">
{{::visit.dated | date: 'HH:mm'}} </vn-date-picker>
</span> <vn-date-picker
</vn-td> class="vn-pa-xs"
<vn-td class="shrink expendable"> label="To"
<span ng-model="$ctrl.dateTo"
title="{{::visit.salesPerson}}" on-change="$ctrl.addFilterDate()">
vn-click-stop="workerDescriptor.show($event, visit.salesPersonFk)" </vn-date-picker>
class="link"> </vn-horizontal>
{{::visit.salesPerson | dashIfEmpty}} </slot-actions>
</span> <slot-table>
</vn-td> <table>
<vn-td> <thead>
<span <tr>
title="{{::visit.clientName}}" <th field="dated">
vn-click-stop="clientDescriptor.show($event, visit.clientFk)" <span translate>Date</span>
class="link"> </th>
{{::visit.clientName}} <th field="hour">
</span> <span translate>Hour</span>
</vn-td> </th>
</vn-tr> <th field="salesPersonFk" class="expendable">
</vn-tbody> <span translate>Salesperson</span>
</vn-table> </th>
<vn-pagination <th field="clientFk">
model="model" <span translate>Client</span>
class="vn-pt-xs" </th>
scroll-selector="vn-monitor-sales-clients vn-table" </tr>
scroll-offset="100"> </thead>
</vn-pagination> <tbody>
<tr ng-repeat="visit in model.data">
<td shrink-date>
<span class="chip">
{{::visit.dated | date:'dd/MM/yy'}}
</span>
</td>
<td shrink-date>
<span class="chip">
{{::visit.hour | date: 'HH:mm'}}
</span>
</td>
<td class="shrink expendable">
<span
title="{{::visit.salesPerson}}"
vn-click-stop="workerDescriptor.show($event, visit.salesPersonFk)"
class="link">
{{::visit.salesPerson | dashIfEmpty}}
</span>
</td>
<td>
<span
title="{{::visit.clientName}}"
vn-click-stop="clientDescriptor.show($event, visit.clientFk)"
class="link">
{{::visit.clientName}}
</span>
</td>
</tr>
</tbody>
<table>
<slot-table>
</smart-table>
</vn-card> </vn-card>
<vn-worker-descriptor-popover <vn-worker-descriptor-popover
vn-id="workerDescriptor"> vn-id="workerDescriptor">
</vn-worker-descriptor-popover> </vn-worker-descriptor-popover>
<vn-client-descriptor-popover <vn-client-descriptor-popover
vn-id="clientDescriptor"> vn-id="clientDescriptor">
</vn-client-descriptor-popover> </vn-client-descriptor-popover>
<vn-contextmenu vn-id="contextmenu" targets="['vn-monitor-sales-clients vn-table']" model="model"
expr-builder="$ctrl.exprBuilder(param, value)">
<slot-menu>
<vn-item translate
ng-if="contextmenu.isFilterAllowed()"
ng-click="contextmenu.filterBySelection()">
Filter by selection
</vn-item>
<vn-item translate
ng-if="contextmenu.isFilterAllowed()"
ng-click="contextmenu.excludeSelection()">
Exclude selection
</vn-item>
<vn-item translate
ng-if="contextmenu.isFilterAllowed()"
ng-click="contextmenu.removeFilter()">
Remove filter
</vn-item>
<vn-item translate
ng-click="contextmenu.removeAllFilters()">
Remove all filters
</vn-item>
<vn-item translate
ng-if="contextmenu.isActionAllowed()"
ng-click="contextmenu.copyValue()">
Copy value
</vn-item>
</slot-menu>
</vn-contextmenu>

View File

@ -2,26 +2,89 @@ import ngModule from '../../module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
export default class Controller extends Section { export default class Controller extends Section {
constructor($element, $) {
super($element, $);
const date = new Date();
this.dateFrom = date;
this.dateTo = date;
this.filter = {
where: {
'v.stamp': {
between: this.dateRange()
}
}
};
this.smartTableOptions = {
activeButtons: {
search: true
},
columns: [
{
field: 'clientFk',
autocomplete: {
url: 'Clients',
showField: 'name',
valueField: 'id'
}
},
{
field: 'salesPersonFk',
autocomplete: {
url: 'Workers/activeWithInheritedRole',
where: `{role: 'salesPerson'}`,
searchFunction: '{firstName: $search}',
showField: 'nickname',
valueField: 'id',
}
},
{
field: 'dated',
searchable: false
},
{
field: 'hour',
searchable: false
}
]
};
}
exprBuilder(param, value) { exprBuilder(param, value) {
switch (param) { switch (param) {
case 'dated':
return {'s.lastUpdate': {
between: this.dateRange(value)}
};
case 'clientFk': case 'clientFk':
return {[`c.id`]: value};
case 'salesPersonFk': case 'salesPersonFk':
return {[`c.${param}`]: value}; return {[`c.${param}`]: value};
} }
} }
dateRange(value) { dateRange() {
const minHour = new Date(value); let from = this.dateFrom;
let to = this.dateTo;
if (!from)
from = new Date();
if (!to)
to = new Date();
const minHour = new Date(from);
minHour.setHours(0, 0, 0, 0); minHour.setHours(0, 0, 0, 0);
const maxHour = new Date(value); const maxHour = new Date(to);
maxHour.setHours(23, 59, 59, 59); maxHour.setHours(23, 59, 59, 59);
return [minHour, maxHour]; return [minHour, maxHour];
} }
addFilterDate() {
this.$.model.filter = {
where: {
'v.stamp': {
between: this.dateRange()
}
}
};
this.$.model.refresh();
}
} }
ngModule.vnComponent('vnMonitorSalesClients', { ngModule.vnComponent('vnMonitorSalesClients', {