Allow customization for Customers tab of Profile view

more tabs to come, this was all i needed for now
This commit is contained in:
Lance Edgar 2020-03-17 12:28:13 -05:00
parent 907a356bea
commit 60157abd46
2 changed files with 112 additions and 109 deletions

View file

@ -9,6 +9,86 @@
${self.page_content()}
</%def>
<%def name="render_customer_tab()">
<b-tab-item label="Customer" icon-pack="fas" :icon="customers.length ? 'check' : null">
<div v-if="customers.length">
<div style="display: flex; justify-content: space-between;">
<p>{{ person.fullName }} is associated with <strong>{{ customers.length }}</strong> customer account(s)</p>
</div>
<br />
<b-collapse v-for="customer in customers"
:key="customer.uuid"
class="panel"
:open="customers.length == 1">
<div slot="trigger"
slot-scope="props"
class="panel-heading"
role="button">
<b-icon pack="fas"
icon="caret-right">
</b-icon>
<strong>#{{ customer.number }} {{ customer.name }}</strong>
</div>
<div class="panel-block">
<div style="display: flex; justify-content: space-between; width: 100%;">
<div style="flex-grow: 1;">
<b-field horizontal label="Number">
{{ customer.number }}
</b-field>
<b-field horizontal label="ID">
{{ customer.id }}
</b-field>
<b-field horizontal label="Name">
{{ customer.name }}
</b-field>
<b-field horizontal label="People">
<ul>
<li v-for="p in customer.people"
:key="p.uuid">
<a v-if="p.uuid != person.uuid"
:href="p.view_profile_url">
{{ p.display_name }}
</a>
<span v-if="p.uuid == person.uuid">
{{ p.display_name }}
</span>
</li>
</ul>
</b-field>
</div>
<div class="buttons" style="align-items: start;">
${self.render_customer_panel_buttons(customer)}
</div>
</div>
</div>
</b-collapse>
</div>
<div v-if="!customers.length">
<p>{{ person.fullName }} has never had a customer account.</p>
</div>
</b-tab-item> <!-- Customer -->
</%def>
<%def name="render_customer_panel_buttons(customer)">
% if request.has_perm('customers.view'):
<b-button tag="a" :href="customer.view_url">
View Customer
</b-button>
% endif
</%def>
<%def name="render_this_page_template()">
${parent.render_this_page_template()}
@ -148,115 +228,7 @@
</div>
</b-tab-item><!-- Personal -->
<b-tab-item label="Customer" ${'icon="check" icon-pack="fas"' if person.customers else ''|n}>
% if person.customers:
<p>${person} is associated with <strong>${len(person.customers)}</strong> customer account(s)</p>
<br />
<div id="customers-accordion">
% for customer in person.customers:
<b-collapse class="panel"
## TODO: what's up with aria-id here?
## aria-id="contentIdForA11y2"
>
<div
slot="trigger"
class="panel-heading"
role="button"
## TODO: what's up with aria-id here?
## aria-controls="contentIdForA11y2"
>
<strong>${customer.id} - ${customer.name}</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>ID</label>
<div class="field">
${customer.id or ''}
</div>
</div>
</div>
<div class="field-wrapper name">
<div class="field-row">
<label>Name</label>
<div class="field">
${customer.name}
</div>
</div>
</div>
% if customer.phones:
% for phone in customer.phones:
<div class="field-wrapper">
<div class="field-row">
<label>Phone Number</label>
<div class="field">
${phone.number} (type: ${phone.type})
</div>
</div>
</div>
% endfor
% else:
<div class="field-wrapper">
<div class="field-row">
<label>Phone Number</label>
<div class="field">
(none on file)
</div>
</div>
</div>
% endif
% if customer.emails:
% for email in customer.emails:
<div class="field-wrapper">
<div class="field-row">
<label>Email Address</label>
<div class="field">
${email.address} (type: ${email.type})
</div>
</div>
</div>
% endfor
% else:
<div class="field-wrapper">
<div class="field-row">
<label>Email Address</label>
<div class="field">
(none on file)
</div>
</div>
</div>
% endif
</div>
<div>
% if request.has_perm('customers.view'):
${h.link_to("View Customer", url('customers.view', uuid=customer.uuid), class_='button')}
% endif
</div>
</div>
</div>
</b-collapse>
% endfor
</div>
% else:
<p>${person} has never been a customer.</p>
% endif
</b-tab-item><!-- Customer -->
${self.render_customer_tab()}
<b-tab-item label="Employee" ${'icon="check" icon-pack="fas"' if employee else ''|n}>
@ -422,6 +394,8 @@
data() {
return {
activeTab: 0,
person: ${json.dumps(person_data)|n},
customers: ${json.dumps(customers_data)|n},
}
},
}

View file

@ -297,6 +297,8 @@ class PeopleView(MasterView):
'instance': person,
'instance_title': self.get_instance_title(person),
'today': localtime(self.rattail_config).date(),
'person_data': self.get_context_person(person),
'customers_data': self.get_context_customers(person),
'employee': employee,
'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,
@ -307,6 +309,33 @@ class PeopleView(MasterView):
template = 'view_profile_buefy' if use_buefy else 'view_profile'
return self.render_to_response(template, context)
def get_context_person(self, person):
return {
'uuid': person.uuid,
'first_name': person.first_name,
'last_name': person.last_name,
'display_name': person.display_name,
'view_url': self.get_action_url('view', person),
'view_profile_url': self.get_action_url('view_profile', person),
}
def get_context_customers(self, person):
data = []
for cp in person._customers:
customer = cp.customer
data.append({
'uuid': customer.uuid,
'ordinal': cp.ordinal,
'id': customer.id,
'number': customer.number,
'name': customer.name,
'view_url': self.request.route_url('customers.view',
uuid=customer.uuid),
'people': [self.get_context_person(p)
for p in customer.people],
})
return data
def get_context_employee_history(self, employee):
data = []
if employee: