mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-15 06:30:26 +02:00
repo change + daily stat improvements
This commit is contained in:
+26
-1
@@ -1826,6 +1826,27 @@ angular
|
||||
return ($scope.data.errors.severity[key] / max) * 100;
|
||||
};
|
||||
|
||||
function computeDailyHistory(history) {
|
||||
var rows = history || [];
|
||||
return rows.map(function (d, i) {
|
||||
var previous = rows[i - 1] || {};
|
||||
var row = Object.assign({}, d);
|
||||
row.dailyRepositories = i ? Math.max(0, (d.nbRepositories || 0) - (previous.nbRepositories || 0)) : 0;
|
||||
row.dailyUsers = i ? Math.max(0, (d.nbUsers || 0) - (previous.nbUsers || 0)) : 0;
|
||||
row.dailyPageViews = i ? Math.max(0, (d.nbPageViews || 0) - (previous.nbPageViews || 0)) : 0;
|
||||
return row;
|
||||
});
|
||||
}
|
||||
|
||||
function todayDailyStats(history) {
|
||||
var latest = history && history.length ? history[history.length - 1] : {};
|
||||
return {
|
||||
repositories: latest.dailyRepositories || 0,
|
||||
users: latest.dailyUsers || 0,
|
||||
pageViews: latest.dailyPageViews || 0,
|
||||
};
|
||||
}
|
||||
|
||||
var historyMaxes = {};
|
||||
$scope.historyBarH = function (d, field) {
|
||||
if (!d || !historyMaxes[field]) return 0;
|
||||
@@ -1839,12 +1860,16 @@ angular
|
||||
|
||||
function load() {
|
||||
$http.get("/api/admin/overview").then(function (r) {
|
||||
r.data.history = computeDailyHistory(r.data.history);
|
||||
r.data.daily = {
|
||||
today: todayDailyStats(r.data.history),
|
||||
};
|
||||
$scope.data = r.data;
|
||||
$scope.loading = false;
|
||||
$scope.error = null;
|
||||
historyMaxes = {};
|
||||
(r.data.history || []).forEach(function (d) {
|
||||
["nbPageViews", "nbRepositories", "nbUsers"].forEach(function (k) {
|
||||
["dailyPageViews", "dailyRepositories", "dailyUsers"].forEach(function (k) {
|
||||
if (!historyMaxes[k] || d[k] > historyMaxes[k]) historyMaxes[k] = d[k];
|
||||
});
|
||||
});
|
||||
|
||||
+31
-7
@@ -1686,6 +1686,24 @@ angular
|
||||
}
|
||||
}
|
||||
|
||||
function parseRepoFullName(url) {
|
||||
try {
|
||||
const parsed = parseGithubUrl(url);
|
||||
if (parsed && parsed.owner && parsed.repo) {
|
||||
return parsed.owner + "/" + parsed.repo;
|
||||
}
|
||||
} catch (_) { /* sourceUrl not yet parseable */ }
|
||||
return null;
|
||||
}
|
||||
|
||||
function sourceRepositoryID() {
|
||||
if (!$scope.isUpdate || !$scope._originalRepositoryID) return undefined;
|
||||
const currentFullName = parseRepoFullName($scope.sourceUrl);
|
||||
return currentFullName === $scope._originalFullName
|
||||
? $scope._originalRepositoryID
|
||||
: undefined;
|
||||
}
|
||||
|
||||
getDefault(() => {
|
||||
// Edit mode: repo
|
||||
if ($routeParams.repoId && $routeParams.repoId != "") {
|
||||
@@ -1695,6 +1713,7 @@ angular
|
||||
$http.get("/api/repo/" + $scope.repoId).then(
|
||||
async (res) => {
|
||||
$scope.sourceUrl = "https://github.com/" + res.data.source.fullName;
|
||||
$scope._originalFullName = res.data.source.fullName;
|
||||
$scope.terms = res.data.options.terms.filter((f) => f).join("\n");
|
||||
$scope.source = res.data.source;
|
||||
$scope.role = res.data.role || "owner";
|
||||
@@ -1708,6 +1727,7 @@ angular
|
||||
$scope.options = Object.assign({}, $scope.options, res.data.options);
|
||||
$scope.conference = res.data.conference;
|
||||
$scope.repositoryID = res.data.source.repositoryID;
|
||||
$scope._originalRepositoryID = res.data.source.repositoryID;
|
||||
if (res.data.options.expirationDate) {
|
||||
$scope.options.expirationDate = new Date(res.data.options.expirationDate);
|
||||
}
|
||||
@@ -1719,7 +1739,6 @@ angular
|
||||
);
|
||||
$scope.$watch("anonymize", () => {
|
||||
if ($scope.anonymize.repoId) $scope.anonymize.repoId.$$element[0].disabled = true;
|
||||
if ($scope.anonymize.sourceUrl) $scope.anonymize.sourceUrl.$$element[0].disabled = true;
|
||||
});
|
||||
}
|
||||
// Edit mode: PR
|
||||
@@ -1788,9 +1807,11 @@ angular
|
||||
// URL change handler - auto-detect type
|
||||
$scope.urlSelected = async () => {
|
||||
$scope.terms = $scope.defaultTerms;
|
||||
$scope.repoId = "";
|
||||
$scope.pullRequestId = "";
|
||||
$scope.gistId = "";
|
||||
if (!$scope.isUpdate) {
|
||||
$scope.repoId = "";
|
||||
$scope.pullRequestId = "";
|
||||
$scope.gistId = "";
|
||||
}
|
||||
$scope.details = null;
|
||||
$scope.branches = [];
|
||||
$scope.source = { type: "GitHubStream", branch: "", commit: "" };
|
||||
@@ -1862,7 +1883,7 @@ angular
|
||||
const o = parseGithubUrl($scope.sourceUrl);
|
||||
try {
|
||||
const branches = await $http.get(`/api/repo/${o.owner}/${o.repo}/branches`, {
|
||||
params: { force: force === true ? "1" : "0", repositoryID: $scope.repositoryID },
|
||||
params: { force: force === true ? "1" : "0", repositoryID: sourceRepositoryID() },
|
||||
});
|
||||
$scope.branches = branches.data;
|
||||
$scope.sourceUnreachable = false;
|
||||
@@ -1910,9 +1931,12 @@ angular
|
||||
// #364) are reflected without waiting for the cached metadata to
|
||||
// expire. The endpoint hits the GitHub API once.
|
||||
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/`, {
|
||||
params: { repositoryID: $scope.repositoryID, force: "1" },
|
||||
params: { repositoryID: sourceRepositoryID(), force: "1" },
|
||||
});
|
||||
$scope.details = res.data;
|
||||
if ($scope.details && $scope.details.id) {
|
||||
$scope.repositoryID = $scope.details.id;
|
||||
}
|
||||
if (!$scope.repoId) {
|
||||
$scope.repoId = $scope.details.repo + "-" + generateRandomId(4);
|
||||
}
|
||||
@@ -1935,7 +1959,7 @@ angular
|
||||
const o = parseGithubUrl($scope.sourceUrl);
|
||||
try {
|
||||
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/readme`, {
|
||||
params: { force: force === true ? "1" : "0", branch: $scope.source.branch, repositoryID: $scope.repositoryID },
|
||||
params: { force: force === true ? "1" : "0", branch: $scope.source.branch, repositoryID: sourceRepositoryID() },
|
||||
});
|
||||
$scope.readme = res.data;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user