diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2017-05-08 21:31:30 -0300 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-05-09 08:31:30 +0800 |
commit | ab79069dc79c4a816eb8d53cbd90fc38833ec117 (patch) | |
tree | a4d59642968befa76afc4330345b8eaf23028a8f /public/js/index.js | |
parent | 51d0becb4232eab6b18959ccc4a895e5df30c4dc (diff) | |
download | gitea-ab79069dc79c4a816eb8d53cbd90fc38833ec117.tar.gz gitea-ab79069dc79c4a816eb8d53cbd90fc38833ec117.zip |
Improve dashboard repo search (#1652)
* Add VueJS
* Improve dashboard search
* Fix tab switching
* Fix input autofocus
Diffstat (limited to 'public/js/index.js')
-rw-r--r-- | public/js/index.js | 69 |
1 files changed, 62 insertions, 7 deletions
diff --git a/public/js/index.js b/public/js/index.js index 31b15a76a7..a3e9e99e7a 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1560,6 +1560,7 @@ $(document).ready(function () { initWebhook(); initAdmin(); initCodeView(); + initDashboardSearch(); // Repo clone url. if ($('#repo-clone-url').length > 0) { @@ -1635,13 +1636,6 @@ $(function () { if ($('.user.signin').length > 0) return; $('form').areYouSure(); - $("#search_repo").on('change paste keyup',function(){ - var value = $(this).val(); - $.map($('.search-list li'), function(i) { - $(i).css("display", (value.trim().length == 0 || $(i).attr("data-title").trim().toLowerCase().indexOf(value.trim().toLowerCase()) > -1) ? "" : "none"); - }); - }); - // Parse SSH Key $("#ssh-key-content").on('change paste keyup',function(){ var arrays = $(this).val().split(" "); @@ -1651,3 +1645,64 @@ $(function () { } }); }); + +function initDashboardSearch() { + var el = document.getElementById('dashboard-repo-search'); + if (!el) { + return; + } + + new Vue({ + delimiters: ['<%', '%>'], + el: el, + + data: { + tab: 'repos', + repos: [], + searchQuery: '', + suburl: document.querySelector('meta[name=_suburl]').content, + uid: document.querySelector('meta[name=_uid]').content + }, + + mounted: function() { + this.searchRepos(); + + Vue.nextTick(function() { + document.querySelector('#search_repo').focus(); + }); + }, + + methods: { + changeTab: function(t) { + this.tab = t; + }, + + searchKeyUp: function() { + this.searchRepos(); + }, + + searchRepos: function() { + var self = this; + $.getJSON(this.searchURL(), function(result) { + self.repos = result.data; + }); + }, + + searchURL: function() { + return this.suburl + '/api/v1/repos/search?uid=' + this.uid + '&q=' + this.searchQuery; + }, + + repoClass: function(repo) { + if (repo.fork) { + return 'octicon octicon-repo-forked'; + } else if (repo.mirror) { + return 'octicon octicon-repo-clone'; + } else if (repo.private) { + return 'octicon octicon-repo-forked'; + } else { + return 'octicon octicon-repo'; + } + } + } + }); +} |