Skip to content

Commit 6a4d682

Browse files
committed
chore(*): update finjs sample as samples browser logic
1 parent 39eb509 commit 6a4d682

File tree

6 files changed

+52
-153
lines changed

6 files changed

+52
-153
lines changed

src/app/grid-finjs/controllers.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="controls-holder">
33
<div class="switches">
44
<div class="control-item">
5-
<igx-switch [checked]="false" [(ngModel)]="theme" (change)="onChange('theme', $event)">Dark</igx-switch>
5+
<igx-switch [checked]="false" (change)="onChange('theme', $event)">Dark</igx-switch>
66
</div>
77
<div class="control-item">
88
<igx-switch [checked]="true" (change)="onChange('grouped', $event)" color="blue" cssClass="finjs-sample-switch">

src/app/grid-finjs/controllers.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class ControllerComponent implements OnInit, OnDestroy {
1818
@Output() public volumeChanged = new EventEmitter<any>();
1919
@Output() public playAction = new EventEmitter<any>();
2020

21-
public theme = false;
21+
public darkTheme = true;
2222
public volume = 1000;
2323
public frequency = 500;
2424
public controls = [

src/app/grid-finjs/grid-finjs.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
displayDensity='compact'
55
hiddenColumnsText="Hidden"
66
primaryKey='ID'
7+
[(groupingExpressions)]="groupingExpressions"
78
[autoGenerate]='false'
89
[data]="data"
910
[hideGroupedColumns]="true"
Lines changed: 28 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,56 @@
11
import {
22
Component,
3-
EventEmitter,
4-
OnDestroy,
5-
OnInit,
6-
Output,
3+
Input,
74
ViewChild } from '@angular/core';
85
import {
96
DefaultSortingStrategy,
107
IgxGridComponent,
118
SortingDirection
129
} from 'igniteui-angular';
1310
import { Contract, REGIONS } from '../shared/financialData';
14-
import { LocalService } from '../shared/local.service';
11+
12+
const GROUPING_EXPRESSIONS = [{
13+
dir: SortingDirection.Desc,
14+
fieldName: 'Category',
15+
ignoreCase: false,
16+
strategy: DefaultSortingStrategy.instance()
17+
},
18+
{
19+
dir: SortingDirection.Desc,
20+
fieldName: 'Type',
21+
ignoreCase: false,
22+
strategy: DefaultSortingStrategy.instance()
23+
},
24+
{
25+
dir: SortingDirection.Desc,
26+
fieldName: 'Contract',
27+
ignoreCase: false,
28+
strategy: DefaultSortingStrategy.instance()
29+
}
30+
];
1531

1632
@Component({
1733
selector: 'app-finjs-grid',
1834
styleUrls: ['./grid-finjs.component.scss'],
1935
templateUrl: './grid-finjs.component.html'
2036
})
21-
export class GridFinJSComponent implements OnInit, OnDestroy {
37+
export class GridFinJSComponent {
2238
@ViewChild('grid1', { static: true }) public grid: IgxGridComponent;
2339

24-
@Output() public selectedDataChanged = new EventEmitter<any>();
25-
@Output() public keyDown = new EventEmitter<any>();
26-
@Output() public chartColumnKeyDown = new EventEmitter<any>();
40+
@Input()
41+
public data: any;
2742

28-
public data = [];
2943
public selectionMode = 'multiple';
3044
public contracts = Contract;
3145
public regions = REGIONS;
3246
public columnFormat = { digitsInfo: '1.3-3'};
3347
public showToolbar = true;
34-
public volume = 1000;
35-
public frequency = 500;
36-
private subscription$;
37-
38-
constructor(public finService: LocalService) {
39-
this.finService.getFinancialData(this.volume);
40-
this.subscription$ = this.finService.records.subscribe(x => {
41-
this.data = x;
42-
});
43-
}
44-
45-
public ngOnInit() {
46-
this.grid.groupingExpressions = [{
47-
dir: SortingDirection.Desc,
48-
fieldName: 'Category',
49-
ignoreCase: false,
50-
strategy: DefaultSortingStrategy.instance()
51-
},
52-
{
53-
dir: SortingDirection.Desc,
54-
fieldName: 'Type',
55-
ignoreCase: false,
56-
strategy: DefaultSortingStrategy.instance()
57-
},
58-
{
59-
dir: SortingDirection.Desc,
60-
fieldName: 'Settlement',
61-
ignoreCase: false,
62-
strategy: DefaultSortingStrategy.instance()
63-
}
64-
];
65-
}
48+
public groupingExpressions = GROUPING_EXPRESSIONS;
6649

67-
public ngOnDestroy() {
68-
if (this.subscription$) {
69-
this.subscription$.unsubscribe();
70-
}
71-
}
72-
73-
/** Event Handlers */
74-
75-
public onChange() {
76-
if (this.grid.groupingExpressions.length > 0) {
77-
this.grid.groupingExpressions = [];
78-
} else {
79-
this.grid.groupingExpressions = [{
80-
dir: SortingDirection.Desc,
81-
fieldName: 'Category',
82-
ignoreCase: false,
83-
strategy: DefaultSortingStrategy.instance()
84-
},
85-
{
86-
dir: SortingDirection.Desc,
87-
fieldName: 'Type',
88-
ignoreCase: false,
89-
strategy: DefaultSortingStrategy.instance()
90-
},
91-
{
92-
dir: SortingDirection.Desc,
93-
fieldName: 'Contract',
94-
ignoreCase: false,
95-
strategy: DefaultSortingStrategy.instance()
96-
}
97-
];
98-
}
99-
}
50+
constructor() { }
10051

101-
public toggleGrouping() {
102-
if (this.grid.groupingExpressions.length > 0) {
103-
this.grid.groupingExpressions = [];
104-
} else {
105-
this.grid.groupingExpressions = [{
106-
dir: SortingDirection.Desc,
107-
fieldName: 'Category',
108-
ignoreCase: false,
109-
strategy: DefaultSortingStrategy.instance()
110-
},
111-
{
112-
dir: SortingDirection.Desc,
113-
fieldName: 'Type',
114-
ignoreCase: false,
115-
strategy: DefaultSortingStrategy.instance()
116-
},
117-
{
118-
dir: SortingDirection.Desc,
119-
fieldName: 'Contract',
120-
ignoreCase: false,
121-
strategy: DefaultSortingStrategy.instance()
122-
}
123-
];
124-
}
52+
public toggleGrouping(newValue: boolean) {
53+
this.groupingExpressions = newValue ? GROUPING_EXPRESSIONS : [];
12554
}
12655

12756
/** Grid CellStyles and CellClasses */
@@ -132,7 +61,6 @@ export class GridFinJSComponent implements OnInit, OnDestroy {
13261
private strongPositive = (rowData: any): boolean => rowData['Change(%)'] >= 1;
13362
private strongNegative = (rowData: any): boolean => rowData['Change(%)'] <= -1;
13463

135-
/* eslint-disable @typescript-eslint/member-ordering */
13664
public trends = {
13765
changeNeg: this.changeNegative,
13866
changePos: this.changePositive,
@@ -148,9 +76,4 @@ export class GridFinJSComponent implements OnInit, OnDestroy {
14876
strongNegative2: this.strongNegative,
14977
strongPositive2: this.strongPositive
15078
};
151-
/* eslint-enable @typescript-eslint/member-ordering */
152-
153-
public get grouped(): boolean {
154-
return this.grid.groupingExpressions.length > 0;
155-
}
15679
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<div class="grid__wrapper" [class.fin-dark-theme]="theme">
1+
<div class="grid__wrapper" [class.fin-dark-theme]="darkTheme">
22
<app-finjs-controllers #controllers
33
(switchChanged)="onSwitchChanged($event)"
44
(volumeChanged)="onVolumeChanged($event)"
55
(playAction)="onPlayAction($event)">
66
</app-finjs-controllers>
7-
<app-finjs-grid #grid>
7+
<app-finjs-grid #grid [data]="data$ | async">
88
</app-finjs-grid>
99
</div>
Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
1-
import { AfterViewInit, Component, EventEmitter, OnDestroy, Output, ViewChild } from '@angular/core';
2-
import { FinancialData } from '../shared/financialData';
1+
import { Component, EventEmitter, OnDestroy, Output, ViewChild } from '@angular/core';
2+
import { Subject } from 'rxjs';
3+
import { takeUntil } from 'rxjs/operators';
4+
import { LocalService } from '../shared/local.service';
35
import { ControllerComponent } from './controllers.component';
46
import { GridFinJSComponent } from './grid-finjs.component';
57

68
@Component({
9+
providers: [LocalService],
710
selector: 'app-finjs-main',
811
styleUrls: ['./main.component.scss'],
912
templateUrl: './main.component.html'
1013
})
11-
export class MainComponent implements AfterViewInit, OnDestroy {
14+
export class MainComponent implements OnDestroy {
1215
@ViewChild('grid', { static: true }) public finGrid: GridFinJSComponent;
1316
@ViewChild('controllers', { static: true }) public controller: ControllerComponent;
1417

1518
@Output() public switch = new EventEmitter<any>();
1619
@Output() public recordsVolume = new EventEmitter<any>();
1720
@Output() public frequencyTimer = new EventEmitter<any>();
1821
@Output() public player = new EventEmitter<any>();
19-
public theme = false;
22+
2023
public volume = 1000;
2124
public frequency = 500;
22-
23-
private subscription$;
25+
public darkTheme = true;
26+
public data$: any;
27+
private destroy$ = new Subject<any>();
2428
private _timer;
2529

26-
constructor() { }
27-
28-
public ngAfterViewInit() {
29-
// this.subscription$ = this.localService.records.subscribe(x => {
30-
// this.finGrid.data = x;
31-
// });
30+
constructor(public finService: LocalService) {
31+
this.finService.getFinancialData(this.volume);
32+
this.data$ = this.finService.records.pipe(takeUntil(this.destroy$));
3233
}
3334

3435
public ngOnDestroy() {
36+
this.destroy$.next(true);
37+
this.destroy$.complete();
3538
this.stopFeed();
3639
}
3740

@@ -42,11 +45,7 @@ export class MainComponent implements AfterViewInit, OnDestroy {
4245
break;
4346
}
4447
case 'grouped': {
45-
this.finGrid.toggleGrouping();
46-
break;
47-
}
48-
case 'theme': {
49-
this.changeTheme(event.value);
48+
this.finGrid.toggleGrouping(event.value);
5049
break;
5150
}
5251
default:
@@ -58,19 +57,19 @@ export class MainComponent implements AfterViewInit, OnDestroy {
5857

5958
public onVolumeChanged(volume: any) {
6059
this.finGrid.grid.deselectAllRows();
61-
this.finGrid.finService.getFinancialData(volume);
60+
this.finService.getFinancialData(volume);
6261
}
6362

6463
public onPlayAction(event: any) {
6564
switch (event.action) {
6665
case 'playAll': {
6766
const currData = this.finGrid.grid.filteredSortedData ?? this.finGrid.data;
68-
this._timer = setInterval(() => this.finGrid.finService.updateAllPriceValues(currData), this.controller.frequency);
67+
this._timer = setInterval(() => this.finService.updateAllPriceValues(currData), this.controller.frequency);
6968
break;
7069
}
7170
case 'playRandom': {
7271
const currData = this.finGrid.data;
73-
this._timer = setInterval(() => this.finGrid.finService.updateRandomPriceValues(currData), this.controller.frequency);
72+
this._timer = setInterval(() => this.finService.updateRandomPriceValues(currData), this.controller.frequency);
7473
break;
7574
}
7675
case 'stop': {
@@ -84,33 +83,9 @@ export class MainComponent implements AfterViewInit, OnDestroy {
8483
}
8584
}
8685

87-
/**
88-
* the below code is needed when accessing the sample through the navigation
89-
* it will style all the space below the sample component element, but not the navigation menu
90-
*/
91-
public changeTheme(dark: true) {
92-
const parentEl = this.parentComponentEl();
93-
if (dark && parentEl.classList.contains('main')) {
94-
parentEl.classList.add('fin-dark-theme');
95-
} else {
96-
parentEl.classList.remove('fin-dark-theme');
97-
}
98-
}
99-
10086
public stopFeed() {
10187
if (this._timer) {
10288
clearInterval(this._timer);
10389
}
104-
if (this.subscription$) {
105-
this.subscription$.unsubscribe();
106-
}
107-
}
108-
109-
/**
110-
* returns the main div container of the Index Component,
111-
* if path is /samples/sample-url, or the appRoot, if path is /sample-url
112-
*/
113-
private parentComponentEl() {
114-
return this.elRef.nativeElement.parentElement.parentElement;
11590
}
11691
}

0 commit comments

Comments
 (0)