Skip to content

Commit 2bfa88a

Browse files
author
Mark Robinson
committed
Redirect to index with form filled if workflow not yet generated for URL
1 parent e74eb7d commit 2bfa88a

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/main/java/org/commonwl/viewer/domain/WorkflowForm.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
*/
2626
public class WorkflowForm {
2727

28+
public WorkflowForm() {}
29+
30+
public WorkflowForm(String githubURL) {
31+
this.githubURL = githubURL;
32+
}
33+
2834
private String githubURL;
2935

3036
public String getGithubURL() {

src/main/java/org/commonwl/viewer/web/PageController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.stereotype.Controller;
2424
import org.springframework.ui.Model;
2525
import org.springframework.web.bind.annotation.GetMapping;
26+
import org.springframework.web.bind.annotation.RequestParam;
2627

2728
@Controller
2829
public class PageController {
@@ -33,8 +34,8 @@ public class PageController {
3334
* @return The view for this page
3435
*/
3536
@GetMapping("/")
36-
public String homePage(Model model) {
37-
model.addAttribute("workflowForm", new WorkflowForm());
37+
public String homePage(Model model, @RequestParam(value = "url", required = false) String defaultURL) {
38+
model.addAttribute("workflowForm", new WorkflowForm(defaultURL));
3839
return "index";
3940
}
4041

src/main/java/org/commonwl/viewer/web/WorkflowController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ public ModelAndView getWorkflowByGithubDetails(@PathVariable("owner") String own
154154
// Get workflow from database
155155
Workflow workflowModel = workflowRepository.findByRetrievedFrom(githubDetails);
156156

157-
// 404 error if workflow does not exist
157+
// Redirect to index with form autofilled if workflow does not already exist
158158
if (workflowModel == null) {
159-
throw new WorkflowNotFoundException();
159+
return new ModelAndView("redirect:/?url=https://github.com/" +
160+
owner + "/" + repoName + "/tree/" + branch + "/" + path);
160161
}
161162

162163
// Display this model along with the view

src/main/resources/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h2>Workflow from Github URL</h2>
5050
<strong>Error:</strong> <span th:errors="*{githubURL}">Error message here</span>
5151
</div>
5252
<div class="input-group">
53-
<input type="text" class="form-control" placeholder="Github URL" id="githubURL" name="githubURL" th:field="*{githubURL}" />
53+
<input type="text" class="form-control" placeholder="Github URL" id="githubURL" name="githubURL" th:field="*{githubURL}" th:value="${formURL}" />
5454
<span class="input-group-btn">
5555
<button class="btn btn-primary" type="submit">Parse Workflow</button>
5656
</span>

0 commit comments

Comments
 (0)