From 8e55e7036aafb485058bf9122bf47cde73a54c33 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 14 Dec 2017 16:42:00 +0100 Subject: Remove duplicate links in StopArea index view Refs #5287 --- app/views/stop_areas/index.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index c4d880081..99b399f5c 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -51,7 +51,7 @@ attribute: Proc.new { |s| (s.area_type.nil? ? '-' : t("enumerize.stop_area.area_type.#{s.try(:area_type)}")) } \ ), \ ], - links: [:show, :edit, :delete], + links: [:show], cls: 'table has-filter has-search' = new_pagination @stop_areas, 'pull-right' -- cgit v1.2.3 From 676f45e8fd85c1422345d4d27ba2385e4bd536fe Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 09:11:04 +0100 Subject: Refs #5287; Add specs for the view. Refactor to come --- app/helpers/table_builder_helper.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 37f01ce0d..64bec6bae 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -188,10 +188,16 @@ module TableBuilderHelper end def tbody(collection, columns, selectable, links, overhead) + if collection.respond_to?(:model) + model_name = collection.model.name.split("::").last + else + model_name = "item" + end + content_tag :tbody do collection.map do |item| - - content_tag :tr do + klass = "#{model_name.parameterize}-#{item.id}" + content_tag :tr, class: klass do bcont = [] if selectable -- cgit v1.2.3 From 129f10e701a72690091cd4e5af1c88e55194e12d Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Mon, 18 Dec 2017 19:18:31 +0100 Subject: Fix link use in StopArea name into stop_areas#index. Refs #5287 --- app/views/stop_areas/index.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index 99b399f5c..dbf3b848d 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -24,7 +24,7 @@ key: :name, \ attribute: 'name', \ link_to: lambda do |stop_area| \ - referential_stop_area_path( \ + stop_area_referential_stop_area_path( \ @stop_area_referential, \ stop_area \ ) \ -- cgit v1.2.3 From 4983eca8f4be6acf00589d4d34e7dc17377bb070 Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 19 Dec 2017 13:09:47 +0100 Subject: Refs #5287@0.5h; Use I18n in dashboard For calendars panel, instead of hardcoded string --- app/assets/stylesheets/components/_panels.sass | 1 + app/views/dashboards/_dashboard.html.slim | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/assets/stylesheets/components/_panels.sass b/app/assets/stylesheets/components/_panels.sass index e9f615081..ab25d8184 100644 --- a/app/assets/stylesheets/components/_panels.sass +++ b/app/assets/stylesheets/components/_panels.sass @@ -34,6 +34,7 @@ a text-decoration: none color: $blue + text-transform: capitalize &:hover, &:focus color: $darkblue diff --git a/app/views/dashboards/_dashboard.html.slim b/app/views/dashboards/_dashboard.html.slim index e5aa5093a..7d547bf4c 100644 --- a/app/views/dashboards/_dashboard.html.slim +++ b/app/views/dashboards/_dashboard.html.slim @@ -22,7 +22,7 @@ .panel.panel-default .panel-heading h3.panel-title.with_actions - = link_to "Modèles de calendrier", calendars_path + = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), calendars_path div = link_to '', calendars_path, class: ' fa fa-chevron-right pull-right' - if @dashboard.current_organisation.calendars.present? -- cgit v1.2.3 From eeaa2876f46e77c337fa30ab4b299acff3a29d09 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 19 Dec 2017 14:44:00 +0100 Subject: Remove update & create links Refs #5307 --- app/decorators/referential_line_decorator.rb | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'app') diff --git a/app/decorators/referential_line_decorator.rb b/app/decorators/referential_line_decorator.rb index 55acf7ed9..654f68bf5 100644 --- a/app/decorators/referential_line_decorator.rb +++ b/app/decorators/referential_line_decorator.rb @@ -24,21 +24,6 @@ class ReferentialLineDecorator < Draper::Decorator ) ) - if h.policy(Chouette::Line).create? && - context[:referential].organisation == context[:current_organisation] - links << Link.new( - content: h.t('actions.new'), - href: h.new_referential_line_path(context[:referential]) - ) - end - - if h.policy(object).update? - links << Link.new( - content: h.t('actions.edit'), - href: h.edit_referential_line_path(context[:referential], object) - ) - end - if h.policy(object).destroy? links << Link.new( content: h.destroy_link_content('actions.destroy'), -- cgit v1.2.3 From 4b9eebda5bb81a214c87351c01c720c0cb0cf2e8 Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 19 Dec 2017 16:10:15 +0100 Subject: Refs #5287; Uniformize actions --- app/decorators/stop_area_decorator.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'app') diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb index 4e777292d..8b2ebf490 100644 --- a/app/decorators/stop_area_decorator.rb +++ b/app/decorators/stop_area_decorator.rb @@ -7,15 +7,6 @@ class StopAreaDecorator < Draper::Decorator links = [] stop_area ||= object - if h.policy(Chouette::StopArea).new? - links << Link.new( - content: h.t('stop_areas.actions.new'), - href: h.new_stop_area_referential_stop_area_path( - stop_area.stop_area_referential - ) - ) - end - if h.policy(stop_area).update? links << Link.new( content: h.t('stop_areas.actions.edit'), -- cgit v1.2.3 From 2736ff5e010586266176a9a0fb0ac8dc6e227f63 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 17:01:49 +0100 Subject: Ref #5291@2h; Specs setup - Refactor specs helper to be more generic - Write missing specs for the Workbenches#show view We now have failing tests highlighting the bug --- app/helpers/table_builder_helper.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 64bec6bae..59906dc87 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -95,6 +95,18 @@ module TableBuilderHelper class: cls end + def self.item_row_class_name collection + if collection.respond_to?(:model) + model_name = collection.model.name + elsif collection.respond_to?(:first) + model_name = collection.first.class.name + else + model_name = "item" + end + + model_name.split("::").last.parameterize + end + private def thead(collection, columns, sortable, selectable, has_links, overhead, model ) @@ -188,15 +200,11 @@ module TableBuilderHelper end def tbody(collection, columns, selectable, links, overhead) - if collection.respond_to?(:model) - model_name = collection.model.name.split("::").last - else - model_name = "item" - end + model_name = TableBuilderHelper.item_row_class_name collection content_tag :tbody do collection.map do |item| - klass = "#{model_name.parameterize}-#{item.id}" + klass = "#{model_name}-#{item.id}" content_tag :tr, class: klass do bcont = [] -- cgit v1.2.3 From 926c0a338e86c7f0e1f651ba507e8120fb26ad17 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 17:54:31 +0100 Subject: Refs: #5291@1h; Update TableBuilderHelper Update TableBuilderHelper to allow the `selectable` param to be a lambda, thus allowing us to have row-based granularity. --- app/helpers/table_builder_helper.rb | 131 +++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 63 deletions(-) (limited to 'app') diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 59906dc87..de78e903d 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -199,88 +199,92 @@ module TableBuilderHelper end end - def tbody(collection, columns, selectable, links, overhead) - model_name = TableBuilderHelper.item_row_class_name collection - - content_tag :tbody do - collection.map do |item| - klass = "#{model_name}-#{item.id}" - content_tag :tr, class: klass do - bcont = [] - - if selectable - bcont << content_tag( - :td, - checkbox(id_name: item.try(:id), value: item.try(:id)) - ) - end - - columns.each do |column| - value = column.value(item) - - if column.linkable? - path = column.link_to(item) - link = link_to(value, path) + def tr item, columns, selectable, links, overhead, model_name + klass = "#{model_name}-#{item.id}" + content_tag :tr, class: klass do + bcont = [] + if selectable + disabled = selectable.respond_to?(:call) && !selectable.call(item) + bcont << content_tag( + :td, + checkbox(id_name: item.try(:id), value: item.try(:id), disabled: disabled) + ) + end - if overhead.empty? - bcont << content_tag(:td, link, title: 'Voir') + columns.each do |column| + value = column.value(item) - else - i = columns.index(column) + if column.linkable? + path = column.link_to(item) + link = link_to(value, path) - if overhead[i].blank? - if (i > 0) && (overhead[i - 1][:width] > 1) - clsArrayAlt = overhead[i - 1][:cls].split + if overhead.empty? + bcont << content_tag(:td, link, title: 'Voir') - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt)) + else + i = columns.index(column) - else - bcont << content_tag(:td, link, title: 'Voir') - end + if overhead[i].blank? + if (i > 0) && (overhead[i - 1][:width] > 1) + clsArrayAlt = overhead[i - 1][:cls].split - else - clsArray = overhead[columns.index(column)][:cls].split + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt)) - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray)) - end + else + bcont << content_tag(:td, link, title: 'Voir') end else - if overhead.empty? - bcont << content_tag(:td, value) + clsArray = overhead[columns.index(column)][:cls].split - else - i = columns.index(column) + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray)) + end + end - if overhead[i].blank? - if (i > 0) && (overhead[i - 1][:width] > 1) - clsArrayAlt = overhead[i - 1][:cls].split + else + if overhead.empty? + bcont << content_tag(:td, value) - bcont << content_tag(:td, value, class: td_cls(clsArrayAlt)) + else + i = columns.index(column) - else - bcont << content_tag(:td, value) - end + if overhead[i].blank? + if (i > 0) && (overhead[i - 1][:width] > 1) + clsArrayAlt = overhead[i - 1][:cls].split - else - clsArray = overhead[i][:cls].split + bcont << content_tag(:td, value, class: td_cls(clsArrayAlt)) - bcont << content_tag(:td, value, class: td_cls(clsArray)) - end + else + bcont << content_tag(:td, value) end + + else + clsArray = overhead[i][:cls].split + + bcont << content_tag(:td, value, class: td_cls(clsArray)) end end + end + end - if links.any? || item.try(:action_links).try(:any?) - bcont << content_tag( - :td, - build_links(item, links), - class: 'actions' - ) - end + if links.any? || item.try(:action_links).try(:any?) + bcont << content_tag( + :td, + build_links(item, links), + class: 'actions' + ) + end - bcont.join.html_safe - end + bcont.join.html_safe + end + end + + def tbody(collection, columns, selectable, links, overhead) + model_name = TableBuilderHelper.item_row_class_name collection + + content_tag :tbody do + collection.map do |item| + tr item, columns, selectable, links, overhead, model_name end.join.html_safe end end @@ -355,13 +359,14 @@ module TableBuilderHelper end end - def checkbox(id_name:, value:) + def checkbox(id_name:, value:, disabled: false) content_tag :div, '', class: 'checkbox' do - check_box_tag(id_name, value).concat( + check_box_tag(id_name, value, nil, disabled: disabled).concat( content_tag(:label, '', for: id_name) ) end end + def gear_menu_link(link) content_tag( :li, -- cgit v1.2.3 From 7fb417235919a4c577f2c456db28edc63dc18d63 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 08:52:18 +0100 Subject: Refs #5291@0.5h; Update view Update the view to match the actual controller behaviour. --- app/views/workbenches/show.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index af312fc08..1c82c34b7 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -57,7 +57,7 @@ attribute: '' \ ) \ ], - selectable: true, + selectable: ->(ref){ @workbench.referentials.include?(ref) }, links: [:show, :edit], cls: 'table has-filter has-search' -- cgit v1.2.3 From 74da4b28490d0b8822e74ddf8a7e897d1fc24588 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 09:11:03 +0100 Subject: Refs #5291@0.1h; Add missing styles Add missing styles for disabled checkboxes --- app/assets/stylesheets/base/_config.sass | 1 + app/assets/stylesheets/components/_forms.sass | 7 +++++++ 2 files changed, 8 insertions(+) (limited to 'app') diff --git a/app/assets/stylesheets/base/_config.sass b/app/assets/stylesheets/base/_config.sass index 65444479f..ec1c43e7f 100644 --- a/app/assets/stylesheets/base/_config.sass +++ b/app/assets/stylesheets/base/_config.sass @@ -16,6 +16,7 @@ $blue: #007fbb $darkgrey: #4b4b4b $grey: #a4a4a4 +$lightgrey: rgba($grey, 0.15) $green: #70b12b $red: #da2f36 diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index 9a363ab97..47faf19b1 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -229,6 +229,13 @@ $cbx-size-xs: 15px &[type='checkbox']:checked + label:before background-color: $blue + &[type='checkbox']:disabled + label + &:before + border-color: $grey + background-color: $lightgrey + cursor: not-allowed + &:after + display: none // Table adjustments table, .table .td, td, .th, th -- cgit v1.2.3 From 818bacf718594441052820ea0e7b33b9491a5b71 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 11:53:16 +0100 Subject: Refs #5325@0.5h; Use policies for calendar sharing Use policies to determine if a user is allowed to share a calendar, instead of a hardcoded string --- app/models/user.rb | 2 +- app/policies/calendar_policy.rb | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'app') diff --git a/app/models/user.rb b/app/models/user.rb index 37d35209a..1342f60ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,7 +36,7 @@ class User < ActiveRecord::Base self.name = extra[:full_name] self.email = extra[:email] self.organisation = Organisation.sync_update extra[:organisation_code], extra[:organisation_name], extra[:functional_scope] - self.permissions = Stif::PermissionTranslator.translate(extra[:permissions]) + self.permissions = Stif::PermissionTranslator.translate(extra[:permissions], self.organisation) end def self.portail_api_request diff --git a/app/policies/calendar_policy.rb b/app/policies/calendar_policy.rb index 074c41d8d..3ba708ec9 100644 --- a/app/policies/calendar_policy.rb +++ b/app/policies/calendar_policy.rb @@ -5,18 +5,15 @@ class CalendarPolicy < ApplicationPolicy end end - def create? + def create? !archived? && user.has_permission?('calendars.create') end - def destroy? - !archived? & organisation_match? && user.has_permission?('calendars.destroy') - end - def update? - !archived? && organisation_match? && user.has_permission?('calendars.update') - end + def destroy?; instance_permission("destroy") end + def update?; instance_permission("update") end + def share?; instance_permission("share") end - def share? - user.organisation.name == 'STIF' # FIXME + private + def instance_permission permission + !archived? & organisation_match? && user.has_permission?("calendars.#{permission}") end - end -- cgit v1.2.3 From 6d5ca1fe9782f4e43b38079a920ab0770e2d1cce Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 19 Dec 2017 13:16:03 +0100 Subject: Refs #5325; Fix calendat policy Remove the "!archived?" condition which makes no sense here. --- app/policies/calendar_policy.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/policies/calendar_policy.rb b/app/policies/calendar_policy.rb index 3ba708ec9..c2da8c924 100644 --- a/app/policies/calendar_policy.rb +++ b/app/policies/calendar_policy.rb @@ -6,7 +6,7 @@ class CalendarPolicy < ApplicationPolicy end def create? - !archived? && user.has_permission?('calendars.create') + user.has_permission?('calendars.create') end def destroy?; instance_permission("destroy") end def update?; instance_permission("update") end @@ -14,6 +14,6 @@ class CalendarPolicy < ApplicationPolicy private def instance_permission permission - !archived? & organisation_match? && user.has_permission?("calendars.#{permission}") + organisation_match? && user.has_permission?("calendars.#{permission}") end end -- cgit v1.2.3 From 1c60dcca735efc72b9218353ac255a50aad4e74b Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Tue, 19 Dec 2017 23:27:26 +0100 Subject: Use stop_areas count and not size to display stop_area counter --- app/views/stop_area_referentials/show.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/stop_area_referentials/show.html.slim b/app/views/stop_area_referentials/show.html.slim index d43333fd9..b562df5d5 100644 --- a/app/views/stop_area_referentials/show.html.slim +++ b/app/views/stop_area_referentials/show.html.slim @@ -7,7 +7,7 @@ .col-lg-12.text-right = link_to stop_area_referential_stop_areas_path(@stop_area_referential), class: 'btn btn-primary' do = Referential.human_attribute_name(:stop_areas) - em.small = " (#{@stop_area_referential.stop_areas.size})" + em.small = " (#{@stop_area_referential.stop_areas.count})" - page_header_content_for @stop_area_referential .page_content -- cgit v1.2.3 From 2a496d69c8425a98f500e91facc18c303ae395c5 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Tue, 19 Dec 2017 23:32:05 +0100 Subject: Fix i18n for compliance_check_sets --- app/decorators/compliance_check_set_decorator.rb | 9 --------- app/views/compliance_check_sets/index.html.slim | 4 +--- 2 files changed, 1 insertion(+), 12 deletions(-) (limited to 'app') diff --git a/app/decorators/compliance_check_set_decorator.rb b/app/decorators/compliance_check_set_decorator.rb index 096596b19..c58e14d88 100644 --- a/app/decorators/compliance_check_set_decorator.rb +++ b/app/decorators/compliance_check_set_decorator.rb @@ -3,15 +3,6 @@ class ComplianceCheckSetDecorator < Draper::Decorator def action_links links = [] - - links << Link.new( - content: h.destroy_link_content, - href: h.workbench_compliance_check_sets_path(object.id), - method: :delete, - data: {confirm: h.t('imports.actions.destroy_confirm')} - ) - - links end def lines_status diff --git a/app/views/compliance_check_sets/index.html.slim b/app/views/compliance_check_sets/index.html.slim index f5d1bd777..f109845b4 100644 --- a/app/views/compliance_check_sets/index.html.slim +++ b/app/views/compliance_check_sets/index.html.slim @@ -12,7 +12,7 @@ [ \ TableBuilderHelper::Column.new( \ key: :ref, \ - attribute: 'compliance_check_set_id' \ + attribute: 'id' \ ), \ TableBuilderHelper::Column.new( \ key: :creation_date, \ @@ -41,5 +41,3 @@ .row.mt-xs .col-lg-12 = replacement_msg t('compliance_check_sets.search_no_results') - - -- cgit v1.2.3