Add users context data for profile view
instead of using server-side data/logic for users tab
This commit is contained in:
parent
c1f72e0d11
commit
bf1726a52b
|
@ -1038,61 +1038,56 @@
|
|||
<%def name="render_user_tab()">
|
||||
<b-tab-item label="User"
|
||||
value="user"
|
||||
${'icon="check" icon-pack="fas"' if person.users else ''|n}>
|
||||
% if person.users:
|
||||
<p>${person} is associated with <strong>${len(person.users)}</strong> user account(s)</p>
|
||||
icon-pack="fas"
|
||||
:icon="users.length ? 'check' : null">
|
||||
|
||||
<div v-if="users.length">
|
||||
|
||||
<p>{{ person.display_name }} is associated with <strong>{{ users.length }}</strong> user account(s)</p>
|
||||
<br />
|
||||
<div id="users-accordion">
|
||||
% for user in person.users:
|
||||
|
||||
<b-collapse class="panel"
|
||||
## TODO: what's up with aria-id here?
|
||||
## aria-id="contentIdForA11y2"
|
||||
>
|
||||
v-for="user in users"
|
||||
:key="user.uuid">
|
||||
|
||||
<div
|
||||
slot="trigger"
|
||||
<div slot="trigger"
|
||||
class="panel-heading"
|
||||
role="button"
|
||||
## TODO: what's up with aria-id here?
|
||||
## aria-controls="contentIdForA11y2"
|
||||
>
|
||||
<strong>${user.username}</strong>
|
||||
role="button">
|
||||
<strong>{{ user.username }}</strong>
|
||||
</div>
|
||||
|
||||
<div class="panel-block">
|
||||
|
||||
<div style="display: flex; justify-content: space-between; width: 100%;">
|
||||
|
||||
<div>
|
||||
|
||||
<div class="field-wrapper id">
|
||||
<div class="field-row">
|
||||
<label>Username</label>
|
||||
<div class="field">
|
||||
${user.username}
|
||||
{{ user.username }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
% if request.has_perm('users.view'):
|
||||
${h.link_to("View User", url('users.view', uuid=user.uuid), class_='button')}
|
||||
<b-button tag="a" :href="user.view_url">
|
||||
View User
|
||||
</b-button>
|
||||
% endif
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</b-collapse>
|
||||
% endfor
|
||||
</div>
|
||||
</div>
|
||||
|
||||
% else:
|
||||
<p>${person} has never been a user.</p>
|
||||
% endif
|
||||
<div v-if="!users.length">
|
||||
<p>{{ person.display_name }} has never been a user.</p>
|
||||
</div>
|
||||
</b-tab-item><!-- User -->
|
||||
</%def>
|
||||
|
||||
|
@ -1791,6 +1786,7 @@
|
|||
members: ${json.dumps(members_data)|n},
|
||||
employee: ${json.dumps(employee_data)|n},
|
||||
employeeHistory: ${json.dumps(employee_history_data)|n},
|
||||
users: ${json.dumps(users_data)|n},
|
||||
phoneTypeOptions: ${json.dumps(phone_type_options)|n},
|
||||
emailTypeOptions: ${json.dumps(email_type_options)|n},
|
||||
maxLengths: ${json.dumps(max_lengths)|n},
|
||||
|
|
|
@ -459,6 +459,7 @@ class PersonView(MasterView):
|
|||
'employee_view_url': self.request.route_url('employees.view', uuid=employee.uuid) if employee else None,
|
||||
'employee_history': employee.get_current_history() if employee else None,
|
||||
'employee_history_data': self.get_context_employee_history(employee),
|
||||
'users_data': self.get_context_users(person),
|
||||
'dynamic_content_title': self.get_context_content_title(person),
|
||||
}
|
||||
|
||||
|
@ -720,6 +721,23 @@ class PersonView(MasterView):
|
|||
})
|
||||
return data
|
||||
|
||||
def get_context_users(self, person):
|
||||
data = []
|
||||
users = person.users
|
||||
for user in users:
|
||||
data.append(self.get_context_user(user))
|
||||
return data
|
||||
|
||||
def get_context_user(self, user):
|
||||
app = self.get_rattail_app()
|
||||
return {
|
||||
'uuid': user.uuid,
|
||||
'username': user.username,
|
||||
'display_name': user.display_name,
|
||||
'email_address': app.get_contact_email_address(user),
|
||||
'view_url': self.request.route_url('users.view', uuid=user.uuid),
|
||||
}
|
||||
|
||||
def ensure_customer(self, person):
|
||||
"""
|
||||
Return the `Customer` record for the given person, establishing it
|
||||
|
|
Loading…
Reference in a new issue