Summary: - Add a PhabricatorApplication. - Make most of the views work well on tablets / phones. The actual "Create" form doesn't, but everything else is good -- need to make device-friendly form layouts before I can do the form. Test Plan: Will attach screenshots. Reviewers: btrahan, chad, vrana Reviewed By: btrahan CC: aran Maniphest Tasks: T1569 Differential Revision: https://secure.phabricator.com/D3293
145 lines
3.8 KiB
PHP
145 lines
3.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright 2012 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.
|
|
*/
|
|
|
|
final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|
|
|
private $id;
|
|
private $handles;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->id = $data['id'];
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
$paste = id(new PhabricatorPasteQuery())
|
|
->setViewer($user)
|
|
->withIDs(array($this->id))
|
|
->executeOne();
|
|
if (!$paste) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$file = id(new PhabricatorFile())->loadOneWhere(
|
|
'phid = %s',
|
|
$paste->getFilePHID());
|
|
if (!$file) {
|
|
return new Aphront400Response();
|
|
}
|
|
|
|
$this->loadHandles(
|
|
array(
|
|
$paste->getAuthorPHID(),
|
|
$paste->getParentPHID(),
|
|
));
|
|
|
|
$header = $this->buildHeaderView($paste);
|
|
$actions = $this->buildActionView($paste, $file);
|
|
$properties = $this->buildPropertyView($paste);
|
|
$source_code = $this->buildSourceCodeView($paste, $file);
|
|
|
|
$nav = $this->buildSideNavView($paste);
|
|
$nav->selectFilter('paste');
|
|
$nav->appendChild(
|
|
array(
|
|
$header,
|
|
$actions,
|
|
$properties,
|
|
$source_code,
|
|
// $forks_panel,
|
|
));
|
|
|
|
return $this->buildApplicationPage(
|
|
$nav,
|
|
array(
|
|
'title' => 'P'.$paste->getID().' '.$paste->getTitle(),
|
|
'device' => true,
|
|
));
|
|
}
|
|
|
|
private function buildHeaderView(PhabricatorPaste $paste) {
|
|
return id(new PhabricatorHeaderView())
|
|
->setObjectName('P'.$paste->getID())
|
|
->setHeader($paste->getTitle());
|
|
}
|
|
|
|
private function buildActionView(
|
|
PhabricatorPaste $paste,
|
|
PhabricatorFile $file) {
|
|
|
|
return id(new PhabricatorActionListView())
|
|
->addAction(
|
|
id(new PhabricatorActionView())
|
|
->setName(pht('Fork This Paste'))
|
|
->setIcon('fork')
|
|
->setHref($this->getApplicationURI('?fork='.$paste->getID())))
|
|
->addAction(
|
|
id(new PhabricatorActionView())
|
|
->setName(pht('View Raw File'))
|
|
->setIcon('file')
|
|
->setHref($file->getBestURI()));
|
|
}
|
|
|
|
private function buildPropertyView(PhabricatorPaste $paste) {
|
|
$user = $this->getRequest()->getUser();
|
|
$properties = new PhabricatorPropertyListView();
|
|
|
|
$properties->addProperty(
|
|
pht('Author'),
|
|
$this->getHandle($paste->getAuthorPHID())->renderLink());
|
|
|
|
$properties->addProperty(
|
|
pht('Created'),
|
|
phabricator_datetime($paste->getDateCreated(), $user));
|
|
|
|
if ($paste->getParentPHID()) {
|
|
$properties->addProperty(
|
|
pht('Forked From'),
|
|
$this->getHandle($paste->getParentPHID())->renderLink());
|
|
}
|
|
|
|
return $properties;
|
|
}
|
|
|
|
private function buildSourceCodeView(
|
|
PhabricatorPaste $paste,
|
|
PhabricatorFile $file) {
|
|
|
|
$language = $paste->getLanguage();
|
|
$source = $file->loadFileData();
|
|
|
|
if (empty($language)) {
|
|
$source = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
|
$paste->getTitle(),
|
|
$source);
|
|
} else {
|
|
$source = PhabricatorSyntaxHighlighter::highlightWithLanguage(
|
|
$language,
|
|
$source);
|
|
}
|
|
|
|
$lines = explode("\n", $source);
|
|
|
|
return id(new PhabricatorSourceCodeView())
|
|
->setLines($lines);
|
|
}
|
|
|
|
}
|