Add new Buefy-specific upgrade template

since that was broken..
This commit is contained in:
Lance Edgar 2023-02-03 15:18:39 -06:00
parent 9faaea881d
commit f0880785a9
5 changed files with 129 additions and 26 deletions

View file

@ -8,6 +8,7 @@
<title>${initial_msg or "Working"}...</title> <title>${initial_msg or "Working"}...</title>
${core_javascript()} ${core_javascript()}
${core_styles()} ${core_styles()}
${self.extra_styles()}
</head> </head>
<body style="height: 100%;"> <body style="height: 100%;">
@ -61,6 +62,8 @@
<div style="flex-grow: 1;"></div> <div style="flex-grow: 1;"></div>
</div> </div>
${self.after_progress()}
</div> </div>
</div> </div>
</section> </section>
@ -72,23 +75,6 @@
let WholePage = { let WholePage = {
template: '#whole-page-template', template: '#whole-page-template',
data() {
return {
progressURL: '${url('progress', key=progress.key, _query={'sessiontype': progress.session.type})}',
progressMessage: "${(initial_msg or "Working").replace('"', '\\"')} (please wait)",
progressMax: null,
progressMaxDisplay: null,
progressValue: null,
stillInProgress: true,
% if can_cancel:
canCancel: true,
cancelURL: '${url('progress.cancel', key=progress.key, _query={'sessiontype': progress.session.type})}',
cancelingProgress: false,
% endif
}
},
computed: { computed: {
totalDisplay() { totalDisplay() {
@ -113,10 +99,15 @@
setTimeout(() => { setTimeout(() => {
this.updateProgress() this.updateProgress()
}, 1000) }, 1000)
// custom logic if applicable
this.mountedCustom()
}, },
methods: { methods: {
mountedCustom() {},
updateProgress() { updateProgress() {
this.$http.get(this.progressURL).then(response => { this.$http.get(this.progressURL).then(response => {
@ -146,6 +137,9 @@
} }
} }
// custom logic if applicable
this.updateProgressCustom(response)
if (this.stillInProgress) { if (this.stillInProgress) {
// fetch progress data again, in one second from now // fetch progress data again, in one second from now
@ -157,6 +151,8 @@
}) })
}, },
updateProgressCustom(response) {},
% if can_cancel: % if can_cancel:
cancelProgress() { cancelProgress() {
@ -178,13 +174,46 @@
} }
} }
Vue.component('whole-page', WholePage) let WholePageData = {
new Vue({ progressURL: '${url('progress', key=progress.key, _query={'sessiontype': progress.session.type})}',
el: '#whole-page-app' progressMessage: "${(initial_msg or "Working").replace('"', '\\"')} (please wait)",
}) progressMax: null,
progressMaxDisplay: null,
progressValue: null,
stillInProgress: true,
% if can_cancel:
canCancel: true,
cancelURL: '${url('progress.cancel', key=progress.key, _query={'sessiontype': progress.session.type})}',
cancelingProgress: false,
% endif
}
</script> </script>
${self.modify_whole_page_vars()}
${self.make_whole_page_app()}
</body> </body>
</html> </html>
<%def name="extra_styles()"></%def>
<%def name="after_progress()"></%def>
<%def name="modify_whole_page_vars()"></%def>
<%def name="make_whole_page_app()">
<script type="text/javascript">
WholePage.data = function() { return WholePageData }
Vue.component('whole-page', WholePage)
new Vue({
el: '#whole-page-app'
})
</script>
</%def>

View file

@ -0,0 +1,69 @@
## -*- coding: utf-8; -*-
<%inherit file="/progress.mako" />
<%def name="extra_styles()">
${parent.extra_styles()}
<style type="text/css">
.progress-with-textout {
border: 1px solid Black;
line-height: 1.2;
margin-top: 1rem;
overflow: auto;
padding: 1rem;
}
</style>
</%def>
<%def name="after_progress()">
<!-- <div ref="stdout" class="stdout"></div> -->
<div ref="textout"
class="progress-with-textout is-family-monospace is-size-7">
<span v-for="line in progressOutput"
:key="line.key"
v-html="line.text">
</span>
## nb. we auto-scroll down to "see" this element
<div ref="seeme"></div>
</div>
</%def>
<%def name="modify_whole_page_vars()">
<script type="text/javascript">
WholePageData.progressURL = '${url('upgrades.execute_progress', uuid=instance.uuid)}'
WholePageData.progressOutput = []
WholePageData.progressOutputCounter = 0
WholePage.methods.mountedCustom = function() {
// grow the textout area to fill most of screen
let textout = this.$refs.textout
let height = window.innerHeight - textout.offsetTop - 100
textout.style.height = height + 'px'
}
WholePage.methods.updateProgressCustom = function(response) {
if (response.data.stdout) {
// add lines to textout area
this.progressOutput.push({
key: ++this.progressOutputCounter,
text: response.data.stdout})
// scroll down to end of textout area
this.$nextTick(() => {
this.$refs.seeme.scrollIntoView({behavior: 'smooth'})
})
}
}
</script>
</%def>
${parent.body()}

View file

@ -78,13 +78,15 @@
<%def name="render_buefy_form()"> <%def name="render_buefy_form()">
<div class="form"> <div class="form">
<${form.component} <${form.component}
% if expose_websockets and master.has_perm('execute'): % if master.has_perm('execute'):
@declare-failure-click="declareFailureClick"
:declare-failure-submitting="declareFailureSubmitting"
% if expose_websockets:
% if instance_executable: % if instance_executable:
@execute-upgrade-click="executeUpgrade" @execute-upgrade-click="executeUpgrade"
% endif % endif
:upgrade-executing="upgradeExecuting" :upgrade-executing="upgradeExecuting"
@declare-failure-click="declareFailureClick" % endif
:declare-failure-submitting="declareFailureSubmitting"
% endif % endif
> >
</${form.component}> </${form.component}>

View file

@ -24,6 +24,7 @@
Model Master View Model Master View
""" """
import io
import os import os
import csv import csv
import datetime import datetime
@ -33,7 +34,6 @@ import tempfile
import logging import logging
import json import json
import six
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import orm from sqlalchemy import orm
import sqlalchemy_continuum as continuum import sqlalchemy_continuum as continuum
@ -115,6 +115,7 @@ class MasterView(View):
executable = False executable = False
execute_progress_template = None execute_progress_template = None
execute_progress_initial_msg = None execute_progress_initial_msg = None
execute_can_cancel = True
supports_prev_next = False supports_prev_next = False
supports_import_batch_from_file = False supports_import_batch_from_file = False
has_input_file_templates = False has_input_file_templates = False
@ -1839,6 +1840,7 @@ class MasterView(View):
return self.render_progress(progress, { return self.render_progress(progress, {
'instance': obj, 'instance': obj,
'initial_msg': self.execute_progress_initial_msg, 'initial_msg': self.execute_progress_initial_msg,
'can_cancel': self.execute_can_cancel,
'cancel_url': self.get_action_url('view', obj), 'cancel_url': self.get_action_url('view', obj),
'cancel_msg': "{} execution was canceled".format(model_title), 'cancel_msg': "{} execution was canceled".format(model_title),
}, template=self.execute_progress_template) }, template=self.execute_progress_template)
@ -3785,7 +3787,7 @@ class MasterView(View):
""" """
obj = self.get_instance() obj = self.get_instance()
fields = self.get_row_csv_fields() fields = self.get_row_csv_fields()
data = six.StringIO() data = io.StringIO()
writer = UnicodeDictWriter(data, fields) writer = UnicodeDictWriter(data, fields)
writer.writeheader() writer.writeheader()
for row in self.get_effective_row_data(sort=True): for row in self.get_effective_row_data(sort=True):

View file

@ -60,6 +60,7 @@ class UpgradeView(MasterView):
executable = True executable = True
execute_progress_template = '/upgrade.mako' execute_progress_template = '/upgrade.mako'
execute_progress_initial_msg = "Upgrading" execute_progress_initial_msg = "Upgrading"
execute_can_cancel = False
labels = { labels = {
'executed_by': "Executed by", 'executed_by': "Executed by",