Skip to content
This repository was archived by the owner on Jun 22, 2020. It is now read-only.

Commit 6f01bfd

Browse files
committed
breaking: rename sortable, filterable, draggable, resizable attrs
1 parent bdb28d2 commit 6f01bfd

File tree

18 files changed

+83
-96
lines changed

18 files changed

+83
-96
lines changed

projects/table-builder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-ru/ng-table-builder",
3-
"version": "0.42.0",
3+
"version": "1.0.0",
44
"license": "MIT",
55
"bugs": {
66
"url": "https://github.com/Angular-RU/ng-table-builder/issues"

projects/table-builder/src/lib/table/components/common/column-options.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export class ColumnOptions {
1010
/**
1111
* preserve track global value for overflowTooltip if selected
1212
*/
13-
@Input('overflow-tooltip') public overflowTooltip: boolean = null;
14-
@Input('filter-type') public filterType: TableFilterType = null;
15-
@Input() public nowrap: boolean = null;
13+
@Input('overflow-tooltip') public overflowTooltip: boolean | null = null;
14+
@Input('filter-type') public filterType: TableFilterType | null = null;
15+
@Input() public nowrap: boolean | null = null;
1616
@Input() public width: number = null;
17-
@Input() public resizable: boolean = null;
18-
@Input() public sortable: boolean = null;
19-
@Input() public filterable: boolean = null;
20-
@Input() public draggable: boolean = null;
17+
@Input('is-resizable') public isResizable: boolean | null = null;
18+
@Input('is-sortable') public isSortable: boolean | null = null;
19+
@Input('is-filterable') public isFilterable: boolean | null = null;
20+
@Input('is-draggable') public isDraggable: boolean | null = null;
2121
@Input('css-class') public cssClass: string[];
2222
@Input('css-style') public cssStyle: string[];
23-
@Input() public stub: string = null;
23+
@Input() public stub: string | null = null;
2424
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function getValidHtmlBooleanAttribute(attribute: boolean): boolean {
2+
return typeof attribute === 'string' ? true : !!attribute;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function getValidPredicate<T>(leftPredicate: T, rightPredicate: T): T {
2+
return leftPredicate === null ? rightPredicate : leftPredicate;
3+
}

projects/table-builder/src/lib/table/services/template-parser/template-parser.service.ts

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { TemplateCellCommon } from '../../directives/rows/template-cell.common';
77
import { TemplateHeadThDirective } from '../../directives/rows/template-head-th.directive';
88
import { ColumnsSchema, ImplicitContext, TableCellOptions } from '../../interfaces/table-builder.external';
99
import { KeyMap, QueryListRef } from '../../interfaces/table-builder.internal';
10+
import { getValidHtmlBooleanAttribute } from '../../operators/get-valid-html-boolean-attribute';
11+
import { getValidPredicate } from '../../operators/get-valid-predicate';
1012
import { SchemaBuilder } from './schema-builder.class';
1113

1214
@Injectable()
@@ -53,21 +55,11 @@ export class TemplateParserService {
5355
onClick: cell.onClick,
5456
dblClick: cell.dblClick,
5557
useDeepPath: key.includes('.'),
56-
context: TemplateParserService.getValidHtmlBooleanAttribute(cell.row)
57-
? ImplicitContext.ROW
58-
: ImplicitContext.CELL,
59-
nowrap: TemplateParserService.getValidPredicate(options.nowrap, cell.nowrap)
58+
context: getValidHtmlBooleanAttribute(cell.row) ? ImplicitContext.ROW : ImplicitContext.CELL,
59+
nowrap: getValidHtmlBooleanAttribute(getValidPredicate(options.nowrap, cell.nowrap))
6060
};
6161
}
6262

63-
private static getValidHtmlBooleanAttribute(attribute: boolean): boolean {
64-
return typeof attribute === 'string' ? true : attribute;
65-
}
66-
67-
private static getValidPredicate<T>(leftPredicate: T, rightPredicate: T): T {
68-
return leftPredicate === null ? rightPredicate : leftPredicate;
69-
}
70-
7163
public toggleColumnVisibility(key: string): void {
7264
this.schema.columns = this.schema.columns.map(
7365
(column: ColumnsSchema): ColumnsSchema =>
@@ -128,10 +120,10 @@ export class TemplateParserService {
128120
const { key, th, td, emptyHead, headTitle }: NgxColumnComponent = column;
129121
const thTemplate: TemplateCellCommon = th || new TemplateHeadThDirective(null);
130122
const tdTemplate: TemplateCellCommon = td || new TemplateBodyTdDirective(null);
131-
const isEmptyHead: boolean = TemplateParserService.getValidHtmlBooleanAttribute(emptyHead);
123+
const isEmptyHead: boolean = getValidHtmlBooleanAttribute(emptyHead);
132124
const thOptions: TableCellOptions = TemplateParserService.templateContext(key, thTemplate, this.columnOptions);
133-
const stickyLeft: boolean = TemplateParserService.getValidHtmlBooleanAttribute(column.stickyLeft);
134-
const stickyRight: boolean = TemplateParserService.getValidHtmlBooleanAttribute(column.stickyRight);
125+
const stickyLeft: boolean = getValidHtmlBooleanAttribute(column.stickyLeft);
126+
const stickyRight: boolean = getValidHtmlBooleanAttribute(column.stickyRight);
135127
const canBeAddDraggable: boolean = !(stickyLeft || stickyRight);
136128
const isModel: boolean = this.keyMap[key];
137129

@@ -140,26 +132,29 @@ export class TemplateParserService {
140132
isModel,
141133
isVisible: true,
142134
excluded: !this.allowedKeyMap[key],
143-
verticalLine: TemplateParserService.getValidHtmlBooleanAttribute(column.verticalLine),
135+
verticalLine: getValidHtmlBooleanAttribute(column.verticalLine),
144136
td: TemplateParserService.templateContext(key, tdTemplate, this.columnOptions),
145-
stickyLeft: TemplateParserService.getValidHtmlBooleanAttribute(column.stickyLeft),
146-
stickyRight: TemplateParserService.getValidHtmlBooleanAttribute(column.stickyRight),
147-
customColumn: TemplateParserService.getValidHtmlBooleanAttribute(column.customKey),
148-
width: TemplateParserService.getValidPredicate(column.width, this.columnOptions.width),
149-
cssClass: TemplateParserService.getValidPredicate(column.cssClass, this.columnOptions.cssClass) || [],
150-
cssStyle: TemplateParserService.getValidPredicate(column.cssStyle, this.columnOptions.cssStyle) || [],
151-
resizable: TemplateParserService.getValidPredicate(column.resizable, this.columnOptions.resizable),
152-
stub: TemplateParserService.getValidPredicate(this.columnOptions.stub, column.stub),
153-
filterable: TemplateParserService.getValidPredicate(column.filterable, this.columnOptions.filterable),
137+
stickyLeft: getValidHtmlBooleanAttribute(column.stickyLeft),
138+
stickyRight: getValidHtmlBooleanAttribute(column.stickyRight),
139+
customColumn: getValidHtmlBooleanAttribute(column.customKey),
140+
width: getValidPredicate(column.width, this.columnOptions.width),
141+
cssClass: getValidPredicate(column.cssClass, this.columnOptions.cssClass) || [],
142+
cssStyle: getValidPredicate(column.cssStyle, this.columnOptions.cssStyle) || [],
143+
resizable: getValidHtmlBooleanAttribute(
144+
getValidPredicate(column.isDraggable, this.columnOptions.isDraggable)
145+
),
146+
stub: getValidPredicate(this.columnOptions.stub, column.stub),
147+
filterable: getValidHtmlBooleanAttribute(
148+
getValidPredicate(column.isFilterable, this.columnOptions.isFilterable)
149+
),
154150
sortable: isModel
155-
? TemplateParserService.getValidPredicate(column.sortable, this.columnOptions.sortable)
151+
? getValidHtmlBooleanAttribute(getValidPredicate(column.isSortable, this.columnOptions.isSortable))
156152
: false,
157153
draggable: canBeAddDraggable
158-
? TemplateParserService.getValidPredicate(column.draggable, this.columnOptions.draggable)
154+
? getValidHtmlBooleanAttribute(getValidPredicate(column.isDraggable, this.columnOptions.isDraggable))
159155
: false,
160-
overflowTooltip: TemplateParserService.getValidPredicate(
161-
this.columnOptions.overflowTooltip,
162-
column.overflowTooltip
156+
overflowTooltip: getValidHtmlBooleanAttribute(
157+
getValidPredicate(this.columnOptions.overflowTooltip, column.overflowTooltip)
163158
),
164159
th: {
165160
...thOptions,

projects/table-builder/src/lib/table/table-builder.api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ export abstract class TableBuilderApiImpl
234234
return this.skipSort !== false;
235235
}
236236

237+
public get isEnableAutoWidthColumn(): boolean {
238+
return this.autoWidth !== false;
239+
}
240+
237241
public get isEnableSelection(): boolean {
238242
return this.enableSelection !== false;
239243
}

projects/table-builder/src/lib/table/table-builder.component.html

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,41 +64,41 @@
6464
: null
6565
"
6666
>
67-
<ng-container *ngFor="let option of columnSchema; let index = index">
67+
<ng-container *ngFor="let schema of columnSchema; let index = index">
6868
<div
6969
#column
7070
cdkDrag
7171
observerView
7272
[cdkDragBoundary]="area"
7373
class="table-grid__column"
74-
*ngIf="option.isVisible"
75-
[ngStyle]="option?.cssStyle"
76-
[ngClass]="option?.cssClass"
77-
[attr.column-id]="option.key"
74+
*ngIf="schema.isVisible"
75+
[ngStyle]="schema?.cssStyle"
76+
[ngClass]="schema?.cssClass"
77+
[attr.column-id]="schema.key"
78+
[style.width.px]="schema?.width"
7879
[cdkDragDisabled]="!accessDragging"
80+
[style.max-width.px]="schema?.width"
81+
[style.min-width.px]="schema?.width"
7982
(cdkDragMoved)="cdkDragMoved($event, root)"
80-
[style.max-width.px]="option?.width"
81-
[style.width.px]="option?.width"
82-
[style.min-width.px]="option?.width"
83-
[class.table-grid__column--with-footer-content]="footerTemplate"
84-
[class.table-grid__column--vertical-line]="verticalBorder || option?.verticalLine"
85-
[class.table-grid__column--custom-column]="option?.customColumn"
86-
[class.table-grid__column--selected-all]="selection.selectionModel.isAll"
87-
[class.table-grid__column--sticky-left]="option?.stickyLeft"
88-
[class.table-grid__column--sticky-right]="option?.stickyRight"
89-
[class.table-grid__column--default-width]="!option?.width"
90-
[class.table-grid__column--auto-width-reset-default-with]="autoWidth !== false"
83+
[class.table-grid__column--sticky-left]="schema?.stickyLeft"
84+
[class.table-grid__column--default-width]="!schema?.width"
9185
[class.table-grid__column--is-visible]="column['visible']"
9286
[class.table-grid__column--is-invisible]="!column['visible']"
93-
[class.table-grid__column--is-draggable]="option?.isModel && option?.draggable"
94-
[class.table-grid__column--is-dragging]="isDragging[option.key]"
9587
[class.table-grid__column--filter-enable]="filterTemplate"
88+
[class.table-grid__column--sticky-right]="schema?.stickyRight"
89+
[class.table-grid__column--custom-column]="schema?.customColumn"
90+
[class.table-grid__column--is-dragging]="isDragging[schema.key]"
91+
[class.table-grid__column--with-footer-content]="footerTemplate"
92+
[class.table-grid__column--selected-all]="selection.selectionModel.isAll"
93+
[class.table-grid__column--vertical-line]="verticalBorder || schema?.verticalLine"
94+
[class.table-grid__column--auto-width-reset-default-with]="isEnableAutoWidthColumn"
95+
[class.table-grid__column--is-draggable]="schema?.isModel && schema?.draggable"
9696
(observeVisible)="markVisibleColumn(column, $event)"
9797
>
9898
<div *ngIf="column['visible']" [@fadeAnimation]>
9999
<table-thead
100100
cdkDragHandle
101-
[column-schema]="option"
101+
[column-schema]="schema"
102102
(mouseleave)="disableDragging()"
103103
[column-width]="column.offsetWidth"
104104
[header-top]="headerRef?.nativeElement.offsetHeight || 0"
@@ -110,7 +110,7 @@
110110
[head-height]="headLineHeight"
111111
(resize)="resizeColumn($event, column)"
112112
(sortByKey)="sortByKey($event)"
113-
(mouseenter)="enableDragging(option.key)"
113+
(mouseenter)="enableDragging(schema.key)"
114114
>
115115
</table-thead>
116116

@@ -120,7 +120,7 @@
120120
[primary-key]="primaryKey"
121121
[isRendered]="isRendered"
122122
[recalculated]="recalculated"
123-
[column-schema]="option"
123+
[column-schema]="schema"
124124
[head-height]="headLineHeight"
125125
[viewport-info]="viewPortInfo"
126126
[table-viewport]="tableViewport"

src/app/samples/sample-eleven/sample-eleven.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@
169169
enable-selection
170170
(schemaChanges)="updatedSchema($event)"
171171
>
172-
<ngx-options [resizable]="true" [draggable]="true" [sortable]="true"></ngx-options>
172+
<ngx-options is-draggable is-sortable></ngx-options>
173173

174-
<ngx-column key="action" custom-key sticky [resizable]="false" [width]="50">
174+
<ngx-column key="action" custom-key sticky [is-draggable]="false" width="50">
175175
<ng-template ngx-th></ng-template>
176176
<ng-template ngx-td row let-row>
177177
{{ table2.selectionModel.get($any(row).id) ? 'x' : '-' }}

src/app/samples/sample-fifteen/sample-fifteen.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
</mat-toolbar>
55

66
<ngx-table-builder [source]="data" (schemaChanges)="updatedSchema($event)" [row-height]="40">
7-
<ngx-options [draggable]="true"></ngx-options>
7+
<ngx-options is-draggable></ngx-options>
88
</ngx-table-builder>

src/app/samples/sample-five/sample-five.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
Also you can customize your columns manually
2525
<ngx-column key="myKey" [resizable]="true">...</ngx-column>
2626
-->
27-
<ngx-options [resizable]="true" [nowrap]="false"></ngx-options>
27+
<ngx-options is-draggable [nowrap]="false"></ngx-options>
2828

2929
<ngx-column key="id" width="80" important-template sticky></ngx-column>
3030
</ngx-table-builder>

0 commit comments

Comments
 (0)