Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion application/client/src/app/service/history/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
);
} else {
const def = Collections.fromMinifiedStr(JSON.parse(smth.content));
// For older filters saved on the user machine we have the used value
// set as a 1 by default. To fix the counter we need to reset it to 0
// because user didn't use it yet.
if (def.used > 0) {
def.used = 0;
}
Comment on lines +65 to +67
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just set the value to zero without having an if branch.

return new Collections(
`Collections:${def.uuid}`,
Collections.fromMinifiedStr(JSON.parse(smth.content)),
def,
storage,
);
}
Expand Down Expand Up @@ -194,6 +200,7 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
);
}

// TODO: Remove this function as this is not used anywhere
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can resolve the TODO then by removing the function

public copy(): Collections {
const uuid = unique();
return new Collections(
Expand Down
13 changes: 9 additions & 4 deletions application/client/src/app/service/history/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export class HistorySession extends Subscriber {
related: (): boolean => {
const related = this.find().related();
if (related !== undefined) {
if (related.used === 0) {
this.storage.collections.used(related.uuid);
}
this.setCollection(related);
this.collections
.applyTo(this.session, this.definitions.list())
Expand Down Expand Up @@ -197,11 +200,13 @@ export class HistorySession extends Subscriber {
}

public apply(collection: Collections) {
if (this.storage.collections.get(collection.uuid) === undefined) {
this.storage.collections.ignoreAll();
const storage_collection = this.storage.collections.get(collection.uuid);

if (storage_collection === undefined) {
this.storage.collections.insert(collection);
} else {
this.storage.collections.used(collection.uuid);
}
}
this.storage.collections.used(collection.uuid);
this.setCollection(collection);
this.definitions.list().forEach((def) => {
this.collections.bind(def);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,14 @@ export class StorageCollections {
if (collection === undefined) {
return;
}
collection.used += 1;
if (collection.used === 0) {
collection.used = 1;
}
collection.last = Date.now();
}

public ignoreAll() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need rename this to something more precise like resetUsedCounters.

this.collections.forEach((c) => (c.used = 0));
}
}
export interface StorageCollections extends LoggerInterface {}
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ export class Preset extends ChangesDetector implements AfterContentInit {
this.collections.used
})`;
} else {
return `${this.collections.name}(${this.collections.used})`;
return `${this.collections.name}`;
}
}

public isUsed(): boolean {
return this.collections.used > 0;
}

public getValue(): string {
return this.collections.name === '-' ? '' : this.collections.name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
&.no-left-margin {
margin-left: 6px;
}
&.used {
background: var(--scheme-color-3);
}
&::hover {
background: var(--scheme-color-4);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<mat-card class="small-title">
<mat-card class="small-title" [ngClass]="isUsed() ? 'used' : ''">
<mat-card-title>
<app-editable-field
(changed)="onRename($event)"
Expand Down
2 changes: 1 addition & 1 deletion application/platform/modules/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Service extends Implementation {
const inited = this._inited;
const register = this._register;
const logger = this._logger;
logger.debug(`initing services...`);
logger.debug(`Initializing Services...`);
async function initialize(
service: Interface & Implementation,
uuids: string[],
Expand Down
Loading