revert Replaced wol link with ajax retrieval. Fixed local settings
This commit is contained in:
pmkuipers 2023-11-20 10:55:12 +01:00
parent ad852c72d5
commit 449618ef9a
11 changed files with 185 additions and 56 deletions

View File

@ -1,24 +0,0 @@
/*eslint no-var: "error" */
/*eslint no-unused-vars: "off" */
/*eslint linebreak-style: "off" */
/*eslint no-trailing-spaces: "off" */
/*eslint-env es6*/
// Put this file in path/to/plugin/amd/src
// You can call it anything you like
import {call} from 'core/ajax';
import notification from 'core/notification';
/**
* Initialize the Page
*/
/**
* Initialize the Page
*/
export function init() {
}

View File

@ -0,0 +1,105 @@
/*eslint no-var: "error" */
/*eslint no-unused-vars: "off" */
/*eslint linebreak-style: "off" */
/*eslint no-trailing-spaces: "off" */
/*eslint-env es6*/
// Put this file in path/to/plugin/amd/src
// You can call it anything you like
import {call} from 'core/ajax';
import notification from 'core/notification';
import Vue from 'local_treestudyplan/vue/vue';
import RVComponents from 'local_treestudyplan/report-viewer-components';
import TSComponents from 'local_treestudyplan/treestudyplan-components';
import Debugger from 'local_treestudyplan/util/debugger';
import {load_strings} from 'local_treestudyplan/util/string-helper';
import {ProcessStudyplans} from 'local_treestudyplan/studyplan-processor';
import PortalVue from 'local_treestudyplan/portal-vue/portal-vue.esm';
import BootstrapVue from 'local_treestudyplan/bootstrap-vue/bootstrap-vue';
Vue.use(TSComponents);
Vue.use(RVComponents);
Vue.use(PortalVue);
Vue.use(BootstrapVue);
let debug = new Debugger("mytreestudyplan");
debug.enable();
let strings = load_strings({
studyplan: {
},
});
/**
* Initialize the Page
*/
/**
* Initialize the Page
* @param {string} type Type of page to show
* @param {Object} arg Arguments passed
*/
export function init(type="myreport",arg) {
// Save time by only starting up the Vue app if the required block element is present
const blockelement = document.getElementById('block_mytreestudyplan');
if(blockelement){
const app = new Vue({
el: '#block_mytreestudyplan',
data: {
"studyplans": [],
},
mounted() {
let call_method;
let call_args;
if(type == "teacher"){
call_method = 'local_treestudyplan_get_teacher_studyplan';
call_args = {};
}
else if(type == "teaching"){
call_method = 'local_treestudyplan_get_teaching_studyplans';
call_args = {};
}
else{
call_method = 'local_treestudyplan_get_own_studyplan';
call_args = {};
}
call([{
methodname: call_method,
args: call_args
}])[0].done(function(response){
debug.info("Studyplans:",response);
const timingval = { future: 0, present: 1, past: 2, };
response.sort((a,b) => {
const timinga = TSComponents.studyplanTiming(a);
const timingb = TSComponents.studyplanTiming(b);
let t = timingval[timinga] - timingval[timingb];
if(t == 0){
// sort by start date if timing is equal
t = new Date(b.startdate).getTime() - new Date(a.startdate).getTime();
if (t == 0) {
// sort by name if timing is equal
t = a.name.localeCompare(b.name);
}
}
return t;
});
app.studyplans = ProcessStudyplans(response);
}).fail(notification.exception);
},
created() {
},
updated() {
},
methods: {
},
});
}
}

View File

@ -16,16 +16,17 @@
/** /**
* Main block code * Main block code
* *
* @package block_bibleblock * @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers * @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
use local_treestudyplan\studyplan;
/** /**
* MyTreestudyplan block base code * MyTreestudyplan block base code
*/ */
class block_bibleblock extends \block_base { class block_mytreestudyplan extends \block_base {
/** /**
* Plugin initialization (before $this->config and $this->page are loaded) * Plugin initialization (before $this->config and $this->page are loaded)
@ -38,14 +39,22 @@ class block_bibleblock extends \block_base {
*/ */
public function specialization() { public function specialization() {
global $CFG; global $CFG;
$this->title = get_string('title', 'block_bibleblock'); $this->title = get_string('title', 'block_mytreestudyplan');
$systemcontext = \context_system::instance();
$teachermode = has_capability("local/treestudyplan:viewuserreports", $systemcontext);
// Load CSS files from treestudyplan. // Load CSS files from treestudyplan.
try { try {
$this->page->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.min.css'));
if($CFG->debugdeveloper){
$this->page->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
}
$this->page->add_body_class("features-treestudyplan"); // Mark body as containing treestudyplan content.
// Include javascript and run studyplan renderer when page loading is complete. // Include javascript and run studyplan renderer when page loading is complete.
$this->page->requires->js_call_amd('block_bibleblock/block_bibleblock', $this->page->requires->js_call_amd('block_mytreestudyplan/block_mytreestudyplan',
'init', 'init',
[]); [$teachermode ? 'teaching' : 'myreport']);
} catch (Exception $x) { } catch (Exception $x) {
// On some occasions (Plugin management), the plugin is loaded after HEAD has been printed. // On some occasions (Plugin management), the plugin is loaded after HEAD has been printed.
// In those cases we don't want to show the block anyway, so ignore the error that gets inevitably thrown. // In those cases we don't want to show the block anyway, so ignore the error that gets inevitably thrown.
@ -61,8 +70,8 @@ class block_bibleblock extends \block_base {
return [ return [
'admin' => false, 'admin' => false,
'site-index' => true, 'site-index' => true,
'course-view' => true, 'course-view' => false,
'mod' => true, 'mod' => false,
'my' => true 'my' => true
]; ];
} }
@ -71,15 +80,37 @@ class block_bibleblock extends \block_base {
* Render block content * Render block content
*/ */
public function get_content() { public function get_content() {
global $CFG;
global $USER;
global $COURSE;
global $OUTPUT; global $OUTPUT;
if ($this->content !== null) { if ($this->content !== null) {
return $this->content; return $this->content;
} }
$data = []; $systemcontext = \context_system::instance();
// TODO: Check if they have the permission in any relevant context, not just system.
$teachermode = has_capability("local/treestudyplan:viewuserreports", $systemcontext);
$this->content = new \stdClass; $this->content = new \stdClass;
$this->content->text = $OUTPUT->render_from_template("block_bibleblock/block", $data); $this->content->text = "";
$mystudyplans = studyplan::find_for_user($USER->id);
$data = [
'teachermode' => $teachermode,
];
$this->content->text = $OUTPUT->render_from_template("block_mytreestudyplan/block", $data);
$inviteurl = $CFG->wwwroot.'/local/treestudyplan/invitations.php';
$invitetext = get_string('manage_invites', 'local_treestudyplan');
if ( (!$teachermode ) && count($mystudyplans) > 0) {
$this->content->footer = "&nbsp; <a class='btn btn-primary' href='{$inviteurl}'>{$invitetext}</a>";
}
return $this->content; return $this->content;
} }

View File

@ -15,14 +15,14 @@
// along with Moodle. If not, see <https://www.gnu.org/licenses/>. // along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/** /**
* Permission descriptions * Permission descriptions
* @package block_bibleblock * @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers * @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$capabilities = [ $capabilities = [
'block/bibleblock:addinstance' => [ 'block/mytreestudyplan:addinstance' => [
'riskbitmask' => RISK_SPAM | RISK_XSS, 'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK, 'contextlevel' => CONTEXT_BLOCK,

View File

@ -15,12 +15,13 @@
// along with Moodle. If not, see <https://www.gnu.org/licenses/>. // along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/** /**
* English language file * English language file
* @package block_bibleblock * @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers * @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
$string['pluginname'] = 'Bibleblock'; $string['pluginname'] = 'My Treestudyplan';
$string['title'] = 'Bible verses'; $string['mytreestudyplan'] = 'MyTreestudyplan';
$string['bibleblock:addinstance'] = 'Add bibleblock'; $string['title'] = 'My Studyplan';
$string['mytreestudyplan:addinstance'] = 'Add my studyplan block';

View File

@ -15,12 +15,13 @@
// along with Moodle. If not, see <https://www.gnu.org/licenses/>. // along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/** /**
* Dutch language file * Dutch language file
* @package block_bibleblock * @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers * @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
$string['pluginname'] = 'Bibleblock'; $string['pluginname'] = 'Mijn Treestudyplan';
$string['title'] = 'Bible verses'; $string['mytreestudyplan'] = 'MyTreestudyplan';
$string['bibleblock:addinstance'] = 'Voeg bibleblock toe'; $string['title'] = 'Mijn Studieplan';
$string['mytreestudyplan:addinstance'] = 'Voeg mijn studieplan block toe';

View File

@ -15,7 +15,7 @@
// along with Moodle. If not, see <https://www.gnu.org/licenses/>. // along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/** /**
* Library page * Library page
* @package block_bibleblock * @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers * @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */

View File

@ -15,7 +15,7 @@
// along with Moodle. If not, see <https://www.gnu.org/licenses/>. // along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/** /**
* Settings page * Settings page
* @package block_bibleblock * @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers * @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */

View File

@ -1,6 +1,10 @@
/* stylelint-disable length-zero-no-unit, color-hex-case, color-hex-length*/ /* stylelint-disable length-zero-no-unit, color-hex-case, color-hex-length*/
.path-block-mytreestudyplan [v-cloak] {
.path-block-bibleblock #block_bibleblock_content { visibility: hidden;
overflow-y: auto; }
.path-block-mytreestudyplan .vue-loader {
width: 32px;
margin: auto;
} }

View File

@ -15,7 +15,7 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>. along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}} }}
{{! {{!
@template block_bibleblock/block @template block_mytreestudyplan/block
Render my treestudyplan block Render my treestudyplan block
@ -33,8 +33,19 @@
} }
}} }}
<div id='block_bibleblock'> <div id='block_mytreestudyplan'>
<h4 id="block_bibleblock_heading"></h4> <div class='vue-loader' v-show='false'>
<div id="block_bibleblock_content"> <div class='spinner-border text-primary' role='status'>
<span class='sr-only'>Loading...</span>
</div>
</div>
<div v-cloak>
{{^teachermode}}
<r-report v-model='studyplans'></r-report>
{{/teachermode}}
{{#teachermode}}
<r-report v-model='studyplans' teachermode></r-report>
{{/teachermode}}
</div> </div>
</div> </div>

View File

@ -15,14 +15,14 @@
// along with Moodle. If not, see <https://www.gnu.org/licenses/>. // along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/** /**
* Version description * Version description
* @package block_bibleblock * @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers * @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->component = 'block_bibleblock'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494). $plugin->component = 'block_mytreestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
$plugin->version = 2023111900; // YYYYMMDDHH (year, month, day, iteration). $plugin->version = 2023090800; // YYYYMMDDHH (year, month, day, iteration).
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11). $plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
$plugin->release = "1.0.0"; $plugin->release = "1.0.0";
@ -31,5 +31,5 @@ $plugin->maturity = MATURITY_RC;
$plugin->supported = [ 311, 401 ]; $plugin->supported = [ 311, 401 ];
$plugin->dependencies = [ $plugin->dependencies = [
'filter_bibleversesnwt' => 2023111900, 'local_treestudyplan' => 2023090700,
]; ];