Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
repositories: splitted repositories into different panels
Browse files Browse the repository at this point in the history
All the repositories were mixed together without distinction from the
repositories accessible via team membership or via visibility. Of
course, if the user is an admin, all the repositories would be listed.
Anyways, a nice enhancement to have this separation and create a sense
of semantic in the UI level.

Signed-off-by: Vítor Avelino <[email protected]>
  • Loading branch information
Vítor Avelino committed Apr 16, 2018
1 parent dfc5357 commit d2d90d4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
17 changes: 17 additions & 0 deletions app/assets/javascripts/modules/repositories/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@ $(() => {
data() {
return {
repositories: window.repositories,
teamRepositoriesNames: window.teamRepositoriesNames,
};
},

computed: {
teamRepositories() {
// eslint-disable-next-line
return this.repositories.filter((r) => {
return this.teamRepositoriesNames.indexOf(r.full_name) !== -1;
});
},

otherRepositories() {
// eslint-disable-next-line
return this.repositories.filter((r) => {
return this.teamRepositoriesNames.indexOf(r.full_name) === -1;
});
},
},
});
});
7 changes: 5 additions & 2 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ class RepositoriesController < ApplicationController
# GET /repositories
# GET /repositories.json
def index
@repositories = policy_scope(Repository).all
@repositories = policy_scope(Repository)
@repositories_serialized = API::Entities::Repositories.represent(
@repositories,
current_user: current_user,
type: :internal
).to_json
respond_with(@repositories)
@team_repositories = Repository
.joins(namespace: { team: :users })
.where("users.id = :user_id", user_id: current_user.id)
.map(&:full_name)
end

# GET /repositories/1
Expand Down
12 changes: 10 additions & 2 deletions app/views/repositories/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
.panel.panel-default.repositories-panel
.panel-heading
h5 Repositories
h5 Repositories via team membership
.panel-body
<repositories-table :repositories="repositories" repositories-path="#{repositories_path}" namespaces-path="#{namespaces_path}" :sortable="true" sort-by="name"></repositories-table>
<repositories-table :repositories="teamRepositories" repositories-path="#{repositories_path}" namespaces-path="#{namespaces_path}" :sortable="true" sort-by="name"></repositories-table>

- if (@repositories.count - @team_repositories.count) > 0
.panel.panel-default.repositories-panel
.panel-heading
h5 Other repositories
.panel-body
<repositories-table :repositories="otherRepositories" repositories-path="#{repositories_path}" namespaces-path="#{namespaces_path}" :sortable="true" sort-by="name"></repositories-table>

- content_for :js_body do
script#js-repositories-table-tmpl type="text/x-template"
Expand All @@ -14,3 +21,4 @@
- content_for :js_header do
javascript:
window.repositories = #{raw @repositories_serialized};
window.teamRepositoriesNames = #{raw @team_repositories};
7 changes: 7 additions & 0 deletions spec/features/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def find_tag_checkbox(name)
expect(page).to have_css(selector)
expect(page).to have_current_path(repositories_path(page: 1))
end

it "doesn't show 'other repositories' panel when empty" do
visit repositories_path

expect(page).to have_content(repository.name)
expect(page).not_to have_content("Other repositories")
end
end

describe "repository#show" do
Expand Down

0 comments on commit d2d90d4

Please sign in to comment.