feat: add basic admin dashboard (#90)

This commit is contained in:
Thomas Durieux
2021-09-23 18:33:21 +02:00
committed by GitHub
parent fe825ad45a
commit 046d0c65cf
12 changed files with 1381 additions and 2 deletions

206
public/script/admin.js Normal file
View File

@@ -0,0 +1,206 @@
angular
.module("admin", [])
.controller("repositoriesAdminController", [
"$scope",
"$http",
"$location",
function ($scope, $http, $location) {
$scope.$watch("user.status", () => {
if ($scope.user == null) {
$location.url("/");
}
});
if ($scope.user == null) {
$location.url("/");
}
$scope.repositories = [];
$scope.total = -1;
$scope.totalPage = 0;
$scope.query = {
page: 1,
limit: 25,
sort: "source.repositoryName",
search: "",
ready: true,
expired: true,
removed: true,
error: true,
preparing: true,
};
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);
}
);
}
getRepositories();
let timeClear = null;
$scope.$watch(
"query",
() => {
clearTimeout(timeClear);
timeClear = setTimeout(getRepositories, 500);
},
true
);
},
])
.controller("usersAdminController", [
"$scope",
"$http",
"$location",
function ($scope, $http, $location) {
$scope.$watch("user.status", () => {
if ($scope.user == null) {
$location.url("/");
}
});
if ($scope.user == null) {
$location.url("/");
}
$scope.users = [];
$scope.total = -1;
$scope.totalPage = 0;
$scope.query = {
page: 1,
limit: 25,
sort: "username",
search: "",
};
function getUsers() {
$http.get("/api/admin/users", { params: $scope.query }).then(
(res) => {
$scope.total = res.data.total;
$scope.totalPage = Math.ceil(res.data.total / $scope.query.limit);
$scope.users = res.data.results;
$scope.$apply();
},
(err) => {
console.error(err);
}
);
}
getUsers();
let timeClear = null;
$scope.$watch(
"query",
() => {
clearTimeout(timeClear);
timeClear = setTimeout(getUsers, 500);
},
true
);
},
])
.controller("conferencesAdminController", [
"$scope",
"$http",
"$location",
function ($scope, $http, $location) {
$scope.$watch("user.status", () => {
if ($scope.user == null) {
$location.url("/");
}
});
if ($scope.user == null) {
$location.url("/");
}
$scope.conferences = [];
$scope.total = -1;
$scope.totalPage = 0;
$scope.query = {
page: 1,
limit: 25,
sort: "name",
search: ""
};
function getConferences() {
$http.get("/api/admin/conferences", { params: $scope.query }).then(
(res) => {
$scope.total = res.data.total;
$scope.totalPage = Math.ceil(res.data.total / $scope.query.limit);
$scope.conferences = res.data.results;
$scope.$apply();
},
(err) => {
console.error(err);
}
);
}
getConferences();
let timeClear = null;
$scope.$watch(
"query",
() => {
clearTimeout(timeClear);
timeClear = setTimeout(getConferences, 500);
},
true
);
},
]).controller("queuesAdminController", [
"$scope",
"$http",
"$location",
function ($scope, $http, $location) {
$scope.$watch("user.status", () => {
if ($scope.user == null) {
$location.url("/");
}
});
if ($scope.user == null) {
$location.url("/");
}
$scope.downloadJobs = [];
$scope.removeJobs = [];
$scope.total = -1;
$scope.totalPage = 0;
$scope.query = {
page: 1,
limit: 25,
sort: "name",
search: ""
};
function getQueues() {
$http.get("/api/admin/queues", { params: $scope.query }).then(
(res) => {
$scope.downloadJobs = res.data.downloadQueue;
$scope.removeJobs = res.data.removeQueue;
$scope.$apply();
},
(err) => {
console.error(err);
}
);
}
getQueues();
let timeClear = null;
$scope.$watch(
"query",
() => {
clearTimeout(timeClear);
timeClear = setTimeout(getQueues, 500);
},
true
);
},
]);

View File

@@ -6,6 +6,7 @@ angular
"ngPDFViewer",
"pascalprecht.translate",
"angular-google-analytics",
"admin",
])
.config(function (
$routeProvider,
@@ -90,6 +91,26 @@ angular
title: "Anonymized Repository - Anonymous GitHub",
reloadOnUrl: false,
})
.when("/admin/", {
templateUrl: "/partials/admin/repositories.htm",
controller: "repositoriesAdminController",
title: "Repositories Admin - Anonymous GitHub",
})
.when("/admin/users", {
templateUrl: "/partials/admin/users.htm",
controller: "usersAdminController",
title: "Users Admin - Anonymous GitHub",
})
.when("/admin/conferences", {
templateUrl: "/partials/admin/conferences.htm",
controller: "conferencesAdminController",
title: "Conferences Admin - Anonymous GitHub",
})
.when("/admin/queues", {
templateUrl: "/partials/admin/queues.htm",
controller: "queuesAdminController",
title: "Queues Admin - Anonymous GitHub",
})
.when("/404", {
templateUrl: "/partials/404.htm",
title: "Page not found - Anonymous GitHub",