From 048d765c2e75cbfd29a22bebd1924a498ceeac91 Mon Sep 17 00:00:00 2001 From: Loos Date: Wed, 24 Sep 2014 20:08:05 -0400 Subject: [PATCH] Louis | Adds client waiting list to client list --- app/controllers/clients_controller.rb | 1 + app/models/client.rb | 8 +++ app/views/clients/index.html.haml | 71 +++++++++++++++++++-------- app/views/static_pages/home.html.haml | 4 -- lib/tasks/dummydata.rake | 2 +- 5 files changed, 60 insertions(+), 26 deletions(-) diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index a234e09..3b53b37 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -3,6 +3,7 @@ class ClientsController < ApplicationController before_action :authenticate_user! def index + @waiting_list = Client.waiting_list @clients = Client.all end diff --git a/app/models/client.rb b/app/models/client.rb index e81eb06..8840405 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -1,4 +1,12 @@ class Client < ActiveRecord::Base has_one :bike belongs_to :agency + + def self.waiting_list + clients = Client.all + non_voided_clients = clients.select{|client| !client.application_voided} + incomplete_clients = non_voided_clients.select{|client| !client.completion_date} + waiting_list = incomplete_clients.sort_by!{|client| client.application_date} + end + end diff --git a/app/views/clients/index.html.haml b/app/views/clients/index.html.haml index 754bcdc..c528a61 100644 --- a/app/views/clients/index.html.haml +++ b/app/views/clients/index.html.haml @@ -1,24 +1,53 @@ .container - %h1 Clients + .row + = link_to ' + New Client', new_client_path, class: "btn btn-default" + .row + %h1 Client Waiting List - %table.table.table-striped.table-bordered.table-hover - %thead - %tr - %th First Name - %th Last Name - %th Agency - %th - %th - %th - %tbody - - @clients.each do |client| + %table.table.table-striped.table-bordered.table-hover + %thead %tr - %td= client.first_name - %td= client.last_name - %td= client.agency.agency_name if client.agency - %td= link_to 'Show', client - %td= link_to 'Edit', edit_client_path(client) - %td= link_to 'Destroy', client, method: :delete, data: { confirm: 'Are you sure?' } - - %br - = link_to ' + New Client', new_client_path, class: "btn btn-default" + %th Number + %th First Name + %th Last Name + %th Application Date + %th Agency + %th + %th + %th + %tbody + - @waiting_list.each_with_index do |client, index| + %tr + %td= index + 1 + %td= client.first_name + %td= client.last_name + %td= client.application_date + %td= client.agency.agency_name if client.agency + %td= link_to 'Show', client + %td= link_to 'Edit', edit_client_path(client) + %td= link_to 'Destroy', client, method: :delete, data: { confirm: 'Are you sure?' } + + %br + .row + %h1 All Clients + + %table.table.table-striped.table-bordered.table-hover + %thead + %tr + %th First Name + %th Last Name + %th Agency + %th + %th + %th + %tbody + - @clients.each do |client| + %tr + %td= client.first_name + %td= client.last_name + %td= client.agency.agency_name if client.agency + %td= link_to 'Show', client + %td= link_to 'Edit', edit_client_path(client) + %td= link_to 'Destroy', client, method: :delete, data: { confirm: 'Are you sure?' } + + %br diff --git a/app/views/static_pages/home.html.haml b/app/views/static_pages/home.html.haml index cf72743..92ff605 100644 --- a/app/views/static_pages/home.html.haml +++ b/app/views/static_pages/home.html.haml @@ -1,9 +1,5 @@ .container %h1 Bike & Client Tracker - - if current_user - = link_to "Sign out", destroy_user_session_path, method: :delete - - else - = link_to "Sign in", new_user_session_path %br = link_to "View All Bikes", bikes_path %br diff --git a/lib/tasks/dummydata.rake b/lib/tasks/dummydata.rake index 869b728..1def745 100644 --- a/lib/tasks/dummydata.rake +++ b/lib/tasks/dummydata.rake @@ -35,7 +35,7 @@ namespace :db do weight: rand(100) + 100, helmet: [true, false].sample, lock: [true, false].sample, - completion_date: rand(30.days).ago, + completion_date: [rand(30.days).ago, nil].sample, bike_type_requested: ["Cruiser", "Road", "Mountain"].sample, will_pay: [true, false].sample, notes: "A great client!",