From 1d4eb7a1b086f38d3a020b76aafb120e8a7e9b6d Mon Sep 17 00:00:00 2001 From: tdurieux Date: Wed, 22 Feb 2023 09:21:14 +0100 Subject: [PATCH] fix: fix action menu in the admin --- public/partials/admin/user.htm | 58 ++++++++++++++++++++++++++++++++ public/script/admin.js | 61 +++++++++++++++++++++++++++++++++- src/Repository.ts | 7 ++-- src/routes/admin.ts | 22 ++++++++---- 4 files changed, 138 insertions(+), 10 deletions(-) diff --git a/public/partials/admin/user.htm b/public/partials/admin/user.htm index 8a4d7e4..71b0066 100644 --- a/public/partials/admin/user.htm +++ b/public/partials/admin/user.htm @@ -245,6 +245,64 @@ > +
+ +
  • { + const toast = { + title: `Refreshing ${repo.repoId}...`, + date: new Date(), + body: `The repository ${repo.repoId} is going to be refreshed.`, + }; + $scope.toasts.push(toast); + repo.s; + + $http.post(`/api/repo/${repo.repoId}/refresh`).then( + (res) => { + if (res.data.status == "ready") { + toast.title = `${repo.repoId} is refreshed.`; + } else { + toast.title = `Refreshing of ${repo.repoId}.`; + } + }, + (error) => { + toast.title = `Error during the refresh of ${repo.repoId}.`; + toast.body = error.body; + } + ); + }; + function getRepositories() { $http.get("/api/admin/repos", { params: $scope.query }).then( (res) => { $scope.total = res.data.total; $scope.totalPage = Math.ceil(res.data.total / $scope.query.limit); $scope.repositories = res.data.results; - $scope.$apply(); }, (err) => { console.error(err); @@ -172,6 +196,41 @@ angular getUser($routeParams.username); getUserRepositories($routeParams.username); + $scope.removeCache = (repo) => { + $http.delete("/api/admin/repos/" + repo.repoId).then( + (res) => { + $scope.$apply(); + }, + (err) => { + console.error(err); + } + ); + }; + + $scope.updateRepository = (repo) => { + const toast = { + title: `Refreshing ${repo.repoId}...`, + date: new Date(), + body: `The repository ${repo.repoId} is going to be refreshed.`, + }; + $scope.toasts.push(toast); + repo.s; + + $http.post(`/api/repo/${repo.repoId}/refresh`).then( + (res) => { + if (res.data.status == "ready") { + toast.title = `${repo.repoId} is refreshed.`; + } else { + toast.title = `Refreshing of ${repo.repoId}.`; + } + }, + (error) => { + toast.title = `Error during the refresh of ${repo.repoId}.`; + toast.body = error.body; + } + ); + }; + let timeClear = null; $scope.$watch( "query", diff --git a/src/Repository.ts b/src/Repository.ts index 0389b95..58bd244 100644 --- a/src/Repository.ts +++ b/src/Repository.ts @@ -196,7 +196,7 @@ export default class Repository { const newCommit = branches.filter((f) => f.name == branch.name)[0] ?.commit; if (branch.commit == newCommit && this.status == "ready") { - console.log(`${this._model.repoId} is up to date`); + console.log(`[UPDATE] ${this._model.repoId} is up to date`); return; } this._model.source.commit = newCommit; @@ -370,7 +370,10 @@ export default class Repository { } get originalCachePath() { - return join(this._model.repoId, "original") + (process.platform === "win32" ? "\\" : "/"); + return ( + join(this._model.repoId, "original") + + (process.platform === "win32" ? "\\" : "/") + ); } get status() { diff --git a/src/routes/admin.ts b/src/routes/admin.ts index fe478fc..e0f19ef 100644 --- a/src/routes/admin.ts +++ b/src/routes/admin.ts @@ -139,17 +139,25 @@ router.get("/repos", async (req, res) => { status.push({ status: "download" }); } const skipIndex = (page - 1) * limit; + const [total, results] = await Promise.all([ + AnonymizedRepositoryModel.find( + { + $and: query, + }, + { originalFiles: 0 } + ).countDocuments(), + AnonymizedRepositoryModel.find({ $and: query }, { originalFiles: 0 }) + .skip(skipIndex) + .sort(sort) + .limit(limit) + .exec(), + ]); res.json({ query: { $and: query }, page, - total: await AnonymizedRepositoryModel.find({ - $and: query, - }).countDocuments(), + total, sort, - results: await AnonymizedRepositoryModel.find({ $and: query }) - .sort(sort) - .limit(limit) - .skip(skipIndex), + results, }); });