Skip to content

Commit

Permalink
refactor(ngrid): refactor the cell rendering engine and refactor the …
Browse files Browse the repository at this point in the history
…group definitions

Closes #123
Closes #131

BREAKING CHANGE:
`prop` and `span` are deprecated from `PblColumnGroupDefinition` and will be removed from version 4.0.0

`prop` and `span` are removed from `PblColumnGroup` and instread columnIds list is used
  • Loading branch information
shlomiassaf committed Nov 15, 2020
1 parent 480ef4d commit 35cb147
Show file tree
Hide file tree
Showing 66 changed files with 1,637 additions and 580 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"coeff",
"deserialize",
"deserializing",
"focusable",
"lunr",
"mdast",
"pebula",
Expand Down
220 changes: 220 additions & 0 deletions 1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
[backends]
{{range $aggName, $aggServices := getGroupedServices .Services }}
[backends."{{ $aggName }}"]
{{range $service := $aggServices }}
{{range $partition := $service.Partitions }}
{{range $instance := $partition.Instances }}
[backends."{{ $aggName }}".servers."{{ $service.ID }}-{{ $instance.ID }}"]
weight = {{ getGroupedWeight $service }}
{{ $endpointName := getLabelValue $service "traefik.servicefabric.endpointname" "" }}
{{if $endpointName }}
url = "{{ getNamedEndpoint $instance $endpointName }}"
{{else}}
url = "{{ getDefaultEndpoint $instance }}"
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
{{range $service := .Services }}
{{if isEnabled $service }}
{{range $partition := $service.Partitions }}
{{if isStateless $service }}
{{ $backendName := $service.Name }}
[backends."{{ $backendName }}"]
{{ $circuitBreaker := getCircuitBreaker $service }}
{{if $circuitBreaker }}
[backends."{{ $backendName }}".circuitBreaker]
expression = "{{ $circuitBreaker.Expression }}"
{{end}}
{{ $loadBalancer := getLoadBalancer $service }}
{{if $loadBalancer }}
[backends."{{ $backendName }}".loadBalancer]
method = "{{ $loadBalancer.Method }}"
sticky = {{ $loadBalancer.Sticky }}
{{if $loadBalancer.Stickiness }}
[backends."{{ $backendName }}".loadBalancer.stickiness]
cookieName = "{{ $loadBalancer.Stickiness.CookieName }}"
{{end}}
{{end}}
{{ $maxConn := getMaxConn $service }}
{{if $maxConn }}
[backends."{{ $backendName }}".maxConn]
extractorFunc = "{{ $maxConn.ExtractorFunc }}"
amount = {{ $maxConn.Amount }}
{{end}}
{{ $healthCheck := getHealthCheck $service }}
{{if $healthCheck }}
[backends."{{ $backendName }}".healthCheck]
path = "{{ $healthCheck.Path }}"
port = {{ $healthCheck.Port }}
interval = "{{ $healthCheck.Interval }}"
hostname = "{{ $healthCheck.Hostname }}"
{{if $healthCheck.Headers }}
[backends."{{ $backendName }}".healthCheck.headers]
{{range $k, $v := $healthCheck.Headers }}
{{$k}} = "{{$v}}"
{{end}}
{{end}}
{{end}}
{{range $instance := $partition.Instances}}
[backends."{{ $service.Name }}".servers."{{ $instance.ID }}"]
weight = {{ getWeight $service }}
{{ $endpointName := getLabelValue $service "traefik.servicefabric.endpointname" "" }}
{{if $endpointName }}
{{ $endpointName := getNamedEndpoint $instance $endpointName }}
{{else}}
{{ $endpointName := getDefaultEndpoint $instance }}
{{end}}
{{if getLabelValue $service "traefik.protocol" "" }}
{{ $endpointName := regexReplaceAll "$https" $endpointName getLabelValue $service "traefik.protocol" }}
{{ $endpointName := regexReplaceAll "$http" $endpointName getLabelValue $service "traefik.protocol" }}
{{end}}
url = "{{ $endpointName }}"
{{end}}
{{else if isStateful $service}}
{{range $replica := $partition.Replicas}}
{{if isPrimary $replica}}
{{ $backendName := getBackendName $service $partition }}
[backends."{{ $backendName }}".servers."{{ $replica.ID }}"]
weight = 1
{{ $endpointName := getLabelValue $service "traefik.servicefabric.endpointname" "" }}
{{if $endpointName }}
url = "{{ getNamedEndpoint $replica $endpointName }}"
{{else}}
url = "{{ getDefaultEndpoint $replica }}"
{{end}}
[backends."{{$backendName}}".LoadBalancer]
method = "drr"
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
[frontends]
{{range $groupName, $groupServices := getGroupedServices .Services }}
{{ $service := index $groupServices 0 }}
[frontends."{{ $groupName }}"]
backend = "{{ $groupName }}"
priority = 50
{{range $key, $value := getFrontendRules $service }}
[frontends."{{ $groupName }}".routes."{{ $key }}"]
rule = "{{ $value }}"
{{end}}
{{end}}
{{range $service := .Services }}
{{if isEnabled $service }}
{{ $frontendName := $service.Name }}
{{if isStateless $service }}
[frontends."frontend-{{ $frontendName }}"]
backend = "{{ $service.Name }}"
passHostHeader = {{ getPassHostHeader $service }}
passTLSCert = {{ getPassTLSCert $service }}
priority = {{ getPriority $service }}
{{ $entryPoints := getEntryPoints $service }}
{{if $entryPoints }}
entryPoints = [{{range $entryPoints }}
"{{.}}",
{{end}}]
{{end}}
{{ $basicAuth := getBasicAuth $service }}
{{if $basicAuth }}
basicAuth = [{{range $basicAuth }}
"{{.}}",
{{end}}]
{{end}}
{{ $whitelist := getWhiteList $service }}
{{if $whitelist }}
[frontends."frontend-{{ $frontendName }}".whiteList]
sourceRange = [{{range $whitelist.SourceRange }}
"{{.}}",
{{end}}]
useXForwardedFor = {{ $whitelist.UseXForwardedFor }}
{{end}}
{{ $redirect := getRedirect $service }}
{{if $redirect }}
[frontends."frontend-{{ $frontendName }}".redirect]
entryPoint = "{{ $redirect.EntryPoint }}"
regex = "{{ $redirect.Regex }}"
replacement = "{{ $redirect.Replacement }}"
permanent = {{ $redirect.Permanent }}
{{end}}
{{ $errorPages := getErrorPages $service }}
{{if $errorPages }}
[frontends."frontend-{{ $frontendName }}".errors]
{{range $pageName, $page := $errorPages }}
[frontends."frontend-{{ $frontendName }}".errors."{{ $pageName }}"]
status = [{{range $page.Status }}
"{{.}}",
{{end}}]
backend = "{{ $page.Backend }}"
query = "{{ $page.Query }}"
{{end}}
{{end}}
{{ $headers := getHeaders $service }}
{{if $headers }}
[frontends."frontend-{{ $frontendName }}".headers]
SSLRedirect = {{ $headers.SSLRedirect }}
SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }}
SSLHost = "{{ $headers.SSLHost }}"
STSSeconds = {{ $headers.STSSeconds }}
STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }}
STSPreload = {{ $headers.STSPreload }}
ForceSTSHeader = {{ $headers.ForceSTSHeader }}
FrameDeny = {{ $headers.FrameDeny }}
CustomFrameOptionsValue = "{{ $headers.CustomFrameOptionsValue }}"
ContentTypeNosniff = {{ $headers.ContentTypeNosniff }}
BrowserXSSFilter = {{ $headers.BrowserXSSFilter }}
CustomBrowserXSSValue = "{{ $headers.CustomBrowserXSSValue }}"
ContentSecurityPolicy = "{{ $headers.ContentSecurityPolicy }}"
PublicKey = "{{ $headers.PublicKey }}"
ReferrerPolicy = "{{ $headers.ReferrerPolicy }}"
IsDevelopment = {{ $headers.IsDevelopment }}
{{if $headers.AllowedHosts }}
AllowedHosts = [{{range $headers.AllowedHosts }}
"{{.}}",
{{end}}]
{{end}}
{{if $headers.HostsProxyHeaders }}
HostsProxyHeaders = [{{range $headers.HostsProxyHeaders }}
"{{.}}",
{{end}}]
{{end}}
{{if $headers.CustomRequestHeaders }}
[frontends."frontend-{{ $frontendName }}".headers.customRequestHeaders]
{{range $k, $v := $headers.CustomRequestHeaders }}
{{$k}} = "{{$v}}"
{{end}}
{{end}}
{{if $headers.CustomResponseHeaders }}
[frontends."frontend-{{ $frontendName }}".headers.customResponseHeaders]
{{range $k, $v := $headers.CustomResponseHeaders }}
{{$k}} = "{{$v}}"
{{end}}
{{end}}
{{if $headers.SSLProxyHeaders }}
[frontends."frontend-{{ $frontendName }}".headers.SSLProxyHeaders]
{{range $k, $v := $headers.SSLProxyHeaders }}
{{$k}} = "{{$v}}"
{{end}}
{{end}}
{{end}}
{{range $key, $value := getFrontendRules $service }}
[frontends."frontend-{{ $frontendName }}".routes."{{ $key }}"]
rule = "{{ $value }}"
{{end}}
{{else if isStateful $service }}
{{range $partition := $service.Partitions }}
{{ $partitionId := $partition.PartitionInformation.ID }}
{{ $rule := getLabelValue $service (print "traefik.frontend.rule.partition." $partitionId) "" }}
{{if $rule }}
[frontends."{{ $service.Name }}/{{ $partitionId }}"]
backend = "{{ getBackendName $service $partition }}"
[frontends."{{ $service.Name }}/{{ $partitionId }}".routes.default]
rule = "{{ $rule }}"
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
[ngridCellClass]="value < 0 ? col.type.data.pbl : col.type.data.pos">{{ value | currency:col.type.data.meta.currency(row):'symbol':col.type.data.format }}</div>
<div *pblNgridCellTypeDef="'flagAndCountry'; col as col; row as row">{{ col.type.data.flagAndCountry(row) }}</div>

<pbl-ngrid-row in *pblNgridInfiniteVirtualRowRef="let row; gridInstance as gridInstance" class="pbl-ngrid-infinite-virtual-row" [grid]="gridInstance" [infiniteRow]="row">
<pbl-ngrid-row in *pblNgridInfiniteVirtualRowDef="let row; gridInstance as gridInstance" class="pbl-ngrid-infinite-virtual-row" [grid]="gridInstance" [infiniteRow]="row">
<mat-spinner diameter="24"></mat-spinner>
</pbl-ngrid-row>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ export class SellerDemoExample {
.headerGroup(
{ type: 'fixed' },
{
prop: 'name',
span: 3,
label: 'Marketing'
label: 'Marketing',
columnIds: ['name', 'email', 'country', 'rating']
}
)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export class GroupColumnsLockExample {
lockColumns: true,
}
)
.headerGroup(
{
prop: 'gender',
span: 2,
label: 'Gender, Email & Country'
},
{
prop: 'birthdate',
span: 1,
label: 'Birthday & Balance',
}
)
.build();
ds = createDS<Person>().onTrigger( () => this.datasource.getPeople(0, 500) ).create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class MovingWithTheApiExample {
.table(
{ prop: 'id', width: '40px' },
{ prop: 'name' },
{ prop: 'language', width: '120px' },
{ prop: 'gender', width: '50px' },
{ prop: 'birthdate', type: 'date' }
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<pbl-ngrid [dataSource]="ds" [columns]="columns">
<mat-progress-bar *ngIf="ds.adapter.virtualRowsLoading | async" mode="indeterminate"></mat-progress-bar>

<pbl-ngrid-row in *pblNgridInfiniteVirtualRowRef="let row; gridInstance as gridInstance" class="pbl-ngrid-infinite-virtual-row" [grid]="gridInstance" [row]="row">
<pbl-ngrid-row in *pblNgridInfiniteVirtualRowDef="let row; gridInstance as gridInstance" class="pbl-ngrid-infinite-virtual-row" [grid]="gridInstance" [row]="row">
</pbl-ngrid-row>

</pbl-ngrid>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mat-elevation-z6 demo-top-nav">
<div class="mat-elevation-z6 demo-top-nav" [class.pbl-ngrid-rtl-layout]="isRtl">
<nav fxLayoutAlign="start center" fxLayoutGap="8px">
<a [routerLink]="['/']" class="ngrid-top-nav-logo-link">
<div fxLayout="row" fxLayoutAlign="start center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ app-search-results {
color: white;
}
}

.ng-custom-logo {
position: relative;
height: $top-nav-bar-height - (2 * $nav-top-bottom-padding);
Expand All @@ -79,6 +80,12 @@ app-search-results {
}
}

.pbl-ngrid-rtl-layout .ng-custom-logo {
& > mat-icon {
transform: translate(50%, -50%);
}
}

.mobile-top-menu {
margin-bottom: -14px;
}
6 changes: 2 additions & 4 deletions libs/ngrid/detail-row/src/lib/detail-row/detail-row-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ export class PblNgridDetailRowPluginDirective<T> implements OnDestroy {
let detailRow = grid.registry.getSingle('detailRowParent');
if (detailRow) {
this._detailRowDef = detailRow = detailRow.clone();
Object.defineProperty(detailRow, 'columns', { enumerable: true, get: () => grid.columnApi.visibleColumnIds });
Object.defineProperty(detailRow, 'when', { enumerable: true, get: () => this._isDetailRow });
detailRow.ngOnChanges({ columns: { isFirstChange: () => true, firstChange: true, currentValue: detailRow.columns, previousValue: null }});
} else if (!this._defaultParentRef) {
// TODO: move to module? set in root registry? put elsewhere to avoid grid sync (see event of registry change)...
this._defaultParentRef = this.injector.get(ComponentFactoryResolver)
Expand All @@ -242,8 +240,8 @@ export class PblNgridDetailRowPluginDirective<T> implements OnDestroy {
}

/**
* Update the grid with detail row infor.
* Instead of calling for a change detection cycle we can assign the new predicates directly to the cdkRowDef instances.
* Update the grid with detail row info.
* Instead of calling for a change detection cycle we can assign the new predicates directly to the pblNgridRowDef instances.
*/
private updateTable(): void {
this.grid._tableRowDef.when = this._isSimpleRow;
Expand Down
20 changes: 5 additions & 15 deletions libs/ngrid/detail-row/src/lib/detail-row/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import {
Component,
Directive,
IterableDiffers,
OnInit,
OnDestroy,
TemplateRef,
} from '@angular/core';
import { CdkRowDef } from '@angular/cdk/table';

import { PblNgridRegistryService, PblNgridSingleTemplateRegistry, PblNgridRowContext } from '@pebula/ngrid';
import { PblNgridRegistryService, PblNgridSingleTemplateRegistry, PblNgridRowContext, PblNgridRowDef } from '@pebula/ngrid';

declare module '@pebula/ngrid/lib/grid/registry/types' {
interface PblNgridSingleRegistryMap {
Expand All @@ -31,24 +29,16 @@ export class PblNgridDetailRowDefDirective extends PblNgridSingleTemplateRegistr
selector: '[pblNgridDetailRowParentRef]',
inputs: ['columns: pblNgridDetailRowParentRef', 'when: pblNgridDetailRowParentRefWhen'],
})
export class PblNgridDetailRowParentRefDirective<T> extends CdkRowDef<T> implements OnInit, OnDestroy {

constructor(template: TemplateRef<PblNgridRowContext<T>>, _differs: IterableDiffers, protected registry: PblNgridRegistryService) {
super(template, _differs);
}

clone(): PblNgridDetailRowParentRefDirective<T> {
const clone = Object.create(this);
this._columnsDiffer = this.columns = undefined;
return clone;
}
export class PblNgridDetailRowParentRefDirective<T> extends PblNgridRowDef<T> implements OnInit, OnDestroy {

ngOnInit(): void {
this.registry.setSingle('detailRowParent', this as any);
}

ngOnDestroy(): void {
this.registry.setSingle('detailRowParent', undefined);
if (this.registry.getSingle('detailRowParent') === this) {
this.registry.setSingle('detailRowParent', undefined);
}
}
}

Expand Down
Loading

0 comments on commit 35cb147

Please sign in to comment.