-
Notifications
You must be signed in to change notification settings - Fork 43
teams: smoother survey submissions formatting (fixes #9285) #9308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,25 +196,38 @@ export class SubmissionsService { | |
| }, []); | ||
| } | ||
|
|
||
| sendSubmissionRequests(users: any[], { parentId, parent }) { | ||
| sendSubmissionRequests(users: any[], { parentId, parent }, team?: { _id: string, name: string, type: string }) { | ||
| const queryOr = team ? [{ 'team._id': team._id }] : users.map((user: any) => ({ 'user._id': user._id, 'source': user.planetCode })); | ||
|
|
||
| return this.couchService.post('submissions/_find', findDocuments({ | ||
| parentId, | ||
| 'parent': { '_rev': parent._rev }, | ||
| '$or': users.map((user: any) => ({ 'user._id': user._id, 'source': user.planetCode })) | ||
| '$or': queryOr | ||
| })).pipe( | ||
| switchMap((submissions: any) => { | ||
| const sender = this.userService.get().name; | ||
|
|
||
| if (team) { | ||
| const teamSubmissionExists = submissions.docs.some((s: any) => s.team?._id === team._id && s.parent._rev === parent._rev); | ||
| if (teamSubmissionExists) { | ||
| return this.couchService.updateDocument('submissions/_bulk_docs', { 'docs': [] }); | ||
| } | ||
| return this.couchService.updateDocument('submissions/_bulk_docs', { | ||
| 'docs': [this.createNewSubmission({ user: {}, parentId, parent, type: 'survey', sender, team })] | ||
| }); | ||
| } | ||
|
|
||
| const newSubmissionUsers = users.filter((user: any) => | ||
| submissions.docs.findIndex((s: any) => (s.user._id === user._id && s.parent._rev === parent._rev)) === -1 | ||
| ); | ||
| const sender = this.userService.get().name; | ||
| return this.couchService.updateDocument('submissions/_bulk_docs', { | ||
| 'docs': newSubmissionUsers.map((user) => this.createNewSubmission({ user, parentId, parent, type: 'survey', sender })) | ||
| }); | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| createSubmission(parent: any, type: string, user: any = {}, team?: string) { | ||
| createSubmission(parent: any, type: string, user: any = {}, team?: { _id: string, name: string, type: string }) { | ||
| return this.couchService.updateDocument('submissions', this.createNewSubmission({ parentId: parent._id, parent, user, type, team })); | ||
| } | ||
|
|
||
|
|
@@ -271,17 +284,14 @@ export class SubmissionsService { | |
| questions: Array.isArray(sub.parent.questions) ? sub.parent.questions : exam.questions | ||
| } | ||
| })); | ||
| const filteredSubmissions = team ? normalizedSubmissions.filter(s => s.team === team) : normalizedSubmissions; | ||
| return forkJoin( | ||
| filteredSubmissions.map(submission => { | ||
| if (submission.team) { | ||
| return this.teamsService.getTeamName(submission.team).pipe(map(teamInfo => ({ ...submission, teamInfo }))); | ||
| } | ||
| return of(submission); | ||
| }) | ||
| ).pipe(map((updatedSubmissions: any[]): [any[], number, string[]] => [ updatedSubmissions, time, questionTexts ])); | ||
| const filteredSubmissions = team ? normalizedSubmissions.filter(s => s.team?._id === team) : normalizedSubmissions; | ||
| const submissionsWithTeamInfo = filteredSubmissions.map(submission => ({ | ||
| ...submission, | ||
| teamInfo: submission.team ? { name: submission.team.name, type: submission.team.type } : null | ||
| })); | ||
| return of<[any[], number, string[]]>([submissionsWithTeamInfo, time, questionTexts]); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few things that were here before that could be improved:
|
||
| }), | ||
| tap(([ updatedSubmissions, time, questionTexts ]) => { | ||
| tap(([ updatedSubmissions, time, questionTexts ]: [any[], number, string[]]) => { | ||
| const title = `${toProperCase($localize`${type}`)} - ${$localize`${exam.name}`} (${updatedSubmissions.length})`; | ||
| const data = updatedSubmissions.map(submission => { | ||
| const answerIndexes = this.answerIndexes(questionTexts, submission); | ||
|
|
@@ -291,6 +301,7 @@ export class SubmissionsService { | |
| ageFromBirthDate(time, submission.user.birthDate) : | ||
| submission.user.age || 'N/A', | ||
| 'Planet': submission.source, | ||
| [$localize`Source`]: submission.androidId !== undefined ? 'myPlanet' : 'Planet', | ||
| [$localize`Date`]: fullLabel(submission.lastUpdateTime), | ||
| [$localize`Group`]: submission.teamInfo?.name || 'N/A', | ||
| [$localize`Group Type`]: submission.teamInfo?.type || 'N/A', | ||
|
|
@@ -454,7 +465,7 @@ export class SubmissionsService { | |
| questions: Array.isArray(sub.parent.questions) ? sub.parent.questions : exam.questions | ||
| } | ||
| })); | ||
| const filteredSubmissions = team ? normalizedSubmissions.filter(s => s.team === team) : normalizedSubmissions; | ||
| const filteredSubmissions = team ? normalizedSubmissions.filter(s => s.team?._id === team) : normalizedSubmissions; | ||
| if (!filteredSubmissions.length) { | ||
| this.dialogsLoadingService.stop(); | ||
| this.planetMessageService.showMessage($localize`There is no survey response`); | ||
|
|
@@ -463,17 +474,10 @@ export class SubmissionsService { | |
| const planetsWithName = attachNamesToPlanets(planets); | ||
| const submissionsWithPlanetName = filteredSubmissions.map(submission => ({ | ||
| ...submission, | ||
| planetName: codeToPlanetName(submission.source, this.stateService.configuration, planetsWithName) | ||
| planetName: codeToPlanetName(submission.source, this.stateService.configuration, planetsWithName), | ||
| teamInfo: submission.team ? { name: submission.team.name, type: submission.team.type } : null | ||
| })); | ||
| return forkJoin( | ||
| submissionsWithPlanetName.map(submission => { | ||
| if (submission.team) { | ||
| return this.teamsService.getTeamName(submission.team).pipe(map(teamInfo => ({ ...submission, teamInfo }))); | ||
| } | ||
| return of(submission); | ||
| }) | ||
| ).pipe(map((updatedSubmissions: any[]): [ any[], number, string[] ] => [ updatedSubmissions, time, questionTexts ]) | ||
| ); | ||
| return of<[any[], number, string[]]>([submissionsWithPlanetName, time, questionTexts]); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, since we're no longer pulling in team info here via another observable we can just use a map instead of switchMap and return the array. |
||
| }) | ||
| ).subscribe(async tuple => { | ||
| if (!tuple) { return; } | ||
|
|
@@ -524,13 +528,15 @@ export class SubmissionsService { | |
| submission.user.age; | ||
| const userGender = submission.user.gender; | ||
| const communityOrNation = submission.planetName; | ||
| const planetSource = submission.androidId !== undefined ? 'myPlanet' : 'Planet'; | ||
| const teamType = submission.teamInfo?.type ? toProperCase(submission.teamInfo.type) : ''; | ||
| const teamName = submission.teamInfo?.name || ''; | ||
| const teamInfo = teamType && teamName ? `<strong>${teamType}</strong>: ${teamName}` : ''; | ||
| return [ | ||
| `<h3>${$localize`Submission`} ${index + 1}</h3>`, | ||
| `<ul>`, | ||
| `<li><strong>Planet ${communityOrNation}</strong></li>`, | ||
| `<li><strong>${$localize`Source:`}</strong> ${planetSource}</li>`, | ||
| `<li><strong>${$localize`Date:`}</strong> ${shortDate}</li>`, | ||
| teamInfo ? `<li>${teamInfo}</li>` : '', | ||
| userGender ? `<li><strong>${$localize`Gender:`}</strong> ${userGender}</li>` : '', | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.