Almost finished problems section
[vchess.git] / public / javascripts / components / problemSummary.js
1 // Preview a problem on variant page
2 Vue.component('my-problem-preview', {
3 props: ['prob','userid'],
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 <div v-show="prob.uid==userid" class="button-group">
14 <button @click="sendSignal('edit')'">Edit</button>
15 <button @click="sendSignal('delete')">Delete</button>
16 </div>
17 </div>
18 </div>
19 `,
20 methods: {
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 sendSignal: function(action) {
33 this.$emit(action + "-problem");
34 },
35 },
36 })