Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

2023 Demo app update #1703

Merged
merged 25 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b55e201
misc: housekeeping documentation app
shanmukhateja Dec 27, 2022
8fd3c7a
misc: rename "Getting Started" to "Installation"
shanmukhateja Dec 27, 2022
8e09d3a
feat: Add Deprecated section boilerplate
shanmukhateja Dec 27, 2022
1812fdc
misc: move deprecated code to new menu
shanmukhateja Dec 27, 2022
10627cb
misc: menu changes pt1
shanmukhateja Dec 27, 2022
ab64d42
misc: update Angular welcome feature
shanmukhateja Dec 27, 2022
1d35323
feat: use Materialize Tabs
shanmukhateja Dec 27, 2022
f0342b9
misc: minor changes
shanmukhateja Dec 28, 2022
36206b1
feat: Add "back to top" div
shanmukhateja Dec 28, 2022
11273b4
[WIP] feat: update sidenav with subheaders
shanmukhateja Dec 28, 2022
62463ee
misc: project changes pt2
shanmukhateja Dec 28, 2022
d43d560
misc: move the tabs init code to app.component
shanmukhateja Dec 29, 2022
1f6e503
fix: use .caption class for description text
shanmukhateja Dec 29, 2022
7675603
feat: Change demo project theme
shanmukhateja Dec 29, 2022
063faa4
fix: add wave effect for all side nav menus
shanmukhateja Dec 29, 2022
72ad56b
fix: FAQ page CSS
shanmukhateja Dec 29, 2022
21404f0
feat: add More info about Angular way deprecation
shanmukhateja Dec 29, 2022
f8dde0f
misc: migrate DatatablesResponse class to separate file
shanmukhateja Dec 30, 2022
4e03350
Add AJAX callback and new server side examples
shanmukhateja Dec 30, 2022
f5790fc
fix: migrate Router link example to TemplateRef
shanmukhateja Dec 30, 2022
46c3de6
misc: remove TODO file from repo
shanmukhateja Dec 30, 2022
32e10ee
Revert "misc: housekeeping documentation app"
shanmukhateja Dec 30, 2022
e01d147
ci: unit tests changes
shanmukhateja Dec 30, 2022
cde75d6
feat: compile demo app to ES2015 format
shanmukhateja Dec 30, 2022
1cec427
fix: add onDestroy to router link example
shanmukhateja Dec 30, 2022
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
2 changes: 1 addition & 1 deletion demo/src/app/advanced/demo-ng-template-ref.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="btn-group d-block text-center">
<button class="btn btn-sm btn-dark" (click)="onAction1()">Action 1</button>
<button class="btn btn-sm btn-dark" (click)="onAction1()">{{actionText}}</button>
</div>
3 changes: 3 additions & 0 deletions demo/src/app/advanced/demo-ng-template-ref.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class DemoNgComponent implements OnInit {
@Input()
data = {};

@Input()
actionText = 'Action 1';

ngOnInit(): void {
}

Expand Down
4 changes: 2 additions & 2 deletions demo/src/app/advanced/dt-instance.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe('DtInstanceComponent', () => {
expect(app).toBeTruthy();
}));

it('should have title "Getting the DataTable instance"', waitForAsync(() => {
it('should have title "Finding DataTable instance"', waitForAsync(() => {
const app = fixture.debugElement.componentInstance as DtInstanceComponent;
expect(app.pageTitle).toBe('Getting the DataTable instance');
expect(app.pageTitle).toBe('Finding DataTable instance');
}));

it('should retrieve Table instance', async () => {
Expand Down
2 changes: 1 addition & 1 deletion demo/src/app/advanced/dt-instance.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DataTableDirective } from 'angular-datatables';
})
export class DtInstanceComponent implements OnInit {

pageTitle = 'Getting the DataTable instance';
pageTitle = 'Finding DataTable instance';
mdIntro = 'assets/docs/advanced/dt-instance/intro.md';
mdHTML = 'assets/docs/advanced/dt-instance/source-html.md';
mdTS = 'assets/docs/advanced/dt-instance/source-ts.md';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe('LoadDtOptionsWithPromiseComponent', () => {
expect(app).toBeTruthy();
}));

it('should have title "Load DataTables Options with Promise"', waitForAsync(() => {
it('should have title "Load DT Options with Promise"', waitForAsync(() => {
const app = fixture.debugElement.componentInstance as LoadDtOptionsWithPromiseComponent;
expect(app.pageTitle).toBe('Load DataTables Options with Promise');
expect(app.pageTitle).toBe('Load DT Options with Promise');
}));

it('should render table from dtOptions as a Promise', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { HttpClient } from '@angular/common/http';
})
export class LoadDtOptionsWithPromiseComponent implements OnInit {

pageTitle = 'Load DataTables Options with Promise';
pageTitle = 'Load DT Options with Promise';
mdIntro = 'assets/docs/advanced/load-dt-opt-with-promise/intro.md';
mdHTML = 'assets/docs/advanced/load-dt-opt-with-promise/source-html.md';
mdTS = 'assets/docs/advanced/load-dt-opt-with-promise/source-ts.md';
Expand Down
3 changes: 3 additions & 0 deletions demo/src/app/advanced/multiple-tables.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
Display the DataTable instances in the console
</button>
</p>

<h5 class="header">Table 1</h5>
<table id="first-table" datatable [dtOptions]="dtOptions[0]" class="row-border hover"></table>
<h5 class="header">Table 2</h5>
<table id="second-table" datatable [dtOptions]="dtOptions[1]" class="row-border hover"></table>

</ng-template>
Expand Down
4 changes: 2 additions & 2 deletions demo/src/app/advanced/multiple-tables.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe('MultipleTablesComponent', () => {
expect(app).toBeTruthy();
}));

it('should have title "Multiple DataTables in the same page"', waitForAsync(() => {
it('should have title "Multiple tables in the same page"', waitForAsync(() => {
const app = fixture.debugElement.componentInstance as MultipleTablesComponent;
expect(app.pageTitle).toBe('Multiple DataTables in the same page');
expect(app.pageTitle).toBe('Multiple tables in the same page');
}));

it('should have two table instances in dtElements', async () => {
Expand Down
2 changes: 1 addition & 1 deletion demo/src/app/advanced/multiple-tables.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DataTableDirective } from 'angular-datatables';
})
export class MultipleTablesComponent implements OnInit {

pageTitle = 'Multiple DataTables in the same page';
pageTitle = 'Multiple tables in the same page';
mdIntro = 'assets/docs/advanced/multiple-tables/intro.md';
mdHTML = 'assets/docs/advanced/multiple-tables/source-html.md';
mdTS = 'assets/docs/advanced/multiple-tables/source-ts.md';
Expand Down
7 changes: 6 additions & 1 deletion demo/src/app/advanced/router-link.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<ng-template #preview>
<table datatable [dtOptions]="dtOptions" class="row-border hover"></table>
<table datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" class="row-border hover"></table>
</ng-template>

<ng-template #demoNg let-data="adtData" let-emitter="captureEvents">
<app-demo-ng-template-ref [data]="data" actionText="View" (emitter)="emitter($event)"></app-demo-ng-template-ref>
</ng-template>

<app-base-demo [pageTitle]="pageTitle" [mdIntro]="mdIntro" [mdHTML]="mdHTML"
[mdTS]="mdTS" [mdTSHeading]="mdTSHeading" [mdTSHigh]="mdTSHigh" [mdTSHighHeading]="mdTSHighHeading"
[template]="preview">
Expand Down
18 changes: 11 additions & 7 deletions demo/src/app/advanced/router-link.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { AppRoutingModule } from '../app.routing';
import { FormsModule } from '@angular/forms';
import { RouterLinkComponent } from './router-link.component';
import { Router } from '@angular/router';
import { By } from '@angular/platform-browser';
import { DemoNgComponent } from './demo-ng-template-ref.component';


let fixture: ComponentFixture<RouterLinkComponent>, component: RouterLinkComponent = null, router: Router = null;
Expand All @@ -18,6 +20,7 @@ describe('RouterLinkComponent', () => {
fixture = TestBed.configureTestingModule({
declarations: [
BaseDemoComponent,
DemoNgComponent,
RouterLinkComponent,
DataTableDirective
],
Expand Down Expand Up @@ -52,19 +55,20 @@ describe('RouterLinkComponent', () => {
expect(app.pageTitle).toBe('Router Link');
}));

it('should open Person info on click', async () => {
it('should respond to button click event inside TemplateRef', async () => {
await fixture.whenStable();

const query = fixture.debugElement.query(By.directive(DataTableDirective));
const dir = query.injector.get(DataTableDirective);
expect(dir).toBeTruthy();

const rSpy = spyOn(router, 'navigate');

const button = document.createElement('button');
button.setAttribute('view-person-id', '3');
fixture.nativeElement.appendChild(button);
const row: HTMLTableRowElement = fixture.nativeElement.querySelector('tbody tr:first-child');
const button: HTMLButtonElement = row.querySelector('button.btn-sm');
button.click();


fixture.detectChanges();
expect(rSpy).toHaveBeenCalledWith(["/person/3"]);
expect(rSpy).toHaveBeenCalled();
});

});
75 changes: 51 additions & 24 deletions demo/src/app/advanced/router-link.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { AfterViewInit, Component, OnInit, Renderer2 } from '@angular/core';
import { AfterViewInit, Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { ADTSettings } from 'angular-datatables/src/models/settings';
import { Subject } from 'rxjs';
import { IDemoNgComponentEventType } from './demo-ng-template-ref-event-type';
import { DemoNgComponent } from './demo-ng-template-ref.component';

@Component({
selector: 'app-router-link',
templateUrl: 'router-link.component.html'
})
export class RouterLinkComponent implements AfterViewInit, OnInit {
export class RouterLinkComponent implements AfterViewInit, OnInit, OnDestroy {

pageTitle = 'Router Link';
mdIntro = 'assets/docs/advanced/router-link/intro.md';
Expand All @@ -15,36 +19,59 @@ export class RouterLinkComponent implements AfterViewInit, OnInit {
mdTSHeading = 'TypeScript (Angular v9 and below)';
mdTSHighHeading = 'TypeScript (Angular v10 and above)';

dtOptions: DataTables.Settings = {};
dtOptions: ADTSettings = {};
dtTrigger = new Subject<ADTSettings>();

constructor(private renderer: Renderer2, private router: Router) { }
@ViewChild('demoNg') demoNg: TemplateRef<DemoNgComponent>;

constructor(
private router: Router
) { }

ngOnInit(): void {
}

ngAfterViewInit() {
const self = this;
// init here as we use ViewChild ref
this.dtOptions = {
ajax: 'data/data.json',
columns: [{
title: 'ID',
data: 'id'
}, {
title: 'First name',
data: 'firstName'
}, {
title: 'Last name',
data: 'lastName'
}, {
title: 'Action',
render: function (data: any, type: any, full: any) {
return '<button class="waves-effect btn" view-person-id="' + full.id + '">View</button>';
columns: [
{
title: 'ID',
data: 'id'
}, {
title: 'First name',
data: 'firstName'
}, {
title: 'Last name',
data: 'lastName'
},
{
title: 'Action',
defaultContent: '',
ngTemplateRef: {
ref: this.demoNg,
context: {
// needed for capturing events inside <ng-template>
captureEvents: self.onCaptureEvent.bind(self)
}
}
}
}]
]
};

// race condition fails unit tests if dtOptions isn't sent with dtTrigger
setTimeout(() => {
this.dtTrigger.next(this.dtOptions);
}, 200);
}

onCaptureEvent(event: IDemoNgComponentEventType) {
this.router.navigate(["/person/" + event.data.id]);
}

ngAfterViewInit(): void {
this.renderer.listen('document', 'click', (event) => {
if (event.target.hasAttribute("view-person-id")) {
this.router.navigate(["/person/" + event.target.getAttribute("view-person-id")]);
}
});
ngOnDestroy(): void {
this.dtTrigger?.unsubscribe();
}
}
4 changes: 2 additions & 2 deletions demo/src/app/app.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ ul.side-nav.fixed ul.collapsible-accordion .collapsible-body li a {
}

.side-nav .logo a {
height: 140px;
background-color: #66ceff;
height: 120px !important;
background-color: #2196f3;
color: #fff;
}

Expand Down
Loading