Skip to content

Commit

Permalink
Add featured flag to repository (#1499).
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenk committed Feb 23, 2017
1 parent 805b50c commit e0dfebf
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 11 deletions.
1 change: 0 additions & 1 deletion app/assets/stylesheets/data_type.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
position: -4px center !important
padding-left: 30px !important


.ui-autocomplete a, .relationList li, a
&[data-type=Team]
+data-icon(team)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ def index
@comments = Comment.latest.limit(10)
@versions = OntologyVersion.accessible_by(current_user).latest.
where(state: 'done').limit(10)
@repositories = Repository.accessible_by(current_user).latest.limit(10)
@repositories = Repository.accessible_by(current_user).latest
@featured_repositories = @repositories.where(featured: true).limit(10)
@common_repositories = @repositories.where(featured: false).limit(10)
end

def show
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def update

def index
@repositories = Repository.accessible_by(current_user)
@featured_repositories = @repositories.where(featured: true)
@common_repositories = @repositories.where(featured: false)
super
end

Expand Down
8 changes: 7 additions & 1 deletion app/helpers/link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ def fancy_link(resource)
resource
end

link_to name, linked_to,
link = link_to name, linked_to,
data_type => value,
title: title

if resource.respond_to?(:featured?) && resource.featured?
%(<i class="fa fa-star-o"></i> #{link}).html_safe
else
link
end
end

def format_links(*args, &block)
Expand Down
3 changes: 3 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def initialize(user, access_token)
(subject.permission?(:editor, user) || subject.public_rw?)
end
end
can [:feature], Repository do |subject|
user.admin?
end
can [:update, :destroy, :permissions], Repository do |subject|
subject.permission?(:owner, user)
end
Expand Down
1 change: 1 addition & 0 deletions app/models/repository/associations_and_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Repository::AssociationsAndAttributes
:source_address,
:remote_type,
:access,
:featured,
:destroy_job_id,
:is_destroying
end
Expand Down
17 changes: 13 additions & 4 deletions app/views/home/_versions.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
.pull-right
= link_to 'Browse Repositories', repositories_path, class: 'btn btn-primary', type: 'button'

- @repositories.each do |repository|
%div
= fancy_link repository
= timestamp repository.updated_at
- if @featured_repositories.any?
%h4 Featured
- @featured_repositories.each do |repository|
%div
= fancy_link repository
= timestamp repository.updated_at

- if @common_repositories.any?
%h4 Common
- @common_repositories.each do |repository|
%div
= fancy_link repository
= timestamp repository.updated_at

%h2 Recently Updated #{Settings.OMS.pluralize.capitalize}

Expand Down
4 changes: 4 additions & 0 deletions app/views/repositories/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
= select_tag :access_options_non_mirror, options_for_select(access_options)
= select_tag :access_options_mirror, options_for_select(access_options_mirror)

- if can?(:feature, @repository)
= f.input :featured, as: :boolean


= f.button :wrapped
17 changes: 13 additions & 4 deletions app/views/repositories/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
= t('.clone_list_prefix')
= link_to t('.clone_list_link'), repositories_path(format: :txt)

.row
.col-md-12.repository-index
%ul.list-group
= render collection
- if @featured_repositories.any?
%h3 Featured Repositories
.row
.col-md-12.repository-index
%ul.list-group
= render @featured_repositories

- if @common_repositories.any?
%h3 Common Repositories
.row
.col-md-12.repository-index
%ul.list-group
= render @common_repositories
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFeaturedFlagToRepositories < ActiveRecord::Migration
def change
add_column :repositories, :featured, :bool, default: false
end
end

0 comments on commit e0dfebf

Please sign in to comment.