ng-jhipster
Version:
A Jhipster util library for Angular 2
47 lines (46 loc) • 1.72 kB
JavaScript
import { Directive, Host, HostListener, Input, ElementRef, Renderer } from '@angular/core';
import { JhiSortDirective } from './sort.directive';
import { ConfigHelper } from '../helper';
export var JhiSortByDirective = (function () {
function JhiSortByDirective(jhiSort, el, renderer) {
this.el = el;
this.renderer = renderer;
this.sortAscIcon = 'fa-sort-asc';
this.sortDescIcon = 'fa-sort-desc';
this.jhiSort = jhiSort;
var config = ConfigHelper.getConfig();
this.sortAscIcon = config.sortAscIcon;
this.sortDescIcon = config.sortDescIcon;
}
JhiSortByDirective.prototype.onClick = function () {
if (this.jhiSort.predicate && this.jhiSort.predicate !== '_score') {
this.jhiSort.sort(this.jhiSortBy);
this.applyClass();
}
};
JhiSortByDirective.prototype.applyClass = function () {
var childSpan = this.el.nativeElement.children[1];
var add = this.sortAscIcon;
if (!this.jhiSort.ascending) {
add = this.sortDescIcon;
}
this.renderer.setElementClass(childSpan, add, true);
};
;
JhiSortByDirective.decorators = [
{ type: Directive, args: [{
selector: '[jhiSortBy]'
},] },
];
/** @nocollapse */
JhiSortByDirective.ctorParameters = function () { return [
{ type: JhiSortDirective, decorators: [{ type: Host },] },
{ type: ElementRef, },
{ type: Renderer, },
]; };
JhiSortByDirective.propDecorators = {
'jhiSortBy': [{ type: Input },],
'onClick': [{ type: HostListener, args: ['click',] },],
};
return JhiSortByDirective;
}());