From ff273177a4d3d2595311960f2ad6245203d6eec0 Mon Sep 17 00:00:00 2001 From: Sumit-solytics Date: Wed, 28 Feb 2024 20:08:47 +0530 Subject: [PATCH] Cron expressions added --- .../pipeline-setting-form.component.html | 19 +++--- .../pipeline-setting-form.component.scss | 8 +++ .../pipeline-setting-form.component.ts | 67 +++++++------------ .../pipeline-setting.dialog.component.ts | 9 +-- .../pipelines/pipelines.effects.ts | 2 +- 5 files changed, 44 insertions(+), 61 deletions(-) diff --git a/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.html b/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.html index 1123f76d..b2e9c1ab 100644 --- a/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.html +++ b/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.html @@ -1,4 +1,4 @@ -
+ Email List *Please add an email. @@ -12,19 +12,20 @@ Schedule Interval - Custom - Daily - Hourly - Weekly + {{ option.charAt(0).toUpperCase() + option.slice(1) }} - - + + *Please add Cron Expression. Cron Expression - +
+ + +
-
diff --git a/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.scss b/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.scss index e2aeec70..f0fc00da 100644 --- a/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.scss +++ b/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.scss @@ -27,4 +27,12 @@ } ::ng-deep .dark-theme .mat-mdc-option.mdc-list-item:hover { background-color: #dce0ee; +} +.cron-expression-field .mat-form-field-flex { + display: flex; +} + +.cron-expression-field .input-container { + display: flex; + align-items: center; } \ No newline at end of file diff --git a/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.ts b/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.ts index 3a0f9672..32ebdb29 100644 --- a/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.ts +++ b/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting-form/pipeline-setting-form.component.ts @@ -13,8 +13,6 @@ import { styleUrls: ['./pipeline-setting-form.component.scss'] }) export class PipelineSettingFormComponent implements OnDestroy { - public readonly intervalsRoot = {label: 'My interval', value: null}; - @ViewChild('intervalInput') intervalInput: NgModel; @ViewChild('emailList') emailList: ElementRef; @ViewChild('expression') expression: NgModel; @@ -31,67 +29,50 @@ export class PipelineSettingFormComponent implements OnDestroy { interval: null, expression: '' }; - intervalsOptions: { label: string; value: string }[]; intervalsNames: string[]; - rootFiltered = false; - isAutoCompleteOpen = false; - loading = false; - noMoreOptions = false; + private subs = new Subscription(); constructor() {} - ngOnInit(): void { - this.searchChanged(['*', null].includes(this.defaultintervalId) ? '' : this.defaultintervalId); - setTimeout(() => { - this.subs.add(this.intervalInput.valueChanges.subscribe(searchString => { - if (searchString !== this.settingFields.interval) { - this.searchChanged(searchString?.label || searchString || ''); - } - })); - }); - } + ngOnInit(): void {} ngOnDestroy(): void { this.subs.unsubscribe(); } - + intervalOptions: string[] = ['custom', 'daily', 'hourly', 'weekly', 'monthly', 'yearly']; + cronExpressions: { [key: string]: string } = { + 'custom': '', + 'daily': '0 0 * * *', + 'hourly': '0 * * * *', + 'weekly': '0 0 * * 0', + 'monthly': '0 0 1 * *', + 'yearly': '0 0 1 1 *' + }; intervalSelected(event: MatAutocompleteSelectedEvent): void { - this.settingFields.interval = event.option.viewValue; - } - setIsAutoCompleteOpen(focus: boolean) { - this.isAutoCompleteOpen = focus; + const selectedInterval = event.option.value; + this.settingFields.interval = selectedInterval; + this.settingFields.expression = this.cronExpressions[selectedInterval]; } - displayFn(interval: IOption | string) { - return typeof interval === 'string' ? interval : interval?.label; + checkCronExpression(): void { + const enteredExpression = this.settingFields.expression.trim(); + const matchingInterval = Object.entries(this.cronExpressions).find(([interval, expression]) => expression === enteredExpression); + if (matchingInterval) { + this.settingFields.interval = matchingInterval[0]; + } else { + this.settingFields.interval = 'custom'; + } } - clear() { - this.intervalInput.control.setValue(''); + navigateToWebsite(): void { + window.open('https://en.wikipedia.org/wiki/Cron', '_blank'); } - send() { this.stepCreated.emit(this.settingFields); } - - searchChanged(searchString: string) { - this.intervalsOptions = null; - this.intervalsNames = null; - this.rootFiltered = searchString && !this.intervalsRoot.label.toLowerCase().includes(searchString.toLowerCase()); - searchString !== null && this.filterSearchChanged.emit({ value: searchString, loadMore: false }); - } - - loadMore(searchString) { - this.loading = true; - this.filterSearchChanged.emit({ value: searchString || '', loadMore: true }); - } - - isFocused(locationRef: HTMLInputElement) { - return document.activeElement === locationRef; - } } diff --git a/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting.dialog.component.ts b/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting.dialog.component.ts index 839fb061..4c051433 100644 --- a/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting.dialog.component.ts +++ b/src/app/webapp-common/pipelines/pipeline-setting/pipeline-setting.dialog.component.ts @@ -26,16 +26,9 @@ export class PipelineSettingDialogComponent { private store: Store, private matDialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: { defaultExperimentId: string} - ) { - // this.experiments$ = this.store.select(selectExperiments); - // this.readOnlyIntervalNames$ = this.store.select(selectExperiments) - // .pipe(map(experiments => experiments?.filter(experiment => isReadOnly(experiment)).map(experiment=> experiment.name))); - // this.store.dispatch(resetTablesFilterProjectsOptions()); - } + ) {} public settingsForm(pipelineForm) { - // eslint-disable-next-line no-console - console.log("i am form", pipelineForm) const pipeline = this.convertFormToPipeline(pipelineForm); this.matDialogRef.close(pipeline); } diff --git a/src/app/webapp-common/pipelines/pipelines.effects.ts b/src/app/webapp-common/pipelines/pipelines.effects.ts index 5f051ba9..9a6ea5a6 100644 --- a/src/app/webapp-common/pipelines/pipelines.effects.ts +++ b/src/app/webapp-common/pipelines/pipelines.effects.ts @@ -215,7 +215,7 @@ export class PipelinesEffects { catchError(err => { return [ requestFailed(err), - setServerError(err, null, 'failed to create a new pipeline step'), + setServerError(err, null, 'failed to make changes in settings'), deactivateLoader(pipelineSettings.type), ] })))