Skip to content

Commit

Permalink
First steps to new navigation dropdown for optiondates.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibernhardf committed Jan 28, 2025
1 parent 78fc295 commit 56ca34b
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 4 deletions.
3 changes: 3 additions & 0 deletions amd/build/bookingjslib.min.js

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

1 change: 1 addition & 0 deletions amd/build/bookingjslib.min.js.map

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

40 changes: 40 additions & 0 deletions amd/src/bookingjslib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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/>.

/**
* Library containing general JS functions for the booking module.
*
* @module mod_booking/bookingjslib
* @copyright 2025 Bernhard Fischer-Sengseis
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Init.
*/
export const init = () => {
// Initialize if necessary.
};

/**
* Navigate to a page.
*
* @param {object} select
*/
export function navigateToPage(select) {
if (select.url) {
window.location.href = select.url;
}
}
3 changes: 2 additions & 1 deletion classes/booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,8 @@ public static function generate_localized_css_for_navigation_labels(string $pref
content: "' . get_string($prefix . 'label' . $scope, 'mod_booking') . '";
position: absolute;
top: -10px;
padding: 0 5px;
left: 5px;
padding: 0 3px;
font-weight: 200;
font-size: small;
background-color: white;
Expand Down
37 changes: 34 additions & 3 deletions report2.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,30 @@
require_once($CFG->dirroot . '/mod/booking/lib.php');

use mod_booking\booking;
use mod_booking\option\dates_handler;
use mod_booking\output\booked_users;
use mod_booking\singleton_service;

global $PAGE, $SITE;

$PAGE->requires->js_call_amd('mod_booking/bookingjslib');

$optionid = optional_param('optionid', 0, PARAM_INT);
$cmid = optional_param('cmid', 0, PARAM_INT);
$courseid = optional_param('courseid', 0, PARAM_INT);

$ticketicon = '<i class="fa fa-fw fa-sm fa-ticket" aria-hidden="true"></i>&nbsp;';
$linkicon = '<i class="fa fa-fw fa-xs fa-external-link" aria-hidden="true"></i>&nbsp;';
$divider = "<span class='mt-1 ml-1 mr-1 mt-3'>
<i class='fa-solid fa-2xs fa-arrow-right' aria-hidden='true' style='color: gray;'></i>
$divider = "<span class='mt-1 ml-1 mr-1 mt-4'>
<i class='fa-solid fa-2xs fa-angle-right' aria-hidden='true' style='color: gray;'></i>
</span>";

$r2syscontext = context_system::instance();
$r2syscap = has_capability('mod/booking:managebookedusers', $r2syscontext);
$r2systemurl = new moodle_url('/mod/booking/report2.php');

if (!empty($optionid)) {
// We are in option scope.
$scopes = ['system', 'course', 'instance', 'option'];
$optionsettings = singleton_service::get_instance_of_booking_option_settings($optionid);
$cmid = $optionsettings->cmid;
Expand Down Expand Up @@ -99,8 +103,33 @@
$divider .
"<a href='{$r2optionurl}' class='report2-option-border'>" .
$linkicon . $optionsettings->get_title_with_prefix() .
"</a></div>";
"</a>";

// Create a navigation dropdown for all optiondates (sessions) of the booking option.
$optiondates = $optionsettings->sessions;
if (!empty($optiondates) && count($optiondates) > 1) {
$data['optiondatesexist'] = true;
foreach ($optiondates as &$optiondate) {
$optiondate = (array) $optiondate;
$optiondate['prettydate'] = dates_handler::prettify_optiondates_start_end(
$optiondate['coursestarttime'],
$optiondate['courseendtime'],
current_language(),
true
);
$dateurl = new moodle_url('/mod/booking/report2.php', [
'optionid' => $optionid,
'optiondateid' => $optiondate['id'],
]);
$optiondate['dateurl'] = $dateurl->out(false);
}
$data['optiondates'] = array_values((array) $optiondates);
// Now we just append the dropdown to the navigation HTML.
$navhtml .= $divider . $OUTPUT->render_from_template('mod_booking/report/navigation_dropdown', $data);
}
$navhtml .= "</div>";
} else if (!empty($cmid)) {
// We are in instance scope.
$scopes = ['system', 'course', 'instance'];
$scope = 'instance';
$scopeid = $cmid;
Expand Down Expand Up @@ -140,6 +169,7 @@
$linkicon . $bookingsettings->name .
"</a>";
} else if (!empty($courseid)) {
// We are in course scope.
$scopes = ['system', 'course'];
$scope = 'course'; // A moodle course containing (a) booking option(s).
$scopeid = $courseid;
Expand Down Expand Up @@ -169,6 +199,7 @@
$linkicon . $course->fullname .
"</a>";
} else {
// We are in system scope.
$scopes = ['system'];
require_login(1, false);
$scope = 'system'; // The whole site.
Expand Down
46 changes: 46 additions & 0 deletions templates/report/navigation_dropdown.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{!
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 mod_booking/report/navigation_dropdown
Classes required for JS:
* none
Data attributes required for JS:
* data-region
Example context (json):
{
"prettydate" : "Mo, 28.01.2025, 12:00-13:00",
"dateurl" : "https://www.exampleurl.xyz"
}
}}
{{#optiondatesexist}}
<span class="mt-1">
<select id="mod-booking-report2-navigation-dropdown"
onchange="navigateToPage(this)" class="form-control">
{{#optiondates}}
<option url="{{dateurl}}">{{prettydate}}</option>
{{/optiondates}}
</select>
</span>
{{/optiondatesexist}}
{{#js}}
require(['mod_booking/bookingjslib'], function(fn) {
fn.init();
});
{{/js}}

0 comments on commit 56ca34b

Please sign in to comment.