Commit 74d5e962 by Ali

CR review by Ali

parent a92e2ca6
......@@ -41,7 +41,7 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
jobApplication = new JobApplicationModel();
subscriptions: Array<Subscription> = [];
sentViaEnum: Array<SentViaEnum>;
sentViaEnum: Array<SentViaEnum> = [];
Message = new MessageModel();
apiUrl = environment.baseUrl;
loggedInId = null;
......@@ -69,9 +69,19 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
ngOnInit(): void {
this.utilsService.resetCounter();
this.showLoader = true;
this.getSetVias();
// 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.appService.getTypes('SentVia')
.subscribe((data: Array<SentViaEnum>) => {
......@@ -80,58 +90,39 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
({
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) {
this.getEngineApplicantViewByID(this.jobId);
this.getEngineApplicantViewByID();
} else {
this.utilsService.createObject(this.jobApplication, this.createdObjs);
this.Message.JobApplication = this.jobApplication;
this.Message.Attachments = [];
this.showLoader = false;
this.setEditorClass();
this.createMessage();
// Should never come to this block
console.error("jobId not found.");
}
}
getEngineApplicantViewByID(jobId: string): void {
getEngineApplicantViewByID(): void {
this.showLoader = true;
this.createdObjs = {};
this.utilsService.resetCounter();
this.utilsService.clearErrorMessages();
this.createMessage();
const assocs =
[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('.')];
this.subscriptions.push(this.messageEngineApplicantViewService.getEngineApplicantViewByID(jobId, assocs)
this.subscriptions.push(this.messageEngineApplicantViewService.getEngineApplicantViewByID(this.jobId, assocs)
.subscribe(
data => {
this.jobApplication = data;
......@@ -149,7 +140,6 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
const msgWrapper = document.getElementsByClassName('messages-wrapper')[0];
msgWrapper.scrollTop = msgWrapper.scrollHeight;
}, 0);
this.setEditorClass();
},
error => {
this.showLoader = false;
......@@ -184,21 +174,13 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
return;
}
this.utilsService.clearErrorMessages();
if (this.form.invalid || this.IsMessageEmpty()) {
this.utilsService.showAllErrorMessages();
} else {
this.showLoader = true;
this.subscriptions.push(this.saveService.saveObjectsWithDefaultSvc(this.createdObjs, this.updatedObjs, this.deletedObjs)
.subscribe(
data => {
this.utilsService.handleSuccess();
let idToNavigate = this.jobApplication.ObjectID;
if (data.created[idToNavigate]) {
idToNavigate = data.created[idToNavigate];
}
this.getEngineApplicantViewByID(idToNavigate);
this.showLoader = false;
this.getEngineApplicantViewByID();
},
error => {
this.showLoader = false;
......@@ -207,7 +189,6 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
)
);
}
}
/**
* Creates a new object of ChatAttachment and assigns the FileToken and Name to it.
......@@ -229,6 +210,7 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
* It simply creates a new object and assigns the default values to it.
*/
createMessage(): void {
this.Message = new MessageModel();
this.Message.SentBy = this.loggedInId;
this.Message.SentVia = this.sentViaEnum[2] ? this.sentViaEnum[2] : this.sentViaEnum[0];
this.utilsService.createObject(this.Message, this.createdObjs);
......@@ -268,41 +250,4 @@ export class MessageEngineApplicantViewComponent extends BaseComponent implement
}, 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