Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loadpoint UI: add direct linking #18498

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions assets/js/components/Loadpoints.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
:batteryConfigured="batteryConfigured"
class="h-100"
:class="{ 'loadpoint-unselected': !selected(index) }"
@click="scrollTo(index)"
@click="goTo(index)"
/>
</div>
</div>
Expand All @@ -37,7 +37,7 @@
:key="index"
class="btn btn-sm btn-link p-0 mx-1 indicator d-flex justify-content-center align-items-center evcc-default-text"
:class="{ 'indicator--selected': selected(index) }"
@click="scrollTo(index)"
@click="goTo(index)"
>
<shopicon-filled-lightning
v-if="isCharging(loadpoint)"
Expand Down Expand Up @@ -70,15 +70,25 @@ export default {
tariffGrid: Number,
tariffCo2: Number,
currency: String,
selectedIndex: Number,
gridConfigured: Boolean,
pvConfigured: Boolean,
batteryConfigured: Boolean,
},
emits: ["index-changed"],
data() {
return { selectedIndex: 0, snapTimeout: null };
return { snapTimeout: null, scrollTimeout: null, highlightedIndex: 0 };
},
watch: {
selectedIndex: function (newIndex) {
this.scrollTo(newIndex);
},
},
mounted() {
this.$refs.carousel.addEventListener("scroll", this.handleCarouselScroll, false);
if (this.selectedIndex > 0) {
this.$refs.carousel.scrollTo({ top: 0, left: this.left(this.selectedIndex) });
}
this.$refs.carousel.addEventListener("scroll", this.handleCarouselScroll);
},
unmounted() {
if (this.$refs.carousel) {
Expand All @@ -89,23 +99,33 @@ export default {
handleCarouselScroll() {
const { scrollLeft } = this.$refs.carousel;
const { offsetWidth } = this.$refs.carousel.children[0];
this.selectedIndex = Math.round((scrollLeft - 7.5) / offsetWidth);
this.highlightedIndex = Math.round((scrollLeft - 7.5) / offsetWidth);

// save scroll position to url if not changing for 2s
clearTimeout(this.scrollTimeout);
this.scrollTimeout = setTimeout(() => {
if (this.highlightedIndex !== this.selectedIndex) {
this.$emit("index-changed", this.highlightedIndex);
}
}, 2000);
},
goTo(index) {
this.$emit("index-changed", index);
},
isCharging(lp) {
return lp.charging && lp.chargePower > 0;
},
selected(index) {
return this.selectedIndex === index;
return this.highlightedIndex === index;
},
left(index) {
return this.$refs.carousel.children[0].offsetWidth * index;
},
scrollTo(index) {
if (this.selectedIndex === index) {
return;
}
this.selectedIndex = index;
this.highlightedIndex = index;
const $carousel = this.$refs.carousel;
const width = $carousel.children[0].offsetWidth;
$carousel.style.scrollSnapType = "none";
$carousel.scrollTo({ top: 0, left: 7.5 + width * index, behavior: "smooth" });
$carousel.scrollTo({ top: 0, left: this.left(index), behavior: "smooth" });

clearTimeout(this.snapTimeout);
this.snapTimeout = setTimeout(() => {
Expand Down
10 changes: 9 additions & 1 deletion assets/js/components/Site.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<h1 class="mb-5 text-gray fs-4">{{ $t("startupError.title") }}</h1>
</div>
<Loadpoints
v-else
v-else-if="loadpoints.length > 0"
class="mt-1 mt-sm-2 flex-grow-1"
:loadpoints="loadpoints"
:vehicles="vehicleList"
Expand All @@ -33,6 +33,8 @@
:pvConfigured="pvConfigured"
:batteryConfigured="batteryConfigured"
:batterySoc="batterySoc"
:selectedIndex="selectedLoadpointIndex"
@index-changed="selectedLoadpointChanged"
/>
<Footer v-bind="footer"></Footer>
</div>
Expand Down Expand Up @@ -61,6 +63,7 @@ export default {
mixins: [formatter, collector],
props: {
loadpoints: Array,
selectedLoadpointIndex: Number,

notifications: Array,
offline: Boolean,
Expand Down Expand Up @@ -164,6 +167,11 @@ export default {
};
},
},
methods: {
selectedLoadpointChanged(index) {
this.$router.push({ query: { lp: index + 1 } });
},
},
};
</script>
<style scoped>
Expand Down
11 changes: 10 additions & 1 deletion assets/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ export default function setupRouter(i18n) {
const router = createRouter({
history: createWebHashHistory(),
routes: [
{ path: "/", component: () => import("./views/Main.vue"), props: true },
{
path: "/",
component: () => import("./views/Main.vue"),
props: (route) => {
const { lp } = route.query;
return {
selectedLoadpointIndex: lp ? parseInt(lp, 10) - 1 : undefined,
};
},
},
{
path: "/config",
component: () => import("./views/Config.vue"),
Expand Down
7 changes: 6 additions & 1 deletion assets/js/views/Main.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<Site :notifications="notifications" v-bind="state"></Site>
<Site
:notifications="notifications"
v-bind="state"
:selected-loadpoint-index="selectedLoadpointIndex"
/>
</template>

<script>
Expand All @@ -11,6 +15,7 @@ export default {
components: { Site },
props: {
notifications: Array,
selectedLoadpointIndex: Number,
},
data: function () {
return store;
Expand Down