diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7ce8c5be..86eff9c5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,9 +3,10 @@ class UsersController < ApplicationController before_action :find_user_by_id before_action :redirect_to_slug, only: [:show] load_and_authorize_resource find_by: :name + before_action :set_updates, except: :index - skip_before_action :authenticate_user!, :only => [ :index, :show ] - skip_before_action :verify_authenticity_token, :only => [:add_keyword, :delete_keyword ] + skip_before_action :authenticate_user!, only: [ :show, :originated, :likes, :opportunities ] + skip_before_action :verify_authenticity_token, only: [:add_keyword, :delete_keyword ] def index @users = User.all @@ -20,12 +21,22 @@ def update end def show - @updates = current_user.updates.page(1) - @last_page = current_user.updates.page(1).last_page? || current_user.updates.empty? + @projects = @user.projects.by_episode(Episode.active) end - def me - redirect_to user_path(current_user) + def originated + @projects = @user.originated_projects + render :show + end + + def likes + @projects = @user.favourites + render :show + end + + def opportunities + @projects = @user.recommended_projects(@episode) + render :show end def add_keyword @@ -34,7 +45,7 @@ def add_keyword logger.debug "Adding keyword \"#{word}\" from user #{@user.id}" current_user.add_keyword! word end - redirect_to :action => "me", notice: "Keyword '#{params[:keyword]}' added." + redirect_to @user, notice: "Keyword '#{params[:keyword]}' added." end def delete_keyword @@ -43,7 +54,7 @@ def delete_keyword logger.debug "Deleting keyword \"#{word}\" to user #{@user.id}" current_user.remove_keyword! word end - redirect_to :action => "me", notice: "Keyword '#{params[:keyword]}' removed." + redirect_to @user, notice: "Keyword '#{params[:keyword]}' removed." end private @@ -59,6 +70,11 @@ def find_user_by_id @user = User.find_by(id: params[:id]) end + def set_updates + @updates = @user.updates.page(1) + @last_page = @user.updates.page(1).last_page? || @user.updates.empty? + end + def redirect_to_slug redirect_to @user if @user end diff --git a/app/models/ability.rb b/app/models/ability.rb index 1207c90f..12cc08ef 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -24,11 +24,12 @@ def initialize(user) # Everyone can: can :read, :all can [:join, :leave, :like, :dislike, :create], Project + can [:originated, :likes, :opportunities], User can [:enroll], Announcement # ...manage things they own - can :manage, Project, originator_id: user.id can :manage, User, id: user.id can :read, Update, author_id: user.id + can :manage, Project, originator_id: user.id can [:edit, :update, :add_keyword, :delete_keyword, :advance, :recess, :add_episode, :delete_episode], Project do |project| project.users.include? user end diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index e15b6829..d43579f2 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -44,7 +44,7 @@ %b.caret %ul.dropdown-menu %li - = link_to(me_users_path, :id => "me_users_path") do + = link_to(user_path(current_user), :id => "me_users_path") do %i.fa.fa-home = current_user.name %li @@ -69,7 +69,7 @@ %li{role: "presentation", class: "dropdown-header"} = current_user.name %li - = link_to(me_users_path) do + = link_to(user_path(current_user)) do %i.fa.fa-home Home %li diff --git a/app/views/projects/_list.html.haml b/app/views/projects/_list.html.haml index a46f6895..c402e1a9 100644 --- a/app/views/projects/_list.html.haml +++ b/app/views/projects/_list.html.haml @@ -1,7 +1,4 @@ -if projects - %table.table - %thead - - projects.each_with_index do |project, index| - %tr - %td{:class => "#{project.aasm_state}"} - = render :partial => "projects/list_item", :locals => {:project => project, :index => index } \ No newline at end of file + - projects.each_with_index do |project, index| + %div{class: "#{project.aasm_state}", style: "border-bottom: 1px solid #ddd; padding: 10px 0 10px 0;"} + = render :partial => "projects/list_item", :locals => {:project => project, :index => index } diff --git a/app/views/users/_empty_projects.html.haml b/app/views/users/_empty_projects.html.haml new file mode 100644 index 00000000..a219daf5 --- /dev/null +++ b/app/views/users/_empty_projects.html.haml @@ -0,0 +1,18 @@ +%p + - if action_name == 'show' + No project yet, join one! + - if @user == current_user + Check out your + = link_to opportunities_user_path(@user) do + opportunities. + - if action_name == "opportunities" + No project is matching your keywords yet, try adding some more on the right. + - if action_name == "originated" + No ideas yet. + - if @user == current_user + How about you + = link_to new_project_path do + create one? + - if action_name == "likes" + No likes yet, spread some + %i.fa.fa-heart \ No newline at end of file diff --git a/app/views/users/_tabs.html.haml b/app/views/users/_tabs.html.haml index 841b41fa..8884101a 100644 --- a/app/views/users/_tabs.html.haml +++ b/app/views/users/_tabs.html.haml @@ -1,5 +1,23 @@ %ul.nav.nav-tabs - - all_state = "active" if action_name == "index" - %li{:class => all_state} - =link_to projects_path, :title => "All projects" do - All \ No newline at end of file + - works_state = "active" if action_name == "show" + %li{:class => works_state} + =link_to user_path(@user), :title => "Ideas #{@user.name} came up with" do + %span + Works on + - originated_state = "active" if action_name == "originated" + %li{:class => originated_state} + =link_to originated_user_path(@user), :title => "Ideas #{@user.name} came up with" do + %span + Originated + - likes_state = "active" if action_name == "likes" + %li{class: likes_state} + =link_to likes_user_path(@user), title: "Things #{@user.name} likes" do + %span.hidden-xs + Likes + %i.fa.fa-star.visible-xs + - opportunities_state = "active" if action_name == "opportunities" + %li{:class => opportunities_state} + =link_to opportunities_user_path(@user), title: "Things #{@user.name} could hack on" do + %span.hidden-xs + Opportunities + %i.fa.fa-user.visible-xs diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 5730ebea..5b472f03 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -15,58 +15,13 @@ .clearfix .row .col-sm-8 - %ul.nav.nav-tabs - // When the user has an active project, show that. If not show opportunities - - if !@user.projects.by_episode(@episode).empty? - %li.active - %a{:href=>"#projects", "data-toggle"=>"tab"} - Works on - = "(#{@user.projects.by_episode(@episode).length})" - - else - %li.active - %a{:href=>"#recommended", "data-toggle"=>"tab"} - Opportunities - = "(#{@user.recommended_projects(@episode).length})" unless @user.recommended_projects(@episode).empty? - %li - %a{:href=>"#ideas", "data-toggle"=>"tab"} - Originated - = "(#{@user.originated_projects.length})" unless @user.originated_projects.empty? - %li - %a{:href=>"#likes", "data-toggle"=>"tab"} - Likes - = "(#{@user.favourites.length})" unless @user.favourites.empty? - // Append opportunities if the user has an active project - - unless @user.projects.empty? - %li - %a{:href=>"#recommended", "data-toggle"=>"tab"} - Opportunities - = "(#{@user.recommended_projects(@episode).length})" unless @user.recommended_projects(@episode).empty? + = render :partial => "users/tabs" .tab-content{:style=>"padding-top: 10px"} - - if !@user.projects.by_episode(@episode).empty? - .tab-pane.active#projects - = render :partial => "projects/list", :locals => {:projects => @user.projects.by_episode(@episode) } - - else - .tab-pane.active#recommended - - if @user.recommended_projects.empty? - %p no project is matching your keywords yet, try adding some more. - - else - = render :partial => "projects/list", :locals => {:projects => @user.recommended_projects } - .tab-pane#ideas - - if @user.originated_projects.empty? - %p no ideas yet + .tab-pane.active#projects + - if @projects.empty? + = render :partial => "empty_projects" - else - = render :partial => "projects/list", :locals => {:projects => @user.originated_projects } - .tab-pane#likes - - if @user.favourites.empty? - %p no projects yet - - else - = render :partial => "projects/list", :locals => {:projects => @user.favourites } - -unless @user.projects.empty? - .tab-pane#recommended - - if @user.recommended_projects.empty? - %p no project is matching your keywords yet, try adding some more. - - else - = render :partial => "projects/list", :locals => {:projects => @user.recommended_projects } + = render :partial => "projects/list", locals: { projects: @projects } .col-sm-4 .row .col-sm-12 diff --git a/config/routes.rb b/config/routes.rb index 37bd61fb..f5c8b728 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,10 +5,10 @@ devise_for :users resources :users, only: [:index, :show] do - collection do - get 'me' - end member do + get 'originated' + get 'likes' + get 'opportunities' post 'keyword', to: "users#add_keyword" delete 'keyword', to: "users#delete_keyword", constraints: { keyword: /[^\/]+/ } end