Skip to content
Merged
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
43 changes: 40 additions & 3 deletions src/apps/api/views/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,51 @@
class DataViewSet(ModelViewSet):
queryset = Data.objects.all()
filter_backends = (DjangoFilterBackend, SearchFilter)
filter_fields = ('type', 'name', 'key', 'was_created_by_competition')
filter_fields = ('type', 'name', 'key', 'was_created_by_competition', 'is_public')
search_fields = ('name', 'description', 'key',)
pagination_class = BasicPagination

def get_queryset(self):
filters = Q(is_public=True) | Q(created_by=self.request.user)

qs = Data.objects.filter(filters)
if self.request.method == 'GET':

# new filters
# -----------

# _public = true if want to show public datasets/submissions
is_public = self.request.query_params.get('_public', 'false') == 'true'

# _type = submission if called from submissions tab to filter only submissions
is_submission = self.request.query_params.get('_type', '') == 'submission'

# _type = dataset if called from datasets and programs tab to filter datasets and programs
is_dataset = self.request.query_params.get('_type', '') == 'dataset'

# get queryset
qs = self.queryset

# filter submissions
if is_submission:
qs = qs.filter(Q(type=Data.SUBMISSION))

# filter datasets and programs
if is_dataset:
qs = qs.filter(~Q(type=Data.SUBMISSION))

# public filter check
if is_public:
qs = qs.filter(Q(created_by=self.request.user) | Q(is_public=True))
else:
qs = qs.filter(Q(created_by=self.request.user))

# if GET is called but provided no filters, fall back to default behaviour
if (not is_submission) and (not is_dataset) and (not is_public):
qs = self.queryset
qs = qs.filter(Q(is_public=True) | Q(created_by=self.request.user))

else:
qs = self.queryset
qs = qs.filter(Q(is_public=True) | Q(created_by=self.request.user))

qs = qs.exclude(Q(type=Data.COMPETITION_BUNDLE) | Q(name__isnull=True))

Expand Down
28 changes: 10 additions & 18 deletions src/static/riot/datasets/management.tag
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
<label>Show Auto Created</label>
<input type="checkbox" ref="auto_created">
</div>
<div class="ui checkbox inline-div" onclick="{ filter.bind(this, undefined) }">
<label>Show Public</label>
<input type="checkbox" ref="show_public">
</div>
<button class="ui green right floated labeled icon button" onclick="{show_creation_modal}">
<i selenium="add-dataset" class="plus icon"></i>
Add Dataset/Program
</button>
<button class="ui red right floated labeled icon button {disabled: marked_datasets.length === 0}" onclick="{delete_datasets}">
<i class="icon delete"></i>
Delete Selected Datasets
Delete Selected
</button>

<!-- Data Table -->
Expand Down Expand Up @@ -52,12 +56,12 @@
<i class="checkmark box icon green" show="{ dataset.is_public }"></i>
</td>
<td class="center aligned">
<button class="ui mini button red icon" onclick="{ delete_dataset.bind(this, dataset) }">
<button show="{dataset.created_by === CODALAB.state.user.username}" class="ui mini button red icon" onclick="{ delete_dataset.bind(this, dataset) }">
<i class="icon delete"></i>
</button>
</td>
<td class="center aligned">
<div class="ui fitted checkbox">
<div show="{dataset.created_by === CODALAB.state.user.username}" class="ui fitted checkbox">
<input type="checkbox" name="delete_checkbox" onclick="{ mark_dataset_for_deletion.bind(this, dataset) }">
<label></label>
</div>
Expand Down Expand Up @@ -276,14 +280,12 @@

self.update_datasets = function (filters) {
filters = filters || {}
let show_datasets_created_by_comp = $(self.refs.auto_created).prop('checked')
if (!show_datasets_created_by_comp) {
filters.was_created_by_competition = false
}
filters.was_created_by_competition = $(self.refs.auto_created).prop('checked')
filters._public = $(self.refs.show_public).prop('checked')
filters._type = "dataset"
CODALAB.api.get_datasets(filters)
.done(function (data) {
self.datasets = data.results
self.datasets = self.filter_out_submissions(self.datasets)
self.pagination = {
"count": data.count,
"next": data.next,
Expand Down Expand Up @@ -442,16 +444,6 @@
}
}

// Function to remove submissions from datasets
self.filter_out_submissions = function(datasets) {
datasets_to_return = []
datasets.forEach(dataset => {
if (dataset.type != "submission"){
datasets_to_return.push(dataset)
}
})
return datasets_to_return
}

// Function to format file size
self.format_file_size = function(file_size) {
Expand Down
13 changes: 8 additions & 5 deletions src/static/riot/submissions/resource_submissions.tag
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<input type="text" placeholder="Search..." ref="search" onkeyup="{ filter.bind(this, undefined) }">
<i class="search icon"></i>
</div>
<div class="ui checkbox inline-div" onclick="{ filter.bind(this, undefined) }">
<label>Show Public</label>
<input type="checkbox" ref="show_public">
</div>
<button class="ui green right floated labeled icon button" onclick="{show_creation_modal}">
<i class="plus icon"></i>
Add Submission
Expand Down Expand Up @@ -43,12 +47,12 @@
<i class="checkmark box icon green" show="{ submission.is_public }"></i>
</td>
<td class="center aligned">
<button class="ui mini button red icon" onclick="{ delete_submission.bind(this, submission) }">
<button show="{submission.created_by === CODALAB.state.user.username}" class="ui mini button red icon" onclick="{ delete_submission.bind(this, submission) }">
<i class="icon delete"></i>
</button>
</td>
<td class="center aligned">
<div class="ui fitted checkbox">
<div show="{submission.created_by === CODALAB.state.user.username}" class="ui fitted checkbox">
<input type="checkbox" name="delete_checkbox" onclick="{ mark_submission_for_deletion.bind(this, submission) }">
<label></label>
</div>
Expand Down Expand Up @@ -220,10 +224,8 @@
self.pretty_date = date => luxon.DateTime.fromISO(date).toLocaleString(luxon.DateTime.DATE_FULL)

self.filter = function (filters) {
let type = $(self.refs.type_filter).val()
filters = filters || {}
_.defaults(filters, {
type: type === '-' ? '' : type,
search: $(self.refs.search).val(),
page: 1,
})
Expand All @@ -250,7 +252,8 @@

self.update_submissions = function (filters) {
filters = filters || {}
filters.type = "submission"
filters._public = $(self.refs.show_public).prop('checked')
filters._type = "submission"
CODALAB.api.get_datasets(filters)
.done(function (data) {
self.submissions = data.results
Expand Down