backoffice: add History links in sidebars (#4960)

This commit is contained in:
Frédéric Péters 2020-08-17 16:40:42 +02:00
parent c5a9ae2094
commit c5f3c1a1f8
9 changed files with 51 additions and 20 deletions

View File

@ -164,7 +164,8 @@ def test_form_snapshot_history(pub, formdef_with_history):
create_superuser(pub)
create_role()
app = login(get_app(pub))
resp = app.get('/backoffice/forms/%s/history/' % formdef_with_history.id)
resp = app.get('/backoffice/forms/%s/' % formdef_with_history.id)
resp = resp.click('History')
assert [x.attrib['class'] for x in resp.pyquery.find('ul.snapshots-list li')] == [
'new-day', 'collapsed', 'collapsed', 'collapsed', 'collapsed', 'collapsed']

View File

@ -16,7 +16,7 @@
import xml.etree.ElementTree as ET
from quixote import get_response, get_session, redirect
from quixote import get_publisher, get_response, get_session, redirect
from quixote.directory import Directory
from quixote.html import TemplateIO, htmltext
@ -60,12 +60,6 @@ class BlockDirectory(FieldsDirectory):
r = TemplateIO(html=True)
r += htmltext('<div id="appbar">')
r += htmltext('<h2>%s</h2>') % self.objectdef.name
r += htmltext('<span class="actions">')
if not self.objectdef.is_readonly():
r += htmltext('<a href="delete" rel="popup">%s</a>') % _('Delete')
r += htmltext('<a href="export">%s</a>') % _('Export')
r += htmltext('<a href="settings" rel="popup">%s</a>') % _('Settings')
r += htmltext('</span>')
r += htmltext('</div>')
r += utils.last_modification_block(obj=self.objectdef)
r += get_session().display_message()
@ -90,6 +84,18 @@ class BlockDirectory(FieldsDirectory):
r += htmltext('</div>')
return r.getvalue()
def get_new_field_form(self, page_id):
r = TemplateIO(html=True)
r += htmltext('<ul id="sidebar-actions">')
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
r += htmltext('<li><a href="export">%s</a></li>') % _('Export')
if get_publisher().snapshot_class:
r += htmltext('<li><a href="history/">%s</a></li>') % _('History')
r += htmltext('<li><a href="settings" rel="popup">%s</a></li>') % _('Settings')
r += htmltext('</ul>')
r += super().get_new_field_form(page_id=page_id)
return r.getvalue()
def delete(self):
form = Form(enctype='multipart/form-data')
if not self.objectdef.is_used():

View File

@ -16,7 +16,7 @@
import xml.etree.ElementTree as ET
from quixote import redirect
from quixote import get_publisher, redirect
from quixote.directory import Directory
from quixote.html import TemplateIO, htmltext
@ -169,11 +169,22 @@ class NamedDataSourcePage(Directory):
get_response().breadcrumb.append((component + '/', self.datasource.name))
self.snapshots_dir = SnapshotsDirectory(self.datasource)
def get_sidebar(self):
r = TemplateIO(html=True)
if self.datasource.is_readonly():
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This data source is readonly.')
r += htmltext('<ul id="sidebar-actions">')
if not self.datasource.is_readonly():
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
r += htmltext('<li><a href="export">%s</a></li>') % _('Export')
if get_publisher().snapshot_class:
r += htmltext('<li><a href="history/">%s</a></li>') % _('History')
r += htmltext('</ul>')
return r.getvalue()
def _q_index(self):
html_top('datasources', title=self.datasource.name)
if self.datasource.is_readonly():
get_response().filter['sidebar'] = htmltext(
'<div class="infonotice"><p>%s</p></div>') % _('This data source is readonly.')
get_response().filter['sidebar'] = self.get_sidebar()
return template.QommonTemplateResponse(
templates=['wcs/backoffice/data-source.html'],
context={'view': self, 'datasource': self.datasource})

View File

@ -622,6 +622,8 @@ class FormDefPage(Directory):
r += htmltext('<li><a rel="popup" href="overwrite">%s</a></li>') % _(
'Overwrite with new import')
r += htmltext('<li><a href="export">%s</a></li>') % _('Export')
if get_publisher().snapshot_class:
r += htmltext('<li><a href="history/">%s</a></li>') % _('History')
r += htmltext('<li><a href="anonymise">%s</a></li>') % _('Anonymise forms')
if not get_publisher().is_using_postgresql():
r += htmltext('<li><a href="archive">%s</a></li>') % _('Archive')

View File

@ -1576,6 +1576,8 @@ class WorkflowPage(Directory):
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
r += htmltext('<li><a href="duplicate">%s</a></li>') % _('Duplicate')
r += htmltext('<li><a href="export">%s</a></li>') % _('Export')
if get_publisher().snapshot_class:
r += htmltext('<li><a href="history/">%s</a></li>') % _('History')
r += htmltext('</ul>')
if not self.workflow.is_readonly():
r += self.get_new_status_form()

View File

@ -16,7 +16,7 @@
import xml.etree.ElementTree as ET
from quixote import redirect
from quixote import get_publisher, get_response, redirect
from quixote.directory import Directory
from quixote.html import TemplateIO, htmltext
@ -108,11 +108,22 @@ class NamedWsCallPage(Directory):
get_response().breadcrumb.append((component + '/', self.wscall.name))
self.snapshots_dir = SnapshotsDirectory(self.wscall)
def get_sidebar(self):
r = TemplateIO(html=True)
if self.wscall.is_readonly():
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This webservice call is readonly.')
r += htmltext('<ul id="sidebar-actions">')
if not self.wscall.is_readonly():
r += htmltext('<li><a href="export">%s</a></li>') % _('Export')
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
if get_publisher().snapshot_class:
r += htmltext('<li><a href="history/">%s</a></li>') % _('History')
r += htmltext('</ul>')
return r.getvalue()
def _q_index(self):
html_top('wscalls', title=self.wscall.name)
if self.wscall.is_readonly():
get_response().filter['sidebar'] = htmltext(
'<div class="infonotice"><p>%s</p></div>') % _('This webservice call is readonly.')
get_response().filter['sidebar'] = self.get_sidebar()
return template.QommonTemplateResponse(
templates=['wcs/backoffice/wscall.html'],
context={'view': self, 'wscall': self.wscall})

View File

@ -183,6 +183,8 @@ class CardDefPage(FormDefPage):
r += htmltext('<li><a rel="popup" href="overwrite">%s</a></li>') % _(
'Overwrite with new import')
r += htmltext('<li><a href="export">%s</a></li>') % _('Export')
if get_publisher().snapshot_class:
r += htmltext('<li><a href="history/">%s</a></li>') % _('History')
r += htmltext('</ul>')
r += LoggedErrorsDirectory.errors_block(formdef_id=self.formdef.id)

View File

@ -4,9 +4,7 @@
<div id="appbar">
<h2>{% trans "Data Source" %} - {{ datasource.name }}</h2>
<span class="actions">
<a href="export">{% trans "Export" %}</a>
{% if not datasource.is_readonly %}
<a href="delete" rel="popup">{% trans "Delete" %}</a>
<a href="edit">{% trans "Edit" %}</a>
{% endif %}
</span>

View File

@ -5,8 +5,6 @@
<h2>{% trans "Webservice Call" %} - {{ wscall.name }}</h2>
{% if not wscall.is_readonly %}
<span class="actions">
<a href="export">{% trans "Export" %}</a>
<a href="delete" rel="popup">{% trans "Delete" %}</a>
<a href="edit">{% trans "Edit" %}</a>
</span>
{% endif %}