Skip to content

Commit

Permalink
Load handler data using XHR
Browse files Browse the repository at this point in the history
This is required since we don't reload the page but use a single page.
For example, the currently selected database may have changed and the
action buttons may have changed too.
  • Loading branch information
pgiraud authored and rjuju committed Nov 10, 2023
1 parent f3b5fcf commit 15f8d6f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
1 change: 1 addition & 0 deletions powa/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def get(self, *args):
timeline=param_timeline,
title=title,
breadcrumbs=breadcrumbs,
handler=self.to_json(),
)
)

Expand Down
41 changes: 19 additions & 22 deletions powa/static/js/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@
<v-app>
<v-app-bar app elevation="2" height="40px;">
<v-btn
:to="handler.homeUrl"
:to="store.handlerConfig.homeUrl"
class="mr-2"
text
color="primary"
exact-path
elevation="0"
>
<img :src="handler.logoUrl" />&nbsp;<b>PoWA</b>
<img :src="store.handlerConfig.logoUrl" />&nbsp;<b>PoWA</b>
</v-btn>
<template v-if="handler.currentUser">
<template v-if="store.handlerConfig.currentUser">
<v-toolbar-title text class="mr-2 text-body-1">
Server <b>{{ handler.currentServer }}</b> ({{
handler.currentConnection
Server <b>{{ store.handlerConfig.currentServer }}</b> ({{
store.handlerConfig.currentConnection
}})
</v-toolbar-title>
<v-btn
text
color="primary"
:to="handler.configUrl"
:to="store.handlerConfig.configUrl"
title="Configuration"
>
<v-icon left>
{{ icons.mdiCog }}
</v-icon>
Configuration
</v-btn>
<v-menu v-if="handler.notifyAllowed" offset-y>
<v-menu v-if="store.handlerConfig.notifyAllowed" offset-y>
<template #activator="{ on, attrs }">
<v-btn text color="primary" v-bind="attrs" v-on="on">
<v-icon left>
Expand All @@ -42,22 +42,22 @@
<v-list-item-title> Reload collector </v-list-item-title>
</v-list-item>
<v-list-item
v-if="handler.server"
v-if="store.handlerConfig.server"
link
@click="forceSnapshot(handler.server)"
@click="forceSnapshot(store.handlerConfig.server)"
>
<v-list-item-title> Force a snapshot </v-list-item-title>
</v-list-item>
<v-list-item
v-if="handler.server"
v-if="store.handlerConfig.server"
link
:data-dbname="handler.database"
@click="refreshDbCat(handler.server, $event)"
:data-dbname="store.handlerConfig.database"
@click="refreshDbCat(store.handlerConfig.server, $event)"
>
<v-list-item-title>
Refresh catalogs
<span v-if="handler.database">
on db {{ handler.database }}</span
<span v-if="store.handlerConfig.database">
on db {{ store.handlerConfig.database }}</span
>
<span v-else> on all db</span>
</v-list-item-title>
Expand All @@ -66,7 +66,7 @@
</v-menu>

<v-spacer></v-spacer>
<v-btn text color="primary" :href="handler.logoutUrl">
<v-btn text color="primary" :href="store.handlerConfig.logoutUrl">
<v-icon left>
{{ icons.mdiPower }}
</v-icon>
Expand All @@ -81,7 +81,7 @@
</template>
</v-switch>
</template>
<template v-if="handler.currentUser" #extension>
<template v-if="store.handlerConfig.currentUser" #extension>
<bread-crumbs :bread-crumb-items="store.breadcrumbs"></bread-crumbs>
<v-spacer></v-spacer>
<date-range-picker ml-auto></date-range-picker>
Expand All @@ -106,13 +106,13 @@
<v-flex>
<ul style="margin-bottom: 0; padding-left: 0">
<li style="display: inline-block">
Version {{ handler.version }}
Version {{ store.handlerConfig.version }}
</li>
<li style="display: inline-block" class="ml-5">
&copy; 2014-2017 Dalibo
</li>
<li style="display: inline-block" class="ml-5">
&copy; 2018-{{ handler.year }} The PoWA-team
&copy; 2018-{{ store.handlerConfig.year }} The PoWA-team
</li>
<li style="display: inline-block" class="ml-5">
<a href="https://powa.readthedocs.io"
Expand Down Expand Up @@ -170,11 +170,7 @@ import BreadCrumbs from "@/components/BreadCrumbs.vue";
import DateRangePicker from "@/components/DateRangePicker/DateRangePicker.vue";
import LoginView from "@/components/LoginView.vue";
let handler;
const instance = getCurrentInstance();
document.querySelectorAll('script[type="text/handler"]').forEach(function (el) {
handler = JSON.parse(el.innerText);
});
let servers;
document.querySelectorAll('script[type="text/servers"]').forEach(function (el) {
Expand All @@ -187,6 +183,7 @@ onMounted(() => {
});
function initDashboard() {
store.handlerConfig = {};
store.dashboardConfig = null;
// Load dahsboard config from same url but asking for JSON instead of HTML
d3.json(window.location.href, {
Expand Down
2 changes: 2 additions & 0 deletions powa/static/js/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let messageId = 1;

const store = reactive({
dashboardConfig: null,
handlerConfig: {},
dataSources: {},
changesUrl: "",
changes: [],
Expand All @@ -34,6 +35,7 @@ const store = reactive({
document.title = config.dashboard.title;
store.dataSources = {};
store.dashboardConfig = config.dashboard;
store.handlerConfig = config.handler;
_.each(config.datasources, function (dataSource) {
try {
if (dataSource.type == "metric_group") {
Expand Down
3 changes: 0 additions & 3 deletions powa/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
</div>
</div>
{% block data %} {% end %}
<script type="text/handler">
{% raw to_json(handler) %}
</script>
<script type="text/messages">
{% raw to_json(dict(flashed_messages().items())) %}
</script>
Expand Down

0 comments on commit 15f8d6f

Please sign in to comment.