Skip to content

Commit

Permalink
Merge branch 'MDL-56673-30-fix1' of http://github.com/damyon/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_30_STABLE
  • Loading branch information
andrewnicols committed Nov 4, 2016
2 parents 3d9ed4a + 5644de2 commit d556156
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion admin/tool/templatelibrary/amd/build/display.min.js

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

2 changes: 1 addition & 1 deletion admin/tool/templatelibrary/amd/build/search.min.js

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

3 changes: 3 additions & 0 deletions admin/tool/templatelibrary/amd/src/display.js
Expand Up @@ -33,6 +33,9 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates'
*/
var findDocsSection = function(templateSource, templateName) {

if (!templateSource) {
return false;
}
// Find the comment section marked with @template component/template.
var marker = "@template " + templateName,
i = 0,
Expand Down
13 changes: 6 additions & 7 deletions admin/tool/templatelibrary/amd/src/search.js
Expand Up @@ -21,8 +21,8 @@
* @copyright 2015 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates'],
function($, ajax, log, notification, templates) {
define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates', 'core/config'],
function($, ajax, log, notification, templates, config) {

/**
* The ajax call has returned with a new list of templates.
Expand All @@ -42,15 +42,14 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates'
*
* @method refreshSearch
*/
var refreshSearch = function() {
var refreshSearch = function(themename) {
var componentStr = $('[data-field="component"]').val();
var searchStr = $('[data-field="search"]').val();

// Trigger the search.

ajax.call([
{ methodname: 'tool_templatelibrary_list_templates',
args: { component: componentStr, search: searchStr },
args: { component: componentStr, search: searchStr, themename: themename },
done: reloadListTemplate,
fail: notification.exception }
], true, false);
Expand Down Expand Up @@ -78,12 +77,12 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates'
};

var changeHandler = function() {
queueRefresh(refreshSearch, 400);
queueRefresh(refreshSearch.bind(this, config.theme), 400);
};
// Add change handlers to refresh the list.
$('[data-region="list-templates"]').on('change', '[data-field="component"]', changeHandler);
$('[data-region="list-templates"]').on('input', '[data-field="search"]', changeHandler);

refreshSearch();
refreshSearch(config.theme);
return {};
});
10 changes: 9 additions & 1 deletion admin/tool/templatelibrary/classes/api.php
Expand Up @@ -47,7 +47,12 @@ class api {
* @return array[string] Where each template is in the form "component/templatename".
*/
public static function list_templates($component = '', $search = '', $themename = '') {
global $CFG;
global $CFG, $PAGE;

if (empty($themename)) {
$themename = $PAGE->theme->name;
}
$themeconfig = \theme_config::load($themename);

$templatedirs = array();
$results = array();
Expand Down Expand Up @@ -77,6 +82,9 @@ public static function list_templates($component = '', $search = '', $themename
foreach ($plugintypes as $type => $dir) {
$plugins = core_component::get_plugin_list_with_file($type, 'templates', false);
foreach ($plugins as $plugin => $dir) {
if ($type == 'theme' && $plugin != $themename && !in_array($plugin, $themeconfig->parents)) {
continue;
}
if (!empty($dir) && is_dir($dir)) {
$pluginname = $type . '_' . $plugin;
$dirs = mustache_template_finder::get_template_directories_for_component($pluginname, $themename);
Expand Down
13 changes: 10 additions & 3 deletions admin/tool/templatelibrary/classes/external.php
Expand Up @@ -59,7 +59,13 @@ public static function list_templates_parameters() {
VALUE_DEFAULT,
''
);
$params = array('component' => $component, 'search' => $search);
$themename = new external_value(
PARAM_COMPONENT,
'The current theme',
VALUE_DEFAULT,
''
);
$params = array('component' => $component, 'search' => $search, 'themename' => $themename);
return new external_function_parameters($params);
}

Expand All @@ -69,14 +75,15 @@ public static function list_templates_parameters() {
* @param string $search The search string.
* @return array[string]
*/
public static function list_templates($component, $search) {
public static function list_templates($component, $search, $themename) {
$params = self::validate_parameters(self::list_templates_parameters(),
array(
'component' => $component,
'search' => $search,
'themename' => $themename,
));

return api::list_templates($component, $search);
return api::list_templates($component, $search, $themename);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

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

$version = 2015111606.10; // 20151116 = branching date YYYYMMDD - do not modify!
$version = 2015111606.11; // 20151116 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

Expand Down

0 comments on commit d556156

Please sign in to comment.