From 94552aa01e3167f0883ff695a2a3d5780285473a Mon Sep 17 00:00:00 2001 From: hjank <jank@uni-potsdam.de> Date: Wed, 6 Jan 2016 10:10:00 +0100 Subject: [PATCH] # index.html: in horizontal top menu bar: moved showContact to the right + authorSystemContentModel.js: added getContextInformation() which returns a list of all added context items + index.html: in horizontal top menu bar: re-added statistics-menu (for downloading that list) + main.js: added event handler for that menu: download list + added possibility to convert JSON objects to ContextInformation, including Parameter, and generate a ContextInfoList from them + added function addItem() to ContextInfoListModel --- index.html | 8 ++++++- .../models/authorSystemContentModel.js | 16 +++++++++++++ js/authoring/models/contextInfoListModel.js | 24 +++++++++++++++++++ js/authoring/models/contextInfoModel.js | 15 ++++++++---- js/authoring/models/parameterModel.js | 7 ++++++ js/main.js | 9 +++++++ 6 files changed, 73 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 3768192..d9c3ed2 100644 --- a/index.html +++ b/index.html @@ -134,7 +134,12 @@ </li> <!--<li><a href="#test"><b class="fui-exit"></b> Testen</a></li>--> <!--<li id="navHeadStatistic"><a href="#statistic"><img src="img/Icons/iconmonstr-bar-chart-icon-32.png"> Statistiken</a></li>--> - <li id="showContact"><a href="#"><b class="fui-document"></b> Kontakt</a></li> + <li class="dropdown"> + <a id="navHeadStatistic" href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="img/Icons/iconmonstr-bar-chart-icon-32.png"> Statistiken</a> + <ul class="dropdown-menu"> + <li id="downloadContextData"><a href="#">Herunterladen <b class="fui-triangle-down" style="float: right"></b></a></li> + </ul> + </li> </ul> <ul class="nav navbar-nav navbar-right"> <li class="dropdown"> @@ -144,6 +149,7 @@ <li id="showLogin"><a href="#">Logout <b class="fui-lock" style="float: right"></b></a></li> </ul> </li> + <li id="showContact"><a href="#"><b class="fui-document"></b> Kontakt</a></li> <li class="active" id="showHelp" style="cursor: pointer"><a><b class="fui-question-circle"></b> Hilfe</a></li> </ul> </div> diff --git a/js/authoring/models/authorSystemContentModel.js b/js/authoring/models/authorSystemContentModel.js index 593392c..e24c9bd 100644 --- a/js/authoring/models/authorSystemContentModel.js +++ b/js/authoring/models/authorSystemContentModel.js @@ -61,4 +61,20 @@ AuthorSystemContent.prototype.removeScenario = function(scenarioName) { if (scenario.getName() == scenarioName) this._scenarioList.splice(i, 1); } +}; + +AuthorSystemContent.prototype.getContextInformation = function() { + var contextList = []; + for (var i in this._scenarioList) { + var unitList = this._scenarioList[i].getUnits(); + for (var j in unitList) { + var unitContext = unitList[j].getContextData(); + for (var k in unitContext) { + var contextItem = unitContext[k]; + if (contextList.indexOf(contextItem) == -1) + contextList.push(contextItem); + } + } + } + return contextList; }; \ No newline at end of file diff --git a/js/authoring/models/contextInfoListModel.js b/js/authoring/models/contextInfoListModel.js index a2f8c72..fbccec0 100644 --- a/js/authoring/models/contextInfoListModel.js +++ b/js/authoring/models/contextInfoListModel.js @@ -44,6 +44,26 @@ function ContextInfoList() { return this; } +// generates and adds a new items list from a list of JSON objects duck-typable as ContextInformation +ContextInfoList.prototype.fromJSON = function (data) { + for (var i in data) { + // "cast" the context items to ContextInformation and remove previously entered values + var contextItem = new ContextInformation().fromJSON(data[i]); + contextItem.setChosenValue(""); + contextItem.setChosenOperator(""); + + // "cast" the item's parameters to Parameter and remove previously entered values + var parameters = [], tempParams = contextItem.getParameters(); + for (var ip in tempParams) { + var param = new Parameter().fromJSON(tempParams[ip]); + param.setChosenValue(""); + parameters.push(param); + } + contextItem.setParameters(parameters); + this._items.push(contextItem); + } +}; + ContextInfoList.prototype.initClasses = function () { for (var key in contextClassDictionary) this._classes.push(key); @@ -53,6 +73,10 @@ ContextInfoList.prototype.setItems = function (items) { this._items = items; }; +ContextInfoList.prototype.addItem = function (item) { + this._items.push(item); +}; + ContextInfoList.prototype.getItems = function () { return this._items; }; diff --git a/js/authoring/models/contextInfoModel.js b/js/authoring/models/contextInfoModel.js index 7174774..7918129 100644 --- a/js/authoring/models/contextInfoModel.js +++ b/js/authoring/models/contextInfoModel.js @@ -2,9 +2,7 @@ * Created by Helena on 04.09.2015. */ - - -// the list of all available context information data types +// the data structure of a context item function ContextInformation() { this._id = ""; @@ -13,15 +11,22 @@ function ContextInformation() { this._min = ""; this._max = ""; this._default = ""; - this._chosenValue = ""; + this._chosenValue = ""; // set by the author in unit editing this._operators = []; - this._chosenOperator = ""; + this._chosenOperator = ""; // set by the author in unit editing this._enums = []; this._parameters = []; return this; } +// support "casting" a duck-typed JSON object to ContextInformation +ContextInformation.prototype.fromJSON = function(item) { + for (i in item) + this[i] = item[i]; + return this; +}; + // getters ContextInformation.prototype.getID = function () { return this._id; diff --git a/js/authoring/models/parameterModel.js b/js/authoring/models/parameterModel.js index 7d09245..51f83d1 100644 --- a/js/authoring/models/parameterModel.js +++ b/js/authoring/models/parameterModel.js @@ -15,6 +15,13 @@ function Parameter() { return this; } +// support "casting" a duck-typed JSON object to Parameter +Parameter.prototype.fromJSON = function(item) { + for (i in item) this[i] = item[i]; + + return this; +}; + // getters Parameter.prototype.getID = function () { return this._id; diff --git a/js/main.js b/js/main.js index cf96422..202e518 100644 --- a/js/main.js +++ b/js/main.js @@ -29,4 +29,13 @@ jsPlumb.ready(function () { // reload data from localStorage initLoader(); + $("#navHeadStatistic").on("click", function() { + var obj = authorSystemContent.getContextInformation(); + var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(obj)); + + var a = $("#downloadContextData > a")[0]; + a.href = 'data:' + data; + a.download = 'data.json'; + }); + }); \ No newline at end of file -- GitLab