Skip to content
Snippets Groups Projects
Commit 37f55b67 authored by Ondřej Trojan's avatar Ondřej Trojan
Browse files

moved language change

parent 07b563a7
No related branches found
No related tags found
No related merge requests found
package com.museum.projection.controller;
import com.museum.projection.dao.ResponseData;
import com.museum.projection.dto.DisplaySetDto;
import com.museum.projection.dto.DisplayTrackDto;
import com.museum.projection.service.DisplaySetService;
import com.museum.projection.service.DisplayTrackService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import javax.annotation.Resource;
import java.security.Principal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.springframework.http.HttpStatus.NOT_FOUND;
@RestController
@RequestMapping("/api")
public class RestApiController {
@Resource
private DisplaySetService displaySetService;
@Resource
private DisplayTrackService displayTrackService;
@GetMapping("/test")
public String get() {
return "Test response from authorized endpoint";
}
@GetMapping(value = "/displaysets", produces = "application/json")
public List<DisplaySetDto> displaySets() {
return displaySetService.getAllDisplaySets();
}
@GetMapping(value = "/displaysets/{id}", produces = "application/json")
public DisplaySetDto displaySetById(@PathVariable String id) {
ResponseData<DisplaySetDto> found = displaySetService.getDisplaySetById(id);
if (found.getData() == null)
throw new ResponseStatusException(NOT_FOUND, "Unable to find display set with id " + id);
return found.getData();
}
@GetMapping(value = "/displaysets/{id}/displaytracks", produces = "application/json")
public List<DisplayTrackDto> displayTracksOfdisplaySetById(@PathVariable String id) {
ResponseData<DisplaySetDto> found = displaySetService.getDisplaySetById(id);
if (found.getData() == null)
throw new ResponseStatusException(NOT_FOUND, "Unable to find display set with id " + id);
return displayTrackService.getDisplayTracksByDisplaySetId(found.getData().getId());
}
@GetMapping(value = "/user", produces = "application/json")
public Map<String, String> currentUser(Principal principal){
return Map.of("username", principal.getName());
}
@GetMapping(value = "/displaytracks", produces = "application/json")
public List<DisplayTrackDto> displayTracks() {
return displayTrackService.getAllDisplayTracks();
}
@GetMapping(value = "/displaytracks/{id}", produces = "application/json")
public DisplayTrackDto displayTrackById(@PathVariable String id) {
ResponseData<DisplayTrackDto> found = displayTrackService.getDisplayTrackById(id);
if (found.getData() == null)
throw new ResponseStatusException(NOT_FOUND, "Unable to find display Track with id " + id);
return found.getData();
}
@ExceptionHandler({ ResponseStatusException.class})
public ResponseEntity<Map<String, Object>> handleException(ResponseStatusException ex) {
System.out.println("Handle ResponseStatusException");
Map<String,Object> ret = new HashMap<>();
ret.put("error", ex.getReason());
ret.put("timestamp", new Timestamp((new Date()).getTime()));
ret.put("status",ex.getStatus());
ResponseEntity< Map<String,Object>> entity = new ResponseEntity<>(ret, ex.getStatus());
return entity;
}
}
......@@ -106,13 +106,13 @@ public class ControlService {
public int getTime(int clientId) {
String command = "get_time";
List<String> ret = sendCommand(getRemoteClient(clientId), command);
return Integer.parseInt(ret.get(0));
return ret.get(0).equals("") ? 0 : Integer.parseInt(ret.get(0));
}
public int getLength(int clientId) {
String command = "get_length";
List<String> ret = sendCommand(getRemoteClient(clientId), command);
return Integer.parseInt(ret.get(0));
return ret.get(0).equals("") ? 0 : Integer.parseInt(ret.get(0));
}
public void play() {
......@@ -136,7 +136,7 @@ public class ControlService {
//TODO remove this from dev
sendCommand(getRemoteClient(i), "add", config.getPlaylistFolderPath().replace("otrojan", "user") + PlaylistService.getPlaylistName(playlistName));
}
logService.createLog("Playlist " + playlistName + " has been set to play");
logService.createLog("Playlist " + playlistName + " has been set to play");
}
public void readCurrentPlaylist(int clientId) {
......
......@@ -26,6 +26,12 @@ a.nav-menu.checked {
color: #007bff !important;
}
.divider-vertical {
height: 40px;
margin: 0 9px;
border-left: 1px solid #F2F2F2;
border-right: 1px solid #FFF;
}
/*Documentation*/
.bd-toc {
......
......@@ -11,15 +11,15 @@
<div class="col">
<span class="text-muted" th:text="#{footer.info}"></span>
</div>
<div class="col text-right">
<span class="text-muted" th:text="#{lang.name}"> </span>&nbsp
<!-- <span>&nbsp</span>-->
<select class="btn btn-sm btn-outline-secondary" id="locales">
<option class="btn btn-sm" th:unless="${#locale.toString() == 'cz' }" value="en" th:text="#{lang.eng}"></option>
<option class="btn btn-sm" value="cz" th:text="#{lang.cz}"></option>
<option class="btn btn-sm" th:if="${#locale.toString() == 'cz' }" value="en" th:text="#{lang.eng}"></option>
</select>
</div>
<!-- <div class="col text-right">-->
<!-- <span class="text-muted" th:text="#{lang.name}"> </span>&nbsp-->
<!--&lt;!&ndash; <span>&nbsp</span>&ndash;&gt;-->
<!-- <select class="btn btn-sm btn-outline-secondary" id="locales">-->
<!-- <option class="btn btn-sm" th:unless="${#locale.toString() == 'cz' }" value="en" th:text="#{lang.eng}"></option>-->
<!-- <option class="btn btn-sm" value="cz" th:text="#{lang.cz}"></option>-->
<!-- <option class="btn btn-sm" th:if="${#locale.toString() == 'cz' }" value="en" th:text="#{lang.eng}"></option>-->
<!-- </select>-->
<!-- </div>-->
</div>
</div>
......
......@@ -56,8 +56,34 @@
</div>
<!-- </div>-->
</nav>
<div class="divider-vertical"></div>
<div class=" mr-md-6">
<span class="text-muted" th:text="#{lang.name}"> </span>&nbsp
<!-- <span>&nbsp</span>-->
<select class="btn btn-sm btn-outline-secondary" id="locales">
<option class="btn btn-sm" th:unless="${#locale.toString() == 'cz' }" value="en" th:text="#{lang.eng}"></option>
<option class="btn btn-sm" value="cz" th:text="#{lang.cz}"></option>
<option class="btn btn-sm" th:if="${#locale.toString() == 'cz' }" value="en" th:text="#{lang.eng}"></option>
</select>
<script type="text/javascript">
$(document).ready(function () {
$("#locales").change(function () {
var selectedOption = $('#locales').val();
if (selectedOption != '') {
window.location.replace('?lang=' + selectedOption);
}
});
});
</script>
</div>
<div class="divider-vertical"></div>
<a sec:authorize="isAuthenticated()" class="my-2 my-md-0 mr-md-3" th:text="#{menu.loggedas}">You are logged as</a><b
class="my-2 my-md-0 mr-md-3" th:text="${name}">unkown</b>
<a sec:authorize="isAuthenticated()" class="btn btn-outline-primary" id="logout" th:text="#{menu.logout}">Log
out</a>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment