aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/referentials_controller.rb2
-rw-r--r--app/decorators/referential_decorator.rb47
-rw-r--r--app/views/referentials/show.html.slim47
-rw-r--r--lib/link.rb10
4 files changed, 90 insertions, 16 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index c65e6552c..50b2e47c6 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -26,6 +26,8 @@ class ReferentialsController < BreadcrumbController
def show
resource.switch
show! do |format|
+ @referential = ReferentialDecorator.new(@referential)
+
format.json {
render :json => { :lines_count => resource.lines.count,
:networks_count => resource.networks.count,
diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb
new file mode 100644
index 000000000..1c2347529
--- /dev/null
+++ b/app/decorators/referential_decorator.rb
@@ -0,0 +1,47 @@
+class ReferentialDecorator < Draper::Decorator
+ delegate_all
+
+ def action_links
+ links = [
+ Link.new(
+ name: h.t('time_tables.index.title'),
+ href: h.referential_time_tables_path(object)
+ )
+ ]
+
+ if h.policy(object).clone?
+ links << Link.new(
+ name: h.t('actions.clone'),
+ href: h.new_referential_path(from: object.id)
+ )
+ end
+
+ if h.policy(object).edit?
+ # button.btn.btn-primary type='button' data-toggle='modal' data-target='#purgeModal' Purger
+
+ if object.archived?
+ links << Link.new(
+ name: h.t('actions.unarchive'),
+ href: h.unarchive_referential_path(object.id),
+ method: :put
+ )
+ else
+ links << Link.new(
+ name: h.t('actions.archive'),
+ href: h.archive_referential_path(object.id),
+ method: :put
+ )
+ end
+ end
+
+ if h.policy(object).destroy?
+ links << Link.new(
+ href: h.referential_path(object),
+ method: :delete,
+ data: { confirm: h.t('referentials.actions.destroy_confirm') }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index 3c1e36302..1bbf350b4 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -8,23 +8,38 @@
/ Below is secondary actions & optional contents (filters, ...)
.row.mb-sm
.col-lg-12.text-right
- = link_to t('time_tables.index.title'), referential_time_tables_path(@referential), class: 'btn btn-primary'
-
- - if policy(@referential).clone?
- = link_to t('actions.clone'), new_referential_path(from: @referential.id), class: 'btn btn-primary'
-
- - if policy(@referential).edit?
- button.btn.btn-primary type='button' data-toggle='modal' data-target='#purgeModal' Purger
-
- - if @referential.archived?
- = link_to t('actions.unarchive'), unarchive_referential_path(@referential.id), method: :put, class: 'btn btn-primary'
+ /= link_to t('time_tables.index.title'), referential_time_tables_path(@referential), class: 'btn btn-primary'
+ /
+ /- if policy(@referential).clone?
+ / = link_to t('actions.clone'), new_referential_path(from: @referential.id), class: 'btn btn-primary'
+ /
+ /- if policy(@referential).edit?
+ / button.btn.btn-primary type='button' data-toggle='modal' data-target='#purgeModal' Purger
+ /
+ / - if @referential.archived?
+ / = link_to t('actions.unarchive'), unarchive_referential_path(@referential.id), method: :put, class: 'btn btn-primary'
+ / - else
+ / = link_to t('actions.archive'), archive_referential_path(@referential.id), method: :put, class: 'btn btn-primary'
+ /
+ /- if policy(@referential).destroy?
+ / = link_to referential_path(@referential), method: :delete, data: {confirm: t('referentials.actions.destroy_confirm')}, class: 'btn btn-primary' do
+ / span.fa.fa-trash
+ / span = t('actions.destroy')
+ /= leslinks.map { |l| link_to l.href, l.label }
+ - @referential.action_links.each do |link|
+ - if link.method == :delete
+ = link_to link.href,
+ method: link.method,
+ data: link.data,
+ class: 'btn btn-primary' do
+ span.fa.fa-trash
+ span = t('actions.destroy')
- else
- = link_to t('actions.archive'), archive_referential_path(@referential.id), method: :put, class: 'btn btn-primary'
-
- - if policy(@referential).destroy?
- = link_to referential_path(@referential), method: :delete, data: {confirm: t('referentials.actions.destroy_confirm')}, class: 'btn btn-primary' do
- span.fa.fa-trash
- span = t('actions.destroy')
+ = link_to link.name,
+ link.href,
+ method: link.method,
+ data: link.data,
+ class: 'btn btn-primary'
/ PageContent
.page_content
diff --git a/lib/link.rb b/lib/link.rb
new file mode 100644
index 000000000..911f189c9
--- /dev/null
+++ b/lib/link.rb
@@ -0,0 +1,10 @@
+class Link
+ attr_reader :name, :href, :method, :data
+
+ def initialize(name: nil, href:, method: :get, data: nil)
+ @name = name
+ @href = href
+ @method = method
+ @data = data
+ end
+end