Skip to content

Commit

Permalink
Added new workflow/functions endpoint and create workflow option (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdkiran authored Aug 13, 2024
1 parent 19bf60a commit d35eb0b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
12 changes: 12 additions & 0 deletions services/workflowService.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,15 @@ func CreateWorkflow(topicName string, functionName string, sinkURL string) (pers
newWorkflow.LastModified = last_modified
return newWorkflow, nil
}

func GetAvaliableWorkflowFunctions() []string {
keys := make([]string, len(persistence.FUNC_MAP))

i := 0
for f := range persistence.FUNC_MAP {
keys[i] = f
i++
}

return keys
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class WorkflowsHome extends HTMLElement {
super()
this.shawdow = this.attachShadow({mode: "open"})
this.shawdow.append(jobsHomeTemplate.content.cloneNode(true))
this.workflowfunctions = []
this.topicNames = []
}

newWorkflow(e) {
Expand Down Expand Up @@ -48,14 +50,17 @@ class WorkflowsHome extends HTMLElement {
}

newWorkflowAction() {
const functionOptions = this.workflowfunctions.map((func) => {return `<option value="${func}">${func}</option>`})
const topicOptions = this.topicNames.map((topic) => {return `<option value="${topic}">${topic}</option>`})

const modalMarkup = `
<wc-modal id="modalThing">
<wc-title>Create New Workflow</wc-title>
<form id="myForm">
<label for="topicName">Topic Name:</label><br>
<input type="text" id="topicName" name="topicName" value=""><br>
<select id="topicName" name="topicName">${topicOptions.join()}</select><br>
<label for="functionName">Function Name:</label><br>
<input type="text" id="functionName" name="functionName" value=""><br>
<select id="functionName" name="functionName">${functionOptions.join()}</select><br>
<label for="sinkURL">Sink Url:</label><br>
<input type="text" id="sinkURL" name="sinkURL" value=""><br>
<br>
Expand Down Expand Up @@ -93,7 +98,23 @@ class WorkflowsHome extends HTMLElement {
return workflow_card_container
}

async getWorkflowFunctions() {
const workflowFunctionsResponse = await fetch('/api/v1/workflow/functions');
const workflowFunctionsResponseData = await workflowFunctionsResponse.json();
this.workflowfunctions = workflowFunctionsResponseData.data
}

async getTopicNames() {
const topicsResponse = await fetch('/api/v1/topic');
const topicsResponseData = await topicsResponse.json();
const topicNames = topicsResponseData.data.map((topic) => {return topic.topicName})
this.topicNames = topicNames
}

async connectedCallback(){
// Async process workflow functions and topics
this.getWorkflowFunctions()
this.getTopicNames()
const pageTitleElement = document.createElement("wc-page-heading-button")
pageTitleElement.innerText = "All Workflows";
pageTitleElement.buttonText = 'New Workflow';
Expand Down
18 changes: 16 additions & 2 deletions web/workflowApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
)

var (
workflowsAllApi = regexp.MustCompile(`^\/api/v1/workflow[\/]*$`)
workflowSingleApi = regexp.MustCompile(`^\/api/v1/workflow\/(.*)$`)
workflowFunctionApi = regexp.MustCompile(`^\/api/v1/workflow/functions[\/]*$`)
workflowsAllApi = regexp.MustCompile(`^\/api/v1/workflow[\/]*$`)
workflowSingleApi = regexp.MustCompile(`^\/api/v1/workflow\/(.*)$`)
)

type workflowAPI struct {
Expand All @@ -26,6 +27,8 @@ func (wf *workflowAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
switch {
case r.Method == http.MethodGet && workflowFunctionApi.MatchString(r.URL.Path):
wf.getWorkflowFunctions(w, r)
case r.Method == http.MethodGet && workflowsAllApi.MatchString(r.URL.Path):
wf.getWorkflows(w, r)
return
Expand Down Expand Up @@ -175,3 +178,14 @@ func (wf *workflowAPI) deleteWorkflow(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(resJsonBytes)
}

func (wf *workflowAPI) getWorkflowFunctions(w http.ResponseWriter, _ *http.Request) {
workflowFunctions := services.GetAvaliableWorkflowFunctions()
resJsonBytes, err := generateSuccessMessage(workflowFunctions)
if err != nil {
apiMessageResponse(w, http.StatusInternalServerError, "internal server error")
return
}
w.WriteHeader(http.StatusOK)
w.Write(resJsonBytes)
}

0 comments on commit d35eb0b

Please sign in to comment.