Browse Source

Added modules to Library listing

Nathan Schneider 3 years ago
parent
commit
67746a0fd9
4 changed files with 38 additions and 10 deletions
  1. 24 2
      _layouts/library.html
  2. 3 3
      _layouts/rule.html
  3. 10 2
      _sass/communityrule.scss
  4. 1 3
      library.md

+ 24 - 2
_layouts/library.html

@@ -3,7 +3,8 @@ layout: default
 ---
 
 <script>
-  
+
+  // Main Library-printing function
   function printLibrary(sheet) {
       const store = new SteinStore(
           "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
@@ -12,22 +13,43 @@ layout: default
       store.read(sheet, { limit: 0, offset: 0 }).then(data => {
           rules = data.reverse();
           libHTML = "";
+          // iterating over all the rules
           for (var i = 0; i < rules.length; i++) {
+              libHTML += "<div class='library-item'>\n";
+              // first the titles
               var title = rules[i]["communityname"];
               if (title == null) { title = "Untitled"; }
               libHTML += "<div class='library-rule-name'>" +
                   "<a href='/create/?r=" + rules[i]["ruleID"] + "'>" +
                   title + "</a></div>\n";
+              // then the authors
               var author = rules[i]["author-text"];
               if (author != null) {
                   libHTML += "<div class='library-rule-author'>" + author + "</div>";
-                  }
+              }
+              // then the structures
               var structure = rules[i]["structure"];
               if (structure != null) {
                   libHTML += "<p class='library-rule-structure'>" + structure;
                   libHTML += "</p>\n\n";
               }
+              // then the modules
+              var modulesRaw = rules[i]["modules"];
+              if (modulesRaw != null) {
+                  libHTML += "<div class='library-module-list'>";
+                  var modulesDOM = document.createElement("DIV");
+                  modulesDOM.innerHTML = "<div>" + modulesRaw + "</div>";
+                  var modules = modulesDOM.getElementsByClassName("module");
+                  for (var x = 0; x < modules.length; x++) {
+                      var moduleName = modules[x].children.item("module-name").innerHTML;
+                      libHTML += "<div class='module library-module'>" +
+                          moduleName + "</div>\n";
+                  }
+                  moduleName + "</div>\n";
+              }
+              libHTML += "</div>\n</div>\n";
           }
+          libHTML += "</div>\n";
           document.getElementById("librarylist").innerHTML = libHTML;
       });
   }

+ 3 - 3
_layouts/rule.html

@@ -439,7 +439,7 @@ layout: default
       // first, RuleBuilder data
       document.getElementById("builder-field").innerHTML = ""; // so it doesn't publish
       if (!builderEmpty()) {
-          rule[0]["builder"] = document.getElementById("module-input").innerHTML;
+          rule[0]["modules"] = document.getElementById("module-input").innerHTML;
       }
       // next, RuleWriter data
       var fields = document.getElementsByClassName("editable");
@@ -467,7 +467,7 @@ layout: default
       const store = new SteinStore(
           "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
       );     
-      store.read(sheet, { search: { ruleID: ID } }).then(data => {
+      store.read("rules", { search: { ruleID: ID } }).then(data => {
           // reads sheet variable from below
           // only runs when we have the data from Goog:
           var rule = data[0];
@@ -484,7 +484,7 @@ layout: default
               }
           }
           // Add Builder content
-          document.getElementById("module-input").innerHTML = rule["builder"];
+          document.getElementById("module-input").innerHTML = rule["modules"];
           // Publish timestamp to Rule
           document.getElementById('dateTime').innerHTML = rule['timestamp'];
           // Finish

+ 10 - 2
_sass/communityrule.scss

@@ -73,7 +73,7 @@
     background-color: lightgray;
     text-align: center;
     border-radius: 10px;
-    padding: 8px;
+    padding: 5px;
     margin: 5px;
     display: inline-block;
     font-size: .8em;
@@ -172,6 +172,9 @@ Enabling users to add links*/
 #librarylist {
     margin: 50px 0 0 0;
 }
+.library-item {
+    margin: 0 0 30px 0;
+}
 .library-rule-name {
     display: inline-block;
     margin: 0;
@@ -185,7 +188,12 @@ Enabling users to add links*/
     color: gray;
 }
 .library-rule-structure {
-    margin: 0 0 30px 0;
+    margin: 0;
+}
+.library-module {
+    font-size: .7em;
+    padding: 1px 5px 1px 5px;
+    margin: 0px;
 }
 
 /* VARIOUS IDs */

+ 1 - 3
library.md

@@ -4,7 +4,5 @@ title: Library
 permalink: /library/
 ---
 
-Browse user-created rules, starting from the most recent.
-
-**This feature is experimental, and rules may be removed without notice.**
+Browse user-created rules, starting from the most recent. This feature is experimental, and rules may be removed without notice.