mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-26 12:30:48 +00:00
Fix recalc and contest edit page
This commit is contained in:
parent
df719dee40
commit
dc332a8062
6 changed files with 30 additions and 24 deletions
|
@ -49,20 +49,6 @@ $(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Submit TODO
|
// 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() {
|
$("a.submit").on('click', function() {
|
||||||
$(this).closest('form').submit()
|
$(this).closest('form').submit()
|
||||||
|
@ -138,7 +124,22 @@ function QuoteText(id, type) {
|
||||||
|
|
||||||
// Match proposal
|
// 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
|
// Fields removing and adding dynamically
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,9 @@ class ContestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def recalc
|
def recalc
|
||||||
|
raise AccessError unless @contest.can_update? cuser
|
||||||
@contest.recalculate
|
@contest.recalculate
|
||||||
render :text => t(:score_recalc), :layout => true
|
redirect_to_back
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|
|
@ -104,8 +104,8 @@ class Contest < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
Match.update_all("diff = null, points1 = null, points2 = null", {:contest_id => self.id})
|
Match.where(contest_id: self.id).update_all("diff = null, points1 = null, points2 = null")
|
||||||
Contester.update_all("score = 0, win = 0, loss = 0, draw = 0, extra = 0", {:contest_id => self.id})
|
Contester.where(contest_id: self.id).update_all("score = 0, win = 0, loss = 0, draw = 0, extra = 0")
|
||||||
matches.finished.chrono.each do |match|
|
matches.finished.chrono.each do |match|
|
||||||
match.recalculate
|
match.recalculate
|
||||||
match.save
|
match.save
|
||||||
|
|
|
@ -128,6 +128,6 @@ class Contester < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.params params, cuser
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -174,7 +174,7 @@
|
||||||
<td><%= contester.statuses[contester.active] %></td>
|
<td><%= contester.statuses[contester.active] %></td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
<% if 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 %>
|
<%= link_to icon('times'), contester, confirm: 'Are you sure?', method: :delete %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= form_for contester do |c| %>
|
<%= form_for contester do |c| %>
|
||||||
|
@ -266,6 +266,10 @@
|
||||||
<%= link_to "New Match", { controller: :matches, action: :new, id: @contest }, { class: 'button' } %>
|
<%= link_to "New Match", { controller: :matches, action: :new, id: @contest }, { class: 'button' } %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= link_to "Recalculate points", recalc_contest_path(@contest), class: :button %>
|
||||||
|
|
||||||
|
<%= link_to "Show", @contest, class: :button %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
|
@ -60,14 +60,14 @@ Ensl::Application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :locks
|
resources :locks
|
||||||
resources :contesters do
|
resources :contesters
|
||||||
collection do
|
|
||||||
|
get "contests/:id/confirmedmatches" => "contests#confirmed_matches", as: :confirmed_matches
|
||||||
|
resources :contests do
|
||||||
|
member do
|
||||||
get :recalc
|
get :recalc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get "contests/:id/confirmedmatches" => "contests#confirmed_matches", as: :confirmed_matches
|
|
||||||
resources :contests
|
|
||||||
resources :challenges
|
resources :challenges
|
||||||
resources :servers
|
resources :servers
|
||||||
resources :predictions
|
resources :predictions
|
||||||
|
|
Loading…
Reference in a new issue