54602e054a13c86d588834944b3d42a4c213a465
[vchess.git] / public / javascripts / components / problemSummary.js
1 // Preview a problem on variant page
2 Vue.component('my-problem-summary', {
3 props: ['prob','userid','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="!!prob.preview" v-html="prob.solution"></p>
12 <p v-else class="problem-time">{{ timestamp2date(prob.added) }}</p>
13 <button v-show="!preview" @click="$emit('show-problem')">Show</button>
14 <div v-show="prob.uid==userid && !preview" class="button-group">
15 <button @click="$emit('edit-problem')">Edit</button>
16 <button @click="$emit('delete-problem')">Delete</button>
17 </div>
18 </div>
19 </div>
20 `,
21 methods: {
22 getDiagram: function(fen) {
23 const fenParsed = V.ParseFen(fen);
24 return getDiagram({
25 position: fenParsed.position,
26 turn: fenParsed.turn,
27 // No need for flags here
28 });
29 },
30 timestamp2date(ts) {
31 return getDate(new Date(ts));
32 },
33 },
34 })