Skip to content

Commit

Permalink
fixes #4 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
sherpadawan committed Sep 3, 2020
1 parent 580923c commit ee02288
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 67 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.3.1
[](#improved)
* taxonomy not required anymore, recognition based on template name #4

[](#bugfix)
* support modular and non modular page #5

# v0.3.0
## 02/09/2020

Expand Down
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ Note that if you use the admin plugin, a file with your configuration, and named

## Usage

fullcalendar plugins, requires you to create a page with taxonomy like, this can be achieve in expert or normal mode
if your calendar is a modular subpage you need to add this taxonomy on the parent page and on the modular child page

```
taxonomy:
category:
- calendar
```
Nothing special, just use the proper templates Fullcalendar or Modular Fullcalendar

## Recurrent events

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: FullCalendar
version: 0.3.0
version: 0.3.1
description: Show Calendar Widget from ICS remote and/or locally uploaded file(s), based on fullcalendar.io
icon: calendar
author:
Expand Down
66 changes: 29 additions & 37 deletions fullcalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class FullcalendarPlugin extends Plugin
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
'onPluginsInitialized' => ['onPluginsInitialized', 0],
'onGetPageTemplates' => ['onGetPageTemplates', 0],
];
}

Expand All @@ -24,7 +25,6 @@ public function onPluginsInitialized()
// Enable the main events we are interested in
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths',0],
'onGetPageTemplates' => ['onGetPageTemplates', 0],
'onPagesInitialized' => ['onPagesInitialized', 0]
]);
}
Expand All @@ -37,37 +37,23 @@ public function onPagesInitialized()
{
$assets = $this->grav['assets'];

//map plugin config
$config = $this->grav['config'];
//we choose settings for security reasons
$json = "var GRAV = {
'config': {
'system': {
'debugger': ". json_encode($config['system']['debugger'])."
},
'plugins': {
'fullcalendar': ".json_encode($config['plugins']['fullcalendar']) ."
}
}
};";
$assets->addInlineJs($json, ['loading'=>'inline', 'position'=>'before']);

//current page node
$currentPage = $this->grav['page'];
$taxo = $currentPage->taxonomy();
//do not process something else than active and calendar page
if ( !$currentPage->active() || empty($taxo['category']) || !in_array('calendar', $taxo['category'])) {
$templateName = $currentPage->template();
$expectedTemplates = ['fullcalendar', 'modular', 'modular_fullcalendar'];
if ( !$currentPage->active() || !in_array($templateName, $expectedTemplates)) {
return;
}
//we expect only one modular calendar
$children = $currentPage->evaluate(['@page.modular'=> $currentPage->route(),
'@taxonomy.category' => 'calendar'
]);
if ($children->count() > 1) {


//WARNING : we expect only one modular calendar
$page = $currentPage;
if ($templateName == 'modular') {
$children = $currentPage->evaluate(['@page.modular'=> $currentPage->route(),'filter'=>['type'=>'modular_fullcalendar'] ]);
$page = $children->current();
} else {
$page = $currentPage;
}
//headers and media
$headers = json_encode($page->header());
$media = $page->getMedia();
$fileUrls = [];
Expand All @@ -76,6 +62,22 @@ public function onPagesInitialized()
$fileUrls[] = ['ics'=>$file->url(), 'name'=>$name];
}
}

//map plugin config
$config = $this->grav['config'];
//we choose settings for security reasons
$json = "var GRAV = {
'config': {
'system': {
'debugger': ". json_encode($config['system']['debugger'])."
},
'plugins': {
'fullcalendar': ".json_encode($config['plugins']['fullcalendar']) ."
}
}
};";
$assets->addInlineJs($json, ['loading'=>'inline', 'position'=>'before']);

//build page headers and media in json
$pageJson =
" GRAV.page = { header:'', media:''};" .
Expand Down Expand Up @@ -104,17 +106,7 @@ public function onTwigTemplatePaths()
public function onGetPageTemplates(Event $event)
{
$types = $event->types;

/* @var Locator $locator */
$locator = $this->grav['locator'];

// Set blueprints & templates.
//$types->scanBlueprints($locator->findResource('plugin://fullcalendar/blueprints'));
$types->scanTemplates($locator->findResource('plugin://fullcalendar/templates'));

// reverse the FUBARd order of blueprints
$event = array_reverse($types['event']);
$types['event'] = $event;
$types->scanTemplates('plugin://fullcalendar/templates/');
}


Expand Down
20 changes: 10 additions & 10 deletions templates/fullcalendar.html.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% extends 'default.html.twig' %}
{% block content %}
<div class="content events">
<div class="container">
<div id='actMonth'></div>
<div id='calendar'></div>
<div id='legend'></div>
</div>
</div>
{% endblock %}
{% extends 'partials/base.html.twig' %}
{% block content %}
<div class="content events">
<div class="container">
<div id='actMonth'></div>
<div id='calendar'></div>
<div id='legend'></div>
</div>
</div>
{% endblock %}
10 changes: 6 additions & 4 deletions templates/modular/modular_fullcalendar.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% extends 'partials/fullcalendar.html.twig' %}
{% block content %}
<div class="content events">
<!-- <a class="togglehide" data-target="#calendar" href="#"><h2>Voir le calendrier</h2></a> -->
{{parent()}}
<div class="content events">
<div class="container">
<div id='actMonth'></div>
<div id='calendar'></div>
<div id='legend'></div>
</div>
</div>
{% endblock %}
7 changes: 0 additions & 7 deletions templates/partials/fullcalendar.html.twig

This file was deleted.

0 comments on commit ee02288

Please sign in to comment.