Skip to content

Commit

Permalink
Update hot_wantedServiceAppointmentsList.js
Browse files Browse the repository at this point in the history
  • Loading branch information
olsenrasmus committed Aug 21, 2023
1 parent 3afc918 commit db5bf1f
Showing 1 changed file with 1 addition and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ export default class Hot_wantedServiceAppointmentsList extends LightningElement
const eventToSend = new CustomEvent('senddetail', { detail: this.isDetails });
this.dispatchEvent(eventToSend);
}
sendCheckedRows() {
this.showSendInterest = this.checkedServiceAppointments.length > 0;
this.sendInterestButtonLabel = 'Meld interesse til ' + this.checkedServiceAppointments.length + ' oppdrag';
const eventToSend = new CustomEvent('sendcheckedrows', { detail: this.checkedServiceAppointments });
this.dispatchEvent(eventToSend);
}
sendInterestButtonLabel = '';

setPreviousFiltersOnRefresh() {
if (sessionStorage.getItem('openfilters2')) {
Expand All @@ -120,34 +113,17 @@ export default class Hot_wantedServiceAppointmentsList extends LightningElement

this.sendFilters();
}
setCheckedRowsOnRefresh() {
if (sessionStorage.getItem('checkedrows') && !this.isDetails) {
this.checkedServiceAppointments = JSON.parse(sessionStorage.getItem('checkedrows'));
sessionStorage.removeItem('checkedrows');
}
this.sendCheckedRows();
}

disconnectedCallback() {
// Going back with browser back or back button on mouse forces page refresh and a disconnect
// Save filters on disconnect to exist only within the current browser tab
sessionStorage.setItem('checkedrows', JSON.stringify(this.checkedServiceAppointments));
}
disconnectedCallback() {}

renderedCallback() {
this.setPreviousFiltersOnRefresh();
this.setCheckedRowsOnRefresh();
sessionStorage.setItem('checkedrowsSavedForRefresh', JSON.stringify(this.checkedServiceAppointments));
}

@track filters = [];
numberTimesCalled = 0;
connectedCallback() {
this.updateURL();
if (sessionStorage.getItem('checkedrowsSavedForRefresh')) {
this.checkedServiceAppointments = JSON.parse(sessionStorage.getItem('checkedrowsSavedForRefresh'));
sessionStorage.removeItem('checkedrowsSavedForRefresh');
}
this.setColumns();
refreshApex(this.wiredAllServiceAppointmentsResult);
}
Expand Down Expand Up @@ -232,7 +208,6 @@ export default class Hot_wantedServiceAppointmentsList extends LightningElement

this.sendRecords();
this.sendFilters();
this.sendCheckedRows();
this.applyFilter({ detail: { filterArray: this.filters, setRecords: true } });
}

Expand All @@ -244,8 +219,6 @@ export default class Hot_wantedServiceAppointmentsList extends LightningElement

@track serviceAppointment;
isDetails = false;
isSeries = false;
seriesRecords = [];
showTable = true;
goToRecordDetails(result) {
this.serviceAppointment = undefined;
Expand All @@ -256,16 +229,9 @@ export default class Hot_wantedServiceAppointmentsList extends LightningElement
for (let serviceAppointment of this.records) {
if (recordId === serviceAppointment.Id) {
this.serviceAppointment = serviceAppointment;
this.isSeries = this.serviceAppointment.HOT_IsSerieoppdrag__c;
this.serviceAppointment.weekday = this.getDayOfWeek(this.serviceAppointment.EarliestStartTime);
}
}
for (let serviceAppointment of this.records) {
if (this.serviceAppointment?.HOT_Request__c === serviceAppointment?.HOT_Request__c) {
this.seriesRecords.push(serviceAppointment);
}
}
this.isSeries = this.seriesRecords.length <= 1 ? false : true;
this.showServiceAppointmentDetails();
}
showServiceAppointmentDetails() {
Expand Down Expand Up @@ -294,55 +260,6 @@ export default class Hot_wantedServiceAppointmentsList extends LightningElement

errorMessage = '';
spin = false;
@track checkedServiceAppointments = [];

handleRowChecked(event) {
this.checkedServiceAppointments = event.detail.checkedRows;
this.sendCheckedRows();
}

showSendInterest = false;
@track serviceAppointmentCommentDetails = [];
sendInterest() {
this.hideSubmitIndicators();
this.showCommentSection();
this.checkedServiceAppointments = [];
this.serviceAppointmentCommentDetails = [];
try {
this.template
.querySelector('c-table')
.getCheckedRows()
.forEach((row) => {
this.checkedServiceAppointments.push(row);
this.serviceAppointmentCommentDetails.push(this.getRecord(row));
});
} catch (error) {
console.log(error);
}
if (this.checkedServiceAppointments.length === 0) {
this.showSendInterest = false;
return;
}
this.showSendInterest = false;
this.showCommentPage();
}

sendInterestAllComplete = false;
sendInterestAll = false;
sendInterestSeries() {
this.template.querySelector('.serviceAppointmentDetails').classList.add('hidden');
this.hideSubmitIndicators();
this.showCommentSection();
this.serviceAppointmentCommentDetails = [];
this.sendInterestAll = true;
this.serviceAppointmentCommentDetails.push(...this.seriesRecords);
this.showCommentPage();
}

showCommentPage() {
this.template.querySelector('.commentPage').classList.remove('hidden');
this.template.querySelector('.commentPage').focus();
}

hideSubmitIndicators() {
this.template.querySelector('.submitted-error').classList.add('hidden');
Expand All @@ -351,25 +268,11 @@ export default class Hot_wantedServiceAppointmentsList extends LightningElement
}

closeModal() {
if (this.sendInterestAllComplete) {
refreshApex(this.wiredAllServiceAppointmentsResult).then(() => {
// Since refreshApex causes the wired methods to run again, the default filters will override current filters.
// Apply previous filter
this.applyFilter({ detail: { filterArray: currentFilters, setRecords: true } });
});
this.goBack();
}
this.sendInterestAllComplete = false;
this.sendInterestAll = false;
this.template.querySelector('.commentPage').classList.add('hidden');
this.template.querySelector('.serviceAppointmentDetails').classList.add('hidden');
}

showCommentSection() {
this.template.querySelector('.comment-details').classList.remove('hidden');
this.template.querySelector('.send-inn-button').classList.remove('hidden');
}

getRecord(id) {
for (let record of this.records) {
if (record.Id === id) {
Expand Down Expand Up @@ -414,9 +317,6 @@ export default class Hot_wantedServiceAppointmentsList extends LightningElement
if (setRecords) {
this.records = filteredRecords;
}
this.checkedServiceAppointmentsFromSession = JSON.parse(
sessionStorage.getItem('checkedrowsSavedForRefresh')
);
} else {
let filteredRecords = [];
let records = this.initialServiceAppointments;
Expand All @@ -434,15 +334,6 @@ export default class Hot_wantedServiceAppointmentsList extends LightningElement
if (setRecords) {
this.records = filteredRecords;
}
this.checkedServiceAppointmentsFromSession = JSON.parse(
sessionStorage.getItem('checkedrowsSavedForRefresh')
);
if (
this.filteredRecordsLength != this.checkedServiceAppointmentsFromSession.length &&
this.numberTimesCalled > 2
) {
this.checkedServiceAppointments = [];
}
}
return this.filteredRecordsLength;
}
Expand Down

0 comments on commit db5bf1f

Please sign in to comment.