feat: dont download notebook if not necessary

This commit is contained in:
tdurieux
2023-02-23 16:21:08 +01:00
parent c59e202124
commit 8221b2ee7f
+19 -11
View File
@@ -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();