Skip to content

Commit

Permalink
tidied ui
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltester committed Mar 9, 2024
1 parent 3d0eec4 commit fc9e869
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public void setToMultiPlayerMode() {
}

public void setToCloudPersistenceMode() {
persistenceLayer.setToCloud();
persistenceLayer = new PersistenceLayer(PersistenceLayer.StorageType.CLOUD);
}

public void setGuiToKeepSessionAlive() {
guiStayAlive=true;
}

public void setToNoPersistenceMode() {
persistenceLayer.switchOffPersistence();
persistenceLayer = new PersistenceLayer(PersistenceLayer.StorageType.NONE);
}

public void enableAdminApi() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ public void setup(final Challengers challengers,
if (persistence != null) {
persistenceReason = persistence.getErrorMessage();
}
html.append("<div class='standoutblock'>");
html.append(String.format("<p><strong>Unknown Challenger ID %s</strong></p>",
persistenceReason));
html.append(showCurrentStatus());
html.append("</div>");
html.append(
multiUserShortHelp(
persistenceLayer.willAutoSaveChallengerStatusToPersistenceLayer(),
Expand All @@ -182,15 +184,18 @@ public void setup(final Challengers challengers,
html.append(storeThingifierDatabaseNameCookie(xChallenger));
html.append(storeCurrentGuidInLocalStorage(xChallenger));

html.append("<div class='standoutblock'>");
html.append(String.format("<p><strong>Progress For Challenger ID %s</strong></p>", xChallenger));
html.append(showCurrentStatus());

html.append(showPreviousGuids());
html.append(inputAChallengeGuidScript());
html.append("</div>");
}else {
html.append(storeThingifierDatabaseNameCookie(xChallenger));
html.append(storeCurrentGuidInLocalStorage(xChallenger));
html.append("<div class='standoutblock'>");
html.append(showCurrentStatus());
html.append("</div>");
}

html.append(renderChallengeData(challengeDefinitions, challenger));
Expand Down Expand Up @@ -288,7 +293,8 @@ private String playerChallengesIntro() {
final StringBuilder html = new StringBuilder();
html.append("<div style='clear:both'>");
html.append("<p>Use the Descriptions of the challenges below to explore the API and solve the challenges." +
" Remember to use the API documentation to see the format of POST requests.</p>");
" Remember to use the API documentation to see the format of POST requests." +
"</p>");
html.append("</div>");
return html.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public PersistenceResponse saveChallengerStatus(final ChallengerAuthData data) {
} catch (Exception e) {

logger.error("Error storing data to bucket for guid: {}", data.getXChallenger(), e);
return new PersistenceResponse().withSuccess(false).withErrorMessage(e.getMessage());
return new PersistenceResponse().withSuccess(false).withErrorMessage("Error storing data to S3");
}
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public PersistenceResponse loadChallengerStatus(final String guid) {
logger.error("Error Reading Challenge Status From S3: {}", guid, e);
return new PersistenceResponse().
withSuccess(false).
withErrorMessage(e.getMessage());
withErrorMessage("Error Reading Challenges Status from S3");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ public class PersistenceLayer {
boolean allowSaveToS3 = false;
boolean allowLoadFromS3 = false;

public void setToCloud() {
storeOn = PersistenceLayer.StorageType.CLOUD;
}

public void switchOffPersistence() {
storeOn=StorageType.NONE;
}

public PersistenceResponse tryToLoadChallenger(final Challengers challengers,
final String xChallengerGuid) {

Expand Down
8 changes: 4 additions & 4 deletions challenger/src/main/resources/public/js/challengerui.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ function showCurrentStatus(){
var doneCount = Object.values(challengerData.challengeStatus).filter(x=>x).length;
var totalCount = Object.values(challengerData.challengeStatus).length;
var leftCount = totalCount - doneCount;
document.writeln(`<p>${totalCount} Challenges: ${doneCount} complete, ${leftCount} remain.`);
document.writeln(`<p>${totalCount} Challenges: ${doneCount} complete, ${leftCount} remain. <br>`);

// only allow save if not in localStorage or is different from local storage
if(localStorage.getItem(`${xChallengerGuid}.progress`)!==JSON.stringify(challengerData)){
if(!autoSaveOn){
document.writeln(`<button onclick="saveChallengerProgressToLocalStorage(challengerData);this.innerText='saved progress';this.setAttribute('disabled',true)">Save Progress to LocalStorage</button>`);
document.writeln(`<button onclick="saveChallengerProgressToLocalStorage(challengerData);this.innerText='saved progress';this.setAttribute('disabled',true)">Save Your Progress to LocalStorage</button>`);
}else{
saveChallengerProgressToLocalStorage(challengerData);
}
Expand All @@ -142,13 +142,13 @@ function showCurrentStatus(){
if(databaseData && databaseData.todos){

document.writeln(`<p>${databaseData.todos.length} todos in database. `);
document.writeln(`<a href='/gui/instances?entity=todo'>View Todos</a> `)
document.writeln(`<a href='/gui/instances?entity=todo'>View Todos</a> <br>`)

// only allow save button if not in localStorage or is different from local storage
document.databaseData.todos.sort((a,b)=>a.id-b.id);
if(localStorage.getItem(`${xChallengerGuid}.data`)!==JSON.stringify(document.databaseData)){
if(!autoSaveOn){
document.writeln(`<button onclick="saveChallengerTodosToLocalStorage(databaseData,challengerData);this.innerText='saved todos';this.setAttribute('disabled',true)">Save Todos Data to LocalStorage</button>`);
document.writeln(`<button onclick="saveChallengerTodosToLocalStorage(databaseData,challengerData);this.innerText='saved todos';this.setAttribute('disabled',true)">Save Your Todos Data to LocalStorage</button>`);
}else{
saveChallengerTodosToLocalStorage(databaseData,challengerData);
}
Expand Down
5 changes: 5 additions & 0 deletions thingifier/src/main/resources/public/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,9 @@ pre.json{
.normal{
font-family: sans-serif;
font-size: 1.0rem;
}

.standoutblock{
background: aliceblue;
padding: 1em;
}

0 comments on commit fc9e869

Please sign in to comment.