script requests added
This commit is contained in:
parent
2649149da7
commit
8adfb9f289
@ -30,6 +30,7 @@ public class DatabaseController {
|
||||
private final DisasterService disasterService;
|
||||
private final SynergyService synergyService;
|
||||
private final ActionScriptsService actionService;
|
||||
private final ActionRequestService actionRequestService;
|
||||
|
||||
private void saveGender(Map<String, String> params) {
|
||||
Boolean canDie = Boolean.parseBoolean(params.get("canDie"));
|
||||
@ -114,6 +115,13 @@ public class DatabaseController {
|
||||
actionService.saveScript(new ActionScript(t1.getId(), t2.getId(), scriptBody));
|
||||
}
|
||||
|
||||
private void saveActionRequest(Map<String, String> params) {
|
||||
String scriptBody = params.get("action_body_text");
|
||||
String name_text = new String(HashUtils.decodeHexString(params.get("action_name_text")));
|
||||
String desc_text = new String(HashUtils.decodeHexString(params.get("action_desc_text")));
|
||||
actionRequestService.saveScript(new ActionScriptRequest(name_text, desc_text, scriptBody));
|
||||
}
|
||||
|
||||
@PostMapping("/api/remove_synergy")
|
||||
public String remove_synergy(@RequestParam Map<String, String> params) {
|
||||
long id = Long.parseLong(params.get("synergy_id"));
|
||||
@ -188,6 +196,12 @@ public class DatabaseController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@PostMapping("/public/api/add_entry_request")
|
||||
public String add_entry_request(@RequestParam Map<String, String> params) {
|
||||
saveActionRequest(params);
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@PostMapping("/api/remove_entry")
|
||||
public String remove_entry(@RequestParam Map<String, String> params) {
|
||||
String section = params.get("section");
|
||||
|
@ -29,6 +29,7 @@ public class PanelController {
|
||||
private final TextDataValService textDataValService;
|
||||
private final DisasterService disasterService;
|
||||
private final ActionScriptsServiceImpl scriptsService;
|
||||
private final ActionRequestServiceImpl actionRequestService;
|
||||
|
||||
private List<Card> dissToCards() {
|
||||
List<Disaster> bios = disasterService.getAllDisasters();
|
||||
@ -135,6 +136,21 @@ public class PanelController {
|
||||
return cards;
|
||||
}
|
||||
|
||||
private List<Card> requestsToCards() {
|
||||
List<ActionScriptRequest> scriptRequests = actionRequestService.getAllActionScripts();
|
||||
List<Card> cards = new ArrayList<>();
|
||||
for( ActionScriptRequest b : scriptRequests ) {
|
||||
Card card = new Card();
|
||||
card.setId(b.getId());
|
||||
card.setTitle(b.getTextName());
|
||||
card.setBody(new ArrayList<>(Arrays.asList(b.getScriptBody().split("\n"))));
|
||||
cards.add(card);
|
||||
}
|
||||
cards.sort(Comparator.comparing(Card::getId));
|
||||
Collections.reverse(cards);
|
||||
return cards;
|
||||
}
|
||||
|
||||
@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());
|
||||
@ -164,6 +180,9 @@ public class PanelController {
|
||||
case "actions":
|
||||
model.addAttribute("cards", actionsToCards() );
|
||||
break;
|
||||
case "script_request":
|
||||
model.addAttribute("cards", requestsToCards() );
|
||||
break;
|
||||
}
|
||||
return "panel";
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.alterdekim.javabot.entities;
|
||||
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@ToString
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "action_scripts_req")
|
||||
public class ActionScriptRequest {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String textName;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String textDesc;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String scriptBody;
|
||||
|
||||
public ActionScriptRequest(String textName, String textDesc, String scriptBody) {
|
||||
this.textName = textName;
|
||||
this.textDesc = textDesc;
|
||||
this.scriptBody = scriptBody;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.alterdekim.javabot.repository;
|
||||
|
||||
import com.alterdekim.javabot.entities.ActionScript;
|
||||
import com.alterdekim.javabot.entities.ActionScriptRequest;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ActionScriptRequestsRepository extends JpaRepository<ActionScriptRequest, Long> {
|
||||
Optional<ActionScriptRequest> findById(Long id);
|
||||
|
||||
List<ActionScriptRequest> findAll();
|
||||
}
|
@ -31,6 +31,7 @@ public class SpringSecurity {
|
||||
authorize
|
||||
.requestMatchers("/panel").hasAnyAuthority("ROLE_ADMIN")
|
||||
.requestMatchers("/api/**").hasAnyAuthority("ROLE_ADMIN")
|
||||
.requestMatchers("/public/**").permitAll()
|
||||
.requestMatchers("/static/**").permitAll()
|
||||
.requestMatchers("/access-denied").permitAll()
|
||||
.requestMatchers("/signup").permitAll()
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.alterdekim.javabot.service;
|
||||
|
||||
import com.alterdekim.javabot.entities.ActionScript;
|
||||
import com.alterdekim.javabot.entities.ActionScriptRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ActionRequestService {
|
||||
List<ActionScriptRequest> getAllActionScripts();
|
||||
ActionScriptRequest getActionScriptById(long scriptId);
|
||||
void removeById(long scriptId);
|
||||
void saveScript(ActionScriptRequest script);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.alterdekim.javabot.service;
|
||||
|
||||
import com.alterdekim.javabot.entities.ActionScript;
|
||||
import com.alterdekim.javabot.entities.ActionScriptRequest;
|
||||
import com.alterdekim.javabot.repository.ActionScriptRequestsRepository;
|
||||
import com.alterdekim.javabot.repository.ActionScriptsRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class ActionRequestServiceImpl implements ActionRequestService {
|
||||
|
||||
private final ActionScriptRequestsRepository actionScriptsRepository;
|
||||
|
||||
@Override
|
||||
public List<ActionScriptRequest> getAllActionScripts() {
|
||||
return actionScriptsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionScriptRequest getActionScriptById(long scriptId) {
|
||||
return actionScriptsRepository.findById(scriptId).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeById(long scriptId) {
|
||||
actionScriptsRepository.deleteById(scriptId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveScript(ActionScriptRequest script) {
|
||||
actionScriptsRepository.save(script);
|
||||
}
|
||||
}
|
||||
|
@ -66,4 +66,6 @@ gllugglist=Luggages list
|
||||
glworklist=Works list
|
||||
scrieditti=Script editor
|
||||
scrieditde=Below you can write a script for Bunker's action card. On the left side you will find code snippets, that will help with it. Happy coding!
|
||||
edditaddbtn=Edit/Add
|
||||
edditaddbtn=Edit/Add
|
||||
edditreq=Send request
|
||||
scrireqq=Script requests
|
@ -66,4 +66,6 @@ gllugglist=Список багажей
|
||||
glworklist=Список профессий
|
||||
scrieditti=Редактор скриптов (карточек действий)
|
||||
scrieditde=Ниже в вашем распоряжении редактор скриптов для карт действий игры Бункер. Слева вы найдете готовые куски кода, которые вам помогут. Удачи!
|
||||
edditaddbtn=Изменить/Добавить
|
||||
edditaddbtn=Изменить/Добавить
|
||||
edditreq=Отправить запрос
|
||||
scrireqq=Запросы на скрипты
|
44
src/main/resources/static/javascript/script-editor-public.js
Normal file
44
src/main/resources/static/javascript/script-editor-public.js
Normal file
@ -0,0 +1,44 @@
|
||||
var editor = ace.edit("script_editor");
|
||||
editor.setTheme("ace/theme/github");
|
||||
editor.session.setMode("ace/mode/lua");
|
||||
|
||||
// set script body
|
||||
// editor.setValue(jobj.scriptBody);
|
||||
|
||||
const snippets = ["player", "players[index]", "genders[index]", "hobbies[index]", "healths[index]", "luggages[index]", "works[index]"];
|
||||
|
||||
function str_toHex(s) {
|
||||
// utf8 to latin1
|
||||
var s = unescape(encodeURIComponent(s));
|
||||
var h = '';
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
h += s.charCodeAt(i).toString(16);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
function pasteSnippet(index) {
|
||||
editor.insert(snippets[index]);
|
||||
}
|
||||
|
||||
function grab_form() {
|
||||
let arr = {};
|
||||
arr["action_body_text"] = editor.getValue();
|
||||
arr["action_desc_text"] = str_toHex($("#action_desc_text").val());
|
||||
arr["action_name_text"] = str_toHex($("#action_name_text").val());
|
||||
return arr;
|
||||
}
|
||||
|
||||
function add_entry() {
|
||||
$.ajax({
|
||||
url: "/public/api/add_entry_request",
|
||||
type: "POST",
|
||||
data: grab_form()
|
||||
}).done(function() {
|
||||
window.location.reload(); // make popup confirm
|
||||
});
|
||||
}
|
||||
|
||||
function edit_submit_entry() {
|
||||
add_entry();
|
||||
}
|
@ -51,10 +51,10 @@ function getActionScript() {
|
||||
$( document ).ready(function() {
|
||||
if ($.urlParam("script_id") != "-1") {
|
||||
getActionScript();
|
||||
$(".dropdown-item").each(function() {
|
||||
$(this).attr("href", $(this).attr("href")+"&script_id="+($.urlParam("script_id")));
|
||||
});
|
||||
}
|
||||
$(".dropdown-item").each(function() {
|
||||
$(this).attr("href", $(this).attr("href")+"&script_id="+($.urlParam("script_id")));
|
||||
});
|
||||
});
|
||||
|
||||
function grab_form() {
|
||||
|
71
src/main/resources/templates/editor-public.html
Normal file
71
src/main/resources/templates/editor-public.html
Normal file
@ -0,0 +1,71 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity6">
|
||||
<head>
|
||||
<th:block th:insert="~{fragments/header}"></th:block>
|
||||
<link rel="stylesheet" href="/static/css/util.css">
|
||||
<link rel="stylesheet" href="/static/css/panel.css">
|
||||
</head>
|
||||
<body class="bg-body-tertiary">
|
||||
<div th:replace="~{fragments/floating_button}"></div>
|
||||
<main>
|
||||
<div class="container">
|
||||
<div class="py-5 text-center">
|
||||
<h2 th:text="#{scrieditti}"></h2>
|
||||
<p class="lead" th:text="#{scrieditde}"></p>
|
||||
</div>
|
||||
<div class="row no-gutters">
|
||||
<div class="col-4 col-md-2">
|
||||
<div class="row">
|
||||
<button type="button" onclick="pasteSnippet(0)" class="btn btn-primary btn-sm btn-block mt-1" th:text="#{exeplayob}"></button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button type="button" onclick="pasteSnippet(1)" class="btn btn-primary btn-sm btn-block mt-1" th:text="#{glplaylis}"></button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button type="button" onclick="pasteSnippet(2)" class="btn btn-primary btn-sm btn-block mt-1" th:text="#{glgenlist}"></button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button type="button" onclick="pasteSnippet(3)" class="btn btn-primary btn-sm btn-block mt-1" th:text="#{glhobblist}"></button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button type="button" onclick="pasteSnippet(4)" class="btn btn-primary btn-sm btn-block mt-1" th:text="#{glheallist}"></button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button type="button" onclick="pasteSnippet(5)" class="btn btn-primary btn-sm btn-block mt-1" th:text="#{gllugglist}"></button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button type="button" onclick="pasteSnippet(6)" class="btn btn-primary btn-sm btn-block mt-1" th:text="#{glworklist}"></button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="dropdown mt-1 w-100" style="padding: 0;">
|
||||
<button class="btn btn-sm btn-secondary dropdown-toggle w-100" type="button" id="langDropDown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
[[#{langl}]]
|
||||
</button>
|
||||
<ul class="dropdown-menu w-100" aria-labelledby="langDropDown">
|
||||
<li><a class="dropdown-item" href="?lang=en" th:text="#{elang}"></a></li>
|
||||
<li><a class="dropdown-item" href="?lang=ru" th:text="#{rlang}"></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-8">
|
||||
<div class="input-group-sm mb-1">
|
||||
<label for="action_name_text" class="col-form-label" th:text="#{inlaname}"></label>
|
||||
<input type="text" class="form-control" id="action_name_text" name="action_name_text">
|
||||
</div>
|
||||
<div class="input-group-sm mb-1">
|
||||
<label for="action_desc_text" class="col-form-label" th:text="#{inladesc}"></label>
|
||||
<input type="text" class="form-control" id="action_desc_text" name="action_desc_text">
|
||||
</div>
|
||||
<button type="button" id="submit_add" onclick="edit_submit_entry()" class="btn btn-primary mb-1" th:text="#{edditreq}"></button>
|
||||
<div id="script_editor" style="height: 50vh"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<div th:replace="~{fragments/footer :: div}"></div>
|
||||
<script src="/static/javascript/base32.js" type="text/javascript"></script>
|
||||
<script src="https://www.unpkg.com/ace-builds@latest/src-noconflict/ace.js"></script>
|
||||
<script src="/static/javascript/script-editor-public.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -44,6 +44,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/panel?section=actions" th:text="#{actions}"></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/panel?section=script_request" th:text="#{scrireqq}"></a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
|
||||
<li class="nav-item dropdown">
|
||||
|
@ -62,7 +62,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- th:if="${is_mobile}" -->
|
||||
</main>
|
||||
<div th:replace="~{fragments/footer :: div}"></div>
|
||||
<script src="/static/javascript/base32.js" type="text/javascript"></script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user