From c815ebc8bdf100fd9648025354c1ad4f89c82b8c Mon Sep 17 00:00:00 2001 From: David Hochbaum Date: Thu, 21 Mar 2024 17:07:04 -0400 Subject: [PATCH 1/9] Adding, loading, and saving all work --- app/controllers/bookmarks.js | 56 ++++++++++++++++++++++++++++++++++++ app/templates/bookmarks.hbs | 29 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/app/controllers/bookmarks.js b/app/controllers/bookmarks.js index 67dff1ed..7e6ddfa0 100644 --- a/app/controllers/bookmarks.js +++ b/app/controllers/bookmarks.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-expressions */ import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; import { computed as computedProp } from '@ember/object'; @@ -6,6 +7,12 @@ import { Promise } from 'rsvp'; export default Controller.extend({ mainMap: service(), metrics: service(), + router: service(), + + savedLayerSets: window.localStorage['saved-layer-sets'] + ? JSON.parse(window.localStorage['saved-layer-sets']) + : [], + // because we must compute the record types based on multiple // promises, the model uses Promise.all // this gets us in trouble when we need to do @@ -26,5 +33,54 @@ export default Controller.extend({ zoom: 15, }); }, + + bookmarkCurrentLayerSet() { + let allLayers = []; + const visibleLayers = []; + const visibleLayerGroups = []; + this.router.currentRoute.parent.attributes.layerGroups.forEach((lg) => { + allLayers = allLayers.concat(lg.layers); + lg.visible ? visibleLayerGroups.push(lg.id) : null; + }); + allLayers.forEach((layer) => { + layer.visibility ? visibleLayers.push(layer.id) : null; + }); + + const layerSet = { + id: crypto.randomUUID(), + name: 'New Saved Layer Set', + visibleLayers, + visibleLayerGroups, + }; + this.set('savedLayerSets', [...this.savedLayerSets, layerSet]); + window.localStorage['saved-layer-sets'] = JSON.stringify( + this.savedLayerSets + ); + }, + + deleteBookmarkedLayerSettings(id) { + this.set( + 'savedLayerSets', + [...this.savedLayerSets].filter((lg) => lg.id !== id) + ); + window.localStorage['saved-layer-sets'] = JSON.stringify( + this.savedLayerSets + ); + }, + + loadBookmarkedLayerSettings(bookmarkId) { + const layerToLoad = this.savedLayerSets.find( + (lg) => bookmarkId === lg.id + ); + const layerGroups = [ + ...this.router.currentRoute.parent.attributes.layerGroups, + ]; + layerGroups.forEach((lg) => { + lg.visible = !!layerToLoad.visibleLayerGroups.includes(lg.id); + lg.layers.forEach((layer) => { + layer.visibility = !!layerToLoad.visibleLayers.includes(layer.id); + }); + }); + }, }, }); diff --git a/app/templates/bookmarks.hbs b/app/templates/bookmarks.hbs index e08e4d0b..ee839f59 100644 --- a/app/templates/bookmarks.hbs +++ b/app/templates/bookmarks.hbs @@ -51,5 +51,34 @@ {{/unless}} +
+

+ Layer Sets + + Bookmark Current Layers + +

+ + +
+ + {{outlet}} \ No newline at end of file From c58371c01028229c8de34327a681aa77def02b8e Mon Sep 17 00:00:00 2001 From: David Hochbaum Date: Thu, 21 Mar 2024 18:08:08 -0400 Subject: [PATCH 2/9] Updating the name works --- app/controllers/bookmarks.js | 18 ++++++++++++++++++ app/templates/bookmarks.hbs | 17 +++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/controllers/bookmarks.js b/app/controllers/bookmarks.js index 7e6ddfa0..ab3ed308 100644 --- a/app/controllers/bookmarks.js +++ b/app/controllers/bookmarks.js @@ -13,6 +13,8 @@ export default Controller.extend({ ? JSON.parse(window.localStorage['saved-layer-sets']) : [], + editMode: false, + // because we must compute the record types based on multiple // promises, the model uses Promise.all // this gets us in trouble when we need to do @@ -68,6 +70,22 @@ export default Controller.extend({ ); }, + updateBookmarkedLayerSettings(id) { + const newLayerSets = [...this.savedLayerSets]; + const updatedLayerSetIndex = newLayerSets.findIndex((lg) => lg.id === id); + newLayerSets[updatedLayerSetIndex].name = + document.getElementById('name').value; + this.set('savedLayerSets', newLayerSets); + window.localStorage['saved-layer-sets'] = JSON.stringify( + this.savedLayerSets + ); + this.set('editMode', false); + }, + + turnOnEditMode(id) { + this.set('editMode', id); + }, + loadBookmarkedLayerSettings(bookmarkId) { const layerToLoad = this.savedLayerSets.find( (lg) => bookmarkId === lg.id diff --git a/app/templates/bookmarks.hbs b/app/templates/bookmarks.hbs index ee839f59..06bac709 100644 --- a/app/templates/bookmarks.hbs +++ b/app/templates/bookmarks.hbs @@ -65,10 +65,19 @@ From 03cc09343038796a8c7e1f9a23338e6c399b9cb0 Mon Sep 17 00:00:00 2001 From: David Hochbaum Date: Fri, 22 Mar 2024 14:57:04 -0400 Subject: [PATCH 6/9] Updated view for no saved layer sets --- app/templates/bookmarks.hbs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/templates/bookmarks.hbs b/app/templates/bookmarks.hbs index 72d8ced0..0f01c722 100644 --- a/app/templates/bookmarks.hbs +++ b/app/templates/bookmarks.hbs @@ -71,6 +71,9 @@ + {{#unless this.savedLayerSets.length}} +

No current saved layer sets.

+ {{/unless}}
    {{#each this.savedLayerSets as |bookmark|}}
  • From b7e8b62e21b4870e66b7634015fe6544186b4343 Mon Sep 17 00:00:00 2001 From: David Hochbaum Date: Mon, 8 Apr 2024 14:46:12 -0400 Subject: [PATCH 7/9] # of bookmarks in menu badge now includes saved layer sets --- app/components/main-header.js | 11 ++++++++++- app/routes/application.js | 5 +++++ app/templates/application.hbs | 2 +- app/templates/components/main-header.hbs | 4 ++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/components/main-header.js b/app/components/main-header.js index 8fa3ebe4..bf83df43 100644 --- a/app/components/main-header.js +++ b/app/components/main-header.js @@ -1,10 +1,19 @@ import Component from '@ember/component'; import { inject as service } from '@ember/service'; +import { computed } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; export default class MainHeaderComponent extends Component { @service('print') printSvc; @service() media; - bookmarks; + @tracked bookmarks; + + @tracked savedLayerSets; + + @computed('bookmarks.length', 'savedLayerSets.length') + get totalBookmarks() { + return this.bookmarks.length + this.savedLayerSets.length; + } } diff --git a/app/routes/application.js b/app/routes/application.js index 1abb8f6d..c879fc8d 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -58,11 +58,16 @@ export default Route.extend({ 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, }; }, }); diff --git a/app/templates/application.hbs b/app/templates/application.hbs index c929e8df..f355c0bd 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -1,4 +1,4 @@ - +
    Homepage {{#if this.printSvc.enabled}} diff --git a/app/templates/components/main-header.hbs b/app/templates/components/main-header.hbs index 09306c92..58b08bcd 100644 --- a/app/templates/components/main-header.hbs +++ b/app/templates/components/main-header.hbs @@ -45,9 +45,9 @@ Saved - {{#if this.bookmarks.length}} + {{#if this.totalBookmarks}} - {{this.bookmarks.length}} + {{this.totalBookmarks}} {{/if}} From 94cc0543ac4a2740fa90c397eaf383bef9c14ad4 Mon Sep 17 00:00:00 2001 From: David Hochbaum Date: Wed, 10 Apr 2024 11:53:17 -0400 Subject: [PATCH 8/9] Loading bookmarks updates URL, number updates correctly, fixed tracking issue --- app/controllers/bookmarks.js | 39 ++++++++++++++++++++++++++++++++++-- app/templates/bookmarks.hbs | 4 ++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/controllers/bookmarks.js b/app/controllers/bookmarks.js index 32250131..ea1f8612 100644 --- a/app/controllers/bookmarks.js +++ b/app/controllers/bookmarks.js @@ -59,17 +59,36 @@ export default Controller.extend({ layer.visibility ? visibleLayers.push(layer.id) : null; }); + const queryParams = {}; + [ + 'layer-groups', + 'selectedZoning', + 'selectedOverlays', + 'selectedFirm', + 'selectedPfirm', + 'selectedCouncilDistricts', + 'selectedLayerGroup', + ].forEach((selected) => { + queryParams[selected] = this.router.currentRoute.queryParams[selected] + ? JSON.parse(this.router.currentRoute.queryParams[selected]) + : undefined; + }); + const layerSet = { id: crypto.randomUUID(), name: 'New Saved Layer Set', visibleLayers, visibleLayerGroups, + queryParams, }; this.set('savedLayerSets', [...this.savedLayerSets, layerSet]); window.localStorage['saved-layer-sets'] = JSON.stringify( this.savedLayerSets ); this.track('bookmarkCurrentLayerSet'); + // Hack to update the # which doesn't update automatically + document.querySelector('.badge.sup').innerText = + parseInt(document.querySelector('.badge.sup').innerText, 10) + 1; }, deleteBookmarkedLayerSettings(id) { @@ -81,6 +100,9 @@ export default Controller.extend({ this.savedLayerSets ); this.track('deleteBookmarkedLayerSettings'); + // Hack to update the # which doesn't update automatically + document.querySelector('.badge.sup').innerText = + parseInt(document.querySelector('.badge.sup').innerText, 10) - 1; }, updateBookmarkedLayerSettings(id) { @@ -98,12 +120,12 @@ export default Controller.extend({ document.getElementById(id).innerText = newLayerSets[updatedLayerSetIndex].name; }, 1); - this.track(''); + this.track('finishUpdateBookmarkedLayerSettings'); }, turnOnEditMode(id) { this.set('editMode', id); - this.track('updateBookmarkedLayerSettings'); + this.track('beginUpdateBookmarkedLayerSettings'); }, loadBookmarkedLayerSettings(bookmarkId) { @@ -119,6 +141,19 @@ export default Controller.extend({ layer.visibility = !!layerToLoad.visibleLayers.includes(layer.id); }); }); + + [ + 'selectedZoning', + 'selectedOverlays', + 'selectedFirm', + 'selectedPfirm', + 'selectedCouncilDistricts', + 'selectedLayerGroup', + ].forEach((selected) => { + this.router.currentRoute.queryParams[selected] = + layerToLoad.queryParams[selected]; + }); + this.track('loadBookmarkedLayerSettings'); }, }, diff --git a/app/templates/bookmarks.hbs b/app/templates/bookmarks.hbs index 0f01c722..c3ff9858 100644 --- a/app/templates/bookmarks.hbs +++ b/app/templates/bookmarks.hbs @@ -92,9 +92,9 @@ - + {{bookmark.name}} - +