diff --git a/mediarepo-ui/src/api/models/SortKey.ts b/mediarepo-ui/src/api/models/SortKey.ts
index 674237e..6ed1d57 100644
--- a/mediarepo-ui/src/api/models/SortKey.ts
+++ b/mediarepo-ui/src/api/models/SortKey.ts
@@ -69,13 +69,17 @@ export class SortKey {
}
}
+ public get rawData(): SortKeyData {
+ return this.data;
+ }
+
public static fromValues(
sortType: SortType,
sortDirection: SortDirection,
namespaceName: string | undefined
) {
let data;
-
+
if (sortType === "Namespace") {
data = {
Namespace: {
@@ -99,8 +103,4 @@ export class SortKey {
return `${this.sortType} ${this.sortDirection}`;
}
}
-
- public rawData(): SortKeyData {
- return this.data;
- }
}
diff --git a/mediarepo-ui/src/api/models/SortingPreset.ts b/mediarepo-ui/src/api/models/SortingPreset.ts
index 9eb258a..43bc7f3 100644
--- a/mediarepo-ui/src/api/models/SortingPreset.ts
+++ b/mediarepo-ui/src/api/models/SortingPreset.ts
@@ -1,20 +1,39 @@
import {SortKey} from "./SortKey";
import {SortingPresetData} from "../api-types/presets";
+import {mapNew} from "./adaptors";
export class SortingPreset {
- private readonly _id: number;
private keys: SortKey[];
constructor(presetData: SortingPresetData) {
this._id = presetData.id;
- this.keys = presetData.keys.map(SortKey.fromRawData);
+ this.keys = presetData.keys.map(mapNew(SortKey));
}
+ private _id: number;
+
public get id(): number {
return this._id;
}
+ public set id(value: number) {
+ this._id = value;
+ }
+
public get sortKeys(): SortKey[] {
- return this.sortKeys;
+ return this.keys;
+ }
+
+ public get rawData(): SortingPresetData {
+ return {
+ id: this._id,
+ keys: this.keys.map(k => k.rawData),
+ };
+ }
+
+ public static fromValues(id: number, keys: SortKey[]) {
+ let preset = new SortingPreset({ id, keys: [] });
+ preset.keys = keys;
+ return preset;
}
}
diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.html b/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.html
index e4de89f..f9e7f61 100644
--- a/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.html
+++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.html
@@ -35,7 +35,8 @@
-
+
diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.ts b/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.ts
index 9737c2d..7c6f149 100644
--- a/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.ts
+++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.ts
@@ -9,7 +9,6 @@ import {
Output,
ViewChild
} from "@angular/core";
-import {SortKey} from "../../../../../api/models/SortKey";
import {MatDialog} from "@angular/material/dialog";
import {SortDialogComponent} from "./sort-dialog/sort-dialog.component";
import {LoggingService} from "../../../../services/logging/logging.service";
@@ -23,6 +22,7 @@ import {FileStatus, FilterExpression,} from "../../../../../api/api-types/files"
import {filterExpressionToString} from "../../../../utils/filter-utils";
import {MatCheckboxChange} from "@angular/material/checkbox";
import * as deepEqual from "fast-deep-equal";
+import {SortingPreset} from "../../../../../api/models/SortingPreset";
@Component({
@@ -32,7 +32,7 @@ import * as deepEqual from "fast-deep-equal";
changeDetection: ChangeDetectionStrategy.OnPush
})
export class FileSearchComponent implements AfterViewChecked, OnInit {
- public sortExpression: SortKey[] = [];
+ public sortingPreset: SortingPreset = new SortingPreset({ id: -1, keys: [] });
public filters: SearchFilters = new SearchFilters([]);
@Input() availableTags: Tag[] = [];
@@ -68,7 +68,7 @@ export class FileSearchComponent implements AfterViewChecked, OnInit {
this.filters = f;
this.assignDisplayedFilters();
});
- this.state.sortKeys.subscribe(s => this.sortExpression = s);
+ this.state.sortingPreset.subscribe(s => this.sortingPreset = s);
this.applyStatusFromFilters();
this.needsScroll = true;
this.assignDisplayedFilters();
@@ -127,20 +127,18 @@ export class FileSearchComponent implements AfterViewChecked, OnInit {
}
public openSortDialog() {
- const sortEntries = this.sortExpression.map(
- key => JSON.parse(JSON.stringify(key.rawData()))).map(
- data => new SortKey(data));
+ const sortingPreset = new SortingPreset(JSON.parse(JSON.stringify(this.sortingPreset.rawData)));
const openedDialog = this.dialog.open(SortDialogComponent, {
minWidth: "40vw",
data: {
- sortEntries,
+ sortingPreset,
},
disableClose: true,
});
- openedDialog.afterClosed().subscribe(async (sortExpression) => {
- if (sortExpression) {
- this.sortExpression = sortExpression;
- this.state.setSortKeys(this.sortExpression);
+ openedDialog.afterClosed().subscribe(async (sortingPreset) => {
+ if (sortingPreset) {
+ this.sortingPreset = sortingPreset;
+ this.state.setSortingPreset(this.sortingPreset);
}
});
}
diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/sort-dialog/sort-dialog.component.html b/mediarepo-ui/src/app/components/shared/sidebar/file-search/sort-dialog/sort-dialog.component.html
index c6fc105..a350274 100644
--- a/mediarepo-ui/src/app/components/shared/sidebar/file-search/sort-dialog/sort-dialog.component.html
+++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/sort-dialog/sort-dialog.component.html
@@ -1,7 +1,7 @@
Sort Entries