Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tao request #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ gem "sdoc", "~> 0.4.0", group: :doc

gem "carrierwave"
gem "mini_magick"
gem 'will_paginate', '>= 3.0.pre'
gem 'delayed_job_active_record'

group :development, :test do
gem "byebug"
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ GEM
execjs
coffee-script-source (1.9.1.1)
debug_inspector (0.0.2)
delayed_job (4.1.1)
activesupport (>= 3.0, < 5.0)
delayed_job_active_record (4.1.0)
activerecord (>= 3.0, < 5)
delayed_job (>= 3.0, < 5)
devise (3.5.2)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -166,6 +171,7 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
will_paginate (3.0.7)

PLATFORMS
ruby
Expand All @@ -176,6 +182,7 @@ DEPENDENCIES
byebug
carrierwave
coffee-rails (~> 4.1.0)
delayed_job_active_record
devise
jbuilder (~> 2.0)
jquery-rails
Expand All @@ -190,6 +197,7 @@ DEPENDENCIES
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)
will_paginate (>= 3.0.pre)

BUNDLED WITH
1.10.6
24 changes: 24 additions & 0 deletions app/controllers/customer/invoices_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Customer::InvoicesController < Customer::BaseController
before_action :authenticate_user!


def index
@invoices = Invoice.where(:request_id => (Request.select(:request_id).where(:customer_id => Customer.select(:customer_id).find_by_user_id(current_user.id))))
end

def accept
@invoice = Invoice.find_by_invoice_id(params[:invoice_id])
@request = Request.find_by_request_id(:request_id => @invoice.request_id)
if @invoice.nil?
flash[:danger] = "No request found"
redirect_to invoices_path
else
@invoice.status = 'accepted'
@invoice.save
@request.status = 'pending'
@request.save
flash[:notice] = "Successful accept response"
redirect_to controller: "invoices", action: "index"
end
end
end
3 changes: 3 additions & 0 deletions app/controllers/customer/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def create
@request.start_point_long = submit_params[:start_point_long].to_f
@request.end_point_lat = submit_params[:end_point_lat].to_f
@request.end_point_long = submit_params[:end_point_long].to_f
@request.status = "none"

distance = GoogleAPI.new().distanceEstimate(@request.start_point_lat,
@request.start_point_long,
Expand Down Expand Up @@ -91,4 +92,6 @@ def validate_customer
redirect_to "root_path"
end
end


end
13 changes: 9 additions & 4 deletions app/controllers/supplier/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ class Supplier::RequestsController < Supplier::BaseController
before_action :authenticate_user!
before_action :request_is_approved?

def index
@requests = Request.all
end

def show
@request = Request.find_by_request_id params[:id]
@breadcrumb = [current_user.role,"detailed request"]
Expand All @@ -18,7 +22,8 @@ def approve
newInvoice = @request.invoices.build
#In this context current user always be supplier
#FIXME: Check role ?
newInvoice.supplier_id = current_user.id
newInvoice.supplier_id = Supplier.select(:supplier_id).find_by_user_id(current_user.id)
newInvoice.status = "pending"
newInvoice.offer_price = params[:offer_price]
newInvoice.message = params[:message]
newInvoice.save
Expand All @@ -30,11 +35,11 @@ def approve

private
def request_is_approved?
invoice = Invoice.find_by request_id: params[:id], supplier_id: current_user.id
invoice = Invoice.find_by request_id: params[:id], supplier_id: Supplier.select(:supplier_id).find_by_user_id(current_user.id)
if invoice.nil?
@show_approve_form = false
else
@show_approve_form = true
else
@show_approve_form = false
end
end
end
3 changes: 2 additions & 1 deletion app/controllers/supplier/vehicles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Supplier::VehiclesController < Supplier::BaseController
def index
@vehicles = Vehicle.all
@vehicles = Vehicle.all.paginate(:page=>params[:page], :per_page => 10)
#@orders = Order.all.order('created_at DESC').paginate(:page=>params[:page], :per_page => 10)
end

def show
Expand Down
4 changes: 4 additions & 0 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Setting < ActiveRecord::Base
self.table_name = "setting"

end
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class User < ActiveRecord::Base
def get_detailed_info
if self.role == "customer"
Customer.find_by user_id: self.id
elsif self.role == "provider"
Provider.find_by user_id: self.id
elsif self.role == "supplier"
Supplier.find_by user_id: self.id
end
end

Expand Down
43 changes: 43 additions & 0 deletions app/views/customer/invoices/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div class="container" id="app-area">
<section class="row">
<a class="btn btn-default" href="#" role="button">Link</a>
<button class="btn btn-default" type="submit">Button</button>
<input class="btn btn-default" type="button" value="Input">
<input class="btn btn-default" type="submit" value="Submit">
</section>
<section class="row">
<br/><br/><br/><br/><br/><br/><br/>
</section>
<section class="row">
<table class="table table-hover">
<thead>
<th> Invoice id </th>
<th> supplier id </th>
<th> offer price</th>
<th> message</th>

</thead>
<tbody>

<% @invoices.each do |invoice|%>
<% if invoice.status == "pending" %>
<tr>
<%= form_tag("/customer/accept_invoice", method: "post", class: "") do %>
<%= hidden_field_tag :invoice_id, invoice.id %>
<td><%= invoice.id %></td>
<td><%= invoice.supplier_id %></td>
<td><%= invoice.offer_price %></td>
<td><%= invoice.message %></td>
<td class="row">
<%= submit_tag("Accept", class: "btn btn-default") %>
</td>
<% end %>
</tr>

<% end %>
<% end %>

</tbody>
</table>
</section>
</div>
11 changes: 11 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
</button>
<%= link_to image_tag("img_home.png"), root_path, class: "navbar-brand", style: "margin-bottom: 10px" %>
</div>
<% if current_user.role == "supplier" %>
<div> <%= link_to "You have " + (Request.where(:status => "none").count - Invoice.where(:supplier_id => Supplier.select(:supplier_id).find_by_user_id(current_user.id)).count).to_s + " request(s)", supplier_profile_path %></div><br />
<div>abc <%= Invoice.where(:supplier_id => (Supplier.select(:supplier_id).find_by_user_id(current_user.id)), :status => "accepted").count%></div>
<% end %>

<% if current_user.role == "customer" %>
<div>
<td> <%= link_to "You have " + Invoice.where(:request_id => (Request.select(:request_id).where(:customer_id => Customer.select(:customer_id).find_by_user_id(current_user.id))), :status => "pending").count.to_s + " response(s)", customer_invoices_path %> </td>

</div>
<% end %>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<% if [email protected]? %>
Expand Down
1 change: 1 addition & 0 deletions app/views/share/request/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<% end %>
</div>
<% elsif %>

<button class="btn btn-default">Approved</button>
<% end %>
</div>
Expand Down
14 changes: 9 additions & 5 deletions app/views/supplier/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@
<tbody>
<% @requests.each do |item| %>
<tr>
<td><%= item.id %></td>
<td><%= item.customer.user.email %></td>
<td>This text is static content....</td>
<td><span class="glyphicon glyphicon-pencil"></span></td>
<td>
<% invoice = Invoice.find_by request_id: item.id, supplier_id: Supplier.select(:supplier_id).find_by_user_id(current_user.id) %>
<% if invoice.nil? %>
<td><%= item.id %></td>
<td><%= item.customer.user.email %></td>
<td>This text is static content....</td>
<td><span class="glyphicon glyphicon-pencil"></span></td>
<td>

<% if item.status == "none" %>
This request curently open, <%= link_to "more...", supplier_request_path(item.id) %></a>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
Expand Down
Empty file.
32 changes: 32 additions & 0 deletions app/views/supplier/requests/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="row">
<h3>View all requests</h3>
</div>

<div class="row">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Date create</th>
<th>From</th>
<th>To</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<% @requests.each do |request| %>
<tr>
<td><%= request.id %></td>
<td><%= request.created_at %></td>
<td><b>Ha Noi</b></td>
<td>Ho Chi Minh</td>
<td>
<%= link_to "", supplier_request_path(request), class: "glyphicon glyphicon-eye-open" %>&nbsp&nbsp
<%= link_to "", edit_supplier_request_path(request), class: "glyphicon glyphicon-pencil" %>&nbsp&nbsp
<span class="glyphicon glyphicon-trash"></span>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
5 changes: 5 additions & 0 deletions bin/delayed_job
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize
1 change: 1 addition & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

# Initialize the Rails application.
Rails.application.initialize!
#config.active_job.queue_adapter = :delayed_job
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
get "profile" => "home#index"
post "approve_request" => "requests#approve"
resources :vehicles
resources :requests, only: [:show]
resources :requests
end

namespace :admin do
Expand All @@ -22,6 +22,8 @@

namespace :customer do
resources :requests
resources :invoices
post "accept_invoice" => "invoices#accept"
get "profile" => "profile#show"
end
end
22 changes: 22 additions & 0 deletions db/migrate/20160121130056_create_delayed_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class CreateDelayedJobs < ActiveRecord::Migration
def self.up
create_table :delayed_jobs, force: true do |table|
table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
table.text :handler, null: false # YAML-encoded string of the object that will do work
table.text :last_error # reason for last failure (See Note below)
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
table.datetime :locked_at # Set when a client is working on this object
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
table.string :locked_by # Who is working on this object (if locked)
table.string :queue # The name of the queue this job is in
table.timestamps null: true
end

add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
end

def self.down
drop_table :delayed_jobs
end
end
Loading