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

Add a document preview to Phriction

Summary: Preview Phriction documents as they are edited, similar to how
Differential/Maniphest work.
Test Plan: Mashed my keyboard while editing a Phriction document.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 684
This commit is contained in:
epriestley 2011-07-16 18:25:45 -07:00
parent 86783fcd07
commit 4a3ebd9a68
11 changed files with 200 additions and 54 deletions

View file

@ -90,7 +90,7 @@ celerity_register_resource_map(array(
),
'aphront-panel-view-css' =>
array(
'uri' => '/res/e0139b9c/rsrc/css/aphront/panel-view.css',
'uri' => '/res/58da9c70/rsrc/css/aphront/panel-view.css',
'type' => 'css',
'requires' =>
array(
@ -293,6 +293,17 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/js/javelin/lib/behavior.js',
),
0 =>
array(
'uri' => '/res/1da00bfe/rsrc/js/javelin/lib/__tests__/URI.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-uri',
1 => 'javelin-php-serializer',
),
'disk' => '/rsrc/js/javelin/lib/__tests__/URI.js',
),
'javelin-behavior-aphront-basic-tokenizer' =>
array(
'uri' => '/res/5e183bd5/rsrc/js/application/core/behavior-tokenizer.js',
@ -590,17 +601,6 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/js/application/maniphest/behavior-transaction-preview.js',
),
0 =>
array(
'uri' => '/res/1da00bfe/rsrc/js/javelin/lib/__tests__/URI.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-uri',
1 => 'javelin-php-serializer',
),
'disk' => '/rsrc/js/javelin/lib/__tests__/URI.js',
),
'javelin-behavior-owners-path-editor' =>
array(
'uri' => '/res/9cf78ffc/rsrc/js/application/owners/owners-path-editor.js',
@ -652,6 +652,19 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/js/application/core/behavior-watch-anchor.js',
),
'javelin-behavior-phriction-document-preview' =>
array(
'uri' => '/res/f1665ecd/rsrc/js/application/phriction/phriction-document-preview.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-behavior',
1 => 'javelin-dom',
2 => 'javelin-util',
3 => 'phabricator-shaped-request',
),
'disk' => '/rsrc/js/application/phriction/phriction-document-preview.js',
),
'javelin-behavior-refresh-csrf' =>
array(
'uri' => '/res/39aa51f7/rsrc/js/application/core/behavior-refresh-csrf.js',
@ -1149,7 +1162,7 @@ celerity_register_resource_map(array(
),
'phriction-document-css' =>
array(
'uri' => '/res/77d5f57f/rsrc/css/application/phriction/phriction-document-css.css',
'uri' => '/res/84784c2d/rsrc/css/application/phriction/phriction-document-css.css',
'type' => 'css',
'requires' =>
array(
@ -1194,6 +1207,30 @@ celerity_register_resource_map(array(
'uri' => '/res/pkg/25f94e94/typeahead.pkg.js',
'type' => 'js',
),
'2ac15016' =>
array (
'name' => 'core.pkg.css',
'symbols' =>
array (
0 => 'phabricator-core-css',
1 => 'phabricator-core-buttons-css',
2 => 'phabricator-standard-page-view',
3 => 'aphront-dialog-view-css',
4 => 'aphront-form-view-css',
5 => 'aphront-panel-view-css',
6 => 'aphront-side-nav-view-css',
7 => 'aphront-table-view-css',
8 => 'aphront-crumbs-view-css',
9 => 'aphront-tokenizer-control-css',
10 => 'aphront-typeahead-control-css',
11 => 'aphront-list-filter-view-css',
12 => 'phabricator-directory-css',
13 => 'phabricator-remarkup-css',
14 => 'syntax-highlighting-css',
),
'uri' => '/res/pkg/2ac15016/core.pkg.css',
'type' => 'css',
),
'307df223' =>
array (
'name' => 'javelin.pkg.js',
@ -1230,30 +1267,6 @@ celerity_register_resource_map(array(
'uri' => '/res/pkg/95b66c1a/differential.pkg.css',
'type' => 'css',
),
'a06761eb' =>
array (
'name' => 'core.pkg.css',
'symbols' =>
array (
0 => 'phabricator-core-css',
1 => 'phabricator-core-buttons-css',
2 => 'phabricator-standard-page-view',
3 => 'aphront-dialog-view-css',
4 => 'aphront-form-view-css',
5 => 'aphront-panel-view-css',
6 => 'aphront-side-nav-view-css',
7 => 'aphront-table-view-css',
8 => 'aphront-crumbs-view-css',
9 => 'aphront-tokenizer-control-css',
10 => 'aphront-typeahead-control-css',
11 => 'aphront-list-filter-view-css',
12 => 'phabricator-directory-css',
13 => 'phabricator-remarkup-css',
14 => 'syntax-highlighting-css',
),
'uri' => '/res/pkg/a06761eb/core.pkg.css',
'type' => 'css',
),
'd0713563' =>
array (
'name' => 'workflow.pkg.js',
@ -1287,15 +1300,15 @@ celerity_register_resource_map(array(
),
'reverse' =>
array (
'aphront-crumbs-view-css' => 'a06761eb',
'aphront-dialog-view-css' => 'a06761eb',
'aphront-form-view-css' => 'a06761eb',
'aphront-list-filter-view-css' => 'a06761eb',
'aphront-panel-view-css' => 'a06761eb',
'aphront-side-nav-view-css' => 'a06761eb',
'aphront-table-view-css' => 'a06761eb',
'aphront-tokenizer-control-css' => 'a06761eb',
'aphront-typeahead-control-css' => 'a06761eb',
'aphront-crumbs-view-css' => '2ac15016',
'aphront-dialog-view-css' => '2ac15016',
'aphront-form-view-css' => '2ac15016',
'aphront-list-filter-view-css' => '2ac15016',
'aphront-panel-view-css' => '2ac15016',
'aphront-side-nav-view-css' => '2ac15016',
'aphront-table-view-css' => '2ac15016',
'aphront-tokenizer-control-css' => '2ac15016',
'aphront-typeahead-control-css' => '2ac15016',
'differential-changeset-view-css' => '95b66c1a',
'differential-core-view-css' => '95b66c1a',
'differential-revision-add-comment-css' => '95b66c1a',
@ -1332,13 +1345,13 @@ celerity_register_resource_map(array(
'javelin-util' => '307df223',
'javelin-vector' => '307df223',
'javelin-workflow' => 'd0713563',
'phabricator-core-buttons-css' => 'a06761eb',
'phabricator-core-css' => 'a06761eb',
'phabricator-directory-css' => 'a06761eb',
'phabricator-core-buttons-css' => '2ac15016',
'phabricator-core-css' => '2ac15016',
'phabricator-directory-css' => '2ac15016',
'phabricator-keyboard-shortcut' => 'd0713563',
'phabricator-keyboard-shortcut-manager' => 'd0713563',
'phabricator-remarkup-css' => 'a06761eb',
'phabricator-standard-page-view' => 'a06761eb',
'syntax-highlighting-css' => 'a06761eb',
'phabricator-remarkup-css' => '2ac15016',
'phabricator-standard-page-view' => '2ac15016',
'syntax-highlighting-css' => '2ac15016',
),
));

View file

@ -592,6 +592,7 @@ phutil_register_library_map(array(
'PhrictionDAO' => 'applications/phriction/storage/base',
'PhrictionDocument' => 'applications/phriction/storage/document',
'PhrictionDocumentController' => 'applications/phriction/controller/document',
'PhrictionDocumentPreviewController' => 'applications/phriction/controller/documentpreview',
'PhrictionDocumentTestCase' => 'applications/phriction/storage/document/__tests__',
'PhrictionEditController' => 'applications/phriction/controller/edit',
'PhrictionHistoryController' => 'applications/phriction/controller/history',
@ -1097,6 +1098,7 @@ phutil_register_library_map(array(
'PhrictionDAO' => 'PhabricatorLiskDAO',
'PhrictionDocument' => 'PhrictionDAO',
'PhrictionDocumentController' => 'PhrictionController',
'PhrictionDocumentPreviewController' => 'PhrictionController',
'PhrictionDocumentTestCase' => 'PhabricatorTestCase',
'PhrictionEditController' => 'PhrictionController',
'PhrictionHistoryController' => 'PhrictionController',

View file

@ -355,6 +355,8 @@ class AphrontDefaultApplicationConfiguration
'history/(?P<slug>.+/)$' => 'PhrictionHistoryController',
'edit/(?:(?P<id>\d+)/)?$' => 'PhrictionEditController',
'preview/$' => 'PhrictionDocumentPreviewController',
),
);
}

View file

@ -41,6 +41,10 @@ class PhabricatorMarkupEngine {
public static function newPhrictionMarkupEngine() {
return self::newMarkupEngine(array(
// Disable image macros on the wiki since they're less useful, we don't
// cache documents, and the module is prohibitively expensive for large
// documents.
'macros' => false,
));
}
@ -71,6 +75,7 @@ class PhabricatorMarkupEngine {
'remarkup.enable-embedded-youtube'),
'custom-inline' => array(),
'custom-block' => array(),
'macros' => true,
);
}
@ -99,7 +104,11 @@ class PhabricatorMarkupEngine {
$rules[] = new PhabricatorRemarkupRuleDiffusion();
$rules[] = new PhabricatorRemarkupRuleManiphest();
$rules[] = new PhabricatorRemarkupRulePaste();
$rules[] = new PhabricatorRemarkupRuleImageMacro();
if ($options['macros']) {
$rules[] = new PhabricatorRemarkupRuleImageMacro();
}
$rules[] = new PhabricatorRemarkupRuleMention();
$rules[] = new PhabricatorRemarkupRulePhriction();

View file

@ -0,0 +1,35 @@
<?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 PhrictionDocumentPreviewController
extends PhrictionController {
public function processRequest() {
$request = $this->getRequest();
$document = $request->getStr('document');
$engine = PhabricatorMarkupEngine::newPhrictionMarkupEngine();
$content =
'<div class="phabricator-remarkup">'.
$engine->markupText($document).
'</div>';
return id(new AphrontAjaxResponse())->setContent($content);
}
}

View file

@ -0,0 +1,16 @@
<?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/markup/engine');
phutil_require_module('phabricator', 'applications/phriction/controller/base');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhrictionDocumentPreviewController.php');

View file

@ -60,6 +60,8 @@ class PhrictionEditController
return new Aphront404Response();
}
require_celerity_resource('phriction-document-css');
$e_title = true;
$errors = array();
@ -133,7 +135,7 @@ class PhrictionEditController
if ($document->getID()) {
$panel_header = 'Edit Phriction Document';
$submit_button = 'Edit Document';
$submit_button = 'Save Changes';
} else {
$panel_header = 'Create New Phriction Document';
$submit_button = 'Create Document';
@ -172,6 +174,7 @@ class PhrictionEditController
->setValue($content->getContent())
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
->setName('content')
->setID('document-textarea')
->setCaption($remarkup_reference))
->appendChild(
id(new AphrontFormSubmitControl())
@ -183,10 +186,31 @@ class PhrictionEditController
->setHeader($panel_header)
->appendChild($form);
$preview_panel =
'<div class="aphront-panel-preview aphront-panel-preview-wide">
<div class="phriction-document-preview-header">
Document Preview
</div>
<div id="document-preview">
<div class="aphront-panel-preview-loading-text">
Loading preview...
</div>
</div>
</div>';
Javelin::initBehavior(
'phriction-document-preview',
array(
'preview' => 'document-preview',
'textarea' => 'document-textarea',
'uri' => '/phriction/preview/',
));
return $this->buildStandardPageResponse(
array(
$error_view,
$panel,
$preview_panel,
),
array(
'title' => 'Edit Document',

View file

@ -15,7 +15,9 @@ 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', 'applications/search/index/indexer/phriction');
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/static');
phutil_require_module('phabricator', 'view/form/control/submit');

View file

@ -55,6 +55,14 @@
padding: 15px 20px;
}
.aphront-panel-preview-wide {
width: 1080px;
margin-left: auto;
margin-right: auto;
padding-left: 2em;
padding-right: 2em;
}
.aphront-panel-preview-loading-text {
color: #666666;
}

View file

@ -56,3 +56,9 @@
margin: 0;
font-weight: bold;
}
.phriction-document-preview-header {
color: #666666;
margin-bottom: 1em;
font-size: 11px;
}

View file

@ -0,0 +1,29 @@
/**
* @provides javelin-behavior-phriction-document-preview
* @requires javelin-behavior
* javelin-dom
* javelin-util
* phabricator-shaped-request
*/
JX.behavior('phriction-document-preview', function(config) {
var preview = JX.$(config.preview);
var textarea = JX.$(config.textarea);
var callback = function(r) {
JX.DOM.setContent(JX.$(config.preview), JX.$H(r));
};
var getdata = function() {
return {
document : textarea.value
};
}
var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata);
var trigger = JX.bind(request, request.trigger);
JX.DOM.listen(textarea, 'keydown', null, trigger);
request.start();
});