Skip to content

Commit 799aaa8

Browse files
authored
Merge pull request #73 from rmd6502/volunteerings_state
Volunteerings state
2 parents 93e0c58 + 10a6d9d commit 799aaa8

22 files changed

+129
-47
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pickle-email-*.html
2727
## Environment normalization:
2828
/.bundle
2929
/vendor/bundle
30+
/vendor/cache
3031

3132
# these should all be checked in to normalize the environment:
3233
# Gemfile.lock, .ruby-version, .ruby-gemset

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ gem 'cancan' # or cancancan
2121
gem 'draper'
2222
gem 'pundit'
2323
gem 'audited', '~> 4.7'
24+
gem 'aasm'
2425

2526

2627
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'

Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4+
aasm (5.0.2)
5+
concurrent-ruby (~> 1.0)
46
actioncable (5.1.6)
57
actionpack (= 5.1.6)
68
nio4r (~> 2.0)
@@ -323,6 +325,7 @@ PLATFORMS
323325
ruby
324326

325327
DEPENDENCIES
328+
aasm
326329
activeadmin
327330
activeadmin-select2
328331
airrecord

app/admin/projects.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
project.website.try(:truncate, 20)
3030
end
3131
column :slack_channel
32-
column :skills do |project|
33-
span project.skills.map(&:name).to_sentence
32+
column :stacks do |project|
33+
span project.stacks.map(&:name).to_sentence
3434
end
3535
column :volunteers do |project|
3636
c = project.volunteers.count

app/admin/volunteerings.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ActiveAdmin.register Volunteering do
2+
# See permitted parameters documentation:
3+
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
4+
#
5+
# permit_params :list, :of, :attributes, :on, :model
6+
#
7+
# or
8+
#
9+
# permit_params do
10+
# permitted = [:permitted, :attributes]
11+
# permitted << :other if params[:action] == 'create' && current_user.admin?
12+
# permitted
13+
# end
14+
15+
end

app/controllers/application_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def new_session_path(scope)
1010
def set_skills
1111
@tech_skills = Skill.tech_skills
1212
@non_tech_skills = Skill.non_tech_skills
13-
@skills = Skill.all
13+
@all_skills = Skill.all
1414
end
1515

1616
def after_sign_in_path_for(resource)

app/controllers/dashboard/projects_controller.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,29 @@ def create
1111
@project.needs_categories = Skill.where(:name => needs_category_names)
1212
if @project.valid?
1313
@project.save
14-
redirect_to dashboard_project_path(@project)
14+
redirect_to edit_dashboard_project_path(@project)
1515
else
16-
render :new_edit
16+
render :edit
1717
end
1818
end
1919

2020
def edit
2121
if resource.mission_aligned
2222
render :aligned_edit
2323
else
24-
render :new_edit
24+
render :edit
2525
end
2626

2727
end
2828

29+
def update
30+
if resource.save
31+
redirect_to edit_dashboard_project_path(@project)
32+
else
33+
render :edit
34+
end
35+
end
36+
2937
private
3038

3139
def begin_of_association_chain

app/models/project.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@ class Project < ApplicationRecord
1010
has_and_belongs_to_many :tech_stack, -> { where tech: true }, class_name: "Skill", join_table: "projects_skills"
1111
has_and_belongs_to_many :non_tech_stack, -> { where tech: !true }, class_name: "Skill", join_table: "projects_skills"
1212

13-
has_and_belongs_to_many :volunteers, class_name: "User", join_table: "projects_volunteers"
13+
has_many :volunteerings
14+
has_many :active_volunteerings, -> { where state: 'active' }, class_name: 'Volunteering'
15+
has_many :volunteers, through: :active_volunteerings, source: 'user'
1416

1517
validates_presence_of :name, :description, :tech_stack, :tech_stack_names
1618

1719
validates :legal_structures, :presence => true,:allow_blank => false
1820

1921
after_save :remove_blank_values
20-
2122
audited
22-
23-
audited associated_with: :user
24-
audited associated_with: :skills
2523
has_associated_audits
2624

2725
def leads

app/models/skill.rb

-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,4 @@ class Skill < ApplicationRecord
1313

1414
audited
1515

16-
audited associated_with: :project
17-
audited associated_with: :user
18-
has_associated_audits
19-
2016
end

app/models/user.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ class User < ApplicationRecord
88
validates_presence_of :name, :email, :slack_username, :location, :hear_about_us, :join_reason
99
validates_acceptance_of :read_code_of_conduct
1010

11-
has_and_belongs_to_many :volunteerings, class_name: "Project", join_table: "projects_volunteers"
11+
has_many :volunteerings
12+
has_many :active_volunteerings, -> { where state: 'active' }, class_name: 'Volunteering'
13+
has_many :projects, through: :active_volunteerings, source: 'user'
1214

1315
# after_create :send_slack_notification
1416

1517
devise :omniauthable, omniauth_providers: [:slack]
1618

1719
audited
18-
19-
audited associated_with: :user
20-
audited associated_with: :skill
2120
has_associated_audits
2221

2322
def self.from_omniauth(auth)

app/models/volunteering.rb

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class Volunteering < ApplicationRecord
2+
include AASM
3+
4+
belongs_to :user
5+
belongs_to :project
6+
7+
audited associated_with: :project
8+
audited associated_with: :user
9+
10+
aasm :column => 'state' do
11+
state :potential, initial: true
12+
state :signed_up
13+
state :invited
14+
state :active
15+
state :resigned
16+
state :removed
17+
state :former
18+
19+
event :apply do
20+
transitions from: [:potential, :former], to: :signed_up
21+
end
22+
23+
event :recruit do
24+
transitions from: [:potential, :former], to: :invited
25+
end
26+
27+
event :confirm do
28+
transitions from: [:signed_up, :invited], to: :active
29+
30+
transitions from: [:resigned, :removed], to: :former
31+
end
32+
33+
event :leave do
34+
transitions from: :active, to: :resigned
35+
end
36+
37+
event :remove do
38+
transitions from: :active, to: :removed
39+
end
40+
41+
end
42+
43+
end

app/views/dashboard/projects/_aligned_form.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<%= f.input :non_tech_stack_names, label: 'Non-Tech Stack', :hint => 'What non-tech attributes does your project have?', :placeholder => "Type something...", :input_html => {:data => {:tokens => format_skills(resource.non_tech_stack), :typeahead_source => format_skills(@non_tech_skills) }} %>
1515

16-
<%= f.input :needs_category_names, :label => 'Needs Categories', :hint => 'What skills are needed for your project? Choose as many as are relevant!', :placeholder => "Type something...", :input_html => {:data => {:tokens => format_skills(resource.needs_categories), :typeahead_source => format_skills(@skills)}} %>
16+
<%= f.input :needs_category_names, :label => 'Needs Categories', :hint => 'What skills are needed for your project? Choose as many as are relevant!', :placeholder => "Type something...", :input_html => {:data => {:tokens => format_skills(resource.needs_categories), :typeahead_source => format_skills(@all_skills)}} %>
1717

1818
<%= f.input :status, :label => 'Project Status',:hint => 'You may select more than one', :collection => Project::STATUSES, :input_html => { :multiple => true }, :include_blank => true, :include_hidden => false %>
1919

app/views/dashboard/projects/_new_form.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<%= f.input :non_tech_stack_names, label: 'Non-Tech Stack', :hint => 'What non-tech attributes does your project have?', :placeholder => "Type something...", :input_html => {:data => {:tokens => format_skills(resource.non_tech_stack), :typeahead_source => format_skills(@non_tech_skills) }} %>
1717

18-
<%= f.input :needs_category_names, :label => 'Needs Categories', :hint => 'What skills are needed for your project? Choose as many as are relevant!', :placeholder => "Type something...", :input_html => {:data => {:tokens => format_skills(resource.needs_categories), :typeahead_source => format_skills(@skills)}} %>
18+
<%= f.input :needs_category_names, :label => 'Needs Categories', :hint => 'What skills are needed for your project? Choose as many as are relevant!', :placeholder => "Type something...", :input_html => {:data => {:tokens => format_skills(resource.needs_categories), :typeahead_source => format_skills(@all_skills)}} %>
1919

2020
<%= f.input :status, :label => 'Project Status',:hint => 'You may select more than one', :collection => Project::STATUSES, :input_html => { :multiple => true }, :include_blank => true, :include_hidden => false %>
2121

app/views/dashboard/projects/aligned_edit.html.erb

-7
This file was deleted.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<h1>Edit Project</h1>
2+
3+
<%= render 'shared/invalid_skill_modal'%>
4+
5+
<% if resource.mission_aligned%>
6+
<%= render 'aligned_form'%>
7+
<% else %>
8+
<%= render 'new_form', dashboard_project: @dashboard_project %>
9+
<% end %>
10+
11+
<%= link_to 'Back', dashboard_projects_path %>

app/views/dashboard/projects/new.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<%= render 'shared/invalid_skill_modal'%>
44

55

6-
<%= render 'form' %>
6+
<%= render 'new_form' %>
77

88
<%= link_to 'Back', dashboard_projects_path %>

app/views/dashboard/projects/new_edit.html.erb

-7
This file was deleted.

app/views/layouts/dashboard.html.erb

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
2020
<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#">ProgBot Dashboard</a>
2121
<input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
22-
<a class="nav-link" href="/skills">Browse Projects by Skills</a>
23-
<a class="nav-link" href="/projects">Browse Projects Alphabetically</a>
2422

2523
<ul class="navbar-nav px-3">
2624
<li class="nav-item text-nowrap">
@@ -58,7 +56,14 @@
5856
Volunteerings
5957
</a>
6058
</li>
61-
59+
<li class="nav-item">
60+
<a class="nav-link" href="/skills">
61+
Browse Projects by Skills
62+
</a>
63+
</li>
64+
<li class="nav-item">
65+
<a class="nav-link" href="/projects">Browse Projects Alphabetically</a>
66+
</li>
6267
</ul>
6368
</div>
6469
</nav>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class ChangeProjectsVolunteersToVolunteerings < ActiveRecord::Migration[5.1]
2+
def change
3+
rename_table :projects_volunteers, :volunteerings
4+
end
5+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddStateToVolunteerings < ActiveRecord::Migration[5.1]
2+
def change
3+
add_column :volunteerings, :state, :string
4+
end
5+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddIdToVolunterings < ActiveRecord::Migration[5.1]
2+
def change
3+
add_column :volunteerings, :id, :primary_key
4+
end
5+
end

db/schema.rb

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 20181231183949) do
13+
ActiveRecord::Schema.define(version: 20190329025330) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -114,13 +114,6 @@
114114
t.index ["skill_id"], name: "index_projects_skills_on_skill_id"
115115
end
116116

117-
create_table "projects_volunteers", id: false, force: :cascade do |t|
118-
t.bigint "project_id"
119-
t.bigint "user_id"
120-
t.index ["project_id"], name: "index_projects_volunteers_on_project_id"
121-
t.index ["user_id"], name: "index_projects_volunteers_on_user_id"
122-
end
123-
124117
create_table "skills", force: :cascade do |t|
125118
t.string "name"
126119
t.datetime "created_at", null: false
@@ -172,4 +165,12 @@
172165
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
173166
end
174167

168+
create_table "volunteerings", force: :cascade do |t|
169+
t.bigint "project_id"
170+
t.bigint "user_id"
171+
t.string "state"
172+
t.index ["project_id"], name: "index_volunteerings_on_project_id"
173+
t.index ["user_id"], name: "index_volunteerings_on_user_id"
174+
end
175+
175176
end

0 commit comments

Comments
 (0)