Finish fixing problems page
[vchess.git] / public / javascripts / components / problemSummary.js
index 6003f08..54602e0 100644 (file)
@@ -1,17 +1,34 @@
-// Show a problem summary on variant page
+// Preview a problem on variant page
 Vue.component('my-problem-summary', {
-       props: ['prob'],
+       props: ['prob','userid','preview'],
        template: `
-               <div class="problem col-sm-12">
-                       <div class="diagram">
-                               {{ getDiagram(prob.fen) }}
+               <div class="row problem">
+                       <div class="col-sm-12 col-md-6 diagram"
+                               v-html="getDiagram(prob.fen)">
                        </div>
-                       <div class="problem-instructions">
-                               {{ prob.instructions.substr(0,32) }}
-                       </div>
-                       <div class="problem-time">
-                               {{ prob.added }}
+                       <div class="col-sm-12 col-md-6">
+                               <p v-html="prob.instructions"></p>
+                               <p v-if="!!prob.preview" v-html="prob.solution"></p>
+                               <p v-else class="problem-time">{{ timestamp2date(prob.added) }}</p>
+                               <button v-show="!preview" @click="$emit('show-problem')">Show</button>
+                               <div v-show="prob.uid==userid && !preview" class="button-group">
+                                       <button @click="$emit('edit-problem')">Edit</button>
+                                       <button @click="$emit('delete-problem')">Delete</button>
+                               </div>
                        </div>
                </div>
        `,
+       methods: {
+               getDiagram: function(fen) {
+                       const fenParsed = V.ParseFen(fen);
+                       return getDiagram({
+                               position: fenParsed.position,
+                               turn: fenParsed.turn,
+                               // No need for flags here
+                       });
+               },
+               timestamp2date(ts) {
+                       return getDate(new Date(ts));
+               },
+       },
 })