Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 41 additions & 44 deletions @angular-generic-table/core/components/generic-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
GtRowMeta,
GtTexts
} from '..';
import { GtMetaPipe } from '../pipes/gt-meta.pipe';
import {GtMetaPipe} from '../pipes/gt-meta.pipe';

@Component({
selector: 'generic-table',
Expand Down Expand Up @@ -95,7 +95,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
if (COLUMNS_WITH_CLASS_NAMES.length > 0) {
console.warn(
'Field setting "classNames" have been deprecated in favor for "columnClass" and will be removed in the future, please update field settings for column with object key: ' +
COLUMNS_WITH_CLASS_NAMES[0].objectKey
COLUMNS_WITH_CLASS_NAMES[0].objectKey
);
}
}
Expand All @@ -110,9 +110,9 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
this._gtSettings[i].sortEnabled =
this._gtSettings[i].sortEnabled !== false
? (this._gtSettings[i].sortEnabled = !(
this._gtSettings[i].sort &&
this._gtSettings[i].sort.indexOf('disable') !== -1
))
this._gtSettings[i].sort &&
this._gtSettings[i].sort.indexOf('disable') !== -1
))
: false;

// check if sorting is undefined...
Expand Down Expand Up @@ -174,7 +174,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
: this.gtOptions.rowSelectionInitialState;
if (selected) {
if (typeof this.metaInfo[row.$$gtRowId] === 'undefined') {
this.metaInfo[row.$$gtRowId] = { isSelected: true };
this.metaInfo[row.$$gtRowId] = {isSelected: true};
} else {
this.metaInfo[row.$$gtRowId].isSelected = true;
}
Expand All @@ -195,7 +195,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>

if (expanded) {
if (typeof this.metaInfo[row.$$gtRowId] === 'undefined') {
this.metaInfo[row.$$gtRowId] = { isOpen: true };
this.metaInfo[row.$$gtRowId] = {isOpen: true};
} else {
this.metaInfo[row.$$gtRowId].isOpen = true;
}
Expand Down Expand Up @@ -294,7 +294,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
};
} = {};

public data: { exportData: Array<any> } = { exportData: [] }; // Store filtered data for export
public data: { exportData: Array<any> } = {exportData: []}; // Store filtered data for export

constructor(private renderer: Renderer2, private gtMetaPipe: GtMetaPipe) {
this.gtEvent.subscribe(($event: GtEvent) => {
Expand All @@ -312,7 +312,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
* @param objectKey - name of key to sort on.
* @param event - such as key press during sorting.
*/
public gtSort = function(objectKey: string, event: any) {
public gtSort = function (objectKey: string, event: any) {
this.inlineEditCancel(); // cancel inline editing

// loop through current settings
Expand All @@ -327,7 +327,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
return;
} else if (
/* check if sorting is undefined... */ typeof this._gtSettings[i]
.sort === 'undefined'
.sort === 'undefined'
) {
// ...is so, set sorting property to enable
this._gtSettings[i].sort = 'enable';
Expand Down Expand Up @@ -397,8 +397,8 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
match !== -1
? ['-' + objectKey]
: ctrlKey || !this.gtOptions.allowUnsorted
? [objectKey]
: [];
? [objectKey]
: [];
break;
}
}
Expand Down Expand Up @@ -432,8 +432,8 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
this._gtSettings[i].sort === 'enable'
? this._gtSettings.length - 1
: this.sortOrder.indexOf(objectKey) === -1
? this.sortOrder.indexOf('-' + objectKey)
: this.sortOrder.indexOf(objectKey);
? this.sortOrder.indexOf('-' + objectKey)
: this.sortOrder.indexOf(objectKey);
} else if (
this._gtSettings[i].sort &&
this._gtSettings[i].sort.indexOf('disable') === -1 &&
Expand Down Expand Up @@ -464,7 +464,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
* @param rowLength - total number of rows.
* @param reset - should page be reset to first page.
*/
public changeRowLength = function(rowLength: any, reset?: boolean) {
public changeRowLength = function (rowLength: any, reset?: boolean) {
let lengthValue = isNaN(parseInt(rowLength, 10))
? 0
: parseInt(rowLength, 10);
Expand Down Expand Up @@ -513,7 +513,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
* Force a redraw of table rows.
* As the table uses pure pipes, we need to force a redraw if an object in the array is changed to see the changes.
*/
public redraw = function($event?: any) {
public redraw = function ($event?: any) {
this.refreshSorting = !this.refreshSorting;
this.refreshPageArray = !this.refreshPageArray;
this.refreshPipe = !this.refreshPipe;
Expand All @@ -538,7 +538,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
}

/** Go to next page. */
public nextPage = function() {
public nextPage = function () {
const page =
this.gtInfo.pageCurrent === this.gtInfo.pageTotal
? this.gtInfo.pageTotal
Expand All @@ -547,14 +547,14 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
};

/** Go to previous page. */
public previousPage = function() {
public previousPage = function () {
const page =
this.gtInfo.pageCurrent === 1 ? 1 : this.gtInfo.pageCurrent - 1;
this.goToPage(page);
};

/** Request more data (used when lazy loading) */
private getData = function() {
private getData = function () {
// ...emit event requesting for more data
this.gtEvent.emit({
name: 'gt-page-changed-lazy',
Expand All @@ -569,7 +569,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
* Go to specific page.
* @param page - page number.
*/
public goToPage = function(page: number) {
public goToPage = function (page: number) {
const previousPage = this.gtInfo.pageCurrent;
this.gtInfo.pageCurrent = page;
this.inlineEditCancel(); // cancel inline edit
Expand Down Expand Up @@ -701,7 +701,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
public rowClick(row: GtRow, $event: MouseEvent) {
this.gtEvent.emit({
name: 'gt-row-clicked',
value: { row: row, event: $event }
value: {row: row, event: $event}
});
}

Expand Down Expand Up @@ -802,9 +802,9 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
eventName = 'expand-all';
this.openRows = this._gtOptions.lazyLoad
? this._pushLazyRows(
this.openRows,
this._gtData[this.gtInfo.pageCurrent - 1].slice()
)
this.openRows,
this._gtData[this.gtInfo.pageCurrent - 1].slice()
)
: this._gtData.slice();
this._updateMetaInfo(this.openRows, property, active);
} else {
Expand All @@ -830,9 +830,9 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
eventName = 'select-all';
this.selectedRows = this._gtOptions.lazyLoad
? this._pushLazyRows(
this.selectedRows,
this._gtData[this.gtInfo.pageCurrent - 1].slice()
)
this.selectedRows,
this._gtData[this.gtInfo.pageCurrent - 1].slice()
)
: this._gtData.slice();
this._updateMetaInfo(this.selectedRows, property, active);
} else {
Expand Down Expand Up @@ -974,7 +974,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
if (property !== 'isUpdated') {
this.metaInfo[row.$$gtRowId][property] = !this.metaInfo[row.$$gtRowId][
property
];
];
}
}
}
Expand All @@ -999,7 +999,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
* @param column - column object.
*/
public gtDropdownSelect(row: GtRow, column: GtRenderField<any, any>) {
const oldValue = { ...row };
const oldValue = {...row};
row[column.objectKey] = column.renderValue;
this.updateRow(row, oldValue);
}
Expand Down Expand Up @@ -1072,7 +1072,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>

// loop through changes in row
Object.keys(CHANGES).map(objectKey => {
const oldValue = { ...ROW };
const oldValue = {...ROW};
ROW[objectKey] = CHANGES[objectKey].renderValue; // update data value
this.updateRow(ROW, oldValue); // update meta info for row and send event
CHANGES[objectKey].edited = false; // disable edit mode
Expand Down Expand Up @@ -1262,7 +1262,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>

// TODO: move to helper functions
/** Sort by sort order */
private getSortOrder = function(a: GtConfigSetting, b: GtConfigSetting) {
private getSortOrder = function (a: GtConfigSetting, b: GtConfigSetting) {
if (a.sortOrder < b.sortOrder) {
return -1;
}
Expand All @@ -1274,7 +1274,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>

// TODO: move to helper functions
/** Sort by column order */
private getColumnOrder = function(a: GtConfigSetting, b: GtConfigSetting) {
private getColumnOrder = function (a: GtConfigSetting, b: GtConfigSetting) {
if (a.columnOrder === undefined) {
return -1;
}
Expand All @@ -1289,7 +1289,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>

// TODO: move to helper functions
/** Create a deep copy of data */
private cloneDeep = function(o: any) {
private cloneDeep = function (o: any) {
return JSON.parse(JSON.stringify(o));
};

Expand Down Expand Up @@ -1318,9 +1318,6 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>

csv += this.escapeCSVDelimiter(exportValue);

csv += this.getProperty(this._gtFields, this._gtSettings[i].objectKey)
.name;

if (i < this._gtSettings.length - 1) {
csv += this._gtOptions.csvDelimiter;
}
Expand All @@ -1343,8 +1340,8 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
fieldSetting.export && typeof fieldSetting.export === 'function'
? fieldSetting.export(row)
: fieldSetting.value && typeof fieldSetting.value === 'function'
? fieldSetting.value(row)
: row[this._gtSettings[i].objectKey];
? fieldSetting.value(row)
: row[this._gtSettings[i].objectKey];

csv += this.escapeCSVDelimiter(exportValue);

Expand Down Expand Up @@ -1372,7 +1369,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
link.setAttribute(
'href',
'data:text/csv;charset=utf-8,' +
encodeURIComponent((useBOM ? BOM : '') + csv)
encodeURIComponent((useBOM ? BOM : '') + csv)
); // URL.createObjectURL(blob));
link.setAttribute(
'download',
Expand All @@ -1395,20 +1392,20 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
}

/** Return property */
private getProperty = function(array: Array<any>, key: string) {
private getProperty = function (array: Array<any>, key: string) {
for (let i = 0; i < array.length; i++) {
if (array[i].objectKey === key) {
return array[i];
}
}
};

private restructureSorting = function() {
private restructureSorting = function () {
/** Check and store sort order upon initialization.
* This is done by checking sort properties in the settings array of the table, if no sorting is defined
* we'll sort the data by the first visible and enabled column in the table(ascending). Please note that actually
* sorting have to be done server side when lazy loading data for obvious reasons. */
// create sorting array
// create sorting array
const sorting = [];
if (this._gtSettings) {
// ...sort settings by sort order
Expand Down Expand Up @@ -1458,7 +1455,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
*/
private escapeCSVDelimiter(value) {
return typeof value === 'string' &&
value.indexOf(this._gtOptions.csvDelimiter) !== -1
value.indexOf(this._gtOptions.csvDelimiter) !== -1
? '"' + value + '"'
: value;
}
Expand All @@ -1475,7 +1472,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
/**
* Extend object function.
*/
private extend = function(a: Object, b: Object) {
private extend = function (a: Object, b: Object) {
for (const key in b) {
if (b.hasOwnProperty(key)) {
a[key] = b[key];
Expand Down