Fix Eightpieces, add some simple variants, add a basic variants classification instea...
[vchess.git] / client / src / views / Variants.vue
index 0390357..d638b07 100644 (file)
@@ -1,68 +1,58 @@
 <template lang="pug">
-div
-       .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
-               label(for="prefixFilter") Type first letters...
-               input#prefixFilter(v-model="curPrefix")
-       .variant.col-sm-12.col-md-5.col-lg-4(
-               v-for="(v,idx) in filteredVariants"
-               :class="{'col-md-offset-1': idx%2==0, 'col-lg-offset-2': idx%2==0}"
-       )
-               router-link(:to="getLink(v.name)")
-                       h4.boxtitle.text-center {{ v.name }}
-                       p.description.text-center {{ st.tr(v.desc) }}
+main
+  .row
+    .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")
 </template>
 
 <script>
 import { store } from "@/store";
 export default {
-  name: "variants",
+  name: "my-variants",
   data: function() {
     return {
-                 curPrefix: "",
-      st: store.state,
+      st: store.state
     };
-       },
-       computed: {
-               filteredVariants: function () {
-                       const capitalizedPrefix = this.curPrefix.replace(/^\w/, c => c.toUpperCase());
-                       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;
-               },
-       },
+  },
+  computed: {
+    content: function() {
+      // (AJAX) Request to get rules content (plain text, HTML)
+      return (
+        require("raw-loader!@/translations/variants/" + this.st.lang + ".pug")
+        // Next two lines fix a weird issue after last update (2019-11)
+        .replace(/\\n/g, " ")
+        .replace(/\\"/g, '"')
+        .replace('module.exports = "', "")
+        .replace(/"$/, "")
+      );
+    }
+  },
   methods: {
+    // oninput listener, required for smartphones:
+    setCurPrefix: function(e) {
+      this.curPrefix = e.target.value;
+    },
     getLink: function(vname) {
       return "/variants/" + vname;
     },
-  },
+    getVclasses: function(varray, idx) {
+      const idxMod2 = idx % 2;
+      return {
+        'col-md-offset-1': idxMod2 == 0,
+        'col-lg-offset-2': idxMod2 == 0,
+        'last-noneighb': idxMod2 == 0 && idx == varray.length - 1
+      };
+    },
+  }
 };
 </script>
 
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped lang="scss">
-h3 {
-  margin: 40px 0 0;
-}
-ul {
-  list-style-type: none;
-  padding: 0;
-}
-li {
-  display: inline-block;
-  margin: 0 10px;
-}
-a {
-  color: #42b983;
-}
+<style lang="sass" scoped>
+a#mainLink
+  display: block
+  margin: 10px auto
+  text-align: center
+  font-size: 1.3em
 </style>