From 0388e02e51ef79cd7f765b57e5cba6ca2f6d818c Mon Sep 17 00:00:00 2001 From: Heber Date: Sun, 3 Mar 2024 15:18:40 -0700 Subject: [PATCH] Update schedule style and details --- dlrs/main/classes/AsyncApexJobsSelector.cls | 7 +- .../classSchedulerModal.html | 78 +++--- .../classSchedulerModal.js | 76 ++++- dlrs/main/lwc/cronBuilder/cronBuilder.html | 263 +++++++++--------- dlrs/main/lwc/cronBuilder/cronBuilder.js | 12 +- 5 files changed, 266 insertions(+), 170 deletions(-) diff --git a/dlrs/main/classes/AsyncApexJobsSelector.cls b/dlrs/main/classes/AsyncApexJobsSelector.cls index 4491f143..cb7010b4 100644 --- a/dlrs/main/classes/AsyncApexJobsSelector.cls +++ b/dlrs/main/classes/AsyncApexJobsSelector.cls @@ -91,7 +91,8 @@ public class AsyncApexJobsSelector extends fflib_SObjectSelector { new List{ 'ApexClass.Name', 'CronTrigger.CronJobDetail.Name', - 'CronTrigger.CronExpression' + 'CronTrigger.CronExpression', + 'CronTrigger.NextFireTime' } ) .setCondition( @@ -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); } diff --git a/dlrs/main/lwc/classSchedulerModal/classSchedulerModal.html b/dlrs/main/lwc/classSchedulerModal/classSchedulerModal.html index 80b9d7f8..75263304 100644 --- a/dlrs/main/lwc/classSchedulerModal/classSchedulerModal.html +++ b/dlrs/main/lwc/classSchedulerModal/classSchedulerModal.html @@ -3,39 +3,45 @@ -

- Total Scheduled Jobs in the Org - ({scheduledJobCount}/{totalAllowedScheduledJobs}) -

- +
+

+ Total Scheduled Jobs in the Org + ({scheduledJobCount}/{totalAllowedScheduledJobs}) +

+
+ +
+
- - Existing Schedules of {className} + +
+

+ Existing Schedules of {className} +

+
+ +
+
-
- + -
Planned New Scheduled Items
- +
+

New schedule patterns

+
+ + +
    + +
+
+
+
+
diff --git a/dlrs/main/lwc/classSchedulerModal/classSchedulerModal.js b/dlrs/main/lwc/classSchedulerModal/classSchedulerModal.js index f97a98a1..65e7d1b5 100644 --- a/dlrs/main/lwc/classSchedulerModal/classSchedulerModal.js +++ b/dlrs/main/lwc/classSchedulerModal/classSchedulerModal.js @@ -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"; @@ -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 @@ -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() { @@ -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 diff --git a/dlrs/main/lwc/cronBuilder/cronBuilder.html b/dlrs/main/lwc/cronBuilder/cronBuilder.html index 7d216678..700e070a 100644 --- a/dlrs/main/lwc/cronBuilder/cronBuilder.html +++ b/dlrs/main/lwc/cronBuilder/cronBuilder.html @@ -1,130 +1,143 @@ diff --git a/dlrs/main/lwc/cronBuilder/cronBuilder.js b/dlrs/main/lwc/cronBuilder/cronBuilder.js index b38c9a29..3f5d94df 100644 --- a/dlrs/main/lwc/cronBuilder/cronBuilder.js +++ b/dlrs/main/lwc/cronBuilder/cronBuilder.js @@ -21,16 +21,18 @@ export default class CronBuilder extends LightningElement { } dayTypes = [ - { label: "Month", value: DAY_TYPE.daysOfMonth }, - { label: "Week", value: DAY_TYPE.daysOfWeek } + { label: "Days of the Month", value: DAY_TYPE.daysOfMonth }, + { label: "Days of the Week", value: DAY_TYPE.daysOfWeek } ]; dayType = DAY_TYPE.daysOfMonth; - monthCols = [ + columns = [ { - label: "Month", - fieldName: "label" + label: "All", + fieldName: "label", + wrapText: true, + hideDefaultActions: true } ];