summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-result-set/run-report-result-set-datasource.ts
diff options
context:
space:
mode:
authormravula <mr257h@att.com>2020-08-31 12:29:32 -0400
committermravula <mr257h@att.com>2020-12-04 12:06:54 -0500
commit220a25a2566c90bc540e7190342f73824d2ff54a (patch)
treeef28fb72e267b842c197b807f5d06fcd990f7f4e /ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-result-set/run-report-result-set-datasource.ts
parentad2d7d08693ccb514d51e15505541bc55051a871 (diff)
Raptor UI Changes, user profile, folder restructure
Issue-ID: PORTAL-902 Change-Id: Ib76bb3fce7efe55504b75d2fc4764bafb9f8e908 Signed-off-by: mravula <mr257h@att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-result-set/run-report-result-set-datasource.ts')
-rw-r--r--ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-result-set/run-report-result-set-datasource.ts86
1 files changed, 86 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-result-set/run-report-result-set-datasource.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-result-set/run-report-result-set-datasource.ts
new file mode 100644
index 00000000..a6a515b5
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report-result-set/run-report-result-set-datasource.ts
@@ -0,0 +1,86 @@
+import { DataSource } from '@angular/cdk/collections';
+import { MatPaginator } from '@angular/material/paginator';
+import { MatSort } from '@angular/material/sort';
+import { map } from 'rxjs/operators';
+import { Observable, of as observableOf, merge } from 'rxjs';
+
+// TODO: Replace this with your own data model type
+export interface RunReportFinalTableItem {
+
+}
+
+// TODO: replace this with real data from your application
+
+
+/**
+ * Data source for the RunReportFinalTable view. This class should
+ * encapsulate all logic for fetching and manipulating the displayed data
+ * (including sorting, pagination, and filtering).
+ */
+export class RunReportFinalTableDataSource extends DataSource<RunReportFinalTableItem> {
+ data: RunReportFinalTableItem[];
+ paginator: MatPaginator;
+ sort: MatSort;
+
+ constructor() {
+ super();
+ }
+
+ /**
+ * Connect this data source to the table. The table will only update when
+ * the returned stream emits new items.
+ * @returns A stream of the items to be rendered.
+ */
+ connect(): Observable<RunReportFinalTableItem[]> {
+ // Combine everything that affects the rendered data into one update
+ // stream for the data-table to consume.
+ const dataMutations = [
+ observableOf(this.data),
+ this.paginator.page,
+ this.sort.sortChange
+ ];
+
+ return merge(...dataMutations).pipe(map(() => {
+ return this.getPagedData(this.getSortedData([...this.data]));
+ }));
+ }
+
+ /**
+ * Called when the table is being destroyed. Use this function, to clean up
+ * any open connections or free any held resources that were set up during connect.
+ */
+ disconnect() {}
+
+ /**
+ * Paginate the data (client-side). If you're using server-side pagination,
+ * this would be replaced by requesting the appropriate data from the server.
+ */
+ private getPagedData(data: RunReportFinalTableItem[]) {
+ const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
+ return data.splice(startIndex, this.paginator.pageSize);
+ }
+
+ /**
+ * Sort the data (client-side). If you're using server-side sorting,
+ * this would be replaced by requesting the appropriate data from the server.
+ */
+ private getSortedData(data: RunReportFinalTableItem[]) {
+ if (!this.sort.active || this.sort.direction === '') {
+ return data;
+ }
+
+ return data.sort((a, b) => {
+ const isAsc = this.sort.direction === 'asc';
+ switch (this.sort.active) {
+ // case 'name': return compare(a.name, b.name, isAsc);
+ // case 'id': return compare(+a.id, +b.id, isAsc);
+ default: return 0;
+ }
+ });
+ }
+}
+
+/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
+function compare(a, b, isAsc) {
+ return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
+}