backoffice: use full template to render workflow and global action page (#77971)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-05-27 14:48:37 +02:00
parent 5d68ae36cf
commit bfda7417b1
4 changed files with 144 additions and 131 deletions

View File

@ -765,7 +765,7 @@ def test_workflow_snapshot_browse(pub):
# check actions are displayed
resp = resp.click('Action')
resp = resp.click('Global Action: Action')
assert '>Deletion<' in resp.text
assert resp.pyquery('#items-list li').text() == 'Deletion'
def test_workflow_snapshot_browse_with_missing_role(pub):

View File

@ -35,7 +35,6 @@ from wcs.categories import WorkflowCategory
from wcs.formdata import Evolution
from wcs.formdef import FormDef, UpdateStatisticsDataAfterJob
from wcs.qommon import _, errors, force_str, misc, template
from wcs.qommon.admin.menu import command_icon
from wcs.qommon.form import (
CheckboxWidget,
ColourWidget,
@ -1375,67 +1374,29 @@ class GlobalActionPage(WorkflowStatusPage):
def _q_index(self):
get_response().set_title('%s - %s' % (_('Workflow'), self.workflow.name))
r = TemplateIO(html=True)
get_response().add_javascript(['jquery.js', 'jquery-ui.js', 'biglist.js', 'qommon.wysiwyg.js'])
r += htmltext('<h2>%s</h2>') % self.action.name
r += get_session().display_message()
r += htmltext('<div class="bo-block">')
r += htmltext('<h2>%s</h2>') % _('Actions')
if not self.action.items:
r += htmltext('<p>%s</p>') % _('There are not yet any actions.')
else:
if self.workflow.is_readonly():
r += htmltext('<ul id="items-list" class="biglist sortable readonly">')
else:
r += htmltext('<p class="items">')
r += str(_('Use drag and drop with the handles to reorder actions.'))
r += htmltext('</p>')
r += htmltext('<ul id="items-list" class="biglist sortable">')
for item in self.action.items:
r += htmltext('<li class="biglistitem" data-id="%s">') % item.id
if self.workflow.is_readonly():
r += str(item.render_as_line())
else:
r += htmltext('<a href="items/%s/">%s</a>') % (item.id, item.render_as_line())
r += htmltext('<p class="commands">')
r += command_icon('items/%s/' % item.id, 'edit')
r += command_icon('items/%s/delete' % item.id, 'remove', popup=True)
r += htmltext('</p>')
r += htmltext('</li>')
r += htmltext('</ul>')
r += htmltext('</div>') # bo-block
sortable = 'sortable readonly' if self.workflow.is_readonly() else 'sortable'
r += htmltext('<div class="bo-block">')
r += htmltext('<h2>%s</h2>') % _('Triggers')
r += (
htmltext('<ul id="triggers-list" class="biglist %s" data-order-function="update_triggers_order">')
% sortable
get_response().add_javascript(
[
'jquery.js',
'jquery-ui.js',
'biglist.js',
'qommon.wysiwyg.js',
'popup.js',
'jquery.colourpicker.js',
]
)
for trigger in self.action.triggers:
r += htmltext('<li class="biglistitem" id="trigId_%s">') % trigger.id
if self.workflow.is_readonly():
r += str(trigger.render_as_line())
else:
r += htmltext('<a rel="popup" href="triggers/%s/">%s</a>') % (
trigger.id,
trigger.render_as_line(),
)
r += htmltext('<p class="commands">')
r += command_icon('triggers/%s/' % trigger.id, 'edit', popup=True)
r += command_icon('triggers/%s/delete' % trigger.id, 'remove', popup=True)
r += htmltext('</p>')
r += htmltext('</li>')
r += htmltext('</ul>')
r += htmltext('</div>') # bo-block
r += htmltext('<p><a href="../../">%s</a></p>') % _('Back to workflow main page')
return template.QommonTemplateResponse(
templates=['wcs/backoffice/workflow-global-action.html'],
context={'view': self, 'workflow': self.workflow, 'action': self.action, 'has_sidebar': True},
is_django_native=True,
)
get_response().filter['sidebar'] = self.get_sidebar()
return r.getvalue()
def snapshot_info_block(self):
return utils.snapshot_info_block(
snapshot=self.workflow.snapshot_object,
url_prefix='../../../../',
url_suffix='global-actions/%s/' % self.status.id,
)
def delete(self):
form = Form(enctype='multipart/form-data')
@ -1480,43 +1441,6 @@ class GlobalActionPage(WorkflowStatusPage):
r += form.render()
return r.getvalue()
def get_sidebar(self):
get_response().add_javascript(['popup.js', 'jquery.colourpicker.js'])
r = TemplateIO(html=True)
if self.workflow.is_default():
r += htmltext('<p>')
r += str(
_(
'''This is the default workflow, you cannot edit it but you can
duplicate it to base your own workflow on it.'''
)
)
r += htmltext('</p>')
elif self.workflow.is_readonly():
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This workflow is readonly.')
r += utils.snapshot_info_block(
snapshot=self.workflow.snapshot_object,
url_prefix='../../../../',
url_suffix='global-actions/%s/' % self.status.id,
)
else:
r += htmltext('<ul id="sidebar-actions">')
r += htmltext('<li><a href="edit" rel="popup">%s</a></li>') % _('Change Action Name')
r += htmltext('<li><a href="backoffice-info-text" rel="popup">%s</a></li>') % _(
'Change Backoffice Information Text'
)
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
r += htmltext('</ul>')
r += htmltext('<div id="new-field">')
r += htmltext('<h3>%s</h3>') % _('New Item')
r += self.get_new_item_form().render()
r += htmltext('</div>')
r += htmltext('<div id="new-trigger">')
r += htmltext('<h3>%s</h3>') % _('New Trigger')
r += self.get_new_trigger_form().render()
r += htmltext('</div>')
return r.getvalue()
def update_triggers_order(self):
request = get_request()
new_order = request.form['order'].strip(';').split(';')
@ -1695,46 +1619,20 @@ class WorkflowPage(Directory):
def _q_index(self):
get_response().set_title(_('Workflow - %s') % self.workflow.name)
get_response().filter['sidebar'] = self.get_sidebar()
get_response().add_javascript(
['jquery.js', 'jquery-ui.js', 'biglist.js', 'svg-pan-zoom.js', 'jquery.colourpicker.js']
)
return template.QommonTemplateResponse(
templates=['wcs/backoffice/workflow.html'],
context={'view': self, 'workflow': self.workflow},
context={'view': self, 'workflow': self.workflow, 'has_sidebar': True},
is_django_native=True,
)
def get_sidebar(self):
r = TemplateIO(html=True)
def snapshot_info_block(self):
return utils.snapshot_info_block(snapshot=self.workflow.snapshot_object)
if self.workflow.is_default():
r += htmltext('<p>')
r += str(
_(
'''This is the default workflow, you cannot edit it but you can
duplicate it to base your own workflow on it.'''
)
)
r += htmltext('</p>')
elif self.workflow.is_readonly():
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This workflow is readonly.')
r += utils.snapshot_info_block(snapshot=self.workflow.snapshot_object)
return r.getvalue()
r += htmltext('<ul id="sidebar-actions">')
if not self.workflow.is_readonly():
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
r += htmltext('<li><a rel="popup" href="duplicate">%s</a></li>') % _('Duplicate')
r += htmltext('<li><a href="export">%s</a></li>') % _('Export')
if get_publisher().snapshot_class and not self.workflow.is_default():
r += htmltext('<li><a rel="popup" href="history/save">%s</a></li>') % _('Save snapshot')
r += htmltext('<li><a href="history/">%s</a></li>') % _('History')
r += htmltext('<li><a href="inspect">%s</a></li>') % _('Inspector')
r += htmltext('</ul>')
if not self.workflow.is_readonly():
r += self.get_new_status_form()
r += LoggedErrorsDirectory.errors_block(workflow_id=self.workflow.id)
return r.getvalue()
def errors_block(self):
return LoggedErrorsDirectory.errors_block(workflow_id=self.workflow.id)
def inspect(self):
get_response().set_title(self.workflow.name)

View File

@ -0,0 +1,83 @@
{% extends "wcs/backoffice.html" %}
{% load i18n %}
{% block appbar-title %}{{ action.name }}{% endblock %}
{% block body %}
<div class="bo-block">
<h2>{% trans "Actions" %}</h2>
{% if not action.items %}
<p>{% trans "There are not yet any actions." %}</p>
{% else %}
{% if not workflow.is_readonly %}
<p class="items">
{% trans "Use drag and drop with the handles to reorder actions." %}
</p>
{% endif %}
{% endif %}
<ul id="items-list" class="biglist sortable {% if workflow.is_readonly %}readonly{% endif %}">
{% for item in action.items %}
<li class="biglistitem" data-id="{{ item.id">
{% if workflow.is_readonly %}{{ item.render_as_line }}
{% else %}
<a href="items/{{ item.id }}/">{{ item.render_as_line }}</a>
<p class="commands">
<span class="edit"><a href="items/{{ item.id }}/" title="{% trans "Edit" %}">{% trans "Edit" %}</a></span>
<span class="remove"><a rel="popup" href="items/{{ item.id }}/delete" title="{% trans "Remove" %}">{% trans "Remove" %}</a></span>
</p>
{% endif %}
</li>
{% endfor %}
</ul>
</div>
<div class="bo-block">
<h2>{% trans "Triggers" %}</h2>
<ul id="triggers-list" class="biglist sortable {% if workflow.is_readonly %}readonly{% endif %}"
data-order-function="update_triggers_order">
{% for trigger in action.triggers %}
<li class="biglistitem" id="trigId_{{ trigger.id }}/">
{% if workflow.is_readonly %}{{ trigger.render_as_line }}
{% else %}
<a href="triggers/{{ trigger.id }}/">{{ trigger.render_as_line }}</a>
<p class="commands">
<span class="edit"><a rel="popup" href="triggers/{{ trigger.id }}/" title="{% trans "Edit" %}">{% trans "Edit" %}</a></span>
<span class="remove"><a rel="popup" href="triggers/{{ trigger.id }}/delete" title="{% trans "Remove" %}">{% trans "Remove" %}</a></span>
</p>
{% endif %}
</li>
{% endfor %}
</ul>
</div>
<p><a href="../../">{% trans "Back to workflow main page" %}</a></p>
{% endblock %}
{% block sidebar-content %}
{% if workflow.is_default %}
<p>
{% blocktrans trimmed %}
This is the default workflow, you cannot edit it but you can
duplicate it to base your own workflow on it.
{% endblocktrans %}
</p>
{% elif workflow.is_readonly %}
<div class="infonotice"><p>{% trans "This workflow is readonly." %}</div>
{{ view.snapshot_info_block|safe }}
{% else %}
<ul id="sidebar-actions">
<li><a href="edit" rel="popup">{% trans "Change Action Name" %}</a></li>
<li><a href="backoffice-info-text" rel="popup">{% trans "Change Backoffice Information Text" %}</a></li>
<li><a href="delete" rel="popup">{% trans "Delete" %}</a></li>
</ul>
<div id="new-field">
<h3>{% trans "New Item" %}</h3>
{{ view.get_new_item_form.render|safe }}
</div>
<div id="new-trigger">
<h3>{% trans "New Trigger" %}</h3>
{{ view.get_new_trigger_form.render|safe }}
</div>
{% endif %}
{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "wcs/backoffice/base.html" %}
{% extends "wcs/backoffice.html" %}
{% load i18n %}
{% block appbar-title %}{{ workflow.name }}{% endblock %}
@ -10,7 +10,7 @@
{% endif %}
{% endblock %}
{% block content %}
{% block body %}
{{ view.last_modification_block|safe }}
<div class="splitcontent-left">
@ -197,3 +197,35 @@
{% endwith %}
{% endblock %}
{% block sidebar-content %}
{% if workflow.is_default %}
<p>
{% blocktrans trimmed %}
This is the default workflow, you cannot edit it but you can
duplicate it to base your own workflow on it.
{% endblocktrans %}
</p>
{% elif workflow.is_readonly %}
<div class="infonotice"><p>{% trans "This workflow is readonly." %}</div>
{{ view.snapshot_info_block|safe }}
{% endif %}
{% if not workflow.is_readonly or workflow.is_default %}
<ul id="sidebar-actions">
{% if not workflow.is_readonly %}
<li><a href="delete" rel="popup">{% trans "Delete" %}</a></li>
{% endif %}
<li><a rel="popup" href="duplicate">{% trans "Duplicate" %}</a></li>
<li><a href="export">{% trans "Export" %}</a></li>
{% if not workflow.is_default %}
<li><a rel="popup" href="history/save">{% trans "Save snapshot" %}</a></li>
<li><a href="history/">{% trans "History" %}</a></li>
{% endif %}
<li><a href="inspect">{% trans "Inspector" %}</a></li>
</ul>
{% if not workflow.is_readonly %}
{{ view.get_new_status_form|safe }}
{% endif %}
{{ view.errors_block|safe }}
{% endif %}
{% endblock %}