Add options for grid results to link straight to Profile view
probably should have done this a long time ago...
This commit is contained in:
parent
f1a8b8df7f
commit
0d52d554e7
8 changed files with 210 additions and 0 deletions
|
@ -45,6 +45,7 @@ class EmployeeView(MasterView):
|
|||
touchable = True
|
||||
supports_autocomplete = True
|
||||
results_downloadable = True
|
||||
configurable = True
|
||||
|
||||
labels = {
|
||||
'id': "ID",
|
||||
|
@ -143,9 +144,41 @@ class EmployeeView(MasterView):
|
|||
|
||||
g.set_label('email', "Email Address")
|
||||
|
||||
if (self.request.has_perm('people.view_profile')
|
||||
and self.should_link_straight_to_profile()):
|
||||
|
||||
# add View Raw action
|
||||
url = lambda r, i: self.request.route_url(
|
||||
f'{route_prefix}.view', **self.get_action_route_kwargs(r))
|
||||
# nb. insert to slot 1, just after normal View action
|
||||
g.main_actions.insert(1, self.make_action(
|
||||
'view_raw', url=url, icon='eye'))
|
||||
|
||||
g.set_link('first_name')
|
||||
g.set_link('last_name')
|
||||
|
||||
def default_view_url(self):
|
||||
if (self.request.has_perm('people.view_profile')
|
||||
and self.should_link_straight_to_profile()):
|
||||
app = self.get_rattail_app()
|
||||
|
||||
def url(employee, i):
|
||||
person = app.get_person(employee)
|
||||
if person:
|
||||
return self.request.route_url(
|
||||
'people.view_profile', uuid=person.uuid,
|
||||
_anchor='employee')
|
||||
return self.get_action_url('view', employee)
|
||||
|
||||
return url
|
||||
|
||||
return super().default_view_url()
|
||||
|
||||
def should_link_straight_to_profile(self):
|
||||
return self.rattail_config.getbool('rattail',
|
||||
'employees.straight_to_profile',
|
||||
default=False)
|
||||
|
||||
def query(self, session):
|
||||
query = super(EmployeeView, self).query(session)
|
||||
query = query.join(model.Person)
|
||||
|
@ -313,6 +346,15 @@ class EmployeeView(MasterView):
|
|||
(model.EmployeeDepartment, 'employee_uuid'),
|
||||
]
|
||||
|
||||
def configure_get_simple_settings(self):
|
||||
return [
|
||||
|
||||
# General
|
||||
{'section': 'rattail',
|
||||
'option': 'employees.straight_to_profile',
|
||||
'type': bool},
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
cls._defaults(config)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue