-
- Notifications
You must be signed in to change notification settings - Fork 6.2k
Use Semantic UI's Search component for user and repo search #2636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits Select commit Hold shift + click to select a range
0d64b05 Use search component on org invitation user input.
harryxu 585024c Search component for collaboration and members.
harryxu ccf5f90 Search component for repo search.
harryxu ef07e73 minCharacters for search input
harryxu e587167 Display full_name for user search.
harryxu 221648c Fixed missing uid query parameter for repo search.
harryxu 77bec9e Removed unused comment.
harryxu ab58a42 Merge branch 'master' into search-input
lafriks 916ad17 Merge branch 'master' into search-input
lafriks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -1230,104 +1230,54 @@ function hideWhenLostFocus(body, parent) { | |
| } | ||
| | ||
| function searchUsers() { | ||
| if (!$('#search-user-box .results').length) { | ||
| return; | ||
| } | ||
| | ||
| var $searchUserBox = $('#search-user-box'); | ||
| var $results = $searchUserBox.find('.results'); | ||
| $searchUserBox.keyup(function () { | ||
| var $this = $(this); | ||
| var keyword = $this.find('input').val(); | ||
| if (keyword.length < 2) { | ||
| $results.hide(); | ||
| return; | ||
| } | ||
| $searchUserBox.search({ | ||
| minCharacters: 2, | ||
| apiSettings: { | ||
| url: suburl + '/api/v1/users/search?q={query}', | ||
| onResponse: function(response) { | ||
| var items = []; | ||
| $.each(response.data, function (i, item) { | ||
| var title = item.login; | ||
| if (item.full_name && item.full_name.length > 0) { | ||
| title += ' (' + item.full_name + ')'; | ||
| } | ||
| items.push({ | ||
| title: title, | ||
| image: item.avatar_url | ||
| }) | ||
| }); | ||
| | ||
| $.ajax({ | ||
| url: suburl + '/api/v1/users/search?q=' + keyword, | ||
| dataType: "json", | ||
| success: function (response) { | ||
| var notEmpty = function (str) { | ||
| return str && str.length > 0; | ||
| }; | ||
| | ||
| $results.html(''); | ||
| | ||
| if (response.ok && response.data.length) { | ||
| var html = ''; | ||
| $.each(response.data, function (i, item) { | ||
| html += '<div class="item"><img class="ui avatar image" src="' + item.avatar_url + '"><span class="username">' + item.login + '</span>'; | ||
| if (notEmpty(item.full_name)) { | ||
| html += ' (' + item.full_name + ')'; | ||
| } | ||
| html += '</div>'; | ||
| }); | ||
| $results.html(html); | ||
| $this.find('.results .item').click(function () { | ||
| $this.find('input').val($(this).find('.username').text()); | ||
| $results.hide(); | ||
| }); | ||
| $results.show(); | ||
| } else { | ||
| $results.hide(); | ||
| } | ||
| return { results: items } | ||
| } | ||
| }); | ||
| }); | ||
| $searchUserBox.find('input').focus(function () { | ||
| $searchUserBox.keyup(); | ||
| }, | ||
| searchFields: ['login', 'full_name'], | ||
| showNoResults: false | ||
| }); | ||
| hideWhenLostFocus('#search-user-box .results', '#search-user-box'); | ||
| } | ||
| | ||
| // FIXME: merge common parts in two functions | ||
| function searchRepositories() { | ||
| if (!$('#search-repo-box .results').length) { | ||
| return; | ||
| } | ||
| | ||
| var $searchRepoBox = $('#search-repo-box'); | ||
| var $results = $searchRepoBox.find('.results'); | ||
| $searchRepoBox.keyup(function () { | ||
| var $this = $(this); | ||
| var keyword = $this.find('input').val(); | ||
| if (keyword.length < 2) { | ||
| $results.hide(); | ||
| return; | ||
| } | ||
| | ||
| $.ajax({ | ||
| url: suburl + '/api/v1/repos/search?q=' + keyword + "&uid=" + $searchRepoBox.data('uid'), | ||
| dataType: "json", | ||
| success: function (response) { | ||
| var notEmpty = function (str) { | ||
| return str && str.length > 0; | ||
| }; | ||
| | ||
| $results.html(''); | ||
| $searchRepoBox.search({ | ||
| minCharacters: 2, | ||
| apiSettings: { | ||
| url: suburl + '/api/v1/repos/search?q={query}', | ||
| ||
| onResponse: function(response) { | ||
| var items = []; | ||
| $.each(response.data, function (i, item) { | ||
| items.push({ | ||
| title: item.full_name.split("/")[1], | ||
| description: item.full_name | ||
| }) | ||
| }); | ||
| | ||
| if (response.ok && response.data.length) { | ||
| var html = ''; | ||
| $.each(response.data, function (i, item) { | ||
| html += '<div class="item"><i class="icon octicon octicon-repo"></i> <span class="fullname">' + item.full_name + '</span></div>'; | ||
| }); | ||
| $results.html(html); | ||
| $this.find('.results .item').click(function () { | ||
| $this.find('input').val($(this).find('.fullname').text().split("/")[1]); | ||
| $results.hide(); | ||
| }); | ||
| $results.show(); | ||
| } else { | ||
| $results.hide(); | ||
| } | ||
| return { results: items } | ||
| } | ||
| }); | ||
| }); | ||
| $searchRepoBox.find('input').focus(function () { | ||
| $searchRepoBox.keyup(); | ||
| }, | ||
| searchFields: ['full_name'], | ||
| showNoResults: false | ||
| }); | ||
| hideWhenLostFocus('#search-repo-box .results', '#search-repo-box'); | ||
| } | ||
| | ||
| function initCodeView() { | ||
| | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove this comment now that it is stale