Add unambiguous section in the PGN + some fixes + code formatting and fix typos
[vchess.git] / client / src / views / Problems.vue
index cfc0637..270707d 100644 (file)
@@ -47,14 +47,14 @@ main
   .row(v-if="showOne")
     .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
       #topPage
-        .button-group(v-if="st.user.id == curproblem.uid")
+        .button-group(v-if="canIedit(curproblem.uid)")
           button(@click="editProblem(curproblem)") {{ st.tr["Edit"] }}
           button(@click="deleteProblem(curproblem)") {{ st.tr["Delete"] }}
         span.vname {{ curproblem.vname }}
         span.uname ({{ curproblem.uname }})
         button.marginleft(@click="backToList()") {{ st.tr["Back to list"] }}
         button.nomargin(@click="gotoPrevNext($event,curproblem,1)")
-          | {{ st.tr["Previous"] }}
+          | {{ st.tr["Previous_p"] }}
         button.nomargin(@click="gotoPrevNext($event,curproblem,-1)")
           | {{ st.tr["Next_p"] }}
       p.oneInstructions.clickable(
@@ -81,6 +81,7 @@ main
         select#selectVariant(v-model="selectedVar")
           option(
             v-for="v in [emptyVar].concat(st.variants)"
+            v-if="!v.noProblems"
             :value="v.id"
           )
             | {{ v.name }}
@@ -144,14 +145,15 @@ export default {
       problems: { "mine": [], "others": [] },
       // timestamp of oldest showed problem:
       cursor: {
-        "mine": Number.MAX_SAFE_INTEGER,
-        "others": Number.MAX_SAFE_INTEGER
+        mine: Number.MAX_SAFE_INTEGER,
+        others: Number.MAX_SAFE_INTEGER
       },
       // hasMore == TRUE: a priori there could be more problems to load
-      hasMore: { "mine": true, "others": true },
+      hasMore: { mine: true, others: true },
       onlyMine: false,
       showOne: false,
       infoMsg: "",
+      admins: [1], //hard-coded for now. TODO
       game: {
         players: [{ name: "Problem" }, { name: "Problem" }],
         mode: "analyze"
@@ -273,6 +275,7 @@ export default {
       this.loadVariant(prob.vid, () => {
         // Set FEN if possible (might not be correct yet)
         if (V.IsGoodFen(prob.fen)) this.setDiagram(prob);
+        else prob.diag = "";
       });
     },
     loadVariant: async function(vid, cb) {
@@ -291,6 +294,7 @@ export default {
       // variant could not be ready, or not defined
       if (prob.vid > 0 && this.loadedVar == prob.vid && V.IsGoodFen(prob.fen))
         this.setDiagram(prob);
+      else prob.diag = "";
     },
     setDiagram: function(prob) {
       // Condition: prob.fen is correct and global V is ready
@@ -371,7 +375,12 @@ export default {
           data: { prob: this.curproblem },
           success: (ret) => {
             if (edit) {
-              let editedP = this.problems.find(p => p.id == this.curproblem.id);
+              let editedP = this.problems["mine"]
+                .find(p => p.id == this.curproblem.id);
+              if (!editedP)
+                // I'm an admin and edit another user' problem
+                editedP = this.problems["others"]
+                  .find(p => p.id == this.curproblem.id);
               this.copyProblem(this.curproblem, editedP);
               this.showProblem(editedP);
             }
@@ -380,7 +389,8 @@ export default {
               newProblem.id = ret.id;
               newProblem.uid = this.st.user.id;
               newProblem.uname = this.st.user.name;
-              this.problems["mine"] = [newProblem].concat(this.problems["mine"]);
+              this.problems["mine"] =
+                [newProblem].concat(this.problems["mine"]);
             }
             document.getElementById("modalNewprob").checked = false;
             this.infoMsg = "";
@@ -388,6 +398,9 @@ export default {
         }
       );
     },
+    canIedit: function(puid) {
+      return this.admins.concat([puid]).includes(this.st.user.id);
+    },
     editProblem: function(prob) {
       // prob.diag might correspond to some other problem or be empty:
       this.setDiagram(prob); //V is loaded at this stage