Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard all/mine filters #467

Merged
merged 14 commits into from
Dec 16, 2017
Merged

Conversation

Espurna
Copy link

@Espurna Espurna commented Dec 12, 2017

Description of the issue/feature this PR addresses

The ability to change panel dashboards depending on assignation.

Current behavior before PR

There is no way to update dashboard panels accordingly to user property.

Desired behavior after PR is merged

A selection list with the values «All» and «Mine» will be added above each section of the Dashboard. The panels and information within each panel will change according to the option selected: for example, if the user selects «Mine», the panel with the summary of worksheets and worksheets statuses will only take into account the worksheets to which the user is assigned.

This feature can be activated/deactivated in bika setup.

selection_028

selection_030

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@xispa xispa self-requested a review December 13, 2017 16:36
Copy link
Member

@xispa xispa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove the option "DashboardAllMine" from setup and always render the "All/Mine" filter. Note also the following error is rised when the cookie is set for the first time:

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module bika.lims.browser.dashboard.dashboard, line 50, in __call__
  Module json, line 338, in loads
  Module json.decoder, line 366, in decode
TypeError: expected string or buffer

self.request.response.redirect(self.portal_url + "/bika-frontpage")
else:
self._init_date_range()
self.dashboard_cookie = get_strings(
json.loads(self.check_dashboard_cookie()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This json.loadswill fail if self.check_dashboard_cookie() returns None (if 'all/mine' filter is disabled) or if the value is not in json format (note this happens when the cookie is created for the first time in self.check_dashboard_cookie(), L74).

@@ -130,6 +198,24 @@ def get_sections(self):
self.get_worksheets_section()]
return sections

def is_filter_enable(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the creation of a function to just only retrieve the setting value from bika_setup is not worth.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, I would omit this is_filter_enable() and always display the "Mine/All" selection list. See comment https://github.com/senaite/bika.lims/pull/467/files#diff-0dde5125b635d6fb55f5372798dae571R550

def get_filter_options(self):
"""
Returns whether the dashboard filter is enabled.
:return: Boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment does not fit with the value the function does/returns

tofrontpage = 'Manager' not in roles and 'LabManager' not in roles

if tofrontpage == True:
if tofrontpage:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better if tofrontpage is True:

Copy link
Author

@Espurna Espurna Dec 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cookie_criteria = self.dashboard_cookie.get(section_name)
if cookie_criteria == 'mine':
query['Creator'] = self.member.getId()
return query
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return is not needed. To be consistent with your previous conditional, you could do the other way round:

if cookie_criteria != 'mine':
    return query
query['Creator'] = self.member.getId()
return query

"statuses will only take into account the worksheets to which"
" the user is assigned.")
),
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say there is no need to add an option in bika_setup, rather always render the 'All/Mine' selection list.

:return: a dictionary or None
"""
# Check setup configuration
if not self.is_filter_enable():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would omit this is_filter_enable() and always display the "Mine/All" selection list. See comment https://github.com/senaite/bika.lims/pull/467/files#diff-0dde5125b635d6fb55f5372798dae571R550

<h2 tal:content="section/title" class='dashboard-section-title'></h2>
<div>
<h2 tal:content="section/title" class='dashboard-section-title'></h2>
<tal:dashboard_filters condition="python: view.is_filter_enable()">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would omit this is_filter_enable() and always display the "Mine/All" selection list. See comment https://github.com/senaite/bika.lims/pull/467/files#diff-0dde5125b635d6fb55f5372798dae571R550

response = request.RESPONSE

# Voiding our special cookie on logout
response.setCookie(DASHBOARD_FILTER_COOKIE, None, path='/', max_age=0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?. I would expect to see the dashboard filtered as I left it some days ago.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just following what we do with other cookies

json.dumps(cookie_raw),
quoted=False,
path='/')
return cookie_raw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return is not required

@xispa xispa merged commit 39ff71b into senaite:master Dec 16, 2017
@Espurna Espurna deleted the task/424-dashboard-all-mine branch January 3, 2018 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants