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

Commit

Permalink
Added namespaces and teams to search
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Fernandes <[email protected]>
  • Loading branch information
msfernandes committed Jun 15, 2016
1 parent 213b734 commit f1a9698
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 17 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
@import 'comments';
@import 'repositories';
@import 'responsive-utilities';
@import 'search';
44 changes: 44 additions & 0 deletions app/assets/stylesheets/search.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.search {
.category-panel {
.result-counter {
float: right;
background-color: $primary-colour;
border-radius: 0.5rem;
padding: 0 0.5rem;
font-weight: bold;
color: $white;
:hover {
background-color: $primary-colour;
}
}
.nav-pills {
.category {
border-radius: 0;
:hover {
border-radius: 0;
background-color: lighten($gray-light, 15);
}
}
.active-cetegory {
background-color: lighten($gray-light, 15);
border-left: 0.5rem solid $primary-colour;
}
}
.nav-tabs {
.category {
border: 1px solid $gray-light;
border-bottom: 0;
border-top: 0.5rem solid $gray-light;
border-radius: 0.5rem 0.5rem 0 0;
background-color: lighten($gray-light, 15);
}
.active-cetegory {
border-top: 0.5rem solid $primary-colour;
background-color: $white;
}
.result-counter {
margin-left: 1rem;
}
}
}
}
2 changes: 2 additions & 0 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ class SearchController < ApplicationController
def index
search = params[:search].split(":").first
@repositories = policy_scope(Repository).search(search)
@teams = policy_scope(Team).search(search)
@namespaces = policy_scope(Namespace).search(search)
end
end
5 changes: 5 additions & 0 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module SearchHelper
def build_search_category_url(params, category)
"#{search_index_path}?utf8=#{params[:utf8]}&search=#{params[:search]}&type=#{category}"
end
end
5 changes: 5 additions & 0 deletions app/models/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

class Namespace < ActiveRecord::Base
include PublicActivity::Common
include SearchCop

search_scope :search do
attributes :name, :description
end

# This regexp is extracted from the reference package of Docker Distribution
# and it matches a valid namespace name.
Expand Down
5 changes: 5 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

class Team < ActiveRecord::Base
include PublicActivity::Common
include SearchCop

search_scope :search do
attributes :name, :description
end

# Returns all the teams that are not special. By special team we mean:
# - It's the global namespace (see: Registry#create_namespaces!).
Expand Down
13 changes: 13 additions & 0 deletions app/views/search/_desktop_categories.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ul.nav.nav-pills.nav-stacked
li[class="category #{params[:type] == "repositories" ? 'active-cetegory' : ''}"]
a href="#{build_search_category_url params, 'repositories'}"
| Repositories
span.result-counter = @repositories.count
li[class="category #{params[:type] == "namespaces" ? 'active-cetegory' : ''}"]
a href="#{build_search_category_url params, 'namespaces'}"
| Namespaces
span.result-counter = @namespaces.count
li[class="category #{params[:type] == "teams" ? 'active-cetegory' : ''}"]
a href="#{build_search_category_url params, 'teams'}"
| Teams
span.result-counter = @teams.count
13 changes: 13 additions & 0 deletions app/views/search/_mobile_categories.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ul.nav.nav-tabs
li[class="category #{params[:type] == "repositories" ? 'active-cetegory' : ''}"]
a href="#{build_search_category_url params, 'repositories'}"
| Repositories
span.result-counter = @repositories.count
li[class="category #{params[:type] == "namespaces" ? 'active-cetegory' : ''}"]
a href="#{build_search_category_url params, 'namespaces'}"
| Namespaces
span.result-counter = @namespaces.count
li[class="category #{params[:type] == "teams" ? 'active-cetegory' : ''}"]
a href="#{build_search_category_url params, 'teams'}"
| Teams
span.result-counter = @teams.count
21 changes: 21 additions & 0 deletions app/views/search/_namespaces.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- if @namespaces.empty?
p No match found.
- else
.table-responsive
table.table.table-stripped.table-hover
thead
tr
th Name
th Repositories
th Webhooks
th Created at
tbody
- @namespaces.each do |namespace|
tr id="namespace_#{namespace.id}"
td= link_to namespace.clean_name, namespace
td= namespace.repositories.count
- if current_user.admin? || namespace.team.users.include?(current_user)
td= link_to namespace.webhooks.count, namespace_webhooks_path(namespace)
- else
td= namespace.webhooks.count
td= time_tag namespace.created_at
16 changes: 16 additions & 0 deletions app/views/search/_repositories.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- if @repositories.empty?
p No match found.
- else
.table-responsive
table.table.table-striped.table-hover
thead
tr
th Namespace
th Repository
th Updated at
tbody
- @repositories.each do |repository|
tr
td= link_to repository.namespace.clean_name, repository.namespace
td= link_to repository.name, repository
td= time_tag repository.updated_at
18 changes: 18 additions & 0 deletions app/views/search/_teams.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- if @teams.empty?
p No match found.
- else
.table-responsive
table.table.table-striped.table-hover
thead
tr
th
th Team
th Number of members
th Number of namespaces
tbody#teams
- @teams.each do |team|
tr
td.table-icon= team_scope_icon(team)
td= link_to team.name, team
td= team.users.enabled.count
td= team.namespaces.count
30 changes: 15 additions & 15 deletions app/views/search/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
.panel.panel-default
.panel-heading
h5 Search results
.panel-body
- if @repositories.empty?
p No match found.
- else
.table-responsive
table.table.table-striped.table-hover
thead
tr
th Namespace
th Repository
tbody
- @repositories.each do |repository|
tr
td= link_to repository.namespace.clean_name, repository.namespace
td= link_to repository.name, repository
.panel-body.search
.row
.col-xs-12.col-md-4.col-lg-3.category-panel
.hidden-xs
= render template: "search/_desktop_categories.html.slim"
.visible-xs
= render template: "search/_mobile_categories.html.slim"
.col-xs-12.col-md-8.col-lg-9.search.search-result
- case params[:type]
- when 'repositories'
= render template: "search/_repositories.html.slim"
-when 'namespaces'
= render template: "search/_namespaces.html.slim"
-when 'teams'
= render template: "search/_teams.html.slim"
3 changes: 2 additions & 1 deletion app/views/shared/_header.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
.search-header.hidden-xs
.header-search-form
= form_tag search_index_path, method: 'get', class: 'navbar-form' do
= search_field_tag 'search', params[:search], class: 'form-control search-field', placeholder: 'Search repository'
= search_field_tag 'search', params[:search], class: 'form-control search-field', placeholder: 'Search'
= hidden_field_tag 'type', 'repositories'
button[type="submit" class="btn btn-default"]
i.fa.fa-search
.button-container
Expand Down
3 changes: 2 additions & 1 deletion app/views/shared/_search.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
.col-xs-12.visible-xs
= form_tag search_index_path, method: 'get', class: 'input-group shared-search' do
.input-group.shared-search
= search_field_tag 'search', params[:search], class: 'form-control', placeholder: 'Search repository'
= search_field_tag 'search', params[:search], class: 'form-control', placeholder: 'Search'
= hidden_field_tag 'type', 'repositories'
span.input-group-btn
button.btn.btn-default
i.fa.fa-search
12 changes: 12 additions & 0 deletions spec/helpers/search_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "rails_helper"

RSpec.describe SearchHelper, type: :helper do

describe "build_search_category_url" do
it "returns true if current user is an owner of the team" do
expected = "#{search_index_path}?utf8=✓&search=&type=repositories"
params = { utf8: "✓", search: "" }
expect(helper.build_search_category_url(params, "repositories")).to eq expected
end
end
end

0 comments on commit f1a9698

Please sign in to comment.