X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FProblems.vue;h=270707d3a46fa0a401ac7508f3ff30e72cbd90c5;hp=1884852a6c92b7aa696860337b958f29585c6b56;hb=2c5d7b20742b802d9c47916915c1114bcfc9a9c3;hpb=9edfb7146fdc4dd08914b2a117d2852e705353aa diff --git a/client/src/views/Problems.vue b/client/src/views/Problems.vue index 1884852a..270707d3 100644 --- a/client/src/views/Problems.vue +++ b/client/src/views/Problems.vue @@ -47,7 +47,7 @@ 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 }} @@ -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 }} @@ -152,6 +153,7 @@ export default { onlyMine: false, showOne: false, infoMsg: "", + admins: [1], //hard-coded for now. TODO game: { players: [{ name: "Problem" }, { name: "Problem" }], mode: "analyze" @@ -373,7 +375,12 @@ export default { data: { prob: this.curproblem }, success: (ret) => { if (edit) { - let editedP = this.problems["mine"].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); } @@ -382,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 = ""; @@ -390,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