Skip to content

Commit

Permalink
Update schedule style and details
Browse files Browse the repository at this point in the history
  • Loading branch information
aheber committed Mar 3, 2024
1 parent 67ec5ac commit 0388e02
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 170 deletions.
7 changes: 6 additions & 1 deletion dlrs/main/classes/AsyncApexJobsSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public class AsyncApexJobsSelector extends fflib_SObjectSelector {
new List<String>{
'ApexClass.Name',
'CronTrigger.CronJobDetail.Name',
'CronTrigger.CronExpression'
'CronTrigger.CronExpression',
'CronTrigger.NextFireTime'
}
)
.setCondition(
Expand All @@ -100,6 +101,10 @@ public class AsyncApexJobsSelector extends fflib_SObjectSelector {
'ApexClass.Name = :className AND ' +
'ApexClass.NamespacePrefix = :namespace'
)
.addOrdering(
'CronTrigger.NextFireTime',
fflib_QueryFactory.SortOrder.ASCENDING
)
.toSOQL();
return Database.query(query);
}
Expand Down
78 changes: 47 additions & 31 deletions dlrs/main/lwc/classSchedulerModal/classSchedulerModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,66 @@
<lightning-modal-body>
<lightning-layout multiple-rows>
<lightning-layout-item size="12">
<p>
Total Scheduled Jobs in the Org
({scheduledJobCount}/{totalAllowedScheduledJobs})
</p>
<lightning-progress-bar
aria-label="Used Scheduled Jobs"
value={scheduledJobCount}
></lightning-progress-bar>
<div class="slds-section slds-is-open">
<h3 class="slds-section__title">
Total Scheduled Jobs in the Org
({scheduledJobCount}/{totalAllowedScheduledJobs})
</h3>
<div class="slds-section__content">
<lightning-progress-bar
aria-label="Used Scheduled Jobs"
value={scheduledJobCount}
></lightning-progress-bar>
</div>
</div>
</lightning-layout-item>
<lightning-layout-item size="12">
<lightning-layout multiple-rows>
<lightning-layout-item size="12" lwc:if={currentSchedule.length}>
Existing Schedules of {className}
<lightning-layout-item
size="12"
lwc:if={currentSchedule.length}
class="slds-p-vertical_small"
>
<div class="slds-section slds-is-open">
<h3 class="slds-section__title">
Existing Schedules of {className}
</h3>
<div class="slds-section__content">
<lightning-datatable
id="currentscheduledatatable"
data={currentSchedule}
columns={currentColumns}
key-field="Id"
onrowaction={handleRowAction}
hide-checkbox-column
></lightning-datatable>
</div>
</div>
</lightning-layout-item>
<template for:each={currentSchedule} for:item="sched">
<lightning-layout-item key={sched.Id} size="12">
<lightning-layout>
<lightning-layout-item flexibility="grow">
{sched.CronTrigger.CronExpression}
</lightning-layout-item>
<lightning-layout-item>
<lightning-button-icon
icon-name="utility:delete"
data-jobid={sched.CronTrigger.Id}
onclick={handleCancelJob}
></lightning-button-icon>
</lightning-layout-item>
</lightning-layout>
</lightning-layout-item>
</template>
</lightning-layout>
</lightning-layout-item>
<lightning-layout-item size="12">
<lightning-layout-item size="12" class="slds-p-vertical_medium">
<c-cron-builder
values={cronStrings}
oncronupdate={handleOnCronUpdate}
templates={templates}
></c-cron-builder>
</lightning-layout-item>
<lightning-layout-item size="12">
<div>Planned New Scheduled Items</div>
<template for:each={cronStrings} for:item="cron">
<div key={cron}>{cron}</div>
</template>
<div class="slds-section slds-is-open">
<h3 class="slds-section__title">New schedule patterns</h3>
<div class="slds-section__content">
<lightning-layout>
<lightning-layout-item flexibility="shrink">
<ul class="slds-has-dividers_around-space">
<template for:each={cronStrings} for:item="cron">
<li key={cron} class="slds-item">{cron}</li>
</template>
</ul>
</lightning-layout-item>
</lightning-layout>
</div>
</div>
</lightning-layout-item>
</lightning-layout>
</lightning-modal-body>
Expand Down
76 changes: 68 additions & 8 deletions dlrs/main/lwc/classSchedulerModal/classSchedulerModal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { api } from "lwc";
import LightningModal from "lightning/modal";

import { ShowToastEvent } from "lightning/platformShowToastEvent";
import LightningConfirm from "lightning/confirm";

import getCurrentJobs from "@salesforce/apex/SchedulerController.getCurrentJobs";
import getTotalScheduledJobs from "@salesforce/apex/SchedulerController.getAllScheduledJobs";
import scheduleJobs from "@salesforce/apex/SchedulerController.scheduleJobs";
Expand All @@ -9,9 +13,32 @@ export default class ClassSchedulerModal extends LightningModal {
cronStrings = [];
// async apex jobs
currentSchedule = [];
currentColumns = [
{ label: "Name", fieldName: "name" },
{
label: "Next Run At",
fieldName: "nextRunAt",
type: "date",
typeAttributes: {
month: "short",
day: "2-digit",
hour: "2-digit",
minute: "2-digit"
},
hideDefaultActions: true
},
{ label: "Cron String", fieldName: "cronString", hideDefaultActions: true },
{
type: "action",
typeAttributes: { rowActions: [{ label: "Delete", name: "delete" }] },
hideDefaultActions: true
}
];

// using the configured Cron strings stub new instances to be scheduled
proposedSchedule = [];
scheduledJobCount = 0;
// Can this be changes for some customers? Is there a place we can get this from?
totalAllowedScheduledJobs = 100;

@api
Expand All @@ -26,24 +53,52 @@ export default class ClassSchedulerModal extends LightningModal {
@api
templates;

async connectedCallback() {
this.currentSchedule = await getCurrentJobs({ className: this.className });
this.scheduledJobCount = (await getTotalScheduledJobs()).length;
connectedCallback() {
this.updateScheduledData();
}

handleOnCronUpdate(event) {
this.cronStrings = event.detail.value;
}

async handleCancelJob(event) {
handleRowAction(event) {
this.handleCancelJob(event.detail.row.id);
}

async handleCancelJob(jobId) {
const confirmed = await LightningConfirm.open({
label: "Delete Scheduled Job",
message: `Are you sure you want to remove the scheduled job?`,
theme: "warning"
});

if (!confirmed) {
return;
}
// get the job id, send to the server to cancel
await cancelScheduledJob({
jobId: event.currentTarget.dataset.jobid
jobId
});

// refresh current jobs list
this.currentSchedule = await getCurrentJobs({ className: this.className });
this.scheduledJobCount = (await getTotalScheduledJobs()).length;
this.updateScheduledData();
}

updateScheduledData() {
getCurrentJobs({
className: this.className
}).then((jobs) => {
this.currentSchedule = jobs.map((j) => ({
id: j.CronTrigger.Id,
name: j.CronTrigger.CronJobDetail.Name,
nextRunAt: j.CronTrigger.NextFireTime,
cronString: j.CronTrigger.CronExpression
}));
console.log(this.currentSchedule);
});

getTotalScheduledJobs().then((jobs) => {
this.scheduledJobCount = jobs.length;
});
}

async handleSchedule() {
Expand All @@ -52,6 +107,11 @@ export default class ClassSchedulerModal extends LightningModal {
className: this.className,
newSchedules: this.cronStrings
});
const evt = new ShowToastEvent({
title: "Succesfully Added Jobs",
variant: "success"
});
this.dispatchEvent(evt);
this.close();
} catch (error) {
// TODO: handle the error better
Expand Down
Loading

0 comments on commit 0388e02

Please sign in to comment.