added background reload for project and file data

This commit is contained in:
Timo Bejan 2020-10-23 19:21:55 +03:00
parent ca9d62b3f4
commit f9e5bb132e
2 changed files with 19 additions and 10 deletions

View File

@ -12,6 +12,8 @@ import {SortingOption} from '../../utils/types';
import {DoughnutChartConfig} from '../../components/simple-doughnut-chart/simple-doughnut-chart.component';
import {groupBy} from '../../utils/functions';
import {DialogService} from '../../dialogs/dialog.service';
import {interval} from "rxjs";
import {flatMap, tap} from "rxjs/operators";
@Component({
@ -20,7 +22,6 @@ import {DialogService} from '../../dialogs/dialog.service';
styleUrls: ['./project-overview-screen.component.scss']
})
export class ProjectOverviewScreenComponent implements OnInit, OnDestroy {
private _fileStatusInterval;
private _selectedFileIds: string[] = [];
public sortingOptions: SortingOption[] = [
@ -52,17 +53,10 @@ export class ProjectOverviewScreenComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this._fileDropOverlayService.initFileDropHandling();
this._calculateChartConfig();
this._fileStatusInterval = setInterval(() => {
this._getFileStatus();
}, 5000);
}
ngOnDestroy(): void {
this._fileDropOverlayService.cleanupFileDropHandling();
if (this._fileStatusInterval) {
clearInterval(this._fileStatusInterval);
this._fileStatusInterval = null;
}
}
public get activeProject() {

View File

@ -1,4 +1,4 @@
import {Injectable} from "@angular/core";
import {Injectable, EventEmitter} from "@angular/core";
import {
FileStatus,
Project,
@ -10,6 +10,8 @@ import {NotificationService, NotificationType} from "../notification/notificatio
import {TranslateService} from "@ngx-translate/core";
import {Router} from "@angular/router";
import {UserService} from "../user/user.service";
import {interval} from "rxjs";
import {tap} from "rxjs/operators";
export interface AppState {
@ -39,6 +41,8 @@ export class AppStateService {
private _appState: AppState;
public fileStatusChanged = new EventEmitter<void>();
constructor(
private readonly _router: Router,
@ -53,6 +57,14 @@ export class AppStateService {
activeProject: null,
activeFile: null
}
interval(5000).pipe(tap(() => {
this.reloadActiveProjectFiles();
})).subscribe();
interval(30000).pipe(tap(() => {
this.loadAllProjects();
})).subscribe();
}
@ -201,7 +213,9 @@ export class AppStateService {
}
async reloadActiveProjectFiles() {
await this.getFiles(this._appState.activeProject.project.projectId);
if(this._appState.activeProject?.project) {
await this.getFiles(this._appState.activeProject.project.projectId);
}
}
async loadAllProjectsIfNecessary() {
@ -214,4 +228,5 @@ export class AppStateService {
await this._reanalysisControllerService.reanalyzeFile(this._appState.activeProject.project.projectId, this._appState.activeFile.fileId).toPromise();
await this.reloadActiveProjectFiles();
}
}