From 25acd6c822e0122e6cc9fc49e229100e5376fc06 Mon Sep 17 00:00:00 2001 From: Morlinest Date: Wed, 1 Nov 2017 20:39:05 +0100 Subject: [PATCH] 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 --- public/js/index.js | 64 ++++++++++++++++++++----- templates/user/dashboard/dashboard.tmpl | 29 ++++++++--- 2 files changed, 74 insertions(+), 19 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index 259980c3c..b6438f296 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'; diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index 8204c0b7e..2ad4008bb 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -43,15 +43,30 @@
@@ -65,7 +80,7 @@ -
  • +
  • {{.i18n.Tr "home.show_more_repos"}}