Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions tabbycat/draw/templates/DraggableTeam.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<draggable-item :drag-payload="dragPayload" :class="[{'bg-dark text-white': isUnavailable},
highlightsCSS, conflictsCSS, hoverConflictsCSS]"
<draggable-item :drag-payload="dragPayload"
:hover-panel="true" :hover-panel-item="hoverableData" :hover-panel-type="'team'"
:hover-conflicts="true" :hover-conflicts-item="clashableID" :hover-conflicts-type="'team'"
:class="[{'bg-dark text-white': isUnavailable}, highlightsCSS, conflictsCSS, hoverConflictsCSS]"
:enable-hover="true" :hover-item="hoverableData" :hover-type="hoverableType">

<span slot="number" class="d-none"><span></span></span>
Expand All @@ -17,9 +19,10 @@ import { mapState } from 'vuex'
import DraggableItem from '../../templates/allocations/DraggableItem.vue'
import HighlightableMixin from '../../templates/allocations/HighlightableMixin.vue'
import HoverablePanelMixin from '../../templates/allocations/HoverablePanelMixin.vue'
import HoverableConflictReceiverMixin from '../../templates/allocations/HoverableConflictReceiverMixin.vue'

export default {
mixins: [HoverablePanelMixin, HighlightableMixin],
mixins: [HoverablePanelMixin, HighlightableMixin, HoverableConflictReceiverMixin],
components: { DraggableItem },
props: {
item: Object,
Expand Down Expand Up @@ -49,6 +52,12 @@ export default {
highlightData: function () {
return this.item
},
clashableType: function () {
return 'team'
},
clashableID: function () {
return this.item && this.item.id ? this.item.id : null
},
hoverableData: function () {
return this.item
},
Expand All @@ -62,6 +71,46 @@ export default {
return this.gettext('Unaffiliated')
}
},
conflictsCSS: function () {
// Panel-level team-vs-team conflicts within the same debate
const debateId = this.dragPayload && this.dragPayload.assignment
if (!debateId || !this.item) { return '' }
const debate = this.$store.getters.allDebatesOrPanels[debateId]
if (!debate || !debate.teams) { return '' }

// Collect other team IDs in this debate
const otherIds = []
for (const pos in debate.teams) {
const tid = debate.teams[pos]
if (tid !== null && tid !== this.item.id) { otherIds.push(tid) }
}
if (otherIds.length === 0) { return '' }

// Same-institution (orange)
if (this.item.institution) {
for (const oid of otherIds) {
const ot = this.$store.getters.allocatableItems[oid]
if (ot && ot.institution && ot.institution === this.item.institution) {
return 'conflictable panel-institution'
}
}
}

// History (blue shades): pick most recent ago among opponents in this debate
const histories = this.$store.getters.teamHistoriesForItem(this.item.id)
if (histories && histories.team) {
let smallestAgo = 99
for (const h of histories.team) {
if (otherIds.includes(h.id) && h.ago < smallestAgo) {
smallestAgo = h.ago
}
}
if (smallestAgo !== 99) {
return `conflictable panel-histories-${smallestAgo}-ago`
}
}
return ''
},
...mapState(['extra']),
},
}
Expand Down
17 changes: 16 additions & 1 deletion tabbycat/draw/templates/EditDebateTeamsContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@
:unallocatedComponent="unallocatedComponent"
:handle-unused-drop="moveTeam">

<drag-and-drop-actions slot="actions" :count="debatesOrPanelsCount"></drag-and-drop-actions>
<drag-and-drop-actions slot="actions" :count="debatesOrPanelsCount">
<template slot="default-highlights">
<button
class="btn conflictable conflicts-toolbar hover-histories-2-ago"
data-toggle="tooltip"
v-text="gettext('Seen')"
:title="'Has been in the same debate previously.'"
/>
<button
class="btn conflictable conflicts-toolbar hover-institution"
data-toggle="tooltip"
v-text="gettext('Institution')"
:title="'Is from the same institution.'"
/>
</template>
</drag-and-drop-actions>

<template slot="extra-messages">
<div id="alertdiv" class="alert alert-warning show">
Expand Down
34 changes: 32 additions & 2 deletions tabbycat/draw/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import logging
import unicodedata
from itertools import product
from itertools import combinations, product
from zoneinfo import ZoneInfo

from django.contrib import messages
Expand Down Expand Up @@ -898,9 +898,39 @@ class EditDebateTeamsView(DebateDragAndDropMixin, AdministratorMixin, TemplateVi
prefetch_teams = False # Fetched in full as get_serialised
edit_permission = Permission.EDIT_DEBATETEAMS

def _get_team_histories_map(self):
now_seq = self.round.seq
histories = {}
debates = Debate.objects.filter(
round__tournament=self.tournament,
round__seq__lt=now_seq,
).select_related('round').prefetch_related('debateteam_set')

for debate in debates:
team_ids = [dt.team_id for dt in debate.debateteam_set.all()]
if len(team_ids) < 2:
continue
ago = now_seq - debate.round.seq
for a, b in combinations(team_ids, 2):
histories.setdefault(a, {'team': []})['team'].append({'id': b, 'ago': ago})
histories.setdefault(b, {'team': []})['team'].append({'id': a, 'ago': ago})
return histories

def get_extra_info(self):
info = super().get_extra_info()
teams = Team.objects.filter(tournament=self.tournament).only('id', 'institution_id')
team_institution_clashes = {}
for t in teams:
if t.institution_id:
team_institution_clashes[t.id] = {'institution': [{'id': t.institution_id}]}
team_histories = self._get_team_histories_map()
info['clashes'] = {'teams': team_institution_clashes, 'adjudicators': {}}
info['histories'] = {'teams': team_histories, 'adjudicators': {}}
return info

def get_serialised_allocatable_items(self):
# TODO: account for shared teams
teams = Team.objects.filter(tournament=self.tournament).prefetch_related('speaker_set')
teams = Team.objects.filter(tournament=self.tournament).prefetch_related('speaker_set', 'break_categories')
teams = annotate_availability(teams, self.round)
populate_win_counts(teams)
serialized_teams = EditDebateTeamsTeamSerializer(teams, many=True)
Expand Down