aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/af83/decorator.rb63
-rw-r--r--lib/af83/decorator/enhanced_decorator.rb22
-rw-r--r--lib/af83/decorator/link.rb5
-rw-r--r--lib/stif/dashboard.rb6
-rw-r--r--lib/tasks/ci.rake15
-rw-r--r--lib/tasks/compliance_check_sets.rb11
-rw-r--r--lib/tasks/imports.rake104
-rw-r--r--lib/tasks/install.rake4
8 files changed, 190 insertions, 40 deletions
diff --git a/lib/af83/decorator.rb b/lib/af83/decorator.rb
index f990555fe..71cf1170d 100644
--- a/lib/af83/decorator.rb
+++ b/lib/af83/decorator.rb
@@ -2,40 +2,49 @@ class AF83::Decorator < ModelDecorator
include AF83::Decorator::EnhancedDecorator
extend AF83::Decorator::EnhancedDecorator::ClassMethods
- def self.decorates klass
- instance_decorator.decorates klass
- end
+ class << self
+ def decorates klass
+ instance_decorator.decorates klass
+ end
- def self.instance_decorator
- @instance_decorator ||= begin
- klass = Class.new(AF83::Decorator::InstanceDecorator)
- klass.delegate_all
- klass
+ def instance_decorator
+ @instance_decorator ||= begin
+ klass = Class.new(AF83::Decorator::InstanceDecorator)
+ klass.delegate_all
+ klass
+ end
end
- end
- def self.with_instance_decorator
- @_with_instance_decorator = true
- yield instance_decorator
- @_with_instance_decorator = false
- end
+ def with_instance_decorator
+ @_with_instance_decorator = true
+ yield instance_decorator
+ @_with_instance_decorator = false
+ end
+
+ def decorate object, options = {}
+ if object.is_a?(ActiveRecord::Base)
+ return instance_decorator.decorate object, options
+ else
+ self.new object, options.update(with: instance_decorator)
+ end
+ end
- def self.decorate object, options = {}
- if object.is_a?(ActiveRecord::Base)
- return instance_decorator.decorate object, options
- else
- self.new object, options.update(with: instance_decorator)
+ def define_instance_method method_name, &block
+ instance_decorator.send(:define_method, method_name, &block)
end
- end
- def self.define_instance_method method_name, &block
- instance_decorator.send(:define_method, method_name, &block)
- end
+ # Defines a class method on the decorated object's class. These
+ # can be called like `object.class.my_method`.
+ def define_instance_class_method method_name, &block
+ instance_decorator.send(:define_singleton_method, method_name, &block)
+ end
+
+ def set_scope_with_instance_decorator value=nil, &block
+ set_scope_without_instance_decorator value, &block
+ instance_decorator.set_scope value, &block
+ end
- # Defines a class method on the decorated object's class. These
- # can be called like `object.class.my_method`.
- def self.define_instance_class_method method_name, &block
- instance_decorator.send(:define_singleton_method, method_name, &block)
+ alias_method_chain :set_scope, :instance_decorator
end
class ActionLinks
diff --git a/lib/af83/decorator/enhanced_decorator.rb b/lib/af83/decorator/enhanced_decorator.rb
index 904d1b2da..fff8bb8b3 100644
--- a/lib/af83/decorator/enhanced_decorator.rb
+++ b/lib/af83/decorator/enhanced_decorator.rb
@@ -25,7 +25,7 @@ module AF83::Decorator::EnhancedDecorator
policy: :create,
before_block: -> (l){
l.content { h.t('actions.add') }
- l.href { [:new, object.klass.name.underscore.singularize] }
+ l.href { [:new, scope, object.klass.model_name.singular] }
}
}
action_link opts.update(args), &block
@@ -37,7 +37,7 @@ module AF83::Decorator::EnhancedDecorator
primary: :index,
before_block: -> (l){
l.content { h.t('actions.show') }
- l.href { [object] }
+ l.href { [scope, object] }
}
}
action_link opts.update(args), &block
@@ -49,7 +49,7 @@ module AF83::Decorator::EnhancedDecorator
policy: :edit,
before_block: -> (l){
l.content { h.t('actions.edit') }
- l.href { [:edit, object] }
+ l.href { [:edit, scope, object] }
}
}
action_link opts.update(args), &block
@@ -62,7 +62,7 @@ module AF83::Decorator::EnhancedDecorator
secondary: :show,
before_block: -> (l){
l.content { h.destroy_link_content }
- l.href { [object] }
+ l.href { [scope, object] }
l.method :delete
l.data {{ confirm: h.t('actions.destroy_confirm') }}
}
@@ -70,6 +70,14 @@ module AF83::Decorator::EnhancedDecorator
action_link opts.update(args), &block
end
+ def set_scope value=nil, &block
+ @scope = value || block
+ end
+
+ def scope
+ @scope
+ end
+
def t key
eval "-> (l){ h.t('#{key}') }"
end
@@ -142,4 +150,10 @@ module AF83::Decorator::EnhancedDecorator
def check_feature feature
h.has_feature? feature
end
+
+ def scope
+ scope = self.class.scope
+ scope = instance_exec &scope if scope.is_a? Proc
+ scope
+ end
end
diff --git a/lib/af83/decorator/link.rb b/lib/af83/decorator/link.rb
index 7d2896e6a..ee09f80dc 100644
--- a/lib/af83/decorator/link.rb
+++ b/lib/af83/decorator/link.rb
@@ -30,7 +30,8 @@ class AF83::Decorator::Link
@options[name] = block
elsif args.size == 0
out = @options[name]
- out = context.instance_exec(self, &out) if out.is_a?(Proc)
+ out = context.instance_exec(self, &out) if out.is_a?(Proc)
+ out = out.flatten.compact if name.to_s == "href" && out.is_a?(Array)
out
else
# we can use l.foo("bar") or l.foo = "bar"
@@ -129,7 +130,9 @@ class AF83::Decorator::Link
out[:method] = link_method
out[:class] = extra_class
out.delete(:link_class)
+ out.delete(:link_method)
out[:class] += " disabled" if disabled
+ out[:class].strip!
out[:disabled] = !!disabled
out
end
diff --git a/lib/stif/dashboard.rb b/lib/stif/dashboard.rb
index b6b6b8284..46c635091 100644
--- a/lib/stif/dashboard.rb
+++ b/lib/stif/dashboard.rb
@@ -4,12 +4,16 @@ module Stif
@workbench ||= current_organisation.workbenches.find_by(name: "Gestion de l'offre")
end
+ def workgroup
+ workbench.workgroup
+ end
+
def referentials
@referentials ||= self.workbench.all_referentials
end
def calendars
- @calendars ||= Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true)
+ @calendars ||= Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, workgroup.id)
end
end
end
diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake
index 13d7b8d73..89f9aa9c8 100644
--- a/lib/tasks/ci.rake
+++ b/lib/tasks/ci.rake
@@ -31,19 +31,22 @@ namespace :ci do
sh "bundle exec bundle-audit check --update"
end
- task :spec => ["ci:assets","spec"]
-
task :assets do
sh "RAILS_ENV=test bundle exec rake assets:precompile"
end
- task :jest => "ci:assets" do
- sh "yarn --no-progress install" # Hack to force install jest after webpack
- sh "node_modules/.bin/jest" unless ["CHOUETTE_JEST_DISABLED"]
+ task :i18n_js_export do
+ sh "RAILS_ENV=test bundle exec rake i18n:js:export"
+ end
+
+ task :jest do
+ sh "node_modules/.bin/jest" unless ENV["CHOUETTE_JEST_DISABLED"]
end
desc "Deploy after CI"
task :deploy do
+ return if ENV["CHOUETTE_DEPLOY_DISABLED"]
+
if deploy_env
sh "cap #{deploy_env} deploy:migrations"
else
@@ -59,4 +62,4 @@ namespace :ci do
end
desc "Run continuous integration tasks (spec, ...)"
-task :ci => ["ci:setup", "ci:spec", "ci:jest", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"]
+task :ci => ["ci:setup", "ci:assets", "ci:i18n_js_export", "spec", "ci:jest", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"]
diff --git a/lib/tasks/compliance_check_sets.rb b/lib/tasks/compliance_check_sets.rb
new file mode 100644
index 000000000..c53c7f9ed
--- /dev/null
+++ b/lib/tasks/compliance_check_sets.rb
@@ -0,0 +1,11 @@
+namespace :compliance_check_sets do
+ desc "Notify parent check sets when children finish"
+ task notify_parent: :environment do
+ ParentNotifier.new(ComplianceCheckSet).notify_when_finished
+ end
+
+ desc "Mark old unfinished check sets as 'aborted'"
+ task abort_old: :environment do
+ ComplianceCheckSet.abort_old
+ end
+end
diff --git a/lib/tasks/imports.rake b/lib/tasks/imports.rake
index 6bc84acc8..b91ff7efb 100644
--- a/lib/tasks/imports.rake
+++ b/lib/tasks/imports.rake
@@ -1,6 +1,108 @@
+require 'csv'
+
namespace :import do
desc "Notify parent imports when children finish"
task notify_parent: :environment do
- ParentImportNotifier.notify_when_finished
+ ParentNotifier.new(Import).notify_when_finished
+ end
+
+ desc "Mark old unfinished Netex imports as 'aborted'"
+ task netex_abort_old: :environment do
+ NetexImport.abort_old
+ end
+
+ def importer_output_to_csv importer
+ filepath = "./#{importer.configuration_name}_#{Time.now.strftime "%y%m%d%H%M"}_out.csv"
+ cols = %w(line kind event message error)
+ if importer.reload.journal.size > 0
+ keys = importer.journal.first["row"].map(&:first)
+ CSV.open(filepath, "w") do |csv|
+ csv << cols + keys
+ importer.journal.each do |j|
+ csv << cols.map{|c| j[c]} + j["row"].map(&:last)
+ end
+ end
+ puts "Import Output written in #{filepath}"
+ end
+ end
+
+ desc "import the given file with the corresponding importer"
+ task :import, [:configuration_name, :filepath, :referential_id] => :environment do |t, args|
+ importer = SimpleImporter.create configuration_name: args[:configuration_name], filepath: args[:filepath]
+ if args[:referential_id].present?
+ referential = Referential.find args[:referential_id]
+ importer.configure do |config|
+ config.add_value :referential, referential
+ config.context = {referential: referential}
+ end
+ end
+ puts "\e[33m***\e[0m Start importing"
+ begin
+ importer.import(verbose: true)
+ rescue Interrupt
+ raise
+ ensure
+ puts "\n\e[33m***\e[0m Import done, status: " + (importer.status == "success" ? "\e[32m" : "\e[31m" ) + (importer.status || "") + "\e[0m"
+ importer_output_to_csv importer
+ end
+ end
+
+ desc "import the given file with the corresponding importer in the given StopAreaReferential"
+ task :import_in_stop_area_referential, [:referential_id, :configuration_name, :filepath] => :environment do |t, args|
+ referential = StopAreaReferential.find args[:referential_id]
+ importer = SimpleImporter.create configuration_name: args[:configuration_name], filepath: args[:filepath]
+ importer.configure do |config|
+ config.add_value :stop_area_referential, referential
+ config.context = {stop_area_referential: referential}
+ end
+ puts "\e[33m***\e[0m Start importing"
+ begin
+ importer.import(verbose: true)
+ rescue Interrupt
+ raise
+ ensure
+ puts "\n\e[33m***\e[0m Import done, status: " + (importer.status == "success" ? "\e[32m" : "\e[31m" ) + (importer.status || "") + "\e[0m"
+ importer_output_to_csv importer
+ end
+ end
+
+ desc "import the given routes files"
+ task :import_routes, [:referential_id, :configuration_name, :mapping_filepath, :filepath] => :environment do |t, args|
+ referential = Referential.find args[:referential_id]
+ referential.switch
+ stop_area_referential = referential.stop_area_referential
+ importer = SimpleImporter.create configuration_name: args[:configuration_name], filepath: args[:filepath]
+ importer.configure do |config|
+ config.add_value :stop_area_referential, referential
+ config.context = {stop_area_referential: stop_area_referential, mapping_filepath: args[:mapping_filepath]}
+ end
+ puts "\e[33m***\e[0m Start importing"
+ begin
+ importer.import(verbose: true)
+ rescue Interrupt
+ raise
+ ensure
+ puts "\n\e[33m***\e[0m Import done, status: " + (importer.status == "success" ? "\e[32m" : "\e[31m" ) + (importer.status || "") + "\e[0m"
+ importer_output_to_csv importer
+ end
+ end
+
+ desc "import the given file with the corresponding importer in the given LineReferential"
+ task :import_in_line_referential, [:referential_id, :configuration_name, :filepath] => :environment do |t, args|
+ referential = LineReferential.find args[:referential_id]
+ importer = SimpleImporter.create configuration_name: args[:configuration_name], filepath: args[:filepath]
+ importer.configure do |config|
+ config.add_value :line_referential, referential
+ config.context = {line_referential: referential}
+ end
+ puts "\e[33m***\e[0m Start importing"
+ begin
+ importer.import(verbose: true)
+ rescue Interrupt
+ raise
+ ensure
+ puts "\n\e[33m***\e[0m Import done, status: " + (importer.status == "success" ? "\e[32m" : "\e[31m" ) + (importer.status || "") + "\e[0m"
+ importer_output_to_csv importer
+ end
end
end
diff --git a/lib/tasks/install.rake b/lib/tasks/install.rake
index 1150825b2..7d8ecdce0 100644
--- a/lib/tasks/install.rake
+++ b/lib/tasks/install.rake
@@ -9,9 +9,11 @@ task :package do
sh "bundle package --all"
sh "bundle exec rake assets:clobber RAILS_ENV=production"
sh "bundle exec rake assets:precompile RAILS_ENV=production"
+ sh "bundle exec rake i18n:js:export RAILS_ENV=production"
sh "tar -rf tmp/package/stif-boiv-release-#{release_name}.tar vendor/cache"
sh "tar -rf tmp/package/stif-boiv-release-#{release_name}.tar public/assets"
sh "tar -rf tmp/package/stif-boiv-release-#{release_name}.tar public/packs"
+ sh "tar -rf tmp/package/stif-boiv-release-#{release_name}.tar public/javascripts"
%w{deploy-helper.sh README sidekiq-stif-boiv.service stif-boiv.conf stif-boiv-setup.sh template-stif-boiv.sql}.each do |f|
cp "install/#{f}", "tmp/package/#{f}"
@@ -37,9 +39,11 @@ task :pkg4docker do
# sh "RAILS_DB_ADAPTER=nulldb bundle exec rake assets:precompile RAILS_ENV=production"
sh "bundle exec rake assets:clobber RAILS_ENV=production"
sh "bundle exec rake assets:precompile RAILS_ENV=production"
+ sh "bundle exec rake i18n:js:export RAILS_ENV=production"
sh "tar -rf tmp/package/stif-boiv-release-#{release_name}.tar vendor/cache"
sh "tar -rf tmp/package/stif-boiv-release-#{release_name}.tar public/assets"
sh "tar -rf tmp/package/stif-boiv-release-#{release_name}.tar public/packs"
+ sh "tar -rf tmp/package/stif-boiv-release-#{release_name}.tar public/javascripts"
sh "gzip -c tmp/package/stif-boiv-release-#{release_name}.tar > tmp/stif-boiv-release.tar.gz"