mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(edge/jobs): migrate item view to react [EE-2220] (#11887)
Some checks failed
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:s390x platform:linux version:]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled
Some checks failed
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:s390x platform:linux version:]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled
This commit is contained in:
parent
62c2bf86aa
commit
eb6d251a73
44 changed files with 778 additions and 886 deletions
|
@ -0,0 +1,79 @@
|
|||
import { addHours, getDate, getHours, getMinutes, getMonth } from 'date-fns';
|
||||
import moment from 'moment';
|
||||
|
||||
import { defaultCronExpression, timeOptions } from './RecurringFieldset';
|
||||
|
||||
interface RecurringViewModel {
|
||||
cronMethod: 'basic' | 'advanced';
|
||||
cronExpression: string;
|
||||
recurring: boolean;
|
||||
recurringOption: (typeof timeOptions)[number]['value'];
|
||||
dateTime: Date;
|
||||
}
|
||||
|
||||
interface RecurringRequestModel {
|
||||
recurring: boolean;
|
||||
cronExpression: string;
|
||||
}
|
||||
|
||||
export function toRecurringRequest(
|
||||
values: RecurringViewModel
|
||||
): RecurringRequestModel {
|
||||
if (values.cronMethod !== 'basic') {
|
||||
return {
|
||||
recurring: true,
|
||||
cronExpression: values.cronExpression,
|
||||
};
|
||||
}
|
||||
|
||||
if (values.recurring) {
|
||||
return {
|
||||
recurring: true,
|
||||
cronExpression: values.recurringOption,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
recurring: false,
|
||||
cronExpression: dateTimeToCron(values.dateTime),
|
||||
};
|
||||
|
||||
function dateTimeToCron(date: Date) {
|
||||
return [
|
||||
getMinutes(date),
|
||||
getHours(date),
|
||||
getDate(date),
|
||||
getMonth(date) + 1,
|
||||
'*',
|
||||
].join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
export function toRecurringViewModel(
|
||||
{ cronExpression, recurring }: RecurringRequestModel = {
|
||||
cronExpression: defaultCronExpression,
|
||||
recurring: true,
|
||||
}
|
||||
): RecurringViewModel {
|
||||
const defaultTime = addHours(new Date(), 1);
|
||||
const scheduled = timeOptions.find((v) => v.value === cronExpression);
|
||||
|
||||
return {
|
||||
recurring,
|
||||
cronExpression,
|
||||
recurringOption: scheduled?.value || defaultCronExpression,
|
||||
cronMethod: recurring && !scheduled ? 'advanced' : 'basic',
|
||||
dateTime: cronExpression
|
||||
? cronToDateTime(cronExpression, defaultTime)
|
||||
: defaultTime,
|
||||
};
|
||||
}
|
||||
|
||||
function cronToDateTime(cron: string, defaultTime: Date): Date {
|
||||
const strings = cron.split(' ');
|
||||
if (strings.length > 4) {
|
||||
return moment(cron, 'm H D M').toDate();
|
||||
}
|
||||
|
||||
return defaultTime;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue