From 6a9c783940c60c2ed7a517d8aa7f387fbd9bec9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDeby?= Date: Wed, 9 Aug 2017 16:23:33 +0200 Subject: [PATCH 1/7] Fix and improve dashboard repo UI --- public/css/index.css | 11 ++ public/js/index.js | 43 ++++++- public/less/_base.less | 14 +++ routers/api/v1/repo/repo.go | 2 + routers/user/home.go | 1 + templates/base/head.tmpl | 3 + templates/user/dashboard/dashboard.tmpl | 160 +++++++++++++----------- 7 files changed, 155 insertions(+), 79 deletions(-) diff --git a/public/css/index.css b/public/css/index.css index 774b559621305..133af2690ae1e 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -471,6 +471,17 @@ footer .ui.language .menu { padding-right: 30px !important; } } +[v-cloak] { + display: none !important; +} +.repos-search { + padding-bottom: 0 !important; +} +.repos-filter { + margin-top: 0 !important; + border-bottom-width: 0 !important; + margin-bottom: 2px !important; +} .markdown:not(code) { overflow: hidden; font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif; diff --git a/public/js/index.js b/public/js/index.js index d79b94b92c7bc..52d5a089d93dc 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1668,14 +1668,21 @@ function initDashboardSearch() { data: { tab: 'repos', repos: [], + reposTotal: 0, + reposFilter: 'all', searchQuery: '', + searchLimit: document.querySelector('meta[name=_search_limit]').content, suburl: document.querySelector('meta[name=_suburl]').content, - uid: document.querySelector('meta[name=_context_uid]').content + uid: document.querySelector('meta[name=_context_uid]').content, + isMounted: false, + isLoading: false }, mounted: function() { this.searchRepos(); + this.isMounted = true; + Vue.nextTick(function() { document.querySelector('#search_repo').focus(); }); @@ -1686,19 +1693,47 @@ function initDashboardSearch() { this.tab = t; }, + changeReposFilter: function(filter) { + this.reposFilter = filter; + }, + + showRepo: function(repo, filter) { + switch (filter) { + case 'sources': + return repo.owner.id == this.uid && !repo.mirror && !repo.fork; + case 'forks': + return repo.owner.id == this.uid && !repo.mirror && repo.fork; + case 'collaborative': + return repo.owner.id != this.uid; + default: + return true; + } + }, + searchKeyUp: function() { this.searchRepos(); }, searchRepos: function() { var self = this; - $.getJSON(this.searchURL(), function(result) { - self.repos = result.data; + this.isLoading = true; + let searchedQuery = this.searchQuery; + $.getJSON(this.searchURL(), function(result, textStatus, request) { + if (searchedQuery == self.searchQuery) { + self.repos = result.data; + if (searchedQuery == "") { + self.reposTotal = request.getResponseHeader('X-Total-Count'); + } + } + }).always(function() { + if (searchedQuery == self.searchQuery) { + self.isLoading = false; + } }); }, searchURL: function() { - return this.suburl + '/api/v1/repos/search?uid=' + this.uid + '&q=' + this.searchQuery; + return this.suburl + '/api/v1/repos/search?uid=' + this.uid + '&q=' + this.searchQuery + '&limit=' + this.searchLimit; }, repoClass: function(repo) { diff --git a/public/less/_base.less b/public/less/_base.less index ba4821035b433..572cec870ed5e 100644 --- a/public/less/_base.less +++ b/public/less/_base.less @@ -464,3 +464,17 @@ footer { padding-right: 30px !important; } } + +[v-cloak] { + display: none !important; +} + +.repos-search { + padding-bottom: 0 !important; +} + +.repos-filter { + margin-top: 0 !important; + border-bottom-width: 0 !important; + margin-bottom: 2px !important; +} \ No newline at end of file diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index edd6a72637aac..e44159817e52b 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -5,6 +5,7 @@ package repo import ( + "fmt" "strings" api "code.gitea.io/sdk/gitea" @@ -91,6 +92,7 @@ func Search(ctx *context.APIContext) { } ctx.SetLinkHeader(int(count), setting.API.MaxResponseItems) + ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", count)) ctx.JSON(200, api.SearchResults{ OK: true, Data: results, diff --git a/routers/user/home.go b/routers/user/home.go index b2096bc2ceead..1707d9d097a54 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -131,6 +131,7 @@ func Dashboard(ctx *context.Context) { ctx.Data["Title"] = ctxUser.DisplayName() + " - " + ctx.Tr("dashboard") ctx.Data["PageIsDashboard"] = true ctx.Data["PageIsNews"] = true + ctx.Data["SearchLimit"] = setting.UI.User.RepoPagingNum // Only user can have collaborative repositories. if !ctxUser.IsOrganization() { diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index bb6f1ecaf521d..88d2b14a46d70 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -17,6 +17,9 @@ {{if .ContextUser}} {{end}} + {{if .SearchLimit}} + + {{end}} {{if .GoGetImport}} diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index 48d6966e189e0..9fcbf26152485 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -8,68 +8,105 @@ {{template "user/dashboard/feeds" .}} +{{template "user/dashboard/repo-search" .}} {{template "base/footer" .}} diff --git a/templates/user/dashboard/repo-search.tmpl b/templates/user/dashboard/repo-search.tmpl new file mode 100644 index 0000000000000..c90e442035e05 --- /dev/null +++ b/templates/user/dashboard/repo-search.tmpl @@ -0,0 +1,108 @@ + \ No newline at end of file From f599456cce0f8a4440c6c4c22e8b00c0e355826f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDeby?= Date: Mon, 14 Aug 2017 09:45:27 +0200 Subject: [PATCH 3/7] Change order of scripts loading --- templates/base/footer.tmpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl index 923f39e85bb07..a0c14db21819e 100644 --- a/templates/base/footer.tmpl +++ b/templates/base/footer.tmpl @@ -45,10 +45,6 @@ {{end}} - - - - {{if .RequireHighlightJS}} @@ -66,5 +62,9 @@ + + + + From f3ae99e9ad40144c6f96ea676e70c32749ab12e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDeby?= Date: Wed, 16 Aug 2017 17:18:01 +0200 Subject: [PATCH 4/7] Add "mirrors" filter --- public/js/index.js | 2 ++ templates/user/dashboard/repo-search.tmpl | 1 + 2 files changed, 3 insertions(+) diff --git a/public/js/index.js b/public/js/index.js index a09e4e3cfd1ba..3152b2a5a42cd 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1712,6 +1712,8 @@ function initVueComponents(){ return repo.owner.id == this.uid && !repo.mirror && !repo.fork; case 'forks': return repo.owner.id == this.uid && !repo.mirror && repo.fork; + case 'mirrors': + return repo.mirror; case 'collaborative': return repo.owner.id != this.uid; default: diff --git a/templates/user/dashboard/repo-search.tmpl b/templates/user/dashboard/repo-search.tmpl index c90e442035e05..27927f915ec8a 100644 --- a/templates/user/dashboard/repo-search.tmpl +++ b/templates/user/dashboard/repo-search.tmpl @@ -26,6 +26,7 @@ All Sources Forks + Mirrors Collaborative From 350c7c2e49d593d6859e3fd876bb8cfd3815d201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDeby?= Date: Tue, 15 Aug 2017 09:18:27 +0200 Subject: [PATCH 5/7] Remove "mirror" tab --- templates/user/dashboard/repo-search.tmpl | 30 +---------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/templates/user/dashboard/repo-search.tmpl b/templates/user/dashboard/repo-search.tmpl index 27927f915ec8a..87faa831e6cb9 100644 --- a/templates/user/dashboard/repo-search.tmpl +++ b/templates/user/dashboard/repo-search.tmpl @@ -1,11 +1,10 @@ \ No newline at end of file From 7472ab31cfeae1dc24faca0466751f117b6d0c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDeby?= Date: Wed, 16 Aug 2017 09:39:58 +0200 Subject: [PATCH 6/7] Remove single tab panel for "org user" --- templates/user/dashboard/repo-search.tmpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/user/dashboard/repo-search.tmpl b/templates/user/dashboard/repo-search.tmpl index 87faa831e6cb9..416a00cb460df 100644 --- a/templates/user/dashboard/repo-search.tmpl +++ b/templates/user/dashboard/repo-search.tmpl @@ -1,11 +1,11 @@