Gitlab CSE Unil

Commit 880053c8 authored by M. Chardon's avatar M. Chardon
Browse files

vue administration :

- mise en place
- gestion des axes via ajax
parent c363a8e9
define(["jquery","core/notification","core/templates","core/fragment"],function(a,b,c,d){var e=null,f=function(a){this.init(),e=a};return f.prototype.selectTool=null,f.prototype.init=function(){var b=a("#editpdlplus_axes").val();a("#editpdlplus_toolbar_"+b).show(),a("#editpdlplus_axes").on("change",function(){a(".toolbar").hide();var b=a("#editpdlplus_axes").val();a("#editpdlplus_toolbar_"+b).show()}),a(".editpdlplus_tool").on("click",function(){var b=a(this).val();a(".editpdlplus_tool").each(function(){a(this).removeClass("btn-primary"),a(this).removeClass("btn-default");var c=a(this).data("enable");1===c&&a(this).val()!==b&&a(this).addClass("btn-default")}),a(this).addClass("btn-primary")}),this.selectTool=a(".editpdlplus_tool").first(),this.initTool(),a("#assignfeedback_editpdfplus_widget_admin_button_addaxis").on("click",this.openDivAddAxis),a("#assignfeedback_editpdfplus_widget_admin_button_editaxis").on("click",this.openDivEditAxis)},f.prototype.initTool=function(){a(this.selectTool).removeClass("btn-default"),a(this.selectTool).addClass("btn-primary")},f.prototype.openDivAddAxis=function(){a("#axistool").hide(),a("#assignfeedback_editpdfplus_widget_admin_div_addaxis").show(),a("#assignfeedback_editpdfplus_widget_admin_div_addaxis > .panel-body").html("");var f={};d.loadFragment("assignfeedback_editpdfplus","axisadd",e,f).done(function(a,b){c.appendNodeContents("#assignfeedback_editpdfplus_widget_admin_div_addaxis > .panel-body",a,b)}.bind(this)).fail(b.exception)},f.prototype.openDivEditAxis=function(){a("#axistool").hide(),a("#assignfeedback_editpdfplus_widget_admin_div_editaxis").show(),a("#assignfeedback_editpdfplus_widget_admin_div_editaxis > .panel-body").html("");var f=a("#editpdlplus_axes option:selected").val(),g={axeid:f};d.loadFragment("assignfeedback_editpdfplus","axisedit",e,g).done(function(a,b){c.appendNodeContents("#assignfeedback_editpdfplus_widget_admin_div_editaxis > .panel-body",a,b)}.bind(this)).fail(b.exception)},f});
\ No newline at end of file
// 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/>.
/*
* @package assignfeedback_editpdfplus
* @copyright 2017 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* @module mod_assignfeedback_editpdfplus/admin_panel
*/
define(['jquery'/*, 'core/yui'*/, 'core/notification', 'core/templates', 'core/fragment'/*,
'core/ajax', 'core/str', 'mod_assign/grading_form_change_checker'*/],
function ($/*, Y*/, notification, templates, fragment/*, ajax, str, checker*/) {
var contextid = null;
/**
* AdminPanel class.
*
* @class AdminPanel
*/
var AdminPanel = function (contextidP) {
//this.registerEventListeners();
this.init();
contextid = contextidP;
};
//
//AdminPanel.prototype.contextid;
//
AdminPanel.prototype.selectTool = null;
//
AdminPanel.prototype.init = function () {
var selectAxis = $("#editpdlplus_axes").val();
$("#editpdlplus_toolbar_" + selectAxis).show();
$("#editpdlplus_axes").on("change", function () {
$(".toolbar").hide();
var selectAxis = $("#editpdlplus_axes").val();
$("#editpdlplus_toolbar_" + selectAxis).show();
});
//
$(".editpdlplus_tool").on("click", function () {
var selectid = $(this).val();
$(".editpdlplus_tool").each(function () {
$(this).removeClass("btn-primary");
$(this).removeClass("btn-default");
var enabled = $(this).data('enable');
if (enabled === 1 && $(this).val() !== selectid) {
$(this).addClass("btn-default");
}
});
$(this).addClass("btn-primary");
});
this.selectTool = $(".editpdlplus_tool").first();
this.initTool();
$("#assignfeedback_editpdfplus_widget_admin_button_addaxis").on("click", this.openDivAddAxis);
$("#assignfeedback_editpdfplus_widget_admin_button_editaxis").on("click", this.openDivEditAxis);
};
//
AdminPanel.prototype.initTool = function () {
$(this.selectTool).removeClass("btn-default");
$(this.selectTool).addClass("btn-primary");
};
//
AdminPanel.prototype.openDivAddAxis = function () {
$("#axistool").hide();
$('#assignfeedback_editpdfplus_widget_admin_div_addaxis').show();
$('#assignfeedback_editpdfplus_widget_admin_div_addaxis > .panel-body').html("");
var params = {};
fragment.loadFragment('assignfeedback_editpdfplus', 'axisadd', contextid, params)
.done(function (html, js) {
templates.appendNodeContents('#assignfeedback_editpdfplus_widget_admin_div_addaxis > .panel-body',
html, js);
}.bind(this)).fail(notification.exception);
};
//
AdminPanel.prototype.openDivEditAxis = function () {
$("#axistool").hide();
$('#assignfeedback_editpdfplus_widget_admin_div_editaxis').show();
$('#assignfeedback_editpdfplus_widget_admin_div_editaxis > .panel-body').html("");
/*var context = {name: 'Tweety bird', intelligence: 2};
templates.render('assignfeedback_editpdfplus/admin_axis_add', context)
// It returns a promise that needs to be resoved.
.then(function (html, js) {
// Here eventually I have my compiled template, and any javascript that it generated.
// The templates object has append, prepend and replace functions.
templates.appendNodeContents('#assignfeedback_editpdfplus_widget_admin_div_editaxis > .panel-body',
html, js);
}).fail(notification.exception);*/
var axeid = $("#editpdlplus_axes option:selected").val();
var params = {axeid: axeid};
fragment.loadFragment('assignfeedback_editpdfplus', 'axisedit', contextid, params)
.done(function (html, js) {
templates.appendNodeContents('#assignfeedback_editpdfplus_widget_admin_div_editaxis > .panel-body',
html, js);
}.bind(this)).fail(notification.exception);
};
return AdminPanel;
});
\ No newline at end of file
<?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/>.
/**
* This file contains the editor class for the assignfeedback_editpdfplus plugin
*
* @package assignfeedback_editpdfplus
* @copyright 2016 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignfeedback_editpdfplus;
use assignfeedback_editpdfplus\axis;
/**
* This class performs crud operations on comments and annotations from a page of a response.
*
* No capability checks are done - they should be done by the calling class.
*
* @package assignfeedback_editpdfplus
* @copyright 2017 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_editor {
/**
*
* @global type $DB
* @param type $axisLabel
* @param type $context
* @return type
*/
public static function add_axis($axisLabel, $context) {
global $DB;
$record = $DB->get_record_sql('SELECT max(order_axis) as order_max FROM {assignfeedback_editpp_axis} WHERE contextid = :contextid', array('contextid' => $context));
$axis = new axis();
$axis->contextid = $context;
$axis->label = $axisLabel;
if ($record->order_max == null) {
$axis->order_axis = 1;
} else {
$axis->order_axis = $record->order_max + 1;
}
return $DB->insert_record('assignfeedback_editpp_axis', $axis);
}
/**
*
* @global type $DB
* @param type $axisLabel
* @param type $context
* @return type
*/
public static function edit_axis($axeid, $axisLabel) {
global $DB;
$axis = $DB->get_record('assignfeedback_editpp_axis', array('id' => $axeid), '*', MUST_EXIST);
$axis->label = $axisLabel;
return $DB->update_record('assignfeedback_editpp_axis', $axis);
}
}
<?php
/**
*
*
* @package assignfeedback_editpdfplus
* @copyright 2017 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignfeedback_editpdfplus\form;
require_once("$CFG->libdir/formslib.php");
use moodleform;
/**
* Description of formslib
*
* @author kury
*/
class axis_form extends moodleform {
protected function definition() {
global $CFG;
$mform = $this->_form;
$mform->_formName="tutu";
$mform->addElement('text', 'label', 'Nom'); // Add elements to your form
$mform->setType('label', PARAM_TEXT); //Set type of element
$mform->addElement('hidden', 'axeid', ''); // Add elements to your form
$mform->setType('hidden', PARAM_INT); //Set type of element
/*$buttonarray[] = &$mform->createElement('submit', 'submitbutton', 'Enregistrer');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');*/
//$this->add_action_buttons();
}
//Custom validation should be added here
function validation($data, $files) {
return array();
}
}
......@@ -297,11 +297,9 @@ class assignfeedback_editpdfplus_renderer extends plugin_renderer_base {
}
$toolbaraxis .= "</div></div>";
$questionchoice = html_writer::select(
[get_string('question_select', 'assignfeedback_editpdfplus'), get_string('question_select_without', 'assignfeedback_editpdfplus'), get_string('question_select_with', 'assignfeedback_editpdfplus')],
'questionselection', 0, FALSE, array('class' => 'form-control'));
[get_string('question_select', 'assignfeedback_editpdfplus'), get_string('question_select_without', 'assignfeedback_editpdfplus'), get_string('question_select_with', 'assignfeedback_editpdfplus')], 'questionselection', 0, FALSE, array('class' => 'form-control'));
$axischoice = html_writer::select(
[get_string('statut_select', 'assignfeedback_editpdfplus'), get_string('statut_select_nc', 'assignfeedback_editpdfplus'), get_string('statut_select_ok', 'assignfeedback_editpdfplus'), get_string('statut_select_ko', 'assignfeedback_editpdfplus')],
'statutselection', 0, FALSE, array('class' => 'form-control'));
[get_string('statut_select', 'assignfeedback_editpdfplus'), get_string('statut_select_nc', 'assignfeedback_editpdfplus'), get_string('statut_select_ok', 'assignfeedback_editpdfplus'), get_string('statut_select_ko', 'assignfeedback_editpdfplus')], 'statutselection', 0, FALSE, array('class' => 'form-control'));
$validatebutton = html_writer::tag('button', get_string('send_pdf_update', 'assignfeedback_editpdfplus'), array('class' => 'button btn btn-default', 'id' => 'student_valide_button'));
$toolbaraxis .= html_writer::div($validatebutton, 'toolbar ', array('role' => 'toolbar'));
$toolbaraxis .= html_writer::div($axischoice, 'toolbar ', array('role' => 'toolbar'));
......@@ -382,4 +380,12 @@ class assignfeedback_editpdfplus_renderer extends plugin_renderer_base {
return $html;
}
public function render_assignfeedback_editpdfplus_widget_admin(assignfeedback_editpdfplus\widget_admin $widget) {
return $this->render_from_template('assignfeedback_editpdfplus/admin', $widget);
}
public function render_assignfeedback_editpdfplus_widget_admin_axisform(moodleform $form){
return $this->render_from_template('assignfeedback_editpdfplus/axis_form', $form);
}
}
<?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/>.
namespace assignfeedback_editpdfplus;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
/**
* This file contains the definition for the library class for edit PDF renderer.
*
* @package assignfeedback_editpdfplus
* @copyright 2016 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class widget_admin implements renderable, templatable {
/** @var int $assignment - Assignment instance id */
public $context = null;
/** @var int $userid - The user id we are grading */
public $course = null;
/** @var int $userid - The user id we are grading */
public $userid = 0;
/** @var tool[] $toolbars */
public $toolbars = array();
/** @var axis[] $toolbars */
public $axis = array();
/**
* Constructor
* @param int $assignment - Assignment instance id
* @param int $userid - The user id we are grading
* @param int $attemptnumber - The attempt number we are grading
* @param moodle_url $downloadurl - A url to download the current generated pdf.
* @param string $downloadfilename - Name of the generated pdf.
* @param string[] $stampfiles - The file names of the stamps.
* @param bool $readonly - Show the readonly interface (no tools).
* @param integer $pagetotal - The total number of pages.
* @param tool[] $toolbars - the different tool to display
* @param axis[] $axis - the different axis to display
*/
public function __construct($context, $course, $userid, $toolbars, $axis) {
$this->context = $context;
$this->course = $course;
$this->userid = $userid;
$this->toolbars = $toolbars;
$this->axis = $axis;
}
public function export_for_template(\renderer_base $output) {
}
}
<?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/>.
/**
* Web service for assignfeedback_editpdfplus
* @package assignfeedback_editpdfplus
* @subpackage db
* @copyright 2017 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$functions = array(
'assignfeedback_editpdfplus_submit_axis_form' => array(
'classname' => 'assignfeedback_editpdfplus_external',
'methodname' => 'submit_axis_form',
'classpath' => 'mod/assign/feedback/editpdfplus/externallib.php',
'description' => 'Test add axis',
'type' => 'write',
'ajax' => true,
'requiredcapability' => 'mod/assignfeedback_editpdfplus:use',
'enabled'=>1,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
),
'assignfeedback_editpdfplus_submit_axis_edit_form' => array(
'classname' => 'assignfeedback_editpdfplus_external',
'methodname' => 'submit_axis_edit_form',
'classpath' => 'mod/assign/feedback/editpdfplus/externallib.php',
'description' => 'Edit an axis',
'type' => 'write',
'ajax' => true,
'requiredcapability' => 'mod/assignfeedback_editpdfplus:use',
'enabled'=>1,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
)
);
<?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/>.
/**
* External assign API
*
* @package assignfeedback_editpdfplus
* @copyright 2017 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/user/externallib.php");
require_once("$CFG->dirroot/mod/assign/locallib.php");
require_once("locallib.php");
require_once("locallib_admin.php");
use \assignfeedback_editpdfplus\form\axis_form;
use \assignfeedback_editpdfplus\admin_editor;
class assignfeedback_editpdfplus_external extends external_api {
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public static function submit_axis_form_parameters() {
return new external_function_parameters(
array(
'jsonformdata' => new external_value(PARAM_RAW, 'The data from the grading form, encoded as a json array')
)
);
}
public static function submit_axis_form($jsonformdata) {
global $USER, $PAGE, $DB;
$params = self::validate_parameters(self::submit_axis_form_parameters(), array(
'jsonformdata' => $jsonformdata
));
$serialiseddata = json_decode($params['jsonformdata']);
$data = array();
parse_str($serialiseddata, $data);
$warnings = array();
if (WS_SERVER) {
// Assume form submission if coming from WS.
$USER->ignoresesskey = true;
//$data['_qf__mod_assign_grade_form_' . $params['userid']] = 1;
}
$course = $DB->get_record('course', array('id' => $data['courseid']), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
$PAGE->set_context($context);
$customdata = (object) $data;
$formparams = array($customdata);
// Data is injected into the form by the last param for the constructor.
$mform = new axis_form(null, $formparams, 'post', '', null, true, $data);
$validateddata = $mform->get_data();
if ($validateddata) {
if ($validateddata->axeid) {
admin_editor::edit_axis($validateddata->axeid, $validateddata->label);
/* $axisTot = admin_editor::get_axis($context->id);
$res = array();
$res[]=array('axeid' => $validateddata->axeid, 'axelabel' => $validateddata->label);
foreach ($axisTot as $axetmp) {
$res[]=array('axeid' => $axetmp->id, 'axelabel' => $axetmp->label);
}
return $res; */
$axeid = $validateddata->axeid;
return array(array('axeid' => $axeid, 'axelabel' => $validateddata->label));
} else {
$axeid = admin_editor::add_axis($validateddata->label, $context->id);
//return array(array('itemid' => $axeid),array('item' => $validateddata->label));
//return array('axe' => array('axeid' => $axeid, 'axelabel' => $validateddata->label));
return array(array('axeid' => $axeid, 'axelabel' => $validateddata->label));
}
} else {
$warnings[] = array('message' => 'erreur à l enregistrement');
}
return $warnings;
}
/* public static function submit_axis_form_returns() {
return new external_warnings();
} */
public static function submit_axis_form_returns() {
return new external_multiple_structure(
new external_single_structure(
array(
'axeid' => new external_value(PARAM_INT, 'axis id'),
'axelabel' => new external_value(PARAM_TEXT, 'axis label'),
'message' => new external_value(PARAM_TEXT, 'message', VALUE_OPTIONAL)
)
)
);
}
}
......@@ -106,5 +106,6 @@ $string['student_statut_nc'] = 'Todo';
$string['student_answer_lib'] = 'Answer';
$string['editpdfplus:use'] = 'Use the plugin';
$string['editpdfplus:notify'] = 'Receive notifications';
$string['admintitle'] = 'Feedback configuration';
$string['adminsubtitle'] = 'Configuration of tools bar for advanded PDF annotation';
$string['admincurrenttoolbar'] = 'Current toolbar';
......@@ -106,5 +106,8 @@ $string['student_statut_nc'] = 'non traité';
$string['student_answer_lib'] = 'Réponse';
$string['editpdfplus:use'] = 'Utiliser le plugin';
$string['editpdfplus:notify'] = 'Recevoir les notifications';
$string['admintitle'] = 'Feedback configuration';
$string['adminsubtitle'] = 'Configuration de la barre d\'outils de l\'annotation PDF avancée';
$string['admincurrenttoolbar'] = 'Barre d\'outils en cours';
......@@ -79,14 +79,53 @@ function assignfeedback_editpdfplus_pluginfile($course, $cm, context $context, $
* @param context_course $context
*/
function assignfeedback_editpdfplus_extend_navigation_course(navigation_node $navigation, stdClass $course, context_course $context) {
$url = new moodle_url('/mod/assign/feedback/editpdfplus/admin/view.php');
$url = new moodle_url('/mod/assign/feedback/editpdfplus/view_admin.php', array('id' => $course->id));
$feedbackadminnode = navigation_node::create('Feedback : configuration', $url, navigation_node::TYPE_CUSTOM, 'Bars d\'outils', 'editpdfplusadmin', new pix_icon('i/grades', ""));
$navigation->add_node($feedbackadminnode);
}
/*function assignfeedback_editpdfplus_extend_navigation_course(navigation_node $parentnode, $course, $context) {
$url = new moodle_url('/course/view.php', array('courseid' => $course->id));
$settingsnode = navigation_node::create('test ND navigation node', $url,
navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
$parentnode->add_node($settingsnode);
}*/
/* function assignfeedback_editpdfplus_extend_navigation_course(navigation_node $parentnode, $course, $context) {
$url = new moodle_url('/course/view.php', array('courseid' => $course->id));
$settingsnode = navigation_node::create('test ND navigation node', $url,
navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
$parentnode->add_node($settingsnode);
} */
function assignfeedback_editpdfplus_output_fragment_axisadd($args) {
global $CFG, $DB;
$context = $args['context'];
if ($context->contextlevel != CONTEXT_COURSE) {
return null;
}
require_once('locallib_admin.php');
if (has_capability('mod/assignfeedback_editpdfplus:use', $context, null, false)) {
$course=$DB->get_record('course', array('id' => $context->instanceid), '*', MUST_EXIST);
$editpdfplus = new assign_feedback_editpdfplus_admin($context, $course);
return $editpdfplus->getAxisForm();
}
return null;
}
function assignfeedback_editpdfplus_output_fragment_axisedit($args) {
global $CFG, $DB;
$context = $args['context'];
$axisid = $args['axeid'];
if ($context->contextlevel != CONTEXT_COURSE) {
return null;
}
require_once('locallib_admin.php');
if (has_capability('mod/assignfeedback_editpdfplus:use', $context, null, false)) {
$course=$DB->get_record('course', array('id' => $context->instanceid), '*', MUST_EXIST);
$editpdfplus = new assign_feedback_editpdfplus_admin($context, $course);
return $editpdfplus->getAxisForm($axisid);
}
return null;
}
......@@ -120,9 +120,6 @@ class assign_feedback_editpdfplus extends assign_feedback_plugin {
$filename = $feedbackfile->get_filename();
}
// Retrieve total number of pages.