@@ -43,6 +43,18 @@ import {
43
43
// PROJECT: POPUPS
44
44
import { FormProfile as ProfileFormProfile } from "@/popups/sidebar/EditProfile.vue";
45
45
46
+ // ENUMERATIONS
47
+ enum GeolocationPermission {
48
+ // Not yet allowed permission.
49
+ NotYetAllowed = "not-yet-allowed",
50
+ // Disallowed permission.
51
+ Disallowed = "disallowed",
52
+ // Allowed permission.
53
+ Allowed = "allowed",
54
+ // Unknown permission.
55
+ Unknown = "unknown"
56
+ }
57
+
46
58
export default {
47
59
name: "EditProfileProfile",
48
60
@@ -64,7 +76,35 @@ export default {
64
76
return {
65
77
// --> DATA <--
66
78
67
- fieldsets: [
79
+ locationCountryOptions: countries.map(country => {
80
+ return {
81
+ value: country.code,
82
+ label: country.name
83
+ };
84
+ }),
85
+
86
+ locationCountryIcon: {
87
+ component: shallowRef(BaseFlag),
88
+
89
+ properties: (value: string) => {
90
+ return {
91
+ code: value,
92
+ width: "20px",
93
+ height: "15px",
94
+ shadow: "none"
95
+ };
96
+ }
97
+ },
98
+
99
+ // --> STATE <--
100
+
101
+ geolocationPermission: GeolocationPermission.Unknown
102
+ };
103
+ },
104
+
105
+ computed: {
106
+ fieldsets(): Array<FormFieldset> {
107
+ return [
68
108
{
69
109
id: "job",
70
110
title: "Job information",
@@ -108,15 +148,12 @@ export default {
108
148
109
149
fields: [
110
150
{
111
- // TODO: implement functionality using this option
112
151
id: "automatic",
113
152
type: FormFieldsetFieldType.Toggle,
114
153
label: "Auto-detect:",
115
154
116
155
data: {
117
- value: {
118
- inner: false
119
- }
156
+ value: this.form.locationAutodetect
120
157
} as FormFieldsetFieldDataToggle
121
158
},
122
159
@@ -127,7 +164,8 @@ export default {
127
164
128
165
data: {
129
166
value: this.form.locationCity,
130
- placeholder: "Enter your current city…"
167
+ placeholder: "Enter your current city…",
168
+ disabled: this.form.locationAutodetect.inner || false
131
169
} as FormFieldsetFieldDataInput
132
170
},
133
171
@@ -140,25 +178,9 @@ export default {
140
178
value: this.form.locationCountry,
141
179
placeholder: "Pick a country…",
142
180
143
- options: countries.map(country => {
144
- return {
145
- value: country.code,
146
- label: country.name
147
- };
148
- }),
149
-
150
- icon: {
151
- component: shallowRef(BaseFlag),
152
-
153
- properties: (value: string) => {
154
- return {
155
- code: value,
156
- width: "20px",
157
- height: "15px",
158
- shadow: "none"
159
- };
160
- }
161
- }
181
+ options: this.locationCountryOptions,
182
+ icon: this.locationCountryIcon,
183
+ disabled: this.form.locationAutodetect.inner || false
162
184
} as FormFieldsetFieldDataSelect
163
185
}
164
186
],
@@ -167,25 +189,34 @@ export default {
167
189
{
168
190
id: "location-mode",
169
191
label: "Location mode:",
170
- value: "Manual", // TODO: need to geocode lat/lon to city/country
171
- icon: FormFieldsetControlIconType.LocationInactive
192
+
193
+ value: this.form.locationAutodetect.inner
194
+ ? "Automatic"
195
+ : "Manual",
196
+
197
+ icon: this.form.locationAutodetect.inner
198
+ ? FormFieldsetControlIconType.LocationActive
199
+ : FormFieldsetControlIconType.LocationInactive
172
200
},
173
201
174
202
{
175
203
id: "location-permission",
176
204
label: "Geolocation permission:",
177
- value: "Disallowed", // TODO: from configuration
178
-
179
- actions: [
180
- {
181
- type: FormFieldsetControlActionType.Button,
182
-
183
- data: {
184
- text: "Manage",
185
- disabled: true
186
- } as FormFieldsetControlActionDataButton
187
- }
188
- ]
205
+ value: this.locationPermissionDetails.label,
206
+ color: this.locationPermissionDetails.color,
207
+ emphasis: this.locationPermissionDetails.emphasis,
208
+
209
+ actions: this.locationPermissionDetails.action
210
+ ? [
211
+ {
212
+ type: FormFieldsetControlActionType.Button,
213
+
214
+ data: {
215
+ text: "Allow"
216
+ } as FormFieldsetControlActionDataButton
217
+ }
218
+ ]
219
+ : undefined
189
220
}
190
221
],
191
222
@@ -198,8 +229,85 @@ export default {
198
229
aside: FormFieldsetOptionAside.Fixed
199
230
}
200
231
}
201
- ] as Array<FormFieldset>
202
- };
232
+ ];
233
+ },
234
+
235
+ locationPermissionDetails(): {
236
+ label: string;
237
+ color: string;
238
+ emphasis?: boolean;
239
+ action?: boolean;
240
+ } {
241
+ switch (this.geolocationPermission) {
242
+ case GeolocationPermission.NotYetAllowed: {
243
+ return {
244
+ label: "Not yet allowed",
245
+ color: this.form.locationAutodetect.inner ? "orange" : "grey",
246
+ emphasis: this.form.locationAutodetect.inner || false
247
+ // action: true -- TODO: add action
248
+ };
249
+ }
250
+
251
+ case GeolocationPermission.Disallowed: {
252
+ return {
253
+ label: "Disallowed",
254
+ color: "red",
255
+ emphasis: this.form.locationAutodetect.inner || false
256
+ };
257
+ }
258
+
259
+ case GeolocationPermission.Allowed: {
260
+ return {
261
+ label: "Allowed",
262
+ color: this.form.locationAutodetect.inner ? "green" : "grey"
263
+ };
264
+ }
265
+
266
+ default: {
267
+ return {
268
+ label: "Unknown",
269
+ color: "grey"
270
+ };
271
+ }
272
+ }
273
+ }
274
+ },
275
+
276
+ async mounted() {
277
+ // Check for geolocation permission
278
+ this.geolocationPermission = await this.acquireGeolocationPermission();
279
+ },
280
+
281
+ methods: {
282
+ // --> HELPERS <--
283
+
284
+ async acquireGeolocationPermission(): Promise<GeolocationPermission> {
285
+ try {
286
+ // Request geolocation permission
287
+ const permission = await navigator.permissions.query({
288
+ name: "geolocation"
289
+ });
290
+
291
+ // Handle acquired permission
292
+ switch (permission.state) {
293
+ case "granted": {
294
+ return GeolocationPermission.Allowed;
295
+ }
296
+
297
+ case "denied": {
298
+ return GeolocationPermission.Disallowed;
299
+ }
300
+
301
+ case "prompt": {
302
+ return GeolocationPermission.NotYetAllowed;
303
+ }
304
+ }
305
+ } catch (error) {
306
+ this.$log.error("Failed acquiring geolocation permission", error);
307
+
308
+ return GeolocationPermission.Unknown;
309
+ }
310
+ }
203
311
}
204
312
};
205
313
</script>
0 commit comments