2013-02-15 23:01:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group conpherence
|
|
|
|
*/
|
|
|
|
final class ConpherenceWidgetController extends
|
|
|
|
ConpherenceController {
|
|
|
|
|
|
|
|
private $conpherenceID;
|
|
|
|
private $conpherence;
|
2013-03-26 21:30:35 +01:00
|
|
|
private $userPreferences;
|
|
|
|
|
|
|
|
public function setUserPreferences(PhabricatorUserPreferences $pref) {
|
|
|
|
$this->userPreferences = $pref;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getUserPreferences() {
|
|
|
|
return $this->userPreferences;
|
|
|
|
}
|
2013-02-15 23:01:27 +01:00
|
|
|
|
|
|
|
public function setConpherence(ConpherenceThread $conpherence) {
|
|
|
|
$this->conpherence = $conpherence;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getConpherence() {
|
|
|
|
return $this->conpherence;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setConpherenceID($conpherence_id) {
|
|
|
|
$this->conpherenceID = $conpherence_id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getConpherenceID() {
|
|
|
|
return $this->conpherenceID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->setConpherenceID(idx($data, 'id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$conpherence_id = $this->getConpherenceID();
|
|
|
|
if (!$conpherence_id) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
$conpherence = id(new ConpherenceThreadQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($conpherence_id))
|
|
|
|
->needWidgetData(true)
|
|
|
|
->executeOne();
|
|
|
|
$this->setConpherence($conpherence);
|
|
|
|
|
2013-03-26 21:30:35 +01:00
|
|
|
$this->setUserPreferences($user->loadPreferences());
|
|
|
|
|
2013-02-15 23:01:27 +01:00
|
|
|
$widgets = $this->renderWidgetPaneContent();
|
|
|
|
$content = $widgets;
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($content);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderWidgetPaneContent() {
|
|
|
|
require_celerity_resource('conpherence-widget-pane-css');
|
2013-03-13 21:03:51 +01:00
|
|
|
require_celerity_resource('sprite-conpherence-css');
|
2013-02-15 23:01:27 +01:00
|
|
|
$conpherence = $this->getConpherence();
|
|
|
|
|
2013-04-02 18:32:40 +02:00
|
|
|
$widgets = array();
|
|
|
|
$widgets[] = phutil_tag(
|
2013-02-15 23:01:27 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'widgets-header'
|
|
|
|
),
|
2013-03-16 07:41:36 +01:00
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'widgets-header-icon-holder'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'sigil' => 'conpherence-change-widget',
|
|
|
|
'meta' => array(
|
2013-04-16 01:27:41 +02:00
|
|
|
'widget' => 'conpherence-menu-pane',
|
2013-03-16 07:41:36 +01:00
|
|
|
),
|
2013-04-16 01:27:41 +02:00
|
|
|
'id' => 'conpherence-menu-pane-toggle',
|
2013-03-16 07:41:36 +01:00
|
|
|
'class' => 'sprite-conpherence conpherence_list_off',
|
2013-02-15 23:01:27 +01:00
|
|
|
),
|
2013-03-16 07:41:36 +01:00
|
|
|
''),
|
|
|
|
javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'sigil' => 'conpherence-change-widget',
|
|
|
|
'meta' => array(
|
2013-04-16 01:27:41 +02:00
|
|
|
'widget' => 'conpherence-message-pane',
|
2013-03-16 07:41:36 +01:00
|
|
|
),
|
2013-04-16 01:27:41 +02:00
|
|
|
'id' => 'conpherence-message-pane-toggle',
|
2013-03-16 07:41:36 +01:00
|
|
|
'class' => 'sprite-conpherence conpherence_conversation_off',
|
2013-03-13 21:03:51 +01:00
|
|
|
),
|
2013-03-16 07:41:36 +01:00
|
|
|
''),
|
|
|
|
javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'sigil' => 'conpherence-change-widget',
|
|
|
|
'meta' => array(
|
|
|
|
'widget' => 'widgets-people',
|
|
|
|
),
|
|
|
|
'id' => 'widgets-people-toggle',
|
2013-05-23 01:05:47 +02:00
|
|
|
'class' =>
|
|
|
|
'sprite-conpherence conpherence_people_on conpherence_people_off'
|
2013-03-13 21:03:51 +01:00
|
|
|
),
|
2013-03-16 07:41:36 +01:00
|
|
|
''),
|
|
|
|
javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'sigil' => 'conpherence-change-widget',
|
|
|
|
'meta' => array(
|
|
|
|
'widget' => 'widgets-files',
|
|
|
|
),
|
|
|
|
'id' => 'widgets-files-toggle',
|
|
|
|
'class' =>
|
2013-05-23 01:05:47 +02:00
|
|
|
'sprite-conpherence conpherence_files_off'
|
2013-02-15 23:01:27 +01:00
|
|
|
),
|
2013-03-16 07:41:36 +01:00
|
|
|
''),
|
|
|
|
javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'sigil' => 'conpherence-change-widget',
|
|
|
|
'meta' => array(
|
|
|
|
'widget' => 'widgets-calendar',
|
|
|
|
),
|
|
|
|
'id' => 'widgets-calendar-toggle',
|
|
|
|
'class' => 'sprite-conpherence conpherence_calendar_off',
|
2013-02-15 23:01:27 +01:00
|
|
|
),
|
2013-03-16 07:41:36 +01:00
|
|
|
''),
|
|
|
|
javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'sigil' => 'conpherence-change-widget',
|
|
|
|
'meta' => array(
|
|
|
|
'widget' => 'widgets-settings',
|
|
|
|
),
|
|
|
|
'id' => 'widgets-settings-toggle',
|
|
|
|
'class' => 'sprite-conpherence conpherence_settings_off',
|
2013-03-13 21:03:51 +01:00
|
|
|
),
|
2013-03-16 07:41:36 +01:00
|
|
|
'')
|
2013-04-02 18:32:40 +02:00
|
|
|
)));
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
// now the widget bodies
|
2013-04-08 20:13:35 +02:00
|
|
|
$widgets[] = javelin_tag(
|
2013-03-16 07:41:36 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'widgets-body',
|
|
|
|
'id' => 'widgets-people',
|
2013-04-08 20:13:35 +02:00
|
|
|
'sigil' => 'widgets-people',
|
2013-03-16 07:41:36 +01:00
|
|
|
),
|
2013-04-02 18:32:40 +02:00
|
|
|
id(new ConpherencePeopleWidgetView())
|
|
|
|
->setUser($user)
|
|
|
|
->setConpherence($conpherence)
|
|
|
|
->setUpdateURI($this->getWidgetURI()));
|
2013-04-08 20:13:35 +02:00
|
|
|
$widgets[] = javelin_tag(
|
2013-04-02 18:32:40 +02:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'widgets-body',
|
|
|
|
'id' => 'widgets-files',
|
2013-04-08 20:13:35 +02:00
|
|
|
'sigil' => 'widgets-files',
|
2013-05-23 01:05:47 +02:00
|
|
|
'style' => 'display: none;'
|
2013-04-02 18:32:40 +02:00
|
|
|
),
|
|
|
|
id(new ConpherenceFileWidgetView())
|
|
|
|
->setUser($user)
|
|
|
|
->setConpherence($conpherence)
|
|
|
|
->setUpdateURI($this->getWidgetURI()));
|
|
|
|
$widgets[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'widgets-body',
|
|
|
|
'id' => 'widgets-calendar',
|
|
|
|
'style' => 'display: none;'
|
|
|
|
),
|
|
|
|
$this->renderCalendarWidgetPaneContent());
|
|
|
|
$widgets[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'widgets-body',
|
|
|
|
'id' => 'widgets-settings',
|
|
|
|
'style' => 'display: none'
|
|
|
|
),
|
|
|
|
$this->renderSettingsWidgetPaneContent());
|
2013-02-15 23:01:27 +01:00
|
|
|
|
2013-04-02 18:32:40 +02:00
|
|
|
// without this implosion we get "," between each element in our widgets
|
|
|
|
// array
|
|
|
|
return array('widgets' => phutil_implode_html('', $widgets));
|
2013-03-13 21:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderSettingsWidgetPaneContent() {
|
2013-03-26 21:30:35 +01:00
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
$conpherence = $this->getConpherence();
|
|
|
|
$participants = $conpherence->getParticipants();
|
|
|
|
$participant = $participants[$user->getPHID()];
|
|
|
|
$default = ConpherenceSettings::EMAIL_ALWAYS;
|
|
|
|
$preference = $this->getUserPreferences();
|
|
|
|
if ($preference) {
|
|
|
|
$default = $preference->getPreference(
|
|
|
|
PhabricatorUserPreferences::PREFERENCE_CONPH_NOTIFICATIONS,
|
|
|
|
ConpherenceSettings::EMAIL_ALWAYS);
|
|
|
|
}
|
|
|
|
$settings = $participant->getSettings();
|
|
|
|
$notifications = idx(
|
|
|
|
$settings,
|
|
|
|
'notifications',
|
|
|
|
$default);
|
|
|
|
$options = id(new AphrontFormRadioButtonControl())
|
|
|
|
->addButton(
|
|
|
|
ConpherenceSettings::EMAIL_ALWAYS,
|
|
|
|
ConpherenceSettings::getHumanString(
|
|
|
|
ConpherenceSettings::EMAIL_ALWAYS),
|
|
|
|
'')
|
|
|
|
->addButton(
|
|
|
|
ConpherenceSettings::NOTIFICATIONS_ONLY,
|
|
|
|
ConpherenceSettings::getHumanString(
|
|
|
|
ConpherenceSettings::NOTIFICATIONS_ONLY),
|
|
|
|
'')
|
|
|
|
->setName('notifications')
|
|
|
|
->setValue($notifications);
|
|
|
|
|
|
|
|
$layout = array(
|
|
|
|
$options,
|
|
|
|
phutil_tag(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'action',
|
|
|
|
'value' => 'notifications'
|
|
|
|
)),
|
2013-04-08 20:13:35 +02:00
|
|
|
phutil_tag(
|
2013-03-26 21:30:35 +01:00
|
|
|
'button',
|
|
|
|
array(
|
2013-04-08 20:13:35 +02:00
|
|
|
'type' => 'submit',
|
2013-03-26 21:30:35 +01:00
|
|
|
'class' => 'notifications-update grey',
|
|
|
|
),
|
|
|
|
pht('Update Notifications'))
|
|
|
|
);
|
|
|
|
|
|
|
|
return phabricator_form(
|
|
|
|
$user,
|
|
|
|
array(
|
|
|
|
'method' => 'POST',
|
2013-04-02 18:32:40 +02:00
|
|
|
'action' => $this->getWidgetURI(),
|
2013-04-08 20:13:35 +02:00
|
|
|
'sigil' => 'notifications-update',
|
2013-03-26 21:30:35 +01:00
|
|
|
),
|
|
|
|
$layout);
|
2013-02-15 23:01:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderCalendarWidgetPaneContent() {
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$conpherence = $this->getConpherence();
|
2013-04-04 02:30:20 +02:00
|
|
|
$participants = $conpherence->getParticipants();
|
2013-02-15 23:01:27 +01:00
|
|
|
$widget_data = $conpherence->getWidgetData();
|
|
|
|
$statuses = $widget_data['statuses'];
|
|
|
|
$handles = $conpherence->getHandles();
|
|
|
|
$content = array();
|
2013-04-04 02:30:20 +02:00
|
|
|
$layout = id(new AphrontMultiColumnView())
|
|
|
|
->setFluidLayout(true);
|
2013-02-15 23:01:27 +01:00
|
|
|
$timestamps = $this->getCalendarWidgetWeekTimestamps();
|
2013-04-04 02:30:20 +02:00
|
|
|
$today = $timestamps['today'];
|
|
|
|
$weekstamps = $timestamps['weekstamps'];
|
2013-02-15 23:01:27 +01:00
|
|
|
$one_day = 24 * 60 * 60;
|
2013-04-04 02:30:20 +02:00
|
|
|
foreach ($weekstamps as $time => $day) {
|
2013-02-15 23:01:27 +01:00
|
|
|
// build a header for the new day
|
2013-04-04 02:30:20 +02:00
|
|
|
$content[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'day-header'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'day-name'
|
|
|
|
),
|
|
|
|
$day->format('l')),
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'day-date'
|
|
|
|
),
|
|
|
|
$day->format('m/d/y'))
|
|
|
|
));
|
|
|
|
|
|
|
|
$week_day_number = $day->format('w');
|
|
|
|
|
2013-02-15 23:01:27 +01:00
|
|
|
|
|
|
|
$day->setTime(0, 0, 0);
|
|
|
|
$epoch_start = $day->format('U');
|
2013-04-04 02:30:20 +02:00
|
|
|
$next_day = clone $day;
|
|
|
|
$next_day->modify('+1 day');
|
|
|
|
$epoch_end = $next_day->format('U');
|
2013-02-15 23:01:27 +01:00
|
|
|
|
2013-04-04 02:30:20 +02:00
|
|
|
$first_status_of_the_day = true;
|
|
|
|
$statuses_of_the_day = array();
|
2013-02-15 23:01:27 +01:00
|
|
|
// keep looking through statuses where we last left off
|
|
|
|
foreach ($statuses as $status) {
|
|
|
|
if ($status->getDateFrom() >= $epoch_end) {
|
|
|
|
// This list is sorted, so we can stop looking.
|
|
|
|
break;
|
|
|
|
}
|
2013-04-16 01:27:41 +02:00
|
|
|
|
2013-02-15 23:01:27 +01:00
|
|
|
if ($status->getDateFrom() < $epoch_end &&
|
2013-04-04 02:30:20 +02:00
|
|
|
$status->getDateTo() > $epoch_start) {
|
2013-04-16 01:27:41 +02:00
|
|
|
if (!$first_status_of_the_day) {
|
|
|
|
$content[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'divider'
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
2013-04-04 02:30:20 +02:00
|
|
|
$statuses_of_the_day[$status->getUserPHID()] = $status;
|
|
|
|
$timespan = $status->getDateTo() - $status->getDateFrom();
|
|
|
|
if ($timespan > $one_day) {
|
|
|
|
$time_str = 'm/d';
|
|
|
|
} else {
|
|
|
|
$time_str = 'h:i A';
|
|
|
|
}
|
|
|
|
$epoch_range = phabricator_format_local_time(
|
|
|
|
$status->getDateFrom(),
|
|
|
|
$user,
|
|
|
|
$time_str) . ' - ' . phabricator_format_local_time(
|
|
|
|
$status->getDateTo(),
|
2013-03-16 07:41:36 +01:00
|
|
|
$user,
|
2013-04-04 02:30:20 +02:00
|
|
|
$time_str);
|
2013-02-15 23:01:27 +01:00
|
|
|
|
2013-04-04 02:30:20 +02:00
|
|
|
$content[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'user-status '.$status->getTextStatus(),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'epoch-range'
|
|
|
|
),
|
|
|
|
$epoch_range),
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'icon',
|
|
|
|
),
|
|
|
|
''),
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'description'
|
|
|
|
),
|
|
|
|
$status->getTerseSummary($user)),
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'participant'
|
|
|
|
),
|
|
|
|
$handles[$status->getUserPHID()]->getName())
|
|
|
|
));
|
|
|
|
$first_status_of_the_day = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// we didn't get a status on this day so add a spacer
|
|
|
|
if ($first_status_of_the_day) {
|
|
|
|
$content[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'spacer'
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
|
|
|
if ($week_day_number > 0 && $week_day_number < 6) {
|
|
|
|
if ($week_day_number == $today->format('w')) {
|
|
|
|
$active_class = '-active';
|
|
|
|
} else {
|
|
|
|
$active_class = '';
|
|
|
|
}
|
|
|
|
$inner_layout = array();
|
|
|
|
foreach ($participants as $phid => $participant) {
|
|
|
|
$status = idx($statuses_of_the_day, $phid, false);
|
|
|
|
if ($status) {
|
|
|
|
$inner_layout[] = phutil_tag(
|
2013-03-16 07:41:36 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2013-04-04 02:30:20 +02:00
|
|
|
'class' => $status->getTextStatus()
|
2013-03-16 07:41:36 +01:00
|
|
|
),
|
2013-04-04 02:30:20 +02:00
|
|
|
'');
|
|
|
|
} else {
|
|
|
|
$inner_layout[] = phutil_tag(
|
|
|
|
'div',
|
2013-03-16 07:41:36 +01:00
|
|
|
array(
|
2013-04-04 02:30:20 +02:00
|
|
|
'class' => 'present'
|
|
|
|
),
|
|
|
|
'');
|
2013-03-16 07:41:36 +01:00
|
|
|
}
|
2013-04-04 02:30:20 +02:00
|
|
|
}
|
|
|
|
$layout->addColumn(
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'day-column'.$active_class
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'day-name'
|
|
|
|
),
|
|
|
|
$day->format('D')),
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'day-number',
|
|
|
|
),
|
|
|
|
$day->format('j')),
|
|
|
|
$inner_layout
|
|
|
|
)));
|
2013-02-15 23:01:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 02:30:20 +02:00
|
|
|
return
|
|
|
|
array(
|
|
|
|
$layout,
|
|
|
|
$content
|
|
|
|
);
|
2013-02-15 23:01:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getCalendarWidgetWeekTimestamps() {
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
|
|
|
|
2013-04-04 02:30:20 +02:00
|
|
|
$today = id(new DateTime('now', $timezone));
|
|
|
|
$monday = clone $today;
|
|
|
|
$monday
|
|
|
|
->modify('+1 day')
|
|
|
|
->modify('last monday');
|
2013-02-15 23:01:27 +01:00
|
|
|
$timestamps = array();
|
|
|
|
for ($day = 0; $day < 7; $day++) {
|
2013-04-04 02:30:20 +02:00
|
|
|
$timestamp = clone $monday;
|
|
|
|
$timestamps[] = $timestamp->modify(sprintf('+%d days', $day));
|
2013-02-15 23:01:27 +01:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:30:20 +02:00
|
|
|
return array(
|
|
|
|
'today' => $today,
|
|
|
|
'weekstamps' => $timestamps
|
|
|
|
);
|
2013-02-15 23:01:27 +01:00
|
|
|
}
|
|
|
|
|
2013-04-02 18:32:40 +02:00
|
|
|
private function getWidgetURI() {
|
|
|
|
$conpherence = $this->getConpherence();
|
|
|
|
return $this->getApplicationURI('update/'.$conpherence->getID().'/');
|
|
|
|
}
|
|
|
|
|
2013-02-15 23:01:27 +01:00
|
|
|
}
|