Skip to content

Commit

Permalink
Show recently added filters after import (close #2148)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev authored and marcmo committed Nov 20, 2024
1 parent 5f9f013 commit 8d020fc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion application/client/src/app/service/history/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
static fromMinifiedStr(src: { [key: string]: number | string }): ICollection {
return {
name: obj.getAsNotEmptyString(src, 'n'),
created: obj.getAsValidNumber(src, 'c'),
created: Date.now(),
used: obj.getAsValidNumber(src, 'u'),
last: obj.getAsValidNumber(src, 'l'),
preset: obj.getAsBool(src, 'p'),
Expand Down Expand Up @@ -264,6 +264,10 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
return this.name !== '' && this.name !== '-';
}

public filterByDateTime(tm: number): boolean {
return this.created > tm;
}

public isSame(collections: Collections): boolean {
return (
this.collections.filters.isSame(collections.collections.filters) &&
Expand Down
4 changes: 4 additions & 0 deletions application/client/src/app/service/history/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class HistorySession extends Subscriber {
suitable(): Suitable;
all(): Collections[];
named(): Collections[];
byTimeStamp(tm: number): Collections[];
} {
return {
related: (): Collections | undefined => {
Expand All @@ -189,6 +190,9 @@ export class HistorySession extends Subscriber {
named: (): Collections[] => {
return this.storage.collections.find().named();
},
byTimeStamp: (tm: number): Collections[] => {
return this.storage.collections.find().byTimeStamp(tm);
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class StorageCollections {
suitable(): Suitable;
named(): Collections[];
all(): Collections[];
byTimeStamp(tm: number): Collections[];
} {
return {
related: (): Collections[] => {
Expand Down Expand Up @@ -146,6 +147,9 @@ export class StorageCollections {
all: (): Collections[] => {
return Array.from(this.collections.values());
},
byTimeStamp: (tm: number): Collections[] => {
return Array.from(this.collections.values()).filter((c) => c.filterByDateTime(tm));
},
};
}

Expand Down
15 changes: 15 additions & 0 deletions application/client/src/app/ui/views/toolbar/history/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Selection {

export class State {
protected parent!: IlcInterface & ChangesDetector;
protected recentImport: number | undefined = undefined;

public history!: HistorySession;
public groups: SuitableGroup[] = [];
Expand Down Expand Up @@ -104,10 +105,12 @@ export class State {
if (files.length !== 1) {
return;
}
this.recentImport = Date.now();
this.parent
.ilc()
.services.system.history.import(files[0].filename)
.then(() => {
this.filtered = -4;
this.list().update();
this.parent.detectChanges();
})
Expand Down Expand Up @@ -139,6 +142,17 @@ export class State {
public update(): State {
const groups: SuitableGroup[] = (() => {
switch (this.filtered) {
case -4:
return [
{
caption: 'Recently Added',
rank: 0,
collections:
this.recentImport !== undefined
? this.history.find().byTimeStamp(this.recentImport)
: this.history.find().all(),
},
];
case -3:
return [{ caption: 'All', rank: 0, collections: this.history.find().all() }];
case -2:
Expand Down Expand Up @@ -185,6 +199,7 @@ export class State {
const suitable = this.history.find().suitable();
const groups = suitable.asGroups();
this.filters = [
...(this.recentImport === undefined ? [] : [{ caption: 'Recently Added', value: -4 }]),
{ caption: 'All', value: -3 },
{ caption: 'All Suitable', value: -2 },
{ caption: 'Named Presets', value: -1 },
Expand Down

0 comments on commit 8d020fc

Please sign in to comment.