diff options
| author | Alban Peignier | 2017-09-30 14:17:28 +0200 |
|---|---|---|
| committer | Alban Peignier | 2017-09-30 14:46:09 +0200 |
| commit | fda2b7b07349fd20cc70d68bf1544a7f51841f70 (patch) | |
| tree | 87772ddf673bcee1861ad5d54d9b26cfaed7fea9 | |
| parent | 1ae15e06f2a56f9a83d670ad9c785a74cb6af43e (diff) | |
| download | chouette-core-fda2b7b07349fd20cc70d68bf1544a7f51841f70.tar.bz2 | |
Create DashboardController with STIF implementation. Refs #4655
| -rw-r--r-- | app/controllers/dashboards_controller.rb | 8 | ||||
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 5 | ||||
| -rw-r--r-- | app/models/dashboard.rb | 27 | ||||
| -rw-r--r-- | app/models/workbench.rb | 1 | ||||
| -rw-r--r-- | app/views/dashboards/show.html.slim | 15 | ||||
| -rw-r--r-- | app/views/stif/dashboards/_dashboard.html.slim | 73 | ||||
| -rw-r--r-- | config/initializers/stif.rb | 4 | ||||
| -rw-r--r-- | config/locales/dashboard.fr.yml | 4 | ||||
| -rw-r--r-- | config/locales/stif.fr.yml | 12 | ||||
| -rw-r--r-- | config/locales/workbenches.fr.yml | 11 | ||||
| -rw-r--r-- | config/routes.rb | 4 | ||||
| -rw-r--r-- | lib/stif/dashboard.rb | 15 |
12 files changed, 163 insertions, 16 deletions
diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb new file mode 100644 index 000000000..4c0042b67 --- /dev/null +++ b/app/controllers/dashboards_controller.rb @@ -0,0 +1,8 @@ +class DashboardsController < BreadcrumbController + respond_to :html, only: [:show] + + def show + @dashboard = Dashboard.create self + end + +end diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index 54ddb8be1..d597ba371 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -5,10 +5,7 @@ class WorkbenchesController < BreadcrumbController respond_to :html, only: [:show, :index] def index - # Only display Wb with selected name, according to #4108 - @workbench = current_organisation.workbenches.find_by(name: "Gestion de l'offre") - @referentials = @workbench.all_referentials - @calendars = Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true) + redirect_to dashboard_path end def show diff --git a/app/models/dashboard.rb b/app/models/dashboard.rb new file mode 100644 index 000000000..a53267db5 --- /dev/null +++ b/app/models/dashboard.rb @@ -0,0 +1,27 @@ +# +# The default Dashboard implementation can be customized in an initializer : +# +# Rails.application.config.to_prepare do +# Dashboard.default_class = Custom::Dashboard +# end +# +class Dashboard + include ActiveModel::Conversion + + @@default_class = self + mattr_accessor :default_class + + attr_reader :context + + def initialize(context) + @context = context + end + + def self.create(context) + default_class.new context + end + + def current_organisation + context.send(:current_organisation) + end +end diff --git a/app/models/workbench.rb b/app/models/workbench.rb index ae111a9c5..c304e8ba9 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -12,6 +12,7 @@ class Workbench < ActiveRecord::Base has_many :imports has_many :workbench_imports has_many :compliance_check_sets + has_many :compliance_control_sets validates :name, presence: true validates :organisation, presence: true diff --git a/app/views/dashboards/show.html.slim b/app/views/dashboards/show.html.slim new file mode 100644 index 000000000..66154712d --- /dev/null +++ b/app/views/dashboards/show.html.slim @@ -0,0 +1,15 @@ +/ PageHeader += pageheader 'tableau-de-bord', + t('.title', organisation: current_organisation.name) + + / Below is secundary actions & optional contents (filters, ...) + .row.mb-sm + .col-lg-12.text-right + - if policy(Api::V1::ApiKey).create? + = link_to t('actions.create_api_key'), new_api_key_path, class: 'btn btn-primary' + + +/ PageContent +.page_content + .container-fluid + = render partial: @dashboard diff --git a/app/views/stif/dashboards/_dashboard.html.slim b/app/views/stif/dashboards/_dashboard.html.slim new file mode 100644 index 000000000..3142ecd5b --- /dev/null +++ b/app/views/stif/dashboards/_dashboard.html.slim @@ -0,0 +1,73 @@ +.row + .col-lg-12 + h2.content_header = t('.subtitle') + +.row + .col-lg-6.col-md-6.col-sm-6.col-xs-12 + .panel.panel-default + .panel-heading + h3.panel-title + = t('.organisation') + + .panel-body + em.small.text-muted = t('.no_content') + + .panel.panel-default + .panel-heading + h3.panel-title + = t('.idf') + + .panel-body + em.small.text-muted = t('.no_content') + + .panel.panel-default + .panel-heading + h3.panel-title + = t('.api_keys') + span.badge.ml-xs = current_organisation.api_keys.count if current_organisation.api_keys.present? + - if current_organisation.api_keys.present? + - current_organisation.api_keys.each do |api_key| + .list-group + = policy(api_key).edit? ? link_to( "#{api_key.name} : #{api_key.token}", edit_api_key_path(api_key), class: 'list-group-item') : "#{api_key.name} : #{api_key.token}" + - else + .panel-body + em.small.text-muted = t('.no_content') + + .col-lg-6.col-md-6.col-sm-6.col-xs-12 + .panel.panel-default + .panel-heading + h3.panel-title.with_actions + div + = t('.referentials') + span.badge.ml-xs = @referentials.count if @referentials.present? + + div + = link_to '', workbench_path(@dashboard.workbench), class: ' fa fa-chevron-right pull-right', title: t('.see') + + - if @referentials.present? + .list-group + - @referentials.each_with_index do |referential, i| + = link_to referential.name, referential_path(referential, workbench_id: referential.workbench_id, current_workbench_id: @dashboard.workbench.id), class: 'list-group-item' if i < 6 + + - else + .panel-body + em.small.text-muted = t('.no_content') + + .panel.panel-default + .panel-heading + h3.panel-title.with_actions + div + = t('.calendars') + 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') + + - if @dashboard.calendars.present? + .list-group + - @dashboard.calendars.each_with_index do |calendar, i| + = link_to calendar.name, calendar_path(calendar), class: 'list-group-item' if i < 6 + + - else + .panel-body + em.small.text-muted = t('.no_content') diff --git a/config/initializers/stif.rb b/config/initializers/stif.rb index 6a79cadc8..f20429575 100644 --- a/config/initializers/stif.rb +++ b/config/initializers/stif.rb @@ -11,3 +11,7 @@ Rails.application.config.to_prepare do end end end unless Rails.env.test? + +Rails.application.config.to_prepare do + Dashboard.default_class = Stif::Dashboard +end diff --git a/config/locales/dashboard.fr.yml b/config/locales/dashboard.fr.yml new file mode 100644 index 000000000..fffb36cd1 --- /dev/null +++ b/config/locales/dashboard.fr.yml @@ -0,0 +1,4 @@ +fr: + dashboards: + show: + title: "Tableau de bord %{organisation}" diff --git a/config/locales/stif.fr.yml b/config/locales/stif.fr.yml new file mode 100644 index 000000000..4c2ecc951 --- /dev/null +++ b/config/locales/stif.fr.yml @@ -0,0 +1,12 @@ +fr: + stif: + dashboards: + dashboard: + subtitle: "Offres de transport" + organisation: "Offres de mon organisation" + idf: "Offres IDF" + api_keys: "Clés d'API" + referentials: "Jeux de données" + calendars: "Calendriers" + see: "Voir la liste" + no_content: "Aucun contenu pour le moment" diff --git a/config/locales/workbenches.fr.yml b/config/locales/workbenches.fr.yml index f361251a0..7a614efc5 100644 --- a/config/locales/workbenches.fr.yml +++ b/config/locales/workbenches.fr.yml @@ -1,16 +1,5 @@ fr: workbenches: - index: - title: "Tableau de bord %{organisation}" - offers: - title: "Offres de transport" - organisation: "Offres de mon organisation" - idf: "Offres IDF" - api_keys: "Clés d'API" - referentials: "Jeux de données" - calendars: "Calendriers" - see: "Voir la liste" - no_content: "Aucun contenu pour le moment" referential_count: zero: "Aucun jeu de données à l'heure actuelle" one: "1 jeu de données à l'heure actuelle" diff --git a/config/routes.rb b/config/routes.rb index cc3896da9..b9e318f91 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ require 'sidekiq/web' ChouetteIhm::Application.routes.draw do + resource :dashboard + resources :workbenches, only: [:show, :index] do delete :referentials, on: :member, action: :delete_referentials resources :imports do @@ -216,7 +218,7 @@ ChouetteIhm::Application.routes.draw do end end - root :to => "workbenches#index" + root :to => "dashboards#show" get '/help/(*slug)' => 'help#show' diff --git a/lib/stif/dashboard.rb b/lib/stif/dashboard.rb new file mode 100644 index 000000000..fafddec62 --- /dev/null +++ b/lib/stif/dashboard.rb @@ -0,0 +1,15 @@ +module Stif + class Dashboard < ::Dashboard + def workbench + @workbench ||= current_organisation.workbenches.find_by(name: "Gestion de l'offre") + end + + def referentials + @referentials ||= @workbench.all_referentials + end + + def calendars + @calendars ||= Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true) + end + end +end |
