Skip to content

Commit

Permalink
[INTERNAL] Reorganize Vue templates #440
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm authored Oct 30, 2023
2 parents 1630dac + a5e4c60 commit 6e5af8c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion promgen/locale/ja/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ msgstr "Projectを削除"
#: templates/promgen/project_detail_hosts.html:21
#: templates/promgen/service_block.html:20
#: templates/promgen/service_block.html:105
#: templates/promgen/silence_form.html:28
#: templates/promgen/vue/silence_form.html:28
msgid "Silence"
msgstr "Silence"

Expand Down
22 changes: 11 additions & 11 deletions promgen/static/js/promgen.vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ Vue.filter("time", function (value, fmtstr = "yyyy-MM-dd HH:mm:ss") {
});

Vue.component("promql-query", {
delimiters: ['[[', ']]'],
props: ["href", "query", "max"],
data: function () {
return {
Expand All @@ -206,11 +207,7 @@ Vue.component("promql-query", {
return "label label-success";
},
},
template: `
<span style="display:none" :title="load|percent" :class="classes">
{{count|localize}} <slot></slot>
</span>
`,
template: '#promql-query-template',
mounted() {
var this_ = this;
var url = new URL(this.href);
Expand All @@ -229,21 +226,24 @@ Vue.component("promql-query", {
});

Vue.component('bootstrap-panel', {
delimiters: ['[[', ']]'],
props: ['heading'],
template: '<div class="panel"><div class="panel-heading">{{heading}}</div><div class="panel-body"><slot /></div></div>'
})
template: '#bootstrap-panel-template',
});

const ExporterResult = Vue.component('exporter-result', {
delimiters: ['[[', ']]'],
props: ['results'],
template: '<bootstrap-panel class="panel-info" heading="Results"><table class="table"><tr v-for="(val, key, index) in results"><td>{{key}}</td><td>{{val}}</td></tr></table></bootstrap-panel>'
})
template: '#exporter-result-template',
});

const ExporterTest = Vue.component('exporter-test', {
// Exporter Test button for Forms
// Acts like a regular form submit button, but hijacks the button
// click and submits it to an alternate URL for testing
delimiters: ['[[', ']]'],
props: ['href', 'target'],
template: '<button @click.prevent="onTestSubmit"><slot /></button>',
template: '#exporter-test-template',
methods: {
onTestSubmit: function (event) {
// Find the parent form our button belongs to so that we can
Expand All @@ -262,4 +262,4 @@ const ExporterTest = Vue.component('exporter-test', {
.catch(error => alert(error))
}
}
})
});
14 changes: 13 additions & 1 deletion promgen/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@
<script src="{% static 'js/linkify.min.js' %}"></script>
<script src="{% static 'js/linkify-string.min.js' %}"></script>
<script src="{% static 'js/vue.min.js' %}"></script>
<script type="text/x-template" id="bootstrap-panel-template">
{% include 'promgen/vue/bootstrap_panel.html' %}
</script>
<script type="text/x-template" id="exporter-result-template">
{% include 'promgen/vue/exporter_result.html' %}
</script>
<script type="text/x-template" id="exporter-test-template">
{% include 'promgen/vue/exporter_test.html' %}
</script>
<script type="text/x-template" id="promql-query-template">
{% include 'promgen/vue/promql_query.html' %}
</script>
<script type="text/x-template" id="silence-form-template">
{% include 'promgen/silence_form.html' %}
{% include 'promgen/vue/silence_form.html' %}
</script>
<script src="{% static 'js/promgen.js' %}"></script>
<script src="{% static 'js/promgen.vue.js' %}"></script>
Expand Down
4 changes: 4 additions & 0 deletions promgen/templates/promgen/vue/bootstrap_panel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="panel">
<div class="panel-heading">[[ heading ]]</div>
<div class="panel-body"><slot /></div>
</div>
8 changes: 8 additions & 0 deletions promgen/templates/promgen/vue/exporter_result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<bootstrap-panel class="panel-info" heading="Results">
<table class="table">
<tr v-for="(val, key, index) in results">
<td>[[ key ]]</td>
<td>[[ val ]]</td>
</tr>
</table>
</bootstrap-panel>
1 change: 1 addition & 0 deletions promgen/templates/promgen/vue/exporter_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button @click.prevent="onTestSubmit"><slot /></button>
3 changes: 3 additions & 0 deletions promgen/templates/promgen/vue/promql_query.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span style="display: none" :title="load | percent" :class="classes">
[[ count | localize ]] <slot></slot>
</span>
File renamed without changes.

0 comments on commit 6e5af8c

Please sign in to comment.