From 8030bee5296105eabe18d4e0e5052b149c959b69 Mon Sep 17 00:00:00 2001
From: mme <mechtel@iqb.hu-berlin.de>
Date: Wed, 3 Apr 2019 15:46:47 +0200
Subject: [PATCH] workspace-files list working again

---
 src/app/app.interceptor.ts                    |  1 -
 src/app/app.module.ts                         |  4 +-
 src/app/maindata.service.ts                   | 10 ++++
 src/app/workspace/backend.service.ts          |  8 +--
 src/app/workspace/files/files.component.html  |  4 +-
 src/app/workspace/files/files.component.ts    | 53 +++++++++++++------
 src/app/workspace/workspace-routing.module.ts |  2 +-
 src/app/workspace/workspace.component.css     |  5 +-
 src/app/workspace/workspace.component.html    |  2 +-
 src/app/workspace/workspace.component.ts      | 21 +++++++-
 src/app/workspace/workspace.interceptor.ts    |  1 -
 src/app/workspace/workspace.module.ts         |  2 +
 src/app/workspace/workspacedata.service.ts    | 12 +----
 src/iqb-theme2.scss                           |  2 +-
 src/styles.css                                | 12 ++---
 15 files changed, 84 insertions(+), 55 deletions(-)

diff --git a/src/app/app.interceptor.ts b/src/app/app.interceptor.ts
index 1469890c..a3db39b8 100644
--- a/src/app/app.interceptor.ts
+++ b/src/app/app.interceptor.ts
@@ -25,7 +25,6 @@ export class AuthInterceptor implements HttpInterceptor {
       }
     });
 
-    console.log('### # app.interceptor >' + requestA.headers.get('AuthToken'));
     return next.handle(requestA);
   }
 }
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 284ef646..fe0a9212 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -18,6 +18,7 @@ import { WorkspaceModule } from './workspace';
 import { StartComponent } from './start/start.component';
 import { SuperadminModule } from './superadmin';
 import { FlexLayoutModule } from "@angular/flex-layout";
+import { httpInterceptorProviders } from './app.interceptor';
 
 @NgModule({
   declarations: [
@@ -55,7 +56,8 @@ import { FlexLayoutModule } from "@angular/flex-layout";
       provide: LocationStrategy,
       useClass: HashLocationStrategy
     },
-    BackendService
+    BackendService,
+    httpInterceptorProviders
   ],
   bootstrap: [AppComponent]
 })
diff --git a/src/app/maindata.service.ts b/src/app/maindata.service.ts
index b9cc217f..70561232 100644
--- a/src/app/maindata.service.ts
+++ b/src/app/maindata.service.ts
@@ -14,6 +14,16 @@ export class MainDataService {
     is_superadmin: false
   };
 
+  public get adminToken() : string {
+    const myLoginData = this.loginData$.getValue();
+    if (myLoginData) {
+      return myLoginData.admintoken;
+    } else {
+      return '';
+    }
+  }
+
+
   public loginData$ = new BehaviorSubject<LoginData>(MainDataService.defaultLoginData);
   public globalErrorMsg$ = new BehaviorSubject<ServerError>(null);
 
diff --git a/src/app/workspace/backend.service.ts b/src/app/workspace/backend.service.ts
index 9d77a071..4c814608 100644
--- a/src/app/workspace/backend.service.ts
+++ b/src/app/workspace/backend.service.ts
@@ -37,15 +37,9 @@ export class BackendService {
   }
 
   // *******************************************************************
-  // Fehlerbehandlung beim Aufrufer
   getFiles(): Observable<GetFileResponseData[] | ServerError> {
-    const httpOptions = {
-      headers: new HttpHeaders({
-        'Content-Type':  'application/json'
-      })
-    };
     return this.http
-      .post<GetFileResponseData[]>(this.serverUrl + 'getFileList.php', {}, httpOptions)
+      .get<GetFileResponseData[]>(this.serverUrlSlim + 'filelist')
         .pipe(
           catchError(ErrorHandler.handle)
         );
diff --git a/src/app/workspace/files/files.component.html b/src/app/workspace/files/files.component.html
index 36056c9e..a4989ec2 100644
--- a/src/app/workspace/files/files.component.html
+++ b/src/app/workspace/files/files.component.html
@@ -5,7 +5,7 @@
 
   <!-- ============================================= -->
   <div class="filelist">
-    <mat-table #table *ngIf="isAdmin" [dataSource]="serverfiles" matSort>
+    <mat-table #table [dataSource]="serverfiles" matSort>
       <ng-container matColumnDef="checked">
           <mat-header-cell *matHeaderCellDef class="checkboxcell">
             <mat-checkbox (change)="checkAll($event.checked)"></mat-checkbox>
@@ -42,7 +42,7 @@
   </div>
 
   <!-- ============================================= -->
-  <div class="uploads" *ngIf="isAdmin">
+  <div class="uploads">
     <button mat-raised-button (click)="deleteFiles()" matTooltip="Markierte Dateien löschen" matTooltipPosition="above">
       <mat-icon>delete</mat-icon>
     </button>
diff --git a/src/app/workspace/files/files.component.ts b/src/app/workspace/files/files.component.ts
index 295a6298..0beafb6e 100644
--- a/src/app/workspace/files/files.component.ts
+++ b/src/app/workspace/files/files.component.ts
@@ -1,14 +1,16 @@
+import { LoginData } from './../../app.interfaces';
+import { MainDataService } from './../../maindata.service';
 import { ServerError } from './../../backend.service';
 import { WorkspaceDataService } from './../workspacedata.service';
 import { GetFileResponseData, CheckWorkspaceResponseData } from './../workspace.interfaces';
 import { ConfirmDialogComponent, ConfirmDialogData, MessageDialogComponent,
   MessageDialogData, MessageType } from '../../iqb-common';
 import { DataSource } from '@angular/cdk/collections';
-import { Observable, BehaviorSubject } from 'rxjs';
+import { Observable, BehaviorSubject, Subscription, merge } from 'rxjs';
 import { MatTableDataSource } from '@angular/material/table';
 import { MatSnackBar } from '@angular/material';
 import { BackendService } from '../backend.service';
-import { Input, Output, EventEmitter, Component, OnInit, Inject, ElementRef } from '@angular/core';
+import { Input, Output, EventEmitter, Component, OnInit, Inject, ElementRef, OnDestroy } from '@angular/core';
 import { NgModule, ViewChild } from '@angular/core';
 import { MatSort, MatDialog } from '@angular/material';
 import { HttpEventType, HttpErrorResponse, HttpEvent } from '@angular/common/http';
@@ -19,12 +21,13 @@ import { IqbFilesUploadQueueComponent, IqbFilesUploadInputForDirective } from '.
   templateUrl: './files.component.html',
   styleUrls: ['./files.component.css']
 })
-export class FilesComponent implements OnInit {
+export class FilesComponent implements OnInit, OnDestroy {
   public serverfiles: MatTableDataSource<GetFileResponseData>;
   public displayedColumns = ['checked', 'filename', 'typelabel', 'filesize', 'filedatetime'];
   public uploadUrl = '';
   public fileNameAlias = 'fileforvo';
   public dataLoading = false;
+  private logindataSubscription: Subscription = null;
 
   // for workspace-check
   public checkErrors = [];
@@ -36,6 +39,7 @@ export class FilesComponent implements OnInit {
   constructor(
     @Inject('SERVER_URL') private serverUrl: string,
     private bs: BackendService,
+    private mds: MainDataService,
     private wds: WorkspaceDataService,
     public confirmDialog: MatDialog,
     public messsageDialog: MatDialog,
@@ -45,7 +49,11 @@ export class FilesComponent implements OnInit {
   }
 
   ngOnInit() {
-    this.updateFileList();
+    this.logindataSubscription = this.mds.loginData$.subscribe(ld => {
+        const ws = this.wds.ws;
+        let at = ld ? ld.admintoken : '';
+        this.updateFileList((ws <= 0) || (at.length === 0));
+    });
   }
 
   // ***********************************************************************************
@@ -119,23 +127,27 @@ export class FilesComponent implements OnInit {
   }
 
   // ***********************************************************************************
-  updateFileList() {
+  updateFileList(empty = false) {
     this.checkErrors = [];
     this.checkWarnings = [];
     this.checkInfos = [];
 
-    this.dataLoading = true;
-    this.bs.getFiles().subscribe(
-      (filedataresponse: GetFileResponseData[]) => {
-        this.serverfiles = new MatTableDataSource(filedataresponse);
-        this.serverfiles.sort = this.sort;
-        this.dataLoading = false;
-        this.wds.setNewErrorMsg();
-      }, (err: ServerError) => {
-        this.wds.setNewErrorMsg(err);
-        this.dataLoading = false;
-      }
-    );
+    if (empty) {
+      this.serverfiles = new MatTableDataSource([]);
+    } else {
+      this.dataLoading = true;
+      this.bs.getFiles().subscribe(
+        (filedataresponse: GetFileResponseData[]) => {
+          this.serverfiles = new MatTableDataSource(filedataresponse);
+          this.serverfiles.sort = this.sort;
+          this.dataLoading = false;
+          this.wds.setNewErrorMsg();
+        }, (err: ServerError) => {
+          this.wds.setNewErrorMsg(err);
+          this.dataLoading = false;
+        }
+      );
+    }
   }
 
   // ***********************************************************************************
@@ -167,4 +179,11 @@ export class FilesComponent implements OnInit {
       }
     );
   }
+
+  // % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
+  ngOnDestroy() {
+    if (this.logindataSubscription !== null) {
+      this.logindataSubscription.unsubscribe();
+    }
+  }
 }
diff --git a/src/app/workspace/workspace-routing.module.ts b/src/app/workspace/workspace-routing.module.ts
index f88d869b..0761950b 100644
--- a/src/app/workspace/workspace-routing.module.ts
+++ b/src/app/workspace/workspace-routing.module.ts
@@ -11,7 +11,7 @@ const routes: Routes = [
     path: 'ws/:ws',
     component: WorkspaceComponent,
     children: [
-      {path: '', redirectTo: 'myfiles', pathMatch: 'full'},
+      {path: '', redirectTo: 'files', pathMatch: 'full'},
       {path: 'files', component: FilesComponent},
       {path: 'syscheck', component: SyscheckComponent},
       {path: 'monitor', component: MonitorComponent},
diff --git a/src/app/workspace/workspace.component.css b/src/app/workspace/workspace.component.css
index aef1123e..c695d220 100644
--- a/src/app/workspace/workspace.component.css
+++ b/src/app/workspace/workspace.component.css
@@ -1,10 +1,7 @@
 /* --------------------------------------------- */
 #buttonsContainer {
-  position: absolute;
-  right: 5px;
-  top: 2px;
-  left: 5px;
   color: white;
+  padding: 0 10px 0 0;
 }
 #buttonsContainer .material-icons {
   font-size: 2.0rem;
diff --git a/src/app/workspace/workspace.component.html b/src/app/workspace/workspace.component.html
index 09939a75..b162d521 100644
--- a/src/app/workspace/workspace.component.html
+++ b/src/app/workspace/workspace.component.html
@@ -3,7 +3,7 @@
     <img src="assets/IQB-LogoA.png" matTooltip="Startseite"/>
   </a>
   <div fxLayout="row" fxLayoutAlign="end center">
-    <p>{{ wds?.wsName }} ({{wds?.wsRole}})</p>
+    <p>{{ pageTitle }}</p>
   </div>
 </div>
 <div class="page-body">
diff --git a/src/app/workspace/workspace.component.ts b/src/app/workspace/workspace.component.ts
index ac196ef3..2700ee25 100644
--- a/src/app/workspace/workspace.component.ts
+++ b/src/app/workspace/workspace.component.ts
@@ -20,6 +20,7 @@ export class WorkspaceComponent implements OnInit, OnDestroy {
 
   public pageTitle = '';
   private routingSubscription: Subscription = null;
+  private logindataSubscription: Subscription = null;
 
   // CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
   constructor(
@@ -31,7 +32,22 @@ export class WorkspaceComponent implements OnInit, OnDestroy {
   // CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
   ngOnInit() {
     this.routingSubscription = this.route.params.subscribe(params => {
-      this.wds.setWorkspaceId(Number(params['ws']));
+      const ws = Number(params['ws']);
+      this.wds.setWorkspaceId(ws);
+      if ((this.mds.adminToken.length > 0) && (ws > 0)) {
+        this.pageTitle = this.mds.getWorkspaceName(ws) + ' (' + this.mds.getWorkspaceRole(ws) + ')';
+      } else {
+        this.pageTitle = '';
+      }
+    });
+
+    this.logindataSubscription = this.mds.loginData$.subscribe(ld => {
+      const ws = this.wds.ws;
+      if (ws > 0) {
+        this.pageTitle = this.mds.getWorkspaceName(ws) + ' (' + this.mds.getWorkspaceRole(ws) + ')';
+      } else {
+        this.pageTitle = '';
+      }
     });
   }
 
@@ -40,5 +56,8 @@ export class WorkspaceComponent implements OnInit, OnDestroy {
     if (this.routingSubscription !== null) {
       this.routingSubscription.unsubscribe();
     }
+    if (this.logindataSubscription !== null) {
+      this.logindataSubscription.unsubscribe();
+    }
   }
 }
diff --git a/src/app/workspace/workspace.interceptor.ts b/src/app/workspace/workspace.interceptor.ts
index 06dec6bc..01876554 100644
--- a/src/app/workspace/workspace.interceptor.ts
+++ b/src/app/workspace/workspace.interceptor.ts
@@ -25,7 +25,6 @@ export class WorkspaceInterceptor implements HttpInterceptor {
       }
     });
 
-    console.log('### # workspace.interceptor >' + requestA.headers.get('AuthToken'));
     return next.handle(requestA);
   }
 }
diff --git a/src/app/workspace/workspace.module.ts b/src/app/workspace/workspace.module.ts
index 10808ec9..01832629 100644
--- a/src/app/workspace/workspace.module.ts
+++ b/src/app/workspace/workspace.module.ts
@@ -23,6 +23,7 @@ import { MonitorComponent } from './monitor/monitor.component';
 import { MatExpansionModule } from '@angular/material/expansion';
 import {MatGridListModule} from '@angular/material/grid-list';
 import { SyscheckComponent } from './syscheck/syscheck.component';
+import { httpInterceptorProviders } from './workspace.interceptor';
 
 @NgModule({
   imports: [
@@ -66,6 +67,7 @@ import { SyscheckComponent } from './syscheck/syscheck.component';
   ],
   providers: [
     BackendService,
+    httpInterceptorProviders,
     WorkspaceDataService
   ],
 })
diff --git a/src/app/workspace/workspacedata.service.ts b/src/app/workspace/workspacedata.service.ts
index e0e8ac0b..3aee6f83 100644
--- a/src/app/workspace/workspacedata.service.ts
+++ b/src/app/workspace/workspacedata.service.ts
@@ -20,14 +20,8 @@ export class WorkspaceDataService {
   public workspaceId$ = new BehaviorSubject<number>(-1);
   public globalErrorMsg$ = new BehaviorSubject<ServerError>(null);
 
-  private _wsName : string;
-  public get wsName() : string {
-    return this._wsName;
-  }
-
-  private _wsRole : string;
-  public get wsRole() : string {
-    return this._wsRole;
+  public get ws() : number {
+    return this.workspaceId$.getValue();
   }
 
 
@@ -74,7 +68,5 @@ export class WorkspaceDataService {
   // *******************************************************************************************************
   setWorkspaceId(newId: number) {
     this.workspaceId$.next(newId);
-    this._wsName = this.mds.getWorkspaceName(newId);
-    this._wsRole = this.mds.getWorkspaceRole(newId);
   }
 }
diff --git a/src/iqb-theme2.scss b/src/iqb-theme2.scss
index c27f1913..215f8b27 100644
--- a/src/iqb-theme2.scss
+++ b/src/iqb-theme2.scss
@@ -12,5 +12,5 @@ body {
   height: 100%;
   margin: 0;
   font-family: "Orienta";
-  background: #003333;
+  background: linear-gradient(to left, #003333, #045659, #0d7b84, #1aa2b2, #2acae5)
 }
diff --git a/src/styles.css b/src/styles.css
index 94b3577a..5f1fdb84 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -12,15 +12,8 @@
   overflow-x: auto;
   position: absolute;
   width: 100%;
-  top: 70px;
+  top: 50px;
   bottom: 0;
-  background: linear-gradient(to left, #003333, #045659, #0d7b84, #1aa2b2, #2acae5)
-  /* background-image: linear-gradient(to bottom, #003333, #00465d, #005791, #005ebe, #8854d0); */
-  /* display: flex;
-  flex-direction: row;
-  flex-wrap: nowrap;
-  align-items: flex-start;
-  justify-content: left; */
 }
 
 
@@ -37,3 +30,6 @@
   right: 0;
 }
 
+.logo img {
+  width: 100px;
+}
-- 
GitLab