MDL-55841 enrol_lti: Make published tool list more user friendly

This commit is contained in:
John Okely 2016-10-24 18:00:47 +08:00
parent 23146bad48
commit 51478048cd
6 changed files with 98 additions and 44 deletions

View file

@ -69,16 +69,14 @@ class manage_table extends \table_sql {
$this->define_columns(array( $this->define_columns(array(
'name', 'name',
'cartridge_url', 'lti1',
'secret', 'lti2',
'proxy_url',
'edit' 'edit'
)); ));
$this->define_headers(array( $this->define_headers(array(
get_string('name'), get_string('name'),
get_string('cartridgeurl', 'enrol_lti'), get_string('lti1', 'enrol_lti'),
get_string('secret', 'enrol_lti'), get_string('lti2', 'enrol_lti'),
get_string('proxyurl', 'enrol_lti'),
get_string('edit') get_string('edit')
)); ));
$this->collapsible(false); $this->collapsible(false);
@ -104,37 +102,54 @@ class manage_table extends \table_sql {
} }
/** /**
* Generate the cartridge URL column. * Generate the LTI1 column.
* *
* @param \stdClass $tool event data. * @param \stdClass $tool instance data.
* @return string * @return string
*/ */
public function col_cartridge_url($tool) { public function col_lti1($tool) {
global $OUTPUT;
$url = helper::get_cartridge_url($tool); $url = helper::get_cartridge_url($tool);
return $this->get_copyable_text($tool, $url); $toolurllabel = get_string('toolurl', 'enrol_lti');
$toolurl = $url;
$secretlabel = get_string('secret', 'enrol_lti');
$secret = $tool->secret;
$data = [
"rows" => [
[ "label" => $toolurllabel, "text" => $toolurl, "id" => "toolurl" ],
[ "label" => $secretlabel, "text" => $secret, "id" => "secret" ],
]
];
$return = $OUTPUT->render_from_template("enrol_lti/copy_grid", $data);
return $return;
} }
/** /**
* Generate the proxy URL column. * Generate the LTI2 column.
* *
* @param \stdClass $tool event data. * @param \stdClass $tool instance data.
* @return string * @return string
*/ */
public function col_proxy_url($tool) { public function col_lti2($tool) {
global $OUTPUT;
$url = helper::get_proxy_url($tool); $url = helper::get_proxy_url($tool);
return $this->get_copyable_text($tool, $url); $toolurllabel = get_string('toolurl', 'enrol_lti');
} $toolurl = $url;
/** $data = [
* Generate the secret column. "rows" => [
* [ "label" => $toolurllabel, "text" => $toolurl, "id" => "toolurl" ],
* @param \stdClass $tool event data. ]
* @return string ];
*/
public function col_secret($tool) { $return = $OUTPUT->render_from_template("enrol_lti/copy_grid", $data);
return $this->get_copyable_text($tool, $tool->secret); return $return;
} }
@ -225,22 +240,4 @@ class manage_table extends \table_sql {
return $text; return $text;
} }
/**
* Returns text to display in the columns.
*
* @param \stdClass $tool the tool
* @param string $text the text to alter
* @return string
* @since Moodle 3.2
*/
protected function get_copyable_text($tool, $text) {
global $OUTPUT;
$copyable = $OUTPUT->render_from_template('core/copy_box', array('text' => $text));
if ($tool->status != ENROL_INSTANCE_ENABLED) {
return \html_writer::tag('span', $copyable, array('class' => 'dimmed_text', 'style' => 'overflow: scroll'));
}
return $copyable;
}
} }

View file

@ -99,6 +99,7 @@ if ($action) {
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('toolsprovided', 'enrol_lti')); echo $OUTPUT->heading(get_string('toolsprovided', 'enrol_lti'));
echo get_string('toolsprovided_help', 'enrol_lti');
if (\enrol_lti\helper::count_lti_tools(array('courseid' => $courseid)) > 0) { if (\enrol_lti\helper::count_lti_tools(array('courseid' => $courseid)) > 0) {
$table = new \enrol_lti\manage_table($courseid); $table = new \enrol_lti\manage_table($courseid);

View file

@ -0,0 +1 @@
cartridgeurl,enrol_lti

View file

@ -24,7 +24,6 @@
$string['allowframeembedding'] = 'Note: It is recommended that the site administration setting \'Allow frame embedding\' is enabled, so that tools are displayed within a frame rather than in a new window.'; $string['allowframeembedding'] = 'Note: It is recommended that the site administration setting \'Allow frame embedding\' is enabled, so that tools are displayed within a frame rather than in a new window.';
$string['authltimustbeenabled'] = 'Note: This plugin requires the LTI authentication plugin to be enabled too.'; $string['authltimustbeenabled'] = 'Note: This plugin requires the LTI authentication plugin to be enabled too.';
$string['cartridgeurl'] = 'Cartridge URL';
$string['couldnotestablishproxy'] = 'Could not establish proxy with consumer.'; $string['couldnotestablishproxy'] = 'Could not establish proxy with consumer.';
$string['enrolenddate'] = 'End date'; $string['enrolenddate'] = 'End date';
$string['enrolenddate_help'] = 'If enabled, users can access until this date only.'; $string['enrolenddate_help'] = 'If enabled, users can access until this date only.';
@ -54,12 +53,13 @@ $string['membersyncmodeenrolandunenrol'] = 'Enrol new and unenrol missing users'
$string['membersyncmodeenrolnew'] = 'Enrol new users'; $string['membersyncmodeenrolnew'] = 'Enrol new users';
$string['membersyncmodeunenrolmissing'] = 'Unenrol missing users'; $string['membersyncmodeunenrolmissing'] = 'Unenrol missing users';
$string['notoolsprovided'] = 'No tools provided'; $string['notoolsprovided'] = 'No tools provided';
$string['lti1'] = 'LTI 1';
$string['lti2'] = 'LTI 2';
$string['lti:config'] = 'Configure \'Publish as LTI tool\' instances'; $string['lti:config'] = 'Configure \'Publish as LTI tool\' instances';
$string['lti:unenrol'] = 'Unenrol users from the course'; $string['lti:unenrol'] = 'Unenrol users from the course';
$string['opentool'] = 'Open tool'; $string['opentool'] = 'Open tool';
$string['pluginname'] = 'Publish as LTI tool'; $string['pluginname'] = 'Publish as LTI tool';
$string['pluginname_desc'] = 'The \'Publish as LTI tool\' plugin, together with the LTI authentication plugin, allows remote users to access selected courses and activities. In other words, Moodle functions as an LTI tool provider.'; $string['pluginname_desc'] = 'The \'Publish as LTI tool\' plugin, together with the LTI authentication plugin, allows remote users to access selected courses and activities. In other words, Moodle functions as an LTI tool provider.';
$string['proxyurl'] = 'Proxy URL';
$string['registration'] = 'Published tool registration'; $string['registration'] = 'Published tool registration';
$string['remotesystem'] = 'Remote system'; $string['remotesystem'] = 'Remote system';
$string['requirecompletion'] = 'Require course or activity completion prior to grade synchronisation'; $string['requirecompletion'] = 'Require course or activity completion prior to grade synchronisation';
@ -75,5 +75,9 @@ $string['successfulregistration'] = 'Successful registration';
$string['tasksyncgrades'] = 'Publish as LTI tool grade sync'; $string['tasksyncgrades'] = 'Publish as LTI tool grade sync';
$string['tasksyncmembers'] = 'Publish as LTI tool users sync'; $string['tasksyncmembers'] = 'Publish as LTI tool users sync';
$string['toolsprovided'] = 'Published tools'; $string['toolsprovided'] = 'Published tools';
$string['toolsprovided_help'] = 'This is the information you need to paste into any system to add these tools. In other systems the Tool URL may be referred to as a configuration URL or a web link.';
$string['tooltobeprovided'] = 'Tool to be published'; $string['tooltobeprovided'] = 'Tool to be published';
$string['toolurl'] = 'Tool URL';
$string['userdefaultvalues'] = 'User default values'; $string['userdefaultvalues'] = 'User default values';
// Deprecated since Moodle 3.2.
$string['cartridgeurl'] = 'Cartridge URL';

View file

@ -1,3 +1,3 @@
.copy_box { .copy_box {
max-width: 15vw; width: 100%;
} }

View file

@ -0,0 +1,51 @@
{{!
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/>.
}}
{{!
@template enrol_lti/copy_grid
The content to display when editing a tool.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* rows An array of objects with label, text and id
Example context (json):
{
"rows": [
{
"label": "Tool URL",
"text": "http://example.com/",
"id": "toolurl"
},
{
"label": "Secret",
"text": "ABCDEF1234567890",
"id": "secret"
}
]
}
}}
{{#rows}}
<label style="display: inline-block; width: 5em" {{#id}}for={{#quote}}{{{id}}}-{{{uniqid}}}{{/quote}}{{/id}}>{{label}}</label>
<div style="display: inline-block">{{> core/copy_box }}</div>
<br/>
{{/rows}}