diff --git a/app/api/employees.js b/app/api/employees.js index fb28f95..a497855 100644 --- a/app/api/employees.js +++ b/app/api/employees.js @@ -62,4 +62,67 @@ export default (api) => { return res.json(out); }); + +/** + * @description get the metadata for the employee + * - id: search by employee id +*/ + api.get(`/employees/:id/metadata`, async (req, res) => { + + // query for employee + if ( !req.params.id ) { + return res.status(400).json({ + error: 'Missing employee identifier' + }); + } + + const id_type = req.query.idType; + + let person = await UcdlibEmployees.getById(req.params.id, id_type); + let employeeId = person.res.rows[0].id; + + const out = { + total: 0, + results: [], + } + + const r = await UcdlibEmployees.getById(employeeId, "id", {includeMetadata:true}) + + out.total = r.res.rowCount; + out.results = r.res.rows; + + return res.json(out); + + }); + + /** + * @description post the updated metadata for the employee + * - id: search by employee id + */ + api.post(`/employees/:id/metadata/`, async (req, res) => { + + // query for employee + if ( !req.params.id ) { + return res.status(400).json({ + error: 'Missing employee identifier' + }); + } + + const out = { + total: 0, + results: [], + } + + const id = req.body.id; + const metadataValue = req.body.metadataValue; + + + const results = await UcdlibEmployees.updateMetadata(id, metadataValue) + + out.total = results.res.rowCount; + out.results = results.res.rows; + + return res.json(out); + + }); } diff --git a/app/client/src/elements/pages/bundles/index.js b/app/client/src/elements/pages/bundles/index.js index 334b92a..3fa9811 100644 --- a/app/client/src/elements/pages/bundles/index.js +++ b/app/client/src/elements/pages/bundles/index.js @@ -1,7 +1,7 @@ const defs = { main : [ 'home', 'onboarding', 'separation', 'separation-new', 'separation-single', 'onboarding-new', - 'onboarding-single', 'permissions-single', 'permissions' + 'onboarding-single', 'permissions-single', 'settings', 'permissions' ], tools: ['patron', 'orgchart', 'tools'] }; diff --git a/app/client/src/elements/pages/bundles/main.js b/app/client/src/elements/pages/bundles/main.js index 67b0cc3..d1862f4 100644 --- a/app/client/src/elements/pages/bundles/main.js +++ b/app/client/src/elements/pages/bundles/main.js @@ -7,3 +7,4 @@ import "../ucdlib-iam-page-permissions-single"; import "../ucdlib-iam-page-separation"; import "../ucdlib-iam-page-separation-new"; import "../ucdlib-iam-page-separation-single"; +import "../ucdlib-iam-page-user-settings"; diff --git a/app/client/src/elements/pages/ucdlib-iam-page-orgchart.tpl.js b/app/client/src/elements/pages/ucdlib-iam-page-orgchart.tpl.js index 3f5cc38..c5be410 100644 --- a/app/client/src/elements/pages/ucdlib-iam-page-orgchart.tpl.js +++ b/app/client/src/elements/pages/ucdlib-iam-page-orgchart.tpl.js @@ -16,7 +16,7 @@ export function render() {

Upload the most recent csv for the organizational chart here. Make sure to use the format which includes headers and the required - columns:
(Lived Name, EE ID, Email, Notes, Department Name, Working Title, Appointment Type Code, Supervisor ID). + columns:
(Lived Name, External ID, Email, Notes, Department Name, Working Title, Appointment Type Code, External ID Reports To).

diff --git a/app/client/src/elements/pages/ucdlib-iam-page-user-settings.js b/app/client/src/elements/pages/ucdlib-iam-page-user-settings.js new file mode 100644 index 0000000..9d75692 --- /dev/null +++ b/app/client/src/elements/pages/ucdlib-iam-page-user-settings.js @@ -0,0 +1,160 @@ +import { LitElement } from 'lit'; +import {render} from "./ucdlib-iam-page-user-settings.tpl.js"; +import { LitCorkUtils, Mixin } from '@ucd-lib/cork-app-utils'; + + +/** + * @description Landing page for user settings + */ +export default class UcdlibIamPageUserSettings extends Mixin(LitElement) + .with(LitCorkUtils) { + + static get properties() { + return { + updateInProgress: {state: true}, + results: {type: Array} + }; + } + + constructor() { + super(); + this.render = render.bind(this); + this._injectModel('AppStateModel','AuthModel', 'EmployeeModel'); + this.token = null; + this.firstName = null; + this.lastName = null; + this.metadata = []; + this.updateList = []; + this.noChange = true; + this.enableDirectReportNotification = null; + this.initialDirectReportNotification = null; + } + + /** + * @description Disables the shadowdom + * @returns + */ + createRenderRoot() { + return this; + } + + + /* Add the check for the new user_setting enable flag */ + + /** + * @method handleDirectReportChange + * @description handle the checkbox changing direct report + * + * @param {Object} e + */ + handleDirectReportChange(e) { + + this.enableDirectReportNotification = e.target.checked; + this.noChange = this.initialDirectReportNotification === this.enableDirectReportNotification; + + this.requestUpdate(); + } + + + /** + * @method _onAppStateUpdate + * @description bound to AppStateModel app-state-update event + * + * @param {Object} e + */ + async _onAppStateUpdate(e) { + if ( e.page != this.id ) return; + this.AppStateModel.showLoaded(this.id); + + this.token = this.AuthModel.getToken().token || null; + this.firstName = this.token.given_name || null; + this.lastName = this.token.family_name || null; + this.iamId = this.token.iamId || null; + this.ccReportsToolTip = "By default, only DIRECT supervisors are CCed on their employee's RT tickets. Checking this box will ensure you are CCed on RT tickets submitted by anyone below you in your reporting line."; + + const r = await this.EmployeeModel.getMetadata(this.iamId, "iamId"); + + this.metadata = r.payload.results[0].metadata; + + this.currentDirectReportStatus(); + + /* More Metadata should be made into a new function */ + + } + + /** + * @method currentDirectReportStatus + * @description get the current Direct Report Status + */ + async currentDirectReportStatus(){ + let meta = this.metadata.find(m => m.metadataKey === "cc_notification"); + this.directReportsId = meta.metadataId; + if(typeof meta.metadataValue === 'string') { + meta = meta ? meta.metadataValue.toLowerCase() : false; + this.initialDirectReportNotification = meta === "true" ? true: false; + + } else { + meta = meta.metadataValue; + this.initialDirectReportNotification = meta; + } + this.enableDirectReportNotification = this.initialDirectReportNotification; + + this.requestUpdate(); + } + + /** + * @description Event handler for when the edit form is submitted + * @param {*} e - form submit event + * @returns + */ + async _onEditSubmit(e){ + e.preventDefault(); + + if ( this.updateInProgress ) return; + this.updateInProgress = true; + + + this.updateList.push({ + id: this.directReportsId, + metadataValue: this.enableDirectReportNotification + }); + + /* Add future object statements for metadata here */ + + let r = []; + + for(let element of this.updateList){ + let res = await this.EmployeeModel.updateMetadata(element, this.iamId); + r.push(res); + } + + const allLoaded = r.every(item => item.state === 'loaded'); + const hasIs400 = r.some(item => item.error?.payload?.is400 === true); + + + let successText = `${this.firstName} ${this.lastName}'s User Settings has been updated.`; + + if (allLoaded) { + this.AppStateModel.refresh(); + setTimeout(() => { + this.AppStateModel.showAlertBanner({message: successText, brandColor: 'quad'}); + }, 1000); + this.updateInProgress = false; + + } else { + if ( hasIs400) { + this.requestUpdate(); + this.AppStateModel.showAlertBanner({message: 'Error when updating the user settings. Form data needs fixing.', brandColor: 'double-decker'}); + this.logger.error('Error in form updating user settings', r); + } else { + this.AppStateModel.showAlertBanner({message: 'An unknown error occurred when updating your User Settings', brandColor: 'double-decker'}); + this.logger.error('Error updating user settings', r); + } + } + } + + + +} + +customElements.define('ucdlib-iam-page-user-settings', UcdlibIamPageUserSettings); \ No newline at end of file diff --git a/app/client/src/elements/pages/ucdlib-iam-page-user-settings.tpl.js b/app/client/src/elements/pages/ucdlib-iam-page-user-settings.tpl.js new file mode 100644 index 0000000..4979800 --- /dev/null +++ b/app/client/src/elements/pages/ucdlib-iam-page-user-settings.tpl.js @@ -0,0 +1,41 @@ +import { html } from 'lit'; + +/** + * @description Main render function for this element + * @returns {TemplateResult} + */ +export function render() { + return html` + +
+
+

RT Functionality

+
+
    +
  • + + +
  • +
+
+ + + +
+
+
+ +`;} \ No newline at end of file diff --git a/app/client/src/elements/ucdlib-iam-app.tpl.js b/app/client/src/elements/ucdlib-iam-app.tpl.js index 7bc1107..778eb6b 100644 --- a/app/client/src/elements/ucdlib-iam-app.tpl.js +++ b/app/client/src/elements/ucdlib-iam-app.tpl.js @@ -9,6 +9,7 @@ export function render() { Logout + User Settings