Add 'display' DB field for nicer variants display. Remove join on Variants table...
[vchess.git] / client / src / views / Variants.vue
index da6478b..4374fd0 100644 (file)
@@ -4,27 +4,57 @@ main
     .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
       a#mainLink(href="/#/variants/list")
         | {{ st.tr["View alphabetical variants list"] }}
-      div(v-html="content")
+      p.text-center
+        a.leftLink(href="https://www.chessvariants.com/what.html")
+          | {{ st.tr["What is a chess variant?"] }}
+        a(href="https://www.chessvariants.com/why.html")
+          | {{ st.tr["Why play chess variants?"] }}
+      p
+        a(href="/#/variants/Chess") Chess
+        | {{ st.tr["chess_v"] }}
+      div(v-for="g of sortedGroups")
+        h3 {{ st.tr["vt" + g] }}
+        p {{ st.tr["vg" + g] }}
+        ul
+          li(v-for="v of variantGroup.get(g)")
+            a(:href="getLink(v)") {{ v.display }}
+            | &nbsp– 
+            | {{ v.description }}
 </template>
 
 <script>
 import { store } from "@/store";
-import afterRawLoad from "@/utils/afterRawLoad";
+import { ajax } from "@/utils/ajax";
 export default {
   name: "my-variants",
   data: function() {
     return {
-      st: store.state
+      st: store.state,
+      variantGroup: []
     };
   },
+  created: function() {
+    ajax(
+      "/variants",
+      "GET",
+      {
+        success: (res) => {
+          this.variantGroup = new Map();
+          res.variantArray.forEach((v) => {
+            if (v.groupe >= 0) {
+              let collection = this.variantGroup.get(v.groupe);
+              if (!collection) this.variantGroup.set(v.groupe, [v]);
+              else collection.push(v);
+            }
+          });
+        }
+      }
+    );
+  },
   computed: {
-    content: function() {
+    sortedGroups: function() {
       return (
-        afterRawLoad(
-          require(
-            "raw-loader!@/translations/variants/" + this.st.lang + ".pug"
-          ).default
-        )
+        Array.from(this.variantGroup.keys()).sort((a, b) => (a < b ? -1 : 1))
       );
     }
   },
@@ -33,8 +63,8 @@ export default {
     setCurPrefix: function(e) {
       this.curPrefix = e.target.value;
     },
-    getLink: function(vname) {
-      return "/variants/" + vname;
+    getLink: function(variant) {
+      return "/#/variants/" + variant.name;
     },
     getVclasses: function(varray, idx) {
       const idxMod2 = idx % 2;
@@ -49,6 +79,9 @@ export default {
 </script>
 
 <style lang="sass" scoped>
+a.leftLink
+  margin-right: 15px
+
 a#mainLink
   display: block
   margin: 10px auto