diff --git a/src/app/browser-window.service.ts b/src/app/browser-window.service.ts index 51afd30d0bc570bb3cb45f5feebcf21986a96f02..dbc6b2de1d37edf7e884382725aafbe9e936b366 100644 --- a/src/app/browser-window.service.ts +++ b/src/app/browser-window.service.ts @@ -10,11 +10,14 @@ import { Injectable } from '@angular/core'; import { Job } from './job'; import { AppAction, Strudelapp, StrudelappInstance } from './strudelapp'; import {BackendSelectionService} from './backend-selection.service'; -import {repeat, take, takeUntil, filter} from 'rxjs/operators'; -import {timer, interval, Subject, BehaviorSubject} from 'rxjs'; +import {repeat, take, takeUntil, filter, catchError} from 'rxjs/operators'; +import {timer, interval, Subject, BehaviorSubject, of} from 'rxjs'; import { ModaldialogComponent } from './modaldialog/modaldialog.component'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA, MatDialogModule } from '@angular/material'; import {NotificationsService } from './notifications.service'; +import { HttpClientModule, HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http'; + +import { environment } from '../environments/environment'; @Injectable({ providedIn: 'root' @@ -26,12 +29,16 @@ export class BrowserWindowService { private openapps: any[]; public cancelJob$: Subject<Job>; - constructor(private backendSelectionService: BackendSelectionService, public dialog: MatDialog, private notifications: NotificationsService) { + constructor(private backendSelectionService: BackendSelectionService, + public dialog: MatDialog, + private notifications: NotificationsService, + private http: HttpClient) { this.backendSelectionService.apiserver.subscribe( (value) => { if (value != null) {this.twsproxy = value.tws ; this.Base = value.tes }}); this.authdone$ = new Subject<boolean>(); this.openapps = []; this.cancelJob$ = new Subject<Job>(); timer(500).pipe(repeat()).subscribe(() => this.checkWindows()); + timer(environment.loginterval).pipe(repeat()).subscribe(() => this.logUsage()); } @@ -64,6 +71,22 @@ export class BrowserWindowService { } } + public logUsage() { + var app: any; + console.log('in log usage'); + this.openapps.forEach( (app,index) => { + if (!app.window.closed) { + if (app.job.state == 'RUNNING') { + console.log('logging',app.job); + this.http.get<any>(environment.logserver+"/"+app.job.identity.site.name+"/"+app.job.identity.username+"/"+app.job.app.name+"/"+app.job.jobid).pipe( //We're expecting 404 not founds + catchError((e) => {console.log(e) ; return of([]);}) + ).subscribe((_) => {return}) + } + } + }) + } + + public checkWindows() { var app: any; this.openapps.forEach( (app,index) => { diff --git a/src/app/settings.service.ts b/src/app/settings.service.ts index 0d8dd7698140f37115d49fc5d8af6626bc17c99d..cd5f861bc43f365b93e860ccc684b9bcad5f712f 100644 --- a/src/app/settings.service.ts +++ b/src/app/settings.service.ts @@ -9,16 +9,30 @@ export class SettingsService { public menuToggle$: BehaviorSubject<boolean>; public useMenu$: BehaviorSubject<boolean>; public appdesc: boolean; + public logging: boolean; constructor() { this.menuToggle$ = new BehaviorSubject<boolean>(true); this.theme$ = new BehaviorSubject<string>('strudel-light-theme'); this.useMenu$ = new BehaviorSubject<boolean>(true); + this.logging = true; this.appdesc = true; this.getTheme(); this.getAppDesc(); + this.getLogging(); } + getLogging() { + let storedvalue = JSON.parse(localStorage.getItem('strudel-logging')); + if (storedvalue !== null) { + this.logging = storedvalue; + } + } + + setLogging(event) { + this.logging = event.checked; + localStorage.setItem('strudel-logging',JSON.stringify(this.logging)); + } getAppDesc() { console.log('loading appdesc setting'); diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 4ead4e21d885533bd9b8fffb34fd25d056468d46..94bfadb0b2b6bcd051f94b70903cb10192363c96 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -13,8 +13,14 @@ </mat-select> </mat-form-field> </div> - <div > - <mat-slide-toggle color=primary [checked]="settingsService.appdesc" (change)="settingsService.setAppDesc($event)">Show Appliction Descriptions</mat-slide-toggle> + <div> + <div > + <mat-slide-toggle color=primary [checked]="settingsService.appdesc" (change)="settingsService.setAppDesc($event)">Show Appliction Descriptions</mat-slide-toggle> + </div> + <div> + <mat-slide-toggle color=primary [checked]="settingsService.logging" (change)="settingsService.setLogging($event)">Allow usage logs to be collected</mat-slide-toggle> + </div> + <div class="heading"><h2>Advanced</h2></div> <div> diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index dc33a858757a7c95ffa88596085efc2a336b2506..f360cced61ea180facc99c1b637f4a1543de6ce2 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,6 +1,8 @@ export const environment = { production: true, - contact: ["<STRUDEL Developers> chris.hines@monash.edu"] + contact: ["<STRUDEL Developers> chris.hines@monash.edu"], + logserver: "https://strudel2-api-dev.cloud.cvl.org.au/logging", + loginterval: 1000000 diff --git a/src/environments/environment.ts b/src/environments/environment.ts index d104f337878214f937cb9c95df2ae8ec0bebeb8b..afac02c27b5bb068894c72637a14433396bc77e0 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -5,5 +5,7 @@ export const environment = { production: false, - contact: ["<STRUDEL Developers> chris.hines@monash.edu"] + contact: ["<STRUDEL Developers> chris.hines@monash.edu"], + logserver: "https://strudel2-dev.cloud.cvl.org.au/logging", + loginterval: 10000 };