Newer
Older

andreistroescu
committed
import { Component, OnInit, ViewChild } from '@angular/core';
import { BackendService, UnitResponse, ResultData, ReviewData, LogData } from './../backend.service';

andreistroescu
committed
import { MainDatastoreService } from './../maindatastore.service';
import { MatSnackBar, MatSort, MatTableDataSource } from '@angular/material';
import { SelectionModel } from '@angular/cdk/collections';
@Component({
templateUrl: './results.component.html',
styleUrls: ['./results.component.css']
})
export class ResultsComponent implements OnInit {
displayedColumns: string[] = ['selectCheckbox', 'groupname', 'bookletsStarted', 'num_units_min', 'num_units_max', 'num_units_mean'];
private resultDataSource = new MatTableDataSource<ResultData>([]);

andreistroescu
committed
private isAdmin = false;
// prepared for selection if needed sometime
private tableselectionCheckbox = new SelectionModel<ResultData>(true, []);
private dataLoading = false;

andreistroescu
committed
@ViewChild(MatSort) sort: MatSort;
constructor(
private bs: BackendService,
private mds: MainDatastoreService,
public snackBar: MatSnackBar
) {
this.mds.isAdmin$.subscribe(
i => this.isAdmin = i);
}
this.mds.adminToken$.subscribe(at => this.updateTable());
this.mds.workspaceId$.subscribe(ws => this.updateTable());
// console.log(saveAs);
updateTable() {
this.dataLoading = true;
this.tableselectionCheckbox.clear();
this.bs.getResultData(this.mds.adminToken$.getValue(), this.mds.workspaceId$.getValue()).subscribe(
(resultData: ResultData[]) => {
this.dataLoading = false;
this.resultDataSource = new MatTableDataSource<ResultData>(resultData);
this.resultDataSource.sort = this.sort;

andreistroescu
committed
}

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));
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
// 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
downloadResponsesCSV() {
if (this.tableselectionCheckbox.selected.length > 0) {
this.dataLoading = true;
const selectedGroups: string[] = [];
this.tableselectionCheckbox.selected.forEach(element => {
selectedGroups.push(element.groupname);
});
this.bs.getResponses(
this.mds.adminToken$.getValue(),
this.mds.workspaceId$.getValue(),
selectedGroups).subscribe(
(responseData: UnitResponse[]) => {
if (responseData.length > 0) {
const columnDelimiter = ';';
const lineDelimiter = '\n';
let myCsvData = 'groupname' + columnDelimiter + 'loginname' + columnDelimiter + 'code' + columnDelimiter +
'bookletname' + columnDelimiter + 'unitname' + columnDelimiter + 'responses' + lineDelimiter;
responseData.forEach((resp: UnitResponse) => {
if ((resp.responses !== null) && (resp.responses.length > 0)) {
myCsvData += '"' + resp.groupname + '"' + columnDelimiter + '"' + resp.loginname + '"' + columnDelimiter + '"' + resp.code + '"' + columnDelimiter +
'"' + resp.bookletname + '"' + columnDelimiter + '"' + resp.unitname + '"' + columnDelimiter + resp.responses.replace(/\\"/g, '""') + 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;
})
}
}
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
// 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
downloadReviewsCSV() {
if (this.tableselectionCheckbox.selected.length > 0) {
this.dataLoading = true;
const selectedGroups: string[] = [];
this.tableselectionCheckbox.selected.forEach(element => {
selectedGroups.push(element.groupname);
});
this.bs.getReviews(
this.mds.adminToken$.getValue(),
this.mds.workspaceId$.getValue(),
selectedGroups).subscribe(
(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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
downloadLogsCSV() {
if (this.tableselectionCheckbox.selected.length > 0) {
this.dataLoading = true;
const selectedGroups: string[] = [];
this.tableselectionCheckbox.selected.forEach(element => {
selectedGroups.push(element.groupname);
});
this.bs.getLogs(
this.mds.adminToken$.getValue(),
this.mds.workspaceId$.getValue(),
selectedGroups).subscribe(
(responseData: LogData[]) => {
if (responseData.length > 0) {
const columnDelimiter = ';';
const lineDelimiter = '\n';
let myCsvData = 'groupname' + columnDelimiter + 'loginname' + columnDelimiter + 'code' + columnDelimiter +
'bookletname' + columnDelimiter + 'unitname' + columnDelimiter +
'logtime' + 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.logtime + '"' + 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;
})
}
}