2176 First working version
gitea/salix/pipeline/head This commit has test failures Details

This commit is contained in:
Joan Sanchez 2020-06-08 12:14:27 +02:00
parent 181f2f0148
commit ab1e8fb622
4 changed files with 164 additions and 247 deletions

View File

@ -5,40 +5,6 @@ export default class Contextmenu {
this.element = $element[0];
this.$ = $;
this.$transclude = $transclude;
// this.displayMode = 'relative';
// Foreach element, apply an addEventListener???
/*
document.body.addEventListener('contextmenu', event => {
if (!event.defaultPrevented)
event.preventDefault();
const target = event.target;
const rect = target.getBoundingClientRect();
console.log('ScreenY', event.pageY);
console.log('OffsetY', event.pageX);
const parent = $.contextmenu;
parent.style.top = event.pageY + 'px';
parent.style.left = event.pageX + 'px';
$.menu.show(parent);
}); */
}
$onInit() {
/* const transcludeElement = this.element.querySelector('vn-menu');
const content = angular.element(transcludeElement);
this.$transclude(($clone, $scope) => {
this.$contentScope = $scope;
// $scope.$target = 'hola??';
const list = angular.element('<vn-list></vn-list>');
list.append($clone);
content.append(list);
}, null, 'menu'); */
}
get targets() {
@ -51,103 +17,143 @@ export default class Contextmenu {
if (!value) return;
for (let selector of value) {
const target = document.querySelector(selector);// Find elements
const target = document.querySelector(selector);
if (!target) continue;
target.addEventListener('contextmenu', event => {
this.target = event.target;
if (!event.defaultPrevented)
event.preventDefault();
if (!this.isFilterEnabled()) return;
const parent = this.$.contextmenu;
parent.style.top = event.pageY + 'px';
parent.style.left = event.pageX + 'px';
this.eventTarget = event.target;
/* const menu = this.element.querySelector('vn-menu');
const list = document.createElement('vn-list');
menu.append(list);
const transcludeElement = this.element.querySelector('vn-list');
const content = angular.element(transcludeElement);
console.log(transcludeElement);
this.$transclude(($clone, $scope) => {
this.$contentScope = $scope;
$scope.$target = 'hola??';
console.log($clone);
content.append($clone);
}, null, 'menu'); */
this.$.menu.show(parent);
});
}
}
/* const transcludeElement = this.element.querySelector('vn-list');
const content = angular.element(transcludeElement);
console.log(transcludeElement);
get row() {
if (!this.target) return null;
this.$transclude(($clone, $scope) => {
this.$contentScope = $scope;
$scope.$target = 'hola??';
content.append($clone);
}); */
return this.target.closest('vn-tr, .vn-tr');
}
get rowIndex() {
if (!this.row) return null;
const table = this.row.closest('vn-table, .vn-table');
const tBody = table.querySelector('vn-tbody, .vn-tbody');
const rows = tBody.querySelectorAll('vn-tr, .vn-tr');
return Array.from(rows).findIndex(
rowItem => rowItem == this.row
);
}
get rowData() {
const model = this.model;
const rowData = model.data[this.rowIndex];
return rowData;
}
get cell() {
if (!this.target) return null;
return this.target.closest('vn-td, .vn-td');
}
get cellIndex() {
if (!this.row) return null;
const cells = this.row.querySelectorAll('vn-td, .vn-td');
return Array.from(cells).findIndex(
cellItem => cellItem == this.cell
);
}
get rowHeader() {
if (!this.row) return null;
const table = this.row.closest('vn-table, .vn-table');
const headerCells = table && table.querySelectorAll('vn-thead vn-th');
const headerCell = headerCells && headerCells[this.cellIndex];
return headerCell;
}
/**
* Selected model field name
*
* @return {string}
*/
get fieldName() {
if (!this.rowHeader) return null;
return this.rowHeader.getAttribute('field');
}
/**
* Selected field value
*
* @return {any}
*/
get fieldValue() {
return this.rowData[this.fieldName];
}
/**
* Returns true if filter is not disabled
*
* @return {Boolean}
*/
isFilterEnabled() {
if (!this.rowHeader) return true;
const isEnabled = this.rowHeader.getAttribute('filter-enabled');
return isEnabled != 'false';
}
/**
* Returns true if filter
* by selection is allowed
*
* @return {Boolean}
*/
isFilterAllowed() {
if (!this.target) return false;
const isTableCell = this.target.closest('vn-td, .vn-td');
return isTableCell && this.fieldName;
}
/**
* Filter by current field selection
*/
filterBySelection() {
// const target = $event.target;
const model = this.model;
const target = this.eventTarget;
console.log(target);
const table = target.closest('.vn-table');
const headerCols = table.querySelectorAll('vn-thead vn-th');
const row = target.closest('.vn-tr');
const col = target.closest('vn-td');
const rowIndex = row.getAttribute('data-index');
const columns = Array.from(row.querySelectorAll('vn-td'));
const fieldIndex = columns.findIndex(column => column == col);
const fieldName = headerCols[fieldIndex].getAttribute('field');
const rowData = model.data[rowIndex];
const filter = {where: {}};
filter['where'][fieldName] = rowData[fieldName];
console.log(filter);
filter['where'][this.fieldName] = this.fieldValue;
model.addFilter(filter);
this.model.addFilter(filter);
}
/**
* Exclude by current field selection
*/
excludeSelection() {
const model = this.model;
const target = this.eventTarget;
const table = target.closest('.vn-table');
const headerCols = table.querySelectorAll('vn-thead vn-th');
const row = target.closest('.vn-tr');
const col = target.closest('vn-td');
const rowIndex = row.getAttribute('data-index');
const columns = Array.from(row.querySelectorAll('vn-td'));
const fieldIndex = columns.findIndex(column => column == col);
const fieldName = headerCols[fieldIndex].getAttribute('field');
const rowData = model.data[rowIndex];
const filter = {where: {}};
filter['where'][fieldName] = {neq: rowData[fieldName]};
console.log(filter);
filter['where'][this.fieldName] = {neq: this.fieldValue};
model.addFilter(filter);
this.model.addFilter(filter);
}
/**
* Removes all applied filters
*/
removeFilter() {
this.model.removeFilter();
}

View File

@ -186,84 +186,46 @@ module.exports = Self => {
let stmt;
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.filter');
/* stmt = new ParameterizedSQL(
`CREATE TEMPORARY TABLE tmp.filter
(INDEX (id))
ENGINE = MEMORY
SELECT
t.id,
t.shipped,
t.nickname,
t.refFk,
t.routeFk,
t.warehouseFk,
t.clientFk,
a.provinceFk,
p.name AS province,
w.name AS warehouse,
am.name AS agencyMode,
am.id AS agencyModeFk,
st.name AS state,
wk.lastName AS salesPerson,
ts.stateFk as stateFk,
ts.alertLevel as alertLevel,
ts.code as alertLevelCode,
u.nickname userNickname,
c.salesPersonFk,
z.hour zoneLanding,
HOUR(z.hour) zoneHour,
MINUTE(z.hour) zoneMinute
FROM ticket t
LEFT JOIN zone z ON z.id = t.zoneFk
LEFT JOIN address a ON a.id = t.addressFk
LEFT JOIN province p ON p.id = a.provinceFk
LEFT JOIN warehouse w ON w.id = t.warehouseFk
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
LEFT JOIN state st ON st.id = ts.stateFk
LEFT JOIN client c ON c.id = t.clientFk
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
LEFT JOIN account.user u ON u.id = wk.userFk`); */
stmt = new ParameterizedSQL(
`CREATE TEMPORARY TABLE tmp.filter
(INDEX (id))
ENGINE = MEMORY
SELECT id, shipped, nickname, refFk, routeFk, warehouseFk
(SELECT
t.id,
t.shipped,
t.nickname,
t.refFk,
t.routeFk,
t.warehouseFk,
t.clientFk,
a.provinceFk,
p.name AS province,
w.name AS warehouse,
am.name AS agencyMode,
am.id AS agencyModeFk,
st.name AS state,
wk.lastName AS salesPerson,
ts.stateFk as stateFk,
ts.alertLevel as alertLevel,
ts.code as alertLevelCode,
u.nickname userNickname,
c.salesPersonFk,
z.hour zoneLanding,
HOUR(z.hour) zoneHour,
MINUTE(z.hour) zoneMinute
FROM ticket t
LEFT JOIN zone z ON z.id = t.zoneFk
LEFT JOIN address a ON a.id = t.addressFk
LEFT JOIN province p ON p.id = a.provinceFk
LEFT JOIN warehouse w ON w.id = t.warehouseFk
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
LEFT JOIN state st ON st.id = ts.stateFk
LEFT JOIN client c ON c.id = t.clientFk
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
LEFT JOIN account.user u ON u.id = wk.userFk)`);
SELECT * FROM (
SELECT
t.id,
t.shipped,
CAST(DATE(t.shipped) AS CHAR) AS shippedDate,
t.nickname,
t.refFk,
t.routeFk,
t.warehouseFk,
t.clientFk,
a.provinceFk,
p.name AS province,
w.name AS warehouse,
am.name AS agencyMode,
am.id AS agencyModeFk,
st.name AS state,
wk.lastName AS salesPerson,
ts.stateFk as stateFk,
ts.alertLevel as alertLevel,
ts.code as alertLevelCode,
u.nickname userNickname,
c.salesPersonFk,
z.hour zoneLanding,
HOUR(z.hour) zoneHour,
MINUTE(z.hour) zoneMinute
FROM ticket t
LEFT JOIN zone z ON z.id = t.zoneFk
LEFT JOIN address a ON a.id = t.addressFk
LEFT JOIN province p ON p.id = a.provinceFk
LEFT JOIN warehouse w ON w.id = t.warehouseFk
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
LEFT JOIN state st ON st.id = ts.stateFk
LEFT JOIN client c ON c.id = t.clientFk
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
LEFT JOIN account.user u ON u.id = wk.userFk) t`);
if (args.orderFk) {
stmt.merge({

View File

@ -15,14 +15,14 @@
</vn-th>
<vn-th></vn-th>
<vn-th field="id" number>Id</vn-th>
<vn-th prefix="t" field="salesPersonFk" class="expendable">Salesperson</vn-th>
<vn-th field="shipped">Date</vn-th>
<vn-th field="salesPersonFk" class="expendable">Salesperson</vn-th>
<vn-th field="shippedDate">Date</vn-th>
<vn-th>Hour</vn-th>
<vn-th field="nickname">Alias</vn-th>
<vn-th field="province" class="expendable">Province</vn-th>
<vn-th field="provinceFk" class="expendable">Province</vn-th>
<vn-th field="stateFk" >State</vn-th>
<vn-th field="agencyModeFk">Agency</vn-th>
<vn-th field="warehouse">Warehouse</vn-th>
<vn-th field="warehouseFk">Warehouse</vn-th>
<vn-th field="refFk" class="expendable">Invoice</vn-th>
<vn-th field="zoneHour" shrink>Closure</vn-th>
<vn-th number>Total</vn-th>
@ -153,15 +153,19 @@
</vn-client-balance-create>
<vn-contextmenu vn-id="contextmenu" targets="['vn-data-viewer']" model="model">
<slot-menu>
<vn-item ng-click="$ctrl.filterBySelection({event: $parent.$ctrl.$eventTarget})" translate>Filter by selection</vn-item>
<vn-item ng-click="$ctrl.excludeSelection($event, $parent.$ctrl.eventTarget)" translate>Exclude selection</vn-item>
<vn-item ng-click="$ctrl.removeFilter()" translate>Remove filter</vn-item>
<vn-item ng-click="contextmenu.filterBySelection()" translate style="color:green">Filter by selection 2</vn-item>
<vn-item ng-click="contextmenu.excludeSelection()" translate style="color:green">Exclude selection 2</vn-item>
<vn-item ng-click="contextmenu.removeFilter()" translate style="color:green">Remove filter 2</vn-item>
<!-- <p>Quicklinks</p>
<vn-item>Order DESC</vn-item>
<vn-item>Order ASC</vn-item> -->
<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-click="contextmenu.removeFilter()" >
Remove filter
</vn-item>
</slot-menu>
</vn-contextmenu>

View File

@ -92,61 +92,6 @@ export default class Controller extends Section {
this.selectedTicket = ticket;
this.$.summary.show();
}
filterBySelection(target) {
// const target = $event.target;
const model = this.$.model;
console.log(target);
const table = target.closest('.vn-table');
const headerCols = table.querySelectorAll('vn-thead vn-th');
const row = target.closest('.vn-tr');
const col = target.closest('vn-td');
const rowIndex = row.getAttribute('data-index');
const columns = Array.from(row.querySelectorAll('vn-td'));
const fieldIndex = columns.findIndex(column => column == col);
const fieldName = headerCols[fieldIndex].getAttribute('field');
const rowData = model.data[rowIndex];
const filter = {where: {}};
filter['where'][fieldName] = rowData[fieldName];
console.log(filter);
model.addFilter(filter);
}
excludeSelection($event, target) {
const model = this.$.model;
const table = target.closest('.vn-table');
const headerCols = table.querySelectorAll('vn-thead vn-th');
const row = target.closest('.vn-tr');
const col = target.closest('vn-td');
const rowIndex = row.getAttribute('data-index');
const columns = Array.from(row.querySelectorAll('vn-td'));
const fieldIndex = columns.findIndex(column => column == col);
const fieldName = headerCols[fieldIndex].getAttribute('field');
const rowData = model.data[rowIndex];
const filter = {where: {}};
filter['where'][fieldName] = {neq: rowData[fieldName]};
console.log(filter);
model.addFilter(filter);
}
removeFilter() {
this.$.model.removeFilter();
}
}
ngModule.component('vnTicketIndex', {