Skip to content

Commit f3f6154

Browse files
committed
Use Semantic UI for inner tabs, clean code
1 parent e523ef3 commit f3f6154

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/static/riot/competitions/detail/submission_modal.tag

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@
4040
<!-- Logs -->
4141
<div class="ui tab modal-tab" data-tab="{admin_: submission.admin}logs" hide="{opts.hide_output}">
4242
<div class="ui top attached inverted pointing menu" if="{logTabs.length > 0}">
43-
<div each="{tab in logTabs}"
44-
class="submission-modal item {active: tab.fullTabId === activeLogTabId}"
45-
data-tab="{tab.fullTabId}"
46-
onclick="{() => { activeLogTabId = tab.fullTabId }}">
43+
<div each="{tab, i in logTabs}"
44+
class="submission-modal item {active: i === 0}"
45+
data-tab="{tab.fullTabId}">
4746
{tab.label}
4847
</div>
4948
</div>
@@ -52,10 +51,10 @@
5251
<pre class="empty">No logs available for this submission.</pre>
5352
</div>
5453
<!-- Dynamic tabs -->
55-
<div each="{tab in logTabs}"
56-
class="ui bottom attached inverted segment tab log {active: tab.fullTabId === activeLogTabId}"
54+
<div each="{tab, i in logTabs}"
55+
class="ui bottom attached inverted segment tab log {active: i === 0}"
5756
data-tab="{tab.fullTabId}">
58-
<pre class="{empty: isEmpty(tab.content)}">{ showLog(tab.content) }</pre>
57+
<pre class="{empty: is_empty(tab.content)}">{ show_log(tab.content) }</pre>
5958
</div>
6059
</div>
6160
<!-- Fact sheet -->
@@ -82,8 +81,8 @@
8281
self.columns = []
8382

8483
// Logs helpers
85-
self.nonEmpty = (v) => !self.isEmpty(v)
86-
self.showLog = (v) => self.nonEmpty(v) ? self.normalizeLog(v) : "No logs for this tab."
84+
self.non_empty = (v) => !self.is_empty(v)
85+
self.show_log = (v) => self.non_empty(v) ? self.normalizeLog(v) : "No logs for this tab."
8786
self.normalizeLog = (v) => {
8887
if (v == null) return v
8988
if (Array.isArray(v)) return v.join('\n')
@@ -92,16 +91,15 @@
9291
}
9392
return String(v)
9493
}
95-
self.isEmpty = (v) => {
94+
self.is_empty = (v) => {
9695
v = self.normalizeLog(v)
9796
return v == null || (typeof v === "string" && v.trim().length === 0)
9897
}
9998

10099
// Dynamic tabs state
101100
self.logTabs = []
102-
self.activeLogTabId = null
103101

104-
self.rebuildLogTabs = () => {
102+
self.rebuild_log_tabs = () => {
105103
const prefix = self.submission && self.submission.admin ? 'admin_' : ''
106104
const candidates = [
107105
{ key:'p_stdout', label:'Prediction output', content: self.logs.prediction_stdout },
@@ -116,16 +114,11 @@
116114

117115
// Keep only non empty tabs
118116
self.logTabs = candidates
119-
.filter(t => !self.isEmpty(t.content))
117+
.filter(t => !self.is_empty(t.content))
120118
.map(t => ({
121119
...t,
122120
fullTabId: `${prefix}${t.key}`
123121
}))
124-
// Select a valid tab as active
125-
const stillValid = self.logTabs.find(t => t.fullTabId === self.activeLogTabId)
126-
if (!stillValid) {
127-
self.activeLogTabId = self.logTabs.length ? self.logTabs[0].fullTabId : null
128-
}
129122
}
130123

131124
self.get_score_details = function (column) {
@@ -140,7 +133,7 @@
140133
}
141134
self.update_submission_details = () => {
142135
self.logs = {}
143-
self.rebuildLogTabs()
136+
self.rebuild_log_tabs()
144137
self.update()
145138
CODALAB.api.get_submission_details(self.submission.id)
146139
.done(function (data) {
@@ -151,19 +144,25 @@
151144
self.detailed_result = data.detailed_result
152145
self.fact_sheet_answers = data.fact_sheet_answers
153146

154-
_.forEach(data.logs, (item) => {
155-
$.get(item.data_file)
156-
.done(function (content) {
157-
self.logs[item.name] = content
158-
self.rebuildLogTabs()
159-
self.update()
160-
setTimeout(() => {
161-
//$(self.root).find('.ui.top.attached.menu .item').tab()
162-
$('.ui.top.attached.menu .item').tab()
163-
}, 0)
164-
})
147+
const requests = data.logs.map(item =>
148+
$.get(item.data_file)
149+
.done(content => { self.logs[item.name] = content })
150+
.fail(() => { self.logs[item.name] = "" })
151+
)
152+
// When all log files are done loading:
153+
$.when.apply($, requests).always(() => {
154+
self.rebuild_log_tabs()
155+
self.update()
156+
setTimeout(() => {
157+
const $items = $(self.root).find('.ui.top.attached.menu .item')
158+
$items.tab()
159+
// pick the first tab deterministically
160+
if (self.logTabs.length) {
161+
$items.tab('change tab', self.logTabs[0].fullTabId)
162+
}
163+
}, 0)
165164
})
166-
self.rebuildLogTabs()
165+
self.rebuild_log_tabs()
167166
self.update()
168167
if (self.submission.admin) {
169168
_.forEach(data.leaderboards, (leaderboard) => {

0 commit comments

Comments
 (0)