From ca646b27fcf071ab30410d1b85d26a9cc2f84cd5 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Wed, 21 Apr 2021 18:39:05 +0200 Subject: [PATCH] improve repository loading --- public/partials/pageView.htm | 1 + public/script/app.js | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/public/partials/pageView.htm b/public/partials/pageView.htm index e3544ba..df89964 100644 --- a/public/partials/pageView.htm +++ b/public/partials/pageView.htm @@ -7,4 +7,5 @@

Error

+

Loading...

Empty file!

\ No newline at end of file diff --git a/public/script/app.js b/public/script/app.js index 8f27796..f37ce79 100644 --- a/public/script/app.js +++ b/public/script/app.js @@ -929,8 +929,14 @@ angular const imageFiles = ["png", "jpg", "jpeg", "gif"]; $scope.repoId = $routeParams.repoId; + $scope.type = "loading"; + $scope.filePath = $routeParams.path || ""; + $scope.paths = $scope.filePath.split("/"); $scope.$on("$routeUpdate", function(event, current, old) { + $scope.filePath = $routeParams.path || ""; + $scope.paths = $scope.filePath.split("/"); + updateContent(); }); @@ -946,6 +952,7 @@ angular if (uri[uri.length - 1] != "/") { uri += "/"; } + // redirect to readme $location.url(uri + file); } @@ -972,6 +979,7 @@ angular } ); } + async function getOptions(callback) { $http.get(`/api/repo/${$scope.repoId}/options`).then( (res) => { @@ -986,19 +994,12 @@ angular } }, (err) => { - $scope.error = err.data.error; + $scope.type = "error"; + $scope.content = err.data.error; } ); } - getOptions((options) => { - getFiles(() => { - if (options.mode == "download") { - getStats(); - } - }); - }); - function getMode(extension) { if (extensionModes[extension]) { return extensionModes[extension]; @@ -1069,9 +1070,6 @@ angular } function updateContent() { - $scope.filePath = $routeParams.path || ""; - $scope.paths = $scope.filePath.split("/"); - $scope.content = ""; $scope.url = `/api/repo/${$scope.repoId}/file/${$scope.filePath}`; @@ -1142,6 +1140,14 @@ angular getContent($scope.filePath); } - updateContent(); + getOptions((options) => { + getFiles(() => { + updateContent(); + + if (options.mode == "download") { + getStats(); + } + }); + }); }, ]);