treeview refactor
gitea/salix/1625-worker_department_treeview This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-10-02 09:54:52 +02:00
parent 183d770483
commit 9473636b5b
10 changed files with 133 additions and 95 deletions

View File

@ -70,4 +70,14 @@ ALTER TABLE `vn2008`.`department`
CHANGE COLUMN `lft` `lft` INT(11) NULL , CHANGE COLUMN `lft` `lft` INT(11) NULL ,
CHANGE COLUMN `rgt` `rgt` INT(11) NULL ; CHANGE COLUMN `rgt` `rgt` INT(11) NULL ;
ALTER TABLE `vn2008`.`department`
DROP INDEX `rgt_UNIQUE` ,
DROP INDEX `lft_UNIQUE` ;
;
ALTER TABLE `vn2008`.`department`
ADD INDEX `lft_rgt_depth_idx` (`lft` ASC, `rgt` ASC, `depth` ASC);
;
UPDATE vn.department SET lft = NULL, rgt = NULL; UPDATE vn.department SET lft = NULL, rgt = NULL;

View File

@ -43,4 +43,3 @@ import './input-file';
import './radio'; import './radio';
import './th'; import './th';
import './treeview'; import './treeview';
import './treeview/child';

View File

@ -1,11 +1,11 @@
<ul ng-if="::$ctrl.items"> <ul ng-if="::$ctrl.items">
<li <li ng-repeat="item in $ctrl.items" >
ng-repeat="item in $ctrl.items" <div
on-drop="$ctrl.onDrop(item, dragged, dropped)" on-drop="$ctrl.onDrop(item, dragged, dropped)"
vn-draggable="{{::$ctrl.draggable}}" vn-draggable="{{::$ctrl.draggable}}"
vn-droppable="{{::$ctrl.droppable}}" vn-droppable="{{::$ctrl.droppable}}"
ng-class="{expanded: item.active}"> ng-class="{expanded: item.active}"
<div
ng-click="$ctrl.toggle($event, item)" ng-click="$ctrl.toggle($event, item)"
class="node clickable"> class="node clickable">
<vn-icon <vn-icon
@ -14,8 +14,12 @@
icon="keyboard_arrow_down" icon="keyboard_arrow_down"
translate-attr="{title: 'Toggle'}"> translate-attr="{title: 'Toggle'}">
</vn-icon> </vn-icon>
<section class="tplItem"></section> <vn-treeview-content
<!-- <vn-check item="item"
transclude-func="$ctrl.transcludeFunc">
</vn-treeview-content>
<!--
<vn-check
vn-acl="{{$ctrl.aclRole}}" vn-acl="{{$ctrl.aclRole}}"
ng-if="$ctrl.selectable" ng-if="$ctrl.selectable"
field="item.selected" field="item.selected"
@ -30,9 +34,10 @@
ng-click="$ctrl.onIconClick(icon, item, $ctrl.parent, $parent.$index)" ng-click="$ctrl.onIconClick(icon, item, $ctrl.parent, $parent.$index)"
vn-acl="{{$ctrl.aclRole}}" vn-acl="{{$ctrl.aclRole}}"
vn-acl-action="remove"> vn-acl-action="remove">
</vn-icon-button> --> </vn-icon-button>
-->
</div> </div>
<!-- <vn-treeview-child <vn-treeview-childs
items="item.childs" items="item.childs"
parent="item" parent="item"
selectable="$ctrl.selectable" selectable="$ctrl.selectable"
@ -42,10 +47,13 @@
droppable="::$ctrl.droppable" droppable="::$ctrl.droppable"
icons="::$ctrl.icons" icons="::$ctrl.icons"
parent-scope="::$ctrl.parentScope" parent-scope="::$ctrl.parentScope"
acl-role="$ctrl.aclRole"> acl-role="$ctrl.aclRole"
</vn-treeview-child> --> transclude-func="$ctrl.transcludeFunc">
</vn-treeview-childs>
</li> </li>
<!-- <li </ul>
<!--
<li
ng-if="$ctrl.isInsertable && $ctrl.editable" ng-if="$ctrl.isInsertable && $ctrl.editable"
ng-click="$ctrl.onCreate($ctrl.parent)" ng-click="$ctrl.onCreate($ctrl.parent)"
vn-acl="{{$ctrl.aclRole}}" vn-acl="{{$ctrl.aclRole}}"
@ -58,5 +66,4 @@
Create new one Create new one
</div> </div>
</div> </div>
</li> --> </li>
</ul>

View File

@ -4,12 +4,15 @@ import Component from '../../lib/component';
class Controller extends Component { class Controller extends Component {
constructor($element, $scope, $transclude) { constructor($element, $scope, $transclude) {
super($element, $scope); super($element, $scope);
this.$scope = $scope;
this.$transclude = $transclude; this.$transclude = $transclude;
}
$transclude($scope.$parent, tClone => { $onInit() {
this.element.querySelector('.tplItem').appendChild(tClone[0]); this.transcludeFunc((tClone, $scope) => {
}, null, 'tplItem'); $scope.item = this.item;
let content = this.element.querySelector('.content');
angular.element(content).append(tClone);
});
} }
toggle(event, item) { toggle(event, item) {
@ -42,8 +45,8 @@ class Controller extends Component {
Controller.$inject = ['$element', '$scope', '$transclude']; Controller.$inject = ['$element', '$scope', '$transclude'];
ngModule.component('vnTreeviewChild', { ngModule.component('vnTreeviewChilds', {
template: require('./child.html'), template: require('./childs.html'),
controller: Controller, controller: Controller,
bindings: { bindings: {
items: '<', items: '<',
@ -55,10 +58,8 @@ ngModule.component('vnTreeviewChild', {
draggable: '<?', draggable: '<?',
droppable: '<?', droppable: '<?',
aclRole: '<?', aclRole: '<?',
parentScope: '<' parentScope: '<',
}, transcludeFunc: '<'
transclude: {
tplItem: '?tplItem'
}, },
require: { require: {
treeview: '^vnTreeview' treeview: '^vnTreeview'

View File

@ -0,0 +1,23 @@
import ngModule from '../../module';
class Controller {
constructor($element) {
this.$element = $element;
}
$onInit() {
this.transcludeFunc((tClone, $scope) => {
$scope.item = this.item;
this.$element.append(tClone);
});
}
}
Controller.$inject = ['$element'];
ngModule.component('vnTreeviewContent', {
controller: Controller,
bindings: {
item: '<',
transcludeFunc: '<'
}
});

View File

@ -1,7 +1,6 @@
<vn-treeview-child <vn-treeview-childs
acl-role="$ctrl.aclRole" acl-role="$ctrl.aclRole"
items="$ctrl.data" items="$ctrl.items"
parent="$ctrl.data"
selectable="$ctrl.selectable" selectable="$ctrl.selectable"
editable="$ctrl.editable" editable="$ctrl.editable"
disabled="$ctrl.disabled" disabled="$ctrl.disabled"
@ -9,5 +8,6 @@
parent-scope="$ctrl.$scope.$parent" parent-scope="$ctrl.$scope.$parent"
draggable="$ctrl.draggable" draggable="$ctrl.draggable"
droppable="$ctrl.droppable" droppable="$ctrl.droppable"
vn-droppable="{{$ctrl.droppable}}"> vn-droppable="{{$ctrl.droppable}}"
</vn-treeview-child> transclude-func="$ctrl.$transclude">
</vn-treeview-childs>

View File

@ -2,6 +2,9 @@ import ngModule from '../../module';
import Component from '../../lib/component'; import Component from '../../lib/component';
import './style.scss'; import './style.scss';
import './childs';
import './content';
/** /**
* Treeview * Treeview
* *
@ -12,14 +15,7 @@ export default class Treeview extends Component {
super($element, $scope); super($element, $scope);
this.$scope = $scope; this.$scope = $scope;
this.$transclude = $transclude; this.$transclude = $transclude;
this.data = []; this.items = [];
$transclude($scope.$parent, tClone => {
this.element.querySelector('vn-treeview-child').appendChild(tClone[0]);
// Object.assign(scope, option);
// li.appendChild(clone[0]);
// this.scopes[i] = scope;
}, null, 'tplItem');
} }
$onInit() { $onInit() {
@ -28,7 +24,7 @@ export default class Treeview extends Component {
refresh() { refresh() {
this.model.refresh().then(() => { this.model.refresh().then(() => {
this.data = this.model.data; this.items = this.model.data;
}); });
} }
@ -99,7 +95,5 @@ ngModule.component('vnTreeview', {
droppable: '<?', droppable: '<?',
aclRole: '@?' aclRole: '@?'
}, },
transclude: { transclude: true
tplItem: '?tplItem'
}
}); });

View File

@ -1,30 +1,33 @@
@import "effects"; @import "effects";
vn-treeview { vn-treeview-childs {
vn-treeview-child { display: block;
display: block
}
ul { ul {
padding: 0; padding: 0;
margin: 0; margin: 0;
li { & > li {
list-style: none; list-style: none;
& > div > .arrow {
min-width: 24px;
margin-right: 10px;
transition: transform 200ms;
} }
&.expanded > div > .arrow {
transform: rotate(180deg);
} }
& > .node { vn-icon-button {
padding: 0;
}
& > ul > li > .node {
@extend %clickable; @extend %clickable;
display: flex; display: flex;
padding: 5px; padding: 5px;
align-items: center; align-items: center;
& > .arrow {
min-width: 24px;
margin-right: 10px;
transition: transform 200ms;
}
&.expanded > .arrow {
transform: rotate(180deg);
}
& > vn-check:not(.indeterminate) { & > vn-check:not(.indeterminate) {
color: $color-main; color: $color-main;
@ -39,9 +42,4 @@ vn-treeview {
ul { ul {
padding-left: 2.2em; padding-left: 2.2em;
} }
}
}
vn-icon-button {
padding: 0
}
} }

View File

@ -18,6 +18,12 @@
acl-role="deliveryBoss" acl-role="deliveryBoss"
on-selection="$ctrl.onSelection(item, value)" on-selection="$ctrl.onSelection(item, value)"
selectable="true"> selectable="true">
<vn-check
field="item.selected"
on-change="$ctrl.onSelection(item, value)"
triple-state="true"
label="{{::item.name}}">
</vn-check>
</vn-treeview> </vn-treeview>
</vn-card> </vn-card>
</div> </div>

View File

@ -6,14 +6,14 @@
<div class="content-block" compact> <div class="content-block" compact>
<form name="form" compact> <form name="form" compact>
<vn-card margin-medium-v pad-medium> <vn-card margin-medium-v pad-medium>
<vn-treeview vn-id="treeview" model="model" <vn-treeview
vn-id="treeview"
model="model"
on-selection="$ctrl.onSelection(item, value)" on-selection="$ctrl.onSelection(item, value)"
on-create="$ctrl.onCreate(parent)" on-create="$ctrl.onCreate(parent)"
on-drop="$ctrl.onDrop(item, dragged, dropped)" on-drop="$ctrl.onDrop(item, dragged, dropped)"
icons="$ctrl.icons"> icons="$ctrl.icons">
<tpl-item> {{item.name}}
test
</tpl-item>
</vn-treeview> </vn-treeview>
</vn-card> </vn-card>
<vn-button-bar> <vn-button-bar>