1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

Differential comment previews.

This commit is contained in:
epriestley 2011-01-31 18:05:20 -08:00
parent 400524abf8
commit 4736b320ff
17 changed files with 241 additions and 23 deletions

View file

@ -27,7 +27,7 @@ celerity_register_resource_map(array(
),
'aphront-panel-view-css' =>
array(
'uri' => '/res/fe62e634/rsrc/css/aphront/panel-view.css',
'uri' => '/res/63672373/rsrc/css/aphront/panel-view.css',
'type' => 'css',
'requires' =>
array(
@ -36,7 +36,7 @@ celerity_register_resource_map(array(
),
'aphront-request-failure-view-css' =>
array(
'uri' => '/res/d7df3b42/rsrc/css/aphront/request-failure-view.css',
'uri' => '/res/97b8337a/rsrc/css/aphront/request-failure-view.css',
'type' => 'css',
'requires' =>
array(
@ -89,6 +89,15 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/css/application/base/standard-page-view.css',
),
'differential-revision-add-comment-css' =>
array(
'uri' => '/res/623fef21/rsrc/css/application/differential/add-comment.css',
'type' => 'css',
'requires' =>
array(
),
'disk' => '/rsrc/css/application/differential/add-comment.css',
),
'differential-changeset-view-css' =>
array(
'uri' => '/res/658d181a/rsrc/css/application/differential/changeset-view.css',
@ -207,6 +216,16 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/js/application/core/behavior-tokenizer.js',
),
'javelin-behavior-differential-feedback-preview' =>
array(
'uri' => '/res/34fbb670/rsrc/js/application/differential/behavior-comment-preview.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-lib-dev',
),
'disk' => '/rsrc/js/application/differential/behavior-comment-preview.js',
),
'javelin-behavior-differential-populate' =>
array(
'uri' => '/res/9982573c/rsrc/js/application/differential/behavior-populate.js',
@ -274,7 +293,7 @@ celerity_register_resource_map(array(
), array (
'packages' =>
array (
'364a306c' =>
'd348c79d' =>
array (
'name' => 'core.pkg.css',
'symbols' =>
@ -291,7 +310,7 @@ celerity_register_resource_map(array(
9 => 'aphront-typeahead-control-css',
10 => 'phabricator-directory-css',
),
'uri' => '/res/pkg/364a306c/core.pkg.css',
'uri' => '/res/pkg/d348c79d/core.pkg.css',
'type' => 'css',
),
'69b11588' =>
@ -311,17 +330,17 @@ celerity_register_resource_map(array(
),
'reverse' =>
array (
'phabricator-core-css' => '364a306c',
'phabricator-core-buttons-css' => '364a306c',
'phabricator-standard-page-view' => '364a306c',
'aphront-dialog-view-css' => '364a306c',
'aphront-form-view-css' => '364a306c',
'aphront-panel-view-css' => '364a306c',
'aphront-side-nav-view-css' => '364a306c',
'aphront-table-view-css' => '364a306c',
'aphront-tokenizer-control-css' => '364a306c',
'aphront-typeahead-control-css' => '364a306c',
'phabricator-directory-css' => '364a306c',
'phabricator-core-css' => 'd348c79d',
'phabricator-core-buttons-css' => 'd348c79d',
'phabricator-standard-page-view' => 'd348c79d',
'aphront-dialog-view-css' => 'd348c79d',
'aphront-form-view-css' => 'd348c79d',
'aphront-panel-view-css' => 'd348c79d',
'aphront-side-nav-view-css' => 'd348c79d',
'aphront-table-view-css' => 'd348c79d',
'aphront-tokenizer-control-css' => 'd348c79d',
'aphront-typeahead-control-css' => 'd348c79d',
'phabricator-directory-css' => 'd348c79d',
'differential-core-view-css' => '69b11588',
'differential-changeset-view-css' => '69b11588',
'differential-revision-detail-css' => '69b11588',

View file

@ -80,6 +80,7 @@ phutil_register_library_map(array(
'DifferentialComment' => 'applications/differential/storage/comment',
'DifferentialCommentEditor' => 'applications/differential/editor/comment',
'DifferentialCommentMail' => 'applications/differential/mail/comment',
'DifferentialCommentPreviewController' => 'applications/differential/controller/commentpreview',
'DifferentialCommentSaveController' => 'applications/differential/controller/commentsave',
'DifferentialController' => 'applications/differential/controller/base',
'DifferentialDAO' => 'applications/differential/storage/base',
@ -253,6 +254,7 @@ phutil_register_library_map(array(
'DifferentialChangesetViewController' => 'DifferentialController',
'DifferentialComment' => 'DifferentialDAO',
'DifferentialCommentMail' => 'DifferentialMail',
'DifferentialCommentPreviewController' => 'DifferentialController',
'DifferentialCommentSaveController' => 'DifferentialController',
'DifferentialController' => 'PhabricatorController',
'DifferentialDAO' => 'PhabricatorLiskDAO',

View file

@ -87,7 +87,7 @@ class AphrontDefaultApplicationConfiguration
'revision/edit/(?:(?<id>\d+)/)?$'
=> 'DifferentialRevisionEditController',
'comment/' => array(
'preview/$' => 'DifferentialCommentPreviewController',
'preview/(?<id>\d+)/$' => 'DifferentialCommentPreviewController',
'save/$' => 'DifferentialCommentSaveController',
'inline/' => array(
'preview/$' => 'DifferentialInlineCommentPreviewController',

View file

@ -14,6 +14,7 @@ phutil_require_module('phabricator', 'applications/differential/constants/revisi
phutil_require_module('phabricator', 'applications/differential/constants/unitstatus');
phutil_require_module('phabricator', 'applications/differential/storage/diff');
phutil_require_module('phabricator', 'applications/differential/storage/revision');
phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phutil', 'utils');

View file

@ -0,0 +1,54 @@
<?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 DifferentialCommentPreviewController extends DifferentialController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$author_phid = $request->getUser()->getPHID();
$handles = id(new PhabricatorObjectHandleData(array($author_phid)))
->loadHandles();
$factory = new DifferentialMarkupEngineFactory();
$engine = $factory->newDifferentialCommentMarkupEngine();
$comment = new DifferentialComment();
$comment->setContent($request->getStr('content'));
$comment->setAction($request->getStr('action'));
$comment->setAuthorPHID($author_phid);
$view = new DifferentialRevisionCommentView();
$view->setComment($comment);
$view->setHandles($handles);
$view->setMarkupEngine($engine);
$view->setPreview(true);
return id(new AphrontAjaxResponse())
->setContent($view->render());
}
}

View file

@ -0,0 +1,19 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/ajax');
phutil_require_module('phabricator', 'applications/differential/controller/base');
phutil_require_module('phabricator', 'applications/differential/parser/markup');
phutil_require_module('phabricator', 'applications/differential/storage/comment');
phutil_require_module('phabricator', 'applications/differential/view/revisioncomment');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialCommentPreviewController.php');

View file

@ -7,6 +7,7 @@
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_source('DifferentialMail.php');

View file

@ -42,6 +42,9 @@ final class DifferentialAddCommentView extends AphrontView {
}
public function render() {
require_celerity_resource('differential-revision-add-comment-css');
$revision = $this->revision;
$actions = array();
@ -58,19 +61,39 @@ final class DifferentialAddCommentView extends AphrontView {
id(new AphrontFormSelectControl())
->setLabel('Action')
->setName('action')
->setID('comment-action')
->setOptions($actions))
->appendChild(
id(new AphrontFormTextAreaControl())
->setName('comment')
->setID('comment-content')
->setLabel('Comment'))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Comment'));
Javelin::initBehavior(
'differential-feedback-preview',
array(
'uri' => '/differential/comment/preview/'.$revision->getID().'/',
'preview' => 'comment-preview',
'action' => 'comment-action',
'content' => 'comment-content',
));
return
'<div class="differential-panel">'.
'<h1>Add Comment</h1>'.
$form->render().
'<div class="differential-add-comment-panel">'.
'<div class="differential-panel">'.
'<h1>Add Comment</h1>'.
$form->render().
'</div>'.
'<div class="differential-comment-preview">'.
'<div id="comment-preview">'.
'<span class="differential-loading-text">'.
'Loading comment preview...'.
'</span>'.
'</div>'.
'</div>'.
'</div>';
}
}

View file

@ -7,6 +7,8 @@
phutil_require_module('phabricator', 'applications/differential/constants/action');
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/submit');

View file

@ -21,6 +21,7 @@ final class DifferentialRevisionCommentView extends AphrontView {
private $comment;
private $handles;
private $markupEngine;
private $preview;
public function setComment($comment) {
$this->comment = $comment;
@ -37,6 +38,11 @@ final class DifferentialRevisionCommentView extends AphrontView {
return $this;
}
public function setPreview($preview) {
$this->preview = $preview;
return $this;
}
public function render() {
require_celerity_resource('phabricator-remarkup-css');
@ -48,7 +54,11 @@ final class DifferentialRevisionCommentView extends AphrontView {
$action_class = 'differential-comment-action-'.phutil_escape_html($action);
$date = date('F jS, Y g:i:s A', $comment->getDateCreated());
if ($this->preview) {
$date = 'COMMENT PREVIEW';
} else {
$date = date('F jS, Y g:i:s A', $comment->getDateCreated());
}
$author = $this->handles[$comment->getAuthorPHID()];
$author_link = $author->renderLink();

View file

@ -24,6 +24,16 @@ abstract class AphrontFormControl extends AphrontView {
private $name;
private $value;
private $disabled;
private $id;
public function setID($id) {
$this->id = $id;
return $this;
}
public function getID() {
return $this->id;
}
public function setLabel($label) {
$this->label = $label;

View file

@ -30,6 +30,7 @@ class AphrontFormPasswordControl extends AphrontFormControl {
'name' => $this->getName(),
'value' => $this->getValue(),
'disabled' => $this->getDisabled() ? 'disabled' : null,
'id' => $this->getID(),
));
}

View file

@ -50,6 +50,7 @@ class AphrontFormSelectControl extends AphrontFormControl {
array(
'name' => $this->getName(),
'disabled' => $this->getDisabled() ? 'disabled' : null,
'id' => $this->getID(),
),
implode("\n", $options));
}

View file

@ -30,6 +30,7 @@ class AphrontFormTextControl extends AphrontFormControl {
'name' => $this->getName(),
'value' => $this->getValue(),
'disabled' => $this->getDisabled() ? 'disabled' : null,
'id' => $this->getID(),
));
}

View file

@ -48,6 +48,7 @@ class AphrontFormTextAreaControl extends AphrontFormControl {
'name' => $this->getName(),
'disabled' => $this->getDisabled() ? 'disabled' : null,
'class' => $height_class,
'id' => $this->getID(),
),
phutil_escape_html($this->getValue()));
}

View file

@ -0,0 +1,23 @@
/**
* @provides differential-revision-add-comment-css
*/
.differential-add-comment-panel .aphront-form-view {
background: #fffff5;
}
.differential-add-comment-panel .differential-panel {
margin-bottom: 0;
}
.differential-comment-preview {
background: #f0f0f0;
border-bottom: 1px solid #aaaaaa;
margin-bottom: 2em;
max-width: 1120px;
padding: 15px 20px;
}
.differential-comment-preview .differential-loading-text {
color: #aaaaaa;
}

View file

@ -0,0 +1,50 @@
/**
* @provides javelin-behavior-differential-feedback-preview
* @requires javelin-lib-dev
*/
JX.behavior('differential-feedback-preview', function(config) {
var action = JX.$(config.action);
var content = JX.$(config.content);
var preview = JX.$(config.preview);
var aval = null;//action.value;
var cval = null;//content.value;
var defer = null;
var min = null;
var request = null;
function check() {
if (request || (min && (new Date().getTime() < min))) {
// Waiting on an async or just got one back, rate-limit.
return;
}
defer && defer.stop();
if (action.value !== aval || content.value !== cval) {
aval = action.value;
cval = content.value;
request = new JX.Request(config.uri, function(r) {
preview && JX.DOM.setContent(preview, JX.HTML(r));
min = new Date().getTime() + 500;
defer && defer.stop();
defer = JX.defer(check, 500);
});
request.listen('finally', function() { request = null; });
request.setData({action : aval, content : cval});
// If we don't get a response back soon, retry on the next action.
request.setTimeout(2000);
request.send();
} else {
defer = JX.defer(check, 2000);
}
}
JX.DOM.listen(content, 'keydown', null, check);
JX.DOM.listen(action, 'change', null, check);
check();
});