we_bridge_rails_engine_orgs 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/app/assets/javascripts/org_department_positions.js +2 -0
  4. data/app/assets/javascripts/org_departments.js +2 -0
  5. data/app/assets/stylesheets/org_department_positions.css +4 -0
  6. data/app/assets/stylesheets/org_departments.css +4 -0
  7. data/app/controllers/org_department_positions_controller.rb +58 -0
  8. data/app/controllers/org_departments_controller.rb +58 -0
  9. data/app/helpers/org_department_positions_helper.rb +2 -0
  10. data/app/helpers/org_departments_helper.rb +2 -0
  11. data/app/models/org.rb +11 -3
  12. data/app/models/org_branch.rb +15 -0
  13. data/app/models/org_department.rb +19 -0
  14. data/app/models/org_department_position.rb +26 -0
  15. data/app/models/org_department_position_member_mapping.rb +7 -0
  16. data/app/models/org_department_position_text.rb +10 -0
  17. data/app/models/org_department_text.rb +11 -0
  18. data/app/models/org_member.rb +5 -0
  19. data/app/views/org_department_positions/_form.html.builder +14 -0
  20. data/app/views/org_department_positions/edit.html.builder +7 -0
  21. data/app/views/org_department_positions/index.html.builder +25 -0
  22. data/app/views/org_department_positions/new.html.builder +5 -0
  23. data/app/views/org_department_positions/show.html.builder +8 -0
  24. data/app/views/org_departments/_form.html.builder +14 -0
  25. data/app/views/org_departments/edit.html.builder +7 -0
  26. data/app/views/org_departments/index.html.builder +25 -0
  27. data/app/views/org_departments/new.html.builder +5 -0
  28. data/app/views/org_departments/show.html.builder +8 -0
  29. data/config/routes.rb +3 -0
  30. data/db/migrate/20151204183447_create_org_departments.rb +18 -0
  31. data/db/migrate/20151204183612_create_org_department_positions.rb +26 -0
  32. data/lib/we_bridge_rails_engine_orgs/version.rb +1 -1
  33. data/spec/controllers/org_department_positions_controller_spec.rb +159 -0
  34. data/spec/controllers/org_departments_controller_spec.rb +159 -0
  35. data/spec/dummy/db/development.sqlite3 +0 -0
  36. data/spec/dummy/db/schema.rb +47 -1
  37. data/spec/dummy/db/test.sqlite3 +0 -0
  38. data/spec/dummy/log/development.log +1262 -0
  39. data/spec/dummy/log/test.log +3269 -0
  40. data/spec/factories/org_department_positions.rb +6 -0
  41. data/spec/factories/org_departments.rb +6 -0
  42. data/spec/helpers/org_department_positions_helper_spec.rb +15 -0
  43. data/spec/helpers/org_departments_helper_spec.rb +15 -0
  44. data/spec/models/org_branch_spec.rb +26 -1
  45. data/spec/models/org_department_position_spec.rb +5 -0
  46. data/spec/models/org_department_spec.rb +32 -0
  47. data/spec/models/org_member_spec.rb +18 -1
  48. data/spec/models/org_spec.rb +39 -1
  49. data/spec/routing/org_department_positions_routing_spec.rb +39 -0
  50. data/spec/routing/org_departments_routing_spec.rb +39 -0
  51. data/spec/views/org_department_positions/edit.html.builder_spec.rb +14 -0
  52. data/spec/views/org_department_positions/index.html.builder_spec.rb +14 -0
  53. data/spec/views/org_department_positions/new.html.builder_spec.rb +14 -0
  54. data/spec/views/org_department_positions/show.html.builder_spec.rb +11 -0
  55. data/spec/views/org_departments/edit.html.builder_spec.rb +14 -0
  56. data/spec/views/org_departments/index.html.builder_spec.rb +14 -0
  57. data/spec/views/org_departments/new.html.builder_spec.rb +14 -0
  58. data/spec/views/org_departments/show.html.builder_spec.rb +11 -0
  59. metadata +65 -4
  60. data/spec/dummy/tmp/pids/server.pid +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 396170864840366ac5d88174dd8e707d8cc4dfc5
4
- data.tar.gz: 9ae9fb53ab02f0802743dde23b3def46360aee9e
3
+ metadata.gz: 14b9016374ad865cee705818e1fedcc60a6aecf7
4
+ data.tar.gz: 1fe2962883d1053edd554e5a4cf714ba72d1dd8e
5
5
  SHA512:
6
- metadata.gz: d52bb9f1571cf006e27342a59c01e7d82055a9e4dc37a1b0e247cca66fe1c1bd0e0eba4ce9321fae893099351fa9adf70d2c8cf803282f290c02279d9ffd70c4
7
- data.tar.gz: efe37d5be28e6f00cf6ae38b84948274bd5b510d59f3eb3a9ce78b153e6dd65bc7fd04bf30158216193c559352993503947fe53bd35e02ad24660c0e24ebfa22
6
+ metadata.gz: 04cbf683c96391ab51fbcdc1b1461cc52d2d427eea06bccac18d67f3580e8fd76a47cc941394daefe037031a1dd6119e76308eda10be10d66f8e7811fc12fd8e
7
+ data.tar.gz: 3fbe31cbe763da133302f89c64de3bd28fb8f2e1c8a50b4d4b2bbc698b0bf43d140c2085a4d34842cb80adf2b786a6491ac2f62749456c662640c76d9356b7d8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- we_bridge_rails_engine_orgs (0.1.6)
4
+ we_bridge_rails_engine_orgs (0.1.7)
5
5
  actionview-helpers-auto_tag_helper
6
6
  activerecord-mlang
7
7
  we_bridge-auto_view_helper
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,58 @@
1
+ class OrgDepartmentPositionsController < ApplicationController
2
+ before_action :set_org_department_position, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /org_department_positions
5
+ def index
6
+ @org_department_positions = OrgDepartmentPosition.all
7
+ end
8
+
9
+ # GET /org_department_positions/1
10
+ def show
11
+ end
12
+
13
+ # GET /org_department_positions/new
14
+ def new
15
+ @org_department_position = OrgDepartmentPosition.new
16
+ end
17
+
18
+ # GET /org_department_positions/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /org_department_positions
23
+ def create
24
+ @org_department_position = OrgDepartmentPosition.new(org_department_position_params)
25
+
26
+ if @org_department_position.save
27
+ redirect_to @org_department_position, notice: 'Org department position was successfully created.'
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /org_department_positions/1
34
+ def update
35
+ if @org_department_position.update(org_department_position_params)
36
+ redirect_to @org_department_position, notice: 'Org department position was successfully updated.'
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /org_department_positions/1
43
+ def destroy
44
+ @org_department_position.destroy
45
+ redirect_to org_department_positions_url, notice: 'Org department position was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_org_department_position
51
+ @org_department_position = OrgDepartmentPosition.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def org_department_position_params
56
+ params[:org_department_position]
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ class OrgDepartmentsController < ApplicationController
2
+ before_action :set_org_department, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /org_departments
5
+ def index
6
+ @org_departments = OrgDepartment.all
7
+ end
8
+
9
+ # GET /org_departments/1
10
+ def show
11
+ end
12
+
13
+ # GET /org_departments/new
14
+ def new
15
+ @org_department = OrgDepartment.new
16
+ end
17
+
18
+ # GET /org_departments/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /org_departments
23
+ def create
24
+ @org_department = OrgDepartment.new(org_department_params)
25
+
26
+ if @org_department.save
27
+ redirect_to @org_department, notice: 'Org department was successfully created.'
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /org_departments/1
34
+ def update
35
+ if @org_department.update(org_department_params)
36
+ redirect_to @org_department, notice: 'Org department was successfully updated.'
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /org_departments/1
43
+ def destroy
44
+ @org_department.destroy
45
+ redirect_to org_departments_url, notice: 'Org department was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_org_department
51
+ @org_department = OrgDepartment.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def org_department_params
56
+ params[:org_department]
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ module OrgDepartmentPositionsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module OrgDepartmentsHelper
2
+ end
data/app/models/org.rb CHANGED
@@ -3,13 +3,21 @@ require 'activerecord/mlang'
3
3
  class Org < ActiveRecord::Base
4
4
  belongs_to :lang
5
5
  has_many :director_types, class_name: "OrgDirectorType"
6
- has_many :directors, through: :director_types
7
- has_many :members, class_name: "OrgMember"
8
- has_many :member_tags, class_name: "OrgMemberTag"
6
+ has_many :directors, through: :director_types
7
+ has_many :members, class_name: "OrgMember"
8
+ has_many :member_types, class_name: "OrgMemberType"
9
+ has_many :member_tags, class_name: "OrgMemberTag"
10
+ has_many :activities, class_name: "OrgActivity"
9
11
  include ActiveRecord::Mlang
10
12
  include ActionView::Helpers::AutoTagHelper::FormInfo
11
13
  set_accessible_attrs :lang_id, :email,:url,:domain,:started_on,:post_number,:tel
12
14
  set_input_options :email, type: :email
13
15
  set_input_options :url, type: :url
14
16
  set_input_options :tel, type: :phone
17
+
18
+ def representative
19
+ tname = OrgDirectorType.table_name
20
+ self.directors.joins(:org_director_type).where("#{tname}.position" => OrgDirectorType.where(org_id: self.id).minimum(:position)).order(id: :asc).uniq.first
21
+ end
22
+
15
23
  end
@@ -3,6 +3,11 @@ require 'activerecord/mlang'
3
3
  class OrgBranch < ActiveRecord::Base
4
4
  belongs_to :org
5
5
  belongs_to :org_branch_type
6
+ has_many :branch_member_mappings, class_name: "OrgBranchMemberMapping"
7
+ has_many :members, through: :branch_member_mappings, source: :org_member
8
+
9
+ scope :has_member, ->(){ all.joins(branch_member_mappings: :org_member).uniq }
10
+
6
11
  include ActiveRecord::Mlang
7
12
  include ActionView::Helpers::AutoTagHelper::FormInfo
8
13
  set_accessible_attrs :org_branch_type_id, :position
@@ -11,4 +16,14 @@ class OrgBranch < ActiveRecord::Base
11
16
  def __display__
12
17
  self.text.name + self.org_branch_type.__display__
13
18
  end
19
+
20
+ # @member : OrgMember
21
+ def add(member)
22
+ member_id = case member
23
+ when Integer then member
24
+ when OrgMember then member.id
25
+ else member.to_i
26
+ end
27
+ OrgBranchMemberMapping.find_or_create_by(org_member_id: member_id, org_branch_id: self.id)
28
+ end
14
29
  end
@@ -0,0 +1,19 @@
1
+ require 'action_view/helpers/auto_tag_helper/form_info'
2
+ require 'activerecord/mlang'
3
+ class OrgDepartment < ActiveRecord::Base
4
+ belongs_to :org
5
+ belongs_to :manager, class_name: "OrgMember"
6
+ has_many :positions, class_name: "OrgDepartmentPosition"
7
+ has_many :position_member_mappings, through: :positions , source: :member_mappings
8
+ has_many :members, ->(){ uniq }, through: :position_member_mappings, source: :org_member
9
+
10
+ include ActiveRecord::Mlang
11
+ include ActionView::Helpers::AutoTagHelper::FormInfo
12
+
13
+ # def self.editable_columns(); [] ; end
14
+
15
+ def __display__
16
+ self.text.label
17
+ end
18
+
19
+ end
@@ -0,0 +1,26 @@
1
+ require 'action_view/helpers/auto_tag_helper/form_info'
2
+ require 'activerecord/mlang'
3
+ class OrgDepartmentPosition < ActiveRecord::Base
4
+ belongs_to :org_department
5
+ has_many :member_mappings, class_name: "OrgDepartmentPositionMemberMapping"
6
+ has_many :members, through: :member_mappings, source: :org_member
7
+
8
+ include ActiveRecord::Mlang
9
+ include ActionView::Helpers::AutoTagHelper::FormInfo
10
+
11
+ # def self.editable_columns(); [] ; end
12
+
13
+ def __display__
14
+ self.text.label
15
+ end
16
+
17
+ def add(member)
18
+ member_id = case member
19
+ when OrgMember then member.id
20
+ when Integer then member
21
+ else member.to_i
22
+ end
23
+ OrgDepartmentPositionMemberMapping.find_or_create_by(org_department_position_id: self.id, org_member_id: member_id)
24
+ end
25
+
26
+ end
@@ -0,0 +1,7 @@
1
+ class OrgDepartmentPositionMemberMapping < ActiveRecord::Base
2
+ belongs_to :org_department_position
3
+ def position() self.org_department_position; end
4
+ belongs_to :org_member
5
+ def member() self.org_member; end
6
+ end
7
+
@@ -0,0 +1,10 @@
1
+ require 'action_view/helpers/auto_tag_helper/form_info'
2
+ require 'activerecord/mlang'
3
+ class OrgDepartmentPositionText < ActiveRecord::Base
4
+ include ActiveRecord::Mlang::Text
5
+ include ActionView::Helpers::AutoTagHelper::FormInfo
6
+ set_accessible_attrs :name, :desc
7
+ def __display__
8
+ self.name
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require 'action_view/helpers/auto_tag_helper/form_info'
2
+ require 'activerecord/mlang'
3
+ class OrgDepartmentText < ActiveRecord::Base
4
+ include ActiveRecord::Mlang::Text
5
+ include ActionView::Helpers::AutoTagHelper::FormInfo
6
+ set_accessible_attrs :name,:desc
7
+ def __display__
8
+ self.name
9
+ end
10
+ end
11
+
@@ -10,6 +10,9 @@ class OrgMember < ActiveRecord::Base
10
10
  has_many :member_tag_mappings, class_name: "OrgMemberTagMapping"
11
11
  has_many :tags, through: :member_tag_mappings, source: :org_member_tag
12
12
 
13
+ has_many :branch_member_mappings, class_name: "OrgBranchMemberMapping"
14
+ has_many :branches, through: :branch_member_mappings, source: :org_branch
15
+
13
16
  enum sex: [:male,:female, :unknown]
14
17
 
15
18
  include ActiveRecord::Mlang
@@ -20,6 +23,8 @@ class OrgMember < ActiveRecord::Base
20
23
  set_input_options :bday, min: 1, max: 31
21
24
  set_input_options :sex, min: -1, max: 1
22
25
 
26
+ default_scope ->(){ where(retired_on: nil) }
27
+
23
28
  def others
24
29
  self.class.where(org_id: self.org_id).where.not(id: self.id)
25
30
  end
@@ -0,0 +1,14 @@
1
+ form_for @org_department_position do |f|
2
+ markup{|m|
3
+ if @org_department_position.errors.any?
4
+ #error_explanation
5
+ m.h2 "#{pluralize(@org_department_position.errors.count, "error")} prohibited this org_department_position from being saved:"
6
+ m.ul do
7
+ @org_department_position.errors.full_messages.each do |message|
8
+ m.li message
9
+ end
10
+ end
11
+ end
12
+ m << f.submit
13
+ }.html_safe
14
+ end
@@ -0,0 +1,7 @@
1
+ markup do |m|
2
+ m.h1 "Editing org_department_position"
3
+ m << render('form')
4
+ m << link_to('Show', @org_department_position)
5
+ m << link_to('Back', org_department_positions_path)
6
+ end
7
+
@@ -0,0 +1,25 @@
1
+ markup do |m|
2
+ m.h1 'Listing org_department_positions'
3
+ m.table do
4
+ m.thead do
5
+ m.tr do
6
+ m.th
7
+ m.th
8
+ m.th
9
+ end
10
+ end
11
+ m.tbody do
12
+ @org_department_positions.each do |org_department_position|
13
+ m.tr do
14
+ m.td { m << link_to('Show', 'org_department_position') }
15
+ m.td { m << link_to('Edit', edit_org_department_position_path(org_department_position)) }
16
+ m.td { m << link_to('Destroy', org_department_position, data: { confirm: 'Are you sure?' }, method: :delete) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ m.br
23
+ m << link_to('New Org department position', new_org_department_position_path)
24
+
25
+ end
@@ -0,0 +1,5 @@
1
+ markup do |m|
2
+ m.h1 'New org_department_position'
3
+ m << render('form')
4
+ m << link_to('Back', org_department_positions_path)
5
+ end
@@ -0,0 +1,8 @@
1
+ markup do |m|
2
+ m.p id: 'notice'
3
+ m.dl do
4
+ end
5
+
6
+ m << link_to('Edit', edit_org_department_position_path(@org_department_position))
7
+ m << link_to('Back', org_department_positions_path)
8
+ end
@@ -0,0 +1,14 @@
1
+ form_for @org_department do |f|
2
+ markup{|m|
3
+ if @org_department.errors.any?
4
+ #error_explanation
5
+ m.h2 "#{pluralize(@org_department.errors.count, "error")} prohibited this org_department from being saved:"
6
+ m.ul do
7
+ @org_department.errors.full_messages.each do |message|
8
+ m.li message
9
+ end
10
+ end
11
+ end
12
+ m << f.submit
13
+ }.html_safe
14
+ end
@@ -0,0 +1,7 @@
1
+ markup do |m|
2
+ m.h1 "Editing org_department"
3
+ m << render('form')
4
+ m << link_to('Show', @org_department)
5
+ m << link_to('Back', org_departments_path)
6
+ end
7
+
@@ -0,0 +1,25 @@
1
+ markup do |m|
2
+ m.h1 'Listing org_departments'
3
+ m.table do
4
+ m.thead do
5
+ m.tr do
6
+ m.th
7
+ m.th
8
+ m.th
9
+ end
10
+ end
11
+ m.tbody do
12
+ @org_departments.each do |org_department|
13
+ m.tr do
14
+ m.td { m << link_to('Show', 'org_department') }
15
+ m.td { m << link_to('Edit', edit_org_department_path(org_department)) }
16
+ m.td { m << link_to('Destroy', org_department, data: { confirm: 'Are you sure?' }, method: :delete) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ m.br
23
+ m << link_to('New Org department', new_org_department_path)
24
+
25
+ end