This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
233 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,58 @@ | ||
class AuctionParser < Struct.new(:params, :user) | ||
def attributes | ||
general_attributes.merge( | ||
start_datetime: start_datetime, | ||
end_datetime: end_datetime, | ||
user: user | ||
) | ||
end | ||
|
||
def general_attributes | ||
{ | ||
type: type, | ||
title: title, | ||
description: description, | ||
summary: summary, | ||
github_repo: github_repo, | ||
issue_url: issue_url, | ||
awardee_paid_status: auction_params[:awardee_paid_status], | ||
billable_to: auction_params[:billable_to], | ||
cap_proposal_url: auction_params[:cap_proposal_url], | ||
delivery_deadline: delivery_deadline, | ||
delivery_url: delivery_url, | ||
cap_proposal_url: cap_proposal_url, | ||
awardee_paid_status: awardee_paid_status, | ||
published: published, | ||
notes: notes, | ||
billable_to: billable_to, | ||
result: result, | ||
start_price: start_price | ||
} | ||
delivery_url: auction_params[:delivery_url], | ||
description: auction_params[:description], | ||
end_datetime: end_datetime, | ||
github_repo: auction_params[:github_repo], | ||
issue_url: auction_params[:issue_url], | ||
notes: auction_params[:notes], | ||
published: auction_params[:published], | ||
result: auction_params[:result], | ||
start_datetime: start_datetime, | ||
start_price: auction_params[:start_price], | ||
summary: auction_params[:summary], | ||
title: auction_params[:title], | ||
type: auction_params[:type], | ||
user: user | ||
}.reject { |_key, value| value.nil? } | ||
end | ||
|
||
private | ||
|
||
[ | ||
:type, | ||
:title, | ||
:description, | ||
:summary, | ||
:github_repo, | ||
:issue_url, | ||
:awardee_paid_status, | ||
:published, | ||
:awardee_paid_at, | ||
:delivery_url, | ||
:cap_proposal_url, | ||
:notes, | ||
:billable_to, | ||
:result, | ||
:start_price | ||
].each do |key| | ||
define_method key do | ||
params[:auction][key] | ||
end | ||
end | ||
|
||
def delivery_deadline | ||
if params.key?(:due_in_days) | ||
real_days = params[:due_in_days].to_i.business_days | ||
end_of_workday(real_days.after(end_datetime.to_date)) | ||
else | ||
parse_time(params[:auction][:delivery_deadline]) | ||
if auction_params.key?(:due_in_days) && auction_params[:due_in_days].present? | ||
real_days = auction_params[:due_in_days].to_i.business_days | ||
end_of_workday(real_days.after(end_datetime)) | ||
elsif auction_params[:deliery_deadline] | ||
parse_datetime("delivery_deadline") | ||
end | ||
end | ||
|
||
def start_datetime | ||
parse_time(params[:auction][:start_datetime]) | ||
parse_datetime("start_datetime") | ||
end | ||
|
||
def end_datetime | ||
parse_time(params[:auction][:end_datetime]) | ||
parse_datetime("end_datetime") | ||
end | ||
|
||
def parse_time(time) | ||
return nil if time.nil? | ||
parsed_time = Chronic.parse(time) | ||
fail ArgumentError, "Missing or poorly formatted time: '#{time}'" unless parsed_time | ||
|
||
unless time =~ /\d{1,2}:\d{2}/ | ||
parsed_time = parsed_time.beginning_of_day | ||
def parse_datetime(field) | ||
if auction_params["#{field}(1i)"] | ||
Time.zone.local(*(1..5).map { |i| auction_params["#{field}(#{i}i)"] }) | ||
end | ||
parsed_time.utc | ||
end | ||
|
||
def end_of_workday(date) | ||
cob = Time.parse(BusinessTime::Config.end_of_workday) | ||
Time.mktime(date.year, date.month, date.day, cob.hour, cob.min, cob.sec) | ||
end | ||
|
||
def auction_params | ||
params[:auction] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= f.input :delivery_url %> | ||
<%= f.input :result, collection: Auction.results.keys.to_a %> | ||
<%= f.input :cap_proposal_url %> | ||
<%= f.input :awardee_paid_status, collection: Auction.awardee_paid_statuses.keys.to_a %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<%= f.input :type, collection: Auction.types.keys.to_a %> | ||
<%= f.input :title %> | ||
<%= f.input :github_repo %> | ||
<%= f.input :issue_url %> | ||
<%= f.input :summary, as: :text %> | ||
<%= f.input :description, as: :text %> | ||
<%= f.input :start_datetime, as: :datetime, input_html: { type: 'date' } %> | ||
<%= f.input :end_datetime, as: :datetime %> | ||
<% if @auction.new_record? %> | ||
<%= f.input :due_in_days %> | ||
<% else %> | ||
<%= f.input :delivery_deadline, as: :datetime %> | ||
<% end %> | ||
<%= f.input :billable_to %> | ||
<%= f.input :start_price %> | ||
<%= f.input :published, collection: Auction.publisheds.keys.to_a %> | ||
<%= f.input :notes, as: :text %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<h1>Editing auction</h1> | ||
<%= form_for [:admin, @auction], method: 'put' do |f| %> | ||
<%= render partial: 'general_attributes', locals: {f: f} %> | ||
<%= render partial: 'edit_attributes', locals: {f: f} %> | ||
<%= f.submit value: 'Update', :class => 'usa-button usa-button-outline' %> | ||
<%= simple_form_for [:admin, @auction] do |f| %> | ||
<%= render partial: 'form', locals: { f: f } %> | ||
<%= render partial: 'edit_form', locals: { f: f } %> | ||
<%= f.submit class: 'usa-button usa-button-outline' %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
<h1>Create auction</h1> | ||
<%= form_for [:admin, @auction] do |f| %> | ||
<%= render partial: 'general_attributes', locals: {f: f} %> | ||
<%= f.submit value: 'Create', :class => 'usa-button usa-button-outline' %> | ||
<%= simple_form_for [:admin, @auction] do |f| %> | ||
<%= render partial: 'form', locals: { f: f } %> | ||
<%= f.submit class: 'usa-button usa-button-outline' %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.