コード例 #1
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $pager = new AphrontIDPagerView();
     $pager->readFromRequest($request);
     $query = new PhabricatorPasteQuery();
     $query->setViewer($user);
     switch ($this->getFilter()) {
         case 'create':
         default:
             // if we successfully create a paste, we redirect to view it
             $created_paste_redirect = $this->processCreateRequest();
             if ($created_paste_redirect) {
                 return $created_paste_redirect;
             }
             $query->setLimit(10);
             $paste_list = $query->execute();
             $pager = null;
             break;
         case 'my':
             $query->withAuthorPHIDs(array($user->getPHID()));
             $paste_list = $query->executeWithPager($pager);
             break;
         case 'all':
             $paste_list = $query->executeWithPager($pager);
             break;
     }
     $filters = array('create' => array('name' => 'Create Paste'), 'my' => array('name' => 'My Pastes'), 'all' => array('name' => 'All Pastes'));
     $side_nav = new AphrontSideNavView();
     foreach ($filters as $filter_key => $filter) {
         $selected = $filter_key == $this->getFilter();
         $side_nav->addNavItem(phutil_render_tag('a', array('href' => '/paste/filter/' . $filter_key . '/', 'class' => $selected ? 'aphront-side-nav-selected' : null), $filter['name']));
     }
     if ($this->getErrorView()) {
         $side_nav->appendChild($this->getErrorView());
     }
     switch ($this->getFilter()) {
         case 'create':
         default:
             $side_nav->appendChild($this->renderCreatePaste());
             $see_all = phutil_render_tag('a', array('href' => '/paste/filter/all'), 'See all Pastes');
             $header = "Recent Pastes · {$see_all}";
             break;
         case 'my':
             $header = 'Your Pastes';
             break;
         case 'all':
             $header = 'All Pastes';
             break;
     }
     $side_nav->appendChild($this->renderPasteList($paste_list, $header, $pager));
     return $this->buildStandardPageResponse($side_nav, array('title' => 'Paste'));
 }
コード例 #2
0
 public final function executeWithPager(AphrontIDPagerView $pager)
 {
     $this->setLimit($pager->getPageSize() + 1);
     if ($pager->getAfterID()) {
         $this->setAfterID($pager->getAfterID());
     } else {
         if ($pager->getBeforeID()) {
             $this->setBeforeID($pager->getBeforeID());
         }
     }
     $results = $this->execute();
     $sliced_results = $pager->sliceResults($results);
     if ($this->beforeID || count($results) > $pager->getPageSize()) {
         $pager->setNextPageID($this->getPagingValue(last($sliced_results)));
     }
     if ($this->afterID || $this->beforeID && count($results) > $pager->getPageSize()) {
         $pager->setPrevPageID($this->getPagingValue(head($sliced_results)));
     }
     return $sliced_results;
 }
コード例 #3
0
 private function buildFeedView(array $phids)
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $user_phid = $user->getPHID();
     $feed_query = new PhabricatorFeedQuery();
     $feed_query->setViewer($user);
     if ($phids) {
         $feed_query->setFilterPHIDs($phids);
     }
     $pager = new AphrontIDPagerView();
     $pager->readFromRequest($request);
     $pager->setPageSize(200);
     $feed = $feed_query->executeWithPager($pager);
     $builder = new PhabricatorFeedBuilder($feed);
     $builder->setUser($user);
     $feed_view = $builder->buildView();
     return '<div style="padding: 1em 3em;">' . '<div style="margin: 0 1em;">' . '<h1 style="font-size: 18px; ' . 'border-bottom: 1px solid #aaaaaa; ' . 'padding: 0;">Feed</h1>' . '</div>' . $feed_view->render() . '<div class="phabricator-feed-frame">' . $pager->render() . '</div>' . '</div>';
 }
コード例 #4
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $uri = clone $request->getRequestURI();
     $uri->setQueryParams(array());
     $pager = new AphrontIDPagerView();
     $pager->setURI($uri);
     $pager->setPageSize(250);
     $query = id(new PhabricatorChatLogQuery())->setViewer($user)->withChannels(array($this->channel));
     list($after, $before, $map) = $this->getPagingParameters($request, $query);
     $pager->setAfterID($after);
     $pager->setBeforeID($before);
     $logs = $query->executeWithPager($pager);
     // Show chat logs oldest-first.
     $logs = array_reverse($logs);
     // Divide all the logs into blocks, where a block is the same author saying
     // several things in a row. A block ends when another user speaks, or when
     // two minutes pass without the author speaking.
     $blocks = array();
     $block = null;
     $last_author = null;
     $last_epoch = null;
     foreach ($logs as $log) {
         $this_author = $log->getAuthor();
         $this_epoch = $log->getEpoch();
         // Decide whether we should start a new block or not.
         $new_block = $this_author !== $last_author || $this_epoch - 60 * 2 > $last_epoch;
         if ($new_block) {
             if ($block) {
                 $blocks[] = $block;
             }
             $block = array('id' => $log->getID(), 'epoch' => $this_epoch, 'author' => $this_author, 'logs' => array($log));
         } else {
             $block['logs'][] = $log;
         }
         $last_author = $this_author;
         $last_epoch = $this_epoch;
     }
     if ($block) {
         $blocks[] = $block;
     }
     // Figure out CSS classes for the blocks. We alternate colors between
     // lines, and highlight the entire block which contains the target ID or
     // date, if applicable.
     foreach ($blocks as $key => $block) {
         $classes = array();
         if ($key % 2) {
             $classes[] = 'alternate';
         }
         $ids = mpull($block['logs'], 'getID', 'getID');
         if (array_intersect_key($ids, $map)) {
             $classes[] = 'highlight';
         }
         $blocks[$key]['class'] = $classes ? implode(' ', $classes) : null;
     }
     require_celerity_resource('phabricator-chatlog-css');
     $out = array();
     $out[] = '<table class="phabricator-chat-log">';
     foreach ($blocks as $block) {
         $author = $block['author'];
         $author = phutil_utf8_shorten($author, 18);
         $author = phutil_escape_html($author);
         $author = phutil_render_tag('td', array('class' => 'author'), $author);
         $message = mpull($block['logs'], 'getMessage');
         $message = implode("\n", $message);
         $message = phutil_escape_html($message);
         $message = phutil_render_tag('td', array('class' => 'message'), $message);
         $href = $uri->alter('at', $block['id']);
         $timestamp = $block['epoch'];
         $timestamp = phabricator_datetime($timestamp, $user);
         $timestamp = phutil_render_tag('a', array('href' => $href), $timestamp);
         $timestamp = phutil_render_tag('td', array('class' => 'timestamp'), $timestamp);
         $out[] = phutil_render_tag('tr', array('class' => $block['class']), $author . $message . $timestamp);
     }
     $out[] = '</table>';
     $form = id(new AphrontFormView())->setUser($user)->setMethod('GET')->setAction($uri)->appendChild(id(new AphrontFormTextControl())->setLabel('Date')->setName('date')->setValue($request->getStr('date')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Jump'));
     return $this->buildStandardPageResponse(array('<div class="phabricator-chat-log-panel">', $form, '<br />', implode("\n", $out), $pager, '</div>'), array('title' => 'Channel Log'));
 }