Skip to content

Commit

Permalink
implement composer liturgical-calendar/components
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Sep 17, 2024
1 parent ea68e68 commit 5ea3f74
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
20 changes: 15 additions & 5 deletions admin.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

require_once 'vendor/autoload.php';
require_once 'includes/auth.php';

use LiturgicalCalendar\Components\CalendarSelect;

if (!authenticated()) {
header("WWW-Authenticate: Basic realm=\"Please insert your credentials\"");
header($_SERVER["SERVER_PROTOCOL"] . " 401 Unauthorized");
Expand All @@ -16,7 +18,7 @@
$ch = curl_init();

if ($apiVersion === 'dev') {
curl_setopt($ch, CURLOPT_URL, "https://litcal.johnromanodorazio.com/api/$apiVersion/tests/");
curl_setopt($ch, CURLOPT_URL, "https://litcal.johnromanodorazio.com/api/$apiVersion/tests");
} else {
curl_setopt($ch, CURLOPT_URL, "https://litcal.johnromanodorazio.com/api/$apiVersion/testsindex/");
}
Expand Down Expand Up @@ -58,9 +60,17 @@
<label class="w-100 text-center fw-bold border border-top-0 border-start-0 border-end-0 border-secondary"><?php echo _('Create a New Test'); ?></label>
<div class="row justify-content-center align-items-start">
<div class="form-group col col-md-3 border border-top-0 border-bottom-0 border-end-0 border-secondary">
<label for="APICalendarSelect"><?php echo _('Calendar to test'); ?></label>
<select id="APICalendarSelect" class="form-select">
</select>
<?php
$options = ['locale' => 'it']; // set the locale to Italian
$CalendarSelect = new CalendarSelect($options); // use the default API url, but set the locale to Italian
echo $CalendarSelect->getSelect([
'class' => 'form-select',
'id' => 'APICalendarSelect',
'options' => 'all',
'label' => true,
'labelStr' => _('Calendar to test')
]);
?>
</div>
<div class="form-group col col-md-9">
<label><?php echo _("Test Type"); ?></label>
Expand Down
42 changes: 5 additions & 37 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ const setEndpoints = (ev = null) => {
}
switch(ENDPOINTS.VERSION) {
case 'dev':
ENDPOINTS.METADATA = `https://litcal.johnromanodorazio.com/api/dev/calendars/`;
ENDPOINTS.TESTSINDEX = `https://litcal.johnromanodorazio.com/api/dev/tests/`;
ENDPOINTS.EVENTS = `https://litcal.johnromanodorazio.com/api/dev/events/`;
case 'v4':
ENDPOINTS.METADATA = `https://litcal.johnromanodorazio.com/api/dev/calendars`;
ENDPOINTS.TESTSINDEX = `https://litcal.johnromanodorazio.com/api/dev/tests`;
ENDPOINTS.EVENTS = `https://litcal.johnromanodorazio.com/api/dev/events`;
break;
case 'v3':
ENDPOINTS.METADATA = `https://litcal.johnromanodorazio.com/api/v3/LitCalMetadata.php`;
Expand All @@ -189,44 +190,11 @@ const setEndpoints = (ev = null) => {

setEndpoints();

const COUNTRY_NAMES = new Intl.DisplayNames([locale], {type: 'region'});
//const COUNTRY_NAMES = new Intl.DisplayNames([locale], {type: 'region'});
let CalendarNations = [];
let SelectOptions = {};
let DiocesanCalendars;
//const COUNTRIES is available from Countries.js, included in footer.php for admin.php

fetch( ENDPOINTS.METADATA )
.then(data => data.json())
.then(jsonData => {
const { LitCalMetadata } = jsonData;
const { NationalCalendars } = LitCalMetadata;
({DiocesanCalendars} = LitCalMetadata);
Object.freeze(DiocesanCalendars);
for( const [key,value] of Object.entries( DiocesanCalendars ) ) {
if( false === CalendarNations.includes(value.nation) ) {
CalendarNations.push(value.nation);
SelectOptions[value.nation] = [];
}
SelectOptions[value.nation].push(`<option data-calendartype="diocesancalendar" value="${key}">${value.diocese}</option>`);
}

let nations = Object.keys( NationalCalendars );
nations.sort((a, b) => COUNTRY_NAMES.of(COUNTRIES[a]).localeCompare(COUNTRY_NAMES.of(COUNTRIES[b])));
nations.forEach(item => {
if( false === CalendarNations.includes(item) ) {
const calName = item === 'VATICAN' ? 'Universal Roman' : COUNTRY_NAMES.of(COUNTRIES[item]);
$('#APICalendarSelect').append(`<option data-calendartype="nationalcalendar" value="${item}">${calName}</option>`);
}
});

CalendarNations.sort((a, b) => COUNTRY_NAMES.of(COUNTRIES[a]).localeCompare(COUNTRY_NAMES.of(COUNTRIES[b])));
CalendarNations.forEach(item => {
$('#APICalendarSelect').append(`<option data-calendartype="nationalcalendar" value="${item}">${COUNTRY_NAMES.of(COUNTRIES[item])}</option>`);
let $optGroup = $(`<optgroup label="${COUNTRY_NAMES.of(COUNTRIES[item])}">`);
$('#APICalendarSelect').append($optGroup);
SelectOptions[item].forEach(groupItem => $optGroup.append(groupItem));
});
});

/** Prepare PUT new Unit Test */

Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"liturgical-calendar/components": "^1.0"
}
}
59 changes: 59 additions & 0 deletions composer.lock

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

0 comments on commit 5ea3f74

Please sign in to comment.