Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Dec 26, 2023
1 parent fbfa961 commit 9552058
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 18 deletions.
21 changes: 21 additions & 0 deletions backend/files/system/workflows/apply-arguments.post.hl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
.arguments
hyperlambda:string
description:string
args:*

// Verifying user is authorized to access endpoint.
Expand All @@ -30,6 +31,26 @@ else
.
.arguments

// Checking if caller provided a description.
remove-nodes:x:@hyper2lambda/0/[0,1]/\..
if
and
exists:x:@.arguments/*/description
not-null:x:@.arguments/*/description
neq:x:@.arguments/*/description
.:
.lambda
strings.replace:x:@.arguments/*/description
.:"\r\n"
.:"\n"
strings.replace:x:@strings.replace
.:"\n"
.:"\r\n"
unwrap:x:+/*/*
insert-before:x:@hyper2lambda/0
.
..:x:@strings.replace

// Returning updated Hyperlambda to caller.
lambda2hyper:x:@hyper2lambda/*
comments:true
Expand Down
16 changes: 15 additions & 1 deletion backend/files/system/workflows/get-file-arguments.post.hl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@ auth.ticket.verify:root

// Converting Hyperlambda to lambda.
hyper2lambda:x:@.arguments/*/hyperlambda
comments:true

// Iterating through each argument Hyperlambda can handle.
for-each:x:@hyper2lambda/*/.arguments/*
set-name:x:+/+/*/*
get-name:x:@.dp/#
unwrap:x:+/*/*
add:x:../*/return-nodes
add:x:../*/return-nodes/*/args
.
name:x:@.dp/#

// Fetching description if existing.
.desc
if
eq
get-name:x:@hyper2lambda/0
.:..
.lambda
set-value:x:@.desc
get-value:x:@hyper2lambda/0

// Returning arguments to caller, together with their type information.
unwrap:x:+/*
return-nodes
args
description:x:@.desc
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export class IdeEditorComponent implements OnInit, OnDestroy, OnChanges {
this.generalService.showLoading();
this.workflowService.getArguments(this.currentFileData.content).subscribe({

next: (result: any[]) => {
next: (result: any) => {

this.generalService.hideLoading();
this.dialog.open(ParametriseActionDialog, {
Expand All @@ -550,14 +550,19 @@ export class IdeEditorComponent implements OnInit, OnDestroy, OnChanges {
data: {
name: this.currentFileData.path,
is_action: false,
description: 'Edit arguments your Hyperlambda file can handle?',
description: 'Edit description and arguments your Hyperlambda file can handle?',
input: {
description: {
type: 'textarea',
noCandidates: true,
},
arguments: {
type: 'key-value',
},
},
model: {
arguments: result,
arguments: result.args,
description: result.description,
},
candidates: [
{ value: 'string', label: 'string' },
Expand All @@ -584,7 +589,10 @@ export class IdeEditorComponent implements OnInit, OnDestroy, OnChanges {
if (args) {

this.generalService.showLoading();
this.workflowService.applyArguments(this.currentFileData.content, args.arguments).subscribe({
this.workflowService.applyArguments(
this.currentFileData.content,
args.description,
args.arguments).subscribe({

next: (response: MagicResponse) => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,10 @@ export class IdeTreeComponent implements OnInit {
is_action: false,
description: 'What arguments can your Hyperlambda file handle?',
input: {
description: {
type: 'textarea',
noCandidates: true,
},
arguments: {
type: 'key-value',
},
Expand Down Expand Up @@ -749,7 +753,10 @@ export class IdeTreeComponent implements OnInit {
if (args) {

this.generalService.showLoading();
this.workflowService.applyArguments(fileContent, args.arguments).subscribe({
this.workflowService.applyArguments(
fileContent,
args.description,
args.arguments).subscribe({

next: (response: MagicResponse) => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ export class ParametriseActionDialog implements OnInit {
add = true;
field.type = 'key-value';
field.props.options = [];
for (const idxCandidate of this.data.candidates) {
field.props.options.push({
value: idxCandidate.value,
label: idxCandidate.label,
});
if (!this.data.input[idx].noCandidates || this.data.input[idx].noCandidates === false) {
for (const idxCandidate of this.data.candidates) {
field.props.options.push({
value: idxCandidate.value,
label: idxCandidate.label,
});
}
}
break;

Expand Down Expand Up @@ -106,11 +108,13 @@ export class ParametriseActionDialog implements OnInit {
}
}
}
for (const idxCandidate of this.data.candidates) {
field.props.options.push({
value: idxCandidate.value,
label: idxCandidate.label,
});
if (!this.data.input[idx].noCandidates || this.data.input[idx].noCandidates === false) {
for (const idxCandidate of this.data.candidates) {
field.props.options.push({
value: idxCandidate.value,
label: idxCandidate.label,
});
}
}
break;

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/app/services/workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ export class WorkflowService {
/**
* Applies the specified arguments to the specified Hyperlambda and returns to caller.
*/
applyArguments(hyperlambda: string, args: any) {
applyArguments(hyperlambda: string, description: string, args: any) {

return this.httpService.post<MagicResponse>('/magic/system/workflows/apply-arguments', {
hyperlambda,
description,
args,
});
}
Expand All @@ -75,7 +76,7 @@ export class WorkflowService {
*/
getArguments(hyperlambda: string) {

return this.httpService.post<any[]>('/magic/system/workflows/get-file-arguments', {
return this.httpService.post<any>('/magic/system/workflows/get-file-arguments', {
hyperlambda,
});
}
Expand Down

0 comments on commit 9552058

Please sign in to comment.