Przeglądaj źródła

Added slugs to directorates, services & suppliers

pull/3/head
Adrian Short 14 lat temu
rodzic
commit
4caad6bea5
8 zmienionych plików z 39 dodań i 37 usunięć
  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 Wyświetl plik

@@ -10,16 +10,16 @@ get '/' do
haml :home
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)
haml :directorate
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"

result = "Date,Trans No,Directorate,Service,Amount ex. VAT\n"
@@ -32,8 +32,8 @@ get '/suppliers/:id.csv' do
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)
haml :supplier
end
@@ -43,10 +43,10 @@ get '/suppliers/?' do
haml :suppliers
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"

result = "Date,Trans No,Directorate,Supplier,Amount ex. VAT\n"
@@ -59,8 +59,8 @@ get '/services/:id.csv' do
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)
haml :service
end
@@ -70,17 +70,6 @@ get '/services/?' do
haml :services
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
haml :error
end


+ 16
- 3
lib/models.rb Wyświetl plik

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

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

end

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

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

class Supplier
@@ -46,12 +58,13 @@ class Supplier
property :id, Serial
property :name, String, :length => 255, :required => true
property :slug, String, :length => 255
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

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


+ 2
- 2
views/directorate.haml Wyświetl plik

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


+ 1
- 1
views/home.haml Wyświetl plik

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

+ 3
- 3
views/service.haml Wyświetl plik

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


+ 1
- 1
views/services.haml Wyświetl plik

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

+ 3
- 3
views/supplier.haml Wyświetl plik

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

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


+ 1
- 1
views/suppliers.haml Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz