Commit 74d5e962 by Ali

CR review by Ali

parent a92e2ca6
...@@ -41,7 +41,7 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement ...@@ -41,7 +41,7 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
jobApplication = new JobApplicationModel(); jobApplication = new JobApplicationModel();
subscriptions: Array<Subscription> = []; subscriptions: Array<Subscription> = [];
sentViaEnum: Array<SentViaEnum>; sentViaEnum: Array<SentViaEnum> = [];
Message = new MessageModel(); Message = new MessageModel();
apiUrl = environment.baseUrl; apiUrl = environment.baseUrl;
loggedInId = null; loggedInId = null;
...@@ -69,9 +69,19 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement ...@@ -69,9 +69,19 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
ngOnInit(): void { ngOnInit(): void {
this.utilsService.resetCounter(); this.getSetVias();
this.showLoader = true; // For Hiring Team or Applicant
const service = this.embedded ? this.adminPortalLayoutService : this.applicantPortalLayoutService;
if (service.userData) {
this.initComponent(service);
} else {
this.subscriptions.push(service.userDataUpdated.first().subscribe(() => {
this.initComponent(service);
}));
}
}
getSetVias() {
this.subscriptions.push( this.subscriptions.push(
this.appService.getTypes('SentVia') this.appService.getTypes('SentVia')
.subscribe((data: Array<SentViaEnum>) => { .subscribe((data: Array<SentViaEnum>) => {
...@@ -80,58 +90,39 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement ...@@ -80,58 +90,39 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
({ ({
label: elem.Description, command: () => this.Message.SentVia = elem label: elem.Description, command: () => this.Message.SentVia = elem
})); }));
// For Hiring Team or Applicant
const service = this.embedded ? this.adminPortalLayoutService : this.applicantPortalLayoutService;
if (service.userData) {
if (!(service instanceof AdminPortalLayoutService)) {
this.jobId = service.jobId;
this.loggedInId = service.userData.UserID;
} else {
this.loggedInId = service.userData.CompanyUser.User;
}
this.initComponent();
} else {
this.subscriptions.push(service.userDataUpdated
.first()
.subscribe(() => {
this.loggedInId = service.userData.UserID;
if (!(service instanceof AdminPortalLayoutService)) {
this.jobId = service.jobId;
}
this.initComponent();
}));
}
}) })
); );
}
initComponent(service): void {
if (service instanceof AdminPortalLayoutService) {
this.loggedInId = service.userData.CompanyUser.User;
// jobId should come from @Input;
} else {
this.jobId = service.jobId;
this.loggedInId = service.userData.UserID;
} }
initComponent(): void {
if (this.jobId) { if (this.jobId) {
this.getEngineApplicantViewByID(this.jobId); this.getEngineApplicantViewByID();
} else { } else {
this.utilsService.createObject(this.jobApplication, this.createdObjs); // Should never come to this block
this.Message.JobApplication = this.jobApplication; console.error("jobId not found.");
this.Message.Attachments = [];
this.showLoader = false;
this.setEditorClass();
this.createMessage();
} }
} }
getEngineApplicantViewByID(jobId: string): void { getEngineApplicantViewByID(): void {
this.showLoader = true; this.showLoader = true;
this.createdObjs = {}; this.createdObjs = {};
this.utilsService.resetCounter();
this.utilsService.clearErrorMessages();
this.createMessage(); this.createMessage();
const assocs = const assocs =
[ASSOCS.JOB, [ASSOCS.JOB, ASSOCS.HIRING_TEAM].join('.'), ASSOCS.MESSAGES, [ASSOCS.MESSAGES, ASSOCS.SENT_BY].join('.'), [ASSOCS.JOB, [ASSOCS.JOB, ASSOCS.HIRING_TEAM].join('.'), ASSOCS.MESSAGES, [ASSOCS.MESSAGES, ASSOCS.SENT_BY].join('.'),
[ASSOCS.MESSAGES, ASSOCS.ATTACHMENTS].join('.'), [ASSOCS.CANDIDATE, ASSOCS.USER].join('.')]; [ASSOCS.MESSAGES, ASSOCS.ATTACHMENTS].join('.'), [ASSOCS.CANDIDATE, ASSOCS.USER].join('.')];
this.subscriptions.push(this.messageEngineApplicantViewService.getEngineApplicantViewByID(jobId, assocs) this.subscriptions.push(this.messageEngineApplicantViewService.getEngineApplicantViewByID(this.jobId, assocs)
.subscribe( .subscribe(
data => { data => {
this.jobApplication = data; this.jobApplication = data;
...@@ -149,7 +140,6 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement ...@@ -149,7 +140,6 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
const msgWrapper = document.getElementsByClassName('messages-wrapper')[0]; const msgWrapper = document.getElementsByClassName('messages-wrapper')[0];
msgWrapper.scrollTop = msgWrapper.scrollHeight; msgWrapper.scrollTop = msgWrapper.scrollHeight;
}, 0); }, 0);
this.setEditorClass();
}, },
error => { error => {
this.showLoader = false; this.showLoader = false;
...@@ -184,21 +174,13 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement ...@@ -184,21 +174,13 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
return; return;
} }
this.utilsService.clearErrorMessages();
if (this.form.invalid || this.IsMessageEmpty()) {
this.utilsService.showAllErrorMessages();
} else {
this.showLoader = true; this.showLoader = true;
this.subscriptions.push(this.saveService.saveObjectsWithDefaultSvc(this.createdObjs, this.updatedObjs, this.deletedObjs) this.subscriptions.push(this.saveService.saveObjectsWithDefaultSvc(this.createdObjs, this.updatedObjs, this.deletedObjs)
.subscribe( .subscribe(
data => { data => {
this.utilsService.handleSuccess(); this.utilsService.handleSuccess();
let idToNavigate = this.jobApplication.ObjectID; this.showLoader = false;
if (data.created[idToNavigate]) { this.getEngineApplicantViewByID();
idToNavigate = data.created[idToNavigate];
}
this.getEngineApplicantViewByID(idToNavigate);
}, },
error => { error => {
this.showLoader = false; this.showLoader = false;
...@@ -207,7 +189,6 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement ...@@ -207,7 +189,6 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
) )
); );
} }
}
/** /**
* Creates a new object of ChatAttachment and assigns the FileToken and Name to it. * Creates a new object of ChatAttachment and assigns the FileToken and Name to it.
...@@ -229,6 +210,7 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement ...@@ -229,6 +210,7 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
* It simply creates a new object and assigns the default values to it. * It simply creates a new object and assigns the default values to it.
*/ */
createMessage(): void { createMessage(): void {
this.Message = new MessageModel();
this.Message.SentBy = this.loggedInId; this.Message.SentBy = this.loggedInId;
this.Message.SentVia = this.sentViaEnum[2] ? this.sentViaEnum[2] : this.sentViaEnum[0]; this.Message.SentVia = this.sentViaEnum[2] ? this.sentViaEnum[2] : this.sentViaEnum[0];
this.utilsService.createObject(this.Message, this.createdObjs); this.utilsService.createObject(this.Message, this.createdObjs);
...@@ -268,41 +250,4 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement ...@@ -268,41 +250,4 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
}, 0); }, 0);
} }
/**
* Convert rich text into simple text and check if is empty or not!
*/
showPlainText(HTMLTitle: string): string {
if (HTMLTitle === undefined) {
return '';
}
const temp = document.getElementById('showPlainText');
temp.innerHTML = HTMLTitle;
const title = temp.innerText.trim();
temp.innerHTML = '';
return title;
}
/**
* If message content is empty, generate an error message for it.
*/
IsMessageEmpty(): boolean {
const editElement = this.messageEditor.getQuill().container;
const editor = editElement.getElementsByClassName('ql-editor');
if (this.showPlainText(this.Message.MessageContent) === '') {
this.messageEditor.getQuill()
.focus();
editor[0].classList.add('error-block');
return true;
}
editor[0].classList.remove('error-block');
return false;
}
} }
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