From 63de0fdd373a5a2e28c70b38e4bb7f1b793e0b9a Mon Sep 17 00:00:00 2001
From: Chris Hines <chris.hines@monash.edu>
Date: Wed, 26 Aug 2020 10:18:14 +1000
Subject: [PATCH] warn the user of what happens if you open Jupyter Lab first

---
 src/app/app.module.ts                         |  4 ++-
 src/app/browser-window.service.ts             |  7 ++++++
 src/app/tes.service.ts                        |  3 ++-
 src/app/warndialog/warndialog.component.css   |  0
 src/app/warndialog/warndialog.component.html  | 13 ++++++++++
 .../warndialog/warndialog.component.spec.ts   | 25 +++++++++++++++++++
 src/app/warndialog/warndialog.component.ts    | 25 +++++++++++++++++++
 7 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 src/app/warndialog/warndialog.component.css
 create mode 100644 src/app/warndialog/warndialog.component.html
 create mode 100644 src/app/warndialog/warndialog.component.spec.ts
 create mode 100644 src/app/warndialog/warndialog.component.ts

diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 25237dd..386730c 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -66,6 +66,7 @@ import { AboutUsComponent } from './aboutus/aboutus.component';
 import { OurServicesComponent } from './ourservices/ourservices.component';
 import { ContactUsComponent } from './contactus/contactus.component';
 import { NoaccountComponent } from './noaccount/noaccount.component';
+import { WarndialogComponent } from './warndialog/warndialog.component';
 
 // import { FileExplorerModule } from './file-explorer/file-explorer.module';
 
@@ -98,6 +99,7 @@ import { NoaccountComponent } from './noaccount/noaccount.component';
     OurServicesComponent,
     ContactUsComponent,
     NoaccountComponent,
+    WarndialogComponent,
   ],
   imports: [
   BrowserModule,
@@ -136,7 +138,7 @@ import { NoaccountComponent } from './noaccount/noaccount.component';
 
 
   ],
-    entryComponents: [ LogoutdialogComponent, ModaldialogComponent],
+    entryComponents: [ LogoutdialogComponent, ModaldialogComponent, WarndialogComponent],
   //providers: [ StrudelappsService, ComputesitesService, TesService, SubmitAppService, MatDialog, AuthorisationService,BackendSelectionService,SettingsService],
   providers: [NotificationsService, ComputesitesService, TesService, BrowserWindowService, SubmitAppService, MatDialog, AuthorisationService,BackendSelectionService,SettingsService, JobsService],
   bootstrap: [AppComponent]
diff --git a/src/app/browser-window.service.ts b/src/app/browser-window.service.ts
index 8670905..efe537d 100644
--- a/src/app/browser-window.service.ts
+++ b/src/app/browser-window.service.ts
@@ -13,6 +13,7 @@ import {BackendSelectionService} from './backend-selection.service';
 import {repeat, take, takeUntil, filter, catchError, map, tap} from 'rxjs/operators';
 import {timer, interval, Subject, BehaviorSubject, of} from 'rxjs';
 import { ModaldialogComponent } from './modaldialog/modaldialog.component';
+import { WarndialogComponent } from './warndialog/warndialog.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';
@@ -29,6 +30,7 @@ export class BrowserWindowService {
   private authdone$: Subject<boolean>;
   private openapps: any[];
   public cancelJob$: Subject<Job>;
+  private warnref: MatDialogRef<WarndialogComponent>;
 
   constructor(private backendSelectionService: BackendSelectionService,
     public dialog: MatDialog,
@@ -131,6 +133,10 @@ export class BrowserWindowService {
     var app: any;
     this.openapps.forEach( (app,index) => {
       if (app.window.closed) {
+        if (this.warnref !== undefined && this.warnref !== null) {
+          console.log('warnref',this.warnref,this.warnref.getState());
+          this.warnref.close();
+        }
         if (app.job.state == 'RUNNING') {
           let dialogRef = this.dialog.open(ModaldialogComponent, {
             width: '600px',
@@ -147,6 +153,7 @@ export class BrowserWindowService {
 
    public finishAppWindow(windowloc: any, job:Job, action: AppAction) {
      let appwindow = window.open(windowloc);
+     this.warnref = this.dialog.open(WarndialogComponent, {width: '600px', data: job})
      if (appwindow == null) {
          this.notifications.notify('It looks like a window failed to open. Please check your popup blocker settings (Strudel 2 needs to be able to open a window to your application');
          return;
diff --git a/src/app/tes.service.ts b/src/app/tes.service.ts
index 0445842..972e4e8 100644
--- a/src/app/tes.service.ts
+++ b/src/app/tes.service.ts
@@ -71,6 +71,7 @@ public openWindow$: Subject<any>;
 
  private getUserHealthError(error: any, identity: Identity) {
    identity.accountalerts.next([]);
+   console.error(error)
    this.notifications.notify("There was an error checking your user account");
  }
 
@@ -91,7 +92,7 @@ getUserHealth(identity: Identity)  {
   params.set('username',JSON.stringify(identity.username));
   
   this.updateUserHealthSub = this.runCommand(identity,identity.site.userhealth)
-    .pipe(takeUntil(this.cancelRequests$))
+    .pipe(takeUntil(this.cancelRequests$),tap((v) => console.log(v)))
     .subscribe(resp => this.addUserHealth(identity,resp), error => this.getUserHealthError(error,identity));
 }
 
diff --git a/src/app/warndialog/warndialog.component.css b/src/app/warndialog/warndialog.component.css
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/warndialog/warndialog.component.html b/src/app/warndialog/warndialog.component.html
new file mode 100644
index 0000000..c4e20fc
--- /dev/null
+++ b/src/app/warndialog/warndialog.component.html
@@ -0,0 +1,13 @@
+  <div *ngIf="data.name !== undefined && data.name !== null">
+  <h2>{{ data.name }} Running</h2>
+  It looks like you already connected to {{ data.name }}<br>
+  </div>
+  <div *ngIf="data.name === undefined || data.name === null">
+  <h2>Application Running</h2>
+  It looks like you already connected to a Strudel2 Application<br>
+  </div>
+  Depending on which applications you are connecting to and which order you open the windows in, you may experience bugs<br>
+  For example if you open Jupyter Lab then a terminal Jupyter Lab will misbehave. If you open terminal the Jupyter Lab this will be OK.
+  <div fxLayout="row" fxLayoutAlign="space-between stretch" style="width: 100%">
+  <button mat-button (click)="close(null)">OK, Got it!</button>
+  </div>
diff --git a/src/app/warndialog/warndialog.component.spec.ts b/src/app/warndialog/warndialog.component.spec.ts
new file mode 100644
index 0000000..d3dfec3
--- /dev/null
+++ b/src/app/warndialog/warndialog.component.spec.ts
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { WarndialogComponent } from './warndialog.component';
+
+describe('WarndialogComponent', () => {
+  let component: WarndialogComponent;
+  let fixture: ComponentFixture<WarndialogComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      declarations: [ WarndialogComponent ]
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(WarndialogComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});
diff --git a/src/app/warndialog/warndialog.component.ts b/src/app/warndialog/warndialog.component.ts
new file mode 100644
index 0000000..a4c01c9
--- /dev/null
+++ b/src/app/warndialog/warndialog.component.ts
@@ -0,0 +1,25 @@
+
+import { Component, OnInit, Inject  } from '@angular/core';
+import { MatDialog, MatDialogRef, MAT_DIALOG_DATA, MatDialogModule } from '@angular/material';
+
+@Component({
+  selector: 'app-warndialog',
+  templateUrl: './warndialog.component.html',
+  styleUrls: ['./warndialog.component.css']
+})
+export class WarndialogComponent implements OnInit {
+
+  constructor(
+    public dialogRef: MatDialogRef<WarndialogComponent>,
+    @Inject(MAT_DIALOG_DATA) public data: any,
+) {
+   }
+
+  ngOnInit() {
+  }
+
+  close(rv) {
+    this.dialogRef.close(rv);
+  }
+
+}
-- 
GitLab