Commit 28c5e91e by GD-A-150752

Code-Review comments-added

parent 5acafeab
......@@ -90,6 +90,9 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
.subscribe(
(params: Params) => {
/**
* First condition identifies if the template is being created from workflow template
*/
if (this.templateCreationFromWorkflow()) {
this.messageTemplate.HiringTeam = this.adminPortalLayoutService.getHiringTeamID().ObjectID;
......@@ -101,11 +104,17 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
this.setInputListener();
this.showLoader = false;
/**
* Second condition identifies if the template is being updated from workflow template
*/
} else if (this.templateUpdateFromWorkflow() || (params.id && params.id !== '0')) {
this.editMode = true;
this.getMessageTemplateByID(this.templateUpdateFromWorkflow() ? this.objectID : params.id);
} else {
/**
* Third condition identifies if the template is being created within this component
*/
this.messageTemplate.HiringTeam = this.adminPortalLayoutService.getHiringTeamID().ObjectID;
if (this.messageTemplateTypes) {
......@@ -128,6 +137,10 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
);
}
/**
* Save button is visible only if selected template is created by the selected hiring team or
* if the template is in edit mode
*/
showSaveBtn(): boolean {
return this.messageTemplate && this.messageTemplate.ObjectID ?
(this.messageTemplate.HiringTeam === this.adminPortalLayoutService.getHiringTeamID().ObjectID ||
......@@ -147,6 +160,10 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
return false;
}
/**
* This function sets two types of input listeners, upon click and upon writing anything in the field.
* Whenever the event is triggered, it stores the current cursor position of that specific field.
*/
setInputListener(): void {
let editElement;
setTimeout(() => {
......@@ -185,6 +202,10 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
}, 0);
}
/**
* In Email template type, user may add anchor tag in editor.
* This function gets the Quill view child and inserts or updates its content as per placeholder selected.
*/
addAnchorText(show: boolean): void {
if (!show || this.linkText === '') {
......@@ -217,6 +238,10 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
this.contentLinkModal.hide();
}
/**
* When content of editor is updated using placeholder, it doesn't reflect value in the ngModel
* This function is called only once before saving the template to re-assign value of content in ngModel.
*/
assignContent(): void {
const editor = this.messageContentEditor.getQuill().container;
if (editor) {
......@@ -233,7 +258,7 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
this.contentPlaceholder = $event;
if (!this.contentPlaceholder || !this.contentPlaceholder.Value) {
if (!this.contentPlaceholder || !this.contentPlaceholder.Value || this.contentPlaceholder.Value === 'null') {
return;
}
......@@ -259,6 +284,9 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
this.resetSelect('contentPlaceholderOptions');
}
/**
* When a template is switched from Email to SMS type, plain text is shown in the textarea instead of rich HTML.
*/
showPlainText(HTMLTitle: string): string {
const temp = document.getElementById('showPlainText');
temp.innerHTML = HTMLTitle;
......@@ -268,6 +296,10 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
return title;
}
/**
* User may revert back to EMAIL from SMS, in this case, rich HTML content is preserved in a variable whenever
* SMS type is changed to EMAIL
*/
storeMessageContent($event): void {
if (!$event) {
......@@ -289,10 +321,10 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
if (this.ContentPlaceholderOptionsEnum) {
if (this.emailTemplateType()) {
this.contentPlaceholderOptions = this.ContentPlaceholderOptionsEnum.filter(option => option.ShowForContent ||
option.Value === '-');
option.Value === 'null');
} else {
this.contentPlaceholderOptions = this.ContentPlaceholderOptionsEnum
.filter(option => option.ShowForContent && !option.IsLink || option.Value === '-');
.filter(option => option.ShowForContent && !option.IsLink || option.Value === 'null');
}
}
......@@ -340,6 +372,8 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
this.templateTypeId =
this.messageTemplateTypes.find(elem => elem.Value === this.messageTemplate.TemplateType.Value).id;
this.showLoader = false;
// Significance of setTimeout is to call the function at the end of browser stack
// in order to make sure that UI has been updated prior to calling its view-child
setTimeout(() => this.setInputListener(), 0);
},
error => {
......@@ -361,7 +395,7 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
}
cancelClicked(): void {
// If new message template is being created from 'EditWorkFlowComponent'
// If new message template is being created from 'EditWorkFlowComponent', don't show listing.
if (this.templateCreationFromWorkflow() || this.templateUpdateFromWorkflow()) {
this.closeModal.emit(-1);
} else {
......@@ -389,7 +423,7 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
if (data.created[id]) {
id = data.created[id];
}
// emitting value to component, in this case 'Edit-Workflow-Template'
this.closeModal.emit(id);
} else if (this.templateUpdateFromWorkflow()) {
this.closeModal.emit(this.messageTemplate.ObjectID);
......@@ -411,16 +445,17 @@ export class EditMessageTemplateComponent extends BaseComponent implements OnIni
this.subscriptions.push(this.appService.getPlaceholderOptionsEnum()
.subscribe(options => {
this.ContentPlaceholderOptionsEnum = options;
// Changed null value to 'null' in order to use it in select-2 component which takes value as a string
this.ContentPlaceholderOptionsEnum.filter(option => option.Value === null)
.map(val => {
val.Value = '-';
val.Value = 'null';
return val;
});
this.contentPlaceholderOptions =
this.ContentPlaceholderOptionsEnum.filter(option => option.ShowForContent || option.Value === '-');
this.ContentPlaceholderOptionsEnum.filter(option => option.ShowForContent || option.Value === 'null');
this.subjectPlaceholderOptions =
this.ContentPlaceholderOptionsEnum.filter(option => option.ShowForSubject || option.Value === '-');
this.ContentPlaceholderOptionsEnum.filter(option => option.ShowForSubject || option.Value === 'null');
})
);
}
......
......@@ -101,13 +101,15 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
this.stageTypes = response[0];
this.stepTypeOptions = response[1];
// Changed null value to 'null' in order to use it in select-2 component which takes value as a string
this.stepTypeOptions.filter(type => type.Value === null)
.map(val => {
val.Value = '-';
val.Value = 'null';
return val;
});
// Diversity is shown only is enabled by selected hiring team
if (!this.adminPortalLayoutService.getHiringTeamID().HasDiversity) {
this.stepTypeOptions = this.stepTypeOptions.filter(type => type.Value !== 'DIVERSITY');
}
......@@ -131,6 +133,9 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
this.getMessageTemplates();
}
/**
* When a new template is created, following default values are to assigned.
*/
setDefaults(): void {
this.workflow.TemplateName = 'Workflow Template';
this.workflow.LandingButtonText = 'Apply Now';
......@@ -144,6 +149,9 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
this.workflow.HiringTeam = this.adminPortalLayoutService.getHiringTeamID().ObjectID;
}
/**
* Other than generic, add pre-stage and post-stage
*/
addDefaultStages(): void {
this.workflow.WorkFlowStages = [];
this.stageTypes.forEach(stage => {
......@@ -178,12 +186,16 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
return !stage.StageType.IsPostStage && !stage.StageType.IsPreStage;
}
/**
* Instead of filtering stages on UI, every time a single change is made.
* This function creates three separate arrays for three types of stages (pre-stage, generic-stage, post-stage)
*/
filterStages(): void {
this.preStages = this.filteredStages(true, false);
this.preStages = this.workflow.WorkFlowStages.filter(stage => stage.StageType.IsPreStage);
this.genericStages = this.filteredStages(false, false);
this.genericStages = this.workflow.WorkFlowStages.filter(stage => !stage.StageType.IsPreStage && !stage.StageType.IsPostStage);
this.postStages = this.filteredStages(false, true);
this.postStages = this.workflow.WorkFlowStages.filter(stage => stage.StageType.IsPostStage);
}
showSaveBtn(): boolean {
......@@ -208,16 +220,6 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
return (this.editField[id] === undefined || this.editField[id] === false);
}
filteredStages(isPreStage: boolean, isPostStage: boolean): Array<WorkflowStageModel> {
if (isPreStage) {
return this.workflow.WorkFlowStages.filter(stage => stage.StageType.IsPreStage);
} else if (isPostStage) {
return this.workflow.WorkFlowStages.filter(stage => stage.StageType.IsPostStage);
} else {
return this.workflow.WorkFlowStages.filter(stage => !stage.StageType.IsPreStage && !stage.StageType.IsPostStage);
}
}
emailResponseSelected(): boolean {
return this.workflow.ApplicationResponseAction &&
this.workflow.ApplicationResponseAction.Value === 'EMAIL_RESPONSE';
......@@ -265,6 +267,13 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
message.VarianceString = `${message.Variance}m`;
}
/**
* Whenever Delay value is provided in message schedule section, it changes it into a delay string consisting of
* number of days, hours and minutes.
* Input mask gets values in the form of __:__:__
* Parsing of this value takes place in this function, moreover it sorts the messages as well
* @param message
*/
generateDelayString(message: WorkflowMessageModel): void {
if (!message.Delay) {
......@@ -333,6 +342,11 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
this.messageTemplates.push(newTemplate);
}
/**
* This function sets the parameters to be sent to edit-message-template component
* @param $event
* @param message
*/
showMessageTemplateDialog($event, message: WorkflowMessageModel): void {
const template = $event.value;
if (template.id && template.id === '0') {
......@@ -354,6 +368,11 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
}
}
/**
* When the dialog is closed, whether a template is created or updated, it is fetched by sending request to API.
* Newly created or updated template is selected and shown in the dropdown of message in message scheduling section.
* @param value
*/
closeDialog(value): void {
if (value === -1) {
// Cancel button is clicked
......@@ -401,7 +420,7 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
const stepType = step.StepType;
this.utilsService.removeMultiRefObject(step, stage, 'Steps', this.createdObjs, this.updatedObjs, this.deletedObjs);
this.reAssignStepOrders(stage);
stage.Steps.map((step, index) => step.SortOrder = index + 1);
this.addStepType(stepType);
}
});
......@@ -417,10 +436,6 @@ export class EditWorkflowTemplateComponent extends BaseComponent implements OnIn
this.resetSelect('stepTypes');
}
reAssignStepOrders(stage: WorkflowStageModel): void {
stage.Steps.map((step, index) => step.SortOrder = index + 1);
}
addMessage(stage: WorkflowStageModel): void {
const message = new WorkflowMessageModel(stage.ObjectID);
message.ApplicantSources = this.utilsService.cloneObject(this.applicantSources);
......
......@@ -2,10 +2,10 @@ export class SorterModel {
static count;
description;
ascending;
ObjectID;
Value;
constructor(des: string, sort: boolean) {
this.ObjectID = SorterModel.count++;
this.Value = SorterModel.count++;
this.description = des;
this.ascending = sort;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment