Make the Diffusion UI vaguely usable in some cases.
This commit is contained in:
@@ -30,6 +30,10 @@ abstract class DiffusionController extends PhabricatorController {
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getDiffusionRequest() {
|
||||
return $this->diffusionRequest;
|
||||
}
|
||||
|
||||
public function buildStandardPageResponse($view, array $data) {
|
||||
|
||||
$page = $this->buildStandardPageView();
|
||||
@@ -44,4 +48,183 @@ abstract class DiffusionController extends PhabricatorController {
|
||||
return $response->setContent($page->render());
|
||||
}
|
||||
|
||||
final protected function buildSideNav($selected, $has_change_view) {
|
||||
$nav = new AphrontSideNavView();
|
||||
|
||||
$navs = array(
|
||||
'history' => 'History View',
|
||||
'browse' => 'Browse View',
|
||||
'change' => 'Change View',
|
||||
);
|
||||
|
||||
if (!$has_change_view) {
|
||||
unset($navs['change']);
|
||||
}
|
||||
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
$repository = $drequest->getRepository();
|
||||
$callsign = $repository->getCallsign();
|
||||
|
||||
$branch_uri = $drequest->getBranchURIComponent($drequest->getBranch());
|
||||
$path_uri = $branch_uri.$drequest->getPath();
|
||||
|
||||
$commit_uri = null;
|
||||
$raw_commit = $drequest->getRawCommit();
|
||||
if ($raw_commit) {
|
||||
$commit_uri = ';'.$drequest->getCommitURIComponent($raw_commit);
|
||||
}
|
||||
|
||||
foreach ($navs as $uri => $name) {
|
||||
$nav->addNavItem(
|
||||
phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => "/diffusion/{$callsign}/{$uri}/{$path_uri}{$commit_uri}",
|
||||
'class' =>
|
||||
($uri == $selected
|
||||
? 'aphront-side-nav-selected'
|
||||
: null),
|
||||
),
|
||||
$name));
|
||||
}
|
||||
|
||||
return $nav;
|
||||
}
|
||||
|
||||
public function buildCrumbs(array $spec = array()) {
|
||||
$drequest = $this->diffusionRequest;
|
||||
|
||||
$crumbs = new AphrontCrumbsView();
|
||||
|
||||
$crumb_list = array();
|
||||
|
||||
$repository = $drequest->getRepository();
|
||||
if ($repository) {
|
||||
$crumb_list[] = phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/diffusion/',
|
||||
),
|
||||
'Diffusion');
|
||||
} else {
|
||||
$crumb_list[] = 'Diffusion';
|
||||
$crumbs->setCrumbs($crumb_list);
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
$callsign = $repository->getCallsign();
|
||||
$repository_name = phutil_escape_html($repository->getName()).' Repository';
|
||||
|
||||
$branch_name = $drequest->getBranch();
|
||||
if ($branch_name) {
|
||||
$repository_name .= ' ('.phutil_escape_html($branch_name).')';
|
||||
}
|
||||
|
||||
$branch_uri = $drequest->getBranchURIComponent($drequest->getBranch());
|
||||
|
||||
if (empty($spec['view'])) {
|
||||
$crumb_list[] = $repository_name;
|
||||
$crumbs->setCrumbs($crumb_list);
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
$crumb_list[] = phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => "/diffusion/{$callsign}/",
|
||||
),
|
||||
$repository_name);
|
||||
|
||||
|
||||
if (empty($spec['view'])) {
|
||||
$crumbs->setCrumbs($crumb_list);
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
$view = $spec['view'];
|
||||
|
||||
switch ($view) {
|
||||
case 'history':
|
||||
$view_name = 'History';
|
||||
break;
|
||||
case 'browse':
|
||||
$view_name = 'Browse';
|
||||
break;
|
||||
}
|
||||
|
||||
$path = null;
|
||||
if (isset($spec['path'])) {
|
||||
$path = $drequest->getPath();
|
||||
}
|
||||
|
||||
$view_root_uri = "/diffusion/{$callsign}/{$view}/{$branch_uri}";
|
||||
$jump_href = $view_root_uri;
|
||||
|
||||
$view_tail_uri = null;
|
||||
$raw_commit = $drequest->getRawCommit();
|
||||
if ($raw_commit) {
|
||||
$view_tail_uri = ';'.$drequest->getCommitURIComponent($raw_commit);
|
||||
}
|
||||
|
||||
if (!strlen($path)) {
|
||||
$crumb_list[] = $view_name;
|
||||
} else {
|
||||
|
||||
$crumb_list[] = phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $view_root_uri.$view_tail_uri,
|
||||
),
|
||||
$view_name);
|
||||
|
||||
$path_parts = explode('/', $path);
|
||||
do {
|
||||
$last = array_pop($path_parts);
|
||||
} while ($last == '');
|
||||
|
||||
$path_sections = array();
|
||||
$thus_far = '';
|
||||
foreach ($path_parts as $path_part) {
|
||||
$thus_far .= $path_part.'/';
|
||||
$path_sections[] = phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $view_root_uri.$thus_far.$view_tail_uri,
|
||||
),
|
||||
phutil_escape_html($path_part));
|
||||
}
|
||||
|
||||
$path_sections[] = phutil_escape_html($last);
|
||||
$path_sections = '/'.implode('/', $path_sections);
|
||||
|
||||
$jump_href = $view_root_uri.$thus_far.$last;
|
||||
|
||||
$crumb_list[] = $path_sections;
|
||||
}
|
||||
|
||||
$last_crumb = array_pop($crumb_list);
|
||||
|
||||
if ($raw_commit) {
|
||||
$commit_link = DiffusionView::linkCommit(
|
||||
$repository,
|
||||
$raw_commit);
|
||||
$jump_link = phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $jump_href,
|
||||
),
|
||||
'Jump to HEAD');
|
||||
$last_crumb .= " @ {$commit_link} ({$jump_link})";
|
||||
} else {
|
||||
$last_crumb .= " @ HEAD";
|
||||
}
|
||||
|
||||
$crumb_list[] = $last_crumb;
|
||||
|
||||
|
||||
$crumbs->setCrumbs($crumb_list);
|
||||
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
phutil_require_module('phabricator', 'aphront/response/webpage');
|
||||
phutil_require_module('phabricator', 'applications/base/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/request/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/base');
|
||||
phutil_require_module('phabricator', 'view/layout/crumbs');
|
||||
phutil_require_module('phabricator', 'view/layout/sidenav');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,13 @@ class DiffusionBrowseController extends DiffusionController {
|
||||
|
||||
$content = array();
|
||||
|
||||
$content[] = $this->buildCrumbs(
|
||||
array(
|
||||
'branch' => true,
|
||||
'path' => true,
|
||||
'view' => 'browse',
|
||||
));
|
||||
|
||||
if (!$results) {
|
||||
|
||||
switch ($browse_query->getReasonForEmptyResultSet()) {
|
||||
@@ -69,19 +76,16 @@ class DiffusionBrowseController extends DiffusionController {
|
||||
$browse_table->setPaths($results);
|
||||
|
||||
$browse_panel = new AphrontPanelView();
|
||||
$browse_panel->setHeader($drequest->getPath());
|
||||
$browse_panel->appendChild($browse_table);
|
||||
|
||||
$content[] = $browse_panel;
|
||||
|
||||
// TODO: Branch table
|
||||
}
|
||||
|
||||
// TODO: Crumbs
|
||||
// TODO: Side nav
|
||||
$nav = $this->buildSideNav('browse', false);
|
||||
$nav->appendChild($content);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$content,
|
||||
$nav,
|
||||
array(
|
||||
'title' => basename($drequest->getPath()),
|
||||
));
|
||||
|
||||
@@ -19,6 +19,15 @@
|
||||
class DiffusionBrowseFileController extends DiffusionController {
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$content = array();
|
||||
$content[] = $this->buildCrumbs(
|
||||
array(
|
||||
'branch' => true,
|
||||
'path' => true,
|
||||
'view' => 'browse',
|
||||
));
|
||||
|
||||
$file_query = DiffusionFileContentQuery::newFromDiffusionRequest(
|
||||
$this->diffusionRequest);
|
||||
$file_content = $file_query->loadFileContent();
|
||||
@@ -26,13 +35,19 @@ class DiffusionBrowseFileController extends DiffusionController {
|
||||
$corpus = phutil_render_tag(
|
||||
'textarea',
|
||||
array(
|
||||
'style' => 'margin: 1em 2em; width: 90%; height: 80em;',
|
||||
),
|
||||
phutil_escape_html($file_content->getCorpus()));
|
||||
|
||||
$content[] = $corpus;
|
||||
|
||||
// TODO: blame, color, line numbers, highlighting, etc etc
|
||||
|
||||
$nav = $this->buildSideNav('browse', true);
|
||||
$nav->appendChild($content);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$corpus,
|
||||
$nav,
|
||||
array(
|
||||
'title' => 'Browse',
|
||||
));
|
||||
|
||||
@@ -28,21 +28,30 @@ class DiffusionHistoryController extends DiffusionController {
|
||||
|
||||
$content = array();
|
||||
|
||||
$content[] = $this->buildCrumbs(
|
||||
array(
|
||||
'branch' => true,
|
||||
'path' => true,
|
||||
'view' => 'history',
|
||||
));
|
||||
|
||||
$history_table = new DiffusionHistoryTableView();
|
||||
$history_table->setDiffusionRequest($drequest);
|
||||
$history_table->setHistory($history);
|
||||
|
||||
$history_panel = new AphrontPanelView();
|
||||
$history_panel->setHeader($drequest->getPath());
|
||||
$history_panel->appendChild($history_table);
|
||||
|
||||
$content[] = $history_panel;
|
||||
|
||||
// TODO: Crumbs
|
||||
// TODO: Side nav
|
||||
// TODO: Sometimes we do have a change view, we need to look at the most
|
||||
// recent history entry to figure it out.
|
||||
|
||||
$nav = $this->buildSideNav('history', false);
|
||||
$nav->appendChild($content);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$content,
|
||||
$nav,
|
||||
array(
|
||||
'title' => 'history',
|
||||
));
|
||||
|
||||
@@ -49,7 +49,7 @@ class DiffusionHomeController extends DiffusionController {
|
||||
phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '#', // TODO: Link
|
||||
'href' => '/diffusion/'.$repository->getCallsign().'/',
|
||||
),
|
||||
phutil_escape_html($repository->getName())),
|
||||
$repository->getVersionControlSystem(),
|
||||
@@ -81,8 +81,13 @@ class DiffusionHomeController extends DiffusionController {
|
||||
$panel->setHeader('Browse Repositories');
|
||||
$panel->appendChild($table);
|
||||
|
||||
$crumbs = $this->buildCrumbs();
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$panel,
|
||||
array(
|
||||
$crumbs,
|
||||
$panel,
|
||||
),
|
||||
array(
|
||||
'title' => 'Diffusion',
|
||||
));
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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 DiffusionRepositoryController extends DiffusionController {
|
||||
|
||||
public function processRequest() {
|
||||
$drequest = $this->diffusionRequest;
|
||||
|
||||
$content = array();
|
||||
|
||||
$crumbs = $this->buildCrumbs();
|
||||
$content[] = $crumbs;
|
||||
|
||||
$history_query = DiffusionHistoryQuery::newFromDiffusionRequest(
|
||||
$drequest);
|
||||
$history_query->setLimit(15);
|
||||
|
||||
$history = $history_query->loadHistory();
|
||||
$history_table = new DiffusionHistoryTableView();
|
||||
$history_table->setDiffusionRequest($drequest);
|
||||
$history_table->setHistory($history);
|
||||
|
||||
$panel = new AphrontPanelView();
|
||||
$panel->setHeader('Recent Commits');
|
||||
$panel->appendChild($history_table);
|
||||
|
||||
$content[] = $panel;
|
||||
|
||||
$browse_query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest);
|
||||
$results = $browse_query->loadPaths();
|
||||
|
||||
$browse_table = new DiffusionBrowseTableView();
|
||||
$browse_table->setDiffusionRequest($drequest);
|
||||
$browse_table->setPaths($results);
|
||||
|
||||
$browse_panel = new AphrontPanelView();
|
||||
$browse_panel->setHeader('Browse Repository');
|
||||
$browse_panel->appendChild($browse_table);
|
||||
|
||||
$content[] = $browse_panel;
|
||||
|
||||
if ($drequest->getBranch() !== null) {
|
||||
$branch_query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
|
||||
$branches = $branch_query->loadBranches();
|
||||
|
||||
$branch_table = new DiffusionBranchTableView();
|
||||
$branch_table->setDiffusionRequest($drequest);
|
||||
$branch_table->setBranches($branches);
|
||||
|
||||
$branch_panel = new AphrontPanelView();
|
||||
$branch_panel->setHeader('Branches');
|
||||
$branch_panel->appendChild($branch_table);
|
||||
|
||||
$content[] = $branch_panel;
|
||||
}
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$content,
|
||||
array(
|
||||
'title' => 'Diffusion',
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/branch/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/browse/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/history/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/branchtable');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/browsetable');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/historytable');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
|
||||
phutil_require_source('DiffusionRepositoryController.php');
|
||||
Reference in New Issue
Block a user