-
Notifications
You must be signed in to change notification settings - Fork 82
/
SearchFieldsOfStudyForm.vue
381 lines (360 loc) · 10.5 KB
/
SearchFieldsOfStudyForm.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
96
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
158
159
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<template>
<v-form class="px-5 pb-5 pt-3" id="fos-search-form" novalidate="false">
<h3 class="my-4">Location</h3>
<location-institution-search
@search-query="handleLocationSelection"
:horizontal="false"
:initial_state="input.state"
:initial_zip="input.zip"
:initial_distance="input.distance"
/>
<!-- Salary After Completing -->
<div>
<h3 class="my-4" id="search-fos-salary" for="search-fos-salary">
Salary After Completing
<v-btn
v-if="
input.fos_salary.join(',') !==
utility.formDefault.fos_salary.join(',')
"
@click="
input.fos_salary = _.cloneDeep(utility.formDefault.fos_salary)
"
icon
aria-label="Clear Salary After Complete Input"
>
<v-icon>mdi mdi-close</v-icon>
</v-btn>
</h3>
<v-range-slider
id="search-fos-salary"
name="search-fos-salary"
v-model="input.fos_salary"
:max="utility.fieldOfStudySalary.max"
:min="utility.fieldOfStudySalary.min"
hide-details
class="align-center"
color="primaryfos"
track-color="dark-gray"
thumb-color="primaryfos"
thumb-label
aria-label="Salary After Complete Range Slider"
>
<template v-slot:prepend>
<div style="display:inline-flex;min-width:100%;">
<span class="mt-2">$</span>
<v-text-field
:value="input.fos_salary[0]"
class="mt-0 pt-0 ml-2"
hide-details
single-line
type="number"
style="width: 54px;min-width:54px;"
suffix="k"
@change="$set(input.fos_salary, 0, $event)"
aria-label="Minimum Salary After Complete"
></v-text-field>
</div>
</template>
<template v-slot:append>
<span class="mt-2">$</span>
<v-text-field
:value="input.fos_salary[1]"
class="mt-0 pt-0 ml-2"
hide-details
single-line
type="number"
style="width: 54px;min-width:54px;"
suffix="k"
@change="$set(input.fos_salary, 1, $event)"
aria-label="Maximum Salary After Complete"
></v-text-field>
</template>
</v-range-slider>
</div>
<!-- Median Total Debt -->
<div class="mb-4">
<h3 class="my-4" id="search-fos-median-debt" for="search-fos-median-debt">
Median Total Debt
<v-btn
v-if="
input.fos_debt.join(',') !== utility.formDefault.fos_debt.join(',')
"
@click="input.fos_debt = _.cloneDeep(utility.formDefault.fos_debt)"
icon
aria-label="Clear Median Total Debt Input"
>
<v-icon>mdi mdi-close</v-icon>
</v-btn>
</h3>
<v-range-slider
name="search-fos-median-debt"
v-model="input.fos_debt"
:max="utility.fieldOfStudyDebt.max"
:min="utility.fieldOfStudyDebt.min"
hide-details
class="align-center"
color="primaryfos"
track-color="dark-gray"
thumb-color="primaryfos"
thumb-label
aria-label="Median Total Debt Range Slider"
>
<template v-slot:prepend>
<div style="display:inline-flex;min-width:100%;">
<span class="mt-2">$</span>
<v-text-field
:value="input.fos_debt[0]"
class="mt-0 pt-0 ml-2"
hide-details
single-line
type="number"
style="width: 54px;min-width:54px;"
suffix="k"
@change="$set(input.fos_debt, 0, $event)"
aria-label="Minimum Median Total Debt"
></v-text-field>
</div>
</template>
<template v-slot:append>
<span class="mt-2">$</span>
<v-text-field
:value="input.fos_debt[1]"
class="mt-0 pt-0 ml-2"
hide-details
single-line
type="number"
style="width: 54px;min-width:54px;"
suffix="k"
@change="$set(input.fos_debt, 1, $event)"
aria-label="Maximum Median Total Debt"
></v-text-field>
</template>
</v-range-slider>
</div>
<!-- WIOA Programs -->
<div class="">
<h3 class="my-4" id="search-fos-dolflag" for="search-fos-dolflag">
WIOA Programs
<tooltip definition="wioa-participants" />
</h3>
<v-checkbox
id="search-form-dolflag"
name="search-fos-dolflag"
class="search-form-dolflag-cb my-0 py-0"
v-model="input.dolflag"
label="Only show schools that have Department of Labor WIOA programs"
color="secondary"
hide-details
value="true"
></v-checkbox>
</div>
<v-btn
type="submit"
class="sr-only"
color="secondary"
large
@click="$emit('search-query', cleanInput)"
>Find Schools</v-btn
>
</v-form>
</template>
<script>
import FieldAutocomplete from "~/components/FieldAutocomplete.vue"
import FieldOfStudySearch from "~/components/FieldOfStudySearch.vue"
import FieldOfStudyDetailChip from "~/components/FieldOfStudyDetailChip.vue"
import Tooltip from "~/components/Tooltip.vue"
import LocationCheck from "~/js/mixins/LocationCheck.js"
import { SiteData } from "~/js/mixins/SiteData.js"
import _ from "lodash"
import LocationInstitutionSearch from "~/components/LocationInstitutionSearch.vue"
import { megaMerge } from "~/js/forms.js"
export default {
mixins: [SiteData, LocationCheck],
props: {
urlParsedParams: {
type: Object,
},
autoSubmit: {
type: Boolean,
default: false,
},
},
components: {
FieldAutocomplete,
FieldOfStudySearch,
FieldOfStudyDetailChip,
Tooltip,
LocationInstitutionSearch,
},
data() {
return {
input: {
fos_salary: [0, 150],
fos_debt: [0, 50],
dolflag: null,
state: null,
zip: null,
distance: null,
lat: null,
long: null,
},
utility: {
formDefault: {
fos_salary: [0, 150],
fos_debt: [0, 50],
state: null,
zip: null,
distance: 50,
lat: null,
long: null,
},
rules: {
required: (value) => !!value || "Required.",
numerical: (value) => {
const pattern = /^\d+$/
return pattern.test(value) || "Numerical"
},
},
fieldOfStudySalary: {
min: 0,
max: 150,
},
fieldOfStudyDebt: {
min: 0,
max: 50,
},
initialized: false,
},
}
},
computed: {
cleanInput() {
let defaultValues = _.cloneDeep(this.utility.formDefault)
let groomedInput = {}
for (const key in this.input) {
if (!_.has(defaultValues, key)) {
continue
}
if (
!_.isEqual(this.input[key], defaultValues[key]) ||
key === "cip4_degree"
) {
groomedInput[key] = this.input[key]
} else {
groomedInput[key] = null
}
}
// Handle edge case for distance :(
if (groomedInput.zip) {
groomedInput.distance = this.input.distance
} else {
_.unset(groomedInput, "distance")
}
// Format Sliders - Happens here to ensure if shows up in url in desired format
if (groomedInput.fos_salary) {
groomedInput.fos_salary =
groomedInput.fos_salary[0] * 1000 +
".." +
groomedInput.fos_salary[1] * 1000
}
if (groomedInput.fos_debt) {
groomedInput.fos_debt =
groomedInput.fos_debt[0] * 1000 +
".." +
groomedInput.fos_debt[1] * 1000
}
return groomedInput
},
},
watch: {
cleanInput: {
handler(newValue, oldValue) {
// On first load trigger query immediately, then debounce additional queries.
if (!this.autoSubmit) {
return
}
if (this.utility.initialized) {
this.debounceEmitSearchQuery()
} else {
this.$emit("search-query", { ...newValue })
this.utility.initialized = true
}
},
deep: true,
},
urlParsedParams: {
handler(newValue, oldValue) {
this.mapInputFromProp()
},
deep: true,
},
},
created() {
// Set default Form Object
this.utility.formDefault = _.cloneDeep(this.input)
// Map Input from passed values
this.mapInputFromProp()
// Debounce search event
this.debounceEmitSearchQuery = _.debounce(function() {
// Send new param object, reset page
this.$emit("search-query", {
...this.cleanInput,
page: 0,
})
}, 1000)
},
mounted() {
this.$root.$on("search-form-reset", (e) => {
this.resetFormDefault()
})
},
methods: {
mapInputFromProp() {
// Merge import data object (used for v-models) with items passed from the URL
_.mergeWith(this.input, this.urlParsedParams, function(
objVal,
newObjValue,
key
) {
// Perform Any alterations or validations with the URL components
switch (key) {
case "fos_debt":
case "fos_salary":
// Format range sliders from backend value to frontend value
let valueArray = newObjValue.split("..")
return valueArray.map((value) => {
if (Number(value) <= 0) {
return 0
} else {
return Number(value / 1000)
}
})
break
default:
if (_.isArray(objVal) && _.isString(newObjValue)) {
return [newObjValue]
}
break
}
})
},
handleLocationSelection(params) {
this.input = { ...this.input, ...params }
//this.$emit("search-query", this.cleanInput)
},
resetFormDefault() {
// TODO - Create reset value method, pass desired fields to method, return default values from object.
this.input = _.cloneDeep(this.utility.formDefault)
this.utility.enable = _.cloneDeep(this.utility.formDefault)
this.location.latLon = null
this.location.error = null
this.utility.location = null
},
handleLocationSelection(params) {
this.input = { ...this.input, ...params }
this.input.page = 1
},
},
}
</script>