mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-06 13:47:59 +02:00
feat: dont download notebook if not necessary
This commit is contained in:
+19
-11
@@ -415,18 +415,26 @@ angular
|
|||||||
restrict: "E",
|
restrict: "E",
|
||||||
scope: { file: "=" },
|
scope: { file: "=" },
|
||||||
controller: function ($element, $scope, $http) {
|
controller: function ($element, $scope, $http) {
|
||||||
|
function renderNotebookJSON(json) {
|
||||||
|
$element.html("");
|
||||||
|
const notebook = nb.parse(json);
|
||||||
|
try {
|
||||||
|
const rendered = notebook.render();
|
||||||
|
$element.append(rendered);
|
||||||
|
Prism.highlightAll();
|
||||||
|
} catch (error) {
|
||||||
|
$element.html("Unable to render the notebook.");
|
||||||
|
}
|
||||||
|
}
|
||||||
function render() {
|
function render() {
|
||||||
if (!$scope.file) return;
|
// $element.html("");
|
||||||
$http.get($scope.file).then((res) => {
|
if ($scope.$parent.content) {
|
||||||
var notebook = nb.parse(res.data);
|
renderNotebookJSON(JSON.parse($scope.$parent.content));
|
||||||
try {
|
} else if ($scope.file) {
|
||||||
var rendered = notebook.render();
|
$http
|
||||||
$element.append(rendered);
|
.get($scope.file.download_url)
|
||||||
Prism.highlightAll();
|
.then((res) => renderNotebookJSON(res.data));
|
||||||
} catch (error) {
|
}
|
||||||
$element.html("Unable to render the notebook.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
$scope.$watch("file", (v) => {
|
$scope.$watch("file", (v) => {
|
||||||
render();
|
render();
|
||||||
|
|||||||
Reference in New Issue
Block a user