Skip to content

Commit 1fa7184

Browse files
author
eznedan
committed
ADD: delete btn
1 parent 5a2f0e3 commit 1fa7184

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

src/main/java/com/ericsson/ei/frontend/WebController.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ public ResponseEntity<String> switchBackEndInstance(Model model, HttpServletRequ
143143
}
144144
}
145145

146+
@RequestMapping(value = "/switch-backend", method = RequestMethod.DELETE)
147+
public ResponseEntity<String> deleteBackEndInstance(Model model, HttpServletRequest request) {
148+
try {
149+
String body = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
150+
utils.setInstances(new JSONArray(body));
151+
utils.writeIntoFile();
152+
utils.parseBackEndInstancesFile();
153+
return new ResponseEntity<>(HttpStatus.OK);
154+
} catch (Exception e) {
155+
return new ResponseEntity<>("Internal error", HttpStatus.INTERNAL_SERVER_ERROR);
156+
}
157+
}
158+
146159
@RequestMapping(value = "/add-instances", method = RequestMethod.POST)
147160
public ResponseEntity<String> addInstanceInformation(Model model, HttpServletRequest request) {
148161
try {

src/main/java/com/ericsson/ei/frontend/model/BackEndInformation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.springframework.beans.factory.annotation.Value;
88
import org.springframework.stereotype.Component;
99

10+
import javax.validation.constraints.Max;
11+
import javax.validation.constraints.Min;
1012
import javax.validation.constraints.NotNull;
1113

1214
@Getter
@@ -27,7 +29,7 @@ public class BackEndInformation {
2729

2830
@JsonProperty("port")
2931
@Value("${ei.backendServerPort}")
30-
@NotNull
32+
@NotNull @Min(1) @Max(65535)
3133
private int port;
3234

3335
@JsonProperty("path")
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
[{"path":"","port":8090,"name":"core","host":"localhost","checked":true,"https":false},{"path":"","port":8098,"name":"test","host":"localhost23","checked":false,"https":false},{"path":"","port":"567","name":"hgjghj","host":"ghjghj","checked":false,"https":false}]
1+
[
2+
{
3+
"path": "",
4+
"port": 8091,
5+
"name": "core",
6+
"host": "localhost",
7+
"checked": false,
8+
"https": false
9+
},
10+
{
11+
"path": "/eiffel",
12+
"port": 8080,
13+
"name": "test",
14+
"host": "localhost23",
15+
"checked": true,
16+
"https": false
17+
}
18+
]

src/main/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ server.port=8080
1313

1414
######## EI Backend
1515
ei.frontendServiceHost=localhost
16-
ei.frontendServicePort=8080
16+
ei.frontendServicePort=8092
1717
ei.frontendContextPath=
1818
ei.backendServerHost=localhost
19-
ei.backendServerPort=8090
19+
ei.backendServerPort=8091
2020
ei.backendContextPath=
2121
ei.useSecureHttp=false
2222
ei.backendInstancesPath=src\\main\\resources\\EIBackendInstancesExample.json

src/main/resources/static/js/switch-instances.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ jQuery(document).ready(function() {
2222

2323
self.removeInstance = function() {
2424
self.instances.remove(this);
25+
$.ajax({
26+
url: "/switch-backend",
27+
type: "DELETE",
28+
data: ko.toJSON(self.instances),
29+
contentType: 'application/json; charset=utf-8',
30+
cache: false,
31+
error: function (XMLHttpRequest, textStatus, errorThrown) {
32+
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
33+
},
34+
success: function (responseData, textStatus) {
35+
$.jGrowl("Backend instance was deleted", {sticky: false, theme: 'Notify'});
36+
$("#mainFrame").load("switch-backend.html");
37+
}
38+
});
2539
}
2640

2741
self.submit = function(instances) {

0 commit comments

Comments
 (0)