From b944afa618373a05d146a4c3f623417b6bcd2c6f Mon Sep 17 00:00:00 2001 From: strayge Date: Fri, 6 Nov 2020 00:33:25 +0300 Subject: [PATCH 1/2] save columns sort state at "get addons" --- .../pages/get-addons/get-addons.component.html | 4 ++-- .../pages/get-addons/get-addons.component.ts | 15 ++++++++++++++- .../src/app/services/wowup/wowup.service.ts | 18 ++++++++++++++++++ wowup-electron/src/common/constants.ts | 2 ++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/wowup-electron/src/app/pages/get-addons/get-addons.component.html b/wowup-electron/src/app/pages/get-addons/get-addons.component.html index 02e4bfa8..605d1f78 100644 --- a/wowup-electron/src/app/pages/get-addons/get-addons.component.html +++ b/wowup-electron/src/app/pages/get-addons/get-addons.component.html @@ -100,8 +100,8 @@ matSort (matSortChange)="onSortChange()" [dataSource]="dataSource" - matSortActive="downloadCount" - matSortDirection="desc" + [matSortActive]="activeSort" + [matSortDirection]="activeSortDirection" class="mat-elevation-z8" > diff --git a/wowup-electron/src/app/pages/get-addons/get-addons.component.ts b/wowup-electron/src/app/pages/get-addons/get-addons.component.ts index 23600914..385c7040 100644 --- a/wowup-electron/src/app/pages/get-addons/get-addons.component.ts +++ b/wowup-electron/src/app/pages/get-addons/get-addons.component.ts @@ -47,6 +47,8 @@ export class GetAddonsComponent implements OnInit, OnDestroy { private _lazyLoaded: boolean = false; public dataSource = new MatTableDataSource([]); + public activeSort = "downloadCount"; + public activeSortDirection = "desc"; columns: ColumnState[] = [ { name: "name", display: "Addon", visible: true }, @@ -97,7 +99,13 @@ export class GetAddonsComponent implements OnInit, OnDestroy { }); } - ngOnInit(): void {} + ngOnInit(): void { + const sortOrder = this._wowUpService.getAddonsSortOrder; + if(sortOrder){ + this.activeSort = sortOrder.name; + this.activeSortDirection = sortOrder.direction; + } + } ngOnDestroy() { this._subscriptions.forEach((sub) => sub.unsubscribe()); @@ -108,6 +116,11 @@ export class GetAddonsComponent implements OnInit, OnDestroy { if (this.table) { this.table.nativeElement.scrollIntoView({ behavior: "smooth" }); } + + this._wowUpService.getAddonsSortOrder = { + name: this.sort.active, + direction: this.sort.start || "", + }; } onStatusColumnUpdated() { diff --git a/wowup-electron/src/app/services/wowup/wowup.service.ts b/wowup-electron/src/app/services/wowup/wowup.service.ts index a5326fc7..0548409b 100644 --- a/wowup-electron/src/app/services/wowup/wowup.service.ts +++ b/wowup-electron/src/app/services/wowup/wowup.service.ts @@ -24,6 +24,8 @@ import { SELECTED_LANGUAGE_PREFERENCE_KEY, MY_ADDONS_HIDDEN_COLUMNS_KEY, MY_ADDONS_SORT_ORDER, + GET_ADDONS_HIDDEN_COLUMNS_KEY, + GET_ADDONS_SORT_ORDER, } from "../../../common/constants"; import { WowClientType } from "../../models/warcraft/wow-client-type"; import { AddonChannelType } from "../../models/wowup/addon-channel-type"; @@ -210,6 +212,22 @@ export class WowUpService { this._preferenceStorageService.setObject(MY_ADDONS_SORT_ORDER, sortOrder); } + public get getAddonsHiddenColumns() { + return this._preferenceStorageService.getObject(GET_ADDONS_HIDDEN_COLUMNS_KEY) || []; + } + + public set getAddonsHiddenColumns(columnStates: ColumnState[]) { + this._preferenceStorageService.setObject(GET_ADDONS_HIDDEN_COLUMNS_KEY, columnStates); + } + + public get getAddonsSortOrder(): SortOrder { + return this._preferenceStorageService.getObject(GET_ADDONS_SORT_ORDER); + } + + public set getAddonsSortOrder(sortOrder: SortOrder) { + this._preferenceStorageService.setObject(GET_ADDONS_SORT_ORDER, sortOrder); + } + public getClientDefaultAddonChannelKey(clientType: WowClientType) { const typeName = getEnumName(WowClientType, clientType); return `${typeName}${DEFAULT_CHANNEL_PREFERENCE_KEY_SUFFIX}`.toLowerCase(); diff --git a/wowup-electron/src/common/constants.ts b/wowup-electron/src/common/constants.ts index 0e80c666..d30ccb40 100644 --- a/wowup-electron/src/common/constants.ts +++ b/wowup-electron/src/common/constants.ts @@ -31,6 +31,8 @@ export const NO_LATEST_SEARCH_RESULT_FILES_ERROR = "NO_LATEST_SEARCH_RESULT_FILE export const SELECTED_LANGUAGE_PREFERENCE_KEY = "selected_language"; export const MY_ADDONS_HIDDEN_COLUMNS_KEY = "my_addons_hidden_columns"; export const MY_ADDONS_SORT_ORDER = "my_addons_sort_order"; +export const GET_ADDONS_HIDDEN_COLUMNS_KEY = "get_addons_hidden_columns"; +export const GET_ADDONS_SORT_ORDER = "get_addons_sort_order"; // APP UPDATER export const APP_UPDATE_ERROR = "app-update-error"; From 58821c4599b56c7b07d4c9a5eb3e317488038a72 Mon Sep 17 00:00:00 2001 From: strayge Date: Fri, 6 Nov 2020 00:50:01 +0300 Subject: [PATCH 2/2] show/hide columns at "get addons" --- .../get-addons/get-addons.component.html | 32 ++++++++++++- .../pages/get-addons/get-addons.component.ts | 45 +++++++++++++++++-- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/wowup-electron/src/app/pages/get-addons/get-addons.component.html b/wowup-electron/src/app/pages/get-addons/get-addons.component.html index 605d1f78..921cb1d5 100644 --- a/wowup-electron/src/app/pages/get-addons/get-addons.component.html +++ b/wowup-electron/src/app/pages/get-addons/get-addons.component.html @@ -197,7 +197,10 @@ - + + + +
+ + +
+
+ {{ "PAGES.MY_ADDONS.COLUMNS_CONTEXT_MENU.TITLE" | translate }} +
+
+ + + {{ column.display | translate }} + +
+
diff --git a/wowup-electron/src/app/pages/get-addons/get-addons.component.ts b/wowup-electron/src/app/pages/get-addons/get-addons.component.ts index 385c7040..852f7ef1 100644 --- a/wowup-electron/src/app/pages/get-addons/get-addons.component.ts +++ b/wowup-electron/src/app/pages/get-addons/get-addons.component.ts @@ -29,6 +29,8 @@ import { AddonService } from "../../services/addons/addon.service"; import { SessionService } from "../../services/session/session.service"; import { WarcraftService } from "../../services/warcraft/warcraft.service"; import { WowUpService } from "../../services/wowup/wowup.service"; +import { MatMenuTrigger } from "@angular/material/menu"; +import { MatCheckboxChange } from "@angular/material/checkbox"; @Component({ selector: "app-get-addons", @@ -41,6 +43,7 @@ export class GetAddonsComponent implements OnInit, OnDestroy { @ViewChild(MatSort) sort: MatSort; @ViewChild("table", { read: ElementRef }) table: ElementRef; + @ViewChild("columnContextMenuTrigger") columnContextMenu: MatMenuTrigger; private _subscriptions: Subscription[] = []; private _isSelectedTab: boolean = false; @@ -52,10 +55,10 @@ export class GetAddonsComponent implements OnInit, OnDestroy { columns: ColumnState[] = [ { name: "name", display: "Addon", visible: true }, - { name: "downloadCount", display: "Downloads", visible: true }, - { name: "releasedAt", display: "Released At", visible: true }, - { name: "author", display: "Author", visible: true }, - { name: "providerName", display: "Provider", visible: true }, + { name: "downloadCount", display: "Downloads", visible: true, allowToggle: true }, + { name: "releasedAt", display: "Released At", visible: true, allowToggle: true }, + { name: "author", display: "Author", visible: true, allowToggle: true }, + { name: "providerName", display: "Provider", visible: true, allowToggle: true }, { name: "status", display: "Status", visible: true }, ]; @@ -78,6 +81,7 @@ export class GetAddonsComponent implements OnInit, OnDestroy { public query = ""; public isBusy = true; public selectedClient = WowClientType.None; + public contextMenuPosition = { x: "0px", y: "0px" }; constructor( private _addonService: AddonService, @@ -105,6 +109,18 @@ export class GetAddonsComponent implements OnInit, OnDestroy { this.activeSort = sortOrder.name; this.activeSortDirection = sortOrder.direction; } + + const columnStates = this._wowUpService.getAddonsHiddenColumns; + this.columns.forEach((col) => { + if (!col.allowToggle) { + return; + } + + const state = _.find(columnStates, (cs) => cs.name === col.name); + if (state) { + col.visible = state.visible; + } + }); } ngOnDestroy() { @@ -127,6 +143,27 @@ export class GetAddonsComponent implements OnInit, OnDestroy { this._cdRef.detectChanges(); } + public onHeaderContext(event: MouseEvent) { + event.preventDefault(); + this.updateContextMenuPosition(event); + this.columnContextMenu.menuData = { + columns: this.columns.filter((col) => col.allowToggle), + }; + this.columnContextMenu.menu.focusFirstItem("mouse"); + this.columnContextMenu.openMenu(); + } + + private updateContextMenuPosition(event: MouseEvent) { + this.contextMenuPosition.x = event.clientX + "px"; + this.contextMenuPosition.y = event.clientY + "px"; + } + + public onColumnVisibleChange(event: MatCheckboxChange, column: ColumnState) { + const col = this.columns.find((col) => col.name === column.name); + col.visible = event.checked; + this._wowUpService.getAddonsHiddenColumns = [...this.columns]; + } + private lazyLoad() { if (this._lazyLoaded) { return;