This commit is contained in:
Javi Gallego 2019-01-28 12:09:29 +01:00
commit 99d0d73136
5 changed files with 31 additions and 8 deletions

View File

@ -1,5 +1,5 @@
<ul ng-if="$ctrl.items">
<li ng-repeat="item in $ctrl.items" ng-class="{'selected' : item.selected, 'included': item.included}">
<li ng-repeat="item in $ctrl.items" ng-class="{'selected' : item.selected && !item.excluded, 'included': item.included}">
<vn-horizontal>
<vn-auto class="actions">
<vn-icon icon="keyboard_arrow_up" ng-if="item.childs.length"
@ -11,7 +11,7 @@
</vn-auto>
<vn-one class="description">
<vn-horizontal>
<vn-check vn-auto field="item.selected"
<vn-check vn-auto field="item.selected && !item.excluded"
on-change="$ctrl.select(item)">
</vn-check>
<vn-one ng-dblclick="$ctrl.toggle(item)" class="text unselectable">

View File

@ -74,7 +74,7 @@ export default class Treeview extends Component {
for (let i = 0; i < childs.length; i++) {
childs[i].included = false;
if ((node.selected || node.included && this.hasCheckedParents(childs[i])) && !childs[i].selected)
if (((node.selected || node.included && this.hasCheckedParents(childs[i])) && !childs[i].selected) && !node.excluded)
childs[i].included = true;
this.repaintDesc(childs[i]);
@ -107,6 +107,13 @@ export default class Treeview extends Component {
}
onSelection(item) {
let canBeExcluded = this.hasCheckedChilds(item) || this.hasCheckedParents(item);
if (!item.selected && item.included && canBeExcluded)
item.excluded = true;
else
item.excluded = false;
item.selected = !item.selected;
if (item.selected && item.included)

View File

@ -23,13 +23,30 @@ module.exports = Self => {
});
Self.toggleIsIncluded = async(zoneFk, geoFk) => {
const models = Self.app.models;
const geo = await models.ZoneTreeview.findById(geoFk);
const isIncluded = await Self.findOne({
where: {zoneFk, geoFk}
});
const hasCheckedParents = await Self.rawSql(
`SELECT id
FROM vn.zoneTreeview zt
JOIN vn.zoneIncluded zi ON zi.geoFk = zt.id
WHERE zt.lft < ? AND zt.rgt > ?`, [geo.lft, geo.rgt]
);
const hasCheckedChilds = await Self.rawSql(
`SELECT id
FROM vn.zoneTreeview zt
JOIN vn.zoneIncluded zi ON zi.geoFk = zt.id
WHERE zt.lft > ? AND zt.rgt < ?`, [geo.lft, geo.rgt]
);
const isExcluded = hasCheckedParents.length || hasCheckedChilds.length;
if (isIncluded)
return Self.destroyAll({zoneFk, geoFk});
else
return Self.upsert({zoneFk, geoFk});
return Self.upsert({zoneFk, geoFk, isIncluded: isExcluded});
};
};

View File

@ -78,7 +78,8 @@ module.exports = Self => {
pt.depth,
pt.sons,
ti.id IS NOT NULL hasCheckedChilds,
zi.geoFk IS NOT NULL AS selected
zi.geoFk IS NOT NULL AS selected,
zi.isIncluded AS excluded
FROM zoneTreeview pt
LEFT JOIN vn.zoneIncluded zi
ON zi.geoFk = pt.id AND zi.zoneFk = ?

View File

@ -1,8 +1,6 @@
<vn-card class="summary">
<h5>{{$ctrl.summary.name}}</h5>
<vn-vertical pad-medium>
<vn-auto>
<h5 text-center pad-small-v class="title">{{$ctrl.summary.name}}</h5>
</vn-auto>
<vn-horizontal pad-medium>
<vn-one>
<vn-label-value label="Id"