diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass index 6433384852d..5cd59044b83 100644 --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -1,3 +1,2 @@ @import bootstrap @import font-awesome -@import base diff --git a/app/controllers/practices_controller.rb b/app/controllers/practices_controller.rb index 6af8e2871bf..881ec66cf81 100644 --- a/app/controllers/practices_controller.rb +++ b/app/controllers/practices_controller.rb @@ -3,7 +3,14 @@ class PracticesController < ApplicationController before_action :set_practice, only: %w(show edit update destroy) def index - @practices = Practice.all + case current_user.major + when :programmer + @practices = Practice.for_programmer + when :designer + @practices = Practice.for_designer + else + @practices = Practice.all + end end def show @@ -41,7 +48,7 @@ def destroy private def practice_params - params.require(:practice).permit(:title, :description) + params.require(:practice).permit(:title, :description, :aim) end def set_practice diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index df0dc519e5f..6d0c1f091bc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -49,7 +49,8 @@ def user_params :last_name, :email, :password, - :password_cofirmation + :password_cofirmation, + :major ) end diff --git a/app/decorators/practice_decorator.rb b/app/decorators/practice_decorator.rb index 664d1cecb38..5732d2b15e3 100644 --- a/app/decorators/practice_decorator.rb +++ b/app/decorators/practice_decorator.rb @@ -13,6 +13,10 @@ def learning_status(user_id) end end + def for + "for #{self.aim.to_s}" + end + private def btn_group { 'unstarted' => 'btn', 'active' => 'btn btn-info', 'complete' => 'btn btn-success' } diff --git a/app/models/learning.rb b/app/models/learning.rb index abad897d966..e8473968520 100644 --- a/app/models/learning.rb +++ b/app/models/learning.rb @@ -1,5 +1,5 @@ class Learning < ActiveRecord::Base - as_enum :status, active: 0, complete: 1 + as_enum :status, [:active, :complete] belongs_to :user belongs_to :practice diff --git a/app/models/practice.rb b/app/models/practice.rb index 6bac53ef5e4..f27458bf1a6 100644 --- a/app/models/practice.rb +++ b/app/models/practice.rb @@ -1,6 +1,10 @@ class Practice < ActiveRecord::Base + as_enum :aim, [:everyone, :programmer, :designer] has_many :learnings validates :title, presence: true validates :description, presence: true + + scope :for_programmer, ->{ where.not(aim_cd: Practice.designer) } + scope :for_designer, ->{ where.not(aim_cd: Practice.programmer) } end diff --git a/app/models/user.rb b/app/models/user.rb index 58db1095299..4ae884b6195 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,22 @@ class User < ActiveRecord::Base + as_enum :major, [:programmer, :designer] authenticates_with_sorcery! has_many :learnings + + has_many :completed_learnings, + -> { where(status_cd: 1) }, + class_name: 'Learning' + has_many :completed_practices, + through: :completed_learnings, + source: :practice + + has_many :active_learnings, + -> { where(status_cd: 0) }, + class_name: 'Learning' + has_many :active_practices, + through: :active_learnings, + source: :practice + validates_length_of :password, minimum: 4, if: :password validates_confirmation_of :password, if: :password validates :login_name, presence: true, uniqueness: true diff --git a/app/views/practices/_form.html.haml b/app/views/practices/_form.html.haml index ed5271a1fb8..e45bd86e539 100644 --- a/app/views/practices/_form.html.haml +++ b/app/views/practices/_form.html.haml @@ -3,4 +3,5 @@ = error_messages_for :practice = f.input :title, input_html: { class: 'input-block-level' } = f.input :description, input_html: { class: 'input-block-level', rows: 20 } + = f.select :aim, Practice.aims.keys = f.submit nil, class: 'btn btn-primary' diff --git a/app/views/practices/show.html.haml b/app/views/practices/show.html.haml index 504642a4867..bdcde11b44e 100644 --- a/app/views/practices/show.html.haml +++ b/app/views/practices/show.html.haml @@ -1,4 +1,5 @@ %h1= @practice.title +%p= @practice.for - if @practice.description? .practice= simple_format rendering(@practice.description) = link_to t('edit'), edit_practice_path(@practice), class: 'btn' diff --git a/app/views/users/_form.html.haml b/app/views/users/_form.html.haml index 7b1d75eb978..53e38cbcfd7 100644 --- a/app/views/users/_form.html.haml +++ b/app/views/users/_form.html.haml @@ -7,4 +7,5 @@ = f.input :email, hint: false, placeholder: t('helpers.label.user.email') = f.input :password, hint: false, placeholder: t('helpers.label.user.password') = f.input :password_confirmation, hint: false, placeholder: t('helpers.label.user.password_confirmation') + = f.select :major, User.majors.keys = f.submit nil, class: 'btn btn-large' diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 2d9ef1a2c06..492f901cecd 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,3 +1,4 @@ .icon= gravatar_tag @user, size: 100 %p= @user.login_name %p= @user.full_name +%p= @user.major diff --git a/db/migrate/20130315065106_add_columns_to_users_and_practices.rb b/db/migrate/20130315065106_add_columns_to_users_and_practices.rb new file mode 100644 index 00000000000..34c5187bf6c --- /dev/null +++ b/db/migrate/20130315065106_add_columns_to_users_and_practices.rb @@ -0,0 +1,6 @@ +class AddColumnsToUsersAndPractices < ActiveRecord::Migration + def change + add_column :practices, :aim_cd, :integer, null: false, default: 0 + add_column :users, :major_cd, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index bb5b5a6c697..91f9fb2a5a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20130313095813) do +ActiveRecord::Schema.define(version: 20130315065106) do create_table "learnings", force: true do |t| t.integer "user_id", null: false @@ -22,10 +22,11 @@ end create_table "practices", force: true do |t| - t.string "title", null: false + t.string "title", null: false t.text "description" t.datetime "created_at" t.datetime "updated_at" + t.integer "aim_cd", default: 0, null: false end create_table "users", force: true do |t| @@ -39,6 +40,7 @@ t.datetime "remember_me_token_expires_at" t.string "first_name" t.string "last_name" + t.integer "major_cd" end add_index "users", ["remember_me_token"], name: "index_users_on_remember_me_token" diff --git a/db/seeds.rb b/db/seeds.rb index a56dccaa54b..099f09f44d6 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -11,16 +11,18 @@ last_name: 'Komagata', email: 'komagata@gmail.com', password: 'testtest', - password_confirmation: 'testtest' + password_confirmation: 'testtest', + major_cd: 0 ) User.create!( login_name: 'machida', first_name: 'Teppei', - last_name: 'machida', + last_name: 'Machida', email: 'machidanohimitsu@gmail.com', password: 'testtest', - password_confirmation: 'testtest' + password_confirmation: 'testtest', + major_cd: 1 ) import_fixture 'practices'