mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-17 02:27:19 +02:00
fix: auto select file when a folder is selected
This commit is contained in:
+26
-14
@@ -1505,7 +1505,9 @@ angular
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$scope.filePath = $routeParams.path || "";
|
$scope.filePath = $routeParams.path || "";
|
||||||
$scope.paths = $scope.filePath.split("/");
|
$scope.paths = $scope.filePath
|
||||||
|
.split("/")
|
||||||
|
.filter((f) => f && f.trim().length > 0);
|
||||||
|
|
||||||
if ($scope.repoId != $routeParams.repoId) {
|
if ($scope.repoId != $routeParams.repoId) {
|
||||||
return init();
|
return init();
|
||||||
@@ -1514,19 +1516,7 @@ angular
|
|||||||
updateContent();
|
updateContent();
|
||||||
});
|
});
|
||||||
|
|
||||||
function getFiles(callback) {
|
function selectFile() {
|
||||||
$http.get(`/api/repo/${$scope.repoId}/files/`).then(
|
|
||||||
(res) => {
|
|
||||||
$scope.files = res.data;
|
|
||||||
if ($scope.paths.length == 0 || $scope.paths[0] == "") {
|
|
||||||
// redirect to readme
|
|
||||||
const readmeCandidates = {};
|
|
||||||
for (const file in $scope.files) {
|
|
||||||
if (file.toLowerCase().indexOf("readme") > -1) {
|
|
||||||
readmeCandidates[file.toLowerCase()] = file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const readmePriority = [
|
const readmePriority = [
|
||||||
"readme.md",
|
"readme.md",
|
||||||
"readme.txt",
|
"readme.txt",
|
||||||
@@ -1534,6 +1524,23 @@ angular
|
|||||||
"readme.1st",
|
"readme.1st",
|
||||||
"readme",
|
"readme",
|
||||||
];
|
];
|
||||||
|
// find current folder
|
||||||
|
let currentFolder = $scope.files;
|
||||||
|
for (const p of $scope.paths) {
|
||||||
|
if (currentFolder[p]) {
|
||||||
|
currentFolder = currentFolder[p];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentFolder.size && Number.isInteger(currentFolder.size)) {
|
||||||
|
// a file is already selected
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const readmeCandidates = {};
|
||||||
|
for (const file in currentFolder) {
|
||||||
|
if (file.toLowerCase().indexOf("readme") > -1) {
|
||||||
|
readmeCandidates[file.toLowerCase()] = file;
|
||||||
|
}
|
||||||
|
}
|
||||||
let best_match = null;
|
let best_match = null;
|
||||||
for (const p of readmePriority) {
|
for (const p of readmePriority) {
|
||||||
if (readmeCandidates[p]) {
|
if (readmeCandidates[p]) {
|
||||||
@@ -1553,6 +1560,11 @@ angular
|
|||||||
$location.url(uri + readmeCandidates[best_match]);
|
$location.url(uri + readmeCandidates[best_match]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function getFiles(callback) {
|
||||||
|
$http.get(`/api/repo/${$scope.repoId}/files/`).then(
|
||||||
|
(res) => {
|
||||||
|
$scope.files = res.data;
|
||||||
|
selectFile();
|
||||||
if (callback) {
|
if (callback) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user