From c2aad2188a0d6c66f38cca04188ef818dfb7d7b0 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Tue, 10 Apr 2018 11:51:26 +0800 Subject: [PATCH] MDL-61899 tool_dataprivacy: Addition of js file and misc. updates. Includes MDL-61489 --- .../amd/build/expand_contract.min.js | 1 + .../dataprivacy/amd/src/expand_contract.js | 89 +++++++++++++++++++ .../dataprivacy/classes/metadata_registry.php | 2 +- .../output/data_registry_compliance_page.php | 11 +-- .../dataprivacy/lang/en/tool_dataprivacy.php | 2 +- .../{dataregistry2.php => pluginregistry.php} | 4 +- admin/tool/dataprivacy/settings.php | 5 +- .../templates/component_status.mustache | 33 +------ .../data_registry_compliance.mustache | 50 ++++------- 9 files changed, 120 insertions(+), 77 deletions(-) create mode 100644 admin/tool/dataprivacy/amd/build/expand_contract.min.js create mode 100644 admin/tool/dataprivacy/amd/src/expand_contract.js rename admin/tool/dataprivacy/{dataregistry2.php => pluginregistry.php} (91%) diff --git a/admin/tool/dataprivacy/amd/build/expand_contract.min.js b/admin/tool/dataprivacy/amd/build/expand_contract.min.js new file mode 100644 index 00000000000..3419d58da10 --- /dev/null +++ b/admin/tool/dataprivacy/amd/build/expand_contract.min.js @@ -0,0 +1 @@ +define(["jquery","core/url","core/str"],function(a,b,c){var d=a(''),e=a('');return{expandCollapse:function(a,b){a.hasClass("hide")?(a.removeClass("hide"),a.addClass("visible"),a.attr("aria-expanded",!0),b.find(":header i.fa").removeClass("fa-plus-square"),b.find(":header i.fa").addClass("fa-minus-square"),b.find(":header img.icon").attr("src",d.attr("src"))):(a.removeClass("visible"),a.addClass("hide"),a.attr("aria-expanded",!1),b.find(":header i.fa").removeClass("fa-minus-square"),b.find(":header i.fa").addClass("fa-plus-square"),b.find(":header img.icon").attr("src",e.attr("src")))},expandCollapseAll:function(b){var f="visible"==b?"hide":"visible",g="visible"==b,h="visible"==b?"fa-plus-square":"fa-minus-square",i="visible"==b?"fa-minus-square":"fa-plus-square",j="visible"==b?d.attr("src"):e.attr("src");a("."+f).each(function(){a(this).removeClass(f),a(this).addClass(b),a(this).attr("aria-expanded",g)}),a(".tool_dataprivacy-expand-all").data("visibilityState",f),c.get_string(f,"tool_dataprivacy").then(function(b){a(".tool_dataprivacy-expand-all").html(b)})["catch"](Notification.exception),a(":header i.fa").each(function(){a(this).removeClass(h),a(this).addClass(i)}),a(":header img.icon").each(function(){a(this).attr("src",j)})}}}); \ No newline at end of file diff --git a/admin/tool/dataprivacy/amd/src/expand_contract.js b/admin/tool/dataprivacy/amd/src/expand_contract.js new file mode 100644 index 00000000000..ad48c8796f8 --- /dev/null +++ b/admin/tool/dataprivacy/amd/src/expand_contract.js @@ -0,0 +1,89 @@ +// 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 . + +/** + * Potential user selector module. + * + * @module tool_dataprivacy/expand_contract + * @class page-expand-contract + * @package tool_dataprivacy + * @copyright 2018 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define(['jquery', 'core/url', 'core/str'], function($, url, str) { + + var expandedImage = $(''); + var collapsedImage = $(''); + + return /** @alias module:tool_dataprivacy/expand-collapse */ { + /** + * Expand or collapse a selected node. + * + * @param {object} targetnode The node that we want to expand / collapse + * @param {object} thisnode The node that was clicked. + * @return {null} + */ + expandCollapse: function(targetnode, thisnode) { + if (targetnode.hasClass('hide')) { + targetnode.removeClass('hide'); + targetnode.addClass('visible'); + targetnode.attr('aria-expanded', true); + thisnode.find(':header i.fa').removeClass('fa-plus-square'); + thisnode.find(':header i.fa').addClass('fa-minus-square'); + thisnode.find(':header img.icon').attr('src', expandedImage.attr('src')); + } else { + targetnode.removeClass('visible'); + targetnode.addClass('hide'); + targetnode.attr('aria-expanded', false); + thisnode.find(':header i.fa').removeClass('fa-minus-square'); + thisnode.find(':header i.fa').addClass('fa-plus-square'); + thisnode.find(':header img.icon').attr('src', collapsedImage.attr('src')); + } + }, + + /** + * Expand or collapse all nodes on this page. + * + * @param {string} nextstate The next state to change to. + * @return {null} + */ + expandCollapseAll: function(nextstate) { + var currentstate = (nextstate == 'visible') ? 'hide' : 'visible'; + var ariaexpandedstate = (nextstate == 'visible') ? true : false; + var iconclassnow = (nextstate == 'visible') ? 'fa-plus-square' : 'fa-minus-square'; + var iconclassnext = (nextstate == 'visible') ? 'fa-minus-square' : 'fa-plus-square'; + var imagenow = (nextstate == 'visible') ? expandedImage.attr('src') : collapsedImage.attr('src'); + $('.' + currentstate).each(function() { + $(this).removeClass(currentstate); + $(this).addClass(nextstate); + $(this).attr('aria-expanded', ariaexpandedstate); + }); + $('.tool_dataprivacy-expand-all').data('visibilityState', currentstate); + + str.get_string(currentstate, 'tool_dataprivacy').then(function(langString) { + $('.tool_dataprivacy-expand-all').html(langString); + }).catch(Notification.exception); + + $(':header i.fa').each(function() { + $(this).removeClass(iconclassnow); + $(this).addClass(iconclassnext); + }); + $(':header img.icon').each(function() { + $(this).attr('src', imagenow); + }); + } + }; +}); \ No newline at end of file diff --git a/admin/tool/dataprivacy/classes/metadata_registry.php b/admin/tool/dataprivacy/classes/metadata_registry.php index caa8bb4f012..a9457ad9b15 100644 --- a/admin/tool/dataprivacy/classes/metadata_registry.php +++ b/admin/tool/dataprivacy/classes/metadata_registry.php @@ -139,7 +139,7 @@ class metadata_registry { return array_map(function($plugins) { return array_filter($plugins, function($plugindata) { return !$plugindata->is_standard(); - }); + }); }, \core_plugin_manager::instance()->get_plugins()); } } diff --git a/admin/tool/dataprivacy/classes/output/data_registry_compliance_page.php b/admin/tool/dataprivacy/classes/output/data_registry_compliance_page.php index 9d7c225702e..fb9f5bb2528 100644 --- a/admin/tool/dataprivacy/classes/output/data_registry_compliance_page.php +++ b/admin/tool/dataprivacy/classes/output/data_registry_compliance_page.php @@ -26,7 +26,6 @@ defined('MOODLE_INTERNAL') || die(); use renderable; use renderer_base; -use stdClass; use templatable; require_once($CFG->libdir . '/coursecatlib.php'); @@ -41,6 +40,7 @@ require_once($CFG->libdir . '/blocklib.php'); */ class data_registry_compliance_page implements renderable, templatable { + /** @var array meta-data to be displayed about the system. */ protected $metadata; /** @@ -57,13 +57,6 @@ class data_registry_compliance_page implements renderable, templatable { * @return stdClass */ public function export_for_template(renderer_base $output) { - global $PAGE; - - $data = ['types' => $this->metadata]; - // print_object($data); - - return $data; + return ['types' => $this->metadata]; } - - } diff --git a/admin/tool/dataprivacy/lang/en/tool_dataprivacy.php b/admin/tool/dataprivacy/lang/en/tool_dataprivacy.php index 410a5c2d269..19070a1639a 100644 --- a/admin/tool/dataprivacy/lang/en/tool_dataprivacy.php +++ b/admin/tool/dataprivacy/lang/en/tool_dataprivacy.php @@ -64,7 +64,6 @@ $string['dataprivacy:managedatarequests'] = 'Manage data requests'; $string['dataprivacy:managedataregistry'] = 'Manage data registry'; $string['dataprivacysettings'] = 'Data privacy settings'; $string['dataregistry'] = 'Data registry'; -$string['dataregistry2'] = 'Plugin privacy registry'; $string['dataregistrysetup'] = 'Settings'; $string['datarequestemailsubject'] = 'Data request: {$a}'; $string['datarequests'] = 'Data requests'; @@ -130,6 +129,7 @@ $string['nopurposes'] = 'There are no purposes yet'; $string['nosubjectaccessrequests'] = 'There are no data requests that you need to act on'; $string['nosystemdefaults'] = 'Site purpose and category have not yet been defined.'; $string['notset'] = 'Not set (use the default value)'; +$string['pluginregistry'] = 'Plugin privacy registry'; $string['pluginregistrytitle'] = 'Plugin privacy compliance registry'; $string['privacy'] = 'Privacy'; $string['privacy:metadata:request'] = 'Information from personal data requests (subject access and deletion requests) made for this site.'; diff --git a/admin/tool/dataprivacy/dataregistry2.php b/admin/tool/dataprivacy/pluginregistry.php similarity index 91% rename from admin/tool/dataprivacy/dataregistry2.php rename to admin/tool/dataprivacy/pluginregistry.php index e3b4f6c766a..060bd81db69 100644 --- a/admin/tool/dataprivacy/dataregistry2.php +++ b/admin/tool/dataprivacy/pluginregistry.php @@ -28,8 +28,8 @@ require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/dataprivacy/lib.php'); $contextlevel = optional_param('contextlevel', CONTEXT_SYSTEM, PARAM_INT); $contextid = optional_param('contextid', 0, PARAM_INT); -$url = new moodle_url('/admin/tool/dataprivacy/dataregistry2.php'); -$title = get_string('dataregistry2', 'tool_dataprivacy'); +$url = new moodle_url('/' . $CFG->admin . '/tool/dataprivacy/pluginregistry.php'); +$title = get_string('pluginregistry', 'tool_dataprivacy'); \tool_dataprivacy\page_helper::setup($url, $title); diff --git a/admin/tool/dataprivacy/settings.php b/admin/tool/dataprivacy/settings.php index 5e2c398b246..9ba6bdadb4e 100644 --- a/admin/tool/dataprivacy/settings.php +++ b/admin/tool/dataprivacy/settings.php @@ -70,8 +70,9 @@ $ADMIN->add('privacy', new admin_externalpage('dataregistry', get_string('datare // Link that leads to the review page of expired contexts that are up for deletion. $ADMIN->add('privacy', new admin_externalpage('datadeletion', get_string('datadeletion', 'tool_dataprivacy'), new moodle_url('/admin/tool/dataprivacy/datadeletion.php'), 'tool/dataprivacy:managedataregistry') +); // Link that leads to the other data registry management page. -$ADMIN->add('dataprivacysettings', new admin_externalpage('dataregistry2', get_string('dataregistry2', 'tool_dataprivacy'), - new moodle_url('/admin/tool/dataprivacy/dataregistry2.php'), 'tool/dataprivacy:managedataregistry') +$ADMIN->add('privacy', new admin_externalpage('pluginregistry', get_string('pluginregistry', 'tool_dataprivacy'), + new moodle_url('/admin/tool/dataprivacy/pluginregistry.php'), 'tool/dataprivacy:managedataregistry') ); diff --git a/admin/tool/dataprivacy/templates/component_status.mustache b/admin/tool/dataprivacy/templates/component_status.mustache index 4c37e95dd93..79c906386bb 100644 --- a/admin/tool/dataprivacy/templates/component_status.mustache +++ b/admin/tool/dataprivacy/templates/component_status.mustache @@ -50,10 +50,9 @@
{{/compliant}} - - -{{#js}} -require(['jquery', 'core/url'], function($, url) { - - var expandedImage = $(''); - var collapsedImage = $(''); - - $('.expand').click(function(e) { - e.preventDefault(); - e.stopPropagation(); - e.stopImmediatePropagation(); - var component = $(this).data('component'); - var metadata = $('[data-section=\'' + component + '\']'); - var metainfo = metadata.attr('class'); - if (metadata.attr('class') === 'hide') { - metadata.attr('class', 'visible'); - $(this).children('img').attr('src', expandedImage.attr('src')); - metadata.attr('aria-expanded', true); - } else { - metadata.attr('class', 'hide'); - $(this).children('img').attr('src', collapsedImage.attr('src')); - metadata.attr('aria-expanded', false); - } - }); -}); -{{/js}} + \ No newline at end of file diff --git a/admin/tool/dataprivacy/templates/data_registry_compliance.mustache b/admin/tool/dataprivacy/templates/data_registry_compliance.mustache index 79dfece3872..259c59c742e 100644 --- a/admin/tool/dataprivacy/templates/data_registry_compliance.mustache +++ b/admin/tool/dataprivacy/templates/data_registry_compliance.mustache @@ -36,7 +36,7 @@ } } }} -
+

{{#str}}pluginregistrytitle, tool_dataprivacy{{/str}}


{{#str}}explanationtitle, tool_dataprivacy{{/str}}

@@ -51,11 +51,11 @@ {{#types}}
-