Skip to content

Commit 5e076a2

Browse files
authored
Merge pull request #2314 from codalab/bundle_management_refactoring
Refactoring - refactored bundle_management code
2 parents f3501a3 + e7a3260 commit 5e076a2

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

src/static/riot/competitions/bundle_management.tag

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<input type="text" placeholder="Search..." ref="search" onkeyup="{ filter.bind(this, undefined) }">
55
<i class="search icon"></i>
66
</div>
7-
<button class="ui red right floated labeled icon button {disabled: marked_datasets.length === 0}" onclick="{delete_datasets}">
7+
<button class="ui red right floated labeled icon button {disabled: marked_competition_bundles.length === 0}" onclick="{delete_competition_bundles}">
88
<i class="icon delete"></i>
99
Delete Selected
1010
</button>
1111

1212
<!-- Data Table -->
13-
<table id="bundlesTable" class="ui {selectable: datasets.length > 0} celled compact sortable table">
13+
<table id="bundlesTable" class="ui {selectable: competition_bundles.length > 0} celled compact sortable table">
1414
<thead>
1515
<tr>
1616
<th>File Name</th>
@@ -23,41 +23,41 @@
2323
</thead>
2424

2525
<tbody>
26-
<tr each="{ dataset, index in datasets }"
26+
<tr each="{ bundle, index in competition_bundles }"
2727
class="dataset-row"
28-
onclick="{show_info_modal.bind(this, dataset)}">
29-
<td>{ dataset.name }</td>
28+
onclick="{show_info_modal.bind(this, bundle)}">
29+
<td>{ bundle.name }</td>
3030
<td>
31-
<div if="{dataset.competition}" class="ui fitted">
32-
<a id="competitionLink" href="{URLS.COMPETITION_DETAIL(dataset.competition.id)}" target="_blank">{dataset.competition.title}</a>
31+
<div if="{bundle.competition}" class="ui fitted">
32+
<a id="competitionLink" href="{URLS.COMPETITION_DETAIL(bundle.competition.id)}" target="_blank">{bundle.competition.title}</a>
3333
</div>
3434
</td>
35-
<td>{ pretty_bytes(dataset.file_size) }</td>
36-
<td>{ timeSince(Date.parse(dataset.created_when)) } ago</td>
35+
<td>{ pretty_bytes(bundle.file_size) }</td>
36+
<td>{ timeSince(Date.parse(bundle.created_when)) } ago</td>
3737
<td class="center aligned">
38-
<button show="{dataset.created_by === CODALAB.state.user.username}" class="ui mini button red icon" onclick="{ delete_dataset.bind(this, dataset) }">
38+
<button show="{bundle.created_by === CODALAB.state.user.username}" class="ui mini button red icon" onclick="{ delete_competition_bundle.bind(this, bundle) }">
3939
<i class="icon delete"></i>
4040
</button>
4141
</td>
4242
<td class="center aligned">
43-
<div show="{dataset.created_by === CODALAB.state.user.username}" class="ui fitted checkbox">
44-
<input type="checkbox" name="delete_checkbox" onclick="{ mark_dataset_for_deletion.bind(this, dataset) }">
43+
<div show="{bundle.created_by === CODALAB.state.user.username}" class="ui fitted checkbox">
44+
<input type="checkbox" name="delete_checkbox" onclick="{ mark_competition_bundle_for_deletion.bind(this, bundle) }">
4545
<label></label>
4646
</div>
4747
</td>
4848
</tr>
49-
<tr if="{datasets.length === 0}">
49+
<tr if="{competition_bundles.length === 0}">
5050
<td class="center aligned" colspan="6">
51-
<em>No Datasets Yet!</em>
51+
<em>No Competition Bundles Yet!</em>
5252
</td>
5353
</tr>
5454
</tbody>
5555

5656
<tfoot>
5757
<!-- Pagination -->
5858
<tr>
59-
<th colspan="8" if="{datasets.length > 0}">
60-
<div class="ui right floated pagination menu" if="{datasets.length > 0}">
59+
<th colspan="8" if="{competition_bundles.length > 0}">
60+
<div class="ui right floated pagination menu" if="{competition_bundles.length > 0}">
6161
<a show="{!!_.get(pagination, 'previous')}" class="icon item" onclick="{previous_page}">
6262
<i class="left chevron icon"></i>
6363
</a>
@@ -125,16 +125,16 @@
125125
Init
126126
---------------------------------------------------------------------*/
127127

128-
self.datasets = []
129-
self.marked_datasets = []
128+
self.competition_bundles = []
129+
self.marked_competition_bundles = []
130130
self.selected_row = {}
131131
self.page = 1
132132

133133
self.one("mount", function () {
134134
$(".ui.dropdown", self.root).dropdown()
135135
$(".ui.checkbox", self.root).checkbox()
136136
$('#bundlesTable').tablesort()
137-
self.update_datasets()
137+
self.update_competition_bundles()
138138
})
139139

140140
/*---------------------------------------------------------------------
@@ -150,7 +150,7 @@
150150
page: 1,
151151
})
152152
self.page = filters.page
153-
self.update_datasets(filters)
153+
self.update_competition_bundles(filters)
154154
}
155155

156156
self.next_page = function () {
@@ -171,12 +171,12 @@
171171
}
172172
}
173173

174-
self.update_datasets = function (filters) {
174+
self.update_competition_bundles = function (filters) {
175175
filters = filters || {}
176176
filters._type = "bundle"
177177
CODALAB.api.get_datasets(filters)
178178
.done(function (data) {
179-
self.datasets = data.results
179+
self.competition_bundles = data.results
180180
self.pagination = {
181181
"count": data.count,
182182
"next": data.next,
@@ -185,16 +185,16 @@
185185
self.update()
186186
})
187187
.fail(function (response) {
188-
toastr.error("Could not load datasets...")
188+
toastr.error("Could not load competition bundles...")
189189
})
190190
}
191191

192-
self.delete_dataset = function (dataset, e) {
193-
if (confirm(`Are you sure you want to delete '${dataset.name}'?`)) {
194-
CODALAB.api.delete_dataset(dataset.id)
192+
self.delete_competition_bundle = function (bundle, e) {
193+
if (confirm(`Are you sure you want to delete '${bundle.name}'?`)) {
194+
CODALAB.api.delete_dataset(bundle.id)
195195
.done(function () {
196-
self.update_datasets()
197-
toastr.success("Dataset deleted successfully!")
196+
self.update_competition_bundles()
197+
toastr.success("Competition bundle deleted successfully!")
198198
CODALAB.events.trigger('reload_quota_cleanup')
199199
})
200200
.fail(function (response) {
@@ -204,13 +204,13 @@
204204
event.stopPropagation()
205205
}
206206

207-
self.delete_datasets = function () {
208-
if (confirm(`Are you sure you want to delete multiple datasets?`)) {
209-
CODALAB.api.delete_datasets(self.marked_datasets)
207+
self.delete_competition_bundles = function () {
208+
if (confirm(`Are you sure you want to delete multiple competition bundles?`)) {
209+
CODALAB.api.delete_datasets(self.marked_competition_bundles)
210210
.done(function () {
211-
self.update_datasets()
212-
toastr.success("Dataset deleted successfully!")
213-
self.marked_datasets = []
211+
self.update_competition_bundles()
212+
toastr.success("Competition bundles deleted successfully!")
213+
self.marked_competition_bundles = []
214214
CODALAB.events.trigger('reload_quota_cleanup')
215215
})
216216
.fail(function (response) {
@@ -222,12 +222,12 @@
222222
event.stopPropagation()
223223
}
224224

225-
self.mark_dataset_for_deletion = function(dataset, e) {
225+
self.mark_competition_bundle_for_deletion = function(bundle, e) {
226226
if (e.target.checked) {
227-
self.marked_datasets.push(dataset.id)
227+
self.marked_competition_bundles.push(bundle.id)
228228
}
229229
else {
230-
self.marked_datasets.splice(self.marked_datasets.indexOf(dataset.id), 1)
230+
self.marked_competition_bundles.splice(self.marked_competition_bundles.indexOf(bundle.id), 1)
231231
}
232232
}
233233

@@ -241,6 +241,9 @@
241241
$(self.refs.info_modal).modal('show')
242242
}
243243

244+
// Update bundles on unused bundles delete
245+
CODALAB.events.on('reload_competition_bundles', self.update_competition_bundles)
246+
244247

245248
</script>
246249

0 commit comments

Comments
 (0)