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

Refactor ticket purchase #1606

Merged
merged 2 commits into from Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/assets/javascripts/osem-dashboard.js
Expand Up @@ -55,18 +55,34 @@ $(function() {
}

function draw_line_chart(animation, $canvas){
var options = get_animation({}, animation);
var chart_data = create_dataset($canvas);
var weeks = $canvas.parent().data('weeks');
var data = {
labels : weeks,
datasets : chart_data
}

var options = get_animation(wholeNumberAxisFix(data), animation);
var ctx = $canvas.get(0).getContext("2d");
new Chart(ctx).Line(data, options);
}

function wholeNumberAxisFix(data){
var maxValue = false;
for(datasetIndex = 0; datasetIndex < data.datasets.length; ++datasetIndex){
var setMax = Math.max.apply(null, data.datasets[datasetIndex].data);
if (maxValue === false || setMax > maxValue) maxValue = setMax;
}

var steps = maxValue;
var stepWidth = 1;
if (maxValue > 10) {
stepWidth = Math.floor(maxValue / 10);
steps = Math.ceil(maxValue / stepWidth);
}
return { scaleOverride: true, scaleSteps: steps, scaleStepWidth: stepWidth, scaleStartValue: 0 };
}

function create_dataset($canvas){
var selected = getSelectedConferences($canvas);
var chart_data = $canvas.parent().data('chart');
Expand Down
1 change: 1 addition & 0 deletions app/controllers/ticket_purchases_controller.rb
Expand Up @@ -2,6 +2,7 @@ class TicketPurchasesController < ApplicationController
before_filter :authenticate_user!
load_resource :conference, find_by: :short_title
authorize_resource :conference_registrations, class: Registration
authorize_resource

def create
current_user.ticket_purchases.by_conference(@conference).unpaid.destroy_all
Expand Down