Skip to content

Commit

Permalink
Merge branch 'MDL-63876-master' of git://github.com/damyon/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Mar 29, 2019
2 parents 0920f35 + f44557d commit 7ccbfdd
Show file tree
Hide file tree
Showing 48 changed files with 1,294 additions and 240 deletions.
2 changes: 1 addition & 1 deletion admin/tool/lp/amd/build/competencyactions.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion admin/tool/lp/amd/build/competencytree.min.js

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

1 change: 1 addition & 0 deletions admin/tool/lp/amd/build/form_competency_element.min.js

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

1 change: 1 addition & 0 deletions admin/tool/lp/amd/src/competencyactions.js
Expand Up @@ -672,6 +672,7 @@ define(['jquery',
context.showdeleterelatedaction = true;
context.showrelatedcompetencies = true;
context.showrule = false;
context.pluginbaseurl = url.relativeUrl('/admin/tool/lp');

if (competency.ruleoutcome != Outcomes.NONE) {
// Get the outcome and rule name.
Expand Down
8 changes: 6 additions & 2 deletions admin/tool/lp/amd/src/competencytree.js
Expand Up @@ -136,18 +136,22 @@ define(['core/ajax', 'core/notification', 'core/templates', 'tool_lp/tree', 'too
/**
* Initialise the tree.
*
* @param {Number} id The competency id.
* @param {Number} id The competency framework id.
* @param {String} shortname The framework shortname
* @param {String} search The current search string
* @param {String} selector The selector for the tree div
* @param {Boolean} canmanage Can manage the competencies
* @param {Number} competencyid The id of the competency to show first
*/
init: function(id, shortname, search, selector, canmanage) {
init: function(id, shortname, search, selector, canmanage, competencyid) {
competencyFrameworkId = id;
competencyFrameworkShortName = shortname;
competencyFramworkCanManage = canmanage;
treeSelector = selector;
loadCompetencies(search).fail(notification.exception);
if (competencyid > 0) {
currentNodeId = competencyid;
}

this.on('selectionchanged', rememberCurrent);
},
Expand Down
138 changes: 138 additions & 0 deletions admin/tool/lp/amd/src/form_competency_element.js
@@ -0,0 +1,138 @@
// 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/>.

/**
* Badge select competency actions
*
* @module tool_lp/form_competency_element
* @package tool_lp
* @copyright 2019 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'tool_lp/competencypicker', 'core/ajax', 'core/notification', 'core/templates'],
function($, Picker, Ajax, Notification, Templates) {

var pickerInstance = null;

var pageContextId = 1;

/**
* Re-render the list of selected competencies.
*
* @method renderCompetencies
* @return {boolean}
*/
var renderCompetencies = function() {
var currentCompetencies = $('[data-action="competencies"]').val();
var requests = [];
var i = 0;

if (currentCompetencies != '') {
currentCompetencies = currentCompetencies.split(',');
for (i = 0; i < currentCompetencies.length; i++) {
requests[requests.length] = {
methodname: 'core_competency_read_competency',
args: {id: currentCompetencies[i]}
};
}
}

$.when.apply($, Ajax.call(requests, false)).then(function() {
var i = 0,
competencies = [];

for (i = 0; i < arguments.length; i++) {
competencies[i] = arguments[i];
}
var context = {
competencies: competencies
};

return Templates.render('tool_lp/form_competency_list', context);
}).then(function(html, js) {
Templates.replaceNode($('[data-region="competencies"]'), html, js);
return true;
}).fail(Notification.exception);

return true;
};

/**
* Deselect a competency
*
* @method unpickCompetenciesHandler
* @param {Event} e
* @return {boolean}
*/
var unpickCompetenciesHandler = function(e) {
var currentCompetencies = $('[data-action="competencies"]').val().split(','),
newCompetencies = [],
i,
toRemove = $(e.currentTarget).data('id');

for (i = 0; i < currentCompetencies.length; i++) {
if (currentCompetencies[i] != toRemove) {
newCompetencies[newCompetencies.length] = currentCompetencies[i];
}
}

$('[data-action="competencies"]').val(newCompetencies.join(','));

return renderCompetencies();
};

/**
* Open a competencies popup to relate competencies.
*
* @method pickCompetenciesHandler
*/
var pickCompetenciesHandler = function() {
var currentCompetencies = $('[data-action="competencies"]').val().split(',');

if (!pickerInstance) {
pickerInstance = new Picker(pageContextId, false, 'parents', true);
pickerInstance.on('save', function(e, data) {
var before = $('[data-action="competencies"]').val();
var compIds = data.competencyIds;
if (before != '') {
compIds = compIds.concat(before.split(','));
}
var value = compIds.join(',');

$('[data-action="competencies"]').val(value);

return renderCompetencies();
});
}

pickerInstance.setDisallowedCompetencyIDs(currentCompetencies);
pickerInstance.display();
};

return /** @alias module:tool_lp/form_competency_element */ {
/**
* Listen for clicks on the competency picker and push the changes to the form element.
*
* @method init
* @param {Integer} contextId
*/
init: function(contextId) {
pageContextId = contextId;
renderCompetencies();
$('[data-action="select-competencies"]').on('click', pickCompetenciesHandler);
$('body').on('click', '[data-action="deselect-competency"]', unpickCompetenciesHandler);
}
};
});
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/external.php
Expand Up @@ -205,7 +205,7 @@ public static function data_for_competencies_manage_page($competencyframeworkid,
self::validate_context($framework->get_context());
$output = $PAGE->get_renderer('tool_lp');

$renderable = new output\manage_competencies_page($framework, $params['search'], $framework->get_context());
$renderable = new output\manage_competencies_page($framework, $params['search'], $framework->get_context(), null);

$data = $renderable->export_for_template($output);

Expand Down
4 changes: 4 additions & 0 deletions admin/tool/lp/classes/external/competency_path_exporter.php
Expand Up @@ -76,6 +76,9 @@ protected static function define_other_properties() {
],
'pagecontextid' => [
'type' => PARAM_INT
],
'showlinks' => [
'type' => PARAM_BOOL
]
];
}
Expand All @@ -91,6 +94,7 @@ protected function get_other_values(renderer_base $output) {
$ancestors = [];
$nodescount = count($this->related['ancestors']);
$i = 1;
$result->showlinks = \core_competency\api::show_links();
foreach ($this->related['ancestors'] as $competency) {
$exporter = new path_node_exporter([
'id' => $competency->get('id'),
Expand Down
Expand Up @@ -27,6 +27,7 @@
use context_course;
use renderer_base;
use stdClass;
use moodle_url;
use core_competency\competency_framework;
use core_competency\external\competency_exporter;
use core_competency\external\competency_framework_exporter;
Expand Down Expand Up @@ -82,7 +83,10 @@ protected static function define_other_properties() {
),
'comppath' => array(
'type' => competency_path_exporter::read_properties_definition(),
)
),
'pluginbaseurl' => [
'type' => PARAM_URL
]
);
}

Expand Down Expand Up @@ -136,6 +140,8 @@ protected function get_other_values(renderer_base $output) {
'context' => $context
]);
$result->comppath = $exporter->export($output);
$result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$result->showlinks = \core_competency\api::show_links();

return (array) $result;
}
Expand Down
12 changes: 11 additions & 1 deletion admin/tool/lp/classes/output/manage_competencies_page.php
Expand Up @@ -62,17 +62,22 @@ class manage_competencies_page implements renderable, templatable {
/** @var context $pagecontext The page context. */
protected $pagecontext = null;

/** @var \core_competency\competency $competency The competency to show when the page loads. */
protected $competency = null;

/**
* Construct this renderable.
*
* @param \core_competency\competency_framework $framework Competency framework.
* @param string $search Search string.
* @param context $pagecontext The page context.
* @param \core_competency\competency $competency The core competency to show when the page loads.
*/
public function __construct($framework, $search, $pagecontext) {
public function __construct($framework, $search, $pagecontext, $competency) {
$this->framework = $framework;
$this->pagecontext = $pagecontext;
$this->search = $search;
$this->competency = $competency;
$addpage = new single_button(
new moodle_url('/admin/tool/lp/editcompetencyframework.php'),
get_string('addnewcompetency', 'tool_lp')
Expand All @@ -97,6 +102,11 @@ public function export_for_template(renderer_base $output) {
$data->pagecontextid = $this->pagecontext->id;
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);

$data->competencyid = 0;
if ($this->competency) {
$data->competencyid = $this->competency->get('id');
}

$rulesmodules = array();
$rules = competency::get_available_rules();
foreach ($rules as $type => $rulename) {
Expand Down
98 changes: 98 additions & 0 deletions admin/tool/lp/classes/site_competencies_form_element.php
@@ -0,0 +1,98 @@
<?php
// 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/>.


/**
* Site competencies element.
*
* @package tool_lp
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

global $CFG;

require_once($CFG->libdir . '/form/hidden.php');

/**
* Site competencies element.
*
* @package tool_lp
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lp_site_competencies_form_element extends MoodleQuickForm_hidden {

/**
* Constructor
*
* @param string $elementname Element name.
* @param string $value The element value.
* @param mixed $attributes Either a typical HTML attribute string or an associative array.
*/
public function __construct($elementname=null, $value='', $attributes=null) {
if ($elementname == null) {
// This is broken quickforms messing with the constructors.
return;
}
$attributes = array_merge(['data-action' => 'competencies'], $attributes ? $attributes : []);

parent::__construct($elementname, $value, $attributes);
$this->setType('hidden');
}

/**
* Generate the hidden field and the controls to show and pick the competencies.
*/
public function toHtml() {
global $PAGE;

$html = parent::toHTML();

if (!$this->isFrozen()) {
$context = context_system::instance();
$params = [$context->id];
// Require some JS to select the competencies.
$PAGE->requires->js_call_amd('tool_lp/form_competency_element', 'init', $params);
$html .= '<div class="form-group row">';
$html .= '<div class="col-md-3"></div>';
$html .= '<div class="col-md-9">';
$html .= '<div data-region="competencies"></div>';
$html .= '<div class="mt-3">';
$html .= '<a class="btn btn-secondary" role="button" data-action="select-competencies">';
$html .= get_string('addcompetency', 'tool_lp');
$html .= '</a>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
}
return $html;
}

/**
* Accepts a renderer
*
* @param HTML_QuickForm_Renderer $renderer the renderer for the element.
* @param boolean $required not used.
* @param string $error not used.
* @return void
*/
public function accept(&$renderer, $required=false, $error=null) {
$renderer->renderElement($this, false, '');
}
}

0 comments on commit 7ccbfdd

Please sign in to comment.