Fix recalc and contest edit page

This commit is contained in:
Ari Timonen 2020-03-30 03:26:32 +03:00
parent df719dee40
commit dc332a8062
6 changed files with 30 additions and 24 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -174,7 +174,7 @@
<td><%= contester.statuses[contester.active] %></td>
<td class="actions">
<% 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' } %>
</div>
</div>
<%= link_to "Recalculate points", recalc_contest_path(@contest), class: :button %>
<%= link_to "Show", @contest, class: :button %>
</div>
<script type="text/javascript">

View file

@ -60,14 +60,14 @@ Ensl::Application.routes.draw do
end
end
resources :locks
resources :contesters do
collection do
resources :contesters
get "contests/:id/confirmedmatches" => "contests#confirmed_matches", as: :confirmed_matches
resources :contests do
member do
get :recalc
end
end
get "contests/:id/confirmedmatches" => "contests#confirmed_matches", as: :confirmed_matches
resources :contests
resources :challenges
resources :servers
resources :predictions