Skip to content

Commit

Permalink
Improve dashboard repo search (#1652)
Browse files Browse the repository at this point in the history
* Add VueJS

* Improve dashboard search

* Fix tab switching

* Fix input autofocus
  • Loading branch information
andreynering authored and lunny committed May 9, 2017
1 parent 51d0bec commit ab79069
Show file tree
Hide file tree
Showing 6 changed files with 8,654 additions and 32 deletions.
3 changes: 0 additions & 3 deletions models/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
cond = builder.NewCond()
)

if len(opts.Keyword) == 0 {
return repos, 0, nil
}
opts.Keyword = strings.ToLower(opts.Keyword)

if opts.Page <= 0 {
Expand Down
69 changes: 62 additions & 7 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,7 @@ $(document).ready(function () {
initWebhook();
initAdmin();
initCodeView();
initDashboardSearch();

// Repo clone url.
if ($('#repo-clone-url').length > 0) {
Expand Down Expand Up @@ -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(" ");
Expand All @@ -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';
}
}
}
});
}
Loading

0 comments on commit ab79069

Please sign in to comment.