Skip to content

Commit

Permalink
fix reload page bugs with navdir
Browse files Browse the repository at this point in the history
  • Loading branch information
solderq35 committed Dec 28, 2023
1 parent c606d2f commit 11225b2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/components/charts/chartController.vue
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export default {
// check if current chart is the largest chart, don't map if so
// may need a better way to differentiate charts, but this works for now
// and accounts for have two charts that are the same length
if (chart.backgroundColor != largestChart.backgroundColor) {
if (chart.backgroundColor !== largestChart.backgroundColor) {
// loop through all data points in current chart and map x-value to largest chart
// also create a datapoint for the original x-value so that we can display it on tooltip hover
for (let i in chart.data) {
Expand Down
16 changes: 11 additions & 5 deletions src/components/view/navdir.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<el-col class="main">
<el-row class="bar">
<el-col :span="20">
<!-- The !otherView stuff is currently overwritten by view.vue, see comments there. Maybe need a follow-up
meeting with Brandon and Ross to see if they want any of the navDir features on the comparison pages.
Download data feature might need some edits, if so. -->
<el-menu
v-if="!otherView"
mode="horizontal"
Expand Down Expand Up @@ -97,9 +100,7 @@ export default {
if (this.publicView) {
return this.$store.getters['map/building'](this.$route.params.id)
} else {
let view = this.$store.getters['user/view'](this.$route.params.id)
if (!view) view = this.$store.getters['view']
return view
return this.$store.getters['view']
}
}
},
Expand All @@ -114,6 +115,8 @@ export default {
}
return rValue
} else {
// References to anything about "user", "users", "personal", etc are an obsolete admin frontend feature.
// All references to these things (at least in .vue files) hould be removed in a future PR, but out of scope for now.
return this.$store.getters['user/views']
}
}
Expand Down Expand Up @@ -157,8 +160,10 @@ export default {
},
otherView: {
get () {
if (this.viewOrBuilding.path === 'view') {
return true
if (this.viewOrBuilding) {
if (this.viewOrBuilding.path === 'view') {
return true
}
}
return false
}
Expand All @@ -168,6 +173,7 @@ export default {
get () {
try {
let path = this.$store.getters['map/building'](this.$route.params.id).path
// eslint-disable-next-line
let mgId = this.$store.getters[path + '/primaryGroup']('Electricity').id
return true
} catch (err) {
Expand Down
90 changes: 49 additions & 41 deletions src/components/view/view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ export default {
},
async created () {
await this.$store.dispatch('map/loadMap')
this.navVis = this.personalView || this.$route.path.includes('building') || this.otherView
// Currently, this.navVis is just set to show the navdir on "building" page, and hide on other pages.
// If you want to configure different navdir behavior on the comparison page, e.g. show "share button"
// but not other buttons on navdir, then you may as well just set this.navVis to true here,
// and remove references to navVis in watch > $route section (20 lines or so below), then configure
// this.otherView (or whatever) in navdir.vue file.
// However, this.navVis is still needed here as it guarantees the navbar is not shown before
// await this.$store.dispatch('map/loadMap') completes, preventing errors in navdir file.
// this.navVis = true
this.navVis = this.$route.path.includes('building')
console.log(this.navVis)
await this.$store.dispatch('user/user')
if (!this.view.id) {
await this.$store.dispatch('view/changeView', this.$route.params.id)
Expand All @@ -61,6 +70,8 @@ export default {
$route: {
immediate: true,
handler: async function (to, from) {
this.navVis = this.$route.path.includes('building')
console.log(this.navVis)
if (
!this.$route.path.includes('building') &&
!this.$route.path.includes('compare') &&
Expand All @@ -75,21 +86,24 @@ export default {
this.$store.commit(card.path + '/intervalUnit', this.intervalUnit)
}
}
// Reset multStart and multEnd variables whenever you are on a comparison page for just 1 building
let buildingComparisonNumber = JSON.parse(decodeURI(this.$route.params.buildings)).length
if (this.$route.path.includes('compare') && buildingComparisonNumber === 1) {
for (let card of this.cards) {
if (!card.path) return
this.$nextTick(() => {
let blockpath = this.cards[0].path
let searchTerm = 'block_'
let chartIndex = blockpath.indexOf(searchTerm)
// console.log(blockpath.slice(chartIndex + searchTerm.length))
let blockID = blockpath.slice(chartIndex + searchTerm.length)
// console.log(blockpath + '/chart_' + blockID + '/multStart')
this.$store.commit(blockpath + '/chart_' + blockID + '/clearAndSetMultStart', [this.dateStart])
this.$store.commit(blockpath + '/chart_' + blockID + '/clearAndSetMultEnd', [this.dateEnd])
})
if (this.$route.path.includes('compare')) {
// Reset multStart and multEnd variables whenever you are on a comparison page for just 1 building
let buildingComparisonNumber = JSON.parse(decodeURI(this.$route.params.buildings)).length
console.log(buildingComparisonNumber)
if (buildingComparisonNumber === 1) {
for (let card of this.cards) {
if (!card.path) return
this.$nextTick(() => {
let blockpath = this.cards[0].path
let searchTerm = 'block_'
let chartIndex = blockpath.indexOf(searchTerm)
// console.log(blockpath.slice(chartIndex + searchTerm.length))
let blockID = blockpath.slice(chartIndex + searchTerm.length)
// console.log(blockpath + '/chart_' + blockID + '/multStart')
this.$store.commit(blockpath + '/chart_' + blockID + '/clearAndSetMultStart', [this.dateStart])
this.$store.commit(blockpath + '/chart_' + blockID + '/clearAndSetMultEnd', [this.dateEnd])
})
}
}
}
}
Expand Down Expand Up @@ -159,23 +173,25 @@ export default {
this.$store.commit(card.path + '/intervalUnit', this.intervalUnit)
})
}
// Reset multStart and multEnd variables whenever you are on a comparison page for just 1 building
let buildingComparisonNumber = JSON.parse(decodeURI(this.$route.params.buildings)).length
// console.log(buildingComparisonNumber)
if (this.$route.path.includes('compare') && buildingComparisonNumber === 1) {
for (let card of this.cards) {
if (!card.path) return
this.$nextTick(() => {
let blockpath = this.cards[0].path
let searchTerm = 'block_'
let chartIndex = blockpath.indexOf(searchTerm)
// console.log(blockpath.slice(chartIndex + searchTerm.length))
let blockID = blockpath.slice(chartIndex + searchTerm.length)
// console.log(blockpath + '/chart_' + blockID + '/multStart')
this.$store.commit(blockpath + '/chart_' + blockID + '/clearAndSetMultStart', [this.dateStart])
this.$store.commit(blockpath + '/chart_' + blockID + '/clearAndSetMultEnd', [this.dateEnd])
// console.log(this.$store.getters)
})
if (this.$route.path.includes('compare')) {
// Reset multStart and multEnd variables whenever you are on a comparison page for just 1 building
let buildingComparisonNumber = JSON.parse(decodeURI(this.$route.params.buildings)).length
console.log(buildingComparisonNumber)
if (buildingComparisonNumber === 1) {
for (let card of this.cards) {
if (!card.path) return
this.$nextTick(() => {
let blockpath = this.cards[0].path
let searchTerm = 'block_'
let chartIndex = blockpath.indexOf(searchTerm)
// console.log(blockpath.slice(chartIndex + searchTerm.length))
let blockID = blockpath.slice(chartIndex + searchTerm.length)
// console.log(blockpath + '/chart_' + blockID + '/multStart')
this.$store.commit(blockpath + '/chart_' + blockID + '/clearAndSetMultStart', [this.dateStart])
this.$store.commit(blockpath + '/chart_' + blockID + '/clearAndSetMultEnd', [this.dateEnd])
// console.log(this.$store.getters)
})
}
}
}
}
Expand All @@ -195,14 +211,6 @@ export default {
return false
}
},
otherView: {
get () {
if (this.view.path === 'view') {
return true
}
return false
}
},
view: {
get () {
if (this.$route.path.includes('building')) {
Expand Down

0 comments on commit 11225b2

Please sign in to comment.