Merge pull request '2805-fix(entry_latestBuys): save chekeds when crudModel load more data' (#1045) from 2805-entry_latestBuy_saveChekeds into dev
Reviewed-on: #1045 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
fcce73086e
|
@ -4,6 +4,7 @@
|
|||
order="itemFk DESC"
|
||||
limit="20"
|
||||
data="$ctrl.buys"
|
||||
on-data-change="$ctrl.reCheck()"
|
||||
auto-load="true">
|
||||
</vn-crud-model>
|
||||
<vn-portal slot="topbar">
|
||||
|
@ -21,7 +22,7 @@
|
|||
<smart-table
|
||||
model="model"
|
||||
view-config-id="latestBuys"
|
||||
options="$ctrl.smartTableOptions"
|
||||
options="$ctrl.smartTableOptions"
|
||||
expr-builder="$ctrl.exprBuilder(param, value)">
|
||||
<slot-table>
|
||||
<table>
|
||||
|
@ -123,17 +124,18 @@
|
|||
<tbody>
|
||||
<tr ng-repeat="buy in $ctrl.buys"
|
||||
vn-anchor="::{
|
||||
state: 'entry.card.buy.index',
|
||||
state: 'entry.card.buy.index',
|
||||
params: {id: {{::buy.entryFk}}}
|
||||
}">
|
||||
<td>
|
||||
<vn-check
|
||||
<vn-check
|
||||
ng-model="buy.checked"
|
||||
on-change="$ctrl.saveChecked(buy.id)"
|
||||
vn-click-stop>
|
||||
</vn-check>
|
||||
</td>
|
||||
<td >
|
||||
<img
|
||||
<img
|
||||
ng-src="{{::$root.imagePath('catalog', '50x50', buy.itemFk)}}"
|
||||
zoom-image="{{::$root.imagePath('catalog', '1600x900', buy.itemFk)}}"
|
||||
vn-click-stop
|
||||
|
@ -147,12 +149,12 @@
|
|||
</span>
|
||||
</td>
|
||||
<td number>
|
||||
<vn-chip class="transparent" translate-attr="buy.groupingMode == 2 ? {title: 'Minimun amount'} : {title: 'Packing'}" ng-class="{'message': buy.groupingMode == 2}">
|
||||
<vn-chip class="transparent" translate-attr="buy.groupingMode == 2 ? {title: 'Minimun amount'} : {title: 'Packing'}" ng-class="{'message': buy.groupingMode == 2}">
|
||||
<span>{{::buy.packing | dashIfEmpty}}</span>
|
||||
</vn-chip>
|
||||
</td>
|
||||
<td number>
|
||||
<vn-chip class="transparent" translate-attr="buy.groupingMode == 1 ? {title: 'Minimun amount'} : {title: 'Grouping'}" ng-class="{'message': buy.groupingMode == 1}">
|
||||
<vn-chip class="transparent" translate-attr="buy.groupingMode == 1 ? {title: 'Minimun amount'} : {title: 'Grouping'}" ng-class="{'message': buy.groupingMode == 1}">
|
||||
<span>{{::buy.grouping | dashIfEmpty}}</span>
|
||||
</vn-chip>
|
||||
</td>
|
||||
|
@ -186,7 +188,7 @@
|
|||
<vn-check
|
||||
disabled="true"
|
||||
ng-model="::buy.isActive">
|
||||
</vn-check>
|
||||
</vn-check>
|
||||
</td>
|
||||
<td>{{::buy.family}}</td>
|
||||
<td>
|
||||
|
@ -204,7 +206,7 @@
|
|||
<vn-check
|
||||
disabled="true"
|
||||
ng-model="::buy.isIgnored">
|
||||
</vn-check>
|
||||
</vn-check>
|
||||
</td>
|
||||
<td number>{{::buy.price2 | currency: 'EUR':2}}</td>
|
||||
<td number>{{::buy.price3 | currency: 'EUR':2}}</td>
|
||||
|
@ -231,7 +233,7 @@
|
|||
</vn-button>
|
||||
</vn-vertical>
|
||||
</div>
|
||||
<vn-dialog class="edit"
|
||||
<vn-dialog class="edit"
|
||||
vn-id="edit"
|
||||
on-accept="$ctrl.onEditAccept()"
|
||||
on-close="$ctrl.editedColumn = null">
|
||||
|
|
|
@ -7,6 +7,7 @@ export default class Controller extends Section {
|
|||
super($element, $);
|
||||
this.editedColumn;
|
||||
this.checkAll = false;
|
||||
this.checkedBuys = [];
|
||||
|
||||
this.smartTableOptions = {
|
||||
activeButtons: {
|
||||
|
@ -139,6 +140,7 @@ export default class Controller extends Section {
|
|||
|
||||
uncheck() {
|
||||
this.checkAll = false;
|
||||
this.checkedBuys = [];
|
||||
}
|
||||
|
||||
get totalChecked() {
|
||||
|
@ -148,6 +150,23 @@ export default class Controller extends Section {
|
|||
return this.checked.length;
|
||||
}
|
||||
|
||||
saveChecked(buyId) {
|
||||
const index = this.checkedBuys.indexOf(buyId);
|
||||
if (index !== -1)
|
||||
return this.checkedBuys.splice(index, 1);
|
||||
return this.checkedBuys.push(buyId);
|
||||
}
|
||||
|
||||
reCheck() {
|
||||
if (!this.$.model.data) return;
|
||||
if (!this.checkedBuys.length) return;
|
||||
|
||||
this.$.model.data.forEach(buy => {
|
||||
if (this.checkedBuys.includes(buy.id))
|
||||
buy.checked = true;
|
||||
});
|
||||
}
|
||||
|
||||
onEditAccept() {
|
||||
const rowsToEdit = [];
|
||||
for (let row of this.checked)
|
||||
|
|
|
@ -57,5 +57,44 @@ describe('Entry', () => {
|
|||
expect(result.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reCheck()', () => {
|
||||
it(`should recheck buys`, () => {
|
||||
controller.$.model.data = [
|
||||
{checked: false, id: 1},
|
||||
{checked: false, id: 2},
|
||||
{checked: false, id: 3},
|
||||
{checked: false, id: 4},
|
||||
];
|
||||
controller.checkedBuys = [1, 2];
|
||||
|
||||
controller.reCheck();
|
||||
|
||||
expect(controller.$.model.data[0].checked).toEqual(true);
|
||||
expect(controller.$.model.data[1].checked).toEqual(true);
|
||||
expect(controller.$.model.data[2].checked).toEqual(false);
|
||||
expect(controller.$.model.data[3].checked).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('saveChecked()', () => {
|
||||
it(`should check buy`, () => {
|
||||
const buyCheck = 3;
|
||||
controller.checkedBuys = [1, 2];
|
||||
|
||||
controller.saveChecked(buyCheck);
|
||||
|
||||
expect(controller.checkedBuys[2]).toEqual(buyCheck);
|
||||
});
|
||||
|
||||
it(`should uncheck buy`, () => {
|
||||
const buyUncheck = 3;
|
||||
controller.checkedBuys = [1, 2, 3];
|
||||
|
||||
controller.saveChecked(buyUncheck);
|
||||
|
||||
expect(controller.checkedBuys[2]).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue