Make services selectable via dropdown
Change-Id: I575abcd51c9acb3a3f74526c8cb1fd99a4dcd585
Signed-off-by: Fauth Dirk <Dirk.Fauth@de.bosch.com>
diff --git a/manager/src/main/java/org/eclipse/app4mc/cloud/manager/WorkflowController.java b/manager/src/main/java/org/eclipse/app4mc/cloud/manager/WorkflowController.java
index 7020d82..7b21e2d 100644
--- a/manager/src/main/java/org/eclipse/app4mc/cloud/manager/WorkflowController.java
+++ b/manager/src/main/java/org/eclipse/app4mc/cloud/manager/WorkflowController.java
@@ -88,6 +88,23 @@
return "workflow";
}
+ @PostMapping("/select/{selected}")
+ public String selectService(
+ @PathVariable(name = "selected") String selected,
+ @ModelAttribute WorkflowStatus ws) {
+
+ ws.addSelectedService(selected);
+
+ // render the form view
+ return "workflow";
+ }
+
+ @GetMapping("/selectedServices")
+ public String getSelectedServices() {
+ // render the servicesList fragment contained in selectedServices.html
+ return "selectedServices :: servicesList";
+ }
+
@PostMapping("/workflow")
public String handleFileUpload(
@RequestParam("file") MultipartFile file,
@@ -104,7 +121,7 @@
final WorkflowStatus workflowStatus = ws;
if (file.isEmpty()) {
- workflowStatus.addMessage("Select a file to upload");
+ workflowStatus.addError("Select a file to upload");
return "redirect:/workflow";
}
@@ -118,6 +135,10 @@
if (services != null) {
Path inputFile = storageService.load(uuid, file.getOriginalFilename());
for (String service : services) {
+ if (StringUtils.isEmpty(service)) {
+ continue;
+ }
+
// if an error occurred stop the workflow
if (!workflowStatus.getErrors().isEmpty()) {
break;
@@ -193,7 +214,7 @@
statusUrl = getUrlFromLink(uploadResponse.getHeaders().get("Link"), "status");
} else {
// error
- workflowStatus.addError("Upload to " + serviceName + " failed! Workflow stopped!");
+ workflowStatus.addError("Upload to " + serviceName + " failed! Error code: " + uploadResponse.getStatus() + " - Workflow stopped!");
return null;
}
@@ -277,7 +298,7 @@
} else {
String errorUrl = getUrlFromLink(linkHeaders, "error");
if (errorUrl != null) {
- workflowStatus.addMessage(serviceName + " processing finished with error");
+ workflowStatus.addError(serviceName + " processing finished with error");
// download error file
Path migrationSubDir = storageService.load(workflowStatus.getUuid(), "_" + serviceName.toLowerCase());
diff --git a/manager/src/main/java/org/eclipse/app4mc/cloud/manager/WorkflowStatus.java b/manager/src/main/java/org/eclipse/app4mc/cloud/manager/WorkflowStatus.java
index 469a192..0fb9b85 100644
--- a/manager/src/main/java/org/eclipse/app4mc/cloud/manager/WorkflowStatus.java
+++ b/manager/src/main/java/org/eclipse/app4mc/cloud/manager/WorkflowStatus.java
@@ -20,6 +20,7 @@
public class WorkflowStatus {
private String uuid;
+ private ArrayList<String> selectedServices = new ArrayList<>();
private ArrayList<String> messages = new ArrayList<>();
private ArrayList<String> errors = new ArrayList<>();
private HashMap<String, String> results = new LinkedHashMap<>();
@@ -32,6 +33,14 @@
this.uuid = uuid;
}
+ public ArrayList<String> getSelectedServices() {
+ return selectedServices;
+ }
+
+ public void addSelectedService(String service) {
+ this.selectedServices.add(service);
+ }
+
public ArrayList<String> getMessages() {
return messages;
}
@@ -57,6 +66,7 @@
}
public void clear() {
+ this.selectedServices.clear();
this.messages.clear();
this.errors.clear();
this.results.clear();
diff --git a/manager/src/main/resources/templates/selectedServices.html b/manager/src/main/resources/templates/selectedServices.html
new file mode 100644
index 0000000..904f5f0
--- /dev/null
+++ b/manager/src/main/resources/templates/selectedServices.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html xmlns:th="https://www.thymeleaf.org">
+
+<head>
+</head>
+
+<body>
+ <div th:fragment="servicesList" id="selectedServices">
+ <span th:each="selected : ${workflowStatus.selectedServices}">
+ <select name="services" id="services" onchange="updateSelectedServices(this.value)">
+ <option></option>
+ <option
+ th:each="service : ${cloudServiceDefinitions}"
+ th:text="${service.name}"
+ th:value="${service.name}"
+ th:selected="${service.name == selected}">
+ </option>
+ </select><br>
+ </span>
+ <select name="services" id="services" onchange="updateSelectedServices(this.value)">
+ <option></option>
+ <option
+ th:each="service : ${cloudServiceDefinitions}"
+ th:text="${service.name}"
+ th:value="${service.name}"
+ th:selected="${service.name == selected}">
+ </option>
+ </select><br>
+ </div>
+</body>
+</html>
diff --git a/manager/src/main/resources/templates/workflow.html b/manager/src/main/resources/templates/workflow.html
index 9a18fbe..48d1c34 100644
--- a/manager/src/main/resources/templates/workflow.html
+++ b/manager/src/main/resources/templates/workflow.html
@@ -1,7 +1,23 @@
<html xmlns:th="https://www.thymeleaf.org">
<head>
- <title>APP4MC Cloud Manager - Workflow</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>APP4MC Cloud Manager - Workflow</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
+<script type="text/javascript">
+function updateSelectedServices(service) {
+ $.ajax({
+ type: 'POST',
+ url: '/select/' + service,
+ success: function(result) {
+ $('#selectedServicesBlock').load('/selectedServices');
+ }
+ });
+}
+
+$(document).ready(function(){
+ $('#selectedServicesBlock').load('/selectedServices');
+});
+</script>
</head>
<body>
@@ -10,11 +26,11 @@
<table>
<tr><td>Select input file to process:</td><td><input type="file" name="file" /></td></tr>
<tr>
- <td>Select service(s) to process:</td>
+ <td valign="top">Select service(s) to process:</td>
<td>
- <span th:each="service : ${cloudServiceDefinitions}">
- <input type="checkbox" name="services" th:text="${service.name}" th:value="${service.name}" /><br>
- </span>
+ <div id="selectedServicesBlock">
+
+ </div>
</td>
</tr>
<tr>