MDL-63876 competencies: Use direct URL

Instead of showing competencies in a dialogue, give them their own full url to
display the competency in the framework it belongs to. This is useful for exported
data that won't have access to javascript.
This commit is contained in:
Damyon Wiese
2019-03-29 11:31:15 +08:00
parent da5e19a128
commit 15e6a76e6f
10 changed files with 39 additions and 13 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
define(["core/ajax","core/notification","core/templates","tool_lp/tree","tool_lp/competency_outcomes","jquery"],function(a,b,c,d,e,f){var g={},h=0,i="",j="",k="",l=!1,m=function(a,b){var c=0,d=!1;for(a.haschildren=!1,a.children=[],c=0;c<b.length;c++)d=b[c],d.parentid==a.id&&(a.haschildren=!0,a.children.push(d),m(d,b))},n=function(b){var e=f.Deferred();return c.render("tool_lp/loading",{}).done(function(n,o){c.replaceNodeContents(f(j),n,o);var p=a.call([{methodname:"core_competency_search_competencies",args:{searchtext:b,competencyframeworkid:h}}]);p[0].done(function(a){g={};var b=0;for(b=0;b<a.length;b++)g[a[b].id]=a[b];var h=[],n=!1;for(b=0;b<a.length;b++)n=a[b],0===parseInt(n.parentid,10)&&(h.push(n),m(n,a));var o={shortname:i,canmanage:l,competencies:h};c.render("tool_lp/competencies_tree_root",o).done(function(a,b){c.replaceNodeContents(f(j),f(a).html(),b);var h=new d(j,(!1));if(k){var i=f(j).find("[data-id="+k+"]");i.length&&(h.selectItem(i),h.updateFocus(i))}e.resolve(g)}).fail(e.reject)}).fail(e.reject)}),e.promise()},o=function(a,b){var c=b.selected;k=c.attr("data-id")};return{init:function(a,c,d,e,f){h=a,i=c,l=f,j=e,n(d).fail(b.exception),this.on("selectionchanged",o)},on:function(a,b){f(j).on(a,b)},getChildren:function(a){var b=[];return f.each(g,function(c,d){d.parentid==a&&b.push(d)}),b},getCompetencyFrameworkId:function(){return h},getCompetency:function(a){return g[a]},getCompetencyLevel:function(a){var b=this.getCompetency(a),c=b.path.replace(/^\/|\/$/g,"").split("/").length;return c},hasChildren:function(a){return this.getChildren(a).length>0},hasRule:function(a){var b=this.getCompetency(a);return!!b&&(b.ruleoutcome!=e.OUTCOME_NONE&&b.ruletype)},reloadCompetencies:function(){return n("").fail(b.exception)},listCompetencies:function(){return g}}});
define(["core/ajax","core/notification","core/templates","tool_lp/tree","tool_lp/competency_outcomes","jquery"],function(a,b,c,d,e,f){var g={},h=0,i="",j="",k="",l=!1,m=function(a,b){var c=0,d=!1;for(a.haschildren=!1,a.children=[],c=0;c<b.length;c++)d=b[c],d.parentid==a.id&&(a.haschildren=!0,a.children.push(d),m(d,b))},n=function(b){var e=f.Deferred();return c.render("tool_lp/loading",{}).done(function(n,o){c.replaceNodeContents(f(j),n,o);var p=a.call([{methodname:"core_competency_search_competencies",args:{searchtext:b,competencyframeworkid:h}}]);p[0].done(function(a){g={};var b=0;for(b=0;b<a.length;b++)g[a[b].id]=a[b];var h=[],n=!1;for(b=0;b<a.length;b++)n=a[b],0===parseInt(n.parentid,10)&&(h.push(n),m(n,a));var o={shortname:i,canmanage:l,competencies:h};c.render("tool_lp/competencies_tree_root",o).done(function(a,b){c.replaceNodeContents(f(j),f(a).html(),b);var h=new d(j,(!1));if(k){var i=f(j).find("[data-id="+k+"]");i.length&&(h.selectItem(i),h.updateFocus(i))}e.resolve(g)}).fail(e.reject)}).fail(e.reject)}),e.promise()},o=function(a,b){var c=b.selected;k=c.attr("data-id")};return{init:function(a,c,d,e,f,g){h=a,i=c,l=f,j=e,n(d).fail(b.exception),g>0&&(k=g),this.on("selectionchanged",o)},on:function(a,b){f(j).on(a,b)},getChildren:function(a){var b=[];return f.each(g,function(c,d){d.parentid==a&&b.push(d)}),b},getCompetencyFrameworkId:function(){return h},getCompetency:function(a){return g[a]},getCompetencyLevel:function(a){var b=this.getCompetency(a),c=b.path.replace(/^\/|\/$/g,"").split("/").length;return c},hasChildren:function(a){return this.getChildren(a).length>0},hasRule:function(a){var b=this.getCompetency(a);return!!b&&(b.ruleoutcome!=e.OUTCOME_NONE&&b.ruletype)},reloadCompetencies:function(){return n("").fail(b.exception)},listCompetencies:function(){return g}}});
@@ -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.
+6 -2
View File
@@ -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
*/
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);
},
@@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
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;
@@ -82,7 +83,10 @@ class competency_summary_exporter extends \core\external\exporter {
),
'comppath' => array(
'type' => competency_path_exporter::read_properties_definition(),
)
),
'pluginbaseurl' => [
'type' => PARAM_URL
]
);
}
@@ -136,6 +140,7 @@ class competency_summary_exporter extends \core\external\exporter {
'context' => $context
]);
$result->comppath = $exporter->export($output);
$result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
return (array) $result;
}
@@ -69,10 +69,11 @@ class manage_competencies_page implements renderable, templatable {
* @param string $search Search string.
* @param context $pagecontext The page context.
*/
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')
@@ -97,6 +98,11 @@ class manage_competencies_page implements renderable, templatable {
$data->pagecontextid = $this->pagecontext->id;
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$competencyid = 0;
if ($this->competency) {
$data->competencyid = $this->competency->get('id');
}
$rulesmodules = array();
$rules = competency::get_available_rules();
foreach ($rules as $type => $rulename) {
+13 -4
View File
@@ -25,14 +25,23 @@
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to the context we came from.
$search = optional_param('search', '', PARAM_RAW);
$id = required_param('competencyframeworkid', PARAM_INT);
$competencyid = optional_param('competencyid', 0, PARAM_INT);
$competency = null;
if ($competencyid) {
$competency = \core_competency\api::read_competency($competencyid);
$id = $competency->get('competencyframeworkid');
$pagecontext = $competency->get_context();
$pagecontextid = $pagecontext->id; // Reference to the context we came from.
} else {
$id = required_param('competencyframeworkid', PARAM_INT);
$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to the context we came from.
$pagecontext = context::instance_by_id($pagecontextid);
}
require_login();
\core_competency\api::require_enabled();
$pagecontext = context::instance_by_id($pagecontextid);
$framework = \core_competency\api::read_framework($id);
$context = $framework->get_context();
@@ -58,7 +67,7 @@ $PAGE->set_heading($title);
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
$page = new \tool_lp\output\manage_competencies_page($framework, $search, $pagecontext);
$page = new \tool_lp\output\manage_competencies_page($framework, $search, $pagecontext, $competency);
echo $output->render($page);
// Log the framework viewed event after rendering the page.
@@ -59,7 +59,7 @@
<a href="{{pluginbaseurl}}/competencies.php?competencyframeworkid={{framework.id}}&pagecontextid={{pagecontextid}}" >{{{framework.name}}}</a>
/
{{#ancestors}}
<a data-action="competency-dialogue" href="#" data-id="{{id}}">{{{name}}}</a>
<a href="{{pluginbaseurl}}/competencies.php?competencyid={{id}}">{{{name}}}</a>
{{^last}}<span> / </span>{{/last}}
{{/ancestors}}
</small>
@@ -50,7 +50,7 @@
}}
<div class='competency-heading'>
<h4 id="competency_link_{{competency.id}}">{{{competency.shortname}}}
<small>{{competency.idnumber}}</small>
<small><a href="{{pluginbaseurl}}/competencies.php?competencyid={{competency.id}}">{{competency.idnumber}}</a></small>
</h4>
{{#framework}}
<div class='competency-origin'>
@@ -135,7 +135,8 @@ require(['tool_lp/tree', 'tool_lp/competencytree', 'tool_lp/competencyactions',
{{#quote}} {{{framework.shortname}}} {{/quote}},
'{{search}}',
'[data-enhance=tree]',
{{canmanage}});
{{canmanage}},
{{competencyid}});
actions.init(treeModel, {{pagecontextid}}, '{{{framework.taxonomies}}}', {{{rulesmodules}}});