Refactor Rules to have an ID that is referenced instead of copying details everywhere.

This commit is contained in:
Patrick Fairbank
2020-03-15 21:09:48 -07:00
parent 4c3850e2e4
commit 49758eaafd
18 changed files with 183 additions and 138 deletions

View File

@@ -96,7 +96,9 @@
<h4>Fouls</h4>
{{"{{#each fouls}}"}}
<div class="row">
<div class="col-lg-3 col-lg-offset-1">{{"{{#if IsTechnical}}"}}Tech {{"{{/if}}"}}Foul</div>
<div class="col-lg-3 col-lg-offset-1">
{{"{{#if IsTechnical}}"}}Tech {{"{{/if}}"}}Foul{{"{{#if IsRankingPoint}}"}}+RP{{"{{/if}}"}}
</div>
<div class="col-lg-3">Team {{"{{TeamId}}"}}</div>
<div class="col-lg-3" data-toggle="tooltip" title="{{"{{Description}}"}}">{{"{{RuleNumber}}"}}</div>
</div>

View File

@@ -158,22 +158,16 @@
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Rule Violated</label>
<div class="col-lg-3">
<input type="text" class="form-control input-sm"
name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}RuleNumber">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Is Technical</label>
<div class="col-lg-3">
<input type="checkbox" class="input-sm" name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}IsTechnical">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Free Ranking Point</label>
<div class="col-lg-3">
<input type="checkbox" class="input-sm" name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}IsRankingPoint">
<label class="col-lg-4 control-label">Rule</label>
<div class="col-lg-7">
<select class="form-control" name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}RuleId">
{{range $rule := .Rules}}
<option value="{{$rule.Id}}">{{$rule.RuleNumber}}
[{{if $rule.IsTechnical}}Tech {{end}}Foul{{if $rule.IsRankingPoint}}+RP{{end}}]:
{{$rule.Description}}
</option>
{{end}}
</select>
</div>
</div>
<div class="form-group">

View File

@@ -26,10 +26,10 @@
<h4>Fouls</h4>
<table class="table">
{{range $foul := .RedFouls}}
{{template "foul" dict "foul" $foul "color" "red"}}
{{template "foul" dict "foul" $foul "color" "red" "rules" $.Rules}}
{{end}}
{{range $foul := .BlueFouls}}
{{template "foul" dict "foul" $foul "color" "blue"}}
{{template "foul" dict "foul" $foul "color" "blue" "rules" $.Rules}}
{{end}}
</table>
<h4>Yellow/Red Cards</h4>
@@ -58,13 +58,10 @@
</div>
<div class="row">
{{range $rule := .Rules}}
<a class="btn btn-sm
{{if $rule.IsTechnical}}btn-danger{{else if $rule.IsRankingPoint}}btn-primary
{{else}}btn-warning{{end}}
btn-referee btn-rule"
data-rule="{{$rule.RuleNumber}}" data-is-technical="{{$rule.IsTechnical}}"
data-is-ranking-point="{{$rule.IsRankingPoint}}" onclick="setFoulRule(this);"
data-toggle="tooltip" title="{{$rule.Description}}">
<a class="btn btn-sm {{if $rule.IsTechnical}}btn-danger{{else if $rule.IsRankingPoint}}btn-primary
{{else}}btn-warning{{end}} btn-referee btn-rule"
data-rule-id="{{$rule.Id}}" onclick="setFoulRule(this);" data-toggle="tooltip"
title="{{$rule.Description}}">
{{$rule.RuleNumber}}{{if $rule.IsTechnical}}<sup>T</sup>
{{else if $rule.IsRankingPoint}}<sup>RP</sup>{{end}}
</a>
@@ -108,10 +105,13 @@
<tr class="row-{{.color}}">
<td>{{.foul.TeamId}}</td>
<td>
{{.foul.RuleNumber}}{{if .foul.IsTechnical}}<sup>T</sup>{{else if .foul.IsRankingPoint}}<sup>RP</sup>{{end}}
{{$rule := index .rules .foul.RuleId}}
{{$rule.RuleNumber}}{{if $rule.IsTechnical}}<sup>T</sup>{{else if $rule.IsRankingPoint}}<sup>RP</sup>{{end}}
</td>
<td>
<a class="btn btn-sm btn-danger" onclick="deleteFoul('{{.color}}', {{.foul.TeamId}}, '{{.foul.RuleId}}',
{{.foul.TimeInMatchSec}});">Delete</a>
</td>
<td><a class="btn btn-sm btn-danger" onclick="deleteFoul('{{.color}}', {{.foul.TeamId}}, '{{.foul.RuleNumber}}',
{{.foul.IsTechnical}}, {{.foul.IsRankingPoint}}, {{.foul.TimeInMatchSec}});">Delete</a></td>
</tr>
{{end}}
{{define "card"}}