Skip to content

Commit fa1cf2d

Browse files
authored
Adds Instructions task type (#2153)
1 parent 9c3a09d commit fa1cf2d

File tree

7 files changed

+33
-2
lines changed

7 files changed

+33
-2
lines changed

web/src/app/components/tasks-editor/task-form/task-form.component.html

+13-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<div>{{ Tasks[taskGroup].label }}</div>
4444
</div>
4545

46-
<div class="toolbar-right">
46+
<div class="toolbar-right" *ngIf="taskGroup !== TaskGroup.INSTRUCTIONS">
4747
<div>
4848
<mat-label>Required</mat-label>
4949

@@ -70,6 +70,18 @@
7070
</button>
7171
</mat-menu>
7272
</div>
73+
74+
<div class="toolbar-right" *ngIf="taskGroup === TaskGroup.INSTRUCTIONS">
75+
<button mat-icon-button [matMenuTriggerFor]="menu">
76+
<mat-icon>more_vert</mat-icon>
77+
</button>
78+
79+
<mat-menu #menu="matMenu">
80+
<button mat-menu-item (click)="onTaskDelete()">
81+
<span>Delete</span>
82+
</button>
83+
</mat-menu>
84+
</div>
7385
</div>
7486

7587
<div class="task-form">

web/src/app/components/tasks-editor/task-form/task-form.component.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const Tasks: {
9999
icon: string;
100100
label: string;
101101
placeholder: string;
102-
requiredMessage: string;
102+
requiredMessage?: string;
103103
isGeometry?: boolean;
104104
};
105105
} = {
@@ -136,6 +136,11 @@ export const Tasks: {
136136
requiredMessage: 'Instructions are required',
137137
isGeometry: true,
138138
},
139+
[TaskGroup.INSTRUCTIONS]: {
140+
icon: 'list_alt_check',
141+
label: 'Instructions',
142+
placeholder: 'Instructions',
143+
},
139144
};
140145

141146
const GeometryTasks = List([TaskGroup.DROP_PIN, TaskGroup.DRAW_AREA]);

web/src/app/components/tasks-editor/tasks-editor.component.ts

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export enum TaskGroup {
4747
DROP_PIN = 3,
4848
DRAW_AREA = 4,
4949
CAPTURE_LOCATION = 5,
50+
INSTRUCTIONS = 6,
5051
}
5152

5253
export const taskGroupToTypes = new Map([
@@ -65,6 +66,7 @@ export const taskGroupToTypes = new Map([
6566
[TaskGroup.DROP_PIN, List([TaskType.DROP_PIN])],
6667
[TaskGroup.DRAW_AREA, List([TaskType.DRAW_AREA])],
6768
[TaskGroup.CAPTURE_LOCATION, List([TaskType.CAPTURE_LOCATION])],
69+
[TaskGroup.INSTRUCTIONS, List([TaskType.INSTRUCTIONS])],
6870
]);
6971

7072
export const taskTypeToGroup = new Map([
@@ -78,6 +80,7 @@ export const taskTypeToGroup = new Map([
7880
[TaskType.DROP_PIN, TaskGroup.DROP_PIN],
7981
[TaskType.DRAW_AREA, TaskGroup.DRAW_AREA],
8082
[TaskType.CAPTURE_LOCATION, TaskGroup.CAPTURE_LOCATION],
83+
[TaskType.INSTRUCTIONS, TaskGroup.INSTRUCTIONS],
8184
]);
8285

8386
@Component({
@@ -94,6 +97,7 @@ export class TasksEditorComponent {
9497
@Output() onValueChanges: EventEmitter<boolean> = new EventEmitter<boolean>();
9598

9699
addableTaskGroups: Array<TaskGroup> = [
100+
TaskGroup.INSTRUCTIONS,
97101
TaskGroup.QUESTION,
98102
TaskGroup.PHOTO,
99103
TaskGroup.CAPTURE_LOCATION,

web/src/app/converters/firebase-data-converter.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const TASK_TYPE_ENUMS_BY_STRING = Map([
4646
[TaskType.DROP_PIN, 'drop_pin'],
4747
[TaskType.DRAW_AREA, 'draw_area'],
4848
[TaskType.CAPTURE_LOCATION, 'capture_location'],
49+
[TaskType.INSTRUCTIONS, 'instructions'],
4950
]);
5051

5152
export class FirebaseDataConverter {

web/src/app/converters/proto-model-converter.ts

+6
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ function toTaskTypeMessage(
169169
type: Pb.Task.NumberQuestion.Type.FLOAT,
170170
}),
171171
};
172+
case TaskType.INSTRUCTIONS:
173+
return {
174+
instructions: new Pb.Task.InstructionsTask({
175+
text: '',
176+
}),
177+
};
172178
case TaskType.DATE:
173179
return {
174180
dateTimeQuestion: new Pb.Task.DateTimeQuestion({

web/src/app/converters/survey-data-converter.ts

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function taskPbToModelTaskType(pb: Pb.ITask): TaskType {
124124
drawGeometry,
125125
captureLocation,
126126
takePhoto,
127+
instructions,
127128
} = pb;
128129

129130
if (textQuestion) return TaskType.TEXT;
@@ -145,6 +146,7 @@ function taskPbToModelTaskType(pb: Pb.ITask): TaskType {
145146
else throw new Error('Error converting to Task: invalid task data');
146147
} else if (captureLocation) return TaskType.CAPTURE_LOCATION;
147148
else if (takePhoto) return TaskType.PHOTO;
149+
else if (instructions) return TaskType.INSTRUCTIONS;
148150
else throw new Error('Error converting to Task: invalid task data');
149151
}
150152

web/src/app/models/task/task.model.ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export enum TaskType {
5353
DRAW_AREA = 8,
5454
DROP_PIN = 9,
5555
CAPTURE_LOCATION = 10,
56+
INSTRUCTIONS = 11,
5657
}
5758

5859
// TODO: add a subclass of Task for each task type.

0 commit comments

Comments
 (0)