public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); $query = id(new PhluxVariableQuery())->setViewer($viewer); $vars = $query->executeWithCursorPager($pager); $view = new PHUIObjectItemListView(); $view->setFlush(true); foreach ($vars as $var) { $key = $var->getVariableKey(); $item = new PHUIObjectItemView(); $item->setHeader($key); $item->setHref($this->getApplicationURI('/view/' . $key . '/')); $item->addIcon('none', phabricator_datetime($var->getDateModified(), $viewer)); $view->addItem($item); } $crumbs = $this->buildApplicationCrumbs(); $box = id(new PHUIObjectBoxView())->setHeaderText('Variables')->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->appendChild($view); $title = pht('Variable List'); $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-copy'); $crumbs->addTextCrumb($title, $this->getApplicationURI()); $crumbs->setBorder(true); $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($box, $pager)); return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $query = new PhabricatorPasteQuery(); $query->setViewer($user); $nav = $this->buildSideNavView(); $filter = $nav->selectFilter($this->filter, 'my'); switch ($filter) { case 'my': $query->withAuthorPHIDs(array($user->getPHID())); $title = pht('My Pastes'); $nodata = pht("You haven't created any Pastes yet."); break; case 'all': $title = pht('All Pastes'); $nodata = pht("There are no Pastes yet."); break; } $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); $pastes = $query->executeWithCursorPager($pager); $list = $this->buildPasteList($pastes); $list->setHeader($title); $list->setPager($pager); $list->setNoDataString($nodata); $nav->appendChild($list); return $this->buildApplicationPage($nav, array('title' => $title, 'device' => true)); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $conn_table = new PhabricatorConduitConnectionLog(); $call_table = new PhabricatorConduitMethodCallLog(); $conn_r = $call_table->establishConnection('r'); $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); $pager->setPageSize(500); $query = id(new PhabricatorConduitLogQuery())->setViewer($viewer); $methods = $request->getStrList('methods'); if ($methods) { $query->withMethods($methods); } $calls = $query->executeWithCursorPager($pager); $conn_ids = array_filter(mpull($calls, 'getConnectionID')); $conns = array(); if ($conn_ids) { $conns = $conn_table->loadAllWhere('id IN (%Ld)', $conn_ids); } $table = $this->renderCallTable($calls, $conns); $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Call Logs'))->appendChild($table); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Call Logs')); return $this->buildApplicationPage(array($crumbs, $box, $pager), array('title' => pht('Conduit Logs'))); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $pager = new AphrontCursorPagerView(); $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->executeWithCursorPager($pager); break; case 'all': $paste_list = $query->executeWithCursorPager($pager); break; } $side_nav = $this->buildSideNavView(); $side_nav->selectFilter($this->getFilter()); 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"; break; case 'my': $header = 'Your Pastes'; break; case 'all': $header = 'All Pastes'; break; } $this->loadHandles(mpull($paste_list, 'getAuthorPHID')); $list = $this->buildPasteList($paste_list); $list->setHeader($header); $list->setPager($pager); $side_nav->appendChild($list); return $this->buildApplicationPage($side_nav, array('title' => 'Paste', 'device' => true)); }
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); $logs = id(new PhabricatorDaemonLogQuery())->setViewer($viewer)->setAllowStatusWrites(true)->executeWithCursorPager($pager); $daemon_table = id(new PhabricatorDaemonLogListView())->setViewer($viewer)->setDaemonLogs($logs); $box = id(new PHUIObjectBoxView())->setHeaderText(pht('All Daemons'))->setTable($daemon_table); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('All Daemons')); $nav = $this->buildSideNavView(); $nav->selectFilter('log'); $nav->setCrumbs($crumbs); $nav->appendChild($box); $nav->appendChild($pager); return $this->newPage()->setTitle(pht('All Daemons'))->appendChild($nav); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); $logs = id(new PhabricatorDaemonLogQuery())->setViewer($viewer)->setAllowStatusWrites(true)->executeWithCursorPager($pager); $daemon_table = new PhabricatorDaemonLogListView(); $daemon_table->setUser($request->getUser()); $daemon_table->setDaemonLogs($logs); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('All Daemons')); $nav = $this->buildSideNavView(); $nav->selectFilter('log'); $nav->setCrumbs($crumbs); $nav->appendChild($daemon_table); $nav->appendChild($pager); return $this->buildApplicationPage($nav, array('title' => pht('All Daemons'))); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); $query = id(new PhortuneProductQuery())->setViewer($viewer); $products = $query->executeWithCursorPager($pager); $title = pht('Product List'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Products'), $this->getApplicationURI('product/')); $crumbs->addAction(id(new PHUIListItemView())->setName(pht('Create Product'))->setHref($this->getApplicationURI('product/edit/'))->setIcon('fa-plus-square')); $product_list = id(new PHUIObjectItemListView())->setUser($viewer)->setNoDataString(pht('No products.')); foreach ($products as $product) { $view_uri = $this->getApplicationURI('product/view/' . $product->getID() . '/'); $price = $product->getPriceAsCurrency(); $item = id(new PHUIObjectItemView())->setObjectName($product->getID())->setHeader($product->getProductName())->setHref($view_uri)->addAttribute($price->formatForDisplay()); $product_list->addItem($item); } return $this->buildApplicationPage(array($crumbs, $product_list, $pager), array('title' => $title)); }
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); $query = id(new PhluxVariableQuery())->setViewer($viewer); $vars = $query->executeWithCursorPager($pager); $view = new PHUIObjectItemListView(); foreach ($vars as $var) { $key = $var->getVariableKey(); $item = new PHUIObjectItemView(); $item->setHeader($key); $item->setHref($this->getApplicationURI('/view/' . $key . '/')); $item->addIcon('none', phabricator_datetime($var->getDateModified(), $viewer)); $view->addItem($item); } $crumbs = $this->buildApplicationCrumbs(); $title = pht('Variable List'); $crumbs->addTextCrumb($title, $this->getApplicationURI()); return $this->buildApplicationPage(array($crumbs, $view, $pager), array('title' => $title)); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); $query = id(new PhortuneProductQuery())->setViewer($viewer); $products = $query->executeWithCursorPager($pager); $title = pht('Product List'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Products'), $this->getApplicationURI('product/')); $crumbs->addAction(id(new PHUIListItemView())->setName(pht('Create Product'))->setHref($this->getApplicationURI('product/edit/'))->setIcon('fa-plus-square')); $crumbs->setBorder(true); $product_list = id(new PHUIObjectItemListView())->setUser($viewer)->setNoDataString(pht('No products.')); foreach ($products as $product) { $view_uri = $this->getApplicationURI('product/view/' . $product->getID() . '/'); $price = $product->getPriceAsCurrency(); $item = id(new PHUIObjectItemView())->setObjectName($product->getID())->setHeader($product->getProductName())->setHref($view_uri)->addAttribute($price->formatForDisplay())->setIcon('fa-gift'); $product_list->addItem($item); } $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Products'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setObjectList($product_list); $header = id(new PHUIHeaderView())->setHeader(pht('Products'))->setHeaderIcon('fa-gift'); $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($box, $pager)); return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view); }
public function newPagerForSavedQuery(PhabricatorSavedQuery $saved) { if ($this->shouldUseOffsetPaging()) { $pager = new PHUIPagerView(); } else { $pager = new AphrontCursorPagerView(); } $page_size = $this->getPageSize($saved); if (is_finite($page_size)) { $pager->setPageSize($page_size); } else { // Consider an INF pagesize to mean a large finite pagesize. // TODO: It would be nice to handle this more gracefully, but math // with INF seems to vary across PHP versions, systems, and runtimes. $pager->setPageSize(0xffff); } return $pager; }
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 AphrontCursorPagerView(); $pager->readFromRequest($request); $pager->setPageSize(200); $feed = $feed_query->executeWithCursorPager($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>'; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $uri = clone $request->getRequestURI(); $uri->setQueryParams(array()); $pager = new AphrontCursorPagerView(); $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->executeWithCursorPager($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')); }
public final function executeWithCursorPager(AphrontCursorPagerView $pager) { $limit = $pager->getPageSize(); $this->setLimit($limit + 1); if ($pager->getAfterID()) { $this->setAfterID($pager->getAfterID()); } else { if ($pager->getBeforeID()) { $this->setBeforeID($pager->getBeforeID()); } } $results = $this->execute(); $count = count($results); $sliced_results = $pager->sliceResults($results); if ($sliced_results) { list($before, $after) = $this->getPageCursors($sliced_results); if ($pager->getBeforeID() || $count > $limit) { $pager->setNextPageID($after); } if ($pager->getAfterID() || $pager->getBeforeID() && $count > $limit) { $pager->setPrevPageID($before); } } return $sliced_results; }
/** * @task pager */ protected function addPagerResults(array $results, AphrontCursorPagerView $pager) { $results['cursor'] = array('limit' => $pager->getPageSize(), 'after' => $pager->getNextPageID(), 'before' => $pager->getPrevPageID()); return $results; }
public final function executeWithCursorPager(AphrontCursorPagerView $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; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('channelID'); $uri = clone $request->getRequestURI(); $uri->setQueryParams(array()); $pager = new AphrontCursorPagerView(); $pager->setURI($uri); $pager->setPageSize(250); $query = id(new PhabricatorChatLogQuery())->setViewer($viewer)->withChannelIDs(array($id)); $channel = id(new PhabricatorChatLogChannelQuery())->setViewer($viewer)->withIDs(array($id))->executeOne(); if (!$channel) { return new Aphront404Response(); } list($after, $before, $map) = $this->getPagingParameters($request, $query); $pager->setAfterID($after); $pager->setBeforeID($before); $logs = $query->executeWithCursorPager($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(); foreach ($blocks as $block) { $author = $block['author']; $author = id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(18)->truncateString($author); $author = phutil_tag('td', array('class' => 'author'), $author); $href = $uri->alter('at', $block['id']); $timestamp = $block['epoch']; $timestamp = phabricator_datetime($timestamp, $viewer); $timestamp = phutil_tag('a', array('href' => $href, 'class' => 'timestamp'), $timestamp); $message = mpull($block['logs'], 'getMessage'); $message = implode("\n", $message); $message = phutil_tag('td', array('class' => 'message'), array($timestamp, $message)); $out[] = phutil_tag('tr', array('class' => $block['class']), array($author, $message)); } $links = array(); $first_uri = $pager->getFirstPageURI(); if ($first_uri) { $links[] = phutil_tag('a', array('href' => $first_uri), "« " . pht('Newest')); } $prev_uri = $pager->getPrevPageURI(); if ($prev_uri) { $links[] = phutil_tag('a', array('href' => $prev_uri), "‹ " . pht('Newer')); } $next_uri = $pager->getNextPageURI(); if ($next_uri) { $links[] = phutil_tag('a', array('href' => $next_uri), pht('Older') . " ›"); } $pager_bottom = phutil_tag('div', array('class' => 'phabricator-chat-log-pager-bottom'), $links); $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($channel->getChannelName(), $uri); $form = id(new AphrontFormView())->setUser($viewer)->setMethod('GET')->setAction($uri)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Date'))->setName('date')->setValue($request->getStr('date')))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Jump'))); $table = phutil_tag('table', array('class' => 'phabricator-chat-log'), $out); $log = phutil_tag('div', array('class' => 'phabricator-chat-log-panel'), $table); $jump_link = id(new PHUIButtonView())->setTag('a')->setHref('#latest')->setText(pht('Jump to Bottom'))->setIconFont('fa-arrow-circle-down'); $jump_target = phutil_tag('div', array('id' => 'latest')); $content = phutil_tag('div', array('class' => 'phabricator-chat-log-wrap'), array($log, $jump_target, $pager_bottom)); $header = id(new PHUIHeaderView())->setHeader($channel->getChannelName())->setSubHeader($channel->getServiceName())->addActionLink($jump_link); $box = id(new PHUIObjectBoxView())->setHeader($header)->setCollapsed(true)->appendChild($content); $box->setShowHide(pht('Search Dates'), pht('Hide Dates'), $form, '#'); return $this->buildApplicationPage(array($crumbs, $box), array('title' => pht('Channel Log'))); }
/** * @task internal */ protected function renderContent(AphrontRequest $request) { $user = $request->getUser(); $matches = null; $path = $request->getPath(); // default to the blog-wide values $this->setTitle($this->getBlog()->getName()); $this->setDescription($this->getBlog()->getDescription()); $this->setOGType('website'); $this->setURIPath(''); if (preg_match('@^/post/(?P<name>.*)$@', $path, $matches)) { $post = id(new PhamePostQuery())->setViewer($user)->withBlogPHIDs(array($this->getBlog()->getPHID()))->withPhameTitles(array($matches['name']))->executeOne(); if ($post) { $description = $post->getMarkupText(PhamePost::MARKUP_FIELD_SUMMARY); $this->setTitle($post->getTitle()); $this->setDescription($description); $this->setOGType('article'); $this->setURIPath('post/' . $post->getPhameTitle()); $view = head($this->buildPostViews(array($post))); return $this->renderPostDetail($view); } } else { $pager = new AphrontCursorPagerView(); if (preg_match('@^/older/(?P<before>\\d+)/$@', $path, $matches)) { $pager->setAfterID($matches['before']); } else { if (preg_match('@^/newer/(?P<after>\\d)/$@', $path, $matches)) { $pager->setBeforeID($matches['after']); } else { if (preg_match('@^/$@', $path, $matches)) { // Just show the first page. } else { return null; } } } $pager->setPageSize($this->getPageSize()); $posts = id(new PhamePostQuery())->setViewer($user)->withBlogPHIDs(array($this->getBlog()->getPHID()))->executeWithCursorPager($pager); $this->pager = $pager; if ($posts) { $views = $this->buildPostViews($posts); return $this->renderPostList($views); } } return null; }