-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathapplication.js
76 lines (61 loc) · 2.09 KB
/
application.js
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
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import config from 'labs-zola/config/environment';
const { defaultLayerGroupState } = config;
export default Route.extend({
mainMap: service(),
fastboot: service(),
router: service(),
store: service(),
beforeModel(transition) {
const { targetName } = transition;
// only transition to about if target is index
if (targetName === 'index') {
// TODO: handle hash in fastboot
if (!this.fastboot.isFastBoot) {
const { hash } = window.location;
// preserve hash token so it's applied across transitions
if (hash) {
this.mainMap.set('knownHashIntent', hash);
}
}
this.router.transitionTo(`/about${transition.intent.url}`);
}
if (
targetName === 'map-feature.lot' ||
targetName === 'map-feature.lot-comparison'
) {
this.set('mainMap.routeIntentIsNested', true);
}
},
async model() {
const { layerGroups: layerGroupsParams } = this.paramsFor('application');
// fetch layer groups based on configured environment variable
const layerGroups = await this.store.query('layer-group', {
'layer-groups': defaultLayerGroupState,
});
// get the params and override the layer group state up-front
layerGroups.forEach((group) => {
group.set('visible', layerGroupsParams.includes(group.id));
});
// extract the meta node, see ember-data & json:api
const { meta } = layerGroups;
// pass down a hash representation of the layer group ids
const layerGroupsObject = layerGroups.reduce((accumulator, current) => {
accumulator[current.get('id')] = current;
return accumulator;
}, {});
const bookmarks = await this.store.findAll('bookmark');
await bookmarks.invoke('get', 'bookmark');
const savedLayerSets = window.localStorage['saved-layer-sets']
? JSON.parse(window.localStorage['saved-layer-sets'])
: [];
return {
layerGroups,
layerGroupsObject,
meta,
bookmarks,
savedLayerSets,
};
},
});