Skip to content

Commit b7286dd

Browse files
Use boolean for used counter for collections
For denoting the used collection we are using the number, this commit changes that to boolean
1 parent 635b536 commit b7286dd

File tree

7 files changed

+35
-15
lines changed

7 files changed

+35
-15
lines changed

application/client/src/app/service/history/collections.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface ICollection {
2424
name: string;
2525
created: number;
2626
last: number;
27-
used: number;
27+
used: boolean;
2828
uuid: string;
2929
preset: boolean;
3030
relations: string[];
@@ -45,7 +45,7 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
4545
name: '-',
4646
last: Date.now(),
4747
created: Date.now(),
48-
used: 1,
48+
used: true,
4949
uuid: smth.uuid(),
5050
preset: false,
5151
relations: [],
@@ -62,8 +62,8 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
6262
// For older filters saved on the user machine we have the used value
6363
// set as a 1 by default. To fix the counter we need to reset it to 0
6464
// because user didn't use it yet.
65-
if (def.used >= 1) {
66-
def.used = 0;
65+
if (def.used) {
66+
def.used = false;
6767
}
6868
return new Collections(
6969
`Collections:${def.uuid}`,
@@ -102,7 +102,7 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
102102
name: '-',
103103
last: Date.now(),
104104
created: Date.now(),
105-
used: 1,
105+
used: true,
106106
uuid: uuid,
107107
preset: false,
108108
relations: [],
@@ -119,7 +119,7 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
119119
return {
120120
name: obj.getAsNotEmptyString(src, 'n'),
121121
created: Date.now(),
122-
used: obj.getAsValidNumber(src, 'u'),
122+
used: obj.getAsValidBooleanFromNumber(src, 'u'),
123123
last: obj.getAsValidNumber(src, 'l'),
124124
preset: obj.getAsBool(src, 'p'),
125125
uuid: obj.getAsNotEmptyString(src, 'uu'),
@@ -133,7 +133,7 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
133133

134134
public name: string;
135135
public created: number;
136-
public used: number;
136+
public used: boolean;
137137
public last: number;
138138
public uuid: string;
139139
public preset: boolean;
@@ -200,6 +200,7 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
200200
);
201201
}
202202

203+
// TODO: Remove this function as this is not used anywhere
203204
public copy(): Collections {
204205
const uuid = unique();
205206
return new Collections(
@@ -208,7 +209,7 @@ export class Collections implements EntryConvertable, Equal<Collections>, Empty
208209
name: this.name,
209210
last: Date.now(),
210211
created: Date.now(),
211-
used: 1,
212+
used: true,
212213
uuid,
213214
preset: false,
214215
relations: [],

application/client/src/app/service/history/session.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class HistorySession extends Subscriber {
115115
related: (): boolean => {
116116
const related = this.find().related();
117117
if (related !== undefined) {
118-
if (related.used === 0) {
118+
if (!related.used) {
119119
this.storage.collections.used(related.uuid);
120120
}
121121
this.setCollection(related);
@@ -200,14 +200,12 @@ export class HistorySession extends Subscriber {
200200
}
201201

202202
public apply(collection: Collections) {
203+
this.storage.collections.ignoreAll();
203204
const storage_collection = this.storage.collections.get(collection.uuid);
204205

205206
if (storage_collection === undefined) {
206207
this.storage.collections.insert(collection);
207208
}
208-
if (storage_collection !== undefined && storage_collection.used > 0) {
209-
return;
210-
}
211209
this.storage.collections.used(collection.uuid);
212210
this.setCollection(collection);
213211
this.definitions.list().forEach((def) => {

application/client/src/app/service/history/storage.collections.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,14 @@ export class StorageCollections {
162162
if (collection === undefined) {
163163
return;
164164
}
165-
collection.used += 1;
165+
if (!collection.used) {
166+
collection.used = true;
167+
}
166168
collection.last = Date.now();
167169
}
170+
171+
public ignoreAll() {
172+
this.collections.forEach((c) => (c.used = false));
173+
}
168174
}
169175
export interface StorageCollections extends LoggerInterface {}

application/client/src/app/ui/views/toolbar/history/preset/component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,14 @@ export class Preset extends ChangesDetector implements AfterContentInit {
8484
this.collections.used
8585
})`;
8686
} else {
87-
return `${this.collections.name}(${this.collections.used})`;
87+
return `${this.collections.name}`;
8888
}
8989
}
9090

91+
public isUsed(): boolean {
92+
return this.collections.used;
93+
}
94+
9195
public getValue(): string {
9296
return this.collections.name === '-' ? '' : this.collections.name;
9397
}

application/client/src/app/ui/views/toolbar/history/preset/styles.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
&.no-left-margin {
3030
margin-left: 6px;
3131
}
32+
&.used {
33+
background: var(--scheme-color-3);
34+
}
3235
&::hover {
3336
background: var(--scheme-color-4);
3437
}

application/client/src/app/ui/views/toolbar/history/preset/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<mat-card class="small-title">
1+
<mat-card class="small-title" [ngClass]="isUsed() ? 'used' : ''">
22
<mat-card-title>
33
<app-editable-field
44
(changed)="onRename($event)"

application/platform/env/obj.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ export function getAsValidNumber(
291291
return src[key];
292292
}
293293

294+
export function getAsValidBooleanFromNumber(
295+
src: any,
296+
key: string
297+
): boolean {
298+
const value = getAsValidNumber(src, key);
299+
return value !== 0;
300+
}
301+
294302
export function getAsValidNumberOrUndefined(
295303
src: any,
296304
key: string,

0 commit comments

Comments
 (0)