feat(entry_latest-buys): add multi-check-dummy
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-04-12 14:40:25 +02:00
parent 73ee790f8d
commit 8e87ab62a8
8 changed files with 91 additions and 10 deletions

View File

@ -0,0 +1 @@
SelectAllRows: Select the {{rows}} row(s)

View File

@ -0,0 +1,3 @@
SelectAllRows: Seleccionar las {{rows}} fila(s)
All: Se han seleccionado
row(s) have been selected.: fila(s).

View File

@ -2,4 +2,23 @@
ng-model="$ctrl.checked" ng-model="$ctrl.checked"
indeterminate="$ctrl.isIndeterminate" indeterminate="$ctrl.isIndeterminate"
translate-attr="{title: 'Check all'}"> translate-attr="{title: 'Check all'}">
</vn-check> </vn-check>
<vn-icon-button
class="vn-pl-none"
ng-if="$ctrl.checked && $ctrl.checkDummy"
icon="expand_more"
vn-popover="menu"
ng-click="$ctrl.countRows()">
</vn-icon-button>
<vn-menu vn-id="menu">
<vn-list ng-click="$ctrl.checkDummy()">
<span translate>All</span>
<span class="bold">
{{$ctrl.rows}}
</span>
<span translate>row(s) have been selected.</span>
<span class="bold link">
{{$ctrl.AllRowsCount}}
</span>
</vn-list>
</vn-menu>

View File

@ -138,6 +138,27 @@ export default class MultiCheck extends FormInput {
}); });
} }
countRows() {
if (!this.model || !this.model.data) return;
const data = this.model.data;
const params = {
filter: {
where: this.model.userParams,
limit: null
}
};
this.$http.get(this.model.url, {params})
.then(res => {
this.AllRows = res.data;
this.AllRowsCount = this.$t('SelectAllRows', {
rows: res.data.length
});
});
this.rows = data.length;
this.checkedDummy = data.length;
}
/** /**
* Toggles checked property on * Toggles checked property on
* all instances * all instances
@ -158,7 +179,9 @@ ngModule.vnComponent('vnMultiCheck', {
checkField: '@?', checkField: '@?',
checkAll: '=?', checkAll: '=?',
checked: '=?', checked: '=?',
disabled: '<?' disabled: '<?',
checkDummy: '<?',
checkedDummy: '=?'
} }
}); });

View File

@ -1,5 +1,17 @@
@import "variables";
vn-multi-check { vn-multi-check {
.vn-check { .vn-check {
margin-bottom: 12px margin-bottom: 12px
} }
vn-list{
padding: 50px;
}
vn-menu{
padding: 50px;
}
}
.bold{
font-weight: bold;
} }

View File

@ -19,6 +19,11 @@ module.exports = Self => {
type: ['Object'], type: ['Object'],
required: true, required: true,
description: `the buys which will be modified` description: `the buys which will be modified`
},
{
arg: 'filter',
type: ['object'],
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
}], }],
returns: { returns: {
type: 'Object', type: 'Object',
@ -30,8 +35,9 @@ module.exports = Self => {
} }
}); });
Self.editLatestBuys = async(field, newValue, lines, options) => { Self.editLatestBuys = async(field, newValue, lines, filter, options) => {
let tx; let tx;
console.log(filter);
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
@ -64,8 +70,16 @@ module.exports = Self => {
const models = Self.app.models; const models = Self.app.models;
const model = models[modelName]; const model = models[modelName];
try { try {
let result;
console.log(filter);
if (filter) {
result = await model.upsertWithWhere(filter, value, myOptions);
if (tx) await tx.commit();
return result;
}
const promises = []; const promises = [];
const targets = lines.map(line => { const targets = lines.map(line => {
@ -74,11 +88,10 @@ module.exports = Self => {
const value = {}; const value = {};
value[field] = newValue; value[field] = newValue;
for (let target of targets) for (let target of targets)
promises.push(model.upsertWithWhere({id: target}, value, myOptions)); promises.push(model.upsertWithWhere({id: target}, value, myOptions));
const result = await Promise.all(promises); result = await Promise.all(promises);
if (tx) await tx.commit(); if (tx) await tx.commit();

View File

@ -31,7 +31,9 @@
<vn-multi-check <vn-multi-check
checked="$ctrl.checkAll" checked="$ctrl.checkAll"
model="model" model="model"
check-field="$checked"> check-field="$checked"
check-dummy="$ctrl.checkDummy"
checked-dummy="$ctrl.checkedDummy">
</vn-multi-check> </vn-multi-check>
</th> </th>
<th translate>Picture</th> <th translate>Picture</th>

View File

@ -89,11 +89,13 @@ export default class Controller extends Section {
get checked() { get checked() {
const buys = this.$.model.data || []; const buys = this.$.model.data || [];
const checkedBuys = []; let checkedBuys = [];
for (let buy of buys) { for (let buy of buys) {
if (buy.$checked) if (buy.$checked)
checkedBuys.push(buy); checkedBuys.push(buy);
} }
if (this.checkedDummy)
checkedBuys = this.checkedDummy;
return checkedBuys; return checkedBuys;
} }
@ -149,11 +151,12 @@ export default class Controller extends Section {
const rowsToEdit = []; const rowsToEdit = [];
for (let row of this.checked) for (let row of this.checked)
rowsToEdit.push({id: row.id, itemFk: row.itemFk}); rowsToEdit.push({id: row.id, itemFk: row.itemFk});
console.log(this.editFilter);
const data = { const data = {
field: this.editedColumn.field, field: this.editedColumn.field,
newValue: this.editedColumn.newValue, newValue: this.editedColumn.newValue,
lines: rowsToEdit lines: rowsToEdit,
filter: this.editFilter
}; };
return this.$http.post('Buys/editLatestBuys', data) return this.$http.post('Buys/editLatestBuys', data)
@ -162,6 +165,11 @@ export default class Controller extends Section {
this.$.model.refresh(); this.$.model.refresh();
}); });
} }
checkDummy() {
console.log('editFilter', this.model.userParams);
this.editFilter = this.model.userParams;
}
} }
ngModule.component('vnEntryLatestBuys', { ngModule.component('vnEntryLatestBuys', {