From dc332a806246d8f9d2a08e4baaea3970a0528ef0 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Mon, 30 Mar 2020 03:26:32 +0300 Subject: [PATCH] Fix recalc and contest edit page --- app/assets/javascripts/local.js | 29 +++++++++++++------------- app/controllers/contests_controller.rb | 3 ++- app/models/contest.rb | 4 ++-- app/models/contester.rb | 2 +- app/views/contests/edit.html.erb | 6 +++++- config/routes.rb | 10 ++++----- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/local.js b/app/assets/javascripts/local.js index 936b86f..0af15bd 100644 --- a/app/assets/javascripts/local.js +++ b/app/assets/javascripts/local.js @@ -49,20 +49,6 @@ $(function() { }); // Submit TODO - $("form.edit_match_proposal a").on('click', function() { - var form = $(this).closest('form.edit_match_proposal'); - form.children("input#match_proposal_status").val($(this).dataset.id); - $.post(form.attr('action'),form.serialize(), function(data) { - tr = form.closest('tr'); - tr.children('td').eq(2).text(data.status); - if(data.status === 'Revoked' || data.status === 'Rejected') tr.children('td').eq(3).empty(); - }, 'json') - .error(function (err) { - errjson = JSON.parse(err.responseText); - alert(errjson.error.message); - }); - } - ); $("a.submit").on('click', function() { $(this).closest('form').submit() @@ -138,7 +124,22 @@ function QuoteText(id, type) { // Match proposal +$("form.edit_match_proposal a").on('click', function() { + var form = $(this).closest('form.edit_match_proposal'); + form.children("input#match_proposal_status").val($(this).dataset.id); + $.post(form.attr('action'),form.serialize(), function(data) { + tr = form.closest('tr'); + tr.children('td').eq(2).text(data.status); + if(data.status === 'Revoked' || data.status === 'Rejected') tr.children('td').eq(3).empty(); + }, 'json') + .error(function (err) { + errjson = JSON.parse(err.responseText); + alert(errjson.error.message); + }); + } +); +// Tooltip to help admin // Fields removing and adding dynamically diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 5acd705..c0b51bd 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -39,8 +39,9 @@ class ContestsController < ApplicationController end def recalc + raise AccessError unless @contest.can_update? cuser @contest.recalculate - render :text => t(:score_recalc), :layout => true + redirect_to_back end def new diff --git a/app/models/contest.rb b/app/models/contest.rb index 4ef692b..dfeaf21 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -104,8 +104,8 @@ class Contest < ActiveRecord::Base end def recalculate - Match.update_all("diff = null, points1 = null, points2 = null", {:contest_id => self.id}) - Contester.update_all("score = 0, win = 0, loss = 0, draw = 0, extra = 0", {:contest_id => self.id}) + Match.where(contest_id: self.id).update_all("diff = null, points1 = null, points2 = null") + Contester.where(contest_id: self.id).update_all("score = 0, win = 0, loss = 0, draw = 0, extra = 0") matches.finished.chrono.each do |match| match.recalculate match.save diff --git a/app/models/contester.rb b/app/models/contester.rb index cc2f119..4e0128e 100644 --- a/app/models/contester.rb +++ b/app/models/contester.rb @@ -128,6 +128,6 @@ class Contester < ActiveRecord::Base end def self.params params, cuser - params.require(:contester).permit(:team_id, :score, :win, :lowss, :draw, :contest_id, :active, :extra, :user) + params.require(:contester).permit(:team_id, :score, :win, :loss, :draw, :contest_id, :active, :extra, :user) end end diff --git a/app/views/contests/edit.html.erb b/app/views/contests/edit.html.erb index 283c38c..b708e03 100644 --- a/app/views/contests/edit.html.erb +++ b/app/views/contests/edit.html.erb @@ -174,7 +174,7 @@ <%= contester.statuses[contester.active] %> <% if contester.active %> - <%= link_to icon('pencil'), edit_contester_path(contester) %> + <%= link_to icon('pencil'), edit_contester_path(contester) %> <%= link_to icon('times'), contester, confirm: 'Are you sure?', method: :delete %> <% else %> <%= form_for contester do |c| %> @@ -266,6 +266,10 @@ <%= link_to "New Match", { controller: :matches, action: :new, id: @contest }, { class: 'button' } %> + + <%= link_to "Recalculate points", recalc_contest_path(@contest), class: :button %> + + <%= link_to "Show", @contest, class: :button %>