summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-11-18 22:28:10 -0800
committerJesse Morgan <jesse@jesterpm.net>2013-11-18 22:28:10 -0800
commit0cb9b37b723386d1e902f556e9dbbbe093d2789f (patch)
treed1a172148327247618c7d30572e9fa486a925f42
parent3521cc4003f738cc1433cfe484470dd9f7577360 (diff)
Making strict viewing order configurable.
-rw-r--r--src/com/p4square/grow/config/Config.java14
-rw-r--r--src/com/p4square/grow/frontend/TrainingPageResource.java6
-rw-r--r--src/templates/templates/training.ftl2
-rw-r--r--tst/com/p4square/grow/config/ConfigTest.java7
-rw-r--r--tst/com/p4square/grow/config/ConfigTest.properties4
5 files changed, 30 insertions, 3 deletions
diff --git a/src/com/p4square/grow/config/Config.java b/src/com/p4square/grow/config/Config.java
index fea75e0..d739d61 100644
--- a/src/com/p4square/grow/config/Config.java
+++ b/src/com/p4square/grow/config/Config.java
@@ -150,4 +150,18 @@ public class Config {
return defaultValue;
}
+
+ public boolean getBoolean(String key) {
+ return getBoolean(key, false);
+ }
+
+ public boolean getBoolean(String key, boolean defaultValue) {
+ final String propertyValue = getString(key);
+
+ if (propertyValue != null) {
+ return (propertyValue.charAt(0) & 0xDF) == 'T';
+ }
+
+ return defaultValue;
+ }
}
diff --git a/src/com/p4square/grow/frontend/TrainingPageResource.java b/src/com/p4square/grow/frontend/TrainingPageResource.java
index 311bc2c..d181190 100644
--- a/src/com/p4square/grow/frontend/TrainingPageResource.java
+++ b/src/com/p4square/grow/frontend/TrainingPageResource.java
@@ -119,6 +119,7 @@ public class TrainingPageResource extends FreeMarkerPageResource {
// The user is not allowed to view chapters after his highest completed chapter.
// In this loop we find which chapters are allowed and check if the user tried
// to skip ahead.
+ boolean allowUserToSkip = mConfig.getBoolean("allowUserToSkip", true);
String defaultChapter = null;
boolean userTriedToSkip = false;
@@ -134,9 +135,9 @@ public class TrainingPageResource extends FreeMarkerPageResource {
}
} else {
- allowed = false;
+ allowed = allowUserToSkip;
- if (chapterId.equals(mChapter)) {
+ if (!allowUserToSkip && chapterId.equals(mChapter)) {
userTriedToSkip = true;
}
}
@@ -194,6 +195,7 @@ public class TrainingPageResource extends FreeMarkerPageResource {
root.put("isChapterAllowed", allowedChapters);
root.put("chapterProgress", chapterProgress);
root.put("videos", videos);
+ root.put("allowUserToSkip", allowUserToSkip);
return new TemplateRepresentation(mTrainingTemplate, root, MediaType.TEXT_HTML);
diff --git a/src/templates/templates/training.ftl b/src/templates/templates/training.ftl
index 80c5ca4..cf230b6 100644
--- a/src/templates/templates/training.ftl
+++ b/src/templates/templates/training.ftl
@@ -50,7 +50,7 @@
<#if (video.pdf!"") != "">
<span class="pdf"><a href="${video.pdf}" target="_blank">Outline</a></span>
</#if>
- <#if allowed && !video.completed>
+ <#if !allowUserToSkip && allowed && !video.completed>
<#assign allowed = false>
</#if>
</article>
diff --git a/tst/com/p4square/grow/config/ConfigTest.java b/tst/com/p4square/grow/config/ConfigTest.java
index 17185de..ccb39da 100644
--- a/tst/com/p4square/grow/config/ConfigTest.java
+++ b/tst/com/p4square/grow/config/ConfigTest.java
@@ -51,5 +51,12 @@ public class ConfigTest {
// Non number test
assertEquals(Integer.MIN_VALUE, domain1.getInt("notANumber"));
+
+ // Test Boolean values
+ assertTrue(domain1.getBoolean("boolean1"));
+ assertTrue(domain1.getBoolean("boolean2"));
+ assertFalse(domain1.getBoolean("boolean3"));
+ assertFalse(domain1.getBoolean("notABool"));
+ assertTrue(domain1.getBoolean("notABool", true));
}
}
diff --git a/tst/com/p4square/grow/config/ConfigTest.properties b/tst/com/p4square/grow/config/ConfigTest.properties
index 8a8328d..e5b4032 100644
--- a/tst/com/p4square/grow/config/ConfigTest.properties
+++ b/tst/com/p4square/grow/config/ConfigTest.properties
@@ -10,3 +10,7 @@ domain1.onlyInDomain1 = domain1Value
*.number = 5
*.notANumber = Hello
+
+*.boolean1 = True
+*.boolean2 = true
+*.boolean3 = false