Skip to content

Commit 107ac3b

Browse files
Mutugiiidogi
andauthored
manager: smoother survey submissions team column (fixes #9066) (#9074)
Co-authored-by: dogi <[email protected]>
1 parent d74b53d commit 107ac3b

File tree

5 files changed

+45
-35
lines changed

5 files changed

+45
-35
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.20.16",
4+
"version": "0.20.17",
55
"myplanet": {
6-
"latest": "v0.30.39",
7-
"min": "v0.29.39"
6+
"latest": "v0.30.63",
7+
"min": "v0.29.63"
88
},
99
"scripts": {
1010
"ng": "ng",

src/app/submissions/submissions.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
<mat-header-cell *matHeaderCellDef mat-sort-header="stepNum" i18n>Course Step</mat-header-cell>
6969
<mat-cell *matCellDef="let element" style="cursor: pointer">{{element.stepNum || ''}}</mat-cell>
7070
</ng-container>
71+
<ng-container matColumnDef="teamInfo">
72+
<mat-header-cell *matHeaderCellDef mat-sort-header="teamInfo" i18n>Team/Enterprise</mat-header-cell>
73+
<mat-cell *matCellDef="let element" style="cursor: pointer">
74+
<ng-container *ngIf="element.teamInfo">{{element.teamInfo?.name}} ({{element.teamInfo?.type}})</ng-container>
75+
</mat-cell>
76+
</ng-container>
7177
<ng-container matColumnDef="status">
7278
<mat-header-cell *matHeaderCellDef mat-sort-header="status" i18n>Status</mat-header-cell>
7379
<mat-cell *matCellDef="let element" [ngSwitch]="element.status" style="cursor: pointer">

src/app/submissions/submissions.component.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ import { MatSort } from '@angular/material/sort';
44
import { MatTableDataSource } from '@angular/material/table';
55
import { composeFilterFunctions, filterDropdowns, dropdownsFill, filterSpecificFieldsByWord } from '../shared/table-helpers';
66
import { Router, ActivatedRoute } from '@angular/router';
7-
import { takeUntil } from 'rxjs/operators';
8-
import { Subject, zip } from 'rxjs';
7+
import { takeUntil, map } from 'rxjs/operators';
8+
import { Subject, zip, forkJoin, of, Observable } from 'rxjs';
99
import { SubmissionsService } from './submissions.service';
1010
import { UserService } from '../shared/user.service';
1111
import { findDocuments } from '../shared/mangoQueries';
1212
import { DialogsLoadingService } from '../shared/dialogs/dialogs-loading.service';
1313
import { CoursesService } from '../courses/courses.service';
1414
import { DeviceInfoService, DeviceType } from '../shared/device-info.service';
15+
import { TeamsService } from '../teams/teams.service';
16+
1517
const columnsByFilterAndMode = {
1618
exam: {
1719
grade: [ 'name', 'courseTitle', 'stepNum', 'status', 'grade', 'user', 'lastUpdateTime', 'gradeTime' ]
1820
},
1921
survey: {
20-
grade: [ 'name', 'courseTitle', 'stepNum', 'status', 'user', 'lastUpdateTime' ],
21-
survey: [ 'name', 'courseTitle', 'stepNum', 'status', 'lastUpdateTime' ]
22+
grade: [ 'name', 'courseTitle', 'stepNum', 'teamInfo', 'status', 'user', 'lastUpdateTime' ],
23+
survey: [ 'name', 'courseTitle', 'stepNum', 'teamInfo', 'status', 'lastUpdateTime' ]
2224
}
2325
};
2426

@@ -31,7 +33,7 @@ export class SubmissionsComponent implements OnInit, AfterViewChecked, OnDestroy
3133

3234
@Input() isDialog = false;
3335
@Input() parentId: string;
34-
@Input() displayedColumns = [ 'name', 'courseTitle', 'stepNum', 'status', 'user', 'lastUpdateTime', 'gradeTime' ];
36+
@Input() displayedColumns = [ 'name', 'courseTitle', 'stepNum', 'teamInfo', 'status', 'user', 'lastUpdateTime', 'gradeTime' ];
3537
@Output() submissionClick = new EventEmitter<any>();
3638
@ViewChild(MatPaginator) paginator: MatPaginator;
3739
@ViewChild(MatSort) sort: MatSort;
@@ -60,6 +62,7 @@ export class SubmissionsComponent implements OnInit, AfterViewChecked, OnDestroy
6062
private coursesService: CoursesService,
6163
private dialogsLoadingService: DialogsLoadingService,
6264
private deviceInfoService: DeviceInfoService,
65+
private teamsService: TeamsService
6366
) {
6467
this.dialogsLoadingService.start();
6568
this.deviceType = this.deviceInfoService.getDeviceType();
@@ -89,13 +92,16 @@ export class SubmissionsComponent implements OnInit, AfterViewChecked, OnDestroy
8992
}
9093
return sList;
9194
}, []).map(submission => this.appendCourseInfo(submission, courses));
92-
// Sort in descending lastUpdateTime order, so the recent submission can be shown on the top
93-
submissions.sort((a, b) => b.lastUpdateTime - a.lastUpdateTime);
94-
this.submissions.data = submissions.map(submission => ({
95-
...submission, submittedBy: this.submissionsService.submissionName(submission.user)
96-
}));
97-
this.dialogsLoadingService.stop();
98-
this.applyFilter('');
95+
forkJoin(submissions.map(s => this.appendTeamInfo$(s))).subscribe(subs => {
96+
// Sort in descending lastUpdateTime order, so the recent submission can be shown on the top
97+
subs.sort((a, b) => b.lastUpdateTime - a.lastUpdateTime);
98+
this.submissions.data = subs.map(submission => ({
99+
...submission,
100+
submittedBy: this.submissionsService.submissionName(submission.user)
101+
}));
102+
this.dialogsLoadingService.stop();
103+
this.applyFilter('');
104+
});
99105
});
100106
this.submissionsService.updateSubmissions({ query: this.submissionQuery() });
101107
this.setupTable();
@@ -227,4 +233,9 @@ export class SubmissionsComponent implements OnInit, AfterViewChecked, OnDestroy
227233
return { ...submission, courseTitle: submissionCourse.doc.courseTitle, stepNum };
228234
}
229235

236+
appendTeamInfo$(submission): Observable<any> {
237+
if (!submission.team) { return of({ ...submission, teamName: '' }); }
238+
return this.teamsService.getTeamName(submission.team).pipe(map((teamInfo: any) => ({ ...submission, teamInfo })));
239+
}
240+
230241
}

src/app/submissions/submissions.service.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ export class SubmissionsService {
287287
return forkJoin(
288288
filteredSubmissions.map(submission => {
289289
if (submission.team) {
290-
return this.teamsService.getTeamName(submission.team).pipe(
291-
map(teamName => ({ ...submission, teamName }))
292-
);
290+
return this.teamsService.getTeamName(submission.team).pipe(map(teamInfo => ({ ...submission, teamInfo })));
293291
}
294292
return of(submission);
295293
})
@@ -304,7 +302,8 @@ export class SubmissionsService {
304302
'Age (years)': submission.user.birthDate ? ageFromBirthDate(time, submission.user.birthDate) : submission.user.age || 'N/A',
305303
'Planet': submission.source,
306304
'Date': submission.lastUpdateTime,
307-
'Team/Enterprise': submission.teamName || 'N/A',
305+
'Group': submission.teamInfo?.name || 'N/A',
306+
'Group Type': submission.teamInfo?.type || 'N/A',
308307
...questionTexts.reduce((answerObj, text, index) => ({
309308
...answerObj,
310309
[`"Q${index + 1}: ${markdownToPlainText(text).replace(/"/g, '""')}"`]:
@@ -465,7 +464,7 @@ export class SubmissionsService {
465464
return forkJoin(
466465
submissionsWithPlanetName.map(submission => {
467466
if (submission.team) {
468-
return this.teamsService.getTeamName(submission.team).pipe(map(teamName => ({ ...submission, teamName })));
467+
return this.teamsService.getTeamName(submission.team).pipe(map(teamInfo => ({ ...submission, teamInfo })));
469468
}
470469
return of(submission);
471470
})
@@ -516,20 +515,18 @@ export class SubmissionsService {
516515
surveyHeader(responseHeader: boolean, exam, index: number, submission): string {
517516
if (responseHeader) {
518517
const shortDate = this.formatShortDate(submission.lastUpdateTime);
519-
const userAge = submission.user.birthDate
520-
? ageFromBirthDate(submission.lastUpdateTime, submission.user.birthDate)
521-
: submission.user.age;
518+
const userAge = submission.user.birthDate ? ageFromBirthDate(submission.lastUpdateTime, submission.user.birthDate) : submission.user.age;
522519
const userGender = submission.user.gender;
523520
const communityOrNation = submission.planetName;
524-
const teamName = submission.teamName
525-
? submission.teamName.replace(/^(Team|Enterprise):/, (match) => `<strong>${match}</strong>`)
526-
: '';
521+
const teamType = submission.teamInfo?.type ? toProperCase(submission.teamInfo.type) : '';
522+
const teamName = submission.teamInfo?.name || '';
523+
const teamInfo = teamType && teamName ? `<strong>${teamType}</strong>: ${teamName}` : '';
527524
return [
528525
`<h3>Submission ${index + 1}</h3>`,
529526
`<ul>`,
530527
`<li><strong>Planet ${communityOrNation}</strong></li>`,
531528
`<li><strong>Date:</strong> ${shortDate}</li>`,
532-
teamName ? `<li>${teamName}</li>` : '',
529+
teamInfo ? `<li>${teamInfo}</li>` : '',
533530
userGender ? `<li><strong>Gender:</strong> ${userGender}</li>` : '',
534531
userAge ? `<li><strong>Age:</strong> ${userAge}</li>` : '',
535532
`</ul>`,

src/app/teams/teams.service.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,17 +375,13 @@ export class TeamsService {
375375
return this.updateTeam(newServicesDoc);
376376
}
377377

378-
getTeamName(teamId: string): Observable<string> {
378+
getTeamName(teamId: string): Observable<Object> {
379379
return this.couchService.get(`${this.dbName}/${teamId}`).pipe(
380380
map((team: any) => {
381-
if (team && team.name) {
382-
if (team.type && team.type === 'enterprise') {
383-
return `Enterprise: ${team.name}`;
384-
} else {
385-
return `Team: ${team.name}`;
386-
}
381+
if (team) {
382+
return { 'name': team.name, 'type': team.type };
387383
}
388-
return teamId;
384+
return { id: teamId };
389385
}),
390386
);
391387
}

0 commit comments

Comments
 (0)