From 5936d1c12ef895a020d449465412de6ebf6765a9 Mon Sep 17 00:00:00 2001 From: Arif Date: Thu, 15 Feb 2024 19:04:24 +0800 Subject: [PATCH 1/9] Save issue table settings --- src/app/app.module.ts | 4 ++++ .../services/issue-table-settings.service.ts | 10 ++++++++++ .../issue-tables/issue-tables.component.html | 17 +++++++++++++++-- .../issue-tables/issue-tables.component.ts | 16 ++++++++++++++-- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 src/app/core/services/issue-table-settings.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e82cbd181..5d566684a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -36,6 +36,7 @@ import { LabelDefinitionPopupComponent } from './shared/label-definition-popup/l import { HeaderComponent } from './shared/layout'; import { markedOptionsFactory } from './shared/lib/marked'; import { SharedModule } from './shared/shared.module'; +import { IssueTableSettingsService } from './core/services/issue-table-settings.service'; @NgModule({ declarations: [AppComponent, HeaderComponent, UserConfirmationComponent, LabelDefinitionPopupComponent, SessionFixConfirmationComponent], @@ -76,6 +77,9 @@ import { SharedModule } from './shared/shared.module'; { provide: ErrorHandler, useClass: ErrorHandlingService + }, + { + provide: IssueTableSettingsService } ], bootstrap: [AppComponent] diff --git a/src/app/core/services/issue-table-settings.service.ts b/src/app/core/services/issue-table-settings.service.ts new file mode 100644 index 000000000..ea4b4edd7 --- /dev/null +++ b/src/app/core/services/issue-table-settings.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from '@angular/core'; +@Injectable({ + providedIn: 'root' +}) +export class IssueTableSettingsService { + public sortActiveId = ''; + public sortDirection = ''; + public pageSize = 20; + public pageIndex = 0; +} diff --git a/src/app/shared/issue-tables/issue-tables.component.html b/src/app/shared/issue-tables/issue-tables.component.html index 777aa52bc..72cbcc3f4 100644 --- a/src/app/shared/issue-tables/issue-tables.component.html +++ b/src/app/shared/issue-tables/issue-tables.component.html @@ -1,4 +1,11 @@ - + ID @@ -262,4 +269,10 @@ - + diff --git a/src/app/shared/issue-tables/issue-tables.component.ts b/src/app/shared/issue-tables/issue-tables.component.ts index d428c8df2..553d5ec46 100644 --- a/src/app/shared/issue-tables/issue-tables.component.ts +++ b/src/app/shared/issue-tables/issue-tables.component.ts @@ -1,7 +1,7 @@ import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core'; -import { MatPaginator } from '@angular/material/paginator'; +import { MatPaginator, PageEvent } from '@angular/material/paginator'; import { MatSnackBar } from '@angular/material/snack-bar'; -import { MatSort } from '@angular/material/sort'; +import { MatSort, Sort } from '@angular/material/sort'; import { finalize } from 'rxjs/operators'; import { Issue, STATUS } from '../../core/models/issue.model'; import { DialogService } from '../../core/services/dialog.service'; @@ -15,6 +15,7 @@ import { PhaseService } from '../../core/services/phase.service'; import { UserService } from '../../core/services/user.service'; import { UndoActionComponent } from '../../shared/action-toasters/undo-action/undo-action.component'; import { IssuesDataTable } from './IssuesDataTable'; +import { IssueTableSettingsService } from '../../core/services/issue-table-settings.service'; export enum ACTION_BUTTONS { VIEW_IN_WEB, @@ -57,6 +58,7 @@ export class IssueTablesComponent implements OnInit, AfterViewInit { public labelService: LabelService, private githubService: GithubService, public issueService: IssueService, + public issueTableSettingsService: IssueTableSettingsService, private phaseService: PhaseService, private errorHandlingService: ErrorHandlingService, private logger: LoggingService, @@ -75,6 +77,16 @@ export class IssueTablesComponent implements OnInit, AfterViewInit { }); } + sortChange(newSort: Sort) { + this.issueTableSettingsService.sortActiveId = newSort.active; + this.issueTableSettingsService.sortDirection = newSort.direction; + } + + pageChange(pageEvent: PageEvent) { + this.issueTableSettingsService.pageSize = pageEvent.pageSize; + this.issueTableSettingsService.pageIndex = pageEvent.pageIndex; + } + isActionVisible(action: ACTION_BUTTONS): boolean { return this.actions.includes(action); } From 391bd7b271fbea042fa1499226dc805f97234601 Mon Sep 17 00:00:00 2001 From: Arif Date: Thu, 15 Feb 2024 19:07:07 +0800 Subject: [PATCH 2/9] Fix import order --- src/app/app.module.ts | 2 +- src/app/shared/issue-tables/issue-tables.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5d566684a..9309063ce 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,6 +23,7 @@ import { GithubServiceFactory } from './core/services/factories/factory.github.s import { IssueServiceFactory } from './core/services/factories/factory.issue.service'; import { GithubService } from './core/services/github.service'; import { GithubEventService } from './core/services/githubevent.service'; +import { IssueTableSettingsService } from './core/services/issue-table-settings.service'; import { IssueService } from './core/services/issue.service'; import { LoggingService } from './core/services/logging.service'; import { PhaseService } from './core/services/phase.service'; @@ -36,7 +37,6 @@ import { LabelDefinitionPopupComponent } from './shared/label-definition-popup/l import { HeaderComponent } from './shared/layout'; import { markedOptionsFactory } from './shared/lib/marked'; import { SharedModule } from './shared/shared.module'; -import { IssueTableSettingsService } from './core/services/issue-table-settings.service'; @NgModule({ declarations: [AppComponent, HeaderComponent, UserConfirmationComponent, LabelDefinitionPopupComponent, SessionFixConfirmationComponent], diff --git a/src/app/shared/issue-tables/issue-tables.component.ts b/src/app/shared/issue-tables/issue-tables.component.ts index 553d5ec46..369e9ad27 100644 --- a/src/app/shared/issue-tables/issue-tables.component.ts +++ b/src/app/shared/issue-tables/issue-tables.component.ts @@ -7,6 +7,7 @@ import { Issue, STATUS } from '../../core/models/issue.model'; import { DialogService } from '../../core/services/dialog.service'; import { ErrorHandlingService } from '../../core/services/error-handling.service'; import { GithubService } from '../../core/services/github.service'; +import { IssueTableSettingsService } from '../../core/services/issue-table-settings.service'; import { IssueService } from '../../core/services/issue.service'; import { LabelService } from '../../core/services/label.service'; import { LoggingService } from '../../core/services/logging.service'; @@ -15,7 +16,6 @@ import { PhaseService } from '../../core/services/phase.service'; import { UserService } from '../../core/services/user.service'; import { UndoActionComponent } from '../../shared/action-toasters/undo-action/undo-action.component'; import { IssuesDataTable } from './IssuesDataTable'; -import { IssueTableSettingsService } from '../../core/services/issue-table-settings.service'; export enum ACTION_BUTTONS { VIEW_IN_WEB, From fbc5bc1e708b6e86079170d90dd2a9e415bf4fda Mon Sep 17 00:00:00 2001 From: Arif Date: Thu, 15 Feb 2024 20:04:10 +0800 Subject: [PATCH 3/9] Add multiple settings for multiple tables --- src/app/app.module.ts | 3 --- src/app/core/models/table-settings.model.ts | 6 ++++++ .../services/issue-table-settings.service.ts | 18 ++++++++++++++---- .../issue-tables/issue-tables.component.html | 8 ++++---- .../issue-tables/issue-tables.component.ts | 14 ++++++++++---- src/app/shared/layout/header.component.ts | 7 ++++++- 6 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 src/app/core/models/table-settings.model.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 9309063ce..728551000 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -77,9 +77,6 @@ import { SharedModule } from './shared/shared.module'; { provide: ErrorHandler, useClass: ErrorHandlingService - }, - { - provide: IssueTableSettingsService } ], bootstrap: [AppComponent] diff --git a/src/app/core/models/table-settings.model.ts b/src/app/core/models/table-settings.model.ts new file mode 100644 index 000000000..cd74ad1cc --- /dev/null +++ b/src/app/core/models/table-settings.model.ts @@ -0,0 +1,6 @@ +export class TableSettings { + public sortActiveId = ''; + public sortDirection = ''; + public pageSize = 20; + public pageIndex = 0; +} diff --git a/src/app/core/services/issue-table-settings.service.ts b/src/app/core/services/issue-table-settings.service.ts index ea4b4edd7..e3c3f85c0 100644 --- a/src/app/core/services/issue-table-settings.service.ts +++ b/src/app/core/services/issue-table-settings.service.ts @@ -1,10 +1,20 @@ import { Injectable } from '@angular/core'; +import { TableSettings } from '../models/table-settings.model'; @Injectable({ providedIn: 'root' }) export class IssueTableSettingsService { - public sortActiveId = ''; - public sortDirection = ''; - public pageSize = 20; - public pageIndex = 0; + private _tableSettingsMap = {}; + + public getTableSettings(tableName: string) { + return this._tableSettingsMap[tableName] || new TableSettings(); + } + + public setTableSettings(tableName: string, tableSettings: TableSettings) { + this._tableSettingsMap[tableName] = tableSettings; + } + + public clearTableSettings() { + this._tableSettingsMap = {}; + } } diff --git a/src/app/shared/issue-tables/issue-tables.component.html b/src/app/shared/issue-tables/issue-tables.component.html index 72cbcc3f4..1279476cf 100644 --- a/src/app/shared/issue-tables/issue-tables.component.html +++ b/src/app/shared/issue-tables/issue-tables.component.html @@ -1,8 +1,8 @@ @@ -271,8 +271,8 @@ diff --git a/src/app/shared/issue-tables/issue-tables.component.ts b/src/app/shared/issue-tables/issue-tables.component.ts index 369e9ad27..8eac80d19 100644 --- a/src/app/shared/issue-tables/issue-tables.component.ts +++ b/src/app/shared/issue-tables/issue-tables.component.ts @@ -16,6 +16,7 @@ import { PhaseService } from '../../core/services/phase.service'; import { UserService } from '../../core/services/user.service'; import { UndoActionComponent } from '../../shared/action-toasters/undo-action/undo-action.component'; import { IssuesDataTable } from './IssuesDataTable'; +import { TableSettings } from '../../core/models/table-settings.model'; export enum ACTION_BUTTONS { VIEW_IN_WEB, @@ -45,6 +46,8 @@ export class IssueTablesComponent implements OnInit, AfterViewInit { issues: IssuesDataTable; issuesPendingDeletion: { [id: number]: boolean }; + public tableSettings: TableSettings; + public readonly action_buttons = ACTION_BUTTONS; // Messages for the modal popup window upon deleting an issue @@ -69,6 +72,7 @@ export class IssueTablesComponent implements OnInit, AfterViewInit { ngOnInit() { this.issues = new IssuesDataTable(this.issueService, this.sort, this.paginator, this.headers, this.filters); this.issuesPendingDeletion = {}; + this.tableSettings = this.issueTableSettingsService.getTableSettings(this.table_name); } ngAfterViewInit(): void { @@ -78,13 +82,15 @@ export class IssueTablesComponent implements OnInit, AfterViewInit { } sortChange(newSort: Sort) { - this.issueTableSettingsService.sortActiveId = newSort.active; - this.issueTableSettingsService.sortDirection = newSort.direction; + this.tableSettings.sortActiveId = newSort.active; + this.tableSettings.sortDirection = newSort.direction; + this.issueTableSettingsService.setTableSettings(this.table_name, this.tableSettings); } pageChange(pageEvent: PageEvent) { - this.issueTableSettingsService.pageSize = pageEvent.pageSize; - this.issueTableSettingsService.pageIndex = pageEvent.pageIndex; + this.tableSettings.pageSize = pageEvent.pageSize; + this.tableSettings.pageIndex = pageEvent.pageIndex; + this.issueTableSettingsService.setTableSettings(this.table_name, this.tableSettings); } isActionVisible(action: ACTION_BUTTONS): boolean { diff --git a/src/app/shared/layout/header.component.ts b/src/app/shared/layout/header.component.ts index 9f6588d05..384c5d941 100644 --- a/src/app/shared/layout/header.component.ts +++ b/src/app/shared/layout/header.component.ts @@ -14,6 +14,7 @@ import { IssueService } from '../../core/services/issue.service'; import { LoggingService } from '../../core/services/logging.service'; import { PhaseDescription, PhaseService } from '../../core/services/phase.service'; import { UserService } from '../../core/services/user.service'; +import { IssueTableSettingsService } from '../../core/services/issue-table-settings.service'; const ISSUE_TRACKER_URL = 'https://github.com/CATcher-org/CATcher/issues'; @@ -45,7 +46,8 @@ export class HeaderComponent implements OnInit { private issueService: IssueService, private errorHandlingService: ErrorHandlingService, private githubService: GithubService, - private dialogService: DialogService + private dialogService: DialogService, + private issueTableSettingsService: IssueTableSettingsService ) { router.events .pipe( @@ -81,6 +83,9 @@ export class HeaderComponent implements OnInit { this.issueService.reset(false); this.reload(); + // Reset Issue Table Settings + this.issueTableSettingsService.clearTableSettings(); + // Route app to new phase. this.router.navigateByUrl(this.phaseService.currentPhase); } From 7ec259df1e70cb269823bb0ee83801ac7fdf96df Mon Sep 17 00:00:00 2001 From: Arif Date: Thu, 15 Feb 2024 20:06:38 +0800 Subject: [PATCH 4/9] Fix import order --- src/app/shared/issue-tables/issue-tables.component.ts | 2 +- src/app/shared/layout/header.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/shared/issue-tables/issue-tables.component.ts b/src/app/shared/issue-tables/issue-tables.component.ts index 8eac80d19..2969dbcff 100644 --- a/src/app/shared/issue-tables/issue-tables.component.ts +++ b/src/app/shared/issue-tables/issue-tables.component.ts @@ -4,6 +4,7 @@ import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSort, Sort } from '@angular/material/sort'; import { finalize } from 'rxjs/operators'; import { Issue, STATUS } from '../../core/models/issue.model'; +import { TableSettings } from '../../core/models/table-settings.model'; import { DialogService } from '../../core/services/dialog.service'; import { ErrorHandlingService } from '../../core/services/error-handling.service'; import { GithubService } from '../../core/services/github.service'; @@ -16,7 +17,6 @@ import { PhaseService } from '../../core/services/phase.service'; import { UserService } from '../../core/services/user.service'; import { UndoActionComponent } from '../../shared/action-toasters/undo-action/undo-action.component'; import { IssuesDataTable } from './IssuesDataTable'; -import { TableSettings } from '../../core/models/table-settings.model'; export enum ACTION_BUTTONS { VIEW_IN_WEB, diff --git a/src/app/shared/layout/header.component.ts b/src/app/shared/layout/header.component.ts index 384c5d941..9c491fe15 100644 --- a/src/app/shared/layout/header.component.ts +++ b/src/app/shared/layout/header.component.ts @@ -10,11 +10,11 @@ import { DialogService } from '../../core/services/dialog.service'; import { ErrorHandlingService } from '../../core/services/error-handling.service'; import { GithubService } from '../../core/services/github.service'; import { GithubEventService } from '../../core/services/githubevent.service'; +import { IssueTableSettingsService } from '../../core/services/issue-table-settings.service'; import { IssueService } from '../../core/services/issue.service'; import { LoggingService } from '../../core/services/logging.service'; import { PhaseDescription, PhaseService } from '../../core/services/phase.service'; import { UserService } from '../../core/services/user.service'; -import { IssueTableSettingsService } from '../../core/services/issue-table-settings.service'; const ISSUE_TRACKER_URL = 'https://github.com/CATcher-org/CATcher/issues'; From 67c2c85bafefc471762ea3a498d5d93ae3cadf9f Mon Sep 17 00:00:00 2001 From: Arif Date: Thu, 15 Feb 2024 20:09:53 +0800 Subject: [PATCH 5/9] Document new service --- src/app/core/services/issue-table-settings.service.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app/core/services/issue-table-settings.service.ts b/src/app/core/services/issue-table-settings.service.ts index e3c3f85c0..13ef32c20 100644 --- a/src/app/core/services/issue-table-settings.service.ts +++ b/src/app/core/services/issue-table-settings.service.ts @@ -3,6 +3,11 @@ import { TableSettings } from '../models/table-settings.model'; @Injectable({ providedIn: 'root' }) + +/** + * Responsible for storing and retrieving the table settings for issue tables created + * Map is required since there can be multiple tables within the same page + */ export class IssueTableSettingsService { private _tableSettingsMap = {}; From e6f3b8e4be07b007e103c4a4f3e4f56740062c5a Mon Sep 17 00:00:00 2001 From: Arif Date: Thu, 15 Feb 2024 20:28:09 +0800 Subject: [PATCH 6/9] Remove unused import --- src/app/app.module.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 728551000..e82cbd181 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,7 +23,6 @@ import { GithubServiceFactory } from './core/services/factories/factory.github.s import { IssueServiceFactory } from './core/services/factories/factory.issue.service'; import { GithubService } from './core/services/github.service'; import { GithubEventService } from './core/services/githubevent.service'; -import { IssueTableSettingsService } from './core/services/issue-table-settings.service'; import { IssueService } from './core/services/issue.service'; import { LoggingService } from './core/services/logging.service'; import { PhaseService } from './core/services/phase.service'; From 511c4f563e40351af98ee3169af2e20a1013eb9a Mon Sep 17 00:00:00 2001 From: Arif Date: Sun, 18 Feb 2024 01:23:32 +0800 Subject: [PATCH 7/9] Add type annotation --- src/app/core/services/issue-table-settings.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/core/services/issue-table-settings.service.ts b/src/app/core/services/issue-table-settings.service.ts index 13ef32c20..85f6723d8 100644 --- a/src/app/core/services/issue-table-settings.service.ts +++ b/src/app/core/services/issue-table-settings.service.ts @@ -9,9 +9,10 @@ import { TableSettings } from '../models/table-settings.model'; * Map is required since there can be multiple tables within the same page */ export class IssueTableSettingsService { - private _tableSettingsMap = {}; + private _tableSettingsMap: { [index: string]: TableSettings } = {}; public getTableSettings(tableName: string) { + console.log(this._tableSettingsMap); return this._tableSettingsMap[tableName] || new TableSettings(); } From fd7882d93e925b0ce94b34f39865638cc7680ebe Mon Sep 17 00:00:00 2001 From: Arif Date: Sun, 18 Feb 2024 01:25:26 +0800 Subject: [PATCH 8/9] Add return type annotation for methods --- src/app/core/services/issue-table-settings.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/core/services/issue-table-settings.service.ts b/src/app/core/services/issue-table-settings.service.ts index 85f6723d8..a65be3d52 100644 --- a/src/app/core/services/issue-table-settings.service.ts +++ b/src/app/core/services/issue-table-settings.service.ts @@ -11,16 +11,16 @@ import { TableSettings } from '../models/table-settings.model'; export class IssueTableSettingsService { private _tableSettingsMap: { [index: string]: TableSettings } = {}; - public getTableSettings(tableName: string) { + public getTableSettings(tableName: string): TableSettings { console.log(this._tableSettingsMap); return this._tableSettingsMap[tableName] || new TableSettings(); } - public setTableSettings(tableName: string, tableSettings: TableSettings) { + public setTableSettings(tableName: string, tableSettings: TableSettings): void { this._tableSettingsMap[tableName] = tableSettings; } - public clearTableSettings() { + public clearTableSettings(): void { this._tableSettingsMap = {}; } } From 63ddff1956457a7e9e7a39259db60b28dda0ed11 Mon Sep 17 00:00:00 2001 From: Arif Date: Mon, 19 Feb 2024 14:34:20 +0800 Subject: [PATCH 9/9] Add comments --- src/app/core/models/table-settings.model.ts | 2 +- src/app/core/services/issue-table-settings.service.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app/core/models/table-settings.model.ts b/src/app/core/models/table-settings.model.ts index cd74ad1cc..174ab6bc8 100644 --- a/src/app/core/models/table-settings.model.ts +++ b/src/app/core/models/table-settings.model.ts @@ -1,5 +1,5 @@ export class TableSettings { - public sortActiveId = ''; + public sortActiveId = ''; // The ID of the column the table is sorted by public sortDirection = ''; public pageSize = 20; public pageIndex = 0; diff --git a/src/app/core/services/issue-table-settings.service.ts b/src/app/core/services/issue-table-settings.service.ts index a65be3d52..2cfdbad7b 100644 --- a/src/app/core/services/issue-table-settings.service.ts +++ b/src/app/core/services/issue-table-settings.service.ts @@ -12,7 +12,6 @@ export class IssueTableSettingsService { private _tableSettingsMap: { [index: string]: TableSettings } = {}; public getTableSettings(tableName: string): TableSettings { - console.log(this._tableSettingsMap); return this._tableSettingsMap[tableName] || new TableSettings(); }