When a Paste has a useful alternative rendering in Files, provide a hint
Summary: Ref T13528. When a file in Paste (like a Jupyter notebook) has a good/useful document engine, provide a link to Files.
Test Plan: {F7409881}
Maniphest Tasks: T13528
Differential Revision: https://secure.phabricator.com/D21196
This commit is contained in:
@@ -121,6 +121,8 @@ final class DarkConsoleCore extends Phobject {
|
||||
$data[$key] = $this->sanitizeForJSON($value);
|
||||
}
|
||||
return $data;
|
||||
} else if (is_resource($data)) {
|
||||
return '<resource>';
|
||||
} else {
|
||||
// Truncate huge strings. Since the data doesn't really matter much,
|
||||
// just truncate bytes to avoid PhutilUTF8StringTruncator overhead.
|
||||
|
||||
@@ -281,4 +281,8 @@ abstract class PhabricatorDocumentEngine
|
||||
));
|
||||
}
|
||||
|
||||
public function shouldSuggestEngine(PhabricatorDocumentRef $ref) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -748,4 +748,8 @@ final class PhabricatorJupyterDocumentEngine
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function shouldSuggestEngine(PhabricatorDocumentRef $ref) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -305,6 +305,12 @@ abstract class PhabricatorDocumentRenderingEngine
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
public function getRefViewURI(
|
||||
PhabricatorDocumentRef $ref,
|
||||
PhabricatorDocumentEngine $engine) {
|
||||
return $this->newRefViewURI($ref, $engine);
|
||||
}
|
||||
|
||||
abstract protected function newRefViewURI(
|
||||
PhabricatorDocumentRef $ref,
|
||||
PhabricatorDocumentEngine $engine);
|
||||
|
||||
@@ -51,16 +51,19 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||
$timeline->setQuoteRef($monogram);
|
||||
$comment_view->setTransactionTimeline($timeline);
|
||||
|
||||
$recommendation_view = $this->newDocumentRecommendationView($paste);
|
||||
|
||||
$paste_view = id(new PHUITwoColumnView())
|
||||
->setHeader($header)
|
||||
->setSubheader($subheader)
|
||||
->setMainColumn(array(
|
||||
->setMainColumn(
|
||||
array(
|
||||
$recommendation_view,
|
||||
$source_code,
|
||||
$timeline,
|
||||
$comment_view,
|
||||
))
|
||||
->setCurtain($curtain)
|
||||
->addClass('ponder-question-view');
|
||||
->setCurtain($curtain);
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle($paste->getFullName())
|
||||
@@ -170,4 +173,58 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||
->setContent($content);
|
||||
}
|
||||
|
||||
private function newDocumentRecommendationView(PhabricatorPaste $paste) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
// See PHI1703. If a viewer is looking at a document in Paste which has
|
||||
// a good rendering via a DocumentEngine, suggest they view the content
|
||||
// in Files instead so they can see it rendered.
|
||||
|
||||
$ref = id(new PhabricatorDocumentRef())
|
||||
->setName($paste->getTitle())
|
||||
->setData($paste->getRawContent());
|
||||
|
||||
$engines = PhabricatorDocumentEngine::getEnginesForRef($viewer, $ref);
|
||||
if (!$engines) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$engine = head($engines);
|
||||
if (!$engine->shouldSuggestEngine($ref)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$file = id(new PhabricatorFileQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($paste->getFilePHID()))
|
||||
->executeOne();
|
||||
if (!$file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$file_ref = id(new PhabricatorDocumentRef())
|
||||
->setFile($file);
|
||||
|
||||
$view_uri = id(new PhabricatorFileDocumentRenderingEngine())
|
||||
->getRefViewURI($file_ref, $engine);
|
||||
|
||||
$view_as_label = $engine->getViewAsLabel($file_ref);
|
||||
|
||||
$view_as_hint = pht(
|
||||
'This content can be rendered as a document in Files.');
|
||||
|
||||
return id(new PHUIInfoView())
|
||||
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
||||
->addButton(
|
||||
id(new PHUIButtonView())
|
||||
->setTag('a')
|
||||
->setText($view_as_label)
|
||||
->setHref($view_uri)
|
||||
->setColor('grey'))
|
||||
->setErrors(
|
||||
array(
|
||||
$view_as_hint,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user