Skip to content

Commit

Permalink
Merge 900039f into 4bb8fff
Browse files Browse the repository at this point in the history
  • Loading branch information
hennevogel committed Feb 9, 2020
2 parents 4bb8fff + 900039f commit 4c2f198
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 74 deletions.
32 changes: 24 additions & 8 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions app/views/projects/_list.html.haml
Original file line number Diff line number Diff line change
@@ -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 }
- 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 }
18 changes: 18 additions & 0 deletions app/views/users/_empty_projects.html.haml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 22 additions & 4 deletions app/views/users/_tabs.html.haml
Original file line number Diff line number Diff line change
@@ -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
- 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
55 changes: 5 additions & 50 deletions app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c2f198

Please sign in to comment.