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>
<br />
<div id="users-accordion">
% for user in person.users:
<b-collapse class="panel" <div v-if="users.length">
## TODO: what's up with aria-id here?
## aria-id="contentIdForA11y2"
>
<div <p>{{ person.display_name }} is associated with <strong>{{ users.length }}</strong> user account(s)</p>
slot="trigger" <br />
class="panel-heading" <div id="users-accordion">
role="button"
## TODO: what's up with aria-id here?
## aria-controls="contentIdForA11y2"
>
<strong>${user.username}</strong>
</div>
<div class="panel-block"> <b-collapse class="panel"
v-for="user in users"
:key="user.uuid">
<div style="display: flex; justify-content: space-between; width: 100%;"> <div slot="trigger"
class="panel-heading"
role="button">
<strong>{{ user.username }}</strong>
</div>
<div> <div class="panel-block">
<div style="display: flex; justify-content: space-between; width: 100%;">
<div class="field-wrapper id">
<div class="field-row">
<label>Username</label>
<div class="field">
${user.username}
</div>
</div>
</div>
<div>
<div class="field-wrapper id">
<div class="field-row">
<label>Username</label>
<div class="field">
{{ user.username }}
</div> </div>
<div>
% if request.has_perm('users.view'):
${h.link_to("View User", url('users.view', uuid=user.uuid), class_='button')}
% endif
</div>
</div> </div>
</div> </div>
</b-collapse> </div>
% endfor
</div>
% else: <div>
<p>${person} has never been a user.</p> % if request.has_perm('users.view'):
% endif <b-button tag="a" :href="user.view_url">
View User
</b-button>
% endif
</div>
</div>
</div>
</b-collapse>
</div>
</div>
<div v-if="!users.length">
<p>{{ person.display_name }} has never been a user.</p>
</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