novo-elements
Version:
Bullhorn's NOVO Element Repository for Angular 2
183 lines (165 loc) • 8.51 kB
text/typescript
import {
ChangeDetectionStrategy, Component, ViewEncapsulation, HostBinding,
Input, ViewChild, Directive, EventEmitter, Output, AfterContentInit,
SimpleChanges, ChangeDetectorRef, Injectable, OnChanges
} from '@angular/core';
import { CDK_TABLE_TEMPLATE, CdkTable } from '@angular/cdk/table';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { NovoSortFilter, NovoSelection } from './sort';
import { NovoSimpleTablePagination } from './pagination';
import { SimpleTableColumn, SimpleTableActionColumn, SimpleTablePaginationOptions, SimpleTableSearchOptions } from './interfaces';
import { ActivityTableService, ActivityTableDataSource } from './table-source';
import { NovoLabelService } from '../../services/novo-label-service';
import { NovoActivityTableState } from './state';
/** Workaround for https://github.com/angular/angular/issues/17849 */
export const _NovoTable = CdkTable;
export class NovoTable<T> extends _NovoTable<T> {
}
export class NovoActivityTableActions { }
export class NovoActivityTableEmptyMessage { }
export class NovoActivityTableNoResultsMessage { }
export class NovoActivityTable<T> implements AfterContentInit, OnChanges {
globalSearchHiddenClassToggle: boolean = false;
activityService: ActivityTableService<T>;
columns: SimpleTableColumn<T>[];
displayedColumns: string[];
actionColumns: SimpleTableActionColumn<T>[];
paginationOptions: SimpleTablePaginationOptions;
searchOptions: SimpleTableSearchOptions;
defaultSort: { id: string, value: string };
set hideGlobalSearch(v: boolean) {
this._hideGlobalSearch = coerceBooleanProperty(v);
this.globalSearchHiddenClassToggle = this._hideGlobalSearch;
}
get hideGlobalSearch() {
return this._hideGlobalSearch;
}
private _hideGlobalSearch: boolean;
set debug(v: boolean) {
this._debug = coerceBooleanProperty(v);
}
get debug() {
return this._debug;
}
private _debug: boolean;
public dataSource: ActivityTableDataSource<T>;
public loading: boolean = true;
get empty() {
return this.dataSource && this.dataSource.totallyEmpty;
}
get loadingClass() {
return this.loading || (this.dataSource && this.dataSource.loading);
}
constructor(public labels: NovoLabelService, private ref: ChangeDetectorRef, public state: NovoActivityTableState) { }
public ngOnChanges(changes: SimpleChanges): void {
if (changes['activityService'] && changes['activityService'].currentValue) {
this.loading = false;
this.dataSource = new ActivityTableDataSource<T>(this.activityService, this.state, this.ref);
this.ref.markForCheck();
}
}
public ngAfterContentInit(): void {
if (!this.paginationOptions) {
this.paginationOptions = {}
}
if (!this.paginationOptions.page) {
this.paginationOptions.page = 0;
}
if (!this.paginationOptions.pageSize) {
this.paginationOptions.pageSize = 50;
}
if (!this.paginationOptions.pageSizeOptions) {
this.paginationOptions.pageSizeOptions = [10, 25, 50, 100];
}
this.state.page = this.paginationOptions.page;
this.state.pageSize = this.paginationOptions.pageSize;
this.ref.markForCheck();
}
public onSearchChange(term: string): void {
this.state.globalSearch = term;
this.state.reset(false, true);
this.state.updates.next({ globalSearch: term });
}
}