| 1 | // Show a problem summary on variant page or new problem preview |
| 2 | Vue.component('my-problem-summary', { |
| 3 | props: ['prob','preview'], |
| 4 | template: ` |
| 5 | <div class="row problem"> |
| 6 | <div class="col-sm-12 col-md-6 diagram" |
| 7 | v-html="getDiagram(prob.fen)"> |
| 8 | </div> |
| 9 | <div class="col-sm-12 col-md-6"> |
| 10 | <p v-html="prob.instructions"></p> |
| 11 | <p v-if="preview" v-html="prob.solution"></p> |
| 12 | <p v-else class="problem-time">{{ timestamp2date(prob.added) }}</p> |
| 13 | <button v-if="!preview" @click="showProblem()">{{ translate("Solve") }}</button> |
| 14 | </div> |
| 15 | </div> |
| 16 | `, |
| 17 | methods: { |
| 18 | translate: function(text) { |
| 19 | return translations[text]; |
| 20 | }, |
| 21 | getDiagram: function(fen) { |
| 22 | const fenParsed = V.ParseFen(fen); |
| 23 | return getDiagram({ |
| 24 | position: fenParsed.position, |
| 25 | turn: fenParsed.turn, |
| 26 | // No need for flags here |
| 27 | }); |
| 28 | }, |
| 29 | timestamp2date(ts) { |
| 30 | return getDate(new Date(ts)); |
| 31 | }, |
| 32 | // Propagate "show problem" event to parent component (my-problems) |
| 33 | showProblem: function() { |
| 34 | this.$emit('show-problem'); |
| 35 | }, |
| 36 | }, |
| 37 | }) |