diff options
| author | Michel Etienne | 2014-08-27 08:59:19 +0200 |
|---|---|---|
| committer | Michel Etienne | 2014-08-27 08:59:19 +0200 |
| commit | 7307e5b746650c332a44ecb023abb827d9d2be0a (patch) | |
| tree | c69bc000c43685275f3ba077958342d5e45e0aff | |
| parent | 5b2a2fa7892c661f81e097a733c621b07d441bc0 (diff) | |
| download | chouette-core-7307e5b746650c332a44ecb023abb827d9d2be0a.tar.bz2 | |
clone stop_area as parent or child, Mantis 26830
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | app/controllers/exports_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/stop_area_copies_controller.rb | 39 | ||||
| -rw-r--r-- | app/models/stop_area_copy.rb | 50 | ||||
| -rw-r--r-- | app/views/exports/_export.erb | 4 | ||||
| -rw-r--r-- | app/views/stop_area_copies/_form.html.erb | 24 | ||||
| -rw-r--r-- | app/views/stop_area_copies/create.html.erb | 1 | ||||
| -rw-r--r-- | app/views/stop_area_copies/new.html.erb | 1 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.erb | 22 | ||||
| -rw-r--r-- | config/locales/exports.yml | 2 | ||||
| -rw-r--r-- | config/locales/formtastic.yml | 30 | ||||
| -rw-r--r-- | config/locales/stop_area_copies.yml | 27 | ||||
| -rw-r--r-- | config/locales/stop_area_imports.yml | 6 | ||||
| -rw-r--r-- | config/locales/stop_areas.yml | 4 | ||||
| -rw-r--r-- | config/routes.rb | 3 |
15 files changed, 188 insertions, 29 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index f010c1b6f..8dafca210 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/afimb/ninoxe.git - revision: abee1ec401e4f8f44528620225e2db2c06e1c97f + revision: 3727e7393fdece893e1baa49916be24140c766b9 branch: sismo specs: ninoxe (1.1.0) diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index 8805c8078..ed2ecd329 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -14,7 +14,7 @@ class ExportsController < ChouetteController def create create! do |success, failure| available_exports - success.html { flash[:notice] = I18n.t('exports.new.flash'); redirect_to referential_exports_path(@referential) } + success.html { flash[:notice] = I18n.t('exports.new.flash')+"<br/>"+I18n.t('exports.new.flash2'); redirect_to referential_exports_path(@referential) } end end diff --git a/app/controllers/stop_area_copies_controller.rb b/app/controllers/stop_area_copies_controller.rb new file mode 100644 index 000000000..01dfc5894 --- /dev/null +++ b/app/controllers/stop_area_copies_controller.rb @@ -0,0 +1,39 @@ +class StopAreaCopiesController < ChouetteController + belongs_to :referential do + belongs_to :stop_area, :parent_class => Chouette::StopArea + end + + actions :new, :create + respond_to :html, :only => :new + + def new + @stop_area_copy = StopAreaCopy.new(:source_id => parent.id, :hierarchy => params[:hierarchy]) + if @stop_area_copy.hierarchy == "child" + if parent.area_type.underscore == "stop_place" + @stop_area_copy.area_type="commercial_stop_point" + else + @stop_area_copy.area_type="boarding_position" + end + else + if parent.area_type.underscore == "stop_place" || parent.area_type.underscore == "commercial_stop_point" + @stop_area_copy.area_type="stop_place" + else + @stop_area_copy.area_type="commercial_stop_point" + end + end + new! + end +# TODO + def create + @stop_area_copy = StopAreaCopy.new(params[:stop_area_copy]) + if @stop_area_copy.save + redirect_to referential_stop_area_path( @referential,parent ), notice: I18n.t("stop_area_copies.new.success") + else + flash[:error] = I18n.t("stop_area_copies.errors.copy_aborted") + "<br>" + @stop_area_copy.errors.full_messages.join("<br>") + render :action => :new + end + end + + protected + +end diff --git a/app/models/stop_area_copy.rb b/app/models/stop_area_copy.rb new file mode 100644 index 000000000..fb661cf79 --- /dev/null +++ b/app/models/stop_area_copy.rb @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +class StopAreaCopy + include ActiveModel::Validations + include ActiveModel::Conversion + extend ActiveModel::Naming + + attr_accessor :source_id, :hierarchy, :area_type + + validates_presence_of :source_id, :hierarchy, :area_type + + def initialize(attributes = {}) + attributes.each { |name, value| send("#{name}=", value) } if attributes + end + + def persisted? + false + end + + def save + begin + if self.valid? + source = Chouette::StopArea.find self.source_id + copy = source.duplicate + copy.name = source.name + copy.area_type = self.area_type.camelcase + # TODO: check area_type validity + Chouette::StopArea.transaction do + if self.hierarchy == "child" + copy.parent_id = source.id + end + copy.save + if self.hierarchy == "parent" + source.parent_id = copy.id + source.save + end + end + true + else + false + end + rescue Exception => exception + Rails.logger.error(exception.message) + errors.add :base, I18n.t("stop_area_copy.errors.exception") + false + end + end + + +end diff --git a/app/views/exports/_export.erb b/app/views/exports/_export.erb index a307d856b..2bda5e4c5 100644 --- a/app/views/exports/_export.erb +++ b/app/views/exports/_export.erb @@ -10,11 +10,13 @@ <li class="remove"><%= link_to "<i class='fa fa-trash-o'></i>".html_safe, referential_export_path(@referential, export), :method => :delete, :data => {:confirm => t('exports.actions.destroy_confirm')}, :class => "remove" %></li> </ul> <div class="history"> - <%= t("exports.statuses.#export.status}") %> + <%= t("exports.statuses.#{export.status}") %> </div> <div class="links"> <% if export.status == 'completed' %> <%= link_to t("exports.actions.download"), referential_export_path(@referential, export, :format => :zip), :class => "download" %> + <% else %> + <% end %> </div> <div class="history"> diff --git a/app/views/stop_area_copies/_form.html.erb b/app/views/stop_area_copies/_form.html.erb new file mode 100644 index 000000000..5ac6fb345 --- /dev/null +++ b/app/views/stop_area_copies/_form.html.erb @@ -0,0 +1,24 @@ +<%= title_tag t("stop_area_copies.new.title."+@stop_area_copy.hierarchy) %> + +<%= semantic_form_for [@referential, @stop_area, @stop_area_copy] do |form| %> + <br> + <%= form.inputs do %> + <%= form.input :source_id , :as => :hidden%> + <%= form.input :hierarchy , :as => :hidden%> + <% if @stop_area_copy.hierarchy == "child"%> + <% if @stop_area.area_type.underscore == "stop_place"%> + <%= form.input :area_type, :as => :select, :input_html => { :disabled => true }, :collection => [@stop_area_copy.area_type], :include_blank => false, :member_label => Proc.new { |stop_area_type| t("area_types.label.#{stop_area_type}") } %> + <%= form.input :area_type , :as => :hidden%> + <% else%> + <%= form.input :area_type, :as => :select, :collection => ["boarding_position","quay"], :include_blank => false, :member_label => Proc.new { |stop_area_type| t("area_types.label.#{stop_area_type}") } %> + <% end %> + <% else %> + <%= form.input :area_type, :as => :select, :input_html => { :disabled => true }, :collection => [@stop_area_copy.area_type], :include_blank => false, :member_label => Proc.new { |stop_area_type| t("area_types.label.#{stop_area_type}") } %> + <%= form.input :area_type , :as => :hidden%> + <% end %> + <% end %> + <%= form.actions do %> + <%= form.action :submit, :as => :button , :label => t( 'formtastic.duplicate' ) %> + <%= form.action :cancel, :as => :link %> + <% end %> +<% end %> diff --git a/app/views/stop_area_copies/create.html.erb b/app/views/stop_area_copies/create.html.erb new file mode 100644 index 000000000..3e3151812 --- /dev/null +++ b/app/views/stop_area_copies/create.html.erb @@ -0,0 +1 @@ +<%= render "form" %>
\ No newline at end of file diff --git a/app/views/stop_area_copies/new.html.erb b/app/views/stop_area_copies/new.html.erb new file mode 100644 index 000000000..3e3151812 --- /dev/null +++ b/app/views/stop_area_copies/new.html.erb @@ -0,0 +1 @@ +<%= render "form" %>
\ No newline at end of file diff --git a/app/views/stop_areas/show.html.erb b/app/views/stop_areas/show.html.erb index dc2e60349..6659b703f 100644 --- a/app/views/stop_areas/show.html.erb +++ b/app/views/stop_areas/show.html.erb @@ -116,25 +116,29 @@ <ul class="actions"> <li><%= link_to t('stop_areas.actions.new'), new_referential_stop_area_path(@referential), :class => "add" %></li> <li><%= link_to t('stop_areas.actions.edit'), edit_referential_stop_area_path(@referential, @stop_area), :class => "edit" %></li> - <li><%= link_to t('stop_areas.actions.destroy'), referential_stop_area_path(@referential, @stop_area), :method => :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, :class => "remove" %></li> + <li><%= link_to t('stop_areas.actions.destroy'), referential_stop_area_path(@referential, @stop_area), :method => :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, :class => "remove" %></li> </ul> </td></tr> <% if manage_itl %> <tr><td> <h4><%= t(".itl_managment") %></h4> <ul class="actions"> - <li><%= link_to t('stop_areas.actions.add_routing_lines'), add_routing_lines_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_lines" %></li> - <li><%= link_to t('stop_areas.actions.add_routing_stops'), add_routing_stops_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_stops" %></li> + <li><%= link_to t('stop_areas.actions.add_routing_lines'), add_routing_lines_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_lines" %></li> + <li><%= link_to t('stop_areas.actions.add_routing_stops'), add_routing_stops_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_stops" %></li> </ul> </td></tr> <% else %> <tr><td> <h4><%= t(".stop_managment") %></h4> <ul class="actions"> - <li><%= link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), :class => "select_parent" %></li> - <% if manage_children %> - <li><%= link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), :class => "add_children" %></li> - <% end %> + <li><font color="#D98F3B"><i class="fa fa-arrow-up fa-fw"></i></font><%= link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), :class => "with_fa" %></li> + <% if @stop_area.parent == nil %> + <li><font color="green"><i class="fa fa-files-o fa-fw"></i></font><%= link_to t('stop_areas.actions.clone_as_parent'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, :hierarchy => "parent"), :class => "with_fa" %></li> + <% end %> + <% if manage_children %> + <li><font color="#D98F3B"><i class="fa fa-sitemap fa-fw"></i></font><%= link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), :class => "with_fa" %></li> + <li><font color="green"><i class="fa fa-files-o fa-fw"></i></font><%= link_to t('stop_areas.actions.clone_as_child'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, :hierarchy => "child"), :class => "with_fa" %></li> + <% end %> </ul> </td></tr> @@ -142,8 +146,8 @@ <tr><td> <h4><%= t(".access_managment") %></h4> <ul class="actions"> - <li><%= link_to t('access_points.actions.new'), new_referential_stop_area_access_point_path(@referential,@stop_area), :class => "add" %></li> - <li><%= link_to t('stop_areas.actions.manage_access_links'), access_links_referential_stop_area_path(@referential,@stop_area), :class => "select_parent" %></li> + <li><font color="green"><i class="fa fa-caret-square-o-right fa-fw"></i></font><%= link_to t('access_points.actions.new'), new_referential_stop_area_access_point_path(@referential,@stop_area), :class => "with_fa" %></li> + <li><font color="#D98F3B"><i class="fa fa-arrows-alt fa-fw"></i></font><%= link_to t('stop_areas.actions.manage_access_links'), access_links_referential_stop_area_path(@referential,@stop_area), :class => "with_fa" %></li> </ul> </td></tr> <% end %> diff --git a/config/locales/exports.yml b/config/locales/exports.yml index 970f7381c..9f7e59e43 100644 --- a/config/locales/exports.yml +++ b/config/locales/exports.yml @@ -9,6 +9,7 @@ en: title: "New export" all: "All" flash: "Export task on queue, refresh page to see progression" + flash2: "On success, a link for download will be displayed" index: title: "Exports" warning: "" @@ -121,6 +122,7 @@ fr: title: "Nouvel export" all: "Toutes" flash: "La demande d'export est mise en file d'attente, veuillez rafraichir régulièrement la page pour le suivre" + flash2: "Une fois l'export terminé, un lien sera disponible pour télécharger le résultat" index: title: "Exports" warning: "" diff --git a/config/locales/formtastic.yml b/config/locales/formtastic.yml index 52c413da8..40ea23472 100644 --- a/config/locales/formtastic.yml +++ b/config/locales/formtastic.yml @@ -1,17 +1,3 @@ -fr: - formtastic: - yes: 'Oui' - no: 'Non' - create: "Créer %{model}" - update: "Modifier %{model}" - submit: 'Valider %{model}' - cancel: 'Annuler' - reset: 'Réinitialiser %{model}' - required: 'requis' - import: "Lancer l'import" - export: "Lancer l'export" - validate: "Lancer la validation" - en: formtastic: yes: 'Yes' @@ -25,3 +11,19 @@ en: import: "Launch import" export: "Launch export" validate: "Launch validation" + duplicate: "Duplicate" + +fr: + formtastic: + yes: 'Oui' + no: 'Non' + create: "Créer %{model}" + update: "Modifier %{model}" + submit: 'Valider %{model}' + cancel: 'Annuler' + reset: 'Réinitialiser %{model}' + required: 'requis' + import: "Lancer l'import" + export: "Lancer l'export" + validate: "Lancer la validation" + duplicate: "Dupliquer" diff --git a/config/locales/stop_area_copies.yml b/config/locales/stop_area_copies.yml new file mode 100644 index 000000000..09425e6c7 --- /dev/null +++ b/config/locales/stop_area_copies.yml @@ -0,0 +1,27 @@ +en: + stop_area_copies: + new: + success: "Clone succedeed" + title: + child: "Clone as child" + parent: "Clone as parent" + errors: + copy_aborted: "Errors prohibited this copy from completing: " + activemodel: + attributes: + stop_area_copy: + area_type: "Area type" +fr: + stop_area_copies: + new: + success: "Clonage réussi" + title: + child: "Cloner pour créer un fils" + parent: "Cloner pour créer un père" + errors: + copy_aborted: "Des erreurs ont empéchées le bon déroulement de la copie: " + activemodel: + attributes: + stop_area_copy: + area_type: "Type d'arrêt" +
\ No newline at end of file diff --git a/config/locales/stop_area_imports.yml b/config/locales/stop_area_imports.yml index c080ea1b5..94d09975e 100644 --- a/config/locales/stop_area_imports.yml +++ b/config/locales/stop_area_imports.yml @@ -3,7 +3,7 @@ en: new: title: "Import stop areas" export_stop_areas: "Export existing stop_areas" - succcess: "Import is a success" + success: "Import is a success" tooltip: file: "Select a CSV or Excel file" errors: @@ -19,11 +19,11 @@ fr: new: title: "Import des arrêts" export_stop_areas: "Exporter les arrêts existants" - succcess: "L'import des données est un succès" + success: "L'import des données est un succès" tooltip: file: "Sélectionner un fichier CSV ou Excel" errors: - import_aborted: "Des erreurs ont empéchées le bon déroulement de l'import: " + import_aborted: "Des erreurs ont empéché le bon déroulement de l'import: " invalid_stop_area: "Erreur colonne %{column}, l'arrêt est invalide : %{message}" exception: "Le fichier est invalide, vous devez fournir un fichier csv, xls ou xlsx valide" activemodel: diff --git a/config/locales/stop_areas.yml b/config/locales/stop_areas.yml index 452395cef..fafc81ac6 100644 --- a/config/locales/stop_areas.yml +++ b/config/locales/stop_areas.yml @@ -14,6 +14,8 @@ en: destroy_confirm: "Are you sure you want destroy this stop?" select_parent: "Manage Parent" add_children: "Manage Children" + clone_as_parent: "Clone as parent" + clone_as_child: "Clone as child" manage_access_points: "Manage Access Points" manage_access_links: "Manage Access Links" add_routing_lines: "Manage constraint's lines" @@ -126,6 +128,8 @@ fr: destroy_confirm: "Etes vous sûr de supprimer cet arrêt ?" select_parent: "Gérer le parent" add_children: "Gérer les fils" + clone_as_parent: "Cloner pour créer un père" + clone_as_child: "Cloner pour créer un fils" add_routing_lines: "Gérer les lignes de l'ITL" add_routing_stops: "Gérer les arrêts de l'ITL" manage_access_points: "Gérer les accès" diff --git a/config/routes.rb b/config/routes.rb index a14f09b48..86f59a516 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,7 @@ ChouetteIhm::Application.routes.draw do resources :group_of_lines do resources :stop_areas do resources :access_points + resources :stop_area_copies resources :stop_area_parents resources :stop_area_children resources :stop_area_routing_lines @@ -72,6 +73,7 @@ ChouetteIhm::Application.routes.draw do resources :lines, :networks, :group_of_lines do resources :stop_areas do resources :access_points + resources :stop_area_copies resources :stop_area_parents resources :stop_area_children resources :stop_area_routing_lines @@ -142,6 +144,7 @@ ChouetteIhm::Application.routes.draw do resources :stop_areas do resources :access_points + resources :stop_area_copies resources :stop_area_parents resources :stop_area_children resources :stop_area_routing_lines |
