Add users context data for profile view

instead of using server-side data/logic for users tab
This commit is contained in:
Lance Edgar 2023-06-16 17:04:39 -05:00
parent c1f72e0d11
commit bf1726a52b
2 changed files with 59 additions and 45 deletions

View file

@ -1038,61 +1038,56 @@
<%def name="render_user_tab()"> <%def name="render_user_tab()">
<b-tab-item label="User" <b-tab-item label="User"
value="user" value="user"
${'icon="check" icon-pack="fas"' if person.users else ''|n}> icon-pack="fas"
% if person.users: :icon="users.length ? 'check' : null">
<p>${person} is associated with <strong>${len(person.users)}</strong> user account(s)</p>
<div v-if="users.length">
<p>{{ person.display_name }} is associated with <strong>{{ users.length }}</strong> user account(s)</p>
<br /> <br />
<div id="users-accordion"> <div id="users-accordion">
% for user in person.users:
<b-collapse class="panel" <b-collapse class="panel"
## TODO: what's up with aria-id here? v-for="user in users"
## aria-id="contentIdForA11y2" :key="user.uuid">
>
<div <div slot="trigger"
slot="trigger"
class="panel-heading" class="panel-heading"
role="button" role="button">
## TODO: what's up with aria-id here? <strong>{{ user.username }}</strong>
## aria-controls="contentIdForA11y2"
>
<strong>${user.username}</strong>
</div> </div>
<div class="panel-block"> <div class="panel-block">
<div style="display: flex; justify-content: space-between; width: 100%;"> <div style="display: flex; justify-content: space-between; width: 100%;">
<div> <div>
<div class="field-wrapper id"> <div class="field-wrapper id">
<div class="field-row"> <div class="field-row">
<label>Username</label> <label>Username</label>
<div class="field"> <div class="field">
${user.username} {{ user.username }}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div> <div>
% if request.has_perm('users.view'): % 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 % endif
</div> </div>
</div> </div>
</div> </div>
</b-collapse> </b-collapse>
% endfor </div>
</div> </div>
% else: <div v-if="!users.length">
<p>${person} has never been a user.</p> <p>{{ person.display_name }} has never been a user.</p>
% endif </div>
</b-tab-item><!-- User --> </b-tab-item><!-- User -->
</%def> </%def>
@ -1791,6 +1786,7 @@
members: ${json.dumps(members_data)|n}, members: ${json.dumps(members_data)|n},
employee: ${json.dumps(employee_data)|n}, employee: ${json.dumps(employee_data)|n},
employeeHistory: ${json.dumps(employee_history_data)|n}, employeeHistory: ${json.dumps(employee_history_data)|n},
users: ${json.dumps(users_data)|n},
phoneTypeOptions: ${json.dumps(phone_type_options)|n}, phoneTypeOptions: ${json.dumps(phone_type_options)|n},
emailTypeOptions: ${json.dumps(email_type_options)|n}, emailTypeOptions: ${json.dumps(email_type_options)|n},
maxLengths: ${json.dumps(max_lengths)|n}, maxLengths: ${json.dumps(max_lengths)|n},

View file

@ -459,6 +459,7 @@ class PersonView(MasterView):
'employee_view_url': self.request.route_url('employees.view', uuid=employee.uuid) if employee else None, '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': employee.get_current_history() if employee else None,
'employee_history_data': self.get_context_employee_history(employee), '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), 'dynamic_content_title': self.get_context_content_title(person),
} }
@ -720,6 +721,23 @@ class PersonView(MasterView):
}) })
return data 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): def ensure_customer(self, person):
""" """
Return the `Customer` record for the given person, establishing it Return the `Customer` record for the given person, establishing it