From 0a68c393560186698b1329e88aee0e5c9ad25e0c Mon Sep 17 00:00:00 2001 From: David Rise Knotten Date: Mon, 12 Apr 2021 21:52:59 +0200 Subject: [PATCH 1/5] Added some of the headwork for a responsive close issue text --- amd/src/issue_view.js | 18 ++++++++++++++++++ classes/output/question_issue_page.php | 2 ++ lang/en/local_qtracker.php | 3 ++- templates/question_issue_page.mustache | 7 +++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 amd/src/issue_view.js diff --git a/amd/src/issue_view.js b/amd/src/issue_view.js new file mode 100644 index 0000000..c13a006 --- /dev/null +++ b/amd/src/issue_view.js @@ -0,0 +1,18 @@ + + + +class IssueView { + constructor() { + const commentandcommitbtn = $("button[name=closeissue]"); + const comment = $("#commenteditoreditable").children("p"); + comment.onchange(event => { + console.log('comment has changed') + if (event.target.value == "") { + commentandcommitbtn.text = closeissuestring; + } else { + commentandcommitbtn.text = commentandcloseissuestring; + } + }) + } + +} diff --git a/classes/output/question_issue_page.php b/classes/output/question_issue_page.php index 01f5d70..38eb474 100644 --- a/classes/output/question_issue_page.php +++ b/classes/output/question_issue_page.php @@ -170,6 +170,8 @@ public function export_for_template(renderer_base $output) { $form = new question_details_form($question, $PAGE->url); $questiondata->questiontext = $form->render(); $data->question = $questiondata; + $data->closeissue = get_string('closeissue', 'local_qtracker'); + $data->commentandcloseisue = get_string('commentandcloseissue', 'local_qtracker'); // Setup text editor. $editor = editors_get_preferred_editor(FORMAT_HTML); diff --git a/lang/en/local_qtracker.php b/lang/en/local_qtracker.php index 1e7e4b8..7c96bdb 100755 --- a/lang/en/local_qtracker.php +++ b/lang/en/local_qtracker.php @@ -80,7 +80,8 @@ $string['closed'] = 'Closed'; $string['reopenissue'] = 'Reopen issue'; -$string['closeissue'] = 'Comment and close issue'; +$string['closeissue'] = 'Close issue'; +$string['commentandcloseissue'] = 'Comment and close issue'; $string['comment'] = 'Comment'; $string['confirm'] = 'Confirm'; diff --git a/templates/question_issue_page.mustache b/templates/question_issue_page.mustache index 9d3499b..2cd289c 100644 --- a/templates/question_issue_page.mustache +++ b/templates/question_issue_page.mustache @@ -125,3 +125,10 @@ {{/questionissue}} +{{#js}} + require(['jquery', 'local_qtracker/issue_view'], function($, IssueView) { + var closeissuestring = "{{closeissue}}" + var commentandcloseissuestring = "{{commentandcloseisue}}" + new IssueView(); + }); +{{/js}} From dd0fddaac237d377b3dfed8177e40d00ffd80c5b Mon Sep 17 00:00:00 2001 From: David Rise Knotten Date: Thu, 6 May 2021 21:52:23 +0200 Subject: [PATCH 2/5] IssueView class --- amd/src/issue_view.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/amd/src/issue_view.js b/amd/src/issue_view.js index c13a006..c28b874 100644 --- a/amd/src/issue_view.js +++ b/amd/src/issue_view.js @@ -1,18 +1,17 @@ - class IssueView { constructor() { - const commentandcommitbtn = $("button[name=closeissue]"); - const comment = $("#commenteditoreditable").children("p"); - comment.onchange(event => { - console.log('comment has changed') - if (event.target.value == "") { - commentandcommitbtn.text = closeissuestring; + const commentandcommitbtn = $("button[name=closeissue]").get(0); + const commentEditor = $("#commenteditor").get(0); + commentEditor.addEventListener("change", event => { + if (commentEditor.value == ('


')) { + commentandcommitbtn.innerText = closeissuestring; } else { - commentandcommitbtn.text = commentandcloseissuestring; + commentandcommitbtn.innerText = commentandcloseissuestring; } }) } - } + + From 9190392e7d9887e9f03dbc199f2898afbee9eef9 Mon Sep 17 00:00:00 2001 From: David Rise Knotten Date: Fri, 4 Jun 2021 22:28:17 +0200 Subject: [PATCH 3/5] Made close and comment button responsive --- amd/build/issue_view.js | 18 +++++++++++++++++ amd/build/issue_view.min.js | 2 ++ amd/build/issue_view.min.js.map | 1 + amd/src/issue_view.js | 28 ++++++++++++++------------ classes/output/question_issue_page.php | 1 + templates/question_issue_page.mustache | 4 +++- 6 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 amd/build/issue_view.js create mode 100644 amd/build/issue_view.min.js create mode 100644 amd/build/issue_view.min.js.map diff --git a/amd/build/issue_view.js b/amd/build/issue_view.js new file mode 100644 index 0000000..c13a006 --- /dev/null +++ b/amd/build/issue_view.js @@ -0,0 +1,18 @@ + + + +class IssueView { + constructor() { + const commentandcommitbtn = $("button[name=closeissue]"); + const comment = $("#commenteditoreditable").children("p"); + comment.onchange(event => { + console.log('comment has changed') + if (event.target.value == "") { + commentandcommitbtn.text = closeissuestring; + } else { + commentandcommitbtn.text = commentandcloseissuestring; + } + }) + } + +} diff --git a/amd/build/issue_view.min.js b/amd/build/issue_view.min.js new file mode 100644 index 0000000..cd1c901 --- /dev/null +++ b/amd/build/issue_view.min.js @@ -0,0 +1,2 @@ +function _classCallCheck(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}define ("local_qtracker/issue_view",["jquery"],function(a){return function b(c,d){_classCallCheck(this,b);var e=a("button[name=closeissue]").get(0),f=a("#commenteditor").get(0);f.addEventListener("change",function(){if("


"==f.value){e.innerText=c}else{e.innerText=d}})}}); +//# sourceMappingURL=issue_view.min.js.map diff --git a/amd/build/issue_view.min.js.map b/amd/build/issue_view.min.js.map new file mode 100644 index 0000000..9b4b9a2 --- /dev/null +++ b/amd/build/issue_view.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/issue_view.js"],"names":["define","$","closeissuestring","commentandcloseissuestring","commentandcommitbtn","get","commentEditor","addEventListener","value","innerText"],"mappings":"8GACAA,OAAM,6BAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,CAe3B,MAbI,YAAYC,CAAZ,CAA8BC,CAA9B,CAA0D,4BAChDC,CAAAA,CAAmB,CAAGH,CAAC,CAAC,yBAAD,CAAD,CAA6BI,GAA7B,CAAiC,CAAjC,CAD0B,CAEhDC,CAAa,CAAGL,CAAC,CAAC,gBAAD,CAAD,CAAoBI,GAApB,CAAwB,CAAxB,CAFgC,CAGtDC,CAAa,CAACC,gBAAd,CAA+B,QAA/B,CAAyC,UAAS,CAC9C,GAA4B,qDAAxB,EAAAD,CAAa,CAACE,KAAlB,CAAgF,CAC5EJ,CAAmB,CAACK,SAApB,CAAgCP,CACnC,CAFD,IAEO,CACHE,CAAmB,CAACK,SAApB,CAAgCN,CACnC,CACJ,CAND,CAOH,CAKR,CAjBK,CAAN","sourcesContent":["\ndefine(['jquery'], function($) {\n class IssueView {\n constructor(closeissuestring, commentandcloseissuestring) {\n const commentandcommitbtn = $(\"button[name=closeissue]\").get(0);\n const commentEditor = $(\"#commenteditor\").get(0);\n commentEditor.addEventListener(\"change\", event => {\n if (commentEditor.value == ('


')) {\n commentandcommitbtn.innerText = closeissuestring;\n } else {\n commentandcommitbtn.innerText = commentandcloseissuestring;\n }\n })\n }\n }\n\n return IssueView;\n\n})\n"],"file":"issue_view.min.js"} \ No newline at end of file diff --git a/amd/src/issue_view.js b/amd/src/issue_view.js index c28b874..99a746a 100644 --- a/amd/src/issue_view.js +++ b/amd/src/issue_view.js @@ -1,17 +1,19 @@ - -class IssueView { - constructor() { - const commentandcommitbtn = $("button[name=closeissue]").get(0); - const commentEditor = $("#commenteditor").get(0); - commentEditor.addEventListener("change", event => { - if (commentEditor.value == ('


')) { - commentandcommitbtn.innerText = closeissuestring; - } else { - commentandcommitbtn.innerText = commentandcloseissuestring; - } - }) +define(['jquery'], function($) { + class IssueView { + constructor(closeissuestring, commentandcloseissuestring) { + const commentandcommitbtn = $("button[name=closeissue]").get(0); + const commentEditor = $("#commenteditor").get(0); + commentEditor.addEventListener("change", event => { + if (commentEditor.value == ('


')) { + commentandcommitbtn.innerText = closeissuestring; + } else { + commentandcommitbtn.innerText = commentandcloseissuestring; + } + }) + } } -} + return IssueView; +}) diff --git a/classes/output/question_issue_page.php b/classes/output/question_issue_page.php index 38eb474..ae9c641 100644 --- a/classes/output/question_issue_page.php +++ b/classes/output/question_issue_page.php @@ -152,6 +152,7 @@ public function export_for_template(renderer_base $output) { $commentbutton->name = "commentissue"; $commentbutton->value = true; $commentbutton->label = get_string('comment', 'local_qtracker'); + $commentbutton->id = 11; $data->commentbutton = $commentbutton; $question = \question_bank::load_question($this->questionissue->get_questionid()); diff --git a/templates/question_issue_page.mustache b/templates/question_issue_page.mustache index 2cd289c..d41c041 100644 --- a/templates/question_issue_page.mustache +++ b/templates/question_issue_page.mustache @@ -127,8 +127,10 @@ {{#js}} require(['jquery', 'local_qtracker/issue_view'], function($, IssueView) { + if ($("[name='closeissue']").length) { var closeissuestring = "{{closeissue}}" var commentandcloseissuestring = "{{commentandcloseisue}}" - new IssueView(); + new IssueView(closeissuestring, commentandcloseissuestring); + } }); {{/js}} From 7db9b48db668d1192a9e73c5d7f56dc46e727a38 Mon Sep 17 00:00:00 2001 From: David Rise Knotten Date: Sat, 12 Jun 2021 15:05:14 +0200 Subject: [PATCH 4/5] Refactored out requirejs from issue view --- amd/build/issue_view.min.js | 2 +- amd/build/issue_view.min.js.map | 2 +- amd/src/issue_view.js | 31 +++++++++++++------------- templates/question_issue_page.mustache | 8 +++---- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/amd/build/issue_view.min.js b/amd/build/issue_view.min.js index cd1c901..3f96f2d 100644 --- a/amd/build/issue_view.min.js +++ b/amd/build/issue_view.min.js @@ -1,2 +1,2 @@ -function _classCallCheck(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}define ("local_qtracker/issue_view",["jquery"],function(a){return function b(c,d){_classCallCheck(this,b);var e=a("button[name=closeissue]").get(0),f=a("#commenteditor").get(0);f.addEventListener("change",function(){if("


"==f.value){e.innerText=c}else{e.innerText=d}})}}); +define ("local_qtracker/issue_view",["exports","jquery"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);function c(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}var d=function a(d,e){c(this,a);var f=(0,b.default)("button[name=closeissue]").get(0),g=(0,b.default)("#commenteditor").get(0);g.addEventListener("change",function(){if("


"==g.value){f.innerText=d}else{f.innerText=e}})};a.default=d;return a.default}); //# sourceMappingURL=issue_view.min.js.map diff --git a/amd/build/issue_view.min.js.map b/amd/build/issue_view.min.js.map index 9b4b9a2..2277a65 100644 --- a/amd/build/issue_view.min.js.map +++ b/amd/build/issue_view.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/issue_view.js"],"names":["define","$","closeissuestring","commentandcloseissuestring","commentandcommitbtn","get","commentEditor","addEventListener","value","innerText"],"mappings":"8GACAA,OAAM,6BAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,CAe3B,MAbI,YAAYC,CAAZ,CAA8BC,CAA9B,CAA0D,4BAChDC,CAAAA,CAAmB,CAAGH,CAAC,CAAC,yBAAD,CAAD,CAA6BI,GAA7B,CAAiC,CAAjC,CAD0B,CAEhDC,CAAa,CAAGL,CAAC,CAAC,gBAAD,CAAD,CAAoBI,GAApB,CAAwB,CAAxB,CAFgC,CAGtDC,CAAa,CAACC,gBAAd,CAA+B,QAA/B,CAAyC,UAAS,CAC9C,GAA4B,qDAAxB,EAAAD,CAAa,CAACE,KAAlB,CAAgF,CAC5EJ,CAAmB,CAACK,SAApB,CAAgCP,CACnC,CAFD,IAEO,CACHE,CAAmB,CAACK,SAApB,CAAgCN,CACnC,CACJ,CAND,CAOH,CAKR,CAjBK,CAAN","sourcesContent":["\ndefine(['jquery'], function($) {\n class IssueView {\n constructor(closeissuestring, commentandcloseissuestring) {\n const commentandcommitbtn = $(\"button[name=closeissue]\").get(0);\n const commentEditor = $(\"#commenteditor\").get(0);\n commentEditor.addEventListener(\"change\", event => {\n if (commentEditor.value == ('


')) {\n commentandcommitbtn.innerText = closeissuestring;\n } else {\n commentandcommitbtn.innerText = commentandcloseissuestring;\n }\n })\n }\n }\n\n return IssueView;\n\n})\n"],"file":"issue_view.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/issue_view.js"],"names":["IssueView","closeissuestring","commentandcloseissuestring","commentandcommitbtn","get","commentEditor","addEventListener","value","innerText"],"mappings":"sJACA,uD,mGAEMA,CAAAA,C,CACF,WAAYC,CAAZ,CAA8BC,CAA9B,CAA0D,cAChDC,CAAAA,CAAmB,CAAG,cAAE,yBAAF,EAA6BC,GAA7B,CAAiC,CAAjC,CAD0B,CAEhDC,CAAa,CAAG,cAAE,gBAAF,EAAoBD,GAApB,CAAwB,CAAxB,CAFgC,CAGtDC,CAAa,CAACC,gBAAd,CAA+B,QAA/B,CAAyC,UAAS,CAC9C,GAA4B,qDAAxB,EAAAD,CAAa,CAACE,KAAlB,CAAgF,CAC5EJ,CAAmB,CAACK,SAApB,CAAgCP,CACnC,CAFD,IAEO,CACHE,CAAmB,CAACK,SAApB,CAAgCN,CACnC,CACJ,CAND,CAOH,C,WAGUF,C","sourcesContent":["\nimport $ from 'jquery';\n\nclass IssueView {\n constructor(closeissuestring, commentandcloseissuestring) {\n const commentandcommitbtn = $(\"button[name=closeissue]\").get(0);\n const commentEditor = $(\"#commenteditor\").get(0);\n commentEditor.addEventListener(\"change\", event => {\n if (commentEditor.value == ('


')) {\n commentandcommitbtn.innerText = closeissuestring;\n } else {\n commentandcommitbtn.innerText = commentandcloseissuestring;\n }\n })\n }\n}\n\nexport default IssueView;\n"],"file":"issue_view.min.js"} \ No newline at end of file diff --git a/amd/src/issue_view.js b/amd/src/issue_view.js index 99a746a..e066ac3 100644 --- a/amd/src/issue_view.js +++ b/amd/src/issue_view.js @@ -1,19 +1,18 @@ -define(['jquery'], function($) { - class IssueView { - constructor(closeissuestring, commentandcloseissuestring) { - const commentandcommitbtn = $("button[name=closeissue]").get(0); - const commentEditor = $("#commenteditor").get(0); - commentEditor.addEventListener("change", event => { - if (commentEditor.value == ('


')) { - commentandcommitbtn.innerText = closeissuestring; - } else { - commentandcommitbtn.innerText = commentandcloseissuestring; - } - }) - } - } +import $ from 'jquery'; - return IssueView; +class IssueView { + constructor(closeissuestring, commentandcloseissuestring) { + const commentandcommitbtn = $("button[name=closeissue]").get(0); + const commentEditor = $("#commenteditor").get(0); + commentEditor.addEventListener("change", event => { + if (commentEditor.value == ('


')) { + commentandcommitbtn.innerText = closeissuestring; + } else { + commentandcommitbtn.innerText = commentandcloseissuestring; + } + }) + } +} -}) +export default IssueView; diff --git a/templates/question_issue_page.mustache b/templates/question_issue_page.mustache index d41c041..c151518 100644 --- a/templates/question_issue_page.mustache +++ b/templates/question_issue_page.mustache @@ -127,10 +127,8 @@ {{#js}} require(['jquery', 'local_qtracker/issue_view'], function($, IssueView) { - if ($("[name='closeissue']").length) { - var closeissuestring = "{{closeissue}}" - var commentandcloseissuestring = "{{commentandcloseisue}}" - new IssueView(closeissuestring, commentandcloseissuestring); - } + if ($("[name='closeissue']").length) { + new IssueView("{{closeissue}}", "{{commentandcloseisue}}"); + } }); {{/js}} From 6d80923a18ed44bb0160fdb82d62c9bd19e825e1 Mon Sep 17 00:00:00 2001 From: David Rise Knotten Date: Sun, 13 Jun 2021 15:52:23 +0200 Subject: [PATCH 5/5] Added some documentation to issue_view-js --- amd/src/issue_view.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/amd/src/issue_view.js b/amd/src/issue_view.js index e066ac3..2cf014d 100644 --- a/amd/src/issue_view.js +++ b/amd/src/issue_view.js @@ -1,4 +1,28 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle 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. +// +// Moodle 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 Moodle. If not, see . +/** + * Manager for managing question issues. + * + * @module local_qtracker/IssueView + * @class IssueView + * @package local_qtracker + * @author David Rise Knotten + * @copyright 2021 NTNU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ import $ from 'jquery'; class IssueView {