backoffice: use a popup for new status (#78147)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-06-03 16:01:45 +02:00
parent 6e552c3fff
commit ecb956bac6
3 changed files with 55 additions and 38 deletions

View File

@ -91,6 +91,9 @@ def test_workflows_new(pub):
assert '<svg ' not in resp.text
# create a new status
resp = resp.click('add status')
resp = resp.forms[0].submit('cancel').follow()
resp = resp.click('add status')
resp.forms[0]['name'] = 'new status'
resp = resp.forms[0].submit()
assert resp.location == 'http://example.net/backoffice/workflows/1/'
@ -126,6 +129,27 @@ def test_workflows_new(pub):
assert wf.possible_status[0].items[0].message == 'bla bla bla'
def test_workflows_status_same_name(pub):
create_superuser(pub)
Workflow.wipe()
workflow = Workflow(name='foo')
workflow.add_status(name='baz')
workflow.store()
app = login(get_app(pub))
resp = app.get(workflow.get_admin_url())
resp = resp.click('add status')
resp.forms[0]['name'] = 'baz'
resp = resp.forms[0].submit()
assert 'There is already a status with that name.' in resp.text
resp.forms[0]['name'] = 'bar'
resp = resp.forms[0].submit().follow()
workflow = Workflow.get(workflow.id)
assert len(workflow.possible_status) == 2
def test_workflows_svg(pub):
create_superuser(pub)
pub.role_class.wipe()

View File

@ -982,7 +982,7 @@ class WorkflowStatusPage(Directory):
class WorkflowStatusDirectory(Directory):
_q_exports = ['']
_q_exports = ['', 'new']
def __init__(self, workflow):
self.workflow = workflow
@ -993,6 +993,31 @@ class WorkflowStatusDirectory(Directory):
def _q_index(self):
return redirect('..')
def new(self):
form = Form(enctype='multipart/form-data')
form.add(StringWidget, 'name', title=_('Name'), required=True, size=50)
form.add_submit('submit', _('Add'))
form.add_submit('cancel', _('Cancel'))
if form.get_widget('cancel').parse():
return redirect(self.workflow.get_admin_url())
if form.is_submitted() and not form.has_errors():
name = form.get_widget('name').parse()
try:
self.workflow.add_status(name)
except DuplicateStatusNameError:
form.get_widget('name').set_error(_('There is already a status with that name.'))
else:
self.workflow.store(comment=_('New status "%s"') % name)
return redirect(self.workflow.get_admin_url())
get_response().breadcrumb.append(('new', _('New Status')))
get_response().set_title(_('New Status'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('New Status')
r += form.render()
return r.getvalue()
class WorkflowVariableWidget(CompositeWidget):
def __init__(self, name, value=None, workflow=None, **kwargs):
@ -1659,17 +1684,6 @@ class WorkflowPage(Directory):
content_type='application/x-wcs-workflow',
)
def get_new_status_form(self):
r = TemplateIO(html=True)
r += htmltext('<div id="new-field">')
r += htmltext('<h3>%s</h3>') % _('New Status')
form = Form(enctype='multipart/form-data', action='newstatus')
form.add(StringWidget, 'name', title=_('Name'), required=True, size=50)
form.add_submit('submit', _('Add'))
r += form.render()
r += htmltext('</div>')
return r.getvalue()
def update_order(self):
get_response().set_content_type('application/json')
new_possible_status = update_order(self.workflow.possible_status)
@ -1697,28 +1711,6 @@ class WorkflowPage(Directory):
self.workflow.store(comment=_('Change in criticality levels order'))
return json.dumps({'err': 0})
def newstatus(self):
form = Form(enctype='multipart/form-data', action='newstatus')
form.add(StringWidget, 'name', title=_('Name'), size=50)
if not form.is_submitted() or form.has_errors():
get_session().message = ('error', _('Submitted form was not filled properly.'))
return redirect('.')
if form.get_widget('name').parse():
try:
self.workflow.add_status(form.get_widget('name').parse())
except DuplicateStatusNameError:
get_session().message = ('error', _('There is already a status with that name.'))
return redirect('.')
else:
get_session().message = ('error', _('Submitted form was not filled properly.'))
return redirect('.')
self.workflow.store(comment=_('New status "%s"') % form.get_widget('name').parse())
return redirect('.')
def edit(self):
form = self.workflow_ui.form_edit()
if form.get_widget('cancel').parse():

View File

@ -15,7 +15,11 @@
<div class="splitcontent-left">
<div class="bo-block">
<h3>{% trans "Possible Status" %}</h3>
<h3>{% trans "Possible Status" %}
{% if not workflow.is_readonly %}
<span class="change">(<a rel="popup" href="status/new">{% trans "add status" %}</a>)</span>
{% endif %}
</h3>
{% if not workflow.possible_status %}
<p>{% trans "There are not yet any status defined in this workflow." %}</p>
{% else %}
@ -223,9 +227,6 @@
{% 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 %}