1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Minor, formalize changeset response class.

This commit is contained in:
epriestley 2012-03-12 21:39:05 -07:00
parent 08775ea366
commit f158b32a54
12 changed files with 183 additions and 22 deletions

View file

@ -67,6 +67,7 @@ phutil_register_library_map(array(
'AphrontPagerView' => 'view/control/pager',
'AphrontPanelView' => 'view/layout/panel',
'AphrontPlainTextResponse' => 'aphront/response/plaintext',
'AphrontProxyResponse' => 'aphront/response/proxy',
'AphrontQueryAccessDeniedException' => 'storage/exception/accessdenied',
'AphrontQueryConnectionException' => 'storage/exception/connection',
'AphrontQueryConnectionLostException' => 'storage/exception/connectionlost',
@ -465,6 +466,7 @@ phutil_register_library_map(array(
'PhabricatorAuthController' => 'applications/auth/controller/base',
'PhabricatorCalendarBrowseController' => 'applications/calendar/controller/browse',
'PhabricatorCalendarController' => 'applications/calendar/controller/base',
'PhabricatorChangesetResponse' => 'infrastructure/diff/response',
'PhabricatorChatLogChannelListController' => 'applications/chatlog/controller/channellist',
'PhabricatorChatLogChannelLogController' => 'applications/chatlog/controller/channellog',
'PhabricatorChatLogConstants' => 'applications/chatlog/constants/base',
@ -961,6 +963,7 @@ phutil_register_library_map(array(
'AphrontPagerView' => 'AphrontView',
'AphrontPanelView' => 'AphrontView',
'AphrontPlainTextResponse' => 'AphrontResponse',
'AphrontProxyResponse' => 'AphrontResponse',
'AphrontQueryAccessDeniedException' => 'AphrontQueryRecoverableException',
'AphrontQueryConnectionException' => 'AphrontQueryException',
'AphrontQueryConnectionLostException' => 'AphrontQueryRecoverableException',
@ -1265,6 +1268,7 @@ phutil_register_library_map(array(
'PhabricatorAuthController' => 'PhabricatorController',
'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController',
'PhabricatorCalendarController' => 'PhabricatorController',
'PhabricatorChangesetResponse' => 'AphrontProxyResponse',
'PhabricatorChatLogChannelListController' => 'PhabricatorChatLogController',
'PhabricatorChatLogChannelLogController' => 'PhabricatorChatLogController',
'PhabricatorChatLogController' => 'PhabricatorController',

View file

@ -0,0 +1,83 @@
<?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.
*/
/**
* Base class for responses which augment other types of responses. For example,
* a response might be substantially an Ajax response, but add structure to the
* response content. It can do this by extending @{class:AphrontProxyResponse},
* instantiating an @{class:AphrontAjaxResponse} in @{method:buildProxy}, and
* then using the proxy to construct the response string in
* @{method:buildResponseString}.
*
* @group aphront
*/
abstract class AphrontProxyResponse extends AphrontResponse {
private $proxy;
protected function getProxy() {
if (!$this->proxy) {
$this->proxy = $this->buildProxy();
}
return $this->proxy;
}
public function setRequest($request) {
$this->getProxy()->setRequest($request);
return $this;
}
public function getRequest() {
return $this->getProxy()->getRequest();
}
public function getHeaders() {
return $this->getProxy()->getHeaders();
}
public function setCacheDurationInSeconds($duration) {
$this->getProxy()->setCacheDurationInSeconds($duration);
return $this;
}
public function setLastModified($epoch_timestamp) {
$this->getProxy()->setLastModified($epoch_timestamp);
return $this;
}
public function setHTTPResponseCode($code) {
$this->getProxy()->setHTTPResponseCode($code);
return $this;
}
public function getHTTPResponseCode() {
return $this->getProxy()->getHTTPResponseCode();
}
public function setFrameable($frameable) {
$this->getProxy()->setFrameable($frameable);
return $this;
}
public function getCacheHeaders() {
return $this->getProxy()->getCacheHeaders();
}
abstract protected function buildProxy();
}

View file

@ -0,0 +1,12 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/base');
phutil_require_source('AphrontProxyResponse.php');

View file

@ -211,14 +211,13 @@ final class DifferentialChangesetViewController extends DifferentialController {
$mcov = $parser->renderModifiedCoverage();
if ($request->isAjax()) {
$content = array(
'coverage' => array(
$coverage = array(
'differential-mcoverage-'.md5($changeset->getFilename()) => $mcov,
),
'changeset' => $output,
);
return id(new AphrontAjaxResponse())
->setContent($content);
return id(new PhabricatorChangesetResponse())
->setRenderedChangeset($output)
->setCoverage($coverage);
}
Javelin::initBehavior('differential-show-more', array(

View file

@ -10,7 +10,6 @@ phutil_require_module('arcanist', 'unit/result');
phutil_require_module('phabricator', 'aphront/response/400');
phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'aphront/response/ajax');
phutil_require_module('phabricator', 'aphront/response/redirect');
phutil_require_module('phabricator', 'aphront/writeguard');
phutil_require_module('phabricator', 'applications/differential/controller/base');
@ -24,6 +23,7 @@ phutil_require_module('phabricator', 'applications/files/storage/file');
phutil_require_module('phabricator', 'applications/markup/engine');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'infrastructure/diff/engine');
phutil_require_module('phabricator', 'infrastructure/diff/response');
phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phutil', 'utils');

View file

@ -52,10 +52,7 @@ final class DiffusionDiffController extends DiffusionController {
DifferentialChangesetParser::parseRangeSpecification($spec);
$output = $parser->render($range_s, $range_e, $mask);
return id(new AphrontAjaxResponse())
->setContent(
array(
'changeset' => $output,
));
return id(new PhabricatorChangesetResponse())
->setRenderedChangeset($output);
}
}

View file

@ -7,11 +7,11 @@
phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'aphront/response/ajax');
phutil_require_module('phabricator', 'applications/differential/parser/changeset');
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
phutil_require_module('phabricator', 'applications/diffusion/query/diff/base');
phutil_require_module('phabricator', 'applications/diffusion/request/base');
phutil_require_module('phabricator', 'infrastructure/diff/response');
phutil_require_module('phutil', 'utils');

View file

@ -41,8 +41,10 @@ final class ManiphestTaskDescriptionChangeController
$request = $this->getRequest();
$user = $request->getUser();
$is_show_more = false;
if (!$this->getTransactionID()) {
$this->setTransactionID($this->getRequest()->getStr('ref'));
$is_show_more = true;
}
$transaction_id = $this->getTransactionID();
@ -72,10 +74,12 @@ final class ManiphestTaskDescriptionChangeController
$view->setRenderFullSummary(true);
$view->setRangeSpecification($request->getStr('range'));
return id(new AphrontAjaxResponse())->setContent(
array(
'changeset' => $view->render(),
));
if ($is_show_more) {
return id(new PhabricatorChangesetResponse())
->setRenderedChangeset($view->render());
} else {
return id(new AphrontAjaxResponse())->setContent($view->render());
}
}
}

View file

@ -13,6 +13,7 @@ phutil_require_module('phabricator', 'applications/maniphest/storage/transaction
phutil_require_module('phabricator', 'applications/maniphest/view/transactiondetail');
phutil_require_module('phabricator', 'applications/markup/engine');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'infrastructure/diff/response');
phutil_require_module('phutil', 'utils');

View file

@ -93,10 +93,8 @@ final class PhrictionDiffController
$output = $parser->render($range_s, $range_e, $mask);
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())->setContent(
array(
'changeset' => $output,
));
return id(new PhabricatorChangesetResponse())
->setRenderedChangeset($output);
}
require_celerity_resource('differential-changeset-view-css');

View file

@ -0,0 +1,50 @@
<?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.
*/
final class PhabricatorChangesetResponse extends AphrontProxyResponse {
private $renderedChangeset;
private $coverage;
public function setRenderedChangeset($rendered_changeset) {
$this->renderedChangeset = $rendered_changeset;
return $this;
}
public function setCoverage($coverage) {
$this->coverage = $coverage;
return $this;
}
protected function buildProxy() {
return new AphrontAjaxResponse();
}
public function buildResponseString() {
$content = array(
'changeset' => $this->renderedChangeset,
);
if ($this->coverage) {
$content['coverage'] = $this->coverage;
}
return $this->getProxy()->setContent($content)->buildResponseString();
}
}

View file

@ -0,0 +1,13 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/ajax');
phutil_require_module('phabricator', 'aphront/response/proxy');
phutil_require_source('PhabricatorChangesetResponse.php');