Commit cedc3964 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Merge branch 'dstore-migration'

Conflicts:
	src/main/config/libarsnova-application.prod.profile.js
parents c26f7a56 203b2189
......@@ -4,3 +4,6 @@
[submodule "vendor/dojotoolkit.org/util"]
path = vendor/dojotoolkit.org/util
url = https://github.com/dojo/util.git
[submodule "vendor/sitepen.com/dstore"]
path = vendor/sitepen.com/dstore
url = https://github.com/SitePen/dstore.git
......@@ -18,7 +18,8 @@ var profile = (function () {
async: true,
baseUrl: "app/",
paths: {
"dojo": "../lib/dojotoolkit.org/dojo"
"dojo": "../lib/dojotoolkit.org/dojo",
"dstore": "../lib/sitepen.com/dstore"
},
hasCache: {
"config-selectorEngine": "lite"
......@@ -30,6 +31,10 @@ var profile = (function () {
name: "dojo",
location: dojoPath + "dojo"
},
{
name: "dstore",
location: "vendor/sitepen.com/dstore"
},
{
name: "arsnova-api",
location: "src/main/websources/lib/thm.de/arsnova/api"
......
......@@ -17,34 +17,31 @@
*/
define(
[
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dojo/_base/declare",
"arsnova-api/store/RestQueryCache",
"arsnova-api/globalConfig",
"arsnova-api/session",
"arsnova-api/socket"
"arsnova-api/socket",
"arsnova-api/model/AudienceQuestion",
"arsnova-api/model/audienceQuestionPropertyMap"
],
function (JsonRestStore, MemoryStore, CacheStore, globalConfig, sessionModel, socket) {
function (declare, RestQueryCache, globalConfig, sessionModel, socket, AudienceQuestion, audienceQuestionPropertyMap) {
"use strict";
var
self = null,
apiPrefix = globalConfig.get().apiPath + "/audiencequestion/",
questionJsonRest = null,
questionMemory = null,
AudienceQuestionStore = declare(RestQueryCache, {
target: apiPrefix,
model: AudienceQuestion,
propertyMap: audienceQuestionPropertyMap
}),
questionStore = null
;
sessionModel.watchKey(function (name, oldValue, value) {
questionJsonRest = new JsonRestStore({
target: apiPrefix,
idProperty: "_id"
});
questionMemory = new MemoryStore({
idProperty: "_id"
});
questionStore = new CacheStore(questionJsonRest, questionMemory);
questionStore = new AudienceQuestionStore();
});
self = {
......@@ -53,16 +50,16 @@ define(
},
getAll: function () {
return questionStore.query({
return questionStore.filter({
sessionkey: sessionModel.getKey()
});
}).fetch();
},
get: function (id) {
var question = questionStore.get(id);
if (!question.text) {
if (!question.body) {
/* force reloading of question */
questionMemory.remove(id);
questionStore.cachingStore.remove(id);
question = questionStore.get(id);
}
......
......@@ -22,14 +22,18 @@ define(
"dojo/Deferred",
"dojo/when",
"dojo/Stateful",
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"arsnova-api/store/RestQueryCache",
"arsnova-api/globalConfig",
"arsnova-api/session",
"arsnova-api/socket"
"arsnova-api/socket",
"arsnova-api/model/LecturerQuestion",
"arsnova-api/model/lecturerQuestionPropertyMap",
"arsnova-api/model/AnswerChoiceSummary",
"arsnova-api/model/answerChoiceSummaryPropertyMap",
"arsnova-api/model/AnswerText",
"arsnova-api/model/answerTextPropertyMap"
],
function (declare, string, Deferred, when, Stateful, JsonRestStore, MemoryStore, CacheStore, globalConfig, sessionModel, socket) {
function (declare, string, Deferred, when, Stateful, RestQueryCache, globalConfig, sessionModel, socket, LecturerQuestion, lecturerQuestionPropertyMap, AnswerChoiceSummary, answerChoiceSummaryPropertyMap, AnswerText, answerTextPropertyMap) {
"use strict";
var
......@@ -37,19 +41,14 @@ define(
apiPrefix = globalConfig.get().apiPath + "/lecturerquestion/",
answerPath = apiPrefix + "${questionId}/answer/",
questionJsonRest = null,
questionMemory = null,
questionStore = null,
questionCache = null,
questionSortIndex = [],
questionSortIndexPi = [],
questionSortIndexJitt = [],
ftAnswerJsonRest = null,
ftAnswerMemory = null,
ftAnswerStore = null,
answerCountJsonRest = [],
answerCountMemory = [],
answerCountStore = [],
answerCountQuestionId = null,
......@@ -57,7 +56,13 @@ define(
/* declarations of private "methods" */
buildQuestionSortIndex = null,
setupAnswerStore
setupAnswerStore,
LecturerQuestionStore = declare(RestQueryCache, {
target: apiPrefix,
model: LecturerQuestion,
propertyMap: lecturerQuestionPropertyMap
})
;
sessionModel.watchKey(function (name, oldValue, value) {
......@@ -77,15 +82,12 @@ define(
return questionStore;
},
getCache: function () {
return questionCache;
},
resetState: function () {
questionJsonRest = new JsonRestStore({
target: apiPrefix,
idProperty: "_id"
});
questionMemory = new MemoryStore({
idProperty: "_id"
});
questionStore = new CacheStore(questionJsonRest, questionMemory);
questionStore = new LecturerQuestionStore();
subjects = [];
},
......@@ -102,13 +104,15 @@ define(
} else if ("jitt" === type) {
params.preparationquestionsonly = true;
}
var questions = questionStore.query(params);
questions.then(function () {
buildQuestionSortIndex();
// var questions = questionStore.query(params);
var questions = questionStore.filter(params);
questionCache = questions.fetch();
questionCache.then(function (questions) {
subjects = [];
buildQuestionSortIndex(questions);
});
return questions;
return questionCache;
},
get: function (questionId) {
......@@ -116,14 +120,12 @@ define(
},
validate: function (question, noAnswers) {
question.sessionKeyword = sessionModel.getKey();
question.questionVariant = question.questionVariant || "lecture";
question.releasedFor = question.releasedFor || "all";
if (noAnswers || !question.possibleAnswers) {
question.possibleAnswers = [];
question.sessionId = sessionModel.getKey();
if (noAnswers || !question.answerOptions) {
question.answerOptions = [];
}
if (!noAnswers && question.possibleAnswers.length < 2 && "freetext" !== question.questionType
|| !question.subject || !question.text || !sessionModel.getKey()) {
if (!noAnswers && question.answerOptions.length < 2 && "freetext" !== question.format
|| !question.subject || !question.body || !sessionModel.getKey()) {
return null;
}
......@@ -152,7 +154,7 @@ define(
}
return questionStore.put(question, {
id: question._id,
id: question.id,
overwrite: true
});
},
......@@ -247,13 +249,13 @@ define(
return null;
}
return questionStore.query({
return questionStore.filter({
sessionkey: sessionModel.getKey(),
filter: "unanswered"
});
}).fetch();
},
getAnswers: function (questionId, piRound, refresh) {
getAnswers: function (questionId, round, refresh) {
if (questionId !== answerCountQuestionId) {
setupAnswerStore(questionId);
answerCountQuestionId = questionId;
......@@ -261,32 +263,29 @@ define(
var question = self.get(questionId);
return when(question, function (question) {
if ("freetext" === question.questionType) {
if (!refresh && ftAnswerMemory.data.length > 0) {
return ftAnswerMemory.query();
if ("freetext" === question.format) {
if (!refresh && ftAnswerStore.cachingStore.data.length > 0) {
return ftAnswerStore.cachingStore.fetch();
}
return ftAnswerStore.query();
return ftAnswerStore.fetch();
}
if (undefined === piRound || piRound < 1 || piRound > 2) {
piRound = question.piRound;
if (undefined === round || round < 1 || round > 2) {
round = question.round;
}
if (refresh || !answerCountStore[piRound]) {
answerCountJsonRest[piRound] = new JsonRestStore({
target: string.substitute(answerPath, {questionId: question._id}),
idProperty: "answerText"
if (refresh || !answerCountStore[round]) {
answerCountStore[round] = new RestQueryCache({
target: string.substitute(answerPath, {questionId: question.id}),
model: AnswerChoiceSummary,
propertyMap: answerChoiceSummaryPropertyMap
});
answerCountMemory[piRound] = new MemoryStore({
idProperty: "answerText"
});
answerCountStore[piRound] = new CacheStore(answerCountJsonRest[piRound], answerCountMemory[piRound]);
return answerCountStore[piRound].query({piround: piRound});
return answerCountStore[round].filter({round: round}).fetch();
}
return answerCountMemory[piRound].query();
return answerCountStore[round].cachingStore.fetch();
});
},
......@@ -319,8 +318,8 @@ define(
return when(question, function (question) {
question.active = !lockQuestion;
question.showStatistic = !lockStats;
question.showAnswer = !lockCorrect;
question.publishResults = !lockStats;
question.publishCorrectAnswer = !lockCorrect;
return self.update(question);
});
......@@ -329,14 +328,14 @@ define(
startSecondPiRound: function (questionId) {
var question = self.get(questionId);
return when(question, function (question) {
question.piRound = 2;
question.round = 2;
return self.update(question);
});
},
getSubjects: function () {
if (0 === subjects.length && questionMemory) {
questionMemory.query().forEach(function (question) {
if (0 === subjects.length && questionStore) {
questionCache.forEach(function (question) {
if (-1 === subjects.indexOf(question.subject)) {
subjects.push(question.subject);
}
......@@ -352,11 +351,10 @@ define(
}
};
buildQuestionSortIndex = function () {
buildQuestionSortIndex = function (questions) {
questionSortIndex = [];
questionSortIndexPi = [];
questionSortIndexJitt = [];
var questions = questionMemory.query();
questions.sort(function (q1, q2) {
var r = q1.subject.localeCompare(q2.subject);
......@@ -364,32 +362,29 @@ define(
r = q1.number - q2.number;
}
if (0 === r) {
r = q1.text.localeCompare(q2.text);
r = q1.body.localeCompare(q2.body);
}
return r;
});
questions.forEach(function (question) {
questionSortIndex.push(question._id);
if ("lecture" === question.questionVariant) {
questionSortIndexPi.push(question._id);
questionSortIndex.push(question.id);
if ("lecture" === question.type) {
questionSortIndexPi.push(question.id);
}
if ("preparation" === question.questionVariant) {
questionSortIndexJitt.push(question._id);
if ("preparation" === question.type) {
questionSortIndexJitt.push(question.id);
}
});
};
setupAnswerStore = function (questionId) {
ftAnswerJsonRest = new JsonRestStore({
ftAnswerStore = new RestQueryCache({
target: string.substitute(answerPath, {questionId: questionId}),
idProperty: "_id"
});
ftAnswerMemory = new MemoryStore({
idProperty: "_id"
model: AnswerText,
propertyMap: answerTextPropertyMap
});
ftAnswerStore = new CacheStore(ftAnswerJsonRest, ftAnswerMemory);
/* remove cached answers */
answerCountStore = [];
......
/*
* This file is part of libarsnova-js.
* Copyright 2013-2014 Daniel Gerhardt <code@dgerhardt.net>
*
* libarsnova-js is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libarsnova-js is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define(
[
"dojo/_base/declare",
"dstore/Model"
],
function (declare, Model) {
"use strict";
return declare(Model, {
schema: {
choices: {
type: "string",
required: true
},
count: {
type: "number",
required: false,
"default": 0
},
abstention: {
type: "boolean",
required: false,
"default": false
}
}
});
}
);
/*
* This file is part of libarsnova-js.
* Copyright 2013-2014 Daniel Gerhardt <code@dgerhardt.net>
*
* libarsnova-js is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libarsnova-js is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define(
[
"dojo/_base/declare",
"dstore/Model"
],
function (declare, Model) {
"use strict";
return declare(Model, {
schema: {
id: {
type: "string",
required: false
},
questionId: {
type: "string",
required: true
},
subject: {
type: "string",
required: true
},
body: {
type: "string",
required: true
},
read: {
type: "boolean",
required: false,
"default": false
},
creation: {
type: "number",
required: false
}
}
});
}
);
/*
* This file is part of libarsnova-js.
* Copyright 2013-2014 Daniel Gerhardt <code@dgerhardt.net>
*
* libarsnova-js is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libarsnova-js is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define(
[
"dojo/_base/declare",
"dstore/Model"
],
function (declare, Model) {
"use strict";
return declare(Model, {
schema: {
id: {
type: "string",
required: false
},
sessionId: {
type: "string",
required: true
},
subject: {
type: "string",
required: true
},
body: {
type: "string",
required: true
},
read: {
type: "boolean",
required: false,
"default": false
},
creation: {
type: "number",
required: false
}
}
});
}
);
/*
* This file is part of libarsnova-js.
* Copyright 2013-2014 Daniel Gerhardt <code@dgerhardt.net>
*
* libarsnova-js is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libarsnova-js is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define(
[
"dojo/_base/declare",
"dstore/Model"
],
function (declare, Model) {
"use strict";
return declare(Model, {
schema: {
id: {
type: "string",
required: false
},
sessionId: {
type: "string",
required: true
},
type: {
type: "string",
required: true,
"default": "lecture"
},
format: {
type: "string",
required: true
},
subject: {
type: "string",
required: true
},
body: {
type: "string",
required: true
},
active: {
type: "boolean",
required: true,
"default": true
},
number: {
type: "number",
required: false