cleanup for recent opened file
This commit is contained in:
parent
c6d2f91602
commit
4305745ece
@ -43,6 +43,7 @@ export class FileStatusWrapper implements FileStatus {
|
||||
readonly hasSuggestions = this.fileStatus.hasSuggestions;
|
||||
|
||||
primaryAttribute: string;
|
||||
lastOpened: boolean;
|
||||
|
||||
constructor(readonly fileStatus: FileStatus, public reviewerName: string, fileAttributesConfig?: FileAttributesConfig) {
|
||||
if (fileAttributesConfig) {
|
||||
|
||||
@ -58,7 +58,7 @@
|
||||
<div
|
||||
*cdkVirtualFor="let fileStatus of sortedDisplayedEntities$ | async; trackBy: trackByPrimaryKey"
|
||||
[class.disabled]="fileStatus.excluded"
|
||||
[class.last-opened]="isLastOpenedFile(fileStatus.fileId)"
|
||||
[class.last-opened]="fileStatus.lastOpened"
|
||||
[class.pointer]="fileStatus.canBeOpened"
|
||||
[routerLink]="fileLink(fileStatus)"
|
||||
class="table-item"
|
||||
|
||||
@ -80,7 +80,7 @@ export class DossierOverviewScreenComponent extends ListingComponent<FileStatusW
|
||||
collapsedDetails = false;
|
||||
dossierAttributes: DossierAttributeWithValue[] = [];
|
||||
protected readonly _primaryKey = 'filename';
|
||||
private readonly _lastOpenedFileKey = 'Dossier-Recent-' + this.currentDossier.dossierId;
|
||||
|
||||
@ViewChild(DossierDetailsComponent, { static: false })
|
||||
private readonly _dossierDetailsComponent: DossierDetailsComponent;
|
||||
private _lastScrolledIndex: number;
|
||||
@ -119,10 +119,6 @@ export class DossierOverviewScreenComponent extends ListingComponent<FileStatusW
|
||||
return this.filterService.getGroup('quickFilters')?.filters.filter(f => !f.required && f.checked);
|
||||
}
|
||||
|
||||
isLastOpenedFile(fileId: string): boolean {
|
||||
return this._userPreferenceService.getLastOpenedFileId(this._lastOpenedFileKey) === fileId;
|
||||
}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
this._loadingService.start();
|
||||
try {
|
||||
|
||||
@ -244,13 +244,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
await this._loadFileData(false);
|
||||
this.displayPDFViewer = true;
|
||||
this._updateCanPerformActions();
|
||||
try {
|
||||
const key = 'Dossier-Recent-' + this.dossierId;
|
||||
await this._userPreferenceControllerService.savePreferences([this.fileId], key).toPromise();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
this._subscribeToFileUpdates();
|
||||
this._loadingService.stop();
|
||||
}
|
||||
|
||||
@ -10,9 +10,7 @@ interface UserAttributes {
|
||||
})
|
||||
export class UserPreferenceService {
|
||||
constructor(private readonly _userPreferenceControllerService: UserPreferenceControllerService) {
|
||||
_userPreferenceControllerService.getAllUserAttributes().subscribe(attributes => {
|
||||
this._userAttributes = attributes ?? {};
|
||||
});
|
||||
this.reload();
|
||||
}
|
||||
|
||||
private _userAttributes: UserAttributes = {};
|
||||
@ -26,15 +24,28 @@ export class UserPreferenceService {
|
||||
return value ? value === 'true' : false;
|
||||
}
|
||||
|
||||
getLastOpenedFileId(key: string): string {
|
||||
getLastOpenedFileForDossier(dossierId: string): string {
|
||||
const key = `Dossier-Recent-${dossierId}`;
|
||||
if (this.userAttributes[key]?.length > 0) {
|
||||
return this.userAttributes[key][0];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
async saveLastOpenedFileForDossier(dossierId: string, fileId: string) {
|
||||
const key = `Dossier-Recent-${dossierId}`;
|
||||
this.userAttributes[key] = [fileId];
|
||||
await this._userPreferenceControllerService.savePreferences([fileId], key).toPromise();
|
||||
}
|
||||
|
||||
toggleDevFeatures() {
|
||||
sessionStorage.setItem('redaction.enable-dev-features', `${!this.areDevFeaturesEnabled}`);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
reload() {
|
||||
this._userPreferenceControllerService.getAllUserAttributes().subscribe(attributes => {
|
||||
this._userAttributes = attributes ?? {};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,8 @@ import {
|
||||
FileAttributesControllerService,
|
||||
FileStatus,
|
||||
ReanalysisControllerService,
|
||||
StatusControllerService
|
||||
StatusControllerService,
|
||||
UserPreferenceControllerService
|
||||
} from '@redaction/red-ui-http';
|
||||
import { Toaster } from '@services/toaster.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
@ -23,6 +24,7 @@ import { DossierTemplateModelWrapper } from '@models/file/dossier-template-model
|
||||
import { DossiersService } from '../modules/dossier/services/dossiers.service';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { humanize } from '@iqser/common-ui';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
|
||||
export interface AppState {
|
||||
dossiers: DossierWrapper[];
|
||||
@ -55,7 +57,8 @@ export class AppStateService {
|
||||
private readonly _dictionaryControllerService: DictionaryControllerService,
|
||||
private readonly _dossierTemplateControllerService: DossierTemplateControllerService,
|
||||
private readonly _statusControllerService: StatusControllerService,
|
||||
private readonly _fileAttributesService: FileAttributesControllerService
|
||||
private readonly _fileAttributesService: FileAttributesControllerService,
|
||||
private readonly _userPreferenceService: UserPreferenceService
|
||||
) {
|
||||
this._appState = {
|
||||
dossiers: [],
|
||||
@ -291,7 +294,7 @@ export class AppStateService {
|
||||
);
|
||||
}
|
||||
|
||||
activateFile(dossierId: string, fileId: string) {
|
||||
async activateFile(dossierId: string, fileId: string) {
|
||||
if (this.activeDossierId === dossierId && this.activeFileId === fileId) return;
|
||||
this.activateDossier(dossierId);
|
||||
if (this.activeDossier) {
|
||||
@ -301,6 +304,15 @@ export class AppStateService {
|
||||
this._router.navigate(['/main/dossiers/' + dossierId]);
|
||||
}
|
||||
}
|
||||
this._updateLastActiveFileForDossier(dossierId, fileId);
|
||||
}
|
||||
|
||||
private async _updateLastActiveFileForDossier(dossierId: string, fileId: string) {
|
||||
this.activeDossier.files.forEach(f => {
|
||||
f.lastOpened = f.fileId === fileId;
|
||||
});
|
||||
|
||||
await this._userPreferenceService.saveLastOpenedFileForDossier(dossierId, fileId);
|
||||
}
|
||||
|
||||
activateDossierTemplate(dossierTemplateId: string) {
|
||||
@ -706,6 +718,10 @@ export class AppStateService {
|
||||
fileStatusChangedEvent.forEach(file => this.fileChanged$.next(file));
|
||||
}
|
||||
|
||||
const lastOpenedFileId = this._userPreferenceService.getLastOpenedFileForDossier(dossier.dossierId);
|
||||
|
||||
dossier.files.forEach(file => (file.lastOpened = file.fileId === lastOpenedFileId));
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user