primera versión del componente vnGridHeader para ordenación de tablas

This commit is contained in:
Dani Herrero 2017-06-21 09:46:31 +02:00
parent 7c28d42be0
commit 3796741371
5 changed files with 28 additions and 41 deletions

View File

@ -1,10 +1,10 @@
<div class="{{$ctrl.className}}"> <div class="{{$ctrl.className}}">
<vn-horizontal ng-if="$ctrl.text" class="orderly"> <vn-horizontal ng-if="$ctrl.text" class="orderly" ng-click="$ctrl.onClick()">
<span translate> <span translate>
{{::$ctrl.text}} {{::$ctrl.text}}
</span> </span>
<vn-icon icon="keyboard_arrow_down" ng-if="$ctrl.showOrder && $ctrl.order === 'DESC'"></vn-icon> <vn-icon icon="keyboard_arrow_down" ng-if="$ctrl.gridHeader.field === $ctrl.field && $ctrl.order === 'DESC'"></vn-icon>
<vn-icon icon="keyboard_arrow_up" ng-if="$ctrl.showOrder && $ctrl.order === 'ASC'"></vn-icon> <vn-icon icon="keyboard_arrow_up" ng-if="$ctrl.gridHeader.field === $ctrl.field && $ctrl.order === 'ASC'"></vn-icon>
</vn-horizontal> </vn-horizontal>
<ng-transclude ng-if="!$ctrl.text"></ng-transclude> <ng-transclude ng-if="!$ctrl.text"></ng-transclude>
</div> </div>

View File

@ -1,40 +1,19 @@
import {module} from '../module'; import {module} from '../module';
export default class vnColumHeader { export default class ColumHeader {
constructor($element, $timeout, $transclude) { constructor() {
this.$element = $element; this.order = undefined;
this.$timeout = $timeout;
this.order = null;
this.showOrder = false;
} }
onClick() { onClick() {
switch (this.order) { if (this.order === 'ASC') {
case 'ASC':
this.$timeout(() => {
this.showOrder = true;
this.order = 'DESC'; this.order = 'DESC';
// this.gH.onOrder(this.field, this.order); } else {
});
break;
default:
this.$timeout(() => {
this.showOrder = true;
this.order = 'ASC'; this.order = 'ASC';
});
break;
} }
this.$timeout( this.gridHeader.selectColum(this);
() => {
this.showOrder = false;
}, 1000);
}
$onInit() {
if (this.field) {
this.$element.bind("click", () => this.onClick());
} }
} }
} ColumHeader.$inject = [];
vnColumHeader.$inject = ['$element', '$timeout'];
module.component('vnColumHeader', { module.component('vnColumHeader', {
template: require('./colum-header.html'), template: require('./colum-header.html'),
@ -44,8 +23,8 @@ module.component('vnColumHeader', {
className: '@?' className: '@?'
}, },
require: { require: {
gH: '^vnGridHeader' gridHeader: '^^vnGridHeader'
}, },
controller: vnColumHeader, controller: ColumHeader,
transclude: true transclude: true
}); });

View File

@ -3,15 +3,24 @@ import './style.scss';
export default class GridHeader { export default class GridHeader {
constructor() { constructor() {
this.field = undefined;
this.order = undefined;
} }
selectColum(col) {
this.field = col.field;
this.order = col.order;
if (this.onOrder)
this.onOrder(this);
}
} }
module.component('vnGridHeader', { module.component('vnGridHeader', {
template: require('./grid-header.html'), template: require('./grid-header.html'),
transclude: true, transclude: true,
binding: { bindings: {
onOrder: '&?' onOrder: '&?'
}, },
component: GridHeader controller: GridHeader
}); });

View File

@ -3,7 +3,6 @@ vn-grid-header {
font-weight: bold; font-weight: bold;
.orderly{ .orderly{
cursor: pointer; cursor: pointer;
text-align: center;
} }
vn-none{ vn-none{
min-width: 60px; min-width: 60px;

View File

@ -1,5 +1,5 @@
<mg-ajax path="/production/api/Tickets/list" options="vnIndex" actions="$ctrl.tickets = index.model.tickets;$ctrl.sumTickets()"></mg-ajax> <mg-ajax path="/production/api/Tickets/list" options="vnIndex" actions="$ctrl.tickets = index.model.tickets;$ctrl.sumTickets()"></mg-ajax>
<mg-ajax path="/production/api/States/productionStates" options="vnIndex as states" actions="$ctrl.states = states.model.states;"></mg-ajax>
<vn-card margin-large> <vn-card margin-large>
<vn-vertical pad-medium> <vn-vertical pad-medium>
@ -53,7 +53,7 @@
<vn-two></vn-two> <vn-two></vn-two>
</vn-horizontal> </vn-horizontal>
<vn-grid-header on-order="$ctrl.onOrder"> <vn-grid-header on-order="$ctrl.onOrder(field, order)">
<vn-none></vn-none> <vn-none></vn-none>
<vn-colum-header vn-none> <vn-colum-header vn-none>
<vn-check model="$ctrl.checkAll"></vn-check> <vn-check model="$ctrl.checkAll"></vn-check>