aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorcedricnjanga2018-01-23 22:46:16 -0800
committercedricnjanga2018-01-23 22:46:16 -0800
commit0f59b9c1d0133393f68194a366aafc27ca23392b (patch)
treeab04bbd04b977a683ee181f0b0bc38c47c2db7f0 /app
parent5ecadfdead964381304fcf56a2564e2045988ef7 (diff)
downloadchouette-core-0f59b9c1d0133393f68194a366aafc27ca23392b.tar.bz2
First draft for including calendars into workgroup for having appropriate scoping
Diffstat (limited to 'app')
-rw-r--r--app/controllers/calendars_controller.rb4
-rw-r--r--app/decorators/calendar_decorator.rb2
-rw-r--r--app/helpers/table_builder_helper.rb8
-rw-r--r--app/helpers/table_builder_helper/custom_links.rb7
-rw-r--r--app/helpers/table_builder_helper/url.rb5
-rw-r--r--app/models/calendar.rb1
-rw-r--r--app/models/workgroup.rb1
-rw-r--r--app/views/calendars/_filters.html.slim4
-rw-r--r--app/views/calendars/index.html.slim4
-rw-r--r--app/views/dashboards/_dashboard.html.slim6
-rw-r--r--app/views/layouts/navigation/_main_nav_left_content_stif.html.slim2
-rw-r--r--app/views/stif/dashboards/_dashboard.html.slim4
12 files changed, 30 insertions, 18 deletions
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb
index 4a752f2b9..72d213953 100644
--- a/app/controllers/calendars_controller.rb
+++ b/app/controllers/calendars_controller.rb
@@ -7,7 +7,9 @@ class CalendarsController < ChouetteController
def index
index! do
- @calendars = ModelDecorator.decorate(@calendars, with: CalendarDecorator)
+ @calendars = ModelDecorator.decorate(@calendars, with: CalendarDecorator, context: {
+ workgroup: current_workgroup
+ })
end
end
diff --git a/app/decorators/calendar_decorator.rb b/app/decorators/calendar_decorator.rb
index 37e2cfe80..ce2c1a2dd 100644
--- a/app/decorators/calendar_decorator.rb
+++ b/app/decorators/calendar_decorator.rb
@@ -7,7 +7,7 @@ class CalendarDecorator < Draper::Decorator
if h.policy(object).destroy?
links << Link.new(
content: h.destroy_link_content,
- href: h.calendar_path(object),
+ href: h.workgroup_calendar_path(context[:workgroup], object),
method: :delete,
data: { confirm: h.t('calendars.actions.destroy_confirm') }
)
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index dede51920..9ead7180a 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -308,7 +308,7 @@ module TableBuilderHelper
menu = content_tag :ul, class: 'dropdown-menu' do
(
- CustomLinks.new(item, pundit_user, links, referential).links +
+ CustomLinks.new(item, pundit_user, links, referential, workgroup).links +
item.action_links.select { |link| link.is_a?(Link) }
).map do |link|
gear_menu_link(link)
@@ -391,4 +391,10 @@ module TableBuilderHelper
# cases, avoid a `NoMethodError`.
@__referential__ ||= try(:current_referential)
end
+
+ def workgroup
+ # Certain controllers don't define a `#current_referential`. In these
+ # cases, avoid a `NoMethodError`.
+ @__workgroup__ ||= try(:current_workgroup)
+ end
end
diff --git a/app/helpers/table_builder_helper/custom_links.rb b/app/helpers/table_builder_helper/custom_links.rb
index b1bb11f10..e09078be0 100644
--- a/app/helpers/table_builder_helper/custom_links.rb
+++ b/app/helpers/table_builder_helper/custom_links.rb
@@ -8,13 +8,14 @@ module TableBuilderHelper
unarchive: :put
}
- attr_reader :actions, :object, :user_context, :referential
+ attr_reader :actions, :object, :user_context, :referential, :workgroup
- def initialize(object, user_context, actions, referential = nil)
+ def initialize(object, user_context, actions, referential = nil, workgroup = nil)
@object = object
@user_context = user_context
@actions = actions
@referential = referential
+ @workgroup = workgroup
end
def links
@@ -34,7 +35,7 @@ module TableBuilderHelper
polymorph_url << action
end
- polymorph_url += URL.polymorphic_url_parts(object, referential)
+ polymorph_url += URL.polymorphic_url_parts(object, referential, workgroup)
end
def method_for_action(action)
diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb
index 28f1ade76..40e1f839f 100644
--- a/app/helpers/table_builder_helper/url.rb
+++ b/app/helpers/table_builder_helper/url.rb
@@ -1,9 +1,9 @@
module TableBuilderHelper
class URL
- def self.polymorphic_url_parts(item, referential)
+ def self.polymorphic_url_parts(item, referential, workgroup)
polymorph_url = []
- unless item.is_a?(Calendar) || item.is_a?(Referential) || item.is_a?(ComplianceControlSet)
+ unless item.is_a?(Referential) || item.is_a?(ComplianceControlSet)
if referential
polymorph_url << referential
polymorph_url << item.line if item.respond_to? :line
@@ -20,6 +20,7 @@ module TableBuilderHelper
end
end
else
+ polymorph_url << item.workgroup if item.is_a?(Calendar)
polymorph_url << item
end
diff --git a/app/models/calendar.rb b/app/models/calendar.rb
index a7fd9220c..236223892 100644
--- a/app/models/calendar.rb
+++ b/app/models/calendar.rb
@@ -8,6 +8,7 @@ class Calendar < ActiveRecord::Base
has_paper_trail class_name: 'PublicVersion'
belongs_to :organisation
+ belongs_to :workgroup
validates_presence_of :name, :short_name, :organisation
validates_uniqueness_of :short_name
diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb
index 3d761e81f..3af20ae23 100644
--- a/app/models/workgroup.rb
+++ b/app/models/workgroup.rb
@@ -3,6 +3,7 @@ class Workgroup < ActiveRecord::Base
belongs_to :stop_area_referential
has_many :workbenches
+ has_many :calendars
has_many :organisations, through: :workbenches
has_many :referentials, through: :workbenches
diff --git a/app/views/calendars/_filters.html.slim b/app/views/calendars/_filters.html.slim
index b5283c1e8..c1d8c47f7 100644
--- a/app/views/calendars/_filters.html.slim
+++ b/app/views/calendars/_filters.html.slim
@@ -1,4 +1,4 @@
-= search_form_for @q, url: calendars_path, builder: SimpleForm::FormBuilder, html: { method: :get, class: 'form form-filter' } do |f|
+= search_form_for @q, url: workgroup_calendars_path(current_workgroup), builder: SimpleForm::FormBuilder, html: { method: :get, class: 'form form-filter' } do |f|
.ffg-row
.input-group.search_bar
= f.search_field :name_or_short_name_cont, class: 'form-control', placeholder: 'Indiquez un nom/nom court de calendrier...'
@@ -18,5 +18,5 @@
= f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date smart_date' }, class: 'form-control', include_blank: true
.actions
- = link_to 'Effacer', calendars_path, class: 'btn btn-link'
+ = link_to 'Effacer', workgroup_calendars_path(current_workgroup), class: 'btn btn-link'
= f.submit 'Filtrer', id: 'calendar_filter_btn', class: 'btn btn-default'
diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim
index 77478a624..d0544856d 100644
--- a/app/views/calendars/index.html.slim
+++ b/app/views/calendars/index.html.slim
@@ -1,7 +1,7 @@
- breadcrumb :calendars
- content_for :page_header_actions do
- if policy(Calendar).create?
- = link_to(t('actions.add'), new_calendar_path, class: 'btn btn-default')
+ = link_to(t('actions.add'), new_workgroup_calendar_path(current_workgroup), class: 'btn btn-default')
.page_content
.container-fluid
@@ -19,7 +19,7 @@
key: :name, \
attribute: 'name', \
link_to: lambda do |calendar| \
- calendar_path(calendar) \
+ workgroup_calendar_path(current_workgroup, calendar) \
end \
), \
TableBuilderHelper::Column.new( \
diff --git a/app/views/dashboards/_dashboard.html.slim b/app/views/dashboards/_dashboard.html.slim
index 075b94ddc..58cfcc542 100644
--- a/app/views/dashboards/_dashboard.html.slim
+++ b/app/views/dashboards/_dashboard.html.slim
@@ -22,13 +22,13 @@
.panel.panel-default
.panel-heading
h3.panel-title.with_actions
- = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), calendars_path
+ = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), workgroup_calendars_path(current_workgroup)
div
- = link_to '', calendars_path, class: ' fa fa-chevron-right pull-right'
+ = link_to '', workgroup_calendars_path(current_workgroup), class: ' fa fa-chevron-right pull-right'
- if @dashboard.current_organisation.calendars.present?
.list-group
- @dashboard.current_organisation.calendars.order("updated_at desc").limit(5).each do |calendar|
- = link_to calendar.name, calendar_path(calendar), class: 'list-group-item'
+ = link_to calendar.name, workgroup_calendars_path(current_workgroup, calendar), class: 'list-group-item'
- else
.panel-body
em.small.text-muted
diff --git a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim
index 3963d4cd4..1b7293d21 100644
--- a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim
+++ b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim
@@ -29,7 +29,7 @@
span Jeux de données
= link_to workbench_imports_path(current_offer_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do
span Import
- = link_to calendars_path, class: 'list-group-item' do
+ = link_to workgroup_calendars_path(current_workgroup), class: 'list-group-item' do
span Modèles de calendrier
= link_to workbench_compliance_check_sets_path(current_offer_workbench), class: 'list-group-item' do
span Rapport de contrôle
diff --git a/app/views/stif/dashboards/_dashboard.html.slim b/app/views/stif/dashboards/_dashboard.html.slim
index 64e7d4f96..c28696a94 100644
--- a/app/views/stif/dashboards/_dashboard.html.slim
+++ b/app/views/stif/dashboards/_dashboard.html.slim
@@ -60,12 +60,12 @@
span.badge.ml-xs = @dashboard.calendars.count if @dashboard.calendars.present?
div
- = link_to '', calendars_path, class: ' fa fa-chevron-right pull-right', title: t('.see')
+ = link_to '', workgroup_calendars_path(current_workgroup), class: ' fa fa-chevron-right pull-right', title: t('.see')
- if @dashboard.calendars.present?
.list-group
- @dashboard.calendars.first(5).each_with_index do |calendar, i|
- = link_to calendar.name, calendar_path(calendar), class: 'list-group-item' if i < 6
+ = link_to calendar.name, workgroup_calendar_path(current_workgroup, calendar), class: 'list-group-item' if i < 6
- else
.panel-body