fixing panel gui.

This commit is contained in:
Michael Wain 2024-11-26 03:38:57 +03:00
parent f25ca4a5d0
commit e00783b1d6
2 changed files with 47 additions and 30 deletions

View File

@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Slf4j
@Controller
@ -151,37 +153,48 @@ public class PanelController {
return cards;
}
private List<List<Card>> toPairs(List<Card> cards) {
List<List<Card>> l = IntStream.range(0, cards.size())
.filter(i -> i % 2 == 0 && i + 1 < cards.size())
.boxed()
.map(i -> List.of(cards.get(i), cards.get(i+1)))
.collect(Collectors.toList());
if( cards.size() % 2 == 1 ) { l.add(Collections.singletonList(cards.get(cards.size()-1))); }
return l;
}
@GetMapping("/panel")
public String panelPage(Model model, @RequestHeader("User-Agent") String uagent, @RequestHeader("Accept") String accepth, @RequestParam(value = "section", defaultValue = "diss") String section) {
model.addAttribute("is_mobile", new UAgentInfo(uagent, accepth).detectSmartphone());
boolean is_mobile = new UAgentInfo(uagent, accepth).detectSmartphone();
model.addAttribute("is_mobile", is_mobile);
model.addAttribute("section", section);
switch (section) {
case "lugg":
model.addAttribute( "cards", luggageToCards() );
model.addAttribute( "cards", is_mobile ? luggageToCards() : toPairs(luggageToCards()) );
break;
case "heal":
model.addAttribute("cards", healToCards() );
model.addAttribute("cards", is_mobile ? healToCards() : toPairs(healToCards()) );
break;
case "prof":
model.addAttribute("cards", workToCards() );
model.addAttribute("cards", is_mobile ? workToCards() : toPairs(workToCards()) );
break;
case "hobb":
model.addAttribute("cards", hobbyToCards() );
model.addAttribute("cards", is_mobile ? hobbyToCards() : toPairs(hobbyToCards()) );
break;
case "agge":
model.addAttribute("cards", bioToCards() );
model.addAttribute("cards", is_mobile ? bioToCards() : toPairs(bioToCards()) );
break;
case "diss":
model.addAttribute("cards", dissToCards() );
model.addAttribute("cards", is_mobile ? dissToCards() : toPairs(dissToCards()) );
break;
case "stats":
// !
break;
case "actions":
model.addAttribute("cards", actionsToCards() );
model.addAttribute("cards", is_mobile ? actionsToCards() : toPairs(actionsToCards()) );
break;
case "script_request":
model.addAttribute("cards", requestsToCards() );
model.addAttribute("cards", is_mobile ? requestsToCards() : toPairs(requestsToCards()) );
break;
}
return "panel";

View File

@ -105,7 +105,7 @@
</div>
</th:block>
<th:block th:unless="${is_mobile}">
<div class="d-flex justify-content-start text-center">
<div class="container justify-content-start text-center">
<div class="col">
<div class="card mt-2">
<div class="card-body">
@ -113,27 +113,31 @@
</div>
</div>
</div>
<th:block th:each="cc: ${cards}">
<div class="col">
<div class="card mt-2">
<div class="card-body">
<h5 class="card-title" th:text="${cc.title}"></h5>
<p class="card-text">
<ul th:each="ll: ${cc.body}">
<li th:text="${ll}"></li>
</ul>
</p>
<th:block th:unless="${section == 'script_request'}">
<a th:unless="${section == 'actions'}" href="#" th:data-id="${cc.id}" data-bs-toggle="modal" data-bs-target="#modal_syn" onclick="show_synergies_modal(this)" class="btn btn-primary" th:text="#{eddittsynn}"></a>
<a href="#" th:data-id="${cc.id}" data-bs-toggle="modal" data-bs-target="#modal" onclick="edit_entry(this)" class="btn btn-primary" th:text="#{edditbtn}"></a>
<a href="#" th:data-id="${cc.id}" onclick="remove_entry(this)" class="btn btn-danger" th:text="#{remombtn}"></a>
</th:block>
<th:block th:if="${section == 'script_request'}">
<a href="#" th:data-id="${cc.id}" onclick="accept_script_request(this)" class="btn btn-success" th:text="#{acceptbtnreq}"></a>
<a href="#" th:data-id="${cc.id}" onclick="remove_entry(this)" class="btn btn-danger" th:text="#{remombtn}"></a>
</th:block>
<th:block th:each="cp: ${cards}">
<div class="row">
<th:block th:each="cc: ${cp}">
<div class="col">
<div class="card mt-2">
<div class="card-body">
<h5 class="card-title" th:text="${cc.title}"></h5>
<p class="card-text">
<ul th:each="ll: ${cc.body}">
<li th:text="${ll}"></li>
</ul>
</p>
<th:block th:unless="${section == 'script_request'}">
<a th:unless="${section == 'actions'}" href="#" th:data-id="${cc.id}" data-bs-toggle="modal" data-bs-target="#modal_syn" onclick="show_synergies_modal(this)" class="btn btn-primary" th:text="#{eddittsynn}"></a>
<a href="#" th:data-id="${cc.id}" data-bs-toggle="modal" data-bs-target="#modal" onclick="edit_entry(this)" class="btn btn-primary" th:text="#{edditbtn}"></a>
<a href="#" th:data-id="${cc.id}" onclick="remove_entry(this)" class="btn btn-danger" th:text="#{remombtn}"></a>
</th:block>
<th:block th:if="${section == 'script_request'}">
<a href="#" th:data-id="${cc.id}" onclick="accept_script_request(this)" class="btn btn-success" th:text="#{acceptbtnreq}"></a>
<a href="#" th:data-id="${cc.id}" onclick="remove_entry(this)" class="btn btn-danger" th:text="#{remombtn}"></a>
</th:block>
</div>
</div>
</div>
</div>
</th:block>
</div>
</th:block>
</div>