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
+14 -6
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 render() { function renderNotebookJSON(json) {
if (!$scope.file) return; $element.html("");
$http.get($scope.file).then((res) => { const notebook = nb.parse(json);
var notebook = nb.parse(res.data);
try { try {
var rendered = notebook.render(); const rendered = notebook.render();
$element.append(rendered); $element.append(rendered);
Prism.highlightAll(); Prism.highlightAll();
} catch (error) { } catch (error) {
$element.html("Unable to render the notebook."); $element.html("Unable to render the notebook.");
} }
}); }
function render() {
// $element.html("");
if ($scope.$parent.content) {
renderNotebookJSON(JSON.parse($scope.$parent.content));
} else if ($scope.file) {
$http
.get($scope.file.download_url)
.then((res) => renderNotebookJSON(res.data));
}
} }
$scope.$watch("file", (v) => { $scope.$watch("file", (v) => {
render(); render();