Skip to content

Commit

Permalink
MDL-61899 tool_dataprivacy: Addition of js file and misc. updates.
Browse files Browse the repository at this point in the history
Includes MDL-61489
  • Loading branch information
abgreeve authored and stronk7 committed Apr 18, 2018
1 parent eb6b4c2 commit c2aad21
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 77 deletions.
1 change: 1 addition & 0 deletions admin/tool/dataprivacy/amd/build/expand_contract.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions admin/tool/dataprivacy/amd/src/expand_contract.js
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

/**
* 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 = $('<img alt="" src="' + url.imageUrl('t/expanded') + '"/>');
var collapsedImage = $('<img alt="" src="' + url.imageUrl('t/collapsed') + '"/>');

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);
});
}
};
});
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/classes/metadata_registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function get_contrib_list() {
return array_map(function($plugins) {
return array_filter($plugins, function($plugindata) {
return !$plugindata->is_standard();
});
});
}, \core_plugin_manager::instance()->get_plugins());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

use renderable;
use renderer_base;
use stdClass;
use templatable;

require_once($CFG->libdir . '/coursecatlib.php');
Expand All @@ -41,6 +40,7 @@
*/
class data_registry_compliance_page implements renderable, templatable {

/** @var array meta-data to be displayed about the system. */
protected $metadata;

/**
Expand All @@ -57,13 +57,6 @@ public function __construct($metadata) {
* @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];
}


}
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/lang/en/tool_dataprivacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
$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';
Expand Down Expand Up @@ -130,6 +129,7 @@
$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.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
$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);

Expand Down
5 changes: 3 additions & 2 deletions admin/tool/dataprivacy/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@
// 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')
);
33 changes: 3 additions & 30 deletions admin/tool/dataprivacy/templates/component_status.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@
<hr />
<div class="row">
{{#compliant}}
<a class="expand" data-component="{{raw_component}}" href='#'>
<h4 class="d-inline p-l-2 " id="{{raw_component}}">{{#pix}}t/collapsed, moodle, {{#str}}expandplugin, tool_dataprivacy{{/str}}{{/pix}}{{component}}</h4>
<a class="component-expand p-l-2" data-component="{{raw_component}}" href='#'>
<h4 class=" d-inline p-l-2 " id="{{raw_component}}">{{#pix}}t/collapsed, moodle, {{#str}}expandplugin, tool_dataprivacy{{/str}}{{/pix}}{{component}}</h4>
</a>
<!-- <span class="badge badge-pill badge-success">{{#str}}compliant, tool_dataprivacy{{/str}}</span> -->
{{/compliant}}
{{^compliant}}
<h4 class="d-inline p-l-3 " id="{{raw_component}}">{{component}}</h4>
Expand Down Expand Up @@ -103,30 +102,4 @@
{{/nullprovider}}
</div>
{{/compliant}}
</div>

{{#js}}
require(['jquery', 'core/url'], function($, url) {
var expandedImage = $('<img alt="" src="' + url.imageUrl('t/expanded') + '"/>');
var collapsedImage = $('<img alt="" src="' + url.imageUrl('t/collapsed') + '"/>');
$('.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}}
</div>
50 changes: 18 additions & 32 deletions admin/tool/dataprivacy/templates/data_registry_compliance.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
}
}}
<div>
<div class="dataprivacy-main">
<h2>{{#str}}pluginregistrytitle, tool_dataprivacy{{/str}}</h2>
<hr />
<p><strong>{{#str}}explanationtitle, tool_dataprivacy{{/str}}</strong></p>
Expand All @@ -51,11 +51,11 @@
{{#types}}
<div>
<div>
<a class="other-expand" href='#' data-plugin="{{plugin_type_raw}}">
<a class="type-expand" href='#' data-plugin="{{plugin_type_raw}}">
<h3 id="{{plugin_type_raw}}">{{#pix}}t/collapsed, moodle, {{#str}}expandplugintype, tool_dataprivacy{{/str}}{{/pix}}{{plugin_type}}</h3>
</a>
</div>
<div class="hide" data-plugintarget="{{plugin_type_raw}}" aria-expanded="false">
<div class="hide p-b-1" data-plugintarget="{{plugin_type_raw}}" aria-expanded="false">
{{#plugins}}
{{> tool_dataprivacy/component_status}}
{{/plugins}}
Expand All @@ -64,45 +64,31 @@
{{/types}}
</div>
{{#js}}
require(['jquery', 'core/url', 'core/str'], function($, url, str) {
require(['jquery', 'tool_dataprivacy/expand_contract'], function($, ec) {
var expandedImage = $('<img alt="" src="' + url.imageUrl('t/expanded') + '"/>');
var collapsedImage = $('<img alt="" src="' + url.imageUrl('t/collapsed') + '"/>');
$('.other-expand').click(function(e) {
$('.type-expand').click(function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
window.console.log(this);
var plugin = $(this).data('plugin');
var thisnode = $(this);
var plugin = thisnode.data('plugin');
var metadata = $('[data-plugintarget=\'' + plugin + '\']');
if (metadata.attr('class') === 'hide') {
metadata.attr('class', 'visible p-b-2');
$(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);
}
ec.expandCollapse(metadata, thisnode);
});

$('.component-expand').click(function(e) {
e.preventDefault();
e.stopPropagation();
var thisnode = $(this);
var plugin = thisnode.data('component');
var metadata = $('[data-section=\'' + plugin + '\']');
ec.expandCollapse(metadata, thisnode);
});

$('.tool_dataprivacy-expand-all').click(function(e) {
e.preventDefault();
e.stopPropagation();
var nextstate = $(this).data('visibilityState');
var currentstate = (nextstate == 'visible') ? 'hide' : 'visible';
var ariaexpandedstate = (nextstate == 'visible') ? true : false;
$('.' + currentstate).each(function() {
$(this).attr('class', nextstate);
$(this).attr('aria-expanded', ariaexpandedstate);
});
$(this).data('visibilityState', currentstate);

str.get_string(currentstate, 'tool_dataprivacy').then(function(langString) {
var visibilitynode = $('.tool_dataprivacy-expand-all');
visibilitynode.html(langString);
}).catch(Notification.exception);
ec.expandCollapseAll(nextstate);
});
});
{{/js}}

0 comments on commit c2aad21

Please sign in to comment.