diff options
| author | Alban Peignier | 2016-09-10 16:48:44 +0200 |
|---|---|---|
| committer | Alban Peignier | 2016-09-10 16:48:44 +0200 |
| commit | 69473fd3c1a8e2d3a9dcfce70c63c6d0a60edd4e (patch) | |
| tree | 8709b50098db1b5a48caa5df2b245fb939e3039a | |
| parent | dd300bbeae39ec67f0dc811b17720b03263bac20 (diff) | |
| download | chouette-core-69473fd3c1a8e2d3a9dcfce70c63c6d0a60edd4e.tar.bz2 | |
Manage GroupOfLines into Referential. Refs #838
| -rw-r--r-- | app/controllers/referential_group_of_lines_controller.rb | 71 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/_form.html.slim | 27 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/_group_of_line.html.slim | 19 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/_group_of_lines.html.slim | 9 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/_lines_detail.html.slim | 2 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/edit.html.slim | 3 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/index.html.slim | 24 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/index.js.slim | 1 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/new.html.slim | 3 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/show.html.slim | 31 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/show.js.slim | 1 | ||||
| -rw-r--r-- | app/views/referential_group_of_lines/show.kml.slim | 10 | ||||
| -rw-r--r-- | config/locales/group_of_lines.en.yml | 20 | ||||
| -rw-r--r-- | config/locales/group_of_lines.fr.yml | 4 | ||||
| -rw-r--r-- | config/routes.rb | 4 |
15 files changed, 217 insertions, 12 deletions
diff --git a/app/controllers/referential_group_of_lines_controller.rb b/app/controllers/referential_group_of_lines_controller.rb new file mode 100644 index 000000000..b00f5360b --- /dev/null +++ b/app/controllers/referential_group_of_lines_controller.rb @@ -0,0 +1,71 @@ +class ReferentialGroupOfLinesController < ChouetteController + defaults :resource_class => Chouette::GroupOfLine, :collection_name => 'group_of_lines', :instance_name => 'group_of_line' + + respond_to :html + respond_to :xml + respond_to :json + respond_to :kml, :only => :show + respond_to :js, :only => :index + + belongs_to :referential + + def show + @map = GroupOfLineMap.new(resource).with_helpers(self) + @lines = resource.lines.order(:name) + show! do + build_breadcrumb :show + end + end + + def index + index! do |format| + format.html { + if collection.out_of_bounds? + redirect_to params.merge(:page => 1) + end + build_breadcrumb :index + } + end + end + + + def name_filter + respond_to do |format| + format.json { render :json => filtered_group_of_lines_maps} + end + end + + + protected + + def filtered_group_of_lines_maps + filtered_group_of_lines.collect do |group_of_line| + { :id => group_of_line.id, :name => group_of_line.name } + end + end + + def filtered_group_of_lines + referential.group_of_lines.select{ |t| t.name =~ /#{params[:q]}/i } + end + + def collection + @q = referential.group_of_lines.search(params[:q]) + @group_of_lines ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) + end + + def resource_url(group_of_line = nil) + referential_group_of_line_path(referential, group_of_line || resource) + end + + def collection_url + referential_group_of_lines_path(referential) + end + + + private + + def group_of_line_params + params.require(:group_of_line).permit( :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :lines, :registration_number, :line_tokens) + end + +end diff --git a/app/views/referential_group_of_lines/_form.html.slim b/app/views/referential_group_of_lines/_form.html.slim new file mode 100644 index 000000000..c3c65df7a --- /dev/null +++ b/app/views/referential_group_of_lines/_form.html.slim @@ -0,0 +1,27 @@ += semantic_form_for [@referential, @group_of_line] do |form| + = form.inputs do + = form.input :name, input_html: { title: I18n.t("formtastic.titles#{format_restriction_for_locales(@referential)}.group_of_line.name") } + = form.input :registration_number, input_html: { title: I18n.t("formtastic.titles#{format_restriction_for_locales(@referential)}.group_of_line.registration_number") } + = form.input :comment + = form.input :objectid, :required => !@group_of_line.new_record?, :input_html => { :title => I18n.t("formtastic.titles#{format_restriction_for_locales(@referential)}.group_of_line.objectid") } + + = form.inputs do + = form.input :line_tokens, label: t('.lines'), as: :text, :input_html => { :"data-pre" => ( @group_of_line.lines.map { |line| { id: line.id, name: line.name } } ).to_json } + + = form.actions do + = form.action :submit, as: :button + = form.action :cancel, as: :link + + +javascript: + $(function() { + $('#group_of_line_line_tokens').tokenInput("#{name_filter_referential_lines_path(@referential, format: :json)}", { + crossDomain: false, + prePopulate: $('#line_tokens').data('pre'), + minChars: 1, + preventDuplicates: true, + hintText: "#{I18n.t('search_hint')", + noResultsText: "#{I18n.t('no_result_text')}", + searchingText: "#{I18n.t('searching_term')}" + }); + });
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/_group_of_line.html.slim b/app/views/referential_group_of_lines/_group_of_line.html.slim new file mode 100644 index 000000000..95a2a4aa5 --- /dev/null +++ b/app/views/referential_group_of_lines/_group_of_line.html.slim @@ -0,0 +1,19 @@ +#index_item.panel.panel-default + .panel-heading + .panel-title.clearfix + span.pull-right + - if edit + = link_to edit_referential_group_of_line_path(@referential, group_of_line), class: 'btn btn-default btn-sm' do + span.fa.fa-pencil + + = link_to('<span class="fa fa-trash-o"></span>'.html_safe, referential_group_of_line_path(@referential, group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm') if delete + + h5 + = link_to [@referential, group_of_line], :class => "preview", :title => "#{Chouette::GroupOfLine.model_name.human.capitalize} #{group_of_line.name}" do + span.name + = truncate(group_of_line.name, :length => 20) + + .panel-body + p + = group_of_line.human_attribute_name('line_count') + = group_of_line.lines.count
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/_group_of_lines.html.slim b/app/views/referential_group_of_lines/_group_of_lines.html.slim new file mode 100644 index 000000000..7e55caebe --- /dev/null +++ b/app/views/referential_group_of_lines/_group_of_lines.html.slim @@ -0,0 +1,9 @@ +.page_info + span.search = t("will_paginate.page_entries_info.search") + = page_entries_info @group_of_lines + +.group_of_lines.paginated_content + = paginated_content(@group_of_lines) + +.pagination + = will_paginate @group_of_lines, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/_lines_detail.html.slim b/app/views/referential_group_of_lines/_lines_detail.html.slim new file mode 100644 index 000000000..f6e9b386e --- /dev/null +++ b/app/views/referential_group_of_lines/_lines_detail.html.slim @@ -0,0 +1,2 @@ +.lines.paginated_content + = paginated_content @lines, "lines/line", delete: false
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/edit.html.slim b/app/views/referential_group_of_lines/edit.html.slim new file mode 100644 index 000000000..75d530b08 --- /dev/null +++ b/app/views/referential_group_of_lines/edit.html.slim @@ -0,0 +1,3 @@ += title_tag t('group_of_lines.edit.title', :group_of_line => @group_of_line.name) + += render 'form'
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/index.html.slim b/app/views/referential_group_of_lines/index.html.slim new file mode 100644 index 000000000..5e3c2eb17 --- /dev/null +++ b/app/views/referential_group_of_lines/index.html.slim @@ -0,0 +1,24 @@ += title_tag t('group_of_lines.index.title') + += search_form_for @q, :url => referential_group_of_lines_path(@referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| + .panel.panel-default + .panel-heading + .input-group.col-md-12 + = f.text_field :name_cont, :placeholder => "#{t('.name')}", class: 'form-control' + .input-group-btn + button.btn.btn-default type="submit" + i.fa.fa-search + + / <!-- /input-group --> + / <!-- <a data-toggle="collapse" data-parent="#search" href="#advanced_search"> --> + / <!-- <i class="fa fa-plus"></i> <%= "#{t('.advanced_search')}" %> --> + / <!-- </a> --> + +#group_of_lines + = render 'group_of_lines' + +- content_for :sidebar do + ul.actions + li + = link_to t('group_of_lines.actions.new'), new_referential_group_of_line_path(@referential), class: 'add' + br
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/index.js.slim b/app/views/referential_group_of_lines/index.js.slim new file mode 100644 index 000000000..c21aa99cd --- /dev/null +++ b/app/views/referential_group_of_lines/index.js.slim @@ -0,0 +1 @@ +| $('#group_of_lines').html("#{escape_javascript(render('group_of_lines'))}");
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/new.html.slim b/app/views/referential_group_of_lines/new.html.slim new file mode 100644 index 000000000..36b5d6b4e --- /dev/null +++ b/app/views/referential_group_of_lines/new.html.slim @@ -0,0 +1,3 @@ += title_tag t('group_of_lines.new.title') + +== render 'form'
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/show.html.slim b/app/views/referential_group_of_lines/show.html.slim new file mode 100644 index 000000000..a0635f158 --- /dev/null +++ b/app/views/referential_group_of_lines/show.html.slim @@ -0,0 +1,31 @@ += title_tag t('group_of_lines.show.title', :group_of_line => @group_of_line.name ) + +.group_of_line_show + = @map.to_html + + .summary + p + label = "#{@group_of_line.human_attribute_name('registration_number')} : " + = @group_of_line.registration_number + + p + label = "#{@group_of_line.human_attribute_name('comment')} : " + = @group_of_line.comment + + p.after_map + + h3.group_of_line_lines = t('.lines') + .lines_detail + == render partial: "lines_detail" + +- content_for :sidebar do + ul.actions + li + = link_to t('group_of_lines.actions.new'), new_referential_group_of_line_path(@referential), class: 'add' + li + = link_to t('group_of_lines.actions.edit'), edit_referential_group_of_line_path(@referential, @group_of_line), class: 'edit' + li + = link_to t('group_of_lines.actions.destroy'), referential_group_of_line_path(@referential, @group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')} , class: 'remove' + br + + = creation_tag(@group_of_line)
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/show.js.slim b/app/views/referential_group_of_lines/show.js.slim new file mode 100644 index 000000000..786400a58 --- /dev/null +++ b/app/views/referential_group_of_lines/show.js.slim @@ -0,0 +1 @@ +| $(function (){ $('.lines_detail').html("#{escape_javascript(render(partial: 'lines_detail'))}"); });
\ No newline at end of file diff --git a/app/views/referential_group_of_lines/show.kml.slim b/app/views/referential_group_of_lines/show.kml.slim new file mode 100644 index 000000000..094d05839 --- /dev/null +++ b/app/views/referential_group_of_lines/show.kml.slim @@ -0,0 +1,10 @@ +doctype XML + +kml xmlns="http://www.opengis.net/kml/2.2" + document + - @group_of_line.commercial_stop_areas.each do |stop_area| + placemark id="#{stop_area.id}" + name = stop_area.name + stop_area_type = stop_area.area_type.underscore + stop_area_type_label = t("area_types.label.#{stop_area.stop_area_type}") + stop_area_type_label = (stop_area.position or stop_area.default_position).kml_representation.html_safe
\ No newline at end of file diff --git a/config/locales/group_of_lines.en.yml b/config/locales/group_of_lines.en.yml index 757ed51cf..b1cc10acc 100644 --- a/config/locales/group_of_lines.en.yml +++ b/config/locales/group_of_lines.en.yml @@ -1,5 +1,5 @@ en: - group_of_lines: + group_of_lines: &en_group_of_lines actions: new: "Add a new group of lines" edit: "Edit this group of lines" @@ -17,10 +17,10 @@ en: name: "Search by name" advanced_search: 'Advanced search' form: - lines: "Associated lines" + lines: "Associated lines" activerecord: models: - group_of_line: + group_of_line: zero: "group of line" one: "group of line" other: "groups of lines" @@ -33,30 +33,32 @@ en: objectid: "Neptune identifier" object_version: "Version" creation_time: "Created on" - creator_id: "Created by" + creator_id: "Created by" formtastic: titles: group_of_line: name: "" - registration_number: "Positif integer." + registration_number: "Positif integer." objectid: "[prefix]:GroupOfLine:[unique_key] : prefix contains only alphanumerical or underscore characters, unique_key accepts also minus character" neptune: group_of_line: name: "" - registration_number: "Positif integer." + registration_number: "Positif integer." objectid: "[prefix]:GroupOfLine:[unique_key] : prefix contains only alphanumerical or underscore characters, unique_key accepts also minus character" netex: group_of_line: name: "" - registration_number: "Positif integer." + registration_number: "Positif integer." objectid: "[prefix]:GroupOfLine:[unique_key] : prefix contains only alphanumerical or underscore characters, unique_key accepts also minus character" gtfs: group_of_line: name: "" - registration_number: "Positif integer." + registration_number: "Positif integer." objectid: "[prefix]:GroupOfLine:[unique_key] : prefix contains only alphanumerical or underscore characters, unique_key accepts also minus character" hub: group_of_line: name: "maximum 75 characters" - registration_number: "Positif integer, unique key, of no more than 8 digits." + registration_number: "Positif integer, unique key, of no more than 8 digits." objectid: "[prefix]:GroupOfLine:[unique_key] : prefix contains only alphanumerical or underscore characters, unique_key accepts also minus character. Maximum length of the unique key = 6." + referential_group_of_lines: + <<: *en_group_of_lines
\ No newline at end of file diff --git a/config/locales/group_of_lines.fr.yml b/config/locales/group_of_lines.fr.yml index b9b7b8bd2..6e0f0640b 100644 --- a/config/locales/group_of_lines.fr.yml +++ b/config/locales/group_of_lines.fr.yml @@ -1,5 +1,5 @@ fr: - group_of_lines: + group_of_lines: &fr_group_of_lines actions: new: "Ajouter un groupe de lignes" edit: "Modifier ce groupe de lignes" @@ -60,3 +60,5 @@ fr: name: "maximum 75 caractères" registration_number: "Entier positif, clé unique, d'un maximum de 8 chiffres." objectid: "[prefixe]:GroupOfLine:[clé_unique] caractères autorisés : alphanumériques et 'souligné' pour le préfixe, la clé unique accepte en plus le 'moins'. Longueur maximale de la clé unique = 6." + referential_group_of_lines: + <<: *fr_group_of_lines
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 414bbde79..1d9354991 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,7 +68,7 @@ ChouetteIhm::Application.routes.draw do resources :autocomplete_time_tables resources :autocomplete_route_sections resources :autocomplete_timebands - resources :group_of_lines do + resources :group_of_lines, controller: "referential_group_of_lines" do collection do get 'name_filter' end @@ -208,4 +208,4 @@ ChouetteIhm::Application.routes.draw do get '/422', :to => 'errors#server_error' get '/500', :to => 'errors#server_error' -end
\ No newline at end of file +end |
