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">
|
||||
|
@ -129,6 +130,7 @@
|
|||
<td>
|
||||
<vn-check
|
||||
ng-model="buy.checked"
|
||||
on-change="$ctrl.saveChecked(buy.id)"
|
||||
vn-click-stop>
|
||||
</vn-check>
|
||||
</td>
|
||||
|
|
|
@ -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