Skip to content

Commit

Permalink
Merge pull request #4 from captive/develop
Browse files Browse the repository at this point in the history
Add the tooltip property
  • Loading branch information
fansaien authored Jan 3, 2020
2 parents e7cd308 + 8de9c7d commit 57e2638
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 2 deletions.
9 changes: 8 additions & 1 deletion classes/EventData.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class EventData
*/
public $end;

/**
*
* @var string|null the tooltip content
*/
public $tooltip;


/**
* @var array Other additional properties
*/
Expand Down Expand Up @@ -135,4 +142,4 @@ protected function parseDateTime(string $dateTime, $timeZone = null)
}
return $date;
}
}
}
3 changes: 3 additions & 0 deletions docs/example.config_calendar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ recordEnd: end_time
# The property to use as the background color displayed on the record, , '' = the default background color in the calendar.less
recordColor: event_color

# The property to use as the content of the tooltip for the record
recordTooltip: [recordTitle]

# Available display modes to be supported in this instance
availableDisplayModes: [month, week, day, list]

Expand Down
29 changes: 28 additions & 1 deletion widgets/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class Calendar extends WidgetBase
*/
public $recordColor = null;

/**
*
* @var string|array The model property to use as the content of the tooltip for the record
*/
public $recordTooltip = null;

/**
* @var array Display modes to allow ['month', 'week', 'day', 'list']
*/
Expand Down Expand Up @@ -130,6 +136,7 @@ public function init()
'recordStart',
'recordEnd',
'recordColor',
'recordTooltip',
'previewMode',
'searchList',
'availableDisplayModes',
Expand Down Expand Up @@ -176,8 +183,12 @@ protected function loadAssets()

$this->addCss(['packages/core/main.min.css', 'packages/list/main.min.css','packages/daygrid/main.min.css','packages/timegrid/main.min.css'], '4.1.0');
$this->addCss(['less/calendar.less'], 'captive.calendar');
// $this->addJs('js/fullcalendar.js', '4.0.0-alpha.4');

//Tooltip
$this->addJs('packages/vendor/popper.min.js', '4.1.0');
$this->addJs('packages/vendor/tooltip.min.js', '4.1.0');

//Calendar
$this->addJs('packages/core/main.min.js', '4.1.0');
$this->addJs('packages/list/main.min.js', '4.1.0');
$this->addJs('packages/daygrid/main.min.js', '4.1.0');
Expand Down Expand Up @@ -676,7 +687,22 @@ public function getRecords($startTime = 0 , $endTime = 0)
$events = [];

$timeZone = new DateTimeZone(Config::get('app.timezone','UTC'));

foreach ($records as $record) {
if (empty($this->recordTooltip)) {
$tooltip = null;
}else {
if (is_array($this->recordTooltip)) {
$tooltip = '';
foreach ($this->recordTooltip as $item){
$keyName = $this->{$item};
$tooltip .= $record->{$keyName} . ' ';
}
}else {
$tooltip = $record->{$this->recordTooltip};
}
}

$eventData = new EventData([
'id' => $record->getKey(),
'url' => $this->getRecordUrl($record),
Expand All @@ -685,6 +711,7 @@ public function getRecords($startTime = 0 , $endTime = 0)
'end' => $record->{$this->recordEnd},
'allDay' => (bool) $record->allDay,
'color' => empty($this->recordColor) ? '' : $record->{$this->recordColor},
'tooltip' => $tooltip
], $timeZone);
$events[] = $eventData->toArray();
}
Expand Down
12 changes: 12 additions & 0 deletions widgets/calendar/assets/js/october.calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
const $calendar = this.$el.find('.calendar-control');
const self = this;
const timezone = $('meta[name="backend-timezone"]').attr('content');
const container = document.querySelector(".calendar-container");

this.calendarControl = new FullCalendar.Calendar($calendar[0], {
plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list', 'momentTimezone'],
Expand All @@ -93,6 +94,17 @@
eventClick: function (info) {
self.onEventClick(info);
},
eventRender: function(info) {
const tooltipContent = info.event.extendedProps.tooltip;
if (tooltipContent) {
let tooltip = new Tooltip(info.el, {
title: tooltipContent,
placement: 'top',
trigger: 'hover',
container: container
});
}
},
events: function (fetchInfo, successCallback, failureCallback){
self.onPrevNextButtonClick(fetchInfo, successCallback, failureCallback);
},
Expand Down
33 changes: 33 additions & 0 deletions widgets/calendar/assets/less/calendar.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,37 @@
}

}

.calendar-tooltip {
position: absolute;
z-index: 9999;
color: black;
width: 150px;
border-radius: 3px;
box-shadow: 0 0 2px rgba(0,0,0,0.5);
text-align: center;
&[x-placement^="top"] {
margin-bottom: 5px;
.tooltip-arrow {
border-width: 5px 5px 0 5px;
border-left-color: transparent;
border-right-color: transparent;
border-bottom-color: transparent;
bottom: -5px;
left: calc(50% - 5px);
margin-top: 0;
margin-bottom: 0;
}
}
.tooltip-arrow {
width: 0;
height: 0;
border-style: solid;
position: absolute;
margin: 5px;
border-color: #34495e;
}
}
}


5 changes: 5 additions & 0 deletions widgets/calendar/assets/packages/vendor/popper.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions widgets/calendar/assets/packages/vendor/tooltip.min.js

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

0 comments on commit 57e2638

Please sign in to comment.