Renamed Resource snippet Positions

This commit is contained in:
Risto Lahtela 2020-03-20 09:43:33 +02:00
parent 7860557a2d
commit ff6f960a84
7 changed files with 17 additions and 15 deletions

View File

@ -73,19 +73,19 @@ public interface ResourceService {
/**
* Loaded before page contents.
*/
HEAD,
PRE_CONTENT,
/**
* Loaded after page contents.
* Loaded after library scripts.
* <p>
* Recommended for modifying the structure of the page or loading libraries.
*/
BODY,
PRE_MAIN_SCRIPT,
/**
* Loaded after script execution.
* <p>
* Recommended for loading data to custom structure on the page.
*/
BODY_END
AFTER_MAIN_SCRIPT
}
class Holder {

View File

@ -84,23 +84,23 @@ public class ResourceSvc implements ResourceService {
return "Error: Given resource did not support WebResource#asString method properly and returned 'null'";
}
StringBuilder toHead = byPosition.get(Position.HEAD);
StringBuilder toHead = byPosition.get(Position.PRE_CONTENT);
if (toHead != null) {
html = StringUtils.replaceOnce(html, "</head>", toHead.append("</head>").toString());
}
StringBuilder toBody = byPosition.get(Position.BODY);
StringBuilder toBody = byPosition.get(Position.PRE_MAIN_SCRIPT);
if (toBody != null) {
if (StringUtils.contains(html, "<!-- End of Page Wrapper -->")) {
html = StringUtils.replaceOnce(html, "<!-- End of Page Wrapper -->", toBody.toString());
if (StringUtils.contains(html, "<script id=\"mainScript\"")) {
html = StringUtils.replaceOnce(html, "<script id=\"mainScript\"", toBody.append("<script id=\"mainScript\"").toString());
} else {
html = StringUtils.replaceOnce(html, "<body>", toBody.append("<body>").toString());
html = StringUtils.replaceOnce(html, "</body>", toBody.append("</body>").toString());
}
}
StringBuilder toBodyEnd = byPosition.get(Position.BODY_END);
StringBuilder toBodyEnd = byPosition.get(Position.AFTER_MAIN_SCRIPT);
if (toBodyEnd != null) {
html = StringUtils.replaceOnce(html, "<\body>", toBodyEnd.append("<\body>").toString());
html = StringUtils.replaceOnce(html, "</body>", toBodyEnd.append("</body>").toString());
}
return html;

View File

@ -245,6 +245,8 @@
<script src="js/sb-admin-2.js"></script>
<script src="js/color-selector.js"></script>
<script id="mainScript"></script>
</body>
</html>

View File

@ -804,7 +804,7 @@
<script src="./js/graphs.js"></script>
<script src="./js/network-values.js"></script>
<script>
<script id="mainScript">
try {
setLoadingText('Calculating values..');
jsonRequest("./v1/network/overview", loadNetworkOverviewValues);

View File

@ -726,7 +726,7 @@
<script src="../js/graphs.js"></script>
<script src="../js/player-values.js"></script>
<script>
<script id="mainScript">
try {
Highcharts.setOptions({
lang: {noData: "No Data to Display"}, time: {timezoneOffset: ${timeZone} * 60}

View File

@ -260,7 +260,7 @@
<script src="js/xmlhttprequests.js"></script>
<script src="js/color-selector.js"></script>
<script>
<script id="mainScript">
try {
jsonRequest("./v1/players", function (playersTableJson, error) {
if (playersTableJson) {

View File

@ -1282,7 +1282,7 @@
<script src="../js/graphs.js"></script>
<script src="../js/server-values.js"></script>
<script>
<script id="mainScript">
try {
setLoadingText('Calculating values..');
jsonRequest("../v1/serverOverview?server=${serverUUID}", loadserverOverviewValues);