From f9e5bb132e5cb6e3796353d86e630431b410c48d Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Fri, 23 Oct 2020 19:21:55 +0300 Subject: [PATCH] added background reload for project and file data --- .../project-overview-screen.component.ts | 10 ++-------- .../red-ui/src/app/state/app-state.service.ts | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.ts b/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.ts index ae2d719ab..9e309ea8a 100644 --- a/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.ts +++ b/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.ts @@ -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() { diff --git a/apps/red-ui/src/app/state/app-state.service.ts b/apps/red-ui/src/app/state/app-state.service.ts index 32ee1c783..8aad4cee4 100644 --- a/apps/red-ui/src/app/state/app-state.service.ts +++ b/apps/red-ui/src/app/state/app-state.service.ts @@ -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(); + 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(); } + }