aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdouard Maffert2016-09-08 12:00:45 +0200
committerEdouard Maffert2016-09-08 12:00:45 +0200
commit9ae84db05b384e2426a16d15004570eb6cf2e7fe (patch)
tree662fd4f01e70d76735b361790928931221f10189
parent165202ba666686f341c6112d833b4a16e32a41e0 (diff)
downloadchouette-core-9ae84db05b384e2426a16d15004570eb6cf2e7fe.tar.bz2
Create referential_companies controller and views and fix companies edit link
-rw-r--r--app/controllers/referential_companies_controller.rb38
-rw-r--r--app/models/referential.rb5
-rw-r--r--app/views/companies/_company.html.slim2
-rw-r--r--app/views/referential_companies/_companies.html.slim9
-rw-r--r--app/views/referential_companies/_company.html.slim16
-rw-r--r--app/views/referential_companies/_form.html.slim18
-rw-r--r--app/views/referential_companies/edit.html.slim2
-rw-r--r--app/views/referential_companies/index.html.slim24
-rw-r--r--app/views/referential_companies/index.js.slim1
-rw-r--r--app/views/referential_companies/new.html.slim2
-rw-r--r--app/views/referential_companies/show.html.slim55
-rw-r--r--config/routes.rb2
-rw-r--r--spec/routing/companies_spec.rb12
13 files changed, 174 insertions, 12 deletions
diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb
new file mode 100644
index 000000000..477c3da9c
--- /dev/null
+++ b/app/controllers/referential_companies_controller.rb
@@ -0,0 +1,38 @@
+class ReferentialCompaniesController < ChouetteController
+ 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
+
+ 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 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 \ No newline at end of file
diff --git a/app/models/referential.rb b/app/models/referential.rb
index d4bdc8374..1cb3e52ba 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -28,6 +28,7 @@ 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
belongs_to :stop_area_referential
# validates_presence_of :stop_area_referential
@@ -65,10 +66,6 @@ class Referential < ActiveRecord::Base
Chouette::GroupOfLine.all
end
- def companies
- Chouette::Company.all
- end
-
def stop_areas
Chouette::StopArea.all
end
diff --git a/app/views/companies/_company.html.slim b/app/views/companies/_company.html.slim
index 519438126..a6707b36c 100644
--- a/app/views/companies/_company.html.slim
+++ b/app/views/companies/_company.html.slim
@@ -2,7 +2,7 @@
.panel-heading
.panel-title.clearfix
span.pull-right
- = link_to edit_referential_company_path(@line_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 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
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
diff --git a/config/routes.rb b/config/routes.rb
index 22c16615a..8a9ae51d2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -149,7 +149,7 @@ ChouetteIhm::Application.routes.draw do
end
end
- resources :companies
+ resources :companies, controller: "referential_companies"
resources :time_tables do
collection do
diff --git a/spec/routing/companies_spec.rb b/spec/routing/companies_spec.rb
index 25f86325b..df16079f3 100644
--- a/spec/routing/companies_spec.rb
+++ b/spec/routing/companies_spec.rb
@@ -3,21 +3,21 @@ require 'spec_helper'
describe CompaniesController do
describe "routing" do
it "not recognize #routes" do
- get( "/referentials/1/companies/2/routes").should_not route_to(
+ get( "/line_referentials/1/companies/2/routes").should_not route_to(
:controller => "companies", :action => "routes",
- :referential_id => "1", :id => "2"
+ :line_referential_id => "1", :id => "2"
)
end
it "not recognize #lines" do
- get( "/referentials/1/companies/2/lines").should_not route_to(
+ get( "/line_referentials/1/companies/2/lines").should_not route_to(
:controller => "companies", :action => "lines",
- :referential_id => "1", :id => "2"
+ :line_referential_id => "1", :id => "2"
)
end
it "recognize and generate #show" do
- get( "/referentials/1/companies/2").should route_to(
+ get( "/line_referentials/1/companies/2").should route_to(
:controller => "companies", :action => "show",
- :referential_id => "1", :id => "2"
+ :line_referential_id => "1", :id => "2"
)
end
end