Skip to content

Commit

Permalink
Merge pull request #75 from basxsoftwareassociation/refactor/datatabl…
Browse files Browse the repository at this point in the history
…e-button-link-improvments

Refactor/datatable button link improvments
  • Loading branch information
saemideluxe authored Sep 7, 2021
2 parents b09950b + 7839efe commit 4b0e0fe
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 170 deletions.
2 changes: 1 addition & 1 deletion bread/contrib/reports/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def exceldownload(request, pk: int):
Report,
browseview=views.BrowseView._with(
columns=["name", "created"],
rowclickaction="read",
rowclickaction=views.BrowseView.gen_rowclickaction("read"),
bulkactions=[
views.browse.BulkAction(
"delete", label=_("Delete"), iconname="trash-can", action=delete
Expand Down
10 changes: 7 additions & 3 deletions bread/contrib/workflows/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ def cancel(self, save=True):
self.save()

def save(self, *args, **kwargs):
self.update_workflow_state()
self.update_workflow_state(runactions=True)
if not self.completed and not self.cancelled and self.done:
self.completed = timezone.now()
super().save(*args, **kwargs)

def update_workflow_state(self):
def update_workflow_state(self, runactions=False):
# don't do anything on the workflow after it has been cancelled
if self.cancelled:
return
Expand All @@ -294,7 +294,11 @@ def update_workflow_state(self):
node = nodequeue.pop()
if not node.done(self):
if isinstance(node, Action):
if any(n.done(self) for n, c in node.inputs):
if (
node.hasincoming(self)
and not getattr(self, node.name)
and runactions
):
actionresult = node.action(self)
if actionresult != getattr(self, node.name):
state_changed = True
Expand Down
51 changes: 31 additions & 20 deletions bread/contrib/workflows/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class WorkflowBrowseView(views.BrowseView):
rowclickaction = "edit"
rowclickaction = views.BrowseView.gen_rowclickaction("edit")

def get_layout(self):
workflow_diagram = layout.modal.Modal(
Expand Down Expand Up @@ -33,13 +33,18 @@ def get_layout(self):
fields = hg.BaseElement(
*[layout.form.FormField(f) for f in self.object.active_fields()]
)
return hg.DIV(
return hg.BaseElement(
hg.H1(self.object, style="margin-bottom: 2rem"),
hg.DIV(
layout.form.Form.wrap_with_form(hg.C("form"), fields),
style="padding: 1rem",
hg.DIV(
layout.form.Form.wrap_with_form(hg.C("form"), fields),
style="padding: 1rem",
),
hg.DIV(
self.object.as_svg(), style="width: 40%; border: 1px solid gray"
),
style="display: flex",
),
hg.DIV(self.object.as_svg(), style="width: 40%; border: 1px solid gray"),
style="display: flex",
)


Expand All @@ -52,22 +57,28 @@ def get_layout(self):
]
)

return hg.DIV(
layout.button.Button(
"Edit",
**layout.aslink_attributes(layout.objectaction(self.object, "edit")),
),
views.layoutasreadonly(
hg.DIV(
hg.DIV(
layout.form.Form.wrap_with_form(hg.C("form"), fields),
style="padding: 1rem",
return hg.BaseElement(
hg.H1(self.object, style="margin-bottom: 2rem"),
hg.DIV(
layout.button.Button(
"Edit",
**layout.aslink_attributes(
layout.objectaction(self.object, "edit")
),
),
views.layoutasreadonly(
hg.DIV(
self.object.as_svg(), style="width: 40%; border: 1px solid gray"
),
style="display: flex;",
)
hg.DIV(
layout.form.Form.wrap_with_form(hg.C("form"), fields),
style="padding: 1rem",
),
hg.DIV(
self.object.as_svg(),
style="width: 40%; border: 1px solid gray",
),
style="display: flex;",
)
),
),
)

Expand Down
1 change: 1 addition & 0 deletions bread/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .components import multiselect # noqa
from .components import notification # noqa
from .components import overflow_menu # noqa
from .components import pagination # noqa
from .components import progress_indicator # noqa
from .components import search # noqa
from .components import search_select # noqa
Expand Down
25 changes: 2 additions & 23 deletions bread/layout/components/button.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import warnings

import htmlgenerator as hg
from django.utils.translation import gettext_lazy as _

from bread.utils.links import Link

from .icon import Icon


Expand Down Expand Up @@ -44,32 +40,15 @@ def __init__(
children += (icon,)
super().__init__(*children, **attributes)

@staticmethod
def fromaction(action, **kwargs):
warnings.warn(
"Button.fromaction is going to be deprecated in the future. Try to use bread.utils.links.Link where possible"
)
buttonargs = {
"icon": action.iconname,
"notext": not action.label,
}
if isinstance(action, Link):
buttonargs["onclick"] = hg.F(
lambda c: f"document.location = '{hg.resolve_lazy(action.href, c)}'"
)
else:
buttonargs["onclick"] = action.js
buttonargs.update(kwargs)
return Button(*([action.label] if action.label else []), **buttonargs)

@staticmethod
def fromlink(link, **kwargs):
buttonargs = {
"icon": link.iconname,
"notext": not link.label,
}
return Button(
*([link.label] if link.label else []), **{**buttonargs, **kwargs}
*([link.label] if link.label else []),
**{**buttonargs, **link.attributes, **kwargs},
).as_href(link.href)

def as_href(self, href):
Expand Down
Loading

0 comments on commit 4b0e0fe

Please sign in to comment.