-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
242 additions
and
4 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
backend/files/misc/workflows/actions/misc/execute-action-if.hl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
/* | ||
* Executes the specified [action] if the specified [condition] is true. | ||
* | ||
* Will pass in all arguments specified to the action. The [condition] can be two different | ||
* values or expressions, and the [comparison] can be eq, neq, mt, mte, lt, lte, or some other | ||
* comparison operator. | ||
* | ||
* The action will use the [comparison] to compare the [lhs] and [rhs] values/expressions. | ||
*/ | ||
.arguments | ||
lhs | ||
type:string | ||
mandatory:bool:true | ||
comparison | ||
type:enum | ||
mandatory:bool:true | ||
values | ||
.:eq | ||
.:neq | ||
.:mt | ||
.:mte | ||
.:lt | ||
.:lte | ||
rhs | ||
type:string | ||
mandatory:bool:true | ||
action | ||
type:action | ||
mandatory:bool:true | ||
arguments | ||
type:key-value | ||
mandatory:bool:false | ||
.icon:settings | ||
|
||
// Sanity checking invocation. | ||
validators.mandatory:x:@.arguments/*/action | ||
validators.mandatory:x:@.arguments/*/lhs | ||
validators.mandatory:x:@.arguments/*/rhs | ||
validators.mandatory:x:@.arguments/*/comparison | ||
|
||
// Making sure we use correct comparison operator. | ||
set-name:x:./*/if/*/comparison | ||
get-value:x:@.arguments/*/comparison | ||
|
||
// Checking if [comparison] yields true. | ||
if | ||
comparison | ||
get-value:x:@.arguments/*/lhs | ||
get-value:x:@.arguments/*/rhs | ||
.lambda | ||
|
||
// Parametrising [execute]. | ||
add:x:./*/execute/*/arguments | ||
get-nodes:x:@.arguments/*/arguments/* | ||
|
||
// Executing file. | ||
execute:magic.workflows.actions.execute | ||
name:_ | ||
filename:x:@.arguments/*/action | ||
arguments | ||
|
||
// Parametrising [return] invocation. | ||
add:x:./*/return | ||
get-nodes:x:@execute/* | ||
|
||
// Returning result of execution to caller. | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
.../components/parametrise-action-dialog/components/formly-action/formly-action.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
|
||
/* | ||
* Copyright (c) 2023 Thomas Hansen - For license inquiries you can contact thomas@ainiro.io. | ||
*/ | ||
|
||
// Angular and system imports. | ||
import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Observable, map, startWith } from 'rxjs'; | ||
|
||
// Application specific imports | ||
import { GeneralService } from 'src/app/services/general.service'; | ||
import { WorkflowService } from 'src/app/services/workflow.service'; | ||
import { MatAutocompleteActivatedEvent } from '@angular/material/autocomplete'; | ||
|
||
/** | ||
* Formly workflow extension field. | ||
*/ | ||
@Component({ | ||
selector: 'app-formly-action', | ||
template: ` | ||
<mat-form-field class="w-100 standalone-field mb-2"> | ||
<mat-label>{{field.props.label}}</mat-label> | ||
<input | ||
[id]="field.key" | ||
type="text" | ||
[placeholder]="field.props.label" | ||
matInput | ||
[formControl]="formControl" | ||
[matAutocomplete]="auto"> | ||
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="optionSelected($event)"> | ||
<mat-option | ||
*ngFor="let option of filteredOptions | async;" | ||
[class]="option.complete === false ? 'warning' : ''" | ||
[matTooltip]="option.complete === false ? 'Incomplete expression, cannot deduce complete path' : ''" | ||
matTooltipPosition="right" | ||
[value]="option.value">{{option.label}}</mat-option> | ||
</mat-autocomplete> | ||
</mat-form-field> | ||
`, | ||
styleUrls: ['./formly-action.scss'] | ||
}) | ||
export class FormlyActionComponent extends FieldType<FieldTypeConfig> implements OnInit { | ||
|
||
filteredOptions: Observable<string[]>; | ||
|
||
constructor( | ||
private generalService: GeneralService, | ||
private workflowService: WorkflowService) { | ||
|
||
super(); | ||
} | ||
|
||
ngOnInit() { | ||
|
||
// Retrieving all workflows from backend. | ||
this.generalService.showLoading(); | ||
this.workflowService.getWorkflowActions().subscribe({ | ||
|
||
next: (result: any[]) => { | ||
|
||
this.generalService.hideLoading(); | ||
|
||
result = (result || []).filter(x => x.filename.indexOf('execute-workflow') === -1 && x.filename.indexOf('execute-action') === -1); | ||
|
||
for (const idx of result) { | ||
(<any[]>this.field.props.options).push({ | ||
value: idx.filename, | ||
label: idx.filename, | ||
complete: true, | ||
}); | ||
} | ||
}, | ||
|
||
error: (error: any) => { | ||
|
||
this.generalService.showFeedback(error?.error?.message ?? error, 'errorMessage'); | ||
this.generalService.hideLoading(); | ||
} | ||
}); | ||
|
||
this.filteredOptions = this.formControl.valueChanges.pipe( | ||
startWith(this.model[<string>this.field.key]), | ||
map(value => this._filter(value || '')), | ||
); | ||
this.formControl.setValue(this.field.model[<string>this.field.key]); | ||
this.formControl.valueChanges.subscribe((val: string) => { | ||
this.model[<string>this.field.key] = val; | ||
}); | ||
} | ||
|
||
optionSelected(e: MatAutocompleteActivatedEvent) { | ||
|
||
// Verifying this is a filename reference. | ||
this.generalService.showLoading(); | ||
if (e.option.value.startsWith('/') && e.option.value.endsWith('.hl')) { | ||
|
||
// Retrieving arguments workflow file can handle. | ||
this.workflowService.getArgumentsForFile(e.option.value).subscribe({ | ||
|
||
next: (result: any) => { | ||
|
||
this.generalService.hideLoading(); | ||
this.props.change.call(this, result); | ||
}, | ||
|
||
error: (error: any) => { | ||
|
||
this.generalService.showFeedback(error?.error?.message ?? error, 'errorMessage'); | ||
this.generalService.hideLoading(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/* | ||
* Private helper methods. | ||
*/ | ||
|
||
private _filter(value: string): any[] { | ||
|
||
if (!value) { | ||
return <any[]>this.field.props.options; | ||
} | ||
|
||
const filterValue = value.toLowerCase(); | ||
return (<any[]>this.field.props.options).filter(option => option.label.toLowerCase().includes(filterValue)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...yper-ide/components/parametrise-action-dialog/components/formly-action/formly-action.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
mat-option.warning { | ||
background-color: #fff0f0; | ||
} | ||
|
||
mat-option.warning:hover, | ||
mat-option.warning:active { | ||
background-color: #f0e0e0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters