mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 12:52:42 +01:00
Add basic draft support to Phriction
Summary: - When a user is creating a Phriction document, save a draft as "phriction:<slug>". - When a user is editing a Phriction document, save a draft as "<document phid>:<document version>". - If a user has an available draft, use that instead of the native content. - If using a draft, tell the user and give them an option to discard it. - If a page is updated, your draft is lost (we show new page content unconditionally) but this should be rare and is the simplest way to resolve this issue in a realtively consistent way. Test Plan: - Recovered drafts for new and edited pages. - Used "nodraft" to discard drafts. Reviewers: davidreuss, btrahan, jungejason Reviewed By: davidreuss CC: aran, davidreuss Maniphest Tasks: T769 Differential Revision: https://secure.phabricator.com/D1378
This commit is contained in:
parent
cf35a640ec
commit
f5e1e3377c
4 changed files with 62 additions and 3 deletions
|
@ -27,6 +27,19 @@ class PhrictionDocumentPreviewController
|
|||
$request = $this->getRequest();
|
||||
$document = $request->getStr('document');
|
||||
|
||||
$draft_key = $request->getStr('draftkey');
|
||||
if ($draft_key) {
|
||||
$table = new PhabricatorDraft();
|
||||
queryfx(
|
||||
$table->establishConnection('w'),
|
||||
'INSERT INTO %T (authorPHID, draftKey, draft) VALUES (%s, %s, %s)
|
||||
ON DUPLICATE KEY UPDATE draft = VALUES(draft)',
|
||||
$table->getTableName(),
|
||||
$request->getUser()->getPHID(),
|
||||
$draft_key,
|
||||
$document);
|
||||
}
|
||||
|
||||
$content_obj = new PhrictionContent();
|
||||
$content_obj->setContent($document);
|
||||
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/ajax');
|
||||
phutil_require_module('phabricator', 'applications/draft/storage/draft');
|
||||
phutil_require_module('phabricator', 'applications/markup/engine');
|
||||
phutil_require_module('phabricator', 'applications/phriction/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/phriction/storage/content');
|
||||
phutil_require_module('phabricator', 'storage/queryfx');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* 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.
|
||||
|
@ -77,6 +77,21 @@ class PhrictionEditController
|
|||
}
|
||||
}
|
||||
|
||||
if ($request->getBool('nodraft')) {
|
||||
$draft = null;
|
||||
$draft_key = null;
|
||||
} else {
|
||||
if ($document->getPHID()) {
|
||||
$draft_key = $document->getPHID().':'.$content->getVersion();
|
||||
} else {
|
||||
$draft_key = 'phriction:'.$content->getSlug();
|
||||
}
|
||||
$draft = id(new PhabricatorDraft())->loadOneWhere(
|
||||
'authorPHID = %s AND draftKey = %s',
|
||||
$user->getPHID(),
|
||||
$draft_key);
|
||||
}
|
||||
|
||||
require_celerity_resource('phriction-document-css');
|
||||
|
||||
$e_title = true;
|
||||
|
@ -101,6 +116,10 @@ class PhrictionEditController
|
|||
|
||||
$editor->save();
|
||||
|
||||
if ($draft) {
|
||||
$draft->delete();
|
||||
}
|
||||
|
||||
$uri = PhrictionDocument::getSlugURI($document->getSlug());
|
||||
return id(new AphrontRedirectResponse())->setURI($uri);
|
||||
}
|
||||
|
@ -144,10 +163,33 @@ class PhrictionEditController
|
|||
|
||||
$cancel_uri = PhrictionDocument::getSlugURI($document->getSlug());
|
||||
|
||||
if ($draft &&
|
||||
strlen($draft->getDraft()) &&
|
||||
($draft->getDraft() != $content->getContent())) {
|
||||
$content_text = $draft->getDraft();
|
||||
|
||||
$discard = phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $request->getRequestURI()->alter('nodraft', true),
|
||||
),
|
||||
'discard this draft');
|
||||
|
||||
$draft_note = new AphrontErrorView();
|
||||
$draft_note->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
||||
$draft_note->setTitle('Recovered Draft');
|
||||
$draft_note->appendChild(
|
||||
'<p>Showing a saved draft of your edits, you can '.$discard.'.</p>');
|
||||
} else {
|
||||
$content_text = $content->getContent();
|
||||
$draft_note = null;
|
||||
}
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($user)
|
||||
->setAction($request->getRequestURI()->getPath())
|
||||
->addHiddenInput('slug', $document->getSlug())
|
||||
->addHiddenInput('nodraft', $request->getBool('nodraft'))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('Title')
|
||||
|
@ -161,7 +203,7 @@ class PhrictionEditController
|
|||
->appendChild(
|
||||
id(new AphrontFormTextAreaControl())
|
||||
->setLabel('Content')
|
||||
->setValue($content->getContent())
|
||||
->setValue($content_text)
|
||||
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
|
||||
->setName('content')
|
||||
->setID('document-textarea')
|
||||
|
@ -204,11 +246,12 @@ class PhrictionEditController
|
|||
array(
|
||||
'preview' => 'document-preview',
|
||||
'textarea' => 'document-textarea',
|
||||
'uri' => '/phriction/preview/',
|
||||
'uri' => '/phriction/preview/?draftkey='.$draft_key,
|
||||
));
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
array(
|
||||
$draft_note,
|
||||
$error_view,
|
||||
$panel,
|
||||
$preview_panel,
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/draft/storage/draft');
|
||||
phutil_require_module('phabricator', 'applications/phriction/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/phriction/editor/document');
|
||||
phutil_require_module('phabricator', 'applications/phriction/storage/content');
|
||||
|
|
Loading…
Reference in a new issue