.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/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 sortVariants(variantGroup.get(g))")
+ a(:href="getLink(v)") {{ v.display }}
+ |  –
+ | {{ st.tr[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))
);
}
},
methods: {
+ sortVariants: function(group) {
+ return group.sort( (v1, v2) => v1.name.localeCompare(v2.name) );
+ },
// oninput listener, required for smartphones:
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;
</script>
<style lang="sass" scoped>
+a.leftLink
+ margin-right: 15px
+
a#mainLink
display: block
margin: 10px auto