-
Notifications
You must be signed in to change notification settings - Fork 0
Sb setting functionality #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sbagg
wants to merge
5
commits into
main
Choose a base branch
from
sb-setting-functionality
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
app/client/src/elements/pages/ucdlib-iam-page-user-settings.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); |
41 changes: 41 additions & 0 deletions
41
app/client/src/elements/pages/ucdlib-iam-page-user-settings.tpl.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { html } from 'lit'; | ||
|
|
||
| /** | ||
| * @description Main render function for this element | ||
| * @returns {TemplateResult} | ||
| */ | ||
| export function render() { | ||
| return html` | ||
| <form @submit=${this._onEditSubmit}> | ||
| <div class="l-container"> | ||
| <div class="l-shrink panel o-box"> | ||
| <h2 class='heading--underline'>RT Functionality</h2> | ||
| <fieldset class="checkbox"> | ||
| <ul class="list--reset"> | ||
| <li> | ||
| <input id="direct-reports" | ||
| name="direct-reports" | ||
| type="checkbox" | ||
| ?disabled=${this.updateInProgress} | ||
| ?checked=${this.enableDirectReportNotification} | ||
| @change=${this.handleDirectReportChange}> | ||
| <label for="direct-reports">All Direct Reports Notification | ||
| <abbr title=${this.ccReportsToolTip}>*</abbr> | ||
| </label> | ||
| </li> | ||
| </ul> | ||
| </fieldset> | ||
|
|
||
|
|
||
| <button | ||
| class='btn btn--primary' | ||
| ?disabled=${this.updateInProgress || this.noChange} | ||
| type='submit'> | ||
| <span ?hidden=${!this.updateInProgress} class='u-space-mr--small'><i class='fas fa-circle-notch fa-spin'></i></span> | ||
| <span>Update</span> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </form> | ||
|
|
||
| `;} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| CREATE TABLE metadata ( | ||
| metadata_id SERIAL PRIMARY KEY, | ||
| metadata_key varchar(50) NOT NULL, | ||
| metadata_value jsonb, | ||
| employee_id integer REFERENCES employees (id) | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.