-// Show a problem summary on variant page
+// Show a problem summary on variant page or new problem preview
Vue.component('my-problem-summary', {
- props: ['prob'],
+ props: ['prob','preview'],
template: `
- <div class="problem col-sm-12" @click="showProblem()">
- <div class="diagram" v-html="getDiagram(prob.fen)"></div>
- <div class="problem-instructions" v-html="prob.instructions.substr(0,32)"></div>
- <div class="problem-time">{{ timestamp2datetime(prob.added) }}</div>
+ <div class="row problem">
+ <div class="col-sm-12 col-md-6 diagram"
+ v-html="getDiagram(prob.fen)">
+ </div>
+ <div class="col-sm-12 col-md-6">
+ <p v-html="prob.instructions"></p>
+ <p v-if="preview" v-html="prob.solution"></p>
+ <p v-else class="problem-time">{{ timestamp2date(prob.added) }}</p>
+ <button v-if="!preview" @click="showProblem()">{{ translate("Solve") }}</button>
+ </div>
</div>
`,
methods: {
+ translate: function(text) {
+ return translations[text];
+ },
getDiagram: function(fen) {
- const fenParts = fen.split(" ");
+ const fenParsed = V.ParseFen(fen);
return getDiagram({
- position: fenParts[0],
+ position: fenParsed.position,
+ turn: fenParsed.turn,
// No need for flags here
- turn: fenParts[2],
});
},
- timestamp2datetime(ts) {
- // TODO
- return ts;
+ timestamp2date(ts) {
+ return getDate(new Date(ts));
},
+ // Propagate "show problem" event to parent component (my-problems)
showProblem: function() {
- alert("show problem");
- //..........
- //TODO: send event with object prob.fen, prob.instructions, prob.solution
- //Event should propagate to game, which set mode=="problem" + other variables
- //click on a problem ==> land on variant page with mode==friend, FEN prefilled... ok
- // click on problem ==> masque problems, affiche game tab, launch new game Friend with
- // FEN + turn + flags + rappel instructions / solution on click sous l'échiquier
+ this.$emit('show-problem');
},
},
})