Newer
Older
import { LogData } from './../workspace.interfaces';
import { WorkspaceDataService } from './../workspacedata.service';
import { ConfirmDialogComponent, ConfirmDialogData } from 'iqb-components';
import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core';
import { MatSnackBar, MatSort, MatTableDataSource, MatDialog } from '@angular/material';
import { SelectionModel } from '@angular/cdk/collections';
import { ResultData, UnitResponse, ReviewData } from '../workspace.interfaces';
@Component({
templateUrl: './results.component.html',
styleUrls: ['./results.component.css']
})
export class ResultsComponent implements OnInit, OnDestroy {
displayedColumns: string[] = ['selectCheckbox', 'groupname', 'bookletsStarted', 'num_units_min', 'num_units_max', 'num_units_mean', 'lastchange'];
public tableselectionCheckbox = new SelectionModel<ResultData>(true, []);
public dataLoading = false;
private workspaceIdSubscription: Subscription = null;

andreistroescu
committed
@ViewChild(MatSort) sort: MatSort;
constructor(
private bs: BackendService,
private deleteConfirmDialog: MatDialog,

andreistroescu
committed
public snackBar: MatSnackBar
this.workspaceIdSubscription = this.wds.workspaceId$.subscribe(ws => {
this.updateTable();
});
if (this.wds.wsRole === 'MO') {
this.resultDataSource = new MatTableDataSource<ResultData>([]);
} else {
this.dataLoading = true;
this.bs.getResultData().subscribe(
(resultData: ResultData[]) => {
this.dataLoading = false;
this.resultDataSource = new MatTableDataSource<ResultData>(resultData);
this.resultDataSource.sort = this.sort;
}
)
}

andreistroescu
committed
isAllSelected() {
const numSelected = this.tableselectionCheckbox.selected.length;
return numSelected === numRows;
}
masterToggle() {
this.isAllSelected() ?
this.tableselectionCheckbox.clear() :
this.resultDataSource.data.forEach(row => this.tableselectionCheckbox.select(row));
// 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
downloadResponsesCSV() {
if (this.tableselectionCheckbox.selected.length > 0) {
this.dataLoading = true;
const selectedGroups: string[] = [];
this.tableselectionCheckbox.selected.forEach(element => {
selectedGroups.push(element.groupname);
});
(responseData: UnitResponse[]) => {
if (responseData.length > 0) {
const columnDelimiter = ';';
const lineDelimiter = '\n';
let myCsvData = 'groupname' + columnDelimiter + 'loginname' + columnDelimiter + 'code' + columnDelimiter +
'bookletname' + columnDelimiter + 'unitname' + columnDelimiter + 'responses' + columnDelimiter +
'restorePoint' + columnDelimiter + 'responseType' + columnDelimiter + 'response-ts' + columnDelimiter +
'restorePoint-ts' + columnDelimiter + 'laststate' + lineDelimiter;
myCsvData += '"' + resp.groupname + '"' + columnDelimiter + '"' + resp.loginname + '"' + columnDelimiter + '"' + resp.code + '"' + columnDelimiter +
'"' + resp.bookletname + '"' + columnDelimiter + '"' + resp.unitname + '"' + columnDelimiter;
if ((resp.responses !== null) && (resp.responses.length > 0)) {
myCsvData += resp.responses.replace(/\\"/g, '""') + columnDelimiter;
} else {
myCsvData += columnDelimiter;
}
if ((resp.restorepoint !== null) && (resp.restorepoint.length > 0)) {
myCsvData += resp.restorepoint.replace(/\\"/g, '""') + columnDelimiter;
} else {
myCsvData += columnDelimiter;
}
if ((resp.responsetype !== null) && (resp.responsetype.length > 0)) {
myCsvData += '"' + resp.responsetype + '"' + columnDelimiter;
} else {
myCsvData += columnDelimiter;
}
myCsvData += resp.responses_ts + columnDelimiter + resp.restorepoint_ts + columnDelimiter;
if ((resp.laststate !== null) && (resp.laststate.length > 0)) {
myCsvData += '"' + resp.laststate + '"' + lineDelimiter;
}
});
var blob = new Blob([myCsvData], {type: "text/csv;charset=utf-8"});
saveAs(blob, "iqb-testcenter-responses.csv");
} else {
this.snackBar.open('Keine Daten verfügbar.', 'Fehler', {duration: 3000});
}
this.tableselectionCheckbox.clear();
this.dataLoading = false;
})
}
}
// 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
downloadReviewsCSV() {
if (this.tableselectionCheckbox.selected.length > 0) {
this.dataLoading = true;
const selectedGroups: string[] = [];
this.tableselectionCheckbox.selected.forEach(element => {
selectedGroups.push(element.groupname);
});
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
(responseData: ReviewData[]) => {
if (responseData.length > 0) {
// collect categories
const allCategories: string[] = [];
responseData.forEach((resp: ReviewData) => {
resp.categories.split(' ').forEach(s => {
const s_trimmed = s.trim();
if (s_trimmed.length > 0) {
if (!allCategories.includes(s_trimmed)) {
allCategories.push(s_trimmed);
}
}
})
});
const columnDelimiter = ';';
const lineDelimiter = '\n';
let myCsvData = 'groupname' + columnDelimiter + 'loginname' + columnDelimiter + 'code' + columnDelimiter +
'bookletname' + columnDelimiter + 'unitname' + columnDelimiter +
'priority' + columnDelimiter;
allCategories.forEach(s => {
myCsvData += 'category: ' + s + columnDelimiter;
});
myCsvData += 'reviewtime' + columnDelimiter + 'entry' + lineDelimiter;
responseData.forEach((resp: ReviewData) => {
if ((resp.entry !== null) && (resp.entry.length > 0)) {
myCsvData += '"' + resp.groupname + '"' + columnDelimiter + '"' + resp.loginname + '"' + columnDelimiter + '"' + resp.code + '"' + columnDelimiter +
'"' + resp.bookletname + '"' + columnDelimiter + '"' + resp.unitname + '"' + columnDelimiter + '"' + resp.priority + '"' + columnDelimiter;
const resp_categories = resp.categories.split(' ');
allCategories.forEach(s => {
if (resp_categories.includes(s)) {
myCsvData += '"X"' + columnDelimiter;
} else {
myCsvData += columnDelimiter;
}
});
myCsvData += '"' + resp.reviewtime + '"' + columnDelimiter + '"' + resp.entry + '"' + lineDelimiter;
}
});
var blob = new Blob([myCsvData], {type: "text/csv;charset=utf-8"});
saveAs(blob, "iqb-testcenter-reviews.csv");
} else {
this.snackBar.open('Keine Daten verfügbar.', 'Fehler', {duration: 3000});
}
this.tableselectionCheckbox.clear();
this.dataLoading = false;
})
}

andreistroescu
committed
// 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
downloadLogsCSV() {
if (this.tableselectionCheckbox.selected.length > 0) {
this.dataLoading = true;
const selectedGroups: string[] = [];
this.tableselectionCheckbox.selected.forEach(element => {
selectedGroups.push(element.groupname);
});
(responseData: LogData[]) => {
if (responseData.length > 0) {
const columnDelimiter = ';';
const lineDelimiter = '\n';
let myCsvData = 'groupname' + columnDelimiter + 'loginname' + columnDelimiter + 'code' + columnDelimiter +
'bookletname' + columnDelimiter + 'unitname' + columnDelimiter +
'timestamp' + columnDelimiter + 'logentry' + lineDelimiter;
responseData.forEach((resp: LogData) => {
if ((resp.logentry !== null) && (resp.logentry.length > 0)) {
myCsvData += '"' + resp.groupname + '"' + columnDelimiter + '"' + resp.loginname + '"' + columnDelimiter + '"' + resp.code + '"' + columnDelimiter +
'"' + resp.bookletname + '"' + columnDelimiter + '"' + resp.unitname + '"' + columnDelimiter + '"' +
resp.timestamp.toString() + '"' + columnDelimiter + resp.logentry.replace(/\\"/g, '""') + lineDelimiter;
}
});
var blob = new Blob([myCsvData], {type: "text/csv;charset=utf-8"});
saveAs(blob, "iqb-testcenter-logs.csv");
} else {
this.snackBar.open('Keine Daten verfügbar.', 'Fehler', {duration: 3000});
}
this.tableselectionCheckbox.clear();
this.dataLoading = false;
})
}
}
deleteData() {
if (this.tableselectionCheckbox.selected.length > 0) {
const selectedGroups: string[] = [];
this.tableselectionCheckbox.selected.forEach(element => {
selectedGroups.push(element.groupname);
});
let prompt = 'Es werden alle Antwort- und Logdaten in der Datenbank für diese ';
if (selectedGroups.length > 1) {
prompt = prompt + selectedGroups.length + ' Gruppen ';
} else {
prompt = prompt + ' Gruppe "' + selectedGroups[0] + '" ';
}
const dialogRef = this.deleteConfirmDialog.open(ConfirmDialogComponent, {
width: '400px',
data: <ConfirmDialogData>{
title: 'Löschen von Gruppendaten',
content: prompt + 'gelöscht. Fortsetzen?',
confirmbuttonlabel: 'Gruppendaten löschen',
showcancel: true
}
});
dialogRef.afterClosed().subscribe(result => {
if (result !== false) {
// =========================================================
this.dataLoading = true;
this.bs.deleteData(selectedGroups).subscribe((deleteOk: boolean) => {
this.tableselectionCheckbox.clear();
this.dataLoading = false;
});
}
});
}
}
// % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
ngOnDestroy() {
if (this.workspaceIdSubscription !== null) {
this.workspaceIdSubscription.unsubscribe();
}
}