Skip to content

Commit ab79069

Browse files
andreyneringlunny
authored andcommitted
Improve dashboard repo search (#1652)
* Add VueJS * Improve dashboard search * Fix tab switching * Fix input autofocus
1 parent 51d0bec commit ab79069

File tree

6 files changed

+8654
-32
lines changed

6 files changed

+8654
-32
lines changed

models/repo_list.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
115115
cond = builder.NewCond()
116116
)
117117

118-
if len(opts.Keyword) == 0 {
119-
return repos, 0, nil
120-
}
121118
opts.Keyword = strings.ToLower(opts.Keyword)
122119

123120
if opts.Page <= 0 {

public/js/index.js

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,7 @@ $(document).ready(function () {
15601560
initWebhook();
15611561
initAdmin();
15621562
initCodeView();
1563+
initDashboardSearch();
15631564

15641565
// Repo clone url.
15651566
if ($('#repo-clone-url').length > 0) {
@@ -1635,13 +1636,6 @@ $(function () {
16351636
if ($('.user.signin').length > 0) return;
16361637
$('form').areYouSure();
16371638

1638-
$("#search_repo").on('change paste keyup',function(){
1639-
var value = $(this).val();
1640-
$.map($('.search-list li'), function(i) {
1641-
$(i).css("display", (value.trim().length == 0 || $(i).attr("data-title").trim().toLowerCase().indexOf(value.trim().toLowerCase()) > -1) ? "" : "none");
1642-
});
1643-
});
1644-
16451639
// Parse SSH Key
16461640
$("#ssh-key-content").on('change paste keyup',function(){
16471641
var arrays = $(this).val().split(" ");
@@ -1651,3 +1645,64 @@ $(function () {
16511645
}
16521646
});
16531647
});
1648+
1649+
function initDashboardSearch() {
1650+
var el = document.getElementById('dashboard-repo-search');
1651+
if (!el) {
1652+
return;
1653+
}
1654+
1655+
new Vue({
1656+
delimiters: ['<%', '%>'],
1657+
el: el,
1658+
1659+
data: {
1660+
tab: 'repos',
1661+
repos: [],
1662+
searchQuery: '',
1663+
suburl: document.querySelector('meta[name=_suburl]').content,
1664+
uid: document.querySelector('meta[name=_uid]').content
1665+
},
1666+
1667+
mounted: function() {
1668+
this.searchRepos();
1669+
1670+
Vue.nextTick(function() {
1671+
document.querySelector('#search_repo').focus();
1672+
});
1673+
},
1674+
1675+
methods: {
1676+
changeTab: function(t) {
1677+
this.tab = t;
1678+
},
1679+
1680+
searchKeyUp: function() {
1681+
this.searchRepos();
1682+
},
1683+
1684+
searchRepos: function() {
1685+
var self = this;
1686+
$.getJSON(this.searchURL(), function(result) {
1687+
self.repos = result.data;
1688+
});
1689+
},
1690+
1691+
searchURL: function() {
1692+
return this.suburl + '/api/v1/repos/search?uid=' + this.uid + '&q=' + this.searchQuery;
1693+
},
1694+
1695+
repoClass: function(repo) {
1696+
if (repo.fork) {
1697+
return 'octicon octicon-repo-forked';
1698+
} else if (repo.mirror) {
1699+
return 'octicon octicon-repo-clone';
1700+
} else if (repo.private) {
1701+
return 'octicon octicon-repo-forked';
1702+
} else {
1703+
return 'octicon octicon-repo';
1704+
}
1705+
}
1706+
}
1707+
});
1708+
}

0 commit comments

Comments
 (0)