-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #6
- Loading branch information
Showing
8 changed files
with
221 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.codeka.gaia.bo; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Gaia settings | ||
*/ | ||
@ConfigurationProperties(prefix = "gaia") | ||
@Component | ||
public class Settings { | ||
|
||
/** | ||
* Gaia's external url (used to allow runners to speak to Gaia) | ||
*/ | ||
private String externalUrl; | ||
|
||
public String getExternalUrl() { | ||
return externalUrl; | ||
} | ||
|
||
public void setExternalUrl(String externalUrl) { | ||
this.externalUrl = externalUrl; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/io/codeka/gaia/controller/SettingsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.codeka.gaia.controller; | ||
|
||
import io.codeka.gaia.bo.Settings; | ||
import io.codeka.gaia.bo.TerraformModule; | ||
import io.codeka.gaia.repository.TerraformModuleRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* The controller for the settings mgmt | ||
*/ | ||
@Controller | ||
public class SettingsController { | ||
|
||
private Settings settings; | ||
|
||
@Autowired | ||
public SettingsController(Settings settings) { | ||
this.settings = settings; | ||
} | ||
|
||
@GetMapping("/settings") | ||
public String settings(Model model){ | ||
model.addAttribute("settings", settings); | ||
|
||
return "settings"; | ||
} | ||
|
||
@PutMapping("/settings") | ||
public String saveModule(@RequestBody Settings settings){ | ||
// update global settings bean | ||
this.settings.setExternalUrl( settings.getExternalUrl() ); | ||
return "settings"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | ||
<head th:replace="layout/header :: header(~{::title})"> | ||
|
||
<title>Gaia - Edit module</title> | ||
|
||
</head> | ||
<body class="dashboard dashboard_2"> | ||
<div class="full_container"> | ||
<div class="inner_container"> | ||
|
||
<div th:replace="~{layout/sidebar}"></div> | ||
|
||
<!-- right content --> | ||
<div id="content"> | ||
|
||
<div th:replace="~{layout/topbar}"></div> | ||
|
||
<div class="midde_cont"> | ||
<div class="container-fluid"> | ||
<div class="row column_title"> | ||
<div class="col-md-12"> | ||
<div class="page_title"> | ||
<h2> Gaia's Settings </h2> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="white_shd full"> | ||
|
||
<div id="app"></div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
<!-- jQuery & bootstrap--> | ||
<script src="webjars/jquery/3.0.0/jquery.min.js"></script> | ||
<script src="webjars/popper.js/1.14.3/popper.min.js"></script> | ||
<script src="webjars/bootstrap/4.3.1/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> | ||
|
||
<template id="template"> | ||
<div> | ||
<div class="full graph_head"> | ||
<div class="heading1 margin_0"> | ||
<h2>Settings</h2> | ||
</div> | ||
</div> | ||
|
||
<div class="padding_infor_info"> | ||
<div class="form-group"> | ||
<label for="externalUrl">External url</label> | ||
<input type="text" class="form-control" id="externalUrl" v-model="externalUrl"> | ||
<small>This is gaia's external URL. This is needed to allow terraform backend support.</small> | ||
</div> | ||
|
||
<button class="btn btn-primary" onclick="saveSettings()"><i class="far fa-save"></i> Save</button> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script src="/webjars/jquery/3.0.0/jquery.min.js"></script> | ||
<script src="/webjars/popper.js/1.14.3/umd/popper.min.js"></script> | ||
<script src="/webjars/bootstrap/4.3.1/js/bootstrap.min.js"></script> | ||
|
||
<script src="/webjars/vue/2.5.16/vue.js"></script> | ||
|
||
<script th:inline="javascript" type="application/ecmascript"> | ||
const settings = [[${settings}]]; | ||
|
||
new Vue({ | ||
el: "#app", | ||
data : settings, | ||
template: "#template" | ||
}); | ||
|
||
function saveSettings(){ | ||
$.ajax({ | ||
url: `/settings`, | ||
data: JSON.stringify(settings), | ||
contentType: "application/json", | ||
method: "PUT" | ||
}) | ||
} | ||
</script> | ||
|
||
<script type="application/ecmascript"> | ||
$(document).ready(function () { | ||
/*-- sidebar js --*/ | ||
$('#sidebarCollapse').on('click', function () { | ||
$('#sidebar').toggleClass('active'); | ||
}); | ||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.codeka.gaia.bo; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SpringBootTest | ||
@TestPropertySource(properties = "gaia.externalUrl=http://172.17.0.1:8080") | ||
class SettingsTest { | ||
|
||
@Autowired | ||
private Settings settings; | ||
|
||
@Test | ||
void settingsShouldNotBeNull(){ | ||
assertNotNull(settings); | ||
} | ||
|
||
@Test | ||
void externalUrl_shouldBeConfigurableViaProperty(){ | ||
assertEquals("http://172.17.0.1:8080", settings.getExternalUrl()); | ||
} | ||
|
||
} |