Experimental change: options replacing randomness (more general)
[vchess.git] / client / src / views / Variants.vue
index 2a3f6cf..f60e5f1 100644 (file)
@@ -2,49 +2,60 @@
 main
   .row
     .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
-      input#prefixFilter(
-        v-model="curPrefix"
-        @input="setCurPrefix($event)"
-        :placeholder="st.tr['Prefix?']"
-      )
-    .variant.col-sm-12.col-md-5.col-lg-4(
-      v-for="(v,idx) in filteredVariants"
-      :class="getVclasses(filteredVariants, idx)"
-    )
-      router-link(:to="getLink(v.name)")
-        h4.boxtitle.text-center {{ v.name }}
-        p.description.text-center {{ st.tr[v.desc] }}
+      a#mainLink(href="/#/variants/list")
+        | {{ st.tr["View alphabetical variants list"] }}
+      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/Chess960") Chess960
+        | {{ st.tr["chess960_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– 
+            | {{ st.tr[v.description] }}
 </template>
 
 <script>
 import { store } from "@/store";
+import { ajax } from "@/utils/ajax";
 export default {
   name: "my-variants",
   data: function() {
     return {
-      curPrefix: "",
-      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: {
-    filteredVariants: function() {
-      const capitalizedPrefix = this.curPrefix.replace(/^\w/, c =>
-        c.toUpperCase()
+    sortedGroups: function() {
+      return (
+        Array.from(this.variantGroup.keys()).sort((a, b) => (a < b ? -1 : 1))
       );
-      const variants = this.st.variants
-        .filter(v => {
-          return v.name.startsWith(capitalizedPrefix);
-        })
-        .map(v => {
-          return {
-            name: v.name,
-            desc: v.description
-          };
-        })
-        .sort((a, b) => {
-          return a.name.localeCompare(b.name);
-        });
-      return variants;
     }
   },
   methods: {
@@ -52,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;
@@ -68,26 +79,12 @@ export default {
 </script>
 
 <style lang="sass" scoped>
-input#prefixFilter
-  display: block
-  margin: 0 auto
+a.leftLink
+  margin-right: 15px
 
-.variant
-  box-sizing: border-box
-  border: 1px solid brown
-  background-color: lightyellow
-  &:hover
-    background-color: yellow
-  a
-    color: #663300
-    text-decoration: none
-  .boxtitle
-    font-weight: bold
-    margin-bottom: 0
-  .description
-    @media screen and (max-width: 767px)
-      margin-top: 0
-
-.last-noneighb
-  margin: 0 auto
+a#mainLink
+  display: block
+  margin: 10px auto
+  text-align: center
+  font-size: 1.3em
 </style>