Browse Source

Added slugs to directorates, services & suppliers

pull/3/head
Adrian Short 14 years ago
parent
commit
4caad6bea5
8 changed files with 39 additions and 37 deletions
  1. +12
    -23
      app.rb
  2. +16
    -3
      lib/models.rb
  3. +2
    -2
      views/directorate.haml
  4. +1
    -1
      views/home.haml
  5. +3
    -3
      views/service.haml
  6. +1
    -1
      views/services.haml
  7. +3
    -3
      views/supplier.haml
  8. +1
    -1
      views/suppliers.haml

+ 12
- 23
app.rb View File

@@ -10,16 +10,16 @@ get '/' do
haml :home haml :home
end end


get '/directorates/:id' do
@directorate = Directorate.get(params[:id])
get '/directorates/:slug' do
@directorate = Directorate.first(:slug => params[:slug])
@total = @directorate.payments.sum(:amount) @total = @directorate.payments.sum(:amount)
haml :directorate haml :directorate
end end


get '/suppliers/:id.csv' do
@supplier = Supplier.get(params[:id])
get '/suppliers/:slug.csv' do
@supplier = Supplier.first(:slug => params[:slug])


headers "Content-Disposition" => "attachment;filename=supplier#{@supplier.id}.csv",
headers "Content-Disposition" => "attachment;filename=supplier-#{@supplier.slug}.csv",
"Content-Type" => "application/octet-stream" "Content-Type" => "application/octet-stream"


result = "Date,Trans No,Directorate,Service,Amount ex. VAT\n" result = "Date,Trans No,Directorate,Service,Amount ex. VAT\n"
@@ -32,8 +32,8 @@ get '/suppliers/:id.csv' do
end end


get '/suppliers/:id' do
@supplier = Supplier.get(params[:id])
get '/suppliers/:slug' do
@supplier = Supplier.first(:slug => params[:slug])
@total = @supplier.payments.sum(:amount) @total = @supplier.payments.sum(:amount)
haml :supplier haml :supplier
end end
@@ -43,10 +43,10 @@ get '/suppliers/?' do
haml :suppliers haml :suppliers
end end


get '/services/:id.csv' do
@service = Service.get(params[:id])
get '/services/:slug.csv' do
@service = Service.first(:slug => params[:slug])


headers "Content-Disposition" => "attachment;filename=service#{@service.id}.csv",
headers "Content-Disposition" => "attachment;filename=service-#{@service.slug}.csv",
"Content-Type" => "application/octet-stream" "Content-Type" => "application/octet-stream"


result = "Date,Trans No,Directorate,Supplier,Amount ex. VAT\n" result = "Date,Trans No,Directorate,Supplier,Amount ex. VAT\n"
@@ -59,8 +59,8 @@ get '/services/:id.csv' do
end end


get '/services/:id' do
@service = Service.get(params[:id])
get '/services/:slug' do
@service = Service.first(:slug => params[:slug])
@total = @service.payments.sum(:amount) @total = @service.payments.sum(:amount)
haml :service haml :service
end end
@@ -70,17 +70,6 @@ get '/services/?' do
haml :services haml :services
end end


get '/wards/:slug/postcode/:postcode/?' do
@ward = Ward.first(:slug => params[:slug])
@postcode = params[:postcode]
haml :wards
end

get '/wards/:slug/?' do
@ward = Ward.first(:slug => params[:slug])
haml :wards
end

get '/error' do get '/error' do
haml :error haml :error
end end


+ 16
- 3
lib/models.rb View File

@@ -28,8 +28,14 @@ class Directorate
property :id, Serial property :id, Serial
property :name, String, :length => 255, :required => true property :name, String, :length => 255, :required => true
property :slug, String, :length => 255
has n, :payments, :order => ['d'] has n, :payments, :order => ['d']

def self.slugify(name)
name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
end

end end


class Service class Service
@@ -37,8 +43,14 @@ class Service
property :id, Serial property :id, Serial
property :name, String, :length => 255, :required => true property :name, String, :length => 255, :required => true
property :slug, String, :length => 255
has n, :payments, :order => ['d'] has n, :payments, :order => ['d']

def self.slugify(name)
name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
end
end end


class Supplier class Supplier
@@ -46,12 +58,13 @@ class Supplier
property :id, Serial property :id, Serial
property :name, String, :length => 255, :required => true property :name, String, :length => 255, :required => true
property :slug, String, :length => 255
has n, :payments, :order => ['d'] has n, :payments, :order => ['d']
# def self.slugify(name)
# name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
# end
def self.slugify(name)
name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
end
end end


DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3") DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")


+ 2
- 2
views/directorate.haml View File

@@ -20,10 +20,10 @@
%tr %tr
%td= payment.d.strftime("%d %b %Y") %td= payment.d.strftime("%d %b %Y")
%td %td
%a{ :href => '/services/' + payment.service.id.to_s }
%a{ :href => '/services/' + payment.service.slug }
= payment.service.name = payment.service.name
%td %td
%a{ :href => '/suppliers/' + payment.supplier.id.to_s }
%a{ :href => '/suppliers/' + payment.supplier.slug }
= payment.supplier.name = payment.supplier.name
%td.right= sprintf("%0d", payment.amount) %td.right= sprintf("%0d", payment.amount)


+ 1
- 1
views/home.haml View File

@@ -7,5 +7,5 @@
- for directorate in @directorates - for directorate in @directorates
%p %p
%a{ :href=> "/directorates/#{directorate.id}" }
%a{ :href=> "/directorates/#{directorate.slug}" }
= directorate.name = directorate.name

+ 3
- 3
views/service.haml View File

@@ -9,7 +9,7 @@
%li %li
= @service.name = @service.name
%p.noprint.download %p.noprint.download
%a{ :href => "/services/#{@service.id}.csv" }
%a{ :href => "/services/#{@service.slug}.csv" }
Download data as CSV Download data as CSV
%table %table
@@ -23,10 +23,10 @@
%tr %tr
%td= payment.d.strftime("%d %b %Y") %td= payment.d.strftime("%d %b %Y")
%td %td
%a{ :href => '/directorates/' + payment.directorate.id.to_s }
%a{ :href => '/directorates/' + payment.directorate.slug }
= payment.directorate.name = payment.directorate.name
%td %td
%a{ :href => '/suppliers/' + payment.supplier.id.to_s }
%a{ :href => '/suppliers/' + payment.supplier.slug }
= payment.supplier.name = payment.supplier.name
%td.right= sprintf("%0d", payment.amount) %td.right= sprintf("%0d", payment.amount)


+ 1
- 1
views/services.haml View File

@@ -9,5 +9,5 @@
- for service in @services - for service in @services
%p %p
%a{ :href=> "/services/#{service.id}" }
%a{ :href=> "/services/#{service.slug}" }
= service.name = service.name

+ 3
- 3
views/supplier.haml View File

@@ -10,7 +10,7 @@
= @supplier.name = @supplier.name


%p.noprint.download %p.noprint.download
%a{ :href => "/suppliers/#{@supplier.id}.csv" }
%a{ :href => "/suppliers/#{@supplier.slug}.csv" }
Download data as CSV Download data as CSV
%table %table
@@ -24,10 +24,10 @@
%tr %tr
%td= payment.d.strftime("%d %b %Y") %td= payment.d.strftime("%d %b %Y")
%td %td
%a{ :href => '/directorates/' + payment.directorate.id.to_s }
%a{ :href => '/directorates/' + payment.directorate.slug }
= payment.directorate.name = payment.directorate.name
%td %td
%a{ :href => '/services/' + payment.service.id.to_s }
%a{ :href => '/services/' + payment.service.slug }
= payment.service.name = payment.service.name
%td.right= sprintf("%0d", payment.amount) %td.right= sprintf("%0d", payment.amount)


+ 1
- 1
views/suppliers.haml View File

@@ -9,5 +9,5 @@
- for supplier in @suppliers - for supplier in @suppliers
%p %p
%a{ :href=> "/suppliers/#{supplier.id}" }
%a{ :href=> "/suppliers/#{supplier.slug}" }
= supplier.name = supplier.name

Loading…
Cancel
Save