summaryrefslogtreecommitdiffstats
path: root/public/js/index.js
diff options
context:
space:
mode:
authorMorlinest <morlinest@gmail.com>2017-11-01 20:39:05 +0100
committerLauris BH <lauris@nix.lv>2017-11-01 21:39:05 +0200
commit25acd6c822e0122e6cc9fc49e229100e5376fc06 (patch)
treea12c1c5af7b33ac245c22bcaa0ab4a1182f9b372 /public/js/index.js
parent266ebf82001bd1daadadfad61c7c576e6adaccab (diff)
downloadgitea-25acd6c822e0122e6cc9fc49e229100e5376fc06.tar.gz
gitea-25acd6c822e0122e6cc9fc49e229100e5376fc06.zip
Use custom search for each filter type in dashboard (#2343)
* Do custom search for each filter in repo-search * Fix search url * Simplify code * Remove loader and reset counts when changing filter
Diffstat (limited to 'public/js/index.js')
-rw-r--r--public/js/index.js64
1 files changed, 52 insertions, 12 deletions
diff --git a/public/js/index.js b/public/js/index.js
index 259980c3ca..b6438f296f 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -1671,12 +1671,46 @@ function initVueComponents(){
reposTotalCount: 0,
reposFilter: 'all',
searchQuery: '',
- isLoading: false
+ isLoading: false,
+ repoTypes: {
+ 'all': {
+ count: 0,
+ searchMode: '',
+ },
+ 'forks': {
+ count: 0,
+ searchMode: 'fork',
+ },
+ 'mirrors': {
+ count: 0,
+ searchMode: 'mirror',
+ },
+ 'sources': {
+ count: 0,
+ searchMode: 'source',
+ },
+ 'collaborative': {
+ count: 0,
+ searchMode: 'collaborative',
+ },
+ }
+ }
+ },
+
+ computed: {
+ showMoreReposLink: function() {
+ return this.repos.length > 0 && this.repos.length < this.repoTypes[this.reposFilter].count;
+ },
+ searchURL: function() {
+ return this.suburl + '/api/v1/repos/search?uid=' + this.uid + '&q=' + this.searchQuery + '&limit=' + this.searchLimit + '&mode=' + this.repoTypes[this.reposFilter].searchMode + (this.reposFilter !== 'all' ? '&exclusive=1' : '');
+ },
+ repoTypeCount: function() {
+ return this.repoTypes[this.reposFilter].count;
}
},
mounted: function() {
- this.searchRepos();
+ this.searchRepos(this.reposFilter);
var self = this;
Vue.nextTick(function() {
@@ -1691,6 +1725,9 @@ function initVueComponents(){
changeReposFilter: function(filter) {
this.reposFilter = filter;
+ this.repos = [];
+ this.repoTypes[filter].count = 0;
+ this.searchRepos(filter);
},
showRepo: function(repo, filter) {
@@ -1708,28 +1745,31 @@ function initVueComponents(){
}
},
- searchRepos: function() {
+ searchRepos: function(reposFilter) {
var self = this;
+
this.isLoading = true;
+
+ var searchedMode = this.repoTypes[reposFilter].searchMode;
+ var searchedURL = this.searchURL;
var searchedQuery = this.searchQuery;
- $.getJSON(this.searchURL(), function(result, textStatus, request) {
- if (searchedQuery == self.searchQuery) {
+
+ $.getJSON(searchedURL, function(result, textStatus, request) {
+ if (searchedURL == self.searchURL) {
self.repos = result.data;
- if (searchedQuery == "") {
- self.reposTotalCount = request.getResponseHeader('X-Total-Count');
+ var count = request.getResponseHeader('X-Total-Count');
+ if (searchedQuery === '' && searchedMode === '') {
+ self.reposTotalCount = count;
}
+ self.repoTypes[reposFilter].count = count;
}
}).always(function() {
- if (searchedQuery == self.searchQuery) {
+ if (searchedURL == self.searchURL) {
self.isLoading = false;
}
});
},
- searchURL: function() {
- return this.suburl + '/api/v1/repos/search?uid=' + this.uid + '&q=' + this.searchQuery + '&limit=' + this.searchLimit;
- },
-
repoClass: function(repo) {
if (repo.fork) {
return 'octicon octicon-repo-forked';