Skip to content

Commit

Permalink
Optimize basic attendees and free/busy view.
Browse files Browse the repository at this point in the history
- Fix date navigation.
- Align all free/busy rows.
- Display user attendees' free/busy times.
- Treat the current user as an user attendee.
  • Loading branch information
yunosh committed Jul 15, 2016
1 parent 7abb4af commit ef27bdc
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 65 deletions.
79 changes: 51 additions & 28 deletions kronolith/attendees.php
Expand Up @@ -22,6 +22,36 @@
$resources = $session->get('kronolith', 'resources', Horde_Session::TYPE_ARRAY);
$editAttendee = null;

// Get the current Free/Busy view; default to the 'day' view if none specified.
$view = Horde_Util::getFormData('view', 'Day');

// Get the date information.
$start = new Horde_Date(
Horde_Util::getFormData('startdate'), date_default_timezone_get()
);
switch ($view) {
case 'Day':
$end = clone $start;
$end->mday++;
break;
case 'Workweek':
case 'Week':
$diff = $start->dayOfWeek()
- ($view == 'Workweek' ? 1 : $prefs->getValue('week_start_monday'));
if ($diff < 0) {
$diff += 7;
}
$start->mday -= $diff;
$end = clone $start;
$end->mday += $view == 'Workweek' ? 5 : 7;
break;
case 'Month':
$start->mday = 1;
$end = clone $start;
$end->month++;
break;
}

// Get the action ID and value. This specifies what action the user initiated.
$actionID = Horde_Util::getFormData('actionID');
if (Horde_Util::getFormData('clearAll')) {
Expand Down Expand Up @@ -61,8 +91,8 @@
/* Do our best to see what the response will be. Note that this
* response is only guarenteed once the event is saved. */
$event = Kronolith::getDriver()->getEvent();
$event->start = new Horde_Date(Horde_Util::getFormData('startdate'));
$event->end = new Horde_Date(Horde_Util::getFormData('enddate'));
$event->start = $start;
$event->end = $end;
$event->start->setTimezone(date_default_timezone_get());
$event->end->setTimezone(date_default_timezone_get());
$response = $resource->getResponse($event);
Expand Down Expand Up @@ -153,9 +183,8 @@
if (!empty($url)) {
$url = new Horde_Url($url, true);
} else {
$date = new Horde_Date(Horde_Util::getFormData('startdate'));
$url = Horde::url($prefs->getValue('defaultview') . '.php', true)
->add('date', $date->dateString());
->add('date', $start->dateString());
}

// Make sure URL is unique.
Expand All @@ -168,48 +197,38 @@
break;
}

// Get the current Free/Busy view; default to the 'day' view if none specified.
$view = Horde_Util::getFormData('view', 'Day');

// Pre-format our delete image/link.
$delimg = Horde::img('delete.png', _("Remove Attendee"));

$ident = $injector->getInstance('Horde_Core_Factory_Identity')->create();
$identities = $ident->getAll('id');

$fbView = Kronolith_FreeBusy_View::singleton($view);
$fbOpts = array('start' => $start->datestamp(), 'end' => $end->datestamp());

// Add the creator as a required attendee in the Free/Busy display
$cal = @unserialize($prefs->getValue('fb_cals'));
if (!is_array($cal)) {
$cal = null;
}

// If the free/busy calendars preference is empty, default to the user's
// default_share preference, and if that's empty, to their username.
if (!$cal) {
$cal = 'internal_' . $prefs->getValue('default_share');
if (!$cal) {
$cal = 'internal_' . $GLOBALS['registry']->getAuth();
}
$cal = array($cal);
}
try {
$vfb = Kronolith_FreeBusy::generate($cal, null, null, true, $GLOBALS['registry']->getAuth());
$vfb = Kronolith_FreeBusy::getForUser(
$GLOBALS['registry']->getAuth(), $fbOpts
);
$fbView->addRequiredMember($vfb);
} catch (Exception $e) {
$notification->push(sprintf(_("Error retrieving your free/busy information: %s"), $e->getMessage()));
}

// Add the Free/Busy information for each attendee.
foreach ($session->get('kronolith', 'attendees') as $attendee) {
if (is_null($attendee->addressObject->host) ||
($attendee->role != Kronolith::PART_REQUIRED &&
$attendee->role != Kronolith::PART_OPTIONAL)) {
if ($attendee->role != Kronolith::PART_REQUIRED &&
$attendee->role != Kronolith::PART_OPTIONAL) {
continue;
}
try {
$vfb = Kronolith_FreeBusy::get($attendee->email);
if ($attendee->user) {
$vfb = Kronolith_Freebusy::getForUser($attendee->user, $fbOpts);
} elseif (is_null($attendee->addressObject->host)) {
$vfb = new Horde_Icalendar_Vfreebusy();
} else {
$vfb = Kronolith_FreeBusy::get($attendee->email);
}
} catch (Exception $e) {
$notification->push(
sprintf(
Expand Down Expand Up @@ -268,7 +287,11 @@

$title = _("Edit attendees");

$attendeesView = new Kronolith_View_Attendees(array('fbView' => $fbView));
$attendeesView = new Kronolith_View_Attendees(array(
'fbView' => $fbView,
'start' => $start,
'end' => $end,
));
$attendeesView->assign(compact('editAttendee', 'title'));

$injector->getInstance('Horde_Core_Factory_Imple')->create('Kronolith_Ajax_Imple_ContactAutoCompleter', array(
Expand Down
3 changes: 1 addition & 2 deletions kronolith/js/edit.js
Expand Up @@ -76,8 +76,7 @@ var KronolithEdit =
case 'attendees_button':
HordePopup.popup({
params: {
startdate: (('000' + $F('start_year')).slice(-4) + ('0' + $F('start_month')).slice(-2) + ('0' + $F('start_day')).slice(-2) + ('0' + $F('start_hour')).slice(-2) + ('0' + $F('start_min')).slice(-2) + '00'),
enddate: (('000' + $F('end_year')).slice(-4) + ('0' + $F('end_month')).slice(-2) + ('0' + $F('end_day')).slice(-2) + ('0' + $F('end_hour')).slice(-2) + ('0' + $F('end_min')).slice(-2) + '00')
startdate: (('000' + $F('start_year')).slice(-4) + ('0' + $F('start_month')).slice(-2) + ('0' + $F('start_day')).slice(-2)),
},
url: elt.readAttribute('href')
});
Expand Down
24 changes: 7 additions & 17 deletions kronolith/lib/FreeBusy/View.php
Expand Up @@ -111,8 +111,7 @@ public function render(Horde_Date $day = null)
$template = $GLOBALS['injector']->createInstance('Horde_Template');
$template->set('title', $this->_title());

$html = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/header.html') .
'<div class="fbgrid">';
$html = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/header.html');

$hours_html = $this->_hours();

Expand All @@ -138,7 +137,6 @@ public function render(Horde_Date $day = null)
$template->set('rows', $rows);
$template->set('span', count($this->_timeBlocks));
$template->set('hours', $hours_html);
$template->set('legend', '');
$html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');
}

Expand All @@ -159,7 +157,6 @@ public function render(Horde_Date $day = null)
$template->set('rows', $rows);
$template->set('span', count($this->_timeBlocks));
$template->set('hours', $hours_html);
$template->set('legend', '');
$html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');
}

Expand Down Expand Up @@ -188,7 +185,6 @@ public function render(Horde_Date $day = null)
$template->set('rows', $rows);
$template->set('span', count($this->_timeBlocks));
$template->set('hours', $hours_html);
$template->set('legend', '');
$html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');
}

Expand All @@ -214,17 +210,6 @@ public function render(Horde_Date $day = null)
$template->set('blocks', $blocks);
$rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');

// Possible meeting times.
// $resource->setAttribute('ORGANIZER', _("Required Attendees"));
// $blocks = $this->_getBlocks($required,
// $required->getFreePeriods($this->_start->timestamp(), $this->_end->timestamp()),
// 'meetingblock.html', _("Required Attendees"));
//
// $template = $GLOBALS['injector']->createInstance('Horde_Template');
// $template->set('name', _("Required Attendees"));
// $template->set('blocks', $blocks);
// $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');

// Reset locale.
setlocale(LC_NUMERIC, $lc);

Expand All @@ -233,14 +218,19 @@ public function render(Horde_Date $day = null)
$template->set('title', _("Overview"));
$template->set('span', count($this->_timeBlocks));
$template->set('hours', $hours_html);
$html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');

$template = $GLOBALS['injector']->createInstance('Horde_Template');
if ($prefs->getValue('show_fb_legend')) {
$template->setOption('gettext', true);
$template->set('span', count($this->_timeBlocks));
$template->set('legend', $template->fetch(KRONOLITH_TEMPLATES . '/fbview/legend.html'));
} else {
$template->set('legend', '');
}
$html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/footer.html');

return $html . $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html') . '</div>';
return $html;
}

/**
Expand Down
14 changes: 9 additions & 5 deletions kronolith/lib/FreeBusy/View/Week.php
Expand Up @@ -71,13 +71,18 @@ protected function _hours()
$width = round(100 / ($span * $this->_days));
for ($i = 0; $i < $this->_days; $i++) {
for ($h = $this->_startHour; $h < $this->_endHour; $h += 3) {
$start = new Horde_Date(array('hour' => $h,
'month' => $this->_start->month,
'mday' => $this->_start->mday + $i,
'year' => $this->_start->year));
$start = new Horde_Date(array(
'hour' => $h,
'month' => $this->_start->month,
'mday' => $this->_start->mday + $i,
'year' => $this->_start->year,
));
$end = new Horde_Date($start);
$end->hour += 2;
$end->min = 59;
if ($end->mday != $start->mday) {
$end->hour = $end->min = 0;
}
$this->_timeBlocks[] = array($start, $end);

$hour = $start->strftime($prefs->getValue('twentyFour') ? '%H:00' : '%I:00');
Expand All @@ -91,7 +96,6 @@ protected function _hours()
protected function _render(Horde_Date $day = null)
{
$this->_start = clone $day;
$this->_start->mday -= ($this->_start->format('w') + 6) % 7;
$this->_end = new Horde_Date($this->_start);
$this->_end->hour = 23;
$this->_end->min = $this->_end->sec = 59;
Expand Down
12 changes: 3 additions & 9 deletions kronolith/lib/View/Attendees.php
Expand Up @@ -36,15 +36,9 @@ public function __construct($config = array())

$this->formInput = Horde_Util::formInput();
$this->view = Horde_Util::getFormData('view', 'Day');
$date = new Horde_Date(
Horde_Util::getFormData('startdate', date('Ymd') . '000000')
);
$end = new Horde_Date(
Horde_Util::getFormData('enddate', date('Ymd') . '000000')
);
$this->date = $date->dateString() . $date->format('Hi00');
$this->end = $end->dateString() . $end->format('Hi00');
$this->freeBusy = $config['fbView']->render($date);
$this->date = $config['start']->dateString();
$this->end = $config['end']->dateString();
$this->freeBusy = $config['fbView']->render($config['start']);
$auth = $injector->getInstance('Horde_Core_Factory_Auth')->create();
if ($auth->hasCapability('list') &&
($conf['auth']['list_users'] == 'list' ||
Expand Down
2 changes: 2 additions & 0 deletions kronolith/templates/attendees/attendees.html.php
Expand Up @@ -9,6 +9,7 @@ function performAction(id, value)

function switchDate(date)
{
document.attendeesForm.enddate.value = document.attendeesForm.enddate.value - document.attendeesForm.startdate.value + date;
document.attendeesForm.startdate.value = date;
document.attendeesForm.submit();
return false;
Expand All @@ -24,6 +25,7 @@ function switchView(view)
function switchDateView(view, date)
{
document.attendeesForm.view.value = view;
document.attendeesForm.enddate.value = document.attendeesForm.enddate.value - document.attendeesForm.startdate.value + date;
document.attendeesForm.startdate.value = date;
document.attendeesForm.submit();
return false;
Expand Down
3 changes: 3 additions & 0 deletions kronolith/templates/fbview/header.html
@@ -1,3 +1,6 @@
<div class="header" style="text-align:center">
<tag:title />
</div>
<br />
<div class="fbgrid">
<table class="nowrap" cellspacing="0" width="100%">
4 changes: 0 additions & 4 deletions kronolith/templates/fbview/section.html
@@ -1,5 +1,3 @@
<br />
<table class="nowrap" cellspacing="0" width="100%">
<tr>
<td class="label">&nbsp;</td>
<td class="label" colspan="<tag:span />"><strong><tag:title /></strong></td>
Expand All @@ -9,5 +7,3 @@
<tag:hours />
</tr>
<tag:rows />
<tag:legend />
</table>

0 comments on commit ef27bdc

Please sign in to comment.