Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ivanthecrazy/hackaton
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan committed Dec 8, 2014
2 parents 92ed165 + 5ffc722 commit 9832cb7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
42 changes: 25 additions & 17 deletions app/controllers/license_agreements_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class LicenseAgreementsController < ApplicationController
before_action :set_license_agreement, only: [:show, :edit, :update, :destroy]
before_action :set_license_agreement, only: [:show, :edit, :update, :destroy, :main_chart]

# GET /license_agreements
# GET /license_agreements.json
Expand All @@ -11,28 +11,24 @@ def index
# GET /license_agreements/1.json
def show
@license_agreements_term = @license_agreement.license_agreement_terms.order('sort')
@main_line_chart = LicenseAgreementAcceptance.where(license_agreement_id: @license_agreement.id).group_by_day(:created_at).count
unless params[:from].blank?
@main_line_chart = LicenseAgreementAcceptance.where('DATE(created_at) >= ?', params[:from]).where(license_agreement_id: @license_agreement.id).group_by_day(:created_at).count
end
unless params[:to].blank?
@main_line_chart = LicenseAgreementAcceptance.where('DATE(created_at) <= ?', params[:to]).where(license_agreement_id: @license_agreement.id).group_by_day(:created_at).count
end
@lat = params[:lat].to_i
@term_acceptance = TermAcceptance.where(license_agreement_term_id: @lat)
unless params["from-#{@lat}"].blank?
@term_acceptance = @term_acceptance.where('DATE(created_at) >= ?', params["from-#{@lat}"])
end
unless params["to-#{@lat}"].blank?
@term_acceptance = @term_acceptance.where('DATE(created_at) <= ?', params["to-#{@lat}"])
end
@term_acceptance = @term_acceptance.group_by_day(:created_at).count
@main_line_chart = LicenseAgreementAcceptance.where(license_agreement_id: @license_agreement.id)
.where('DATE(created_at) >= ?', Time.now - 14.days).group_by_day(:created_at).count
# @lat = params[:lat].to_i
# @term_acceptance = TermAcceptance.where(license_agreement_term_id: @lat)
# unless params["from-#{@lat}"].blank?
# @term_acceptance = @term_acceptance.where('DATE(created_at) >= ?', params["from-#{@lat}"])
# end
# unless params["to-#{@lat}"].blank?
# @term_acceptance = @term_acceptance.where('DATE(created_at) <= ?', params["to-#{@lat}"])
# end
# @term_acceptance = @term_acceptance.group_by_day(:created_at).count
redirect_to license_agreements_path unless !@license_agreement || @license_agreement.user_id == current_user.id
end

def chart_ajax
@lat = params[:lat].to_i
@term_acceptance = TermAcceptance.where(license_agreement_term_id: @lat)
@term_acceptance = @term_acceptance.where('DATE(created_at) >= ?', Time.now - 14.days) if params[:from].blank?
unless params["from"].blank?
@term_acceptance = @term_acceptance.where('DATE(created_at) >= ?', params["from"])
end
Expand All @@ -42,6 +38,18 @@ def chart_ajax
@term_acceptance = @term_acceptance.group_by_day(:created_at).count
end

def main_chart
@main_line_chart = LicenseAgreementAcceptance.where(license_agreement_id: @license_agreement.id)
@main_line_chart = @main_line_chart.where('DATE(created_at) >= ?', Time.now - 14.days) if params[:from].blank?
@main_line_chart = @main_line_chart.group_by_day(:created_at).count
unless params[:from].blank?
@main_line_chart = LicenseAgreementAcceptance.where('DATE(created_at) >= ?', params[:from]).where(license_agreement_id: @license_agreement.id).group_by_day(:created_at).count
end
unless params[:to].blank?
@main_line_chart = LicenseAgreementAcceptance.where('DATE(created_at) <= ?', params[:to]).where(license_agreement_id: @license_agreement.id).group_by_day(:created_at).count
end
end

# GET /license_agreements/new
def new
@license_agreement = LicenseAgreement.new
Expand Down
1 change: 1 addition & 0 deletions app/views/license_agreements/main_chart.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$('#main_line_chart').html('<%=j line_chart @main_line_chart %>');
3 changes: 2 additions & 1 deletion app/views/license_agreements/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ h1 License agreement
td User
td = @license_agreement.user.name
.col-md-8
= form_tag("", method: :get, remote: true) do
= form_tag(main_chart_path(@license_agreement), method: :get, remote: true) do
.row
.col-md-3.col-md-offset-3
= label_tag "From"
Expand All @@ -35,6 +35,7 @@ h1 License agreement
h3 License agreement terms
- @license_agreements_term.each do |lat|
- @term_acceptance = TermAcceptance.where(license_agreement_term_id: lat.id)
- @term_acceptance = @term_acceptance.where('DATE(created_at) >= ?', Time.now - 14.days) if params[:from].blank?
.well
.row
.col-md-7
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations", }

get '/agreements/chart' => 'license_agreements#chart_ajax', :as => :chart
get '/agreements/main_chart/:id' => 'license_agreements#main_chart', :as => :main_chart
get '/demo' => 'markup#demo', :as => :demo
get '/docs' => 'welcome#docs', :as => :documentation
get '/color_changer' => 'welcome#color_changer', :as => :customization
Expand Down

0 comments on commit 9832cb7

Please sign in to comment.