Skip to content

Commit e74eb7d

Browse files
author
Mark Robinson
committed
Use github permalinks for redirects and links
1 parent addb177 commit e74eb7d

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,36 +82,30 @@ public ModelAndView newWorkflowFromGithubURL(@Valid WorkflowForm workflowForm, B
8282
// Go back to index if there are validation errors
8383
return new ModelAndView("index");
8484
} else {
85-
// The ID of the workflow to be redirected to
86-
String workflowID;
87-
8885
// Check database for existing workflow
89-
Workflow existingWorkflow = workflowRepository.findByRetrievedFrom(githubInfo);
90-
if (existingWorkflow != null) {
86+
Workflow workflow = workflowRepository.findByRetrievedFrom(githubInfo);
87+
if (workflow != null) {
9188
logger.info("Fetching existing workflow from DB");
92-
93-
// Get the ID from the existing workflow
94-
workflowID = existingWorkflow.getID();
9589
} else {
9690
// New workflow from Github URL
97-
Workflow newWorkflow = workflowFactory.workflowFromGithub(githubInfo);
91+
workflow = workflowFactory.workflowFromGithub(githubInfo);
9892

9993
// Runtime error
100-
if (newWorkflow == null) {
94+
if (workflow == null) {
10195
bindingResult.rejectValue("githubURL", "githubURL.parsingError");
10296
return new ModelAndView("index");
10397
}
10498

10599
// Save to the MongoDB database
106100
logger.info("Adding new workflow to DB");
107-
workflowRepository.save(newWorkflow);
108-
109-
// Get the ID from the new workflow
110-
workflowID = newWorkflow.getID();
101+
workflowRepository.save(workflow);
111102
}
112103

113104
// Redirect to the workflow
114-
return new ModelAndView("redirect:/workflows/" + workflowID);
105+
GithubDetails githubDetails = workflow.getRetrievedFrom();
106+
return new ModelAndView("redirect:/workflows/github.com/" + githubDetails.getOwner()
107+
+ "/" + githubDetails.getRepoName() + "/tree/" + githubDetails.getBranch()
108+
+ "/" + githubDetails.getPath());
115109
}
116110
}
117111

src/main/resources/templates/workflow.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ <h4 class="modal-title" id="dotGraphLabel">Workflow DOT Graph</h4>
9898

9999
<div class="container">
100100
<div class="row">
101-
<div class="col-md-12" role="main" id="main">
101+
<div class="col-md-12" role="main" id="main" th:with="workflowURL=@{'github.com/' + ${workflow.retrievedFrom.owner} + '/' + ${workflow.retrievedFrom.repoName} + '/tree/' + ${workflow.retrievedFrom.branch} + '/' + ${workflow.retrievedFrom.path}}">
102102
<h2>Workflow: <span th:text="${workflow.label}">Workflow Name</span></h2>
103103
<p>
104-
<a th:href="@{'https://github.com/' + ${workflow.retrievedFrom.owner} + '/' + ${workflow.retrievedFrom.repoName} + '/tree/' + ${workflow.retrievedFrom.branch} + '/' + ${workflow.retrievedFrom.path}}" href="#" rel="noopener" target="_blank">
104+
<a th:href="@{'https://' + ${workflowURL}}" href="#" rel="noopener" target="_blank">
105105
<img id="githubLogo" src="../static/img/GitHub-Mark-32px.png" th:src="@{/img/GitHub-Mark-32px.png}" width="24" height="24" />
106106
</a>
107107
<i>Fetched <span th:text="${{workflow.retrievedOn}}">01/12/16 at 21:00</span></i>
108-
<span th:if="${workflow.roBundle == null}"> - Generating download link&hellip; [<a th:href="@{'/workflows/' + ${workflow.id}}" href="#">Refresh</a>]</span>
108+
<span th:if="${workflow.roBundle == null}"> - Generating download link&hellip; [<a th:href="@{'/workflows/' + ${workflowURL}}" href="#">Refresh</a>]</span>
109109
<span th:if="${workflow.roBundle != null}">
110110
- <a th:href="@{'/workflows/' + ${workflow.id} + '/download'}" href="#" download="bundle.zip">Download as Research Object Bundle</a>
111111
<a href="http://www.researchobject.org/" rel="noopener" target="_blank">[?]</a>

0 commit comments

Comments
 (0)