Skip to content

Commit

Permalink
Merge branch 'master' into deploy-function
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 authored Nov 14, 2024
2 parents c372c0a + 2f7fe45 commit c95e5a5
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 76 deletions.
2 changes: 1 addition & 1 deletion web/src/app/converters/firebase-data-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class FirebaseDataConverter {
return result.value;
}
if (result.value instanceof MultipleSelection) {
return result.value.values.map(option => option.id).toArray();
return result.value.values.toArray();
}
if (result.value instanceof Date) {
return Timestamp.fromDate(result.value);
Expand Down
29 changes: 13 additions & 16 deletions web/src/app/converters/submission-data-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,13 @@ function authInfoPbToModel(pb: Pb.IAuditInfo): AuditInfo {
);
}

function taskDataPbToModel(pb: Pb.ITaskData[], job: Job): SubmissionData {
function taskDataPbToModel(pb: Pb.ITaskData[]): SubmissionData {
const submissionData: {[k: string]: Result} = {};

pb.forEach(taskData => {
const task = job.tasks?.get(taskData.taskId!);

if (!task) return;

let value = null;

const {
taskId,
skipped,
textResponse,
numberResponse,
dateTimeResponse,
Expand All @@ -65,27 +61,28 @@ function taskDataPbToModel(pb: Pb.ITaskData[], job: Job): SubmissionData {
takePhotoResult,
} = taskData;

let value = null;

if (textResponse) value = textResponse.text;
else if (numberResponse) value = numberResponse.number;
else if (dateTimeResponse)
value = new Date(timestampToInt(dateTimeResponse.dateTime));
else if (multipleChoiceResponses) {
value = new MultipleSelection(
task.multipleChoice?.options.filter(({id: optionId}) =>
multipleChoiceResponses!.selectedOptionIds?.includes(optionId)
) || List([]),
multipleChoiceResponses.otherText
);
const {selectedOptionIds, otherText} = multipleChoiceResponses;

value = new MultipleSelection(List(selectedOptionIds || []), otherText);
} else if (drawGeometryResult)
value = geometryPbToModel(drawGeometryResult.geometry!) as Polygon;
else if (captureLocationResult)
value = new Point(
coordinatesPbToModel(captureLocationResult.coordinates!)
);
else if (takePhotoResult) value = takePhotoResult.photoPath;
else throw new Error('Error converting to Submission: invalid task data');

submissionData[task.id] = new Result(value!);
if (value === undefined)
throw new Error('Error converting to Submission: invalid task data');

submissionData[taskId!] = new Result(value, !!skipped);
});

return Map(submissionData);
Expand All @@ -105,6 +102,6 @@ export function submissionDocToModel(
job,
authInfoPbToModel(pb.created!),
authInfoPbToModel(pb.lastModified!),
taskDataPbToModel(pb.taskData, job)
taskDataPbToModel(pb.taskData)
);
}
4 changes: 1 addition & 3 deletions web/src/app/models/submission/multiple-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

import {List} from 'immutable';

import {Option} from 'app/models/task/option.model';

export class MultipleSelection {
constructor(
readonly values: List<Option>,
readonly values: List<string>,
readonly otherValue?: string | null
) {}
}
4 changes: 3 additions & 1 deletion web/src/app/models/submission/result.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import {Polygon} from '../geometry/polygon';
export class Result {
constructor(
readonly value:
| null
| number
| string
| MultipleSelection
| Date
| Point
| Polygon
| MultiPolygon
| MultiPolygon,
readonly skipped: boolean = false
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,59 +34,61 @@
</div>
<div *ngIf="tasks" class="submission-tasks-container">
<div *ngFor="let task of tasks; let i = index">
<mat-divider *ngIf="i > 0"></mat-divider>
<div class="submission-task">
<!-- Question -->
<div class="submission-question">{{task.label}}</div>
<!-- Response -->
<div class="submission-response">
<div *ngIf="getTaskSubmissionResult(task) === undefined" class="submission-no-response">
Skipped
</div>
<div *ngIf="getTaskSubmissionResult(task) !== undefined">
<!-- Multiple choice task types -->
<div *ngIf="task.type === taskType.MULTIPLE_CHOICE" class="submission-response-multiple-choice">
<mat-checkbox disabled="true" checked="true" *ngFor="let option of getTaskMultipleChoiceSelections(task).values">
{{option.label}}
</mat-checkbox>

<mat-checkbox disabled="true" checked="true" *ngIf="getTaskMultipleChoiceSelections(task).otherValue as otherValue">
Other: {{otherValue}}
</mat-checkbox>
</div>
<!-- Photo task types -->
<div *ngIf="task.type === taskType.PHOTO">
<img src="{{this.firebaseURLs.get(getTaskSubmissionResult(task)!.value)}}" class="submission-img"/>
<ng-container *ngIf="getTaskSubmissionResult(task) !== undefined">
<mat-divider *ngIf="i > 0"></mat-divider>
<div class="submission-task">
<!-- Question -->
<div class="submission-question">{{task.label}}</div>
<!-- Response -->
<div class="submission-response">
<div *ngIf="getTaskSubmissionResult(task).skipped" class="submission-no-response">
Skipped
</div>
<!-- Geometry task types -->
<div *ngIf="task.type === taskType.DROP_PIN || task.type === taskType.CAPTURE_LOCATION || task.type === taskType.DRAW_AREA">
<div class="submission-response-geometry" [ngClass]="{'selected-submission-response-geometry': task.id === selectedTaskId}">
<div class="submission-response-geometry-number" [ngStyle]="{ 'background-color': this.submission?.job.color ?? 'black' }">
{{i}}
</div>
<div *ngIf="task.type === taskType.DROP_PIN || task.type === taskType.DRAW_AREA" class="submission-response-geometry-label">
{{task.id}}
</div>
<div *ngIf="task.type === taskType.CAPTURE_LOCATION" class="submission-response-geometry-label">
{{getCaptureLocationCoord(task)}}
<div *ngIf="!getTaskSubmissionResult(task).skipped">
<!-- Multiple choice task types -->
<div *ngIf="task.type === taskType.MULTIPLE_CHOICE" class="submission-response-multiple-choice">
<mat-checkbox disabled="true" checked="true" *ngFor="let option of getTaskMultipleChoiceSelections(task).values">
{{option.label}}
</mat-checkbox>

<mat-checkbox disabled="true" checked="true" *ngIf="getTaskMultipleChoiceSelections(task).otherValue as otherValue">
Other: {{otherValue}}
</mat-checkbox>
</div>
<!-- Photo task types -->
<div *ngIf="task.type === taskType.PHOTO">
<img src="{{this.firebaseURLs.get(getTaskSubmissionResult(task)!.value)}}" class="submission-img"/>
</div>
<!-- Geometry task types -->
<div *ngIf="task.type === taskType.DROP_PIN || task.type === taskType.CAPTURE_LOCATION || task.type === taskType.DRAW_AREA">
<div class="submission-response-geometry" [ngClass]="{'selected-submission-response-geometry': task.id === selectedTaskId}">
<div class="submission-response-geometry-number" [ngStyle]="{ 'background-color': this.submission?.job.color ?? 'black' }">
{{i}}
</div>
<div *ngIf="task.type === taskType.DROP_PIN || task.type === taskType.DRAW_AREA" class="submission-response-geometry-label">
{{task.id}}
</div>
<div *ngIf="task.type === taskType.CAPTURE_LOCATION" class="submission-response-geometry-label">
{{getCaptureLocationCoord(task)}}
</div>
</div>
</div>
</div>
<!-- Date task types -->
<div *ngIf="task.type === taskType.DATE">
{{getDate(task)}}
</div>
<!-- Time task types -->
<div *ngIf="task.type === taskType.TIME">
{{getTime(task)}}
</div>
<!-- Remaining task types -->
<div *ngIf="task.type === taskType.TEXT || task.type === taskType.NUMBER || task.type === taskType.DATE_TIME">
{{getTaskSubmissionResult(task)!.value.toString()}}
<!-- Date task types -->
<div *ngIf="task.type === taskType.DATE">
{{getDate(task)}}
</div>
<!-- Time task types -->
<div *ngIf="task.type === taskType.TIME">
{{getTime(task)}}
</div>
<!-- Remaining task types -->
<div *ngIf="task.type === taskType.TEXT || task.type === taskType.NUMBER || task.type === taskType.DATE_TIME">
{{getTaskSubmissionResult(task)!.value.toString()}}
</div>
</div>
</div>
</div>
</div>
</ng-container>
</div>
</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
* limitations under the License.
*/

import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {
Component,
Input,
OnDestroy,
OnInit,
Pipe,
PipeTransform,
} from '@angular/core';
import {AngularFireStorage} from '@angular/fire/compat/storage';
import {List} from 'immutable';
import {Subscription, firstValueFrom} from 'rxjs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ export class LocationOfInterestPanelComponent implements OnInit, OnDestroy {
getOptions(task: Task, submission: Submission): List<Option> {
const result = submission.data?.get(task.id);
if (result && result instanceof List) {
return (result.value as MultipleSelection).values;
return (
task.multipleChoice?.options.filter(option =>
(result.value as MultipleSelection).values.contains(option.id)
) || List.of()
);
} else {
return List.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ class MockModel {
new AuditInfo(MockModel.user001, new Date(), new Date()),
Map({
task001: new Result('result'),
task003: new Result(new MultipleSelection(List([MockModel.option001]))),
task003: new Result(
new MultipleSelection(List([MockModel.option001.id]))
),
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class SubmissionFormComponent {
const selectedOption: Option = task.getMultipleChoiceOption(
this.submissionForm?.value[task.id]
);
return new Result(new MultipleSelection(List([selectedOption])));
return new Result(new MultipleSelection(List([selectedOption.id])));
}

private addControlsForSelectMultipleTask(
Expand All @@ -289,15 +289,17 @@ export class SubmissionFormComponent {
): void {
const {values: selectedOptions} = result?.value as MultipleSelection;
for (const option of task.multipleChoice!.options) {
group[option.id] = new FormControl(selectedOptions?.contains(option));
group[option.id] = new FormControl(selectedOptions?.contains(option.id));
}
}

private extractDataForSelectMultipleTask(task: Task): Result {
const selectedOptions: MultipleSelection = new MultipleSelection(
task.multipleChoice!.options!.filter(
(option: Option) => this.submissionForm?.value[option.id]
)
task
.multipleChoice!.options!.filter(
(option: Option) => this.submissionForm?.value[option.id]
)
.map(option => option.id)
);
return new Result(selectedOptions);
}
Expand Down

0 comments on commit c95e5a5

Please sign in to comment.