diff --git a/src/main/webapp/app/controller/QuestionExport.js b/src/main/webapp/app/controller/QuestionExport.js index fdaf1a60985f7df6fe210327788ced0168c37207..2569161b627aa271d0c54823da77df1bd8f630ef 100644 --- a/src/main/webapp/app/controller/QuestionExport.js +++ b/src/main/webapp/app/controller/QuestionExport.js @@ -148,12 +148,6 @@ Ext.define("ARSnova.controller.QuestionExport", { }); }, - saveClickQuestionOnFileSystem: function (questionObj, questionSubject) { - var rawJson = JSON.stringify(questionObj); - var blob = new Blob([rawJson], {type: "application/json;charset=utf-8"}); - this.makeAndClickDownloadLink(blob, localStorage.getItem('shortName') + "_" + questionSubject + ".json"); - }, - parseJsonToCsv: function (records, delimiter, excel) { var preparsedQuestion = this.preparseJsontoCsv(records); var csv = ARSnova.utils.CsvUtil.jsonToCsv(preparsedQuestion, delimiter); @@ -163,64 +157,34 @@ Ext.define("ARSnova.controller.QuestionExport", { this.saveFileOnFileSystem(csv, this.filename()); }, - downloadQuestionAnswers: function (questionObj, answers) { + downloadQuestionAnswers: function (questionObj, answers, delimiter, excel) { var header, rows = []; if (questionObj.questionType === 'freetext') { - header = Messages.QUESTION_DATE + "," + Messages.QUESTIONS_CSV_EXPORT_ANSWERS_TIME + "," + Messages.QUESTIONS_CSV_EXPORT_ANSWERS_SUBJECT + "," + Messages.FREETEXT_DETAIL_ANSWER + ",Timestamp"; + rows.push([ + Messages.QUESTION_DATE, + Messages.QUESTIONS_CSV_EXPORT_ANSWERS_TIME, + Messages.QUESTIONS_CSV_EXPORT_ANSWERS_SUBJECT, + Messages.FREETEXT_DETAIL_ANSWER, + "Timestamp"]); answers.each(function (record) { rows.push([record.get('groupDate'), record.get('formattedTime'), record.get('answerSubject'), record.get('answerText'), record.get('timestamp')]); }); } else { - header = Messages.ANSWERS + "," - + Messages.FIRST_ROUND + " " + Messages.GRID_LABEL_RELATIVE + "," + Messages.FIRST_ROUND + " " + Messages.GRID_LABEL_ABSOLUTE + "," - + Messages.SECOND_ROUND + " " + Messages.GRID_LABEL_RELATIVE + "," + Messages.SECOND_ROUND + " " + Messages.GRID_LABEL_ABSOLUTE; + rows.push([ + Messages.ANSWERS, + Messages.FIRST_ROUND + " " + Messages.GRID_LABEL_RELATIVE, + Messages.FIRST_ROUND + " " + Messages.GRID_LABEL_ABSOLUTE, + Messages.SECOND_ROUND + " " + Messages.GRID_LABEL_RELATIVE, + Messages.SECOND_ROUND + " " + Messages.GRID_LABEL_ABSOLUTE]); answers.each(function (record) { rows.push([record.get('text'), record.get('percent-round1'), record.get('value-round1'), record.get('percent-round2'), record.get('value-round2')]); }); } - var csv = ARSnova.utils.CsvUtil.jsonToCsv(rows); - this.saveFileOnFileSystem(header + "\n" + csv, "answer-stats-" + this.getActualDate() + ".csv"); - }, - - parseAnswerOptionsForClick: function (question) { - var clickAnswerOptions = []; - if (question.questionType === "freetext" && question.fixedAnswer) { - clickAnswerOptions.push({ - hashtag: "ImportFromARSnova", - questionIndex: 0, - answerText: question.correctAnswer, - answerOptionNumber: 0, - configCaseSensitive: !question.ignoreCaseSensitive, - configTrimWhitespaces: !question.ignoreWhiteSpaces, - configUsePunctuation: !question.ignorePunctuation, - configUseKeywords: true, - type: "FreeTextAnswerOption" - }); - } else if (question.questionType === "abcd") { - // slice off the "A", "B".. from the answer options - for (var j = 0; j < question.possibleAnswers.length; j++) { - clickAnswerOptions.push({ - hashtag: "ImportFromARSnova", - questionIndex: 0, - answerText: question.possibleAnswers[j].text.slice(3), - answerOptionNumber: j, - isCorrect: question.possibleAnswers[j].correct, - type: "DefaultAnswerOption" - }); - } - } else { - for (var i = 0; i < question.possibleAnswers.length; i++) { - clickAnswerOptions.push({ - hashtag: "ImportFromARSnova", - questionIndex: 0, - answerText: question.possibleAnswers[i].text, - answerOptionNumber: i, - isCorrect: question.possibleAnswers[i].correct, - type: "DefaultAnswerOption" - }); - } + var csv = ARSnova.utils.CsvUtil.jsonToCsv(rows, delimiter); + if (excel) { + csv = 'sep=' + delimiter + '\r\n' + csv; } - return clickAnswerOptions; + this.saveFileOnFileSystem(csv, "answer-stats-" + this.getActualDate() + ".csv"); } }); diff --git a/src/main/webapp/app/view/FreetextAnswerPanel.js b/src/main/webapp/app/view/FreetextAnswerPanel.js index fcd1be8ef937e4817efc9b69f49cba95b00d955f..5f57c96d9ef9d648779e28eb416ca7531fe40d32 100644 --- a/src/main/webapp/app/view/FreetextAnswerPanel.js +++ b/src/main/webapp/app/view/FreetextAnswerPanel.js @@ -119,13 +119,18 @@ Ext.define('ARSnova.view.FreetextAnswerPanel', { } }); + this.exportCsvPanel = Ext.create('ARSnova.view.components.CsvExportMessageBox', { + exportCallback: Ext.bind(this.exportCsv, this) + }); + this.exportButton = Ext.create('Ext.Button', { xtype: 'button', text: Messages.EXPORT_BUTTON_LABEL, align: 'right', handler: function () { - ARSnova.app.getController('QuestionExport').downloadQuestionAnswers(self.questionObj, self.freetextAnswerStore); + this.exportCsvPanel.show(); }, + scope: this, hidden: (ARSnova.app.userRole === ARSnova.app.USER_ROLE_STUDENT) }); @@ -408,5 +413,9 @@ Ext.define('ARSnova.view.FreetextAnswerPanel', { console.log('server-side error'); } }, -1, -1); + }, + + exportCsv: function (delimiter, excel) { + ARSnova.app.getController('QuestionExport').downloadQuestionAnswers(this.questionObj, this.freetextAnswerStore, delimiter, excel); } }); diff --git a/src/main/webapp/app/view/components/CsvExportMessageBox.js b/src/main/webapp/app/view/components/CsvExportMessageBox.js new file mode 100644 index 0000000000000000000000000000000000000000..8799a4951f68ab1033129f82932bc4185381188e --- /dev/null +++ b/src/main/webapp/app/view/components/CsvExportMessageBox.js @@ -0,0 +1,86 @@ +/* + * This file is part of ARSnova Mobile. + * Copyright (C) 2011-2012 Christian Thomas Weber + * Copyright (C) 2012-2019 The ARSnova Team and Contributors + * + * ARSnova Mobile is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ARSnova Mobile 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ARSnova Mobile. If not, see <http://www.gnu.org/licenses/>. + */ +Ext.define('ARSnova.view.components.CsvExportMessageBox', { + extend: 'Ext.MessageBox', + + config: { + exportCallback: Ext.emptyFn, + + hideOnMaskTap: true, + cls: 'importExportFilePanel', + title: Messages.QUESTIONS_EXPORT_MSBOX_TITLE + }, + + initialize: function () { + this.add([{ + xtype: 'button', + iconCls: 'icon-close', + cls: 'closeButton', + handler: function () { this.getParent().hide(); } + }, { + html: Messages.QUESTIONS_CSV_EXPORT_DELIMITER_INFO, + cls: 'x-msgbox-text' + }, { + xtype: 'container', + layout: 'vbox', + defaults: { + scope: this + }, + items: [ + { + xtype: 'fieldset', + itemId: 'csvDelimiterField', + defaults: { + xtype: 'radiofield', + labelWidth: '60%' + }, + items: [{ + name: 'delimiter', + label: Messages.QUESTIONS_CSV_EXPORT_COMMA, + value: ',', + checked: true + }, { + name: 'delimiter', + label: Messages.QUESTIONS_CSV_EXPORT_SEMICOLON, + value: ';' + }, { + name: 'delimiter', + label: Messages.QUESTIONS_CSV_EXPORT_TABULATOR, + value: '\t' + }] + }, { + xtype: 'togglefield', + itemId: 'excelField', + name: 'excel', + label: Messages.QUESTIONS_CSV_EXPORT_EXCEL, + labelWidth: '60%' + }, { + xtype: 'button', + ui: 'action', + text: Messages.EXPORT_BUTTON_LABEL, + handler: function () { + var csvDelimiterField = this.down('#csvDelimiterField'); + var excelField = this.down('#excelField'); + this.getExportCallback()(csvDelimiterField.items.items[0].getGroupValue(), excelField.getValue()); + this.hide(); + } + }] + }]); + } +}); diff --git a/src/main/webapp/app/view/speaker/AudienceQuestionPanel.js b/src/main/webapp/app/view/speaker/AudienceQuestionPanel.js index ec4fc4849bab60ae3f7e890a73d20e2acad75863..aaa428a28d387161330ab54346075c1abd7df456 100644 --- a/src/main/webapp/app/view/speaker/AudienceQuestionPanel.js +++ b/src/main/webapp/app/view/speaker/AudienceQuestionPanel.js @@ -22,6 +22,7 @@ Ext.define('ARSnova.view.speaker.AudienceQuestionPanel', { requires: [ 'ARSnova.view.Caption', 'ARSnova.model.Question', + 'ARSnova.view.components.CsvExportMessageBox', 'ARSnova.view.speaker.MultiVoteStatusButton', 'ARSnova.view.speaker.MultiQuestionStatusButton', 'ARSnova.view.speaker.SortQuestionsPanel' @@ -315,64 +316,8 @@ Ext.define('ARSnova.view.speaker.AudienceQuestionPanel', { }] }); - this.exportCsvPanel = Ext.create('Ext.MessageBox', { - hideOnMaskTap: true, - cls: 'importExportFilePanel', - title: Messages.QUESTIONS_EXPORT_MSBOX_TITLE, - items: [{ - xtype: 'button', - iconCls: 'icon-close', - cls: 'closeButton', - handler: function () { this.getParent().hide(); } - }, { - html: Messages.QUESTIONS_CSV_EXPORT_DELIMITER_INFO, - cls: 'x-msgbox-text' - }, { - xtype: 'container', - layout: 'vbox', - defaults: { - scope: this - }, - items: [ - { - xtype: 'fieldset', - itemId: 'csvDelimiterField', - defaults: { - xtype: 'radiofield', - labelWidth: '60%' - }, - items: [{ - name: 'delimiter', - label: Messages.QUESTIONS_CSV_EXPORT_COMMA, - value: ',', - checked: true - }, { - name: 'delimiter', - label: Messages.QUESTIONS_CSV_EXPORT_SEMICOLON, - value: ';' - }, { - name: 'delimiter', - label: Messages.QUESTIONS_CSV_EXPORT_TABULATOR, - value: '\t' - }] - }, { - xtype: 'togglefield', - itemId: 'excelField', - name: 'excel', - label: Messages.QUESTIONS_CSV_EXPORT_EXCEL, - labelWidth: '60%' - }, { - xtype: 'button', - ui: 'action', - text: Messages.EXPORT_BUTTON_LABEL, - handler: function () { - var csvDelimiterField = this.exportCsvPanel.down('#csvDelimiterField'); - var excelField = this.exportCsvPanel.down('#excelField'); - this.exportCsv(csvDelimiterField.items.items[0].getGroupValue(), excelField.getValue()); - this.exportCsvPanel.hide(); - } - }] - }] + this.exportCsvPanel = Ext.create('ARSnova.view.components.CsvExportMessageBox', { + exportCallback: Ext.bind(this.exportCsv, this) }); this.actionButtonPanel = Ext.create('Ext.Panel', { diff --git a/src/main/webapp/app/view/speaker/QuestionStatisticChart.js b/src/main/webapp/app/view/speaker/QuestionStatisticChart.js index 4cd4e43fa37389f8154f6c38fa6ab322c2a279c9..a7a64d8e52fb9a2f3be277735ed9a16066932c1a 100755 --- a/src/main/webapp/app/view/speaker/QuestionStatisticChart.js +++ b/src/main/webapp/app/view/speaker/QuestionStatisticChart.js @@ -149,6 +149,10 @@ Ext.define('ARSnova.view.speaker.QuestionStatisticChart', { align: 'right' }); + this.exportCsvPanel = Ext.create('ARSnova.view.components.CsvExportMessageBox', { + exportCallback: Ext.bind(this.exportCsv, this) + }); + this.toolbar = Ext.create('Ext.TitleBar', { docked: 'top', ui: 'light', @@ -168,8 +172,9 @@ Ext.define('ARSnova.view.speaker.QuestionStatisticChart', { text: Messages.EXPORT_BUTTON_LABEL, align: 'right', handler: function () { - ARSnova.app.getController('QuestionExport').downloadQuestionAnswers(me.questionObj, me.questionStore); + this.exportCsvPanel.show(); }, + scope: this, hidden: (ARSnova.app.userRole === ARSnova.app.USER_ROLE_STUDENT || me.questionObj.questionType === 'grid') } ] @@ -985,5 +990,9 @@ Ext.define('ARSnova.view.speaker.QuestionStatisticChart', { }); return lighterColors; + }, + + exportCsv: function (delimiter, excel) { + ARSnova.app.getController('QuestionExport').downloadQuestionAnswers(this.questionObj, this.questionStore, delimiter, excel); } });