diff options
| author | Edouard Maffert | 2016-09-09 14:48:40 +0200 |
|---|---|---|
| committer | Edouard Maffert | 2016-09-09 14:48:40 +0200 |
| commit | 4747990c6d3ceb5020d06099d086500b066db6e4 (patch) | |
| tree | 1a2edc21344b1ed67a2a2d91affd522d533b3732 /app | |
| parent | ec8233bf59eed3edbdcf6ebf3b8812ec3d7f7ee7 (diff) | |
| parent | bb12088efba8d755bf29d2edb0309b59953e14f5 (diff) | |
| download | chouette-core-4747990c6d3ceb5020d06099d086500b066db6e4.tar.bz2 | |
Merge branch 'companies_line_referential_association'
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/companies_controller.rb | 22 | ||||
| -rw-r--r-- | app/controllers/referential_companies_controller.rb | 45 | ||||
| -rw-r--r-- | app/helpers/breadcrumb_helper.rb | 21 | ||||
| -rw-r--r-- | app/models/line_referential.rb | 1 | ||||
| -rw-r--r-- | app/models/referential.rb | 14 | ||||
| -rw-r--r-- | app/views/companies/_company.html.slim | 6 | ||||
| -rw-r--r-- | app/views/companies/_form.html.slim | 8 | ||||
| -rw-r--r-- | app/views/companies/index.html.slim | 6 | ||||
| -rw-r--r-- | app/views/companies/show.html.slim | 6 | ||||
| -rw-r--r-- | app/views/line_referentials/show.html.slim | 4 | ||||
| -rw-r--r-- | app/views/referential_companies/_companies.html.slim | 9 | ||||
| -rw-r--r-- | app/views/referential_companies/_company.html.slim | 16 | ||||
| -rw-r--r-- | app/views/referential_companies/_form.html.slim | 18 | ||||
| -rw-r--r-- | app/views/referential_companies/edit.html.slim | 2 | ||||
| -rw-r--r-- | app/views/referential_companies/index.html.slim | 24 | ||||
| -rw-r--r-- | app/views/referential_companies/index.js.slim | 1 | ||||
| -rw-r--r-- | app/views/referential_companies/new.html.slim | 2 | ||||
| -rw-r--r-- | app/views/referential_companies/show.html.slim | 55 |
18 files changed, 225 insertions, 35 deletions
diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index 1abaca9a8..cd0467a21 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -1,13 +1,15 @@ -class CompaniesController < ChouetteController +class CompaniesController < BreadcrumbController + include ApplicationHelper + defaults :resource_class => Chouette::Company respond_to :html respond_to :xml respond_to :json respond_to :js, :only => :index - belongs_to :referential, :parent_class => Referential + belongs_to :line_referential - def index + def index index! do |format| format.html { @@ -16,25 +18,27 @@ class CompaniesController < ChouetteController end } build_breadcrumb :index - end + end end - + protected - def collection - @q = referential.companies.search(params[:q]) + def collection + @q = line_referential.companies.search(params[:q]) @companies ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) end def resource_url(company = nil) - referential_company_path(referential, company || resource) + line_referential_company_path(line_referential, company || resource) end def collection_url - referential_companies_path(referential) + line_referential_companies_path(line_referential) end + alias_method :line_referential, :parent + def company_params params.require(:company).permit( :objectid, :object_version, :creation_time, :creator_id, :name, :short_name, :organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :registration_number, :url, :time_zone ) end diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb new file mode 100644 index 000000000..104deba9f --- /dev/null +++ b/app/controllers/referential_companies_controller.rb @@ -0,0 +1,45 @@ +class ReferentialCompaniesController < ChouetteController + defaults :resource_class => Chouette::Company, :collection_name => 'companies', :instance_name => 'company' + respond_to :html + respond_to :xml + respond_to :json + respond_to :js, :only => :index + + belongs_to :referential, :parent_class => Referential + + def index + index! do |format| + format.html { + if collection.out_of_bounds? + redirect_to params.merge(:page => 1) + end + } + build_breadcrumb :index + end + end + + protected + + def build_resource + super.tap do |company| + company.line_referential = referential.line_referential + end + end + + def collection + @q = referential.companies.search(params[:q]) + @companies ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) + end + + def resource_url(company = nil) + referential_company_path(referential, company || resource) + end + + def collection_url + referential_companies_path(referential) + end + + def company_params + params.require(:company).permit( :objectid, :object_version, :creation_time, :creator_id, :name, :short_name, :organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :registration_number, :url, :time_zone ) + end +end diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index 453c2c622..6cbeee4c9 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -52,6 +52,8 @@ module BreadcrumbHelper user_breadcrumb action when "Referential" referential_breadcrumb action + when "LineReferential" + line_referential_breadcrumb action when "Organisation" organisation_breadcrumb action when "Api::V1::ApiKey" @@ -160,10 +162,23 @@ module BreadcrumbHelper route_breadcrumb :edit end + def line_referential_breadcrumb(action = :edit) + organisation_breadcrumb + if @line_referential + add_breadcrumb breadcrumb_label(@line_referential), line_referential_path(@line_referential), :title => breadcrumb_tooltip(@line_referential) if action == :edit || action == :show || action == :update + end + end + def company_breadcrumb (action) - referential_breadcrumb - add_breadcrumb Chouette::Company.model_name.human(:count => 2), referential_companies_path(@referential) unless action == :index - add_breadcrumb breadcrumb_label(@company), referential_company_path(@referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit + if @line_referential + line_referential_breadcrumb + add_breadcrumb Chouette::Company.model_name.human(:count => 2), line_referential_companies_path(@line_referential) unless action == :index + add_breadcrumb breadcrumb_label(@company), referential_company_path(@line_referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit + else + referential_breadcrumb + add_breadcrumb Chouette::Company.model_name.human(:count => 2), referential_companies_path(@referential) unless action == :index + add_breadcrumb breadcrumb_label(@company), referential_company_path(@referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit + end end def import_breadcrumb (action) diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index 85464f5af..7592bb5f1 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -4,6 +4,7 @@ class LineReferential < ActiveRecord::Base has_many :lines, class_name: 'Chouette::Line' has_many :group_of_lines, class_name: 'Chouette::GroupOfLine' + has_many :companies, class_name: 'Chouette::Company' has_one :line_referential_sync diff --git a/app/models/referential.rb b/app/models/referential.rb index d4bdc8374..0063244e8 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -28,6 +28,8 @@ class Referential < ActiveRecord::Base belongs_to :line_referential # validates_presence_of :line_referential has_many :lines, through: :line_referential + has_many :companies, through: :line_referential + has_many :group_of_lines, through: :line_referential belongs_to :stop_area_referential # validates_presence_of :stop_area_referential @@ -61,14 +63,6 @@ class Referential < ActiveRecord::Base Chouette::Network.all end - def group_of_lines - Chouette::GroupOfLine.all - end - - def companies - Chouette::Company.all - end - def stop_areas Chouette::StopArea.all end @@ -221,5 +215,5 @@ class Referential < ActiveRecord::Base # self.archived = false update_column :archived_at, nil end - -end
\ No newline at end of file + +end diff --git a/app/views/companies/_company.html.slim b/app/views/companies/_company.html.slim index ca1b9f366..a6707b36c 100644 --- a/app/views/companies/_company.html.slim +++ b/app/views/companies/_company.html.slim @@ -2,12 +2,12 @@ .panel-heading .panel-title.clearfix span.pull-right - = link_to edit_referential_company_path(@referential, company), class: 'btn btn-default btn-sm' do + = link_to edit_line_referential_company_path(@line_referential, company), class: 'btn btn-default btn-sm' do span.fa.fa-pencil - = link_to referential_company_path(@referential, company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do + = link_to line_referential_company_path(@line_referential, company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do span.fa.fa-trash-o h5 - = link_to [@referential, company], class: 'preview', title: "#{Chouette::Company.model_name.human.capitalize} #{company.name}" do + = link_to [@line_referential, company], class: 'preview', title: "#{Chouette::Company.model_name.human.capitalize} #{company.name}" do span.name = truncate(company.name, length: 20) .panel-body diff --git a/app/views/companies/_form.html.slim b/app/views/companies/_form.html.slim index 3f8663949..caf75bd8b 100644 --- a/app/views/companies/_form.html.slim +++ b/app/views/companies/_form.html.slim @@ -1,6 +1,6 @@ -= semantic_form_for [@referential, @company] do |form| += semantic_form_for [@line_referential, @company] do |form| = form.inputs do - = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.name") } + = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.name") } = form.input :short_name = form.input :organizational_unit = form.input :operating_department_name @@ -10,9 +10,9 @@ = form.input :email, as: :email = form.input :time_zone, include_blank: true = form.input :url - = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.registration_number") } + = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.registration_number") } = form.input :objectid, :required => !@company.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.objectid") } = form.actions do - = form.action :submit, as: :button + = form.action :submit, as: :button = form.action :cancel, as: :link
\ No newline at end of file diff --git a/app/views/companies/index.html.slim b/app/views/companies/index.html.slim index 711b88607..2fb042fa1 100644 --- a/app/views/companies/index.html.slim +++ b/app/views/companies/index.html.slim @@ -1,6 +1,6 @@ = title_tag t('companies.index.title') -= search_form_for @q, :url => referential_companies_path(@referential), remote: true, :html => {:method => :get, class: 'form-inline', id: 'search', role: "form"} do |f| += search_form_for @q, :url => referential_companies_path(@line_referential), remote: true, :html => {:method => :get, class: 'form-inline', id: 'search', role: "form"} do |f| .panel.panel-default .panel-heading @@ -9,7 +9,7 @@ .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')}" %> --> @@ -21,5 +21,5 @@ - content_for :sidebar do ul.actions li - = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + = link_to t('companies.actions.new'), new_line_referential_company_path(@line_referential), class: 'add' br
\ No newline at end of file diff --git a/app/views/companies/show.html.slim b/app/views/companies/show.html.slim index a445dad61..693cea352 100644 --- a/app/views/companies/show.html.slim +++ b/app/views/companies/show.html.slim @@ -45,11 +45,11 @@ - content_for :sidebar do ul.actions li - = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + = link_to t('companies.actions.new'), new_line_referential_company_path(@line_referential), class: 'add' li - = link_to t('companies.actions.edit'), edit_referential_company_path(@referential, @company), class: 'edit' + = link_to t('companies.actions.edit'), edit_line_referential_company_path(@line_referential, @company), class: 'edit' li - = link_to t('companies.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'remove' + = link_to t('companies.actions.destroy'), line_referential_company_path(@line_referential, @company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'remove' br = creation_tag(@company)
\ No newline at end of file diff --git a/app/views/line_referentials/show.html.slim b/app/views/line_referentials/show.html.slim index 072877c62..019a0650a 100644 --- a/app/views/line_referentials/show.html.slim +++ b/app/views/line_referentials/show.html.slim @@ -13,6 +13,10 @@ span.badge = @line_referential.operating_lines.size = link_to Referential.human_attribute_name("lines"), line_referential_lines_path(@line_referential) + li.list-group-item + span.badge = @line_referential.companies.size + = link_to Referential.human_attribute_name("companies"), line_referential_companies_path(@line_referential) + - unless @line_referential.line_referential_sync.line_sync_operations.empty? h3 Historique des synchronisations diff --git a/app/views/referential_companies/_companies.html.slim b/app/views/referential_companies/_companies.html.slim new file mode 100644 index 000000000..bcd471cc7 --- /dev/null +++ b/app/views/referential_companies/_companies.html.slim @@ -0,0 +1,9 @@ +.page_info + span.search = t('will_paginate.page_entries_info.search') + = page_entries_info(@companies) + +.companies.paginated_content + = paginated_content(@companies) + +.pagination + = will_paginate @companies, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer
\ No newline at end of file diff --git a/app/views/referential_companies/_company.html.slim b/app/views/referential_companies/_company.html.slim new file mode 100644 index 000000000..06e13764e --- /dev/null +++ b/app/views/referential_companies/_company.html.slim @@ -0,0 +1,16 @@ +#index_item.company.panel.panel-default + .panel-heading + .panel-title.clearfix + span.pull-right + = link_to edit_referential_company_path(@referential, company), class: 'btn btn-default btn-sm' do + span.fa.fa-pencil + = link_to referential_company_path(@referential, company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do + span.fa.fa-trash-o + h5 + = link_to [@referential, company], class: 'preview', title: "#{Chouette::Company.model_name.human.capitalize} #{company.name}" do + span.name + = truncate(company.name, length: 20) + .panel-body + p + = company.human_attribute_name('code') + = company.code
\ No newline at end of file diff --git a/app/views/referential_companies/_form.html.slim b/app/views/referential_companies/_form.html.slim new file mode 100644 index 000000000..b02eab3f1 --- /dev/null +++ b/app/views/referential_companies/_form.html.slim @@ -0,0 +1,18 @@ += semantic_form_for [@referential, @company] do |form| + = form.inputs do + = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.name") } + = form.input :short_name + = form.input :organizational_unit + = form.input :operating_department_name + = form.input :code + = form.input :phone, as: :phone + = form.input :fax, as: :phone + = form.input :email, as: :email + = form.input :time_zone, include_blank: true + = form.input :url + = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.registration_number") } + = form.input :objectid, :required => !@company.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.objectid") } + + = form.actions do + = form.action :submit, as: :button + = form.action :cancel, as: :link
\ No newline at end of file diff --git a/app/views/referential_companies/edit.html.slim b/app/views/referential_companies/edit.html.slim new file mode 100644 index 000000000..6c415edfb --- /dev/null +++ b/app/views/referential_companies/edit.html.slim @@ -0,0 +1,2 @@ += title_tag t('companies.edit.title', company: @company.name) += render 'form'
\ No newline at end of file diff --git a/app/views/referential_companies/index.html.slim b/app/views/referential_companies/index.html.slim new file mode 100644 index 000000000..b32f206ca --- /dev/null +++ b/app/views/referential_companies/index.html.slim @@ -0,0 +1,24 @@ += title_tag t('companies.index.title') + += search_form_for @q, :url => referential_companies_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> --> +#companies + = render partial: 'companies', object: @companies + +- content_for :sidebar do + ul.actions + li + = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + br
\ No newline at end of file diff --git a/app/views/referential_companies/index.js.slim b/app/views/referential_companies/index.js.slim new file mode 100644 index 000000000..cfb1c719c --- /dev/null +++ b/app/views/referential_companies/index.js.slim @@ -0,0 +1 @@ +| $('#companies').html("= escape_javascript(render('companies'))");
\ No newline at end of file diff --git a/app/views/referential_companies/new.html.slim b/app/views/referential_companies/new.html.slim new file mode 100644 index 000000000..1acb1786f --- /dev/null +++ b/app/views/referential_companies/new.html.slim @@ -0,0 +1,2 @@ += title_tag t('companies.new.title') += render 'form'
\ No newline at end of file diff --git a/app/views/referential_companies/show.html.slim b/app/views/referential_companies/show.html.slim new file mode 100644 index 000000000..a445dad61 --- /dev/null +++ b/app/views/referential_companies/show.html.slim @@ -0,0 +1,55 @@ += title_tag t('companies.show.title', company: @company.name) + +.company_show + .summary + p + label = "#{Chouette::Company.human_attribute_name('short_name')} : " + = @company.short_name + + p + label = "#{Chouette::Company.human_attribute_name('organizational_unit')} : " + = @company.organizational_unit + + p + label = "#{Chouette::Company.human_attribute_name('operating_department_name')} : " + = @company.operating_department_name + + p + label = "#{Chouette::Company.human_attribute_name('code')} : " + = @company.code + + p + label = "#{Chouette::Company.human_attribute_name('phone')} : " + = @company.phone + + p + label = "#{Chouette::Company.human_attribute_name('fax')} : " + = @company.fax + + p + label = "#{Chouette::Company.human_attribute_name('email')} : " + = @company.email + + p + label = "#{Chouette::Company.human_attribute_name('time_zone')} : " + = @company.time_zone + + p + label = "#{Chouette::Company.human_attribute_name('url')} : " + = @company.url + + p + label = "#{Chouette::Company.human_attribute_name('registration_number')} : " + = @company.registration_number + +- content_for :sidebar do + ul.actions + li + = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + li + = link_to t('companies.actions.edit'), edit_referential_company_path(@referential, @company), class: 'edit' + li + = link_to t('companies.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'remove' + br + + = creation_tag(@company)
\ No newline at end of file |
