Преглед изворни кода

Updated code with some formatting

rohittaware1997 пре 1 година
родитељ
комит
f7b4521e14
3 измењених фајлова са 109 додато и 100 уклоњено
  1. 7 8
      _includes/vue-rule-script.html
  2. 97 89
      _layouts/library.html
  3. 5 3
      assets/js/vue.rules.js

+ 7 - 8
_includes/vue-rule-script.html

@@ -189,7 +189,6 @@
                 </div>
                 <h1>
                     <icon :icon="rule.icon" v-if="rule.icon"></icon> [[rule.name]]
-                    <icon :icon="icons.fork" v-if="rule.forked !== 1"></icon>
                 </h1>
                 <p>[[rule.summary]]</p>
                 <div class="modules__grid" :data-module-id="rule.ruleID" .module="rule">
@@ -205,9 +204,9 @@
                     <span v-if="rule.creator.url"><a :href="rule.creator.url">[[rule.creator.name]]</a></span>
                     <span v-else>[[rule.creator.name]]</span>
                 </div>
-
-                Version History:
-                <!-- <div style="white-space: normal;">
+                <div v-if="rule.forked!==1" class="rule__creator">
+                    Fork History:
+                    <!-- <div style="white-space: normal;">
                     <div v-for="ruleId1 in rule.edit_history" :key="ruleId1"
                         style="display: inline-block; margin-right: 10px;">
                         <a :href="getRuleLink(ruleId1)">[[
@@ -215,10 +214,10 @@
                         <icon :icon="icons.arrow"></icon>
                     </div>
                 </div> -->
-                <div v-for="(ruleId1, index) in rule.edit_history" :key="ruleId1"
-                    style="display: inline-block; margin-right: 10px;">
-                    <a :href="getRuleLink(ruleId1)">[[ getRuleName(ruleId1) ]]</a>
-                    <icon v-if="index < rule.edit_history.length - 1" :icon="icons.arrow"></icon>
+                    <div v-for="(ruleId1, index) in rule.edit_history" :key="ruleId1" style="display: inline-block;">
+                        <a :href="getRuleLink(ruleId1)"> [[ getRuleName(ruleId1) ]]</a>&nbsp;&nbsp;
+                        <icon v-if="index < rule.edit_history.length - 1" :icon="icons.arrow"></icon>
+                    </div>
                 </div>
             </div>
             <div v-else>

+ 97 - 89
_layouts/library.html

@@ -4,99 +4,107 @@ layout: default
 
 <script>
 
-  // Main Library-printing function
-  function printLibrary(sheet) {
-      const store = new SteinStore(
-          "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
-      );
-
-      const backendUrl = "http://localhost:3000/api/get_rules";
-      var rules = "";
-    
-    fetch(backendUrl, {
-          method: 'GET',
-          headers: {
-              'Content-Type': 'application/json',
-              // Add any other headers you may need, such as authorization headers
-          },
-    }).then(response => {
-        if (!response.ok) {
-            throw new Error('Network response was not ok');
-        }
-        return response.json(); // This returns another Promise
-    }).then(data => {
-            
-          libHTML = "";
-          rules = JSON.parse(data.rules)
-        //   console.log(JSON.parse(rules))
-          // iterating over all the rules
-          for (var i = 0; i < rules.length; i++) {
-              libHTML += "<div class='library-item'>\n";
-              // icon if there is one
-              var icon = rules[i]["icon"];
-              var iconHTML = "";
-              if (icon != null) {
-                  iconHTML = "<span class='icon'><img src='" + icon + "' /></span>";
-              }
-
-              // first the titles
-              var title = rules[i]["name"];
-              if (title == null) { title = "Untitled"; }
-              libHTML += "<h2 class='library-rule-name'>" + 
-                  "<a href='/create/?r=" + rules[i]["rule_id"] + "'>" + iconHTML +
-                  title + "</a></h2>\n";
-              // then the authors
-              var author = rules[i]["creatorName"];
-              if (author != null) {
-                  libHTML += "<div class='library-rule-author'>" + author + "</div>";
-              }
-              // then the structures
-              var structure = rules[i]["summary"];
-              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 modules__grid'>";
-                  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;
-          console.log(libHTML)
-      });
-  }
-
-  // allows for using alt sheets
-  var source = "";
-  window.onload = function() {
-      printLibrary('rules');
-  }
+    // Main Library-printing function
+    function printLibrary(sheet) {
+        const store = new SteinStore(
+            "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
+        );
+
+        const backendUrl = "http://localhost:3000/api/get_rules";
+        var rules = "";
+
+        fetch(backendUrl, {
+            method: 'GET',
+            headers: {
+                'Content-Type': 'application/json',
+                // Add any other headers you may need, such as authorization headers
+            },
+        }).then(response => {
+            if (!response.ok) {
+                throw new Error('Network response was not ok');
+            }
+            return response.json(); // This returns another Promise
+        }).then(data => {
+
+            libHTML = "";
+            rules = JSON.parse(data.rules)
+
+            //   console.log(JSON.parse(rules))
+            // iterating over all the rules
+            for (var i = 0; i < rules.length; i++) {
+                libHTML += "<div class='library-item'>\n";
+                // icon if there is one
+                var icon = rules[i]["icon"];
+                var iconHTML = "";
+                if (icon != null) {
+                    iconHTML = "<span class='icon'><img src='" + icon + "' /></span>";
+                }
+
+                // first the titles
+                var title = rules[i]["name"];
+                if (title == null) { title = "Untitled"; }
+                libHTML += "<h2 class='library-rule-name'>" +
+                    "<a href='/create/?r=" + rules[i]["rule_id"] + "'>" + iconHTML +
+                    title + "</a></h2>\n";
+                // then the authors
+                var author = rules[i]["creatorName"];
+                if (author != null) {
+                    libHTML += "<div class='library-rule-author'>" + author + "</div>";
+                }
+                // then the structures
+                var structure = rules[i]["summary"];
+                if (structure != null) {
+                    libHTML += "<p class='library-rule-structure'>" + structure;
+                    libHTML += "</p>\n\n";
+                }
+                // then the modules
+                var modulesRaw = rules[i]["modules"];
+                try {
+                    var modulesRaw = JSON.parse(modulesRaw)
+
+                    // console.log(modulesRaw)
+                    if (modulesRaw != null || modulesRaw != undefined) {
+                        libHTML += "<div class='library-module-list modules__grid'>";
+                        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";
+                    }
+                } catch {
+
+                }
+                libHTML += "</div>\n</div>\n";
+            }
+            libHTML += "</div>\n";
+            document.getElementById("librarylist").innerHTML = libHTML;
+            console.log(libHTML)
+        });
+    }
+
+    // allows for using alt sheets
+    var source = "";
+    window.onload = function () {
+        printLibrary('rules');
+    }
 </script>
 
 
 <article class="post">
 
-  <header class="post-header">
-    <h1 class="post-title">{{ page.title }}</h1>
-  </header>
+    <header class="post-header">
+        <h1 class="post-title">{{ page.title }}</h1>
+    </header>
+
+    <div class="post-content">
+        {{ content }}
 
-  <div class="post-content">
-    {{ content }}
-    
-    <div id="librarylist">
-    </div>    
-  </div>
+        <div id="librarylist">
+        </div>
+    </div>
 
-</article>
+</article>

+ 5 - 3
assets/js/vue.rules.js

@@ -511,9 +511,11 @@ const app = Vue.createApp({
           return;
         }
 
-        const splitArray = rule.list.split(':');
-        const resultArray = splitArray.filter(value => value.trim() !== '');
-
+        var resultArray = ''
+        if (rule.list != null) {
+          const splitArray = rule.list.split(':');
+          resultArray = splitArray.filter(value => value.trim() !== '');
+        }
         var forkedOrNot = 0
         if (resultArray.length == 1) {
           forkedOrNot = 1;