Skip to content

Commit

Permalink
Fix registration update bug and checkbox team interface bug. Add time…
Browse files Browse the repository at this point in the history
…out for msg in team interface. Remove members from individual rankings. Fix unique constraint in invitation key. Fix puzzle titles in info modal.
  • Loading branch information
sonsoleslp committed Feb 6, 2021
1 parent c23be42 commit 7eb5b4b
Show file tree
Hide file tree
Showing 20 changed files with 635 additions and 604 deletions.
4 changes: 3 additions & 1 deletion controllers/escapeRoom_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ exports.update = async (req, res) => {
escapeRoom.forbiddenLateSubmissions = body.forbiddenLateSubmissions === "on";
escapeRoom.description = body.description;
escapeRoom.supportLink = body.supportLink;
escapeRoom.invitation = body.invitation;
escapeRoom.invitation = body.invitation != undefined ? body.invitation.toString() : undefined;
escapeRoom.scope = body.scope === "private";
escapeRoom.teamSize = body.teamSize || 0;
escapeRoom.forceLang = body.forceLang === "en" || body.forceLang === "es" ? body.forceLang : null;
const progressBar = body.progress;

console.log(body);
try {
const er = await escapeRoom.save({"fields": ["title", "subject", "duration", "forbiddenLateSubmissions", "description", "scope", "teamSize", "supportLink", "forceLang", "invitation"]});

Expand Down Expand Up @@ -242,6 +243,7 @@ exports.update = async (req, res) => {
}
res.redirect(`/escapeRooms/${req.escapeRoom.id}/${progressBar || nextStep("edit")}`);
} catch (error) {
console.error(error);
// Console.error(error);
if (error instanceof Sequelize.ValidationError) {
error.errors.forEach((err) => {
Expand Down
2 changes: 1 addition & 1 deletion controllers/members_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const {getRanking} = require("../helpers/utils");

// PUT /escapeRooms/:escapeRoomId/users/:userId/turnos/:turnoId/teams/:teamId
exports.add = async (req, res, next) => {
const direccion = req.body.redir || "/escapeRooms";
const {escapeRoom, turn, team, session, token} = req;
const direccion = req.body.redir || `/escapeRooms/${escapeRoom.id}`;
const {startTime} = team;
const {user} = session;
const transaction = await sequelize.transaction();
Expand Down
5 changes: 3 additions & 2 deletions controllers/team_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ exports.create = async (req, res, next) => {

await teamCreated.addTeamMembers(user.id, {transaction});
await models.participants.create({"attendance": false, "turnId": params.turnoId, "userId": user.id}, {transaction});
req.flash("success", i18n.common.flash.successCreatingTeam);
res.redirect("/escapeRooms");

transaction.commit();
req.flash("success", req.escapeRoom.teamSize === 1 ? i18n.common.flash.successCreatingTeamSingle : i18n.common.flash.successCreatingTeam);
res.redirect(`/escapeRooms/${params.escapeRoomId}`);
} catch (err) {
transaction.rollback();
if (err instanceof Sequelize.ValidationError) {
Expand Down
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
"successCreatingHint": "Hint successfully created",
"successCreatingPuzzle": "Puzzle successfully created",
"successCreatingTeam": "Team successfully created",
"successCreatingTeamSingle": "You have successfully joined the escape room",
"successCreatingTurno": "Shift successfully created",
"successCreatingUser": "User successfully created",
"successDeletingER": "Escape Room successfully deleted",
Expand Down
1 change: 1 addition & 0 deletions i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
"successCreatingHint": "Pista creada con éxito",
"successCreatingPuzzle": "Reto creado con éxito",
"successCreatingTeam": "Equipo creado con éxito",
"successCreatingTeamSingle": "Te has unido con éxito a la escape room",
"successCreatingTurno": "Turno creado con éxito",
"successCreatingUser": "Usuario creado con éxito",
"successDeletingER": "Escape room borrada con éxito",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

"use strict";

module.exports = {"up": (queryInterface, Sequelize) => queryInterface.removeConstraint("escapeRooms", "escapeRooms_invitation_key")};
10 changes: 1 addition & 9 deletions models/escapeRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ module.exports = function (sequelize, DataTypes) {
"validate": {"max": 10000, "notEmpty": {"msg": "El tamaño de los equipos no puede estar vacío."}}
},
"scope": {"type": DataTypes.BOOLEAN},
"invitation": {
"type": DataTypes.STRING
/* "allowNull": false,
"defaultValue" () {
return Math.random().toString(36).
substr(2);
},
"validate": {"notEmpty": {"msg": "La URL de la invitación no puede estar vacía."}}*/
},
"invitation": {"type": DataTypes.STRING},
"teamAppearance": {
"type": DataTypes.TEXT,
"defaultValue": "litera",
Expand Down
52 changes: 30 additions & 22 deletions public/ckeditor/ckeditor4/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,33 @@ $(()=>{
}

if ($("#dialog-config").length) {
$("#dialog-config").dialog({...config,
"buttons": {
[window.accept] : ()=>{
$( "#dialog-config" ).dialog("close");
var result = []
var l = $(".puzzle-preview-select input").length - 1;
$(".puzzle-preview-select input").each((i,e)=>{
if ($(e).prop('checked')){
result.push(i < l ? i : "all");
}
});
$('#'+window.blockId).data("puzzles", result.join(","));
$(".puzzle-preview-select input").prop('checked', false);
},
[window.cancel] : ()=> {
$( "#dialog-config" ).dialog("close");
window.blockId = null;
$(".puzzle-preview-select input").prop('checked', false);
$("#dialog-config").dialog({...config,// "closeOnEscape": false,
"buttons": {
[window.accept] : ()=>{
$( "#dialog-config" ).dialog("close");
var result = []
var l = $(".puzzle-preview-select input").length - 1;
$(".puzzle-preview-select input").each((i,e)=>{
if ($(e).prop('checked')){
result.push(i < l ? i : "all");
}
});

$('#'+window.blockId).data("puzzles", result.join(","));
$(".puzzle-preview-select input").prop('checked', false);
},
[window.cancel] : ()=> {
$( "#dialog-config" ).dialog("close");
window.blockId = null;
$(".puzzle-preview-select input").prop('checked', false);
}
}
}
});
});
$('#dialog-config').on('dialogclose', function(event) {
$( "#dialog-config" ).dialog("close");
window.blockId = null;
$(".puzzle-preview-select input").prop('checked', false);
});
}

$( ".theme-btn" ).on("click",() => {
Expand All @@ -190,9 +196,11 @@ $(()=>{
$("body").on("click", ".config-btn", function(){
var parent = $(this).parent().parent();
window.blockId = parent.attr("id");
var puzzleIds = parent.data("puzzles").toString().split(",");
var puzzleIds = parent.data("puzzles").toString()
puzzleIds = puzzleIds === "" ? [] : puzzleIds.split(",");
var puzzleInputs = $(".puzzle-preview-select input");
puzzleInputs.each((i,e)=>{

if ((puzzleIds.indexOf(i.toString()) !== -1) || (i.toString() == (puzzleInputs.length -1) && puzzleIds.indexOf("all") !== -1)) {
$(e).prop('checked', true);
}
Expand Down Expand Up @@ -235,7 +243,7 @@ $(()=>{
var results = [];
$('.building-block').each((_i,e)=>{
var type = $(e).data("content-type");
var puzzles = $(e).data("puzzles") ? $(e).data("puzzles").toString().split(",") : [];
var puzzles = $(e).data("puzzles") !== "" ? $(e).data("puzzles").toString().split(",") : [];
var obj = {type,puzzles};
if ( type === "text") {
var id = $(e).find(".editor").attr("id");
Expand Down
127 changes: 71 additions & 56 deletions public/js/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ const onPuzzleResponse = async ({code, correctAnswer, solution, "puzzleOrder": p
updateContent(window.ER.erState.content);

appendRetoMsg(ER.info.escapeRoomPuzzles[puzzleOrder], solution);
createAlert("success", `<b>${i18n.newRetoSuperado}</b><br/> ${msg === i18n.correct ? '': escapeHtml(feedback) }`);

let correct = msg === i18n.correct ? '': escapeHtml(feedback);
let time = 5000;
try {
time = correct.split(" ").length*700;
} catch(e){}
createAlert("success", `<b>${i18n.newRetoSuperado}</b><br/> ${correct}`, false, time);
const isLast = ER.erState.retosSuperados.length === ER.info.totalPuzzles;
if (!isLast) {
const puzzleIndex = ER.info.escapeRoomPuzzles.findIndex(puzzle => puzzle.order == puzzleOrder);
Expand All @@ -179,7 +185,12 @@ const onPuzzleResponse = async ({code, correctAnswer, solution, "puzzleOrder": p
}
} else {
if (msg !== i18n.wrong) {
createAlert("danger", escapeHtml(feedback));
let incorrect = escapeHtml(feedback);
let time = 5000;
try {
time = incorrect.split(" ").length*1000;
} catch(e){}
createAlert("danger", incorrect, false, time);
}
if (ER.erState.waitingForPuzzleReply) {
$('#puzzle-input').addClass(correctAnswer ? 'is-valid':'is-invalid');
Expand All @@ -205,7 +216,11 @@ const onHintResponse = async ({code, hintOrder: hintOrderPlus, puzzleOrder: puzz
appendHint(message, puzzleOrder, category);
$('.reto-hint-title-'+puzzleOrder).first().removeClass('animated')
} else { // Someone in my team obtained a hint
createAlert("success", `<b>${i18n.newHint}</b><br/>${escapeHtml(message)}`);
let time = 10000;
try {
time = message.split(" ").length*700;
} catch(e){}
createAlert("success", `<b>${i18n.newHint}</b><br/>${escapeHtml(message)}`, false, time);
await forMs(1000);
appendHint(message, puzzleOrder, category);
if (!moreAvail) {
Expand Down Expand Up @@ -266,7 +281,8 @@ const onInitialInfo = ({code, erState, participation}) => {
};

const onMessage = ({msg}) => {
alertMsg = createAlert("warning", msg, true);
let time = 5000;
alertMsg = createAlert("warning", msg, true, time);
}

const onRanking = ({ranking}) => {
Expand Down Expand Up @@ -342,7 +358,6 @@ const hintReq = ()=>{
}
}


const closeHintModal = async () => {
// Close hint modal
$('#hintModal').addClass('zoomOut');
Expand Down Expand Up @@ -377,8 +392,8 @@ const appendRetoMsg = (puzzle, sol) => {
const appendExtraInfo = (info) => {
$('.otherList').prepend(otherMsg(info));
$('#other-messages-title').show();

}

const updateHintTooltip = (msg) => {
$('.btn-hints-title').attr("data-original-title", msg).tooltip('update');
if(showNavT) {
Expand All @@ -391,26 +406,26 @@ const updateHintTooltip = (msg) => {

const updatePuzzle = (order, currentPuzzle, prevPuzzleOrder) => {
if (order || order === 0) {
// Update title
$('#puzzle-title').data("puzzleOrder", order);
$('#puzzle-title').text(currentPuzzle.title);
// Update input
$('#puzzle-input').val("");
$('#puzzle-input').focus();
$('#puzzle-input').data("puzzleOrder", order);
$('#puzzle-input').removeClass('is-invalid');
$('#puzzle-input').removeClass('is-valid');
// Update button
$('#puzzle-check-btn').data("puzzleOrder", order);
// Update currentReto in modal
$('.reto-hint-li').removeClass('reto-hint-current');
$('.reto-hint-title-'+order).addClass('reto-hint-current');
if (currentPuzzle.automatic) {
$('#puzzle-form').hide()
} else {
$('#puzzle-form').show()
}
// Update title
$('#puzzle-title').data("puzzleOrder", order);
$('#puzzle-title').text(currentPuzzle.title);
// Update input
$('#puzzle-input').val("");
$('#puzzle-input').focus();
$('#puzzle-input').data("puzzleOrder", order);
$('#puzzle-input').removeClass('is-invalid');
$('#puzzle-input').removeClass('is-valid');
// Update button
$('#puzzle-check-btn').data("puzzleOrder", order);
// Update currentReto in modal
$('.reto-hint-li').removeClass('reto-hint-current');
$('.reto-hint-title-'+order).addClass('reto-hint-current');

if (currentPuzzle.automatic) {
$('#puzzle-form').hide()
} else {
$('#puzzle-form').show()
}
} else {
$('.reto-hint-li').removeClass('reto-hint-current');
$('#puzzle-form').hide();
Expand All @@ -420,33 +435,33 @@ const updatePuzzle = (order, currentPuzzle, prevPuzzleOrder) => {
}


const createAlert = (level = "info", msg, keep = false) => {
const createAlert = (level = "info", msg, keep = false, time = 5000) => {
const config = {"message": msg, "alertType": level, "position": "b l", "hideAnimation": "slide", "showAnimation": "bounce"};
if (!keep) {
config.time = 5000;
config.time = time;
config.autoHide = true;
}
return $.easyAlert(config);
};

const updateHint = (puzzleOrder, hintOrder, category) => {
ER.erState.latestHintObtained = new Date();
if (hintOrder === null) {
ER.erState.customHints++;
}
const currentPuzzle = ER.info.escapeRoomPuzzles.find(puz => puz.order === puzzleOrder);
const actualCat = category || currentPuzzle.categories[0];
if (ER.erState.reqHints[puzzleOrder].indexOf(hintOrder) === -1 ) { // Not hint requested before
ER.erState.reqHints[puzzleOrder].push(hintOrder);
ER.erState.automaticHints++;
if (currentPuzzle && hintOrder !== null) {
const hintArr = currentPuzzle.hints[actualCat];
const idx = hintArr.indexOf(hintOrder);
if (idx !== -1) {
hintArr.splice(idx, 1);
}
ER.erState.latestHintObtained = new Date();
if (hintOrder === null) {
ER.erState.customHints++;
}
const currentPuzzle = ER.info.escapeRoomPuzzles.find(puz => puz.order === puzzleOrder);
const actualCat = category || currentPuzzle.categories[0];
if (ER.erState.reqHints[puzzleOrder].indexOf(hintOrder) === -1 ) { // Not hint requested before
ER.erState.reqHints[puzzleOrder].push(hintOrder);
ER.erState.automaticHints++;
if (currentPuzzle && hintOrder !== null) {
const hintArr = currentPuzzle.hints[actualCat];
const idx = hintArr.indexOf(hintOrder);
if (idx !== -1) {
hintArr.splice(idx, 1);
}
}
}
}

const updateSuperados = (puzzleOrder) => {
Expand All @@ -459,19 +474,19 @@ const updateSuperados = (puzzleOrder) => {
var insertContent = (type, payload, puzzles, index) => {
var content = "";
switch(type){
case "countdown":
content = countdownTemplate();
break;
case "ranking":
content = rankingEmptyTemplate();
break;
case "text":
content = `<div class="cke_editable" id="block-${index}">${escapeUnsafeHtml(payload.text)}</div>`;
break;
case "progress":
content = progressBarTemplate();
break;
default:
case "countdown":
content = countdownTemplate();
break;
case "ranking":
content = rankingEmptyTemplate();
break;
case "text":
content = `<div class="cke_editable" id="block-${index}">${escapeUnsafeHtml(payload.text)}</div>`;
break;
case "progress":
content = progressBarTemplate();
break;
default:
}
var htmlContent = $(blockTemplate(content, index));
$('#editor').append(htmlContent);
Expand Down
Loading

0 comments on commit 7eb5b4b

Please sign in to comment.