diff --git a/src/app/workspace-admin/files/files.component.ts b/src/app/workspace-admin/files/files.component.ts index ba60856e2e2cd77804e5a64ae2056f3d0aa85c16..4ebf8bf1ab2e961c42646e9d6bf7ec0875147e4a 100644 --- a/src/app/workspace-admin/files/files.component.ts +++ b/src/app/workspace-admin/files/files.component.ts @@ -41,12 +41,12 @@ export class FilesComponent implements OnInit { public fileNameAlias = 'fileforvo'; public typeLabels = { - 'Testtakers': 'Teilnehmerliste', - 'Booklet': 'Testheft', - 'SysCheck': 'Systemcheck', - 'Resource': 'Ressource', - 'Unit': 'Unit' - } + Testtakers: 'Teilnehmerliste', + Booklet: 'Testheft', + SysCheck: 'Systemcheck', + Resource: 'Ressource', + Unit: 'Unit' + }; @ViewChild(MatSort, { static: true }) sort: MatSort; public fileStats: FileStats = { @@ -83,7 +83,6 @@ export class FilesComponent implements OnInit { public deleteFiles(): void { if (this.wds.wsRole === 'RW') { - const filesToDelete = []; this.serverfiles.data.forEach(element => { if (element.isChecked) { @@ -168,7 +167,7 @@ export class FilesComponent implements OnInit { if (file.report.error && file.report.error.length) { stats.valid += 1; stats.types[file.type].valid += 1; - stats.testtakers += (typeof file.info.testtakers === "number") ? file.info.testtakers : 0; + stats.testtakers += (typeof file.info.testtakers === 'number') ? file.info.testtakers : 0; } }); return stats; diff --git a/src/app/workspace-admin/files/iqb-files/iqb-files.module.ts b/src/app/workspace-admin/files/iqb-files/iqb-files.module.ts index d8097f7ddbe1ece417a0eee74f71a962c9dcc7b4..b4911ad8128f2b5b9b912f54d9d1b72d3f8a64e1 100644 --- a/src/app/workspace-admin/files/iqb-files/iqb-files.module.ts +++ b/src/app/workspace-admin/files/iqb-files/iqb-files.module.ts @@ -9,18 +9,18 @@ import { IqbComponentsModule } from 'iqb-components'; import { IqbFilesUploadComponent } from './iqbFilesUpload/iqbFilesUpload.component'; import { IqbFilesUploadQueueComponent } from './iqbFilesUploadQueue/iqbFilesUploadQueue.component'; import { IqbFilesUploadInputForDirective } from './iqbFilesUploadInputFor/iqbFilesUploadInputFor.directive'; -import {AlertModule} from '../../../shared/alert/alert.module'; +import { AlertModule } from '../../../shared/alert/alert.module'; @NgModule({ - imports: [ - MatButtonModule, - MatProgressBarModule, - MatIconModule, - MatCardModule, - IqbComponentsModule, - CommonModule, - AlertModule - ], + imports: [ + MatButtonModule, + MatProgressBarModule, + MatIconModule, + MatCardModule, + IqbComponentsModule, + CommonModule, + AlertModule + ], declarations: [ IqbFilesUploadComponent, IqbFilesUploadQueueComponent, diff --git a/src/app/workspace-admin/files/iqb-files/iqbFilesUpload/iqbFilesUpload.component.ts b/src/app/workspace-admin/files/iqb-files/iqbFilesUpload/iqbFilesUpload.component.ts index 75406723bcea16036b498fb702b9effbdd88f260..71cac8ad7b24913445d53c57bcb328837e0887ce 100644 --- a/src/app/workspace-admin/files/iqb-files/iqbFilesUpload/iqbFilesUpload.component.ts +++ b/src/app/workspace-admin/files/iqb-files/iqbFilesUpload/iqbFilesUpload.component.ts @@ -1,9 +1,13 @@ -import {Component, EventEmitter, HostBinding, Input, OnDestroy, OnInit, Output} from '@angular/core'; -import {HttpClient, HttpErrorResponse, HttpEvent, HttpEventType, HttpHeaders, HttpParams} from '@angular/common/http'; -import {ApiError} from '../../../../app.interfaces'; - - -interface uploadResponse { +import { + Component, EventEmitter, HostBinding, Input, OnDestroy, OnInit, Output +} from '@angular/core'; +import { + HttpClient, HttpErrorResponse, HttpEvent, HttpEventType, HttpHeaders, HttpParams +} from '@angular/common/http'; +import { Subscription } from 'rxjs'; +import { ApiError } from '../../../../app.interfaces'; + +interface UploadResponse { [filename: string]: { warning?: string[]; error?: string[]; @@ -11,165 +15,164 @@ interface uploadResponse { } } +export enum UploadStatus { + ready, + busy, + ok, + error +} @Component({ - selector: 'iqb-files-upload', - templateUrl: `./iqbFilesUpload.component.html`, - exportAs: 'iqbFilesUpload', - styleUrls: ['../iqb-files.scss'], - }) - - export class IqbFilesUploadComponent implements OnInit, OnDestroy { - @HostBinding('class') myclass = 'iqb-files-upload'; - - constructor( - private myHttpClient: HttpClient) { } - - - private _status: UploadStatus; - get status(): UploadStatus { - return this._status; - } - set status(newstatus: UploadStatus) { - this._status = newstatus; - this.statusChangedEvent.emit(this); - } + selector: 'iqb-files-upload', + templateUrl: './iqbFilesUpload.component.html', + exportAs: 'iqbFilesUpload', + styleUrls: ['../iqb-files.scss'] +}) +export class IqbFilesUploadComponent implements OnInit, OnDestroy { + @HostBinding('class') myclass = 'iqb-files-upload'; + + constructor( + private myHttpClient: HttpClient + ) { } + + private _status: UploadStatus; + get status(): UploadStatus { + return this._status; + } + set status(newstatus: UploadStatus) { + this._status = newstatus; + this.statusChangedEvent.emit(this); + } - private requestResponse: uploadResponse; - get uploadResponse(): uploadResponse { - switch (this._status) { - case UploadStatus.busy: - return {'': {info: ['Bitte warten']}}; - case UploadStatus.ready: - return {'': {info: ['Bereit']}}; - default: - return this.requestResponse; - } + private requestResponse: UploadResponse; + get uploadResponse(): UploadResponse { + switch (this._status) { + case UploadStatus.busy: + return { '': { info: ['Bitte warten'] } }; + case UploadStatus.ready: + return { '': { info: ['Bereit'] } }; + default: + return this.requestResponse; } + } - /* Http request input bindings */ - @Input() - httpUrl = 'http://localhost:8080'; - - @Input() - httpRequestHeaders: HttpHeaders | { - [header: string]: string | string[]; - } = new HttpHeaders().set('Content-Type', 'multipart/form-data'); + /* Http request input bindings */ + @Input() + httpUrl = 'http://localhost:8080'; // TODO use normal backend-connection instead - @Input() - httpRequestParams: HttpParams | { - [param: string]: string | string[]; - } = new HttpParams(); + @Input() + httpRequestHeaders: HttpHeaders | { + [header: string]: string | string[]; + } = new HttpHeaders().set('Content-Type', 'multipart/form-data'); - @Input() - fileAlias = 'file'; + @Input() + httpRequestParams: HttpParams | { + [param: string]: string | string[]; + } = new HttpParams(); - @Input() - folderName = ''; + @Input() + fileAlias = 'file'; - @Input() - folder = ''; + @Input() + folderName = ''; - @Input() - get file(): any { - return this._file; - } - set file(file: any) { - this._file = file; - this._filedate = this._file.lastModified; - this.total = this._file.size; - } + @Input() + folder = ''; - @Input() - set id(id: number) { - this._id = id; - } + @Input() + get file(): any { + return this._file; + } - get id(): number { - return this._id; - } + set file(file: any) { + this._file = file; + this._filedate = this._file.lastModified; + this.total = this._file.size; + } - @Output() removeFileRequestEvent = new EventEmitter<IqbFilesUploadComponent>(); - @Output() statusChangedEvent = new EventEmitter<IqbFilesUploadComponent>(); + @Input() + set id(id: number) { + this._id = id; + } - public progressPercentage = 0; - public loaded = 0; - private total = 0; - private _file: any; - private _filedate = ''; - private _id: number; - private fileUploadSubscription: any; + get id(): number { + return this._id; + } + @Output() removeFileRequestEvent = new EventEmitter<IqbFilesUploadComponent>(); + @Output() statusChangedEvent = new EventEmitter<IqbFilesUploadComponent>(); + + public progressPercentage = 0; + public loaded = 0; + private total = 0; + private _file: any; + private _filedate = ''; + private _id: number; + private fileUploadSubscription: Subscription; + + ngOnInit(): void { + this._status = UploadStatus.ready; + this.requestResponse = {}; + this.upload(); + } - ngOnInit() { - console.log("init new upload shit"); - this._status = UploadStatus.ready; - this.requestResponse = {}; - this.upload(); + upload(): void { + if (this.status !== UploadStatus.ready) { + return; } - upload(): void { - if (this.status === UploadStatus.ready) { - - this.status = UploadStatus.busy; - const formData = new FormData(); - formData.set(this.fileAlias, this._file, this._file.name); - if ((typeof this.folderName !== 'undefined') && (typeof this.folder !== 'undefined')) { - if (this.folderName.length > 0) { - formData.append(this.folderName, this.folder); - } - } - this.fileUploadSubscription = this.myHttpClient.post(this.httpUrl, formData, { - // headers: this.httpRequestHeaders, - observe: 'events', - params: this.httpRequestParams, - reportProgress: true, - responseType: 'json' - }).subscribe((event: HttpEvent<any>) => { - if (event.type === HttpEventType.UploadProgress) { - this.progressPercentage = Math.floor( event.loaded * 100 / event.total ); - this.loaded = event.loaded; - this.total = event.total; - this.status = UploadStatus.busy; - } else if (event.type === HttpEventType.Response) { - this.requestResponse = event.body; - this.status = UploadStatus.ok; - } - }, (err) => { - if (this.fileUploadSubscription) { - this.fileUploadSubscription.unsubscribe(); - } - this.status = UploadStatus.error; - let errorText = 'Hochladen nicht erfolgreich.'; - if (err instanceof HttpErrorResponse) { - errorText = (err as HttpErrorResponse).message; - } else if (err instanceof ApiError) { - const slashPos = err.info.indexOf(' // '); - errorText = (slashPos > 0) ? err.info.substr(slashPos + 4) : err.info; - } - this.requestResponse = {'': {error: [errorText]}}; - }); + this.status = UploadStatus.busy; + const formData = new FormData(); + formData.set(this.fileAlias, this._file, this._file.name); + if ((typeof this.folderName !== 'undefined') && (typeof this.folder !== 'undefined')) { + if (this.folderName.length > 0) { + formData.append(this.folderName, this.folder); } } - public remove(): void { - if (this.fileUploadSubscription) { - this.fileUploadSubscription.unsubscribe(); + this.fileUploadSubscription = this.myHttpClient.post(this.httpUrl, formData, { + // headers: this.httpRequestHeaders, TODO why is this commented, and would it not be better? + observe: 'events', + params: this.httpRequestParams, + reportProgress: true, + responseType: 'json' + }).subscribe((event: HttpEvent<any>) => { + if (event.type === HttpEventType.UploadProgress) { + this.progressPercentage = Math.floor(event.loaded * 100 / event.total); + this.loaded = event.loaded; + this.total = event.total; + this.status = UploadStatus.busy; + } else if (event.type === HttpEventType.Response) { + this.requestResponse = event.body; + this.status = UploadStatus.ok; } - this.removeFileRequestEvent.emit(this); - } - - ngOnDestroy(): void { + }, err => { if (this.fileUploadSubscription) { this.fileUploadSubscription.unsubscribe(); } + this.status = UploadStatus.error; + let errorText = 'Hochladen nicht erfolgreich.'; + if (err instanceof HttpErrorResponse) { + errorText = (err as HttpErrorResponse).message; + } else if (err instanceof ApiError) { + const slashPos = err.info.indexOf(' // '); + errorText = (slashPos > 0) ? err.info.substr(slashPos + 4) : err.info; + } + this.requestResponse = { '': { error: [errorText] } }; + }); + } + + public remove(): void { + if (this.fileUploadSubscription) { + this.fileUploadSubscription.unsubscribe(); } -} + this.removeFileRequestEvent.emit(this); + } -export enum UploadStatus { - ready, - busy, - ok, - error + ngOnDestroy(): void { + if (this.fileUploadSubscription) { + this.fileUploadSubscription.unsubscribe(); + } + } } diff --git a/src/app/workspace-admin/files/iqb-files/iqbFilesUploadInputFor/iqbFilesUploadInputFor.directive.ts b/src/app/workspace-admin/files/iqb-files/iqbFilesUploadInputFor/iqbFilesUploadInputFor.directive.ts index 468c0fbc88373c2d9b8ab6c180cad75b16316920..da6566cf606a623ad83139c29958b161402797a2 100644 --- a/src/app/workspace-admin/files/iqb-files/iqbFilesUploadInputFor/iqbFilesUploadInputFor.directive.ts +++ b/src/app/workspace-admin/files/iqb-files/iqbFilesUploadInputFor/iqbFilesUploadInputFor.directive.ts @@ -1,27 +1,29 @@ -import { Directive, ElementRef, HostListener, Input } from '@angular/core'; +import { + Directive, ElementRef, HostListener, Input +} from '@angular/core'; @Directive({ selector: 'input[iqbFilesUploadInputFor], div[iqbFilesUploadInputFor]', }) -export class IqbFilesUploadInputForDirective { +export class IqbFilesUploadInputForDirective { private _queue: any = null; private _element: HTMLElement; constructor(private element: ElementRef) { - this._element = this.element.nativeElement; + this._element = this.element.nativeElement; } @Input('iqbFilesUploadInputFor') set filesUploadQueue(value: any) { - if (value) { - this._queue = value; - } + if (value) { + this._queue = value; + } } @HostListener('change') public onChange(): any { - const files = this.element.nativeElement.files; + const { files } = this.element.nativeElement; // this.onFileSelected.emit(files); for (let i = 0; i < files.length; i++) { diff --git a/src/app/workspace-admin/files/iqb-files/iqbFilesUploadQueue/iqbFilesUploadQueue.component.ts b/src/app/workspace-admin/files/iqb-files/iqbFilesUploadQueue/iqbFilesUploadQueue.component.ts index 88e20e4c1c1a015c83b9c353d3b106042f5b3ad6..55152ad56e09a48ec0765dd80df8e1a2a72e9fda 100644 --- a/src/app/workspace-admin/files/iqb-files/iqbFilesUploadQueue/iqbFilesUploadQueue.component.ts +++ b/src/app/workspace-admin/files/iqb-files/iqbFilesUploadQueue/iqbFilesUploadQueue.component.ts @@ -4,14 +4,11 @@ import { import { HttpHeaders, HttpParams } from '@angular/common/http'; import { IqbFilesUploadComponent, UploadStatus } from '../iqbFilesUpload/iqbFilesUpload.component'; -/** - * A material design file upload queue component. - */ @Component({ selector: 'iqb-files-upload-queue', templateUrl: 'iqbFilesUploadQueue.component.html', exportAs: 'iqbFilesUploadQueue', - styleUrls: ['../iqb-files.scss'], + styleUrls: ['../iqb-files.scss'] }) export class IqbFilesUploadQueueComponent implements OnDestroy { @ViewChildren(IqbFilesUploadComponent) fileUploads: QueryList<IqbFilesUploadComponent>; @@ -63,27 +60,15 @@ export class IqbFilesUploadQueueComponent implements OnDestroy { this.files.splice(fileToRemove.id, 1); } -/* - updateStatus() { - this.numberOfErrors = 0; - this.numberOfUploads = 0; - - this.fileUploads.forEach((fileUpload) => { - - fileUpload.upload(); - }); - } */ - analyseStatus() { let someoneiscomplete = false; let someoneisbusy = false; let someoneisready = false; - this.fileUploads.forEach((fileUpload) => { + this.fileUploads.forEach(fileUpload => { if ((fileUpload.status === UploadStatus.ok) || (fileUpload.status === UploadStatus.error)) { someoneiscomplete = true; } else if (fileUpload.status === UploadStatus.busy) { someoneisbusy = true; - return; // forEach } else if (fileUpload.status === UploadStatus.ready) { someoneisready = true; } diff --git a/src/app/workspace-admin/workspace.component.ts b/src/app/workspace-admin/workspace.component.ts index e252a541ab2889b4819392273ec6b3e54e33cac3..8350007ece833e15a26d7704b565a960a31cd5eb 100644 --- a/src/app/workspace-admin/workspace.component.ts +++ b/src/app/workspace-admin/workspace.component.ts @@ -18,9 +18,9 @@ export class WorkspaceComponent implements OnInit, OnDestroy { ) { } ngOnInit(): void { - this.routingSubscription = this.route.params.subscribe((params) => { - this.wds.wsId = params['ws']; - this.bs.getWorkspaceData(this.wds.wsId).subscribe((wsData) => { + this.routingSubscription = this.route.params.subscribe(params => { + this.wds.wsId = params.ws; + this.bs.getWorkspaceData(this.wds.wsId).subscribe(wsData => { if (typeof wsData !== 'number') { this.wds.wsName = wsData.name; this.wds.wsRole = wsData.role;