Skip to content

Commit

Permalink
feat: Add default dashboard layout
Browse files Browse the repository at this point in the history
- Added a default dashboard layout consisting of several widgets.
- Each widget has a unique ID, type, and grid configuration.
- The `useDashboardStore` state now initializes with the default dashboard layout.

fix: Update runJob function in tasks store

- Updated the `runJob` function in the `tasks` store to properly handle the response from the API.
- If the job is null, the function will return early.
- The updated job is now properly stored in the store.

feat: Update toMinutes filter

- Updated the `toMinutes` filter to include a new `utc` parameter.
- The `utc` parameter determines whether to consider UTC time or local time.
- Moment objects are created using the respective time zone option.
- The difference in minutes is calculated between the input value and the current time.
  • Loading branch information
realashleybailey committed Sep 17, 2023
1 parent a891a0b commit 0f96e74
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
44 changes: 32 additions & 12 deletions frontend/src/stores/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,42 @@ interface DashboardStoreState {
dashboard: WidgetOptions[];
}

const defaultDashboard: WidgetOptions[] = [
{
id: nanoid(),
type: "InvitesTotal",
grid: { w: 2, h: 2 },
},
{
id: nanoid(),
type: "UsersTotal",
grid: { w: 2, h: 2 },
},
{
id: nanoid(),
type: "TasksTotal",
grid: { w: 2, h: 2 },
},
{
id: nanoid(),
type: "UsersGraph",
grid: { w: 3, h: 4 },
},
{
id: nanoid(),
type: "InvitesGraph",
grid: { w: 3, h: 4 },
},
];

export const useDashboardStore = defineStore("dashboard", {
state: (): DashboardStoreState => ({
dashboard: [
{
id: nanoid(),
type: "InvitesTotal",
grid: { w: 2, h: 2 },
},
{
id: nanoid(),
type: "UsersTotal",
grid: { w: 2, h: 2 },
},
],
dashboard: defaultDashboard,
}),
actions: {
resetDashboard() {
this.dashboard = defaultDashboard;
},
updateWidget(widget: WidgetOptions) {
const index = this.dashboard.findIndex((w) => w.id === widget.id);
this.dashboard[index] = widget;
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/stores/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ export const useTasksStore = defineStore("tasks", {
// Return the job
return job.data as Job;
},
async runJob(id: string) {
// Run the job
const job = await this.$axios.post(`/api/scheduler/jobs/${id}/run`).catch((err) => {
this.$toast.error("Could not run job");
console.error(err);
return null;
});

// If the job is null, return
if (job === null) return;

// Update the job in the store
const index = this.jobs.findIndex((job: Job) => job.id === id);
if (index !== -1) this.jobs[index] = job.data;

// Return the job
return job.data as Job;
},
async pauseJob(id: string) {
// Pause the job
const job = await this.$axios.post(`/api/scheduler/jobs/${id}/pause`).catch((err) => {
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/ts/filters/toMinutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ import moment from "moment";
/**
* toMinutes - Convert a string date or date object to minutes from now
*
* @param {string | Date} value - The date or date string to convert to minutes from now
* @param value - The date or date string to convert to minutes from now
* @param utc - Whether to use UTC or not
* @returns The minutes from now
*/
function toMinutes(value: string | Date): number {
return moment(value).diff(moment(), "minutes");
function toMinutes(value: string | Date, utc: boolean = true): number {
// Define different moments for the local times
const localDateTime = utc ? moment.utc(value) : moment(value);
const localNow = moment();

// Calculate the difference in minutes between the times
return localDateTime.diff(localNow, "minutes");
}

export default toMinutes;

0 comments on commit 0f96e74

Please sign in to comment.