mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Basic Phriction list view
Summary: Pretty much ripped from D636, but somewhat simplified. Lists all the documents in the system. Test Plan: Looked at both of the views, seems to work correctly. Reviewed By: hsb Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran CC: aran, hsb, epriestley Differential Revision: 645
This commit is contained in:
parent
7c21068c9f
commit
6bdbf3c8c2
5 changed files with 217 additions and 0 deletions
|
@ -586,6 +586,7 @@ phutil_register_library_map(array(
|
||||||
'PhrictionDocumentController' => 'applications/phriction/controller/document',
|
'PhrictionDocumentController' => 'applications/phriction/controller/document',
|
||||||
'PhrictionEditController' => 'applications/phriction/controller/edit',
|
'PhrictionEditController' => 'applications/phriction/controller/edit',
|
||||||
'PhrictionHistoryController' => 'applications/phriction/controller/history',
|
'PhrictionHistoryController' => 'applications/phriction/controller/history',
|
||||||
|
'PhrictionListController' => 'applications/phriction/controller/list',
|
||||||
),
|
),
|
||||||
'function' =>
|
'function' =>
|
||||||
array(
|
array(
|
||||||
|
@ -1082,6 +1083,7 @@ phutil_register_library_map(array(
|
||||||
'PhrictionDocumentController' => 'PhrictionController',
|
'PhrictionDocumentController' => 'PhrictionController',
|
||||||
'PhrictionEditController' => 'PhrictionController',
|
'PhrictionEditController' => 'PhrictionController',
|
||||||
'PhrictionHistoryController' => 'PhrictionController',
|
'PhrictionHistoryController' => 'PhrictionController',
|
||||||
|
'PhrictionListController' => 'PhrictionController',
|
||||||
),
|
),
|
||||||
'requires_interface' =>
|
'requires_interface' =>
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -347,6 +347,9 @@ class AphrontDefaultApplicationConfiguration
|
||||||
'/w/(?P<slug>.+/)$' => 'PhrictionDocumentController',
|
'/w/(?P<slug>.+/)$' => 'PhrictionDocumentController',
|
||||||
|
|
||||||
'/phriction/' => array(
|
'/phriction/' => array(
|
||||||
|
'$' => 'PhrictionListController',
|
||||||
|
'list/(?P<view>[^/]+)/$' => 'PhrictionListController',
|
||||||
|
|
||||||
'history(?P<slug>/)$' => 'PhrictionHistoryController',
|
'history(?P<slug>/)$' => 'PhrictionHistoryController',
|
||||||
'history/(?P<slug>.+/)$' => 'PhrictionHistoryController',
|
'history/(?P<slug>.+/)$' => 'PhrictionHistoryController',
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,174 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2011 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PhrictionListController
|
||||||
|
extends PhrictionController {
|
||||||
|
|
||||||
|
private $view;
|
||||||
|
|
||||||
|
public function willProcessRequest(array $data) {
|
||||||
|
$this->view = idx($data, 'view');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function processRequest() {
|
||||||
|
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$user = $request->getUser();
|
||||||
|
|
||||||
|
$views = array(
|
||||||
|
'all' => 'All Documents',
|
||||||
|
'updates' => 'Recently Updated',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (empty($views[$this->view])) {
|
||||||
|
$this->view = 'all';
|
||||||
|
}
|
||||||
|
|
||||||
|
$nav = new AphrontSideNavView();
|
||||||
|
foreach ($views as $view => $name) {
|
||||||
|
$nav->addNavItem(
|
||||||
|
phutil_render_tag(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => '/phriction/list/'.$view.'/',
|
||||||
|
'class' => ($this->view == $view)
|
||||||
|
? 'aphront-side-nav-selected'
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
phutil_escape_html($name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
$pager = new AphrontPagerView();
|
||||||
|
$pager->setURI($request->getRequestURI(), 'page');
|
||||||
|
$pager->setOffset($request->getInt('page'));
|
||||||
|
|
||||||
|
$documents = $this->loadDocuments($pager);
|
||||||
|
|
||||||
|
$content = mpull($documents, 'getContent');
|
||||||
|
$phids = mpull($content, 'getAuthorPHID');
|
||||||
|
|
||||||
|
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
||||||
|
|
||||||
|
|
||||||
|
$rows = array();
|
||||||
|
foreach ($documents as $document) {
|
||||||
|
$content = $document->getContent();
|
||||||
|
$rows[] = array(
|
||||||
|
$handles[$content->getAuthorPHID()]->renderLink(),
|
||||||
|
phutil_render_tag(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => PhrictionDocument::getSlugURI($document->getSlug()),
|
||||||
|
),
|
||||||
|
phutil_escape_html($content->getTitle())),
|
||||||
|
phabricator_date($content->getDateCreated(), $user),
|
||||||
|
phabricator_time($content->getDateCreated(), $user),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$document_table = new AphrontTableView($rows);
|
||||||
|
$document_table->setHeaders(
|
||||||
|
array(
|
||||||
|
'Last Editor',
|
||||||
|
'Title',
|
||||||
|
'Last Update',
|
||||||
|
'Time',
|
||||||
|
));
|
||||||
|
|
||||||
|
$document_table->setColumnClasses(
|
||||||
|
array(
|
||||||
|
'',
|
||||||
|
'wide pri',
|
||||||
|
'',
|
||||||
|
'right',
|
||||||
|
'',
|
||||||
|
'right',
|
||||||
|
));
|
||||||
|
|
||||||
|
$view_headers = array(
|
||||||
|
'all' => 'All Documents',
|
||||||
|
'updates' => 'Recently Updated Documents',
|
||||||
|
);
|
||||||
|
$view_header = $view_headers[$this->view];
|
||||||
|
|
||||||
|
$panel = new AphrontPanelView();
|
||||||
|
$panel->setHeader($view_header);
|
||||||
|
$panel->appendChild($document_table);
|
||||||
|
$panel->appendChild($pager);
|
||||||
|
|
||||||
|
$nav->appendChild($panel);
|
||||||
|
|
||||||
|
return $this->buildStandardPageResponse($nav,
|
||||||
|
array(
|
||||||
|
'title' => 'Phriction Main'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loadDocuments(AphrontPagerView $pager) {
|
||||||
|
|
||||||
|
// TODO: Do we want/need a query object for this?
|
||||||
|
|
||||||
|
$document_dao = new PhrictionDocument();
|
||||||
|
$content_dao = new PhrictionContent();
|
||||||
|
$conn = $document_dao->establishConnection('r');
|
||||||
|
|
||||||
|
switch ($this->view) {
|
||||||
|
case 'all':
|
||||||
|
$data = queryfx_all(
|
||||||
|
$conn,
|
||||||
|
'SELECT * FROM %T ORDER BY id DESC LIMIT %d, %d',
|
||||||
|
$document_dao->getTableName(),
|
||||||
|
$pager->getOffset(),
|
||||||
|
$pager->getPageSize() + 1);
|
||||||
|
break;
|
||||||
|
case 'updates':
|
||||||
|
|
||||||
|
// TODO: This query is a little suspicious, verify we don't need to key
|
||||||
|
// or change it once we get more data.
|
||||||
|
|
||||||
|
$data = queryfx_all(
|
||||||
|
$conn,
|
||||||
|
'SELECT d.* FROM %T d JOIN %T c ON c.documentID = d.id
|
||||||
|
GROUP BY c.documentID
|
||||||
|
ORDER BY MAX(c.id) DESC LIMIT %d, %d',
|
||||||
|
$document_dao->getTableName(),
|
||||||
|
$content_dao->getTableName(),
|
||||||
|
$pager->getOffset(),
|
||||||
|
$pager->getPageSize() + 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Unknown view '{$this->view}'!");
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $pager->sliceResults($data);
|
||||||
|
|
||||||
|
$documents = $document_dao->loadAllFromArray($data);
|
||||||
|
if ($documents) {
|
||||||
|
$content = $content_dao->loadAllWhere(
|
||||||
|
'documentID IN (%Ld)',
|
||||||
|
mpull($documents, 'getID'));
|
||||||
|
$content = mpull($content, null, 'getDocumentID');
|
||||||
|
foreach ($documents as $document) {
|
||||||
|
$document->attachContent($content[$document->getID()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
src/applications/phriction/controller/list/__init__.php
Normal file
24
src/applications/phriction/controller/list/__init__.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is automatically generated. Lint this module to rebuild it.
|
||||||
|
* @generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||||
|
phutil_require_module('phabricator', 'applications/phriction/controller/base');
|
||||||
|
phutil_require_module('phabricator', 'applications/phriction/storage/content');
|
||||||
|
phutil_require_module('phabricator', 'applications/phriction/storage/document');
|
||||||
|
phutil_require_module('phabricator', 'storage/queryfx');
|
||||||
|
phutil_require_module('phabricator', 'view/control/pager');
|
||||||
|
phutil_require_module('phabricator', 'view/control/table');
|
||||||
|
phutil_require_module('phabricator', 'view/layout/panel');
|
||||||
|
phutil_require_module('phabricator', 'view/layout/sidenav');
|
||||||
|
phutil_require_module('phabricator', 'view/utils');
|
||||||
|
|
||||||
|
phutil_require_module('phutil', 'markup');
|
||||||
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_source('PhrictionListController.php');
|
|
@ -24,6 +24,8 @@ class PhrictionDocument extends PhrictionDAO {
|
||||||
protected $depth;
|
protected $depth;
|
||||||
protected $contentID;
|
protected $contentID;
|
||||||
|
|
||||||
|
private $contentObject;
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_AUX_PHID => true,
|
self::CONFIG_AUX_PHID => true,
|
||||||
|
@ -76,4 +78,16 @@ class PhrictionDocument extends PhrictionDAO {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attachContent(PhrictionContent $content) {
|
||||||
|
$this->contentObject = $content;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent() {
|
||||||
|
if (!$this->contentObject) {
|
||||||
|
throw new Exception("Attach content with attachContent() first.");
|
||||||
|
}
|
||||||
|
return $this->contentObject;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue