diff options
| -rw-r--r-- | app/controllers/calendars_controller.rb | 4 | ||||
| -rw-r--r-- | app/decorators/calendar_decorator.rb | 2 | ||||
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 8 | ||||
| -rw-r--r-- | app/helpers/table_builder_helper/custom_links.rb | 7 | ||||
| -rw-r--r-- | app/helpers/table_builder_helper/url.rb | 5 | ||||
| -rw-r--r-- | app/models/calendar.rb | 1 | ||||
| -rw-r--r-- | app/models/workgroup.rb | 1 | ||||
| -rw-r--r-- | app/views/calendars/_filters.html.slim | 4 | ||||
| -rw-r--r-- | app/views/calendars/index.html.slim | 4 | ||||
| -rw-r--r-- | app/views/dashboards/_dashboard.html.slim | 6 | ||||
| -rw-r--r-- | app/views/layouts/navigation/_main_nav_left_content_stif.html.slim | 2 | ||||
| -rw-r--r-- | app/views/stif/dashboards/_dashboard.html.slim | 4 | ||||
| -rw-r--r-- | config/routes.rb | 7 | ||||
| -rw-r--r-- | db/migrate/20180123174450_add_workgroup_id_to_calendars.rb | 6 | ||||
| -rw-r--r-- | db/schema.rb | 6 | ||||
| -rw-r--r-- | lib/stif/dashboard.rb | 2 |
16 files changed, 45 insertions, 24 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 diff --git a/config/routes.rb b/config/routes.rb index 0f60733af..6a6a7cb07 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,9 +111,10 @@ ChouetteIhm::Application.routes.draw do resources :companies resources :networks end - - resources :calendars do - get :autocomplete, on: :collection, controller: 'autocomplete_calendars' + resources :workgroups do + resources :calendars do + get :autocomplete, on: :collection, controller: 'autocomplete_calendars' + end end resources :referentials, except: :index do diff --git a/db/migrate/20180123174450_add_workgroup_id_to_calendars.rb b/db/migrate/20180123174450_add_workgroup_id_to_calendars.rb new file mode 100644 index 000000000..64ad1a752 --- /dev/null +++ b/db/migrate/20180123174450_add_workgroup_id_to_calendars.rb @@ -0,0 +1,6 @@ +class AddWorkgroupIdToCalendars < ActiveRecord::Migration + def change + add_column :calendars, :workgroup_id, :integer, limit: 8 + add_index :calendars, :workgroup_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c5520110..11fb96ee3 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: 20180111200406) do +ActiveRecord::Schema.define(version: 20180123174450) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -90,10 +90,12 @@ ActiveRecord::Schema.define(version: 20180111200406) do t.integer "organisation_id", limit: 8 t.datetime "created_at" t.datetime "updated_at" + t.integer "workgroup_id", limit: 8 end add_index "calendars", ["organisation_id"], name: "index_calendars_on_organisation_id", using: :btree add_index "calendars", ["short_name"], name: "index_calendars_on_short_name", unique: true, using: :btree + add_index "calendars", ["workgroup_id"], name: "index_calendars_on_workgroup_id", using: :btree create_table "clean_up_results", id: :bigserial, force: :cascade do |t| t.string "message_key" @@ -416,9 +418,9 @@ ActiveRecord::Schema.define(version: 20180111200406) do t.string "type" t.integer "parent_id", limit: 8 t.string "parent_type" - t.datetime "notified_parent_at" t.integer "current_step", default: 0 t.integer "total_steps", default: 0 + t.datetime "notified_parent_at" t.string "creator" end diff --git a/lib/stif/dashboard.rb b/lib/stif/dashboard.rb index b6b6b8284..7dd83efbc 100644 --- a/lib/stif/dashboard.rb +++ b/lib/stif/dashboard.rb @@ -9,7 +9,7 @@ module Stif end def calendars - @calendars ||= Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true) + @calendars ||= Calendar.where('workgroup_id = ? OR shared = ?', @workbench.workgroup_id, true) end end end |
