BigW Consortium Gitlab

api.js.coffee 2.4 KB
Newer Older
1
@Api =
2 3
  groups_path: "/api/:version/groups.json"
  group_path: "/api/:version/groups/:id.json"
4
  namespaces_path: "/api/:version/namespaces.json"
5 6
  group_projects_path: "/api/:version/groups/:id/projects.json"
  projects_path: "/api/:version/projects.json"
7
  labels_path: "/api/:version/projects/:id/labels"
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  group: (group_id, callback) ->
    url = Api.buildUrl(Api.group_path)
    url = url.replace(':id', group_id)

    $.ajax(
      url: url
      data:
        private_token: gon.api_token
      dataType: "json"
    ).done (group) ->
      callback(group)

  # Return groups list. Filtered by query
  # Only active groups retrieved
  groups: (query, skip_ldap, callback) ->
    url = Api.buildUrl(Api.groups_path)

    $.ajax(
      url: url
      data:
        private_token: gon.api_token
        search: query
        per_page: 20
      dataType: "json"
    ).done (groups) ->
      callback(groups)

36 37 38 39 40 41 42 43 44 45 46 47 48 49
  # Return namespaces list. Filtered by query
  namespaces: (query, callback) ->
    url = Api.buildUrl(Api.namespaces_path)

    $.ajax(
      url: url
      data:
        private_token: gon.api_token
        search: query
        per_page: 20
      dataType: "json"
    ).done (namespaces) ->
      callback(namespaces)

50
  # Return projects list. Filtered by query
51
  projects: (query, order, callback) ->
52 53 54 55 56 57 58
    url = Api.buildUrl(Api.projects_path)

    $.ajax(
      url: url
      data:
        private_token: gon.api_token
        search: query
59
        order_by: order
60 61 62 63 64
        per_page: 20
      dataType: "json"
    ).done (projects) ->
      callback(projects)

65 66 67 68 69 70 71 72 73 74 75 76
  newLabel: (project_id, data, callback) ->
    url = Api.buildUrl(Api.labels_path)
    url = url.replace(':id', project_id)

    data.private_token = gon.api_token
    $.ajax(
      url: url
      type: "POST"
      data: data
      dataType: "json"
    ).done (label) ->
      callback(label)
77 78
    .error (message) ->
      callback(message.responseJSON)
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  # Return group projects list. Filtered by query
  groupProjects: (group_id, query, callback) ->
    url = Api.buildUrl(Api.group_projects_path)
    url = url.replace(':id', group_id)

    $.ajax(
      url: url
      data:
        private_token: gon.api_token
        search: query
        per_page: 20
      dataType: "json"
    ).done (projects) ->
      callback(projects)

95
  buildUrl: (url) ->
Jim committed
96
    url = gon.relative_url_root + url if gon.relative_url_root?
97
    return url.replace(':version', gon.api_version)