Skip to content

Commit

Permalink
added a time stamp to exceptions for sort purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartondock committed May 29, 2024
1 parent 636b3cc commit 21542d9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/models/user-exceptions.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface UserExceptionData {
newTitle: string,
searchTitle: string,
timeStamp: number,
commandLineArguments: string,
exclude: boolean,
excludeArtwork: boolean
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/preview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ export class PreviewComponent implements OnDestroy {
this.userExceptionsService.addExceptionById(exceptionId, app.extractedTitle, {
newTitle: newTitle,
searchTitle: newPool,
timeStamp: Date.now(),
commandLineArguments: '',
exclude: false,
excludeArtwork: false
Expand Down Expand Up @@ -609,6 +610,7 @@ export class PreviewComponent implements OnDestroy {
this.userExceptionsService.addExceptionById(exceptionKey.exceptionId, exceptionKey.extractedTitle, {
newTitle: '',
searchTitle: '',
timeStamp: Date.now(),
commandLineArguments: '',
exclude: true,
excludeArtwork: false
Expand Down
16 changes: 11 additions & 5 deletions src/renderer/components/user-exceptions.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ExceptionsComponent implements OnDestroy {
private userExceptions: UserExceptions;

sortByOpts: SelectItem[] = _.flatten([
{value: 'dateAdded', displayValue: 'Date Added' },
{value: 'timeStamp', displayValue: 'Date Added' },
{value: 'oldTitle', displayValue: 'Extracted Title'},
{value: 'newTitle', displayValue: 'New Title'}
].map(x=>[
Expand Down Expand Up @@ -79,6 +79,7 @@ export class ExceptionsComponent implements OnDestroy {
newTitle:'',
searchTitle:'',
commandLineArguments: '',
timeStamp: Date.now(),
exclude: false,
excludeArtwork: false
})
Expand All @@ -101,17 +102,22 @@ export class ExceptionsComponent implements OnDestroy {
}

exceptionsSort(c1: FormGroup, c2: FormGroup) {
const sortBy = this.exceptionsService.sortBy.split('|')[0];
const asc = this.exceptionsService.sortBy.split('|')[1]==='asc';
const sortBy = this.sortBy.split('|')[0];
const asc = this.sortBy.split('|')[1]==='asc';
let result: number;
if(!sortBy || sortBy === 'dateAdded') {
result = 1;
if(!sortBy || sortBy === 'timeStamp') {
result = c1.value.timeStamp - c2.value.timeStamp;
} else {
result = c1.value[sortBy].localeCompare(c2.value[sortBy])
}
return asc ? result : -result;
}

prettyDate(timeStamp: number) {
const date = new Date(timeStamp);
return date.toLocaleString()
}

undo() {
this.exceptionsService.setIsUnsaved(false);
this.exceptionsService.setCurrent(null);
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/modifiers/user-exceptions.modifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let versionUp = (version: number) => { return version + 1 };

export const userExceptions: ValidatorModifier<UserExceptions> = {
controlProperty: 'exceptionsVersion',
latestVersion: 1,
latestVersion: 2,
fields: {
undefined: {
'exceptionsVersion': { method: () => 0 },
Expand Down Expand Up @@ -37,6 +37,18 @@ export const userExceptions: ValidatorModifier<UserExceptions> = {
return result;
})
}
},
1: {
'exceptionsVersion': { method: versionUp },
'titles': {
method: ((oldValue: any, oldExceptions: any) => {
let result = _.cloneDeep(oldValue);
for(let key in oldValue) {
result[key].timeStamp = Date.now();
}
return result
})
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/schemas/user-exceptions.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const userExceptions = {
searchTitle: { type: 'string', default: '' },
commandLineArguments: { type: 'string', default: ''},
exclude: { type: 'boolean', default: false },
excludeArtwork: { type: 'boolean', default: false }
excludeArtwork: { type: 'boolean', default: false },
timeStamp: { type: 'number', default: 0}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/services/user-exceptions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class UserExceptionsService {

private validator: json.Validator = new json.Validator(schemas.userExceptions, modifiers.userExceptions);
private savingIsDisabled: boolean = false;
sortBy: string = 'dateAdded|asc';
sortBy: string = 'timeStamp|desc';

constructor(private loggerService: LoggerService) {
this.variableData = new BehaviorSubject({current: null, saved: {titles: {}}});
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/templates/user-exceptions.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ <h1>Excluded Games & Exceptions</h1>
<div class=text style="margin-right: 0.25em;">New Commandline Args: </div>
<ng-text-input class="ngTextInput" placeholder="--custom-args" [formControl]="(item | formGroup).controls['commandLineArguments'] | formControl"></ng-text-input>
</div>
<div class="inlineLeft">
<div class="text" style="margin-right: 0.25em; width: 100%;">Created: {{prettyDate((item | formGroup).controls['timeStamp'].value)}}</div>
</div>
<div class="inlineGroup">
<div class="inlineGroup">
<ng-toggle-button class="ngToggleButton excludeButton" [formControl]="(item | formGroup).controls['exclude'] | formControl">{{lang.text.exclude}}</ng-toggle-button>
Expand Down

0 comments on commit 21542d9

Please sign in to comment.