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

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:
epriestley 2020-05-01 06:00:37 -07:00
parent 65a2b5e219
commit 3c1f393c81
5 changed files with 76 additions and 3 deletions

View file

@ -121,6 +121,8 @@ final class DarkConsoleCore extends Phobject {
$data[$key] = $this->sanitizeForJSON($value); $data[$key] = $this->sanitizeForJSON($value);
} }
return $data; return $data;
} else if (is_resource($data)) {
return '<resource>';
} else { } else {
// Truncate huge strings. Since the data doesn't really matter much, // Truncate huge strings. Since the data doesn't really matter much,
// just truncate bytes to avoid PhutilUTF8StringTruncator overhead. // just truncate bytes to avoid PhutilUTF8StringTruncator overhead.

View file

@ -281,4 +281,8 @@ abstract class PhabricatorDocumentEngine
)); ));
} }
public function shouldSuggestEngine(PhabricatorDocumentRef $ref) {
return false;
}
} }

View file

@ -748,4 +748,8 @@ final class PhabricatorJupyterDocumentEngine
return $content; return $content;
} }
public function shouldSuggestEngine(PhabricatorDocumentRef $ref) {
return true;
}
} }

View file

@ -305,6 +305,12 @@ abstract class PhabricatorDocumentRenderingEngine
return $crumbs; return $crumbs;
} }
public function getRefViewURI(
PhabricatorDocumentRef $ref,
PhabricatorDocumentEngine $engine) {
return $this->newRefViewURI($ref, $engine);
}
abstract protected function newRefViewURI( abstract protected function newRefViewURI(
PhabricatorDocumentRef $ref, PhabricatorDocumentRef $ref,
PhabricatorDocumentEngine $engine); PhabricatorDocumentEngine $engine);

View file

@ -51,16 +51,19 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
$timeline->setQuoteRef($monogram); $timeline->setQuoteRef($monogram);
$comment_view->setTransactionTimeline($timeline); $comment_view->setTransactionTimeline($timeline);
$recommendation_view = $this->newDocumentRecommendationView($paste);
$paste_view = id(new PHUITwoColumnView()) $paste_view = id(new PHUITwoColumnView())
->setHeader($header) ->setHeader($header)
->setSubheader($subheader) ->setSubheader($subheader)
->setMainColumn(array( ->setMainColumn(
array(
$recommendation_view,
$source_code, $source_code,
$timeline, $timeline,
$comment_view, $comment_view,
)) ))
->setCurtain($curtain) ->setCurtain($curtain);
->addClass('ponder-question-view');
return $this->newPage() return $this->newPage()
->setTitle($paste->getFullName()) ->setTitle($paste->getFullName())
@ -170,4 +173,58 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
->setContent($content); ->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,
));
}
} }