@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Adding a calendar preview panel to people profile

Summary: Ref T9606

Test Plan: Open people profile for a user with events today/tomorrow, see a panel under badges panel with event list

Reviewers: chad, epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Maniphest Tasks: T9606

Differential Revision: https://secure.phabricator.com/D15851

+195 -92
+2 -2
resources/celerity/map.php
··· 116 116 'rsrc/css/layout/phabricator-side-menu-view.css' => 'dd849797', 117 117 'rsrc/css/layout/phabricator-source-code-view.css' => 'cbeef983', 118 118 'rsrc/css/phui/calendar/phui-calendar-day.css' => 'd1cf6f93', 119 - 'rsrc/css/phui/calendar/phui-calendar-list.css' => 'c1c7f338', 119 + 'rsrc/css/phui/calendar/phui-calendar-list.css' => 'e0866209', 120 120 'rsrc/css/phui/calendar/phui-calendar-month.css' => '476be7e0', 121 121 'rsrc/css/phui/calendar/phui-calendar.css' => 'ccabe893', 122 122 'rsrc/css/phui/phui-action-list.css' => 'c5eba19d', ··· 822 822 'phui-button-css' => 'a64a8de6', 823 823 'phui-calendar-css' => 'ccabe893', 824 824 'phui-calendar-day-css' => 'd1cf6f93', 825 - 'phui-calendar-list-css' => 'c1c7f338', 825 + 'phui-calendar-list-css' => 'e0866209', 826 826 'phui-calendar-month-css' => '476be7e0', 827 827 'phui-chart-css' => '6bf6f78e', 828 828 'phui-crumbs-view-css' => '6b813619',
+2
src/__phutil_library_map__.php
··· 1569 1569 'PHUICalendarDayView' => 'view/phui/calendar/PHUICalendarDayView.php', 1570 1570 'PHUICalendarListView' => 'view/phui/calendar/PHUICalendarListView.php', 1571 1571 'PHUICalendarMonthView' => 'view/phui/calendar/PHUICalendarMonthView.php', 1572 + 'PHUICalendarWeekView' => 'view/phui/calendar/PHUICalendarWeekView.php', 1572 1573 'PHUICalendarWidgetView' => 'view/phui/calendar/PHUICalendarWidgetView.php', 1573 1574 'PHUIColorPalletteExample' => 'applications/uiexample/examples/PHUIColorPalletteExample.php', 1574 1575 'PHUICrumbView' => 'view/phui/PHUICrumbView.php', ··· 5974 5975 'PHUICalendarDayView' => 'AphrontView', 5975 5976 'PHUICalendarListView' => 'AphrontTagView', 5976 5977 'PHUICalendarMonthView' => 'AphrontView', 5978 + 'PHUICalendarWeekView' => 'AphrontView', 5977 5979 'PHUICalendarWidgetView' => 'AphrontTagView', 5978 5980 'PHUIColorPalletteExample' => 'PhabricatorUIExample', 5979 5981 'PHUICrumbView' => 'AphrontView',
+65
src/applications/people/controller/PhabricatorPeopleProfileViewController.php
··· 59 59 60 60 $projects = $this->buildProjectsView($user); 61 61 $badges = $this->buildBadgesView($user); 62 + $calendar = $this->buildCalendarDayView($user); 62 63 require_celerity_resource('project-view-css'); 63 64 64 65 $home = id(new PHUITwoColumnView()) ··· 73 74 array( 74 75 $projects, 75 76 $badges, 77 + $calendar, 76 78 )); 77 79 78 80 $nav = $this->getProfileMenu(); ··· 167 169 $box = id(new PHUIObjectBoxView()) 168 170 ->setHeader($header) 169 171 ->appendChild($list) 172 + ->setBackground(PHUIObjectBoxView::GREY); 173 + 174 + return $box; 175 + } 176 + 177 + private function buildCalendarDayView(PhabricatorUser $user) { 178 + $viewer = $this->getViewer(); 179 + $class = 'PhabricatorCalendarApplication'; 180 + 181 + if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { 182 + return null; 183 + } 184 + 185 + $midnight = PhabricatorTime::getTodayMidnightDateTime($viewer); 186 + $week_end = clone $midnight; 187 + $week_end = $week_end->modify('+3 days'); 188 + 189 + $range_start = $midnight->format('U'); 190 + $range_end = $week_end->format('U'); 191 + 192 + $query = id(new PhabricatorCalendarEventQuery()) 193 + ->setViewer($viewer) 194 + ->withDateRange($range_start, $range_end) 195 + ->withInvitedPHIDs(array($viewer->getPHID())) 196 + ->withIsCancelled(false); 197 + 198 + $statuses = $query->execute(); 199 + $phids = mpull($statuses, 'getUserPHID'); 200 + $events = array(); 201 + 202 + foreach ($statuses as $status) { 203 + $viewer_is_invited = $status->getIsUserInvited($viewer->getPHID()); 204 + 205 + $can_edit = PhabricatorPolicyFilter::hasCapability( 206 + $viewer, 207 + $status, 208 + PhabricatorPolicyCapability::CAN_EDIT); 209 + 210 + $event = new AphrontCalendarEventView(); 211 + $event->setCanEdit($can_edit); 212 + $event->setEventID($status->getID()); 213 + $event->setEpochRange($status->getDateFrom(), $status->getDateTo()); 214 + $event->setIsAllDay($status->getIsAllDay()); 215 + $event->setIcon($status->getIcon()); 216 + $event->setViewerIsInvited($viewer_is_invited); 217 + 218 + $event->setName($status->getName()); 219 + $event->setURI($status->getURI()); 220 + $events[] = $event; 221 + } 222 + 223 + $events = msort($events, 'getEpochStart'); 224 + $day_view = id(new PHUICalendarWeekView()) 225 + ->setViewer($viewer) 226 + ->setEvents($events) 227 + ->setWeekLength(3) 228 + ->render(); 229 + 230 + $header = id(new PHUIHeaderView()) 231 + ->setHeader(pht('Calendar')); 232 + $box = id(new PHUIObjectBoxView()) 233 + ->setHeader($header) 234 + ->appendChild($day_view) 170 235 ->setBackground(PHUIObjectBoxView::GREY); 171 236 172 237 return $box;
+5 -86
src/view/phui/calendar/PHUICalendarDayView.php
··· 145 145 } 146 146 147 147 $header = $this->renderDayViewHeader(); 148 - $sidebar = $this->renderSidebar(); 148 + $sidebar = id(new PHUICalendarWeekView()) 149 + ->setViewer($this->getViewer()) 150 + ->setEvents($this->events) 151 + ->setDateTime($this->getDateTime()) 152 + ->render(); 149 153 $warnings = $this->getQueryRangeWarning(); 150 154 151 155 $table_id = celerity_generate_unique_node_id(); ··· 240 244 $errors[] = pht('Day is out of query range'); 241 245 } 242 246 return $errors; 243 - } 244 - 245 - private function renderSidebar() { 246 - $this->events = msort($this->events, 'getEpochStart'); 247 - $week_of_boxes = $this->getWeekOfBoxes(); 248 - $filled_boxes = array(); 249 - 250 - foreach ($week_of_boxes as $day_box) { 251 - $box_start = $day_box['start']; 252 - $box_end = id(clone $box_start)->modify('+1 day'); 253 - 254 - $box_start = $box_start->format('U'); 255 - $box_end = $box_end->format('U'); 256 - 257 - $box_events = array(); 258 - 259 - foreach ($this->events as $event) { 260 - $event_start = $event->getEpochStart(); 261 - $event_end = $event->getEpochEnd(); 262 - 263 - if ($event_start < $box_end && $event_end > $box_start) { 264 - $box_events[] = $event; 265 - } 266 - } 267 - 268 - $filled_boxes[] = $this->renderSidebarBox( 269 - $box_events, 270 - $day_box['title']); 271 - } 272 - 273 - return $filled_boxes; 274 - } 275 - 276 - private function renderSidebarBox($events, $title) { 277 - $widget = id(new PHUICalendarWidgetView()) 278 - ->addClass('calendar-day-view-sidebar'); 279 - 280 - $list = id(new PHUICalendarListView()) 281 - ->setUser($this->getViewer()) 282 - ->setView('day'); 283 - 284 - if (count($events) == 0) { 285 - $list->showBlankState(true); 286 - } else { 287 - $sorted_events = msort($events, 'getEpochStart'); 288 - foreach ($sorted_events as $event) { 289 - $list->addEvent($event); 290 - } 291 - } 292 - 293 - $widget 294 - ->setCalendarList($list) 295 - ->setHeader($title); 296 - return $widget; 297 - } 298 - 299 - private function getWeekOfBoxes() { 300 - $sidebar_day_boxes = array(); 301 - 302 - $display_start_day = $this->getDateTime(); 303 - $display_end_day = id(clone $display_start_day)->modify('+6 day'); 304 - 305 - $box_start_time = clone $display_start_day; 306 - 307 - $today_time = PhabricatorTime::getTodayMidnightDateTime($this->getViewer()); 308 - $tomorrow_time = clone $today_time; 309 - $tomorrow_time->modify('+1 day'); 310 - 311 - while ($box_start_time <= $display_end_day) { 312 - if ($box_start_time == $today_time) { 313 - $title = pht('Today'); 314 - } else if ($box_start_time == $tomorrow_time) { 315 - $title = pht('Tomorrow'); 316 - } else { 317 - $title = $box_start_time->format('l'); 318 - } 319 - 320 - $sidebar_day_boxes[] = array( 321 - 'title' => $title, 322 - 'start' => clone $box_start_time, 323 - ); 324 - 325 - $box_start_time->modify('+1 day'); 326 - } 327 - return $sidebar_day_boxes; 328 247 } 329 248 330 249 private function renderDayViewHeader() {
+121
src/view/phui/calendar/PHUICalendarWeekView.php
··· 1 + <?php 2 + 3 + final class PHUICalendarWeekView extends AphrontView { 4 + private $events; 5 + private $dateTime; 6 + private $weekLength = 7; 7 + 8 + public function setEvents($events) { 9 + $this->events = $events; 10 + return $this; 11 + } 12 + 13 + public function setDateTime($date_time) { 14 + $this->dateTime = $date_time; 15 + return $this; 16 + } 17 + 18 + private function getDateTime() { 19 + if ($this->dateTime) { 20 + return $this->dateTime; 21 + } 22 + return $this->getDefaultDateTime(); 23 + } 24 + 25 + public function setWeekLength($week_length) { 26 + $this->weekLength = $week_length; 27 + return $this; 28 + } 29 + 30 + public function render() { 31 + $this->events = msort($this->events, 'getEpochStart'); 32 + $week_of_boxes = $this->getWeekOfBoxes(); 33 + $filled_boxes = array(); 34 + 35 + foreach ($week_of_boxes as $day_box) { 36 + $box_start = $day_box['start']; 37 + $box_end = id(clone $box_start)->modify('+1 day'); 38 + 39 + $box_start = $box_start->format('U'); 40 + $box_end = $box_end->format('U'); 41 + 42 + $box_events = array(); 43 + 44 + foreach ($this->events as $event) { 45 + $event_start = $event->getEpochStart(); 46 + $event_end = $event->getEpochEnd(); 47 + 48 + if ($event_start < $box_end && $event_end > $box_start) { 49 + $box_events[] = $event; 50 + } 51 + } 52 + 53 + $filled_boxes[] = $this->renderSidebarBox( 54 + $box_events, 55 + $day_box['title']); 56 + } 57 + 58 + return $filled_boxes; 59 + } 60 + 61 + private function renderSidebarBox($events, $title) { 62 + $widget = id(new PHUICalendarWidgetView()) 63 + ->addClass('calendar-day-view-sidebar'); 64 + 65 + $list = id(new PHUICalendarListView()) 66 + ->setUser($this->getViewer()) 67 + ->setView('day'); 68 + 69 + if (count($events) == 0) { 70 + $list->showBlankState(true); 71 + } else { 72 + $sorted_events = msort($events, 'getEpochStart'); 73 + foreach ($sorted_events as $event) { 74 + $list->addEvent($event); 75 + } 76 + } 77 + 78 + $widget 79 + ->setCalendarList($list) 80 + ->setHeader($title); 81 + return $widget; 82 + } 83 + 84 + private function getWeekOfBoxes() { 85 + $day_boxes = array(); 86 + $week_length = $this->weekLength - 1; 87 + 88 + $display_start_day = $this->getDateTime(); 89 + $display_end_day = id(clone $display_start_day) 90 + ->modify('+'.$week_length.' day'); 91 + 92 + $box_start_time = clone $display_start_day; 93 + 94 + $today_time = PhabricatorTime::getTodayMidnightDateTime($this->getViewer()); 95 + $tomorrow_time = clone $today_time; 96 + $tomorrow_time->modify('+1 day'); 97 + 98 + while ($box_start_time <= $display_end_day) { 99 + if ($box_start_time == $today_time) { 100 + $title = pht('Today'); 101 + } else if ($box_start_time == $tomorrow_time) { 102 + $title = pht('Tomorrow'); 103 + } else { 104 + $title = $box_start_time->format('l'); 105 + } 106 + 107 + $day_boxes[] = array( 108 + 'title' => $title, 109 + 'start' => clone $box_start_time, 110 + ); 111 + 112 + $box_start_time->modify('+1 day'); 113 + } 114 + return $day_boxes; 115 + } 116 + 117 + private function getDefaultDateTime() { 118 + return PhabricatorTime::getTodayMidnightDateTime($this->getViewer()); 119 + } 120 + 121 + }
-4
webroot/rsrc/css/phui/calendar/phui-calendar-list.css
··· 2 2 * @provides phui-calendar-list-css 3 3 */ 4 4 5 - .phui-calendar-list-container { 6 - width: 300px; 7 - } 8 - 9 5 .device-phone .phui-calendar-list-container { 10 6 width: auto; 11 7 }