Skip to content

Commit

Permalink
updated get workflow method and moved to view class
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Stippel authored and santonelli committed Oct 18, 2018
1 parent 86c17d9 commit 8ec6441
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 35 deletions.
32 changes: 26 additions & 6 deletions src/collective/sidebar/browser/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from collective.sidebar.utils import crop
from collective.sidebar.utils import get_translated
from collective.sidebar.utils import get_user
from collective.sidebar.utils import get_workflow_data
from plone import api
from plone.app.layout.viewlets.common import ViewletBase
from Products.CMFCore.interfaces import IFolderish
Expand Down Expand Up @@ -184,11 +183,32 @@ def get_folder_contents_url(self):
else:
return parent_url

def get_workflow(self):
"""
Return options for the workflow.
"""
return get_workflow_data(self.context)
def get_workflow_data(self):
"""
Return the workflow data for the context.
"""
portal_workflow = api.portal.get_tool('portal_workflow')
transitions = portal_workflow.getTransitionsFor(self.context)
result = {
'state': {
'name': '',
'color': 'sidebar-blue',
},
'transitions': [],
}
if transitions:
# Get the current state
state = api.content.get_state(self.context, None)
# Set a color for the state
if state == 'private':
result['state']['color'] = 'sidebar-red'
elif state == 'pending':
result['state']['color'] = 'sidebar-yellow'
elif state == 'visible':
result['state']['color'] = 'sidebar-purple'
result['state']['name'] = get_translated(state, self)
result['transitions'] = transitions
return result


class CoverViewlet(SidebarViewlet):
Expand Down
2 changes: 1 addition & 1 deletion src/collective/sidebar/browser/static/cover.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#portal-navigation-cover {
background: @black;
background: @sidebar-black;
height: 100%;
left: 0;
opacity: 0;
Expand Down
43 changes: 40 additions & 3 deletions src/collective/sidebar/browser/static/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,46 @@
@screen-lg-min: 1200px;

// Default Colors
@black: #2F3334;
@grey: #EBECEF;
@white: #FAFAFA;
@sidebar-black: #2F3334;
@sidebar-blue: #42A5F5;
@sidebar-green: #66BB6A;
@sidebar-grey: #EBECEF;
@sidebar-purple: #7B1FA2;
@sidebar-red: #F44336;
@sidebar-white: #FAFAFA;
@sidebar-yellow: #FDD835;

.sidebar-black {
color: @sidebar-black;
}

.sidebar-blue {
color: @sidebar-blue;
}

.sidebar-green {
color: @sidebar-green;
}

.sidebar-grey {
color: @sidebar-grey;
}

.sidebar-purple {
color: @sidebar-purple;
}

.sidebar-red {
color: @sidebar-red;
}

.sidebar-white {
color: @sidebar-white;
}

.sidebar-yellow {
color: @sidebar-yellow;
}

/* Imports */
@import './cover.less';
Expand Down
4 changes: 2 additions & 2 deletions src/collective/sidebar/browser/static/sidebar.less
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}

.menu {
background-color: @white;
background-color: @sidebar-white;
height: 100%;
overflow-x: hidden;
overflow-y: scroll;
Expand All @@ -54,7 +54,7 @@
a:focus,
a:active,
a:visited {
color: @black;
color: @sidebar-black;
display: block;
font-weight: 400;
margin-bottom: 15px;
Expand Down
8 changes: 4 additions & 4 deletions src/collective/sidebar/browser/templates/sidebar.pt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<!-- Workflow -->

<div class="menu-section"
tal:define="data view/get_workflow;
tal:define="data view/get_workflow_data;
absolute_url context/absolute_url;
content_status_modify python:absolute_url + '/content_status_modify';
state python:data['state'];
Expand All @@ -66,12 +66,12 @@
</a>

<a href="#">
<span class="menu-item-icon glyphicon glyphicon-record"></span> <span class="menu-item-title">${state/title}</span>
<span class="menu-item-icon glyphicon glyphicon-record ${state/color}"></span> <span class="menu-item-title">${state/name/title}</span>
</a>

<tal:repeat tal:repeat="transition transitions">
<a href="${content_status_modify}?workflow_action=${transition}${token_arg}">
<span class="menu-item-icon glyphicon glyphicon-transfer"></span> <span class="menu-item-title">${transition/title}</span>
<a href="${content_status_modify}?workflow_action=${transition/id}${token_arg}" title="${transition/title}">
<span class="menu-item-icon glyphicon glyphicon-transfer"></span> <span class="menu-item-title">${transition/name}</span>
</a>
</tal:repeat>

Expand Down
19 changes: 0 additions & 19 deletions src/collective/sidebar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,3 @@ def get_user():
user_id = user.id
user_dir = '/users/{0}'.format(user_id)
return user, user_id, user_dir


def get_workflow_data(context):
"""
Return the workflow data for the context.
"""
portal_workflow = api.portal.get_tool('portal_workflow')
workflows = portal_workflow.getWorkflowsFor(context)
result = {
'state': '',
'transitions': list(),
}
if workflows:
workflow = workflows[0]
state = api.content.get_state(context, None)
transitions = getattr(workflow.states, state).transitions
result['state'] = state
result['transitions'] = transitions
return result

0 comments on commit 8ec6441

Please sign in to comment.