voluntary 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/app/assets/javascripts/voluntary/application.js +1 -1
  2. data/app/assets/javascripts/voluntary/base.js.coffee +30 -1
  3. data/app/assets/stylesheets/voluntary/application.css +1 -0
  4. data/app/assets/stylesheets/voluntary/base.css.sass +1 -1
  5. data/app/controllers/areas_controller.rb +6 -5
  6. data/app/controllers/candidatures_controller.rb +15 -10
  7. data/app/controllers/concerns/voluntary/v1/base_controller.rb +95 -0
  8. data/app/controllers/devise_extensions/registrations_controller.rb +2 -2
  9. data/app/controllers/organizations_controller.rb +7 -6
  10. data/app/controllers/professions_controller.rb +6 -5
  11. data/app/controllers/projects_controller.rb +11 -6
  12. data/app/controllers/users_controller.rb +2 -2
  13. data/app/controllers/vacancies_controller.rb +14 -5
  14. data/app/controllers/voluntary/api/v1/api_controller.rb +9 -0
  15. data/app/controllers/voluntary/application_controller.rb +2 -66
  16. data/app/controllers/workflow/candidatures_controller.rb +1 -1
  17. data/app/controllers/workflow/products_controller.rb +7 -7
  18. data/app/controllers/workflow/stories_controller.rb +1 -1
  19. data/app/controllers/workflow/tasks_controller.rb +2 -2
  20. data/app/controllers/workflow/user/product/areas_controller.rb +2 -2
  21. data/app/controllers/workflow/user/projects_controller.rb +10 -2
  22. data/app/helpers/voluntary/application_helper.rb +79 -0
  23. data/app/helpers/voluntary/collection_helper.rb +45 -0
  24. data/app/helpers/voluntary/comments_helper.rb +13 -0
  25. data/app/helpers/voluntary/form_helper.rb +46 -0
  26. data/app/helpers/voluntary/language_helper.rb +17 -0
  27. data/app/helpers/voluntary/layout_helper.rb +42 -0
  28. data/app/helpers/voluntary/product_helper.rb +36 -0
  29. data/app/helpers/voluntary/show_helper.rb +67 -0
  30. data/app/helpers/voluntary/wizard_helper.rb +29 -0
  31. data/app/models/ability.rb +20 -4
  32. data/app/models/candidature.rb +10 -7
  33. data/app/models/column.rb +1 -0
  34. data/app/models/concerns/user/extensions.rb +5 -0
  35. data/app/models/concerns/user/listable.rb +10 -0
  36. data/app/models/list.rb +30 -0
  37. data/app/models/list_item.rb +22 -0
  38. data/app/models/organization.rb +1 -0
  39. data/app/models/page.rb +2 -1
  40. data/app/models/product.rb +3 -2
  41. data/app/models/project.rb +2 -2
  42. data/app/models/result.rb +1 -0
  43. data/app/models/role.rb +1 -1
  44. data/app/models/state_machines/candidature.rb +17 -1
  45. data/app/models/state_machines/story.rb +15 -2
  46. data/app/models/state_machines/task.rb +33 -0
  47. data/app/models/story.rb +3 -2
  48. data/app/models/task.rb +44 -6
  49. data/app/models/thing.rb +3 -0
  50. data/app/models/user.rb +15 -4
  51. data/app/models/vacancy.rb +7 -5
  52. data/app/presenters/resources/general/wizards/story/steps/setup_tasks_presenter.rb +1 -1
  53. data/app/presenters/shared/collection/table_presenter.rb +1 -1
  54. data/app/views/candidatures/index.html.erb +1 -1
  55. data/app/views/candidatures/show.html.erb +1 -1
  56. data/app/views/columns/_collection.html.erb +0 -0
  57. data/app/views/comments/_resource.html.erb +1 -1
  58. data/app/views/layouts/application.html.erb +12 -0
  59. data/app/views/layouts/shared/_navigation.html.erb +3 -3
  60. data/app/views/organizations/show.html.erb +0 -1
  61. data/app/views/products/index.html.erb +53 -4
  62. data/app/views/projects/_form.html.erb +1 -0
  63. data/app/views/projects/show.html.erb +2 -1
  64. data/app/views/shared/collection/_list.html.erb +1 -1
  65. data/app/views/shared/resource/_actions.html.erb +2 -2
  66. data/app/views/stories/_column_fields.html.erb +0 -0
  67. data/app/views/stories/_form.html.erb +1 -1
  68. data/app/views/stories/steps/_activate.html.erb +1 -1
  69. data/app/views/workflow/products/show.html.erb +1 -1
  70. data/app/views/workflow/project_owner/_candidatures.html.erb +2 -1
  71. data/app/views/workflow/tasks/_work_head.html.erb +1 -1
  72. data/app/views/workflow/tasks/steps/_complete.html.erb +6 -2
  73. data/app/views/workflow/tasks/steps/_review.html.erb +6 -2
  74. data/app/views/workflow/tasks/steps/_work.html.erb +4 -2
  75. data/app/views/workflow/user/product/areas/show.html.erb +0 -0
  76. data/app/views/workflow/user/projects/show.html.erb +0 -0
  77. data/config/initializers/devise.rb +2 -5
  78. data/config/initializers/filter_parameters_logging.rb +1 -0
  79. data/config/initializers/friendly_id.rb +88 -0
  80. data/config/initializers/wrap_parameters.rb +15 -0
  81. data/config/locales/general/en.yml +15 -9
  82. data/config/locales/resources/story/en.yml +1 -0
  83. data/config/routes.rb +9 -0
  84. data/config/routes/workflow.rb +15 -15
  85. data/db/migrate/20120907144853_create_schema.rb +1 -1
  86. data/db/migrate/20120922201955_create_mongo_db_documents.rb +1 -1
  87. data/db/migrate/20121004132105_create_professions.rb +1 -1
  88. data/db/migrate/20121006162913_add_public_attribute_to_roles.rb +20 -1
  89. data/db/migrate/20130817090734_create_lists.rb +33 -0
  90. data/db/migrate/20131018143613_replace_user_by_polymorphic_resource_in_candidatures.rb +46 -0
  91. data/db/migrate/20140307113214_add_user_id_to_organizations.rb +5 -0
  92. data/lib/api_constraints.rb +10 -0
  93. data/lib/applicat/mvc/model/tree.rb +1 -1
  94. data/lib/concerns/model/base_list_item.rb +30 -0
  95. data/lib/concerns/model/base_thing.rb +50 -0
  96. data/lib/db_seed.rb +15 -4
  97. data/lib/generators/voluntary/install/install_generator.rb +17 -16
  98. data/lib/generators/voluntary/install/templates/app/views/layouts/application.html.erb +17 -1
  99. data/lib/generators/voluntary/install/templates/config/main_navigation.rb +1 -260
  100. data/lib/generators/voluntary/install/templates/features/support/integration_sessions_controller.rb +1 -2
  101. data/lib/generators/voluntary/install/templates/spec/factories.rb +19 -0
  102. data/lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb +14 -4
  103. data/lib/generators/voluntary/product_dummy/product_dummy_generator.rb +23 -17
  104. data/lib/generators/voluntary/product_dummy/templates/config/database.example.yml +1 -1
  105. data/lib/generators/voluntary/product_dummy/templates/dummy/spec/factories.rb +19 -0
  106. data/lib/generators/voluntary/product_dummy/templates/dummy/spec/spec_helper.rb +75 -0
  107. data/lib/generators/voluntary/product_dummy/templates/features/support/integration_sessions_controller.rb +1 -2
  108. data/lib/generators/voluntary/product_dummy/templates/spec/factories.rb +19 -0
  109. data/lib/voluntary.rb +10 -22
  110. data/lib/voluntary/engine.rb +27 -3
  111. data/lib/voluntary/navigation.rb +358 -0
  112. data/lib/voluntary/test/rspec_helpers/factories.rb +123 -0
  113. data/lib/voluntary/version.rb +1 -1
  114. data/vendor_extensions/active_model/naming.rb +1 -1
  115. metadata +526 -308
  116. data/app/helpers/application_helper.rb +0 -65
  117. data/app/helpers/collection_helper.rb +0 -35
  118. data/app/helpers/comments_helper.rb +0 -11
  119. data/app/helpers/form_helper.rb +0 -43
  120. data/app/helpers/language_helper.rb +0 -15
  121. data/app/helpers/layout_helper.rb +0 -39
  122. data/app/helpers/product_helper.rb +0 -34
  123. data/app/helpers/show_helper.rb +0 -65
  124. data/app/helpers/wizard_helper.rb +0 -27
  125. data/app/observers/candidature_observer.rb +0 -29
  126. data/app/observers/story_observer.rb +0 -6
  127. data/app/observers/task_observer.rb +0 -34
  128. data/lib/voluntary/helpers/application.rb +0 -69
  129. data/lib/voluntary/helpers/collection.rb +0 -35
  130. data/lib/voluntary/helpers/comments.rb +0 -15
  131. data/lib/voluntary/helpers/form.rb +0 -43
  132. data/lib/voluntary/helpers/language.rb +0 -19
  133. data/lib/voluntary/helpers/layout.rb +0 -28
  134. data/lib/voluntary/helpers/product.rb +0 -36
  135. data/lib/voluntary/helpers/show.rb +0 -69
  136. data/lib/voluntary/helpers/wizard.rb +0 -31
@@ -5,8 +5,7 @@ class IntegrationSessionsController < ActionController::Base
5
5
  end
6
6
 
7
7
  def create
8
- logger.info User.find(params[:user_id]).inspect
9
- sign_in_and_redirect User.find(params[:user_id])
8
+ sign_in_and_redirect User.friendly.find(params[:user_id])
10
9
  end
11
10
  end
12
11
 
@@ -0,0 +1,19 @@
1
+ def r_str
2
+ SecureRandom.hex(3)
3
+ end
4
+
5
+ def resource_has_many(resource, association_name)
6
+ association = if resource.send(association_name).length > 0
7
+ nil
8
+ elsif association_name.to_s.classify.constantize.count > 0
9
+ association_name.to_s.classify.constantize.last
10
+ else
11
+ Factory.create association_name.to_s.singularize.to_sym
12
+ end
13
+
14
+ resource.send(association_name).send('<<', association) if association
15
+ end
16
+
17
+ FactoryGirl.define do
18
+ Voluntary::Test::RspecHelpers::Factories.code.call(self)
19
+ end
@@ -1,16 +1,26 @@
1
1
  class MongoDatabaseCleaner
2
2
  def self.clean
3
- Dir["#{Rails.root}/app/models/**/*.*"].each do |path_name|
4
- path_name.gsub!("#{Rails.root.to_s}/app/models/", '')
3
+ root = Rails.root
4
+
5
+ Dir["#{root}/app/models/**/*.*"].each do |name|
6
+ path_name = name.gsub("#{root}/app/models/", '')
5
7
  path_name = path_name.split('/')
8
+
9
+ next if path_name.try(:first) == 'concerns'
10
+
6
11
  klass = path_name.pop.sub(/\.rb$/,'').camelize
7
12
 
8
13
  unless path_name.none?
9
14
  klass = [path_name.map(&:camelize).join('::'), klass].join('::')
10
15
  end
11
16
 
12
- klass = klass.constantize
13
-
17
+ begin
18
+ klass = klass.constantize
19
+ rescue Exception => e
20
+ raise e
21
+ raise [klass, root, name, path_name].inspect
22
+ end
23
+
14
24
  next if klass.respond_to?(:table_name) || !klass.respond_to?(:delete_all)
15
25
 
16
26
  klass.delete_all
@@ -12,11 +12,16 @@ module Voluntary
12
12
  def gem_dependencies
13
13
  create_file 'Gemfile', ''
14
14
 
15
+ append_file 'Gemfile', :verbose => true do
16
+ <<-EOH
17
+ gemspec path: File.expand_path(File.dirname(__FILE__) + "/../")
18
+ EOH
19
+ end
20
+
15
21
  add_source "http://rubygems.org"
16
22
  add_source "http://gems.github.com"
17
23
 
18
24
  # core
19
- gem 'bundler', '> 1.1.0'
20
25
  gem 'rack-cors', '~> 0.2.4', require: 'rack/cors'
21
26
  gem 'thin', '~> 1.3.1', require: false
22
27
 
@@ -50,42 +55,43 @@ module Voluntary
50
55
  # gem 'markerb', git: 'https://github.com/plataformatec/markerb.git'
51
56
 
52
57
  gem_group :development do
58
+ gem 'mysql2', '~> 0.3.13'
53
59
  gem 'linecache', '0.46', platforms: :mri_18
54
- gem 'capistrano', require: false
55
- gem 'capistrano_colors', require: false
56
- gem 'capistrano-ext', require: false
57
- gem 'yard', require: false
60
+ gem 'capistrano', '~> 3.1.0', require: false
61
+ gem 'capistrano_colors', '~> 0.5.5', require: false
62
+ gem 'capistrano-ext', '~> 1.2.1', require: false
63
+ gem 'yard', '~> 0.7', require: false
58
64
  end
59
65
 
60
66
  gem_group :test do
61
- gem 'cucumber-rails', '1.3.0', require: false
62
- gem 'rspec-instafail', '>= 0.1.7', require: false
63
- gem 'webmock', '~> 1.7', require: false
64
- gem 'simplecov', require: false
67
+ gem 'cucumber-rails', '~> 1.3.0', require: false
68
+ gem 'rspec-instafail', '~> 0.2.4', require: false
69
+ gem 'webmock', '~> 1.8.11', require: false
70
+ gem 'simplecov', '~> 0.7.1', require: false
65
71
  end
66
72
 
67
73
  gem_group :development, :test do
68
74
  gem 'debugger', platforms: :mri_19
69
- gem 'ruby-debug', platforms: :mri_18
75
+ gem 'ruby-debug', '~> 0.10.4', platforms: :mri_18
70
76
  end
71
77
 
72
78
  gem_group :assets do
73
- gem 'therubyracer', platforms: :ruby
79
+ gem 'therubyracer', '~> 0.12.0', platforms: :ruby
74
80
 
75
81
  # asset_sync is required as needed by application.rb
76
- gem 'asset_sync', require: nil
82
+ gem 'asset_sync', '~> 0.5.0', require: nil
77
83
  end
78
84
 
79
85
  gem_group :production do
80
86
  # dependency nokogiri is incompatible with cucumber-rails
81
87
  # gem 'rails_admin', git: 'git://github.com/halida/rails_admin.git'
82
- gem 'fastercsv', '1.5.5', require: false
83
- gem 'rack-ssl', require: 'rack/ssl'
88
+ gem 'fastercsv', '~> 1.5.5', require: false
89
+ gem 'rack-ssl', '~> 1.3.3', require: 'rack/ssl'
84
90
  gem 'rack-rewrite', '~> 1.2.1', require: false
85
91
 
86
92
  # analytics
87
- gem 'rack-google-analytics', require: 'rack/google-analytics'
88
- gem 'rack-piwik', require: 'rack/piwik', require: false
93
+ gem 'rack-google-analytics', '~> 0.11.0', require: 'rack/google-analytics'
94
+ gem 'rack-piwik', '~> 0.1.3', require: 'rack/piwik', require: false
89
95
  end
90
96
  end
91
97
 
@@ -105,4 +111,4 @@ ActionMailer::Base.delivery_method = delivery_method_was
105
111
  end
106
112
  end
107
113
  end
108
- end
114
+ end
@@ -21,7 +21,7 @@ production:
21
21
  encoding: utf8
22
22
  pool: 5
23
23
  host: localhost
24
- username: volontariat
24
+ username: root
25
25
  password:
26
26
 
27
27
  cucumber:
@@ -0,0 +1,19 @@
1
+ def r_str
2
+ SecureRandom.hex(3)
3
+ end
4
+
5
+ def resource_has_many(resource, association_name)
6
+ association = if resource.send(association_name).length > 0
7
+ nil
8
+ elsif association_name.to_s.classify.constantize.count > 0
9
+ association_name.to_s.classify.constantize.last
10
+ else
11
+ Factory.create association_name.to_s.singularize.to_sym
12
+ end
13
+
14
+ resource.send(association_name).send('<<', association) if association
15
+ end
16
+
17
+ FactoryGirl.define do
18
+ Voluntary::Test::RspecHelpers::Factories.code.call(self)
19
+ end
@@ -0,0 +1,75 @@
1
+ if ENV['COVERAGE_REPORT']
2
+ require 'simplecov'
3
+ SimpleCov.start 'rails'
4
+ end
5
+
6
+ require 'rubygems'
7
+ require 'spork'
8
+
9
+ Spork.prefork do
10
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
11
+ ENV["RAILS_ENV"] ||= 'test'
12
+ require File.expand_path("../../config/environment", __FILE__)
13
+ require 'rspec/rails'
14
+ require 'rspec/autorun'
15
+ require 'database_cleaner'
16
+ require 'factory_girl'
17
+ require Rails.root.join("spec/factories")
18
+
19
+ # Requires supporting ruby files with custom matchers and macros, etc,
20
+ # in spec/support/ and its subdirectories.
21
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
22
+
23
+ RSpec.configure do |config|
24
+ # ## Mock Framework
25
+ #
26
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
27
+ #
28
+ # config.mock_with :mocha
29
+ # config.mock_with :flexmock
30
+ # config.mock_with :rr
31
+
32
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
33
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
34
+
35
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
36
+ # examples within a transaction, remove the following line or assign false
37
+ # instead of true.
38
+ config.use_transactional_fixtures = true
39
+
40
+ # If true, the base class of anonymous controllers will be inferred
41
+ # automatically. This will be the default behavior in future versions of
42
+ # rspec-rails.
43
+ config.infer_base_class_for_anonymous_controllers = false
44
+
45
+ # Run specs in random order to surface order dependencies. If you find an
46
+ # order dependency and want to debug it, you can fix the order by providing
47
+ # the seed, which is printed after each run.
48
+ # --seed 1234
49
+ config.order = "random"
50
+
51
+ DatabaseCleaner.strategy = :truncation
52
+
53
+ config.after(:each) do
54
+ DatabaseCleaner.clean
55
+ MongoDatabaseCleaner.clean
56
+ end
57
+ end
58
+ end
59
+
60
+ Spork.each_run do
61
+ # This code will be run each time you run your specs.
62
+ AppConfig.load!
63
+ AppConfig.setup!
64
+ end
65
+
66
+ # https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection
67
+ RSpec.configure do |config|
68
+ config.before(:all) do
69
+ DeferredGarbageCollection.start
70
+ end
71
+
72
+ config.after(:all) do
73
+ DeferredGarbageCollection.reconsider
74
+ end
75
+ end
@@ -5,8 +5,7 @@ class IntegrationSessionsController < ActionController::Base
5
5
  end
6
6
 
7
7
  def create
8
- logger.info User.find(params[:user_id]).inspect
9
- sign_in_and_redirect User.find(params[:user_id])
8
+ sign_in_and_redirect User.friendly.find(params[:user_id])
10
9
  end
11
10
  end
12
11
 
@@ -0,0 +1,19 @@
1
+ def r_str
2
+ SecureRandom.hex(3)
3
+ end
4
+
5
+ def resource_has_many(resource, association_name)
6
+ association = if resource.send(association_name).length > 0
7
+ nil
8
+ elsif association_name.to_s.classify.constantize.count > 0
9
+ association_name.to_s.classify.constantize.last
10
+ else
11
+ Factory.create association_name.to_s.singularize.to_sym
12
+ end
13
+
14
+ resource.send(association_name).send('<<', association) if association
15
+ end
16
+
17
+ FactoryGirl.define do
18
+ Voluntary::Test::RspecHelpers::Factories.code.call(self)
19
+ end
data/lib/voluntary.rb CHANGED
@@ -1,3 +1,7 @@
1
+ # controller
2
+ require 'rails-api'
3
+
4
+ # misc
1
5
  require 'pg'
2
6
  require 'mongoid'
3
7
  require 'foreman'
@@ -30,7 +34,6 @@ require 'country_select'
30
34
  require 'diffy'
31
35
  require 'will_paginate'
32
36
  require 'will_paginate/mongoid'
33
- require 'client_side_validations'
34
37
  require 'gon'
35
38
  require 'carrierwave'
36
39
  require 'fog'
@@ -58,33 +61,18 @@ require 'coffee-rails'
58
61
  require 'handlebars_assets'
59
62
  require 'uglifier'
60
63
  require 'coffee-script'
64
+ require 'font-awesome-rails'
61
65
 
62
- require 'voluntary/helpers/application'
63
- require 'voluntary/helpers/collection'
64
- require 'voluntary/helpers/comments'
65
- require 'voluntary/helpers/form'
66
- require 'voluntary/helpers/language'
67
- require 'voluntary/helpers/layout'
68
- require 'voluntary/helpers/product'
69
- require 'voluntary/helpers/show'
70
- require 'voluntary/helpers/wizard'
66
+ require 'voluntary/navigation'
71
67
 
72
68
  require 'db_seed'
73
69
  require 'volontariat_seed'
74
70
 
71
+ if Rails.env == 'test'
72
+ require 'voluntary/test/rspec_helpers/factories'
73
+ end
74
+
75
75
  require 'voluntary/engine'
76
76
 
77
77
  module Voluntary
78
78
  end
79
-
80
- if defined?(ActionView::Base)
81
- ActionView::Base.send :include, Voluntary::Helpers::Application
82
- ActionView::Base.send :include, Voluntary::Helpers::Collection
83
- ActionView::Base.send :include, Voluntary::Helpers::Comments
84
- ActionView::Base.send :include, Voluntary::Helpers::Form
85
- ActionView::Base.send :include, Voluntary::Helpers::Language
86
- ActionView::Base.send :include, Voluntary::Helpers::Layout
87
- ActionView::Base.send :include, Voluntary::Helpers::Product
88
- ActionView::Base.send :include, Voluntary::Helpers::Show
89
- ActionView::Base.send :include, Voluntary::Helpers::Wizard
90
- end
@@ -1,11 +1,35 @@
1
1
  module Voluntary
2
2
  class Engine < ::Rails::Engine
3
+ config.autoload_paths << File.expand_path("../../../app/models/concerns", __FILE__)
4
+ config.autoload_paths << File.expand_path("../../../app/controllers/concerns", __FILE__)
3
5
  config.autoload_paths << File.expand_path("../..", __FILE__)
4
6
  config.i18n.load_path += Dir[File.expand_path("../../../config/locales/**/*.{rb,yml}", __FILE__)]
5
- config.active_record.observers ||= []
6
7
 
7
- [:candidature_observer, :story_observer, :task_observer].each do |observer|
8
- config.active_record.observers << observer
8
+ config.generators do |g|
9
+ g.orm :active_record
10
+ end
11
+
12
+ config.to_prepare do
13
+ Voluntary::Navigation::Base.add_product('no-name', 'workflow.user.products.no_name.title')
14
+ end
15
+
16
+ initializer "voluntary.add_middleware" do |config|
17
+ config.middleware.insert_after Rack::Runtime, Rack::MethodOverride
18
+ config.middleware.insert_after ActiveRecord::QueryCache, ActionDispatch::Cookies
19
+ config.middleware.insert_after ActionDispatch::Cookies, ActionDispatch::Session::CookieStore
20
+ config.middleware.insert_after ActionDispatch::Session::CookieStore, ActionDispatch::Flash
21
+ end
22
+
23
+ initializer "voluntary.add_view_helpers" do |config|
24
+ ActionView::Base.send :include, Voluntary::ApplicationHelper
25
+ ActionView::Base.send :include, Voluntary::CollectionHelper
26
+ ActionView::Base.send :include, Voluntary::CommentsHelper
27
+ ActionView::Base.send :include, Voluntary::FormHelper
28
+ ActionView::Base.send :include, Voluntary::LanguageHelper
29
+ ActionView::Base.send :include, Voluntary::LayoutHelper
30
+ ActionView::Base.send :include, Voluntary::ProductHelper
31
+ ActionView::Base.send :include, Voluntary::ShowHelper
32
+ ActionView::Base.send :include, Voluntary::WizardHelper
9
33
  end
10
34
  end
11
35
  end
@@ -0,0 +1,358 @@
1
+ module Voluntary
2
+ module Navigation
3
+ class Base
4
+ @@products = {}
5
+ @@menu_options = {}
6
+
7
+ def self.add_product(slug, text)
8
+ @@products[slug] = text
9
+ end
10
+
11
+ def self.products
12
+ @@products
13
+ end
14
+
15
+ def self.add_menu_option(resource, option, value)
16
+ @@menu_options[resource] ||= {}
17
+ @@menu_options[resource][option] = value
18
+ end
19
+
20
+ def self.menu_options(resource)
21
+ @@menu_options[resource] ||= {}
22
+ @@menu_options[resource]
23
+ end
24
+ end
25
+
26
+ def self.code
27
+ Proc.new do |navigation|
28
+ navigation.items do |primary, options|
29
+ primary.dom_class = 'nav'
30
+ primary.item :root, I18n.t('general.index.title'), root_path
31
+
32
+ [:areas, :products, :organizations, :projects, :vacancies, :users, :workflow, :authentication].each do |resource|
33
+ instance_exec primary, ::Voluntary::Navigation::Base.menu_options(resource), &::Voluntary::Navigation.menu_code(resource)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def self.menu_code(resource)
40
+ case resource
41
+ when :areas
42
+ Proc.new do |primary, options|
43
+ primary.item :areas, I18n.t('areas.index.title'), areas_path do |areas|
44
+ areas.item :new, I18n.t('general.new'), new_area_path
45
+
46
+ unless (@area.new_record? rescue true)
47
+ areas.item :show, @area.name, area_path(@area) do |area|
48
+ if can? :destroy, @area
49
+ area.item :destroy, I18n.t('general.destroy'), area_path(@area), method: :delete, confirm: I18n.t('general.questions.are_you_sure')
50
+ end
51
+
52
+ area.item :show, I18n.t('general.details'), "#{area_path(@area)}#top"
53
+ area.item :edit, I18n.t('general.edit'), edit_area_path(@area) if can? :edit, @area
54
+ area.item :users, I18n.t('users.index.title'), area_users_path(@area)
55
+ area.item :projects, I18n.t('projects.index.title'), area_projects_path(@area)
56
+
57
+ if options[:after_resource_has_many]
58
+ instance_exec area, {}, &options[:after_resource_has_many]
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ when :products
65
+ Proc.new do |primary, options|
66
+ primary.item :products, I18n.t('products.index.title'), products_path do |products|
67
+ products.item :new, I18n.t('general.new'), new_product_path
68
+
69
+ unless (@product.new_record? rescue true)
70
+ products.item :show, @product.name, product_path(@product) do |product|
71
+ if can? :edit, @product
72
+ product.item :destroy, I18n.t('general.destroy'), product_path(@product), method: :delete, confirm: I18n.t('general.questions.are_you_sure')
73
+ end
74
+
75
+ product.item :show, I18n.t('general.details'), "#{product_path(@product)}#top"
76
+ product.item :edit, I18n.t('general.edit'), edit_product_path(@product) if can? :edit, @product
77
+
78
+ product.item :projects, I18n.t('projects.index.title'), product_projects_path(@product)
79
+
80
+ if options[:after_resource_has_many]
81
+ instance_exec product, {}, &options[:after_resource_has_many]
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ when :organizations
88
+ Proc.new do |primary, options|
89
+ primary.item :organizations, I18n.t('organizations.index.title'), organizations_path do |organizations|
90
+ organizations.item :new, I18n.t('general.new'), new_organization_path
91
+
92
+ unless (@organization.new_record? rescue true)
93
+ organizations.item :show, @organization.name, organization_path(@organization) do |organization|
94
+ if can? :destroy, @organization
95
+ organization.item :destroy, I18n.t('general.destroy'), organization_path(@organization), method: :delete, confirm: I18n.t('general.questions.are_you_sure')
96
+ end
97
+
98
+ organization.item :show, I18n.t('general.details'), "#{organization_path(@organization)}#top"
99
+ organization.item :edit, I18n.t('general.edit'), edit_organization_path(@organization) if can? :edit, @organization
100
+ organization.item :projects, I18n.t('projects.index.title'), organization_projects_path(@organization)
101
+
102
+ if options[:after_resource_has_many]
103
+ instance_exec organization, {}, &options[:after_resource_has_many]
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ when :projects
110
+ Proc.new do |primary, options|
111
+ primary.item :projects, I18n.t('projects.index.title'), projects_path do |projects|
112
+ projects.item :new, I18n.t('general.new'), new_project_path
113
+
114
+ unless (@project.new_record? rescue true)
115
+ projects.item :show, @project.name, project_path(@project) do |project|
116
+ if can? :destroy, @project
117
+ project.item :destroy, I18n.t('general.destroy'), project_path(@project), method: :delete, confirm: I18n.t('general.questions.are_you_sure')
118
+ end
119
+
120
+ project.item :show, I18n.t('general.details'), "#{project_path(@project)}#top"
121
+ project.item :edit, I18n.t('general.edit'), edit_project_path(@project) if can? :edit, @project
122
+
123
+ project.item :users, I18n.t('users.index.title'), project_users_path(@project)
124
+
125
+ project.item :vacancies, I18n.t('vacancies.index.title'), project_vacancies_path(@project) do |vacancy|
126
+ vacancy.item :new, I18n.t('general.new'), new_project_vacancy_path(@project)
127
+ end
128
+
129
+ project.item :stories, I18n.t('stories.index.title'), project_stories_path(@project) do |stories|
130
+ stories.item :new, I18n.t('general.new'), new_project_story_path(@project)
131
+
132
+ unless (@story.new_record? rescue true)
133
+ stories.item(:show, @story.name, story_path(@story)) do |story|
134
+ if can? :destroy, @story
135
+ story.item :destroy, I18n.t('general.destroy'), story_path(@story), method: :delete, confirm: I18n.t('general.questions.are_you_sure')
136
+ end
137
+
138
+ story.item :show, I18n.t('general.details'), "#{story_path(@story)}#top"
139
+ story.item :edit, I18n.t('general.edit'), edit_story_path(@story) if can? :edit, @story
140
+
141
+ story.item :steps, I18n.t('general.steps'), setup_tasks_story_path(@story) do |steps|
142
+ steps.item :setup_tasks, I18n.t('stories.steps.setup_tasks.title'), setup_tasks_story_path(@story)
143
+ steps.item :activate, I18n.t('general.events.activate'), activate_story_path(@story)
144
+ end
145
+
146
+ story.item :tasks, I18n.t('tasks.index.title'), story_tasks_path(@story) do |tasks|
147
+ tasks.item :new, I18n.t('general.new'), new_story_task_path(@story)
148
+
149
+ unless (@task.new_record? rescue true)
150
+ tasks.item(:show, @task.name, task_path(@task)) do |task|
151
+ if can? :destroy, @task
152
+ task.item :destroy, I18n.t('general.destroy'), task_path(@task), method: :delete, confirm: I18n.t('general.questions.are_you_sure')
153
+ end
154
+
155
+ task.item :show, I18n.t('general.details'), "#{task_path(@task)}#top"
156
+ task.item :edit, I18n.t('general.edit'), edit_task_path(@task) if can? :edit, @task
157
+
158
+ task.item :results, I18n.t('results.index.title'), task_results_path(@task) do |results|
159
+ results.item :new, I18n.t('general.new'), new_task_result_path(@task)
160
+
161
+ unless (@result.new_record? rescue true)
162
+ results.item(:show, @result.name, result_path(@result)) do |result|
163
+ if can? :destroy, @result
164
+ result.item :destroy, I18n.t('general.destroy'), result_path(@result), method: :delete, confirm: I18n.t('general.questions.are_you_sure')
165
+ end
166
+
167
+ result.item :show, I18n.t('general.details'), "#{result_path(@result)}#top"
168
+ result.item :edit, I18n.t('general.edit'), edit_result_path(@result) if can? :edit, @result
169
+
170
+ result.item :comments, I18n.t('comments.index.title'), "#{story_path(@story)}#comments" do |comments|
171
+ comments.item(:new, I18n.t('general.new'), new_story_comment_path(@story)) if @comment
172
+
173
+ if can? :edit, @comment
174
+ comments.item(:edit, I18n.t('general.edit'), edit_comment_path(@comment)) if @comment.try(:id)
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ task.item :comments, I18n.t('comments.index.title'), "#{story_path(@story)}#comments" do |comments|
182
+ comments.item(:new, I18n.t('general.new'), new_story_comment_path(@story)) if @comment
183
+
184
+ if @comment.try(:id) && can?(:edit, @comment)
185
+ comments.item(:edit, I18n.t('general.edit'), edit_comment_path(@comment))
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ story.item :comments, I18n.t('comments.index.title'), "#{story_path(@story)}#comments" do |comments|
193
+ comments.item(:new, I18n.t('general.new'), new_story_comment_path(@story)) if @comment
194
+
195
+ if @comment.try(:id) && can?(:edit, @comment)
196
+ comments.item(:edit, I18n.t('general.edit'), edit_comment_path(@comment))
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end
202
+
203
+ project.item :comments, I18n.t('comments.index.title'), "#{project_path(@project)}#comments" do |comments|
204
+ comments.item(:new, I18n.t('general.new'), new_project_comment_path(@project)) if @comment
205
+
206
+ if @comment.try(:id) && can?(:edit, @comment)
207
+ comments.item(:edit, I18n.t('general.edit'), edit_comment_path(@comment))
208
+ end
209
+ end
210
+
211
+ if options[:after_resource_has_many]
212
+ instance_exec project, {}, &options[:after_resource_has_many]
213
+ end
214
+ end
215
+ end
216
+ end
217
+ end
218
+ when :vacancies
219
+ Proc.new do |primary, options|
220
+ primary.item :vacancies, I18n.t('vacancies.index.title'), vacancies_path do |vacancies|
221
+ vacancies.item :new, I18n.t('general.new'), new_vacancy_path
222
+
223
+ unless (@vacancy.new_record? rescue true)
224
+ vacancies.item :show, "#{@vacancy.name} @ #{@vacancy.project.name}", vacancy_path(@vacancy) do |vacancy|
225
+
226
+ if can? :destroy, @vacancy
227
+ vacancy.item :destroy, I18n.t('general.destroy'), vacancy_path(@vacancy), method: :delete, confirm: I18n.t('general.questions.are_you_sure')
228
+ end
229
+
230
+ vacancy.item :show, I18n.t('general.details'), "#{vacancy_path(@vacancy)}#top"
231
+ vacancy.item :edit, I18n.t('general.edit'), edit_vacancy_path(@vacancy) if can? :edit, @vacancy
232
+
233
+ vacancy.item :candidatures, I18n.t('candidatures.index.title'), vacancy_candidatures_path(@vacancy) do |candidatures|
234
+ candidatures.item :new, I18n.t('general.new'), new_vacancy_candidature_path(@vacancy)
235
+
236
+ unless (@candidature.new_record? rescue true)
237
+ candidatures.item(
238
+ :show, I18n.t('activerecord.models.candidature') + " of #{@candidature.resource.name} @ #{@candidature.vacancy.project.name}",
239
+ candidature_path(@candidature)
240
+ ) do |candidature|
241
+ if can? :destroy, @candidature
242
+ candidature.item :destroy, I18n.t('general.destroy'), candidature_path(@candidature), method: :delete, confirm: I18n.t('general.questions.are_you_sure')
243
+ end
244
+
245
+ candidature.item :show, I18n.t('general.details'), "#{candidature_path(@candidature)}#top"
246
+ candidature.item :edit, I18n.t('general.edit'), edit_candidature_path(@candidature) if can? :edit, @candidature
247
+
248
+ candidature.item :comments, I18n.t('comments.index.title'), "#{candidature_path(@candidature)}#comments" do |comments|
249
+ comments.item(:new, I18n.t('general.new'), new_candidature_comment_path(@candidature)) if @comment
250
+
251
+ if @comment.try(:id) && can?(:edit, @comment)
252
+ comments.item(:edit, I18n.t('general.edit'), edit_comment_path(@comment))
253
+ end
254
+ end
255
+ end
256
+ end
257
+ end
258
+
259
+ vacancy.item :comments, I18n.t('comments.index.title'), "#{vacancy_path(@vacancy)}#comments" do |comments|
260
+ comments.item(:new, I18n.t('general.new'), new_vacancy_comment_path(@vacancy)) if @comment && !@candidature
261
+
262
+ if @comment.try(:id) && can?(:edit, @comment)
263
+ comments.item(:edit, I18n.t('general.edit'), edit_comment_path(@comment))
264
+ end
265
+ end
266
+
267
+ if options[:after_resource_has_many]
268
+ instance_exec vacancy, {}, &options[:after_resource_has_many]
269
+ end
270
+ end
271
+ end
272
+ end
273
+ end
274
+ when :users
275
+ Proc.new do |primary, options|
276
+ primary.item :users, I18n.t('users.index.title'), users_path do |users|
277
+ unless (@user.new_record? rescue true) || current_user.try(:id) == @user.id
278
+ users.item :show, I18n.t('general.details'), "#{user_path(@user)}#top"
279
+
280
+ users.item :projects, I18n.t('projects.index.title'), user_projects_path(@user)
281
+ users.item :candidatures, I18n.t('candidatures.index.title'), user_candidatures_path(@user)
282
+
283
+ if options[:after_resource_has_many]
284
+ instance_exec users, {}, &options[:after_resource_has_many]
285
+ end
286
+ end
287
+ end
288
+ end
289
+ when :workflow
290
+ Proc.new do |primary, options|
291
+ if user_signed_in?
292
+ primary.item :workflow, I18n.t('workflow.index.title'), workflow_path do |workflow|
293
+ workflow.item :project_owner, I18n.t('workflow.project_owner.index.title'), workflow_project_owner_index_path do |project_owner|
294
+ project_owner.item :vacancies, I18n.t('vacancies.index.title'), open_workflow_vacancies_path do |vacancies|
295
+ Vacancy::STATES.each do |state|
296
+ vacancies.item state, I18n.t("vacancies.show.states.#{state}"), eval("#{state}_workflow_vacancies_path")
297
+ end
298
+ end
299
+
300
+ project_owner.item :candidatures, I18n.t('candidatures.index.title'), new_workflow_candidatures_path do |candidatures|
301
+ Candidature::STATES.each do |state|
302
+ candidatures.item state, I18n.t("candidatures.show.states.#{state}"), eval("#{state}_workflow_candidatures_path")
303
+ end
304
+ end
305
+ end
306
+
307
+ workflow.item :user, I18n.t('workflow.user.index.title'), workflow_user_index_path do |user|
308
+ ::Voluntary::Navigation::Base.products.each do |slug, key|
309
+ text = I18n.t(key)
310
+
311
+ user.item slug.gsub('-', '_').to_sym, text, product_workflow_user_index_path(slug) do |product|
312
+ product_slug = @story ? (@story.product.try(:to_param) || 'no-name') : 'no-name'
313
+
314
+ unless (@story.new_record? rescue true) || product_slug != slug
315
+ product.item(:show, @story.name, story_path(@story)) do |story|
316
+ story.item :show, I18n.t('general.details'), "#{story_path(@story)}#top"
317
+
318
+ story.item :tasks, I18n.t('tasks.index.title'), tasks_workflow_user_index_path(@story) do |tasks|
319
+ unless (@task.new_record? rescue true)
320
+ tasks.item(:edit, @task.name, edit_task_workflow_user_index_path(@task))
321
+ end
322
+ end
323
+ end
324
+ end
325
+
326
+ product.item :next_task, I18n.t('workflow.user.tasks.next.title'), next_task_workflow_user_index_path('text-creation')
327
+ end
328
+ end
329
+ end
330
+ end
331
+ end
332
+ end
333
+ when :authentication
334
+ Proc.new do |primary, options|
335
+ if user_signed_in?
336
+ primary.item :profile, I18n.t('users.show.title'), user_path(current_user) do |profile|
337
+ profile.item :show, I18n.t('users.show.title'), user_path(current_user) do |user|
338
+ user.item :show, I18n.t('users.show.title'), "#{user_path(current_user)}#top"
339
+ user.item :settings, I18n.t('users.edit.title'), edit_user_path(current_user)
340
+ user.item :preferences, I18n.t('users.preferences.title'), preferences_user_path(current_user)
341
+ user.item :projects, I18n.t('projects.index.title'), user_projects_path(current_user)
342
+ user.item :candidatures, I18n.t('candidatures.index.title'), user_candidatures_path(current_user)
343
+ end
344
+ end
345
+
346
+ primary.item :sign_out, I18n.t('authentication.sign_out'), destroy_user_session_path, method: :delete
347
+ else
348
+ primary.item :authentication, I18n.t('authentication.title'), new_user_session_path do |authentication|
349
+ authentication.item :sign_in, I18n.t('authentication.sign_in'), new_user_session_path
350
+ #authentication.item :rpx_sign_in, I18n.t('authentication.rpx_sign_in'), 'a' # link_to_rpx
351
+ authentication.item :sign_up, I18n.t('authentication.sign_up'), new_user_registration_path
352
+ end
353
+ end
354
+ end
355
+ end
356
+ end
357
+ end
358
+ end