From e7fb1559f5472789f29b49e88aa7f39780ed7b8a Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 5 Oct 2021 08:25:33 -0400 Subject: [PATCH] Refactor the Employee tab of profile view, per better patterns learned some things from the Personal tab overhaul --- .../templates/people/view_profile_buefy.mako | 380 +++++++----------- tailbone/views/people.py | 6 +- 2 files changed, 161 insertions(+), 225 deletions(-) diff --git a/tailbone/templates/people/view_profile_buefy.mako b/tailbone/templates/people/view_profile_buefy.mako index 114682bd..9ef956a9 100644 --- a/tailbone/templates/people/view_profile_buefy.mako +++ b/tailbone/templates/people/view_profile_buefy.mako @@ -452,20 +452,19 @@ +<%def name="render_personal_tab_cards()"> + ${self.render_personal_name_card()} + ${self.render_personal_address_card()} + ${self.render_personal_phone_card()} + ${self.render_personal_email_card()} + + <%def name="render_personal_tab_template()"> @@ -1362,58 +1365,37 @@ -<%def name="set_employee_data()"> - - - <%def name="declare_employee_tab_vars()"> @@ -1633,8 +1560,8 @@ customers: ${json.dumps(customers_data)|n}, member: null, // TODO members: ${json.dumps(members_data)|n}, - employee: EmployeeData, - employeeHistory: EmployeeHistoryData, + employee: ${json.dumps(employee_data)|n}, + employeeHistory: ${json.dumps(employee_history_data)|n}, phoneTypeOptions: ${json.dumps(phone_type_options)|n}, emailTypeOptions: ${json.dumps(email_type_options)|n}, maxLengths: ${json.dumps(max_lengths)|n}, @@ -1647,6 +1574,12 @@ personUpdated(person) { this.person = person }, + employeeUpdated(employee) { + this.employee = employee + }, + employeeHistoryUpdated(employeeHistory) { + this.employeeHistory = employeeHistory + }, changeContentTitle(newTitle) { this.$emit('change-content-title', newTitle) }, @@ -1722,7 +1655,6 @@ <%def name="make_this_page_component()"> ${parent.make_this_page_component()} ${self.make_personal_tab_component()} - ${self.set_employee_data()} ${self.make_employee_tab_component()} ${self.make_profile_info_component()} diff --git a/tailbone/views/people.py b/tailbone/views/people.py index 0967147d..615cb238 100644 --- a/tailbone/views/people.py +++ b/tailbone/views/people.py @@ -441,6 +441,7 @@ class PersonView(MasterView): 'customers_data': self.get_context_customers(person), 'members_data': self.get_context_members(person), 'employee': employee, + 'employee_data': self.get_context_employee(employee) if employee else {}, '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), @@ -581,6 +582,7 @@ class PersonView(MasterView): app = self.get_rattail_app() handler = app.get_employment_handler() context = handler.get_context_employee(employee) + context['view_url'] = self.request.route_url('employees.view', uuid=employee.uuid) return context def get_context_employee_history(self, employee): @@ -884,6 +886,7 @@ class PersonView(MasterView): start_date = datetime.datetime.strptime(data['start_date'], '%Y-%m-%d').date() employee = handler.begin_employment(person, start_date, employee_id=data['id']) + self.Session.flush() return self.profile_start_employee_result(employee, start_date) def profile_start_employee_result(self, employee, start_date): @@ -912,6 +915,7 @@ class PersonView(MasterView): employee = handler.get_employee(person) handler.end_employment(employee, end_date, revoke_access=data.get('revoke_access')) + self.Session.flush() return self.profile_end_employee_result(employee, end_date) def profile_end_employee_result(self, employee, end_date): @@ -948,9 +952,9 @@ class PersonView(MasterView): self.Session.flush() current_history = employee.get_current_history() - return { 'success': True, + 'employee': self.get_context_employee(employee), 'start_date': six.text_type(current_history.start_date), 'end_date': six.text_type(current_history.end_date or ''), 'employee_history_data': self.get_context_employee_history(employee),