Browse Source

Merge pull request #696 from deiwin/update/user-api-to-include-full-name

add full name to found users' list on the UI
for-closed-social
无闻 10 years ago
parent
commit
cb6be94358
2 changed files with 16 additions and 2 deletions
  1. +8
    -1
      public/js/app.js
  2. +8
    -1
      public/ng/js/gogs.js

+ 8
- 1
public/js/app.js View File

@ -303,6 +303,9 @@ var Gogits = {};
// api working // api working
Gogits.getUsers = function (val, $target) { Gogits.getUsers = function (val, $target) {
var notEmpty = function (str) {
return str && str.length > 0;
}
$.ajax({ $.ajax({
url: '/api/v1/users/search?q=' + val, url: '/api/v1/users/search?q=' + val,
dataType: "json", dataType: "json",
@ -310,7 +313,11 @@ var Gogits = {};
if (json.ok && json.data.length) { if (json.ok && json.data.length) {
var html = ''; var html = '';
$.each(json.data, function (i, item) { $.each(json.data, function (i, item) {
html += '<li><img src="' + item.avatar + '">' + item.username + '</li>';
html += '<li><img src="' + item.avatar + '">' + item.username;
if (notEmpty(item.full_name)) {
html += ' (' + item.full_name + ')';
}
html += '</li>';
}); });
$target.toggleShow(); $target.toggleShow();
$target.find('ul').html(html); $target.find('ul').html(html);

+ 8
- 1
public/ng/js/gogs.js View File

@ -203,6 +203,9 @@ var Gogs = {};
// Search users by keyword. // Search users by keyword.
Gogs.searchUsers = function (val, $target) { Gogs.searchUsers = function (val, $target) {
var notEmpty = function (str) {
return str && str.length > 0;
}
$.ajax({ $.ajax({
url: Gogs.AppSubUrl + '/api/v1/users/search?q=' + val, url: Gogs.AppSubUrl + '/api/v1/users/search?q=' + val,
dataType: "json", dataType: "json",
@ -210,7 +213,11 @@ var Gogs = {};
if (json.ok && json.data.length) { if (json.ok && json.data.length) {
var html = ''; var html = '';
$.each(json.data, function (i, item) { $.each(json.data, function (i, item) {
html += '<li><a><img src="' + item.avatar_url + '">' + item.username + '</a></li>';
html += '<li><a><img src="' + item.avatar_url + '">' + item.username;
if (notEmpty(item.full_name)) {
html += ' (' + item.full_name + ')';
}
html += '</a></li>';
}); });
$target.html(html); $target.html(html);
$target.toggleShow(); $target.toggleShow();

Loading…
Cancel
Save