)
option(
v-for="v in [emptyVar].concat(st.variants)"
+ v-if="!v.noProblems"
:value="v.id"
:selected="curproblem.vid==v.id"
)
.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"] }}
- button.nomargin(@click="gotoPrevNext($event,curproblem,-1)")
+ button.nomargin(@click="gotoPrevNext(curproblem,1)")
+ | {{ st.tr["Previous_p"] }}
+ button.nomargin(@click="gotoPrevNext(curproblem,-1)")
| {{ st.tr["Next_p"] }}
p.oneInstructions.clickable(
v-html="parseHtml(curproblem.instruction)"
select#selectVariant(v-model="selectedVar")
option(
v-for="v in [emptyVar].concat(st.variants)"
+ v-if="!v.noProblems"
:value="v.id"
)
| {{ v.name }}
import { store } from "@/store";
import { ajax } from "@/utils/ajax";
import { checkProblem } from "@/data/problemCheck";
+import params from "@/parameters";
import { getDiagram } from "@/utils/printDiagram";
import { processModalClick } from "@/utils/modalClick";
import { ArrayFun } from "@/utils/array";
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: "",
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) {
// 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
// $nextTick to be sure $refs["basegame"] exists
this.$nextTick(() => {
this.$refs["basegame"].re_setVariables(this.game); });
+ this.curproblem.showSolution = false; //in case of
this.copyProblem(p, this.curproblem);
});
};
);
} else processWhenWeHaveProb();
},
- gotoPrevNext: function(e, prob, dir) {
+ gotoPrevNext: function(prob, dir) {
const mode = (this.onlyMine ? "mine" : "others");
const problems = this.problems[mode];
const startIdx = problems.findIndex(p => p.id == prob.id);
const nextIdx = startIdx + dir;
if (nextIdx >= 0 && nextIdx < problems.length)
this.setHrefPid(problems[nextIdx]);
- else if (this.hasMore[mode]) this.loadMore(mode);
+ else if (this.hasMore[mode]) {
+ this.loadMore(
+ mode,
+ (nbProbs) => {
+ if (nbProbs > 0) this.gotoPrevNext(prob, dir);
+ else alert(this.st.tr["No more problems"]);
+ }
+ );
+ }
else alert(this.st.tr["No more problems"]);
},
prepareNewProblem: function() {
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);
}
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 = "";
}
);
},
+ canIedit: function(puid) {
+ return params.devs.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
const pids = this.problems[mode].map(p => p.id);
ArrayFun.remove(res.problems, p => pids.includes(p.id), "all");
this.decorate(res.problems);
- this.problems[mode] = this.problems[mode].concat(res.problems);
+ this.problems[mode] =
+ this.problems[mode].concat(res.problems)
+ // TODO: problems are alrady sorted, would just need to insert
+ // the current individual problem in list; more generally
+ // there is probably only one misclassified problem.
+ // (Unless the user navigated several times by URL to show a
+ // single problem...)
+ .sort((p1, p2) => p2.added - p1.added);
} else this.hasMore[mode] = false;
- if (!!cb) cb();
+ if (!!cb) cb(L);
}
}
);