Newer
Older
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, Subscription, merge } from 'rxjs';
import { MatTableDataSource } from '@angular/material/table';
import { MatSnackBar } from '@angular/material';
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';
import { IqbFilesUploadQueueComponent, IqbFilesUploadInputForDirective } from '../../iqb-files';
templateUrl: './files.component.html',
styleUrls: ['./files.component.css']
export class FilesComponent implements OnInit, OnDestroy {
public serverfiles: MatTableDataSource<GetFileResponseData>;
public displayedColumns = ['checked', 'filename', 'typelabel', 'filesize', 'filedatetime'];
private logindataSubscription: Subscription = null;
// for workspace-check
public checkErrors = [];
public checkWarnings = [];
public checkInfos = [];
@ViewChild(MatSort) sort: MatSort;
constructor(
@Inject('SERVER_URL') private serverUrl: string,
private bs: BackendService,
public confirmDialog: MatDialog,
public messsageDialog: MatDialog,
public snackBar: MatSnackBar
) {
this.uploadUrl = this.serverUrl + 'php_admin/uploadFile.php';
this.logindataSubscription = this.mds.loginData$.subscribe(ld => {
const ws = this.wds.ws;
let at = ld ? ld.admintoken : '';
this.updateFileList((ws <= 0) || (at.length === 0));
});
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
}
// ***********************************************************************************
checkAll(isChecked: boolean) {
this.serverfiles.data.forEach(element => {
element.isChecked = isChecked;
});
}
// ***********************************************************************************
deleteFiles() {
this.checkErrors = [];
this.checkWarnings = [];
this.checkInfos = [];
const filesToDelete = [];
this.serverfiles.data.forEach(element => {
if (element.isChecked) {
filesToDelete.push(element.type + '::' + element.filename);
}
});
if (filesToDelete.length > 0) {
let prompt = 'Sie haben ';
if (filesToDelete.length > 1) {
prompt = prompt + filesToDelete.length + ' Dateien ausgewählt. Sollen';
} else {
prompt = prompt + ' eine Datei ausgewählt. Soll';
}
const dialogRef = this.confirmDialog.open(ConfirmDialogComponent, {
width: '400px',
data: <ConfirmDialogData>{
title: 'Löschen von Dateien',
content: prompt + ' diese gelöscht werden?',
confirmbuttonlabel: 'Löschen'
}
});
dialogRef.afterClosed().subscribe(result => {
if (result !== false) {
// =========================================================
this.dataLoading = true;
this.bs.deleteFiles(filesToDelete).subscribe(deletefilesresponse => {
if (deletefilesresponse instanceof ServerError) {
this.wds.setNewErrorMsg(deletefilesresponse as ServerError);
} else {
const deletefilesresponseOk = deletefilesresponse as string;
if ((deletefilesresponseOk.length > 5) && (deletefilesresponseOk.substr(0, 2) === 'e:')) {
this.snackBar.open(deletefilesresponseOk.substr(2), 'Fehler', {duration: 1000});
this.snackBar.open(deletefilesresponseOk, '', {duration: 1000});
this.updateFileList();
}
// =========================================================
}
});
} else {
this.messsageDialog.open(MessageDialogComponent, {
width: '400px',
data: <MessageDialogData>{
title: 'Löschen von Dateien',
content: 'Bitte markieren Sie erst Dateien!',
type: MessageType.error
}
});
}
}
// ***********************************************************************************
this.checkErrors = [];
this.checkWarnings = [];
this.checkInfos = [];
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;
}
);
}
}
// ***********************************************************************************
getDownloadRef(element: GetFileResponseData): string {
return this.serverUrl
+ '&fn=' + element.filename;
}
checkWorkspace() {
this.checkErrors = [];
this.checkWarnings = [];
this.checkInfos = [];
this.dataLoading = true;
this.bs.checkWorkspace().subscribe(
(checkResponse: CheckWorkspaceResponseData) => {
// this.serverfiles = new MatTableDataSource(filedataresponse);
// this.serverfiles.sort = this.sort;
this.checkErrors = checkResponse.errors;
this.checkWarnings = checkResponse.warnings;
this.checkInfos = checkResponse.infos;
this.wds.setNewErrorMsg();
this.dataLoading = false;
}, (err: ServerError) => {
this.wds.setNewErrorMsg(err);
this.dataLoading = false;
}
// % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
ngOnDestroy() {
if (this.logindataSubscription !== null) {
this.logindataSubscription.unsubscribe();
}
}