@byu-oit/vue-decision-processing-components 9.4.0 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/deploy.yml +1 -1
- package/ByuDateSelector.vue +54 -0
- package/Report.vue +368 -334
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<byu-control-date-selector
|
|
3
|
+
ref="selector"
|
|
4
|
+
:value="value"
|
|
5
|
+
@change="onChange"
|
|
6
|
+
:date-type="dateType"
|
|
7
|
+
:prior-terms="priorTerms"
|
|
8
|
+
:subsequent-terms="subsequentTerms"
|
|
9
|
+
></byu-control-date-selector>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
export default {
|
|
14
|
+
name: 'ByuDateSelector',
|
|
15
|
+
props: {
|
|
16
|
+
value: String,
|
|
17
|
+
dateType: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: 'CURRENT_YYT'
|
|
20
|
+
},
|
|
21
|
+
priorTerms: {
|
|
22
|
+
type: Number,
|
|
23
|
+
default: 3
|
|
24
|
+
},
|
|
25
|
+
subsequentTerms: {
|
|
26
|
+
type: Number,
|
|
27
|
+
default: 4
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
watch: {
|
|
31
|
+
value(newVal) {
|
|
32
|
+
const element = this.$refs.selector
|
|
33
|
+
if (element && newVal && element.value !== newVal) {
|
|
34
|
+
element.value = newVal
|
|
35
|
+
element.dispatchEvent(new Event('input', { bubbles: true }))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
mounted() {
|
|
40
|
+
if (this.value) {
|
|
41
|
+
const element = this.$refs.selector
|
|
42
|
+
if (element && element.value !== this.value) {
|
|
43
|
+
element.value = this.value
|
|
44
|
+
element.dispatchEvent(new Event('input', { bubbles: true }))
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
methods: {
|
|
49
|
+
onChange(e) {
|
|
50
|
+
this.$emit('input', e.target.value)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
</script>
|
package/Report.vue
CHANGED
|
@@ -1,334 +1,368 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
Copyright 2018 Brigham Young University
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License")
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
-->
|
|
16
|
-
<template>
|
|
17
|
-
<div class="report" v-if="metadata">
|
|
18
|
-
<ReportSvg
|
|
19
|
-
v-if="chart"
|
|
20
|
-
v-bind="$attrs"
|
|
21
|
-
v-on="$listeners"
|
|
22
|
-
:svgContent="svgContent"
|
|
23
|
-
:loaded="loaded"
|
|
24
|
-
:error="error"/>
|
|
25
|
-
<template v-if="!hideDescription">
|
|
26
|
-
<h1 v-if="metadata.description">{{metadata.description}}</h1>
|
|
27
|
-
<h4 v-if="metadata.long_description" class="no-uppercase">{{metadata.long_description}}</h4>
|
|
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
|
-
import
|
|
82
|
-
import
|
|
83
|
-
import
|
|
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
|
-
type: String
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
type: String
|
|
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
|
-
this.
|
|
159
|
-
this.
|
|
160
|
-
this
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
q
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
q.append('
|
|
174
|
-
q.append('
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
q.append('
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
this.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
this
|
|
232
|
-
this.$emit('
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
this.
|
|
236
|
-
this
|
|
237
|
-
this.$emit('
|
|
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
|
-
q
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
q.append('
|
|
279
|
-
q.append('
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
q.append('
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if
|
|
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
|
-
|
|
1
|
+
<!--
|
|
2
|
+
Copyright 2018 Brigham Young University
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License")
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
-->
|
|
16
|
+
<template>
|
|
17
|
+
<div class="report" v-if="metadata">
|
|
18
|
+
<ReportSvg
|
|
19
|
+
v-if="chart"
|
|
20
|
+
v-bind="$attrs"
|
|
21
|
+
v-on="$listeners"
|
|
22
|
+
:svgContent="svgContent"
|
|
23
|
+
:loaded="loaded"
|
|
24
|
+
:error="error"/>
|
|
25
|
+
<template v-if="!hideDescription">
|
|
26
|
+
<h1 v-if="metadata.description">{{metadata.description}}</h1>
|
|
27
|
+
<h4 v-if="metadata.long_description" class="no-uppercase">{{metadata.long_description}}</h4>
|
|
28
|
+
<ByuDateSelector
|
|
29
|
+
v-if="metadata.parameters.includes('admitPeriod')"
|
|
30
|
+
v-model="selectedAdmitPeriod"
|
|
31
|
+
/>
|
|
32
|
+
<date-picker
|
|
33
|
+
v-if="metadata.parameters.includes('date_start') && metadata.parameters.includes('date_end')"
|
|
34
|
+
v-model="dateRange"
|
|
35
|
+
range
|
|
36
|
+
:not-after="new Date()"
|
|
37
|
+
lang="en"
|
|
38
|
+
/>
|
|
39
|
+
</template>
|
|
40
|
+
<template v-if="detail && photoLink">
|
|
41
|
+
<div>
|
|
42
|
+
<input type="checkbox" v-model="showPhotos" id="components-Report-showPhotos">
|
|
43
|
+
<label for="components-Report-showPhotos">Show Photos</label>
|
|
44
|
+
</div>
|
|
45
|
+
<ReportPhotos
|
|
46
|
+
v-if="showPhotos"
|
|
47
|
+
:rows="rows"
|
|
48
|
+
:column-metadata="metadata.columns"
|
|
49
|
+
:loading="loading"
|
|
50
|
+
:error="error"/>
|
|
51
|
+
<ReportDetail
|
|
52
|
+
v-else
|
|
53
|
+
:csv="csvContent"
|
|
54
|
+
:column-metadata="metadata.columns"
|
|
55
|
+
:rows="rows"
|
|
56
|
+
:loading="loading"
|
|
57
|
+
:error="error"
|
|
58
|
+
:detailPath="detailPath"
|
|
59
|
+
:newTab="newTab"/>
|
|
60
|
+
</template>
|
|
61
|
+
<template v-else>
|
|
62
|
+
<ReportDetail
|
|
63
|
+
v-if="detail"
|
|
64
|
+
:csv="csvContent"
|
|
65
|
+
:column-metadata="metadata.columns"
|
|
66
|
+
:rows="rows"
|
|
67
|
+
:loading="loading"
|
|
68
|
+
:error="error"
|
|
69
|
+
:detailPath="detailPath"
|
|
70
|
+
:newTab="newTab" />
|
|
71
|
+
</template>
|
|
72
|
+
<router-link v-else-if="to" :to="to">View Details</router-link>
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|
|
75
|
+
|
|
76
|
+
<script>
|
|
77
|
+
import { parse } from 'csv-string'
|
|
78
|
+
import ReportDetail from './ReportDetail.vue'
|
|
79
|
+
import ReportPhotos from './ReportPhotos.vue'
|
|
80
|
+
import ReportSvg from './ReportSvg.vue'
|
|
81
|
+
import Reports from './vuexModules/reports'
|
|
82
|
+
import DatePicker from 'vue2-datepicker'
|
|
83
|
+
import ByuDateSelector from "./ByuDateSelector.vue"
|
|
84
|
+
|
|
85
|
+
let tabHiddenState = document.hidden
|
|
86
|
+
|
|
87
|
+
export default {
|
|
88
|
+
name: 'Report',
|
|
89
|
+
components: { ByuDateSelector, DatePicker, ReportDetail, ReportPhotos, ReportSvg },
|
|
90
|
+
props: {
|
|
91
|
+
reportName: {
|
|
92
|
+
type: String,
|
|
93
|
+
required: true
|
|
94
|
+
},
|
|
95
|
+
baseUrl: {
|
|
96
|
+
type: String,
|
|
97
|
+
required: true
|
|
98
|
+
},
|
|
99
|
+
chart: Boolean,
|
|
100
|
+
detail: Boolean,
|
|
101
|
+
to: [String, Object],
|
|
102
|
+
detailPath: {
|
|
103
|
+
type: String,
|
|
104
|
+
default: '/report'
|
|
105
|
+
},
|
|
106
|
+
loadData: Boolean,
|
|
107
|
+
admitPeriod: {
|
|
108
|
+
type: String
|
|
109
|
+
},
|
|
110
|
+
paginationParameter: {
|
|
111
|
+
type: String
|
|
112
|
+
},
|
|
113
|
+
limit: {
|
|
114
|
+
type: String
|
|
115
|
+
},
|
|
116
|
+
hideDescription: Boolean,
|
|
117
|
+
newTab: Boolean,
|
|
118
|
+
autoRefresh: Boolean,
|
|
119
|
+
setById: {
|
|
120
|
+
type: String,
|
|
121
|
+
default: ''
|
|
122
|
+
},
|
|
123
|
+
configs: {
|
|
124
|
+
type: Array,
|
|
125
|
+
default: () => []
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
data () {
|
|
129
|
+
return {
|
|
130
|
+
loading: false,
|
|
131
|
+
loaded: false,
|
|
132
|
+
error: false,
|
|
133
|
+
svgContent: null,
|
|
134
|
+
csvContent: null,
|
|
135
|
+
rows: null,
|
|
136
|
+
selectedAdmitPeriod: this.admitPeriod,
|
|
137
|
+
dateRange: null,
|
|
138
|
+
showPhotos: false,
|
|
139
|
+
paginateReport: this.paginationParameter,
|
|
140
|
+
newCursor: 'null'
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
computed: {
|
|
144
|
+
metadata () {
|
|
145
|
+
return this.$store.getters.reportMetadata(this.reportName)
|
|
146
|
+
},
|
|
147
|
+
photoLink () {
|
|
148
|
+
const columnMetadata = this.metadata.columns
|
|
149
|
+
return columnMetadata && columnMetadata.find(m => m.qualifier.includes('link_photo'))
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
methods: {
|
|
153
|
+
async loadReports () {
|
|
154
|
+
if(!this.metadata) {
|
|
155
|
+
// wait for metadata before trying to load report
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
this.loaded = false
|
|
159
|
+
this.error = false
|
|
160
|
+
this.loading = true
|
|
161
|
+
this.$emit('loading')
|
|
162
|
+
window.scrollTo(0, 0)
|
|
163
|
+
|
|
164
|
+
const q = new URLSearchParams()
|
|
165
|
+
q.append('name', this.reportName)
|
|
166
|
+
if (this.selectedAdmitPeriod) {
|
|
167
|
+
q.append('admit_period', this.selectedAdmitPeriod)
|
|
168
|
+
} else if(this.metadata.parameters.includes('admitPeriod')) {
|
|
169
|
+
// Don't attempt to load report if we're missing the admit period
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
if (this.paginateReport && this.paginateReport !== 'null') {
|
|
173
|
+
q.append('pagination_parameter', this.paginateReport)
|
|
174
|
+
q.append('limit', this.limit)
|
|
175
|
+
q.append('cursor', this.newCursor)
|
|
176
|
+
}
|
|
177
|
+
if (this.dateRange) {
|
|
178
|
+
const toYYYYMMDD = dt => dt.toISOString().substr(0, 10)
|
|
179
|
+
const startDate = toYYYYMMDD(this.dateRange[0])
|
|
180
|
+
const endDate = toYYYYMMDD(this.dateRange[1])
|
|
181
|
+
q.append('date_start', startDate)
|
|
182
|
+
q.append('date_end', endDate)
|
|
183
|
+
}
|
|
184
|
+
if (this.metadata.parameters.includes('setById') && this.setById) {
|
|
185
|
+
q.append('set_by_id', this.setById)
|
|
186
|
+
}
|
|
187
|
+
// appends institution if available to url search params
|
|
188
|
+
if(this.metadata.parameters.includes('institutions')) {
|
|
189
|
+
if(this.metadata.parameters.institutions.includes(state.institution))
|
|
190
|
+
q.append('institution', state.institution)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const url = this.baseUrl + '?' + q.toString()
|
|
194
|
+
const loadRequested = () => {
|
|
195
|
+
let promises = []
|
|
196
|
+
if (this.chart) {
|
|
197
|
+
promises.push(this.loadSvg(url))
|
|
198
|
+
}
|
|
199
|
+
if (this.detail || this.loadData) {
|
|
200
|
+
promises.push(this.loadCsv(url))
|
|
201
|
+
}
|
|
202
|
+
return promises
|
|
203
|
+
}
|
|
204
|
+
const promises = loadRequested()
|
|
205
|
+
try {
|
|
206
|
+
await Promise.all(promises)
|
|
207
|
+
this.loaded = true
|
|
208
|
+
this.loading = false
|
|
209
|
+
} catch (err) {
|
|
210
|
+
console.error(err)
|
|
211
|
+
this.error = true
|
|
212
|
+
this.loading = false
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
async loadSvg (url) {
|
|
216
|
+
const svg = await this.loadReport(url, 'image/svg+xml')
|
|
217
|
+
this.svgContent = svg
|
|
218
|
+
},
|
|
219
|
+
async loadCsv (url) {
|
|
220
|
+
let csv = ''
|
|
221
|
+
do {
|
|
222
|
+
const reportResponse = await this.loadReport(url, 'text/csv')
|
|
223
|
+
csv = csv + reportResponse
|
|
224
|
+
const q = this.getQuery()
|
|
225
|
+
url = this.baseUrl + '?' + q.toString()
|
|
226
|
+
} while (this.newCursor && this.newCursor !== 'null')
|
|
227
|
+
|
|
228
|
+
if (csv && csv.length > 0 && /\n/.test(csv)) {
|
|
229
|
+
this.csvContent = csv
|
|
230
|
+
const [headData, ...data] = parse(csv)
|
|
231
|
+
this.rows = data
|
|
232
|
+
this.$emit('csvLoaded', csv)
|
|
233
|
+
this.$emit('reportData', { data })
|
|
234
|
+
} else {
|
|
235
|
+
this.headData = []
|
|
236
|
+
this.rows = []
|
|
237
|
+
this.$emit('csvLoaded', csv)
|
|
238
|
+
this.$emit('reportData', { headers: [], data: [] })
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
async loadReport (url, acceptHeader) {
|
|
242
|
+
try {
|
|
243
|
+
const response = await fetch(url, {
|
|
244
|
+
headers: { accept: acceptHeader },
|
|
245
|
+
cache: 'no-store'
|
|
246
|
+
})
|
|
247
|
+
if (!response.ok) {
|
|
248
|
+
this.error = true
|
|
249
|
+
const err = Error(`Error ${response.status}-'${response.statusText}' while fetching report from ${url}`)
|
|
250
|
+
console.error(err)
|
|
251
|
+
return null
|
|
252
|
+
}
|
|
253
|
+
this.newCursor = response.headers.get('Cursor')
|
|
254
|
+
return await response.text()
|
|
255
|
+
} catch (err) {
|
|
256
|
+
this.error = true
|
|
257
|
+
console.error(err)
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
reloadOnPageBackIntoFocus () {
|
|
261
|
+
if (tabHiddenState != document.hidden) {
|
|
262
|
+
if (!document.hidden) {
|
|
263
|
+
this.loadReports()
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
tabHiddenState = document.hidden
|
|
267
|
+
},
|
|
268
|
+
getQuery() {
|
|
269
|
+
const q = new URLSearchParams()
|
|
270
|
+
q.append('name', this.reportName)
|
|
271
|
+
if (this.selectedAdmitPeriod) {
|
|
272
|
+
q.append('admit_period', this.selectedAdmitPeriod)
|
|
273
|
+
} else if(this.metadata.parameters.includes('admitPeriod')) {
|
|
274
|
+
// Don't attempt to load report if we're missing the admit period
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
if (this.paginateReport && this.paginateReport !== 'null') {
|
|
278
|
+
q.append('pagination_parameter', this.paginateReport)
|
|
279
|
+
q.append('limit', this.limit)
|
|
280
|
+
q.append('cursor', this.newCursor)
|
|
281
|
+
}
|
|
282
|
+
if (this.dateRange) {
|
|
283
|
+
const toYYYYMMDD = dt => dt.toISOString().substr(0, 10)
|
|
284
|
+
const startDate = toYYYYMMDD(this.dateRange[0])
|
|
285
|
+
const endDate = toYYYYMMDD(this.dateRange[1])
|
|
286
|
+
q.append('date_start', startDate)
|
|
287
|
+
q.append('date_end', endDate)
|
|
288
|
+
}
|
|
289
|
+
if (this.metadata.parameters.includes('setById') && this.setById) {
|
|
290
|
+
q.append('set_by_id', this.setById)
|
|
291
|
+
}
|
|
292
|
+
// appends institution if available to url search params
|
|
293
|
+
if(this.metadata.parameters.includes('institutions')) {
|
|
294
|
+
if(this.metadata.parameters.institutions.includes(state.institution))
|
|
295
|
+
q.append('institution', state.institution)
|
|
296
|
+
}
|
|
297
|
+
return q
|
|
298
|
+
},
|
|
299
|
+
async fetchConfigs() {
|
|
300
|
+
try {
|
|
301
|
+
const base = this.env === 'development'
|
|
302
|
+
? 'https://api-sandbox.byu.edu'
|
|
303
|
+
: 'https://api.byu.edu'
|
|
304
|
+
const institution = state.institution
|
|
305
|
+
const response = await fetch(`${base}/domain/applications/${institution}/admission/v1/configs`)
|
|
306
|
+
const json = await response.json()
|
|
307
|
+
this.configs = [...json.closed, ...json.open]
|
|
308
|
+
} catch (err) {
|
|
309
|
+
console.error('Failed to fetch admit period configs:', err)
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
setDefaultAdmitPeriod() {
|
|
313
|
+
const today = new Date()
|
|
314
|
+
const future = this.configs
|
|
315
|
+
.filter(p => new Date(p.close) >= today)
|
|
316
|
+
.sort((a, b) => new Date(a.close) - new Date(b.close))
|
|
317
|
+
|
|
318
|
+
if (future.length > 0) {
|
|
319
|
+
this.selectedAdmitPeriod = future[0].admit_period
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
watch: {
|
|
324
|
+
metadata: {
|
|
325
|
+
handler: 'loadReports'
|
|
326
|
+
},
|
|
327
|
+
baseUrl: {
|
|
328
|
+
handler: 'loadReports',
|
|
329
|
+
immediate: true
|
|
330
|
+
},
|
|
331
|
+
reportName: {
|
|
332
|
+
handler: 'loadReports'
|
|
333
|
+
},
|
|
334
|
+
admitPeriod(newValue) {
|
|
335
|
+
this.selectedAdmitPeriod = newValue
|
|
336
|
+
},
|
|
337
|
+
selectedAdmitPeriod: 'loadReports',
|
|
338
|
+
dateRange: 'loadReports'
|
|
339
|
+
},
|
|
340
|
+
mounted () {
|
|
341
|
+
if (this.autoRefresh) {
|
|
342
|
+
document.addEventListener('visibilitychange', this.reloadOnPageBackIntoFocus)
|
|
343
|
+
}
|
|
344
|
+
// Only fetch configs if none were passed in
|
|
345
|
+
if (this.configs.length === 0) {
|
|
346
|
+
this.fetchConfigs()
|
|
347
|
+
}
|
|
348
|
+
// Only set the default admit period if we have configs, else keep the original default
|
|
349
|
+
if (this.configs.length > 0) {
|
|
350
|
+
this.setDefaultAdmitPeriod()
|
|
351
|
+
} else {
|
|
352
|
+
console.warn('No admit period configs found. Using original default admit period.')
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
beforeDestroy () {
|
|
356
|
+
if (this.autoRefresh) {
|
|
357
|
+
document.removeEventListener('visibilitychange', this.reloadOnPageBackIntoFocus)
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
</script>
|
|
362
|
+
<style scoped>
|
|
363
|
+
.no-uppercase {
|
|
364
|
+
text-transform: none;
|
|
365
|
+
color: var(--gray, gray);
|
|
366
|
+
font-size: 1rem;
|
|
367
|
+
}
|
|
368
|
+
</style>
|
package/package.json
CHANGED