Skip to content

Commit 69571ee

Browse files
committed
Merge branch 'edge'
2 parents d637b6a + 2ee7a25 commit 69571ee

File tree

9 files changed

+166
-25
lines changed

9 files changed

+166
-25
lines changed

datastore/apps/sra/dictionary.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
'datacite.publisher': 'Publisher',
1111
'datacite.resourcetype': 'Resource Type General',
1212
'datacite.title': 'Title',
13+
'creator': 'Creator',
14+
'publicationyear': 'Publication Year',
15+
'publisher': 'Publisher',
16+
'resourcetype': 'Resource Type General',
17+
'title': 'Title',
1318
'Description': 'Description',
1419
'Format': 'Format',
1520
'fundingReference': 'Funding Reference',

datastore/apps/sra/static/sra/js/landingpage.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,32 @@
166166
$scope.model.display = null;
167167
promises.push(
168168
DcrFileService.getItemMetadata(item.id).then(function (result) {
169+
$scope.getValue = function(obj, keypath) {
170+
var current = obj;
171+
while (keypath.length) {
172+
const nextPath = keypath.shift();
173+
if (!current.hasOwnProperty(nextPath)) {
174+
return undefined;
175+
}
176+
current = current[nextPath];
177+
}
178+
return current;
179+
}
180+
181+
$scope.maybeAssign = function(obj) {
182+
var objectToAssignTo = obj;
183+
return function (key, getVal) {
184+
var val = (typeof getVal === 'function')
185+
? getVal()
186+
: getVal;
187+
if (val == null) return objectToAssignTo;
188+
objectToAssignTo[key] = val;
189+
return objectToAssignTo;
190+
}
191+
}
169192
$scope.model.metadata = result.metadata
170193
$scope.model.display = {'sortedMetadata': result.sorted_meta}
171-
$scope.model.display['curatedOrCommunity'] = ($scope.model.item.path.startsWith(DcrPaths.CURATED)) ? 'curated' : 'community';
194+
$scope.model.display['curatedOrCommunity'] = $scope.getValue($scope.model.metadata, ['Identifier', 'value']) ? 'curated' : 'community';
172195

173196
if (Object.keys($scope.model.metadata).length) {
174197
$scope.model.display.showMoreButton = 'show more'
@@ -206,29 +229,7 @@
206229
}
207230

208231
/* create schema.org tags */
209-
$scope.getValue = function(obj, keypath) {
210-
var current = obj;
211-
while (keypath.length) {
212-
const nextPath = keypath.shift();
213-
if (!current.hasOwnProperty(nextPath)) {
214-
return undefined;
215-
}
216-
current = current[nextPath];
217-
}
218-
return current;
219-
}
220232

221-
$scope.maybeAssign = function(obj) {
222-
var objectToAssignTo = obj;
223-
return function (key, getVal) {
224-
var val = (typeof getVal === 'function')
225-
? getVal()
226-
: getVal;
227-
if (val == null) return objectToAssignTo;
228-
objectToAssignTo[key] = val;
229-
return objectToAssignTo;
230-
}
231-
}
232233
var data = {
233234
"@context": "http://schema.org",
234235
"@type": "Dataset",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{% extends 'base.html' %}
2+
{% load staticfiles %}
3+
{% load filters %}
4+
5+
{% block content %}
6+
<h2>Search results matching: {{search_term}}</h2>
7+
<table class="table table-bordered table-striped">
8+
<thead>
9+
<tr>
10+
<th>
11+
<a>
12+
Name
13+
</a>
14+
</th>
15+
<th>
16+
<a>
17+
Size
18+
</a>
19+
</th>
20+
<th>
21+
<a>
22+
Created
23+
</a>
24+
</th>
25+
<th>
26+
<a>
27+
Last Modified
28+
</a>
29+
</th>
30+
</tr>
31+
</thead>
32+
33+
{% for item in matches %}
34+
<tr>
35+
<td>
36+
<a href="{% url 'browse' path=item.path %}">
37+
{% if item.type == 'folder' %} <i class="fa fa-folder"></i> {% else %} <i class="fa fa-file-o"></i> {% endif %} {{ item.label }}
38+
</a>
39+
</td>
40+
<td> {% if item.type == 'file' %} {{item.filesize|bytes}} {% else %} -- {% endif %} </td>
41+
<td>{{item.dateModified|date:"M j, Y g:i:s A"}}</td>
42+
<td>{{ item.dateModified|date:"M j, Y g:i:s A"}}</td>
43+
</tr>
44+
{% endfor %}
45+
</table>
46+
47+
{% endblock %}

datastore/apps/sra/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django import template
2+
import math
3+
4+
register = template.Library()
5+
6+
@register.filter
7+
def bytes(bytes):
8+
units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB']
9+
if bytes == 0:
10+
number = 0
11+
else:
12+
number = int(math.floor(math.log(bytes) / math.log(1024)))
13+
bytes_string = format(bytes / math.pow(1024, math.floor(number)), '.1f')
14+
return (bytes_string + ' ' + units[number])

datastore/apps/sra/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
# view urls
77
url(r'^$', 'home', name='home'),
8-
url(r'^browse/(?P<path>.*)/?$', 'landing_page'),
8+
url(r'^browse/(?P<path>.*)/?$', 'landing_page', name='browse'),
99
url(r'^download/(?P<path>.*)$', 'download_file_anon', name='download'),
10+
url(r'^search/?$', 'search', name='search'),
1011

1112
# api urls
1213
url(r'^api/stat/(?P<path>.*)/?$', 'api_stat', name='api_stat'),

datastore/apps/sra/views.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy
2+
import datetime
23
import json
34
import logging
45
import time
@@ -209,3 +210,62 @@ def download_file_anon(request, path):
209210
logger.exception('Failed to preview file', extra={'path': path})
210211
return HttpResponseBadRequest('Failed to preview file',
211212
content_type='application/json')
213+
214+
215+
def search(request):
216+
search_term = request.GET.get('search_term')
217+
query={
218+
"all": [
219+
{"type": "path",
220+
"args": {"prefix": "/iplant/home/shared"}
221+
}
222+
],
223+
"any": [
224+
{"type": "label",
225+
"args": {"exact": False, "label": search_term}
226+
},
227+
{"type": "metadata",
228+
"args": {"value": search_term}
229+
}
230+
]
231+
}
232+
233+
tc = TerrainClient('anonymous', 'anonymous@cyverse.org')
234+
list_resp = tc.search(query)
235+
files=[]
236+
folders=[]
237+
matches=[]
238+
239+
for item in list_resp['hits']:
240+
if item['_type'] == 'file':
241+
files.append({
242+
'path': item['_source']['path'].lstrip('/'),
243+
'label': item['_source']['label'],
244+
'filesize': item['_source']['fileSize'],
245+
'dateCreated': datetime.datetime.fromtimestamp(item['_source']['dateCreated']/1000.0),
246+
'dateModified': datetime.datetime.fromtimestamp(item['_source']['dateModified']/1000.0),
247+
})
248+
matches.append({
249+
'path': item['_source']['path'].lstrip('/'),
250+
'label': item['_source']['label'],
251+
'filesize': item['_source']['fileSize'],
252+
'dateCreated': datetime.datetime.fromtimestamp(item['_source']['dateCreated']/1000.0),
253+
'dateModified': datetime.datetime.fromtimestamp(item['_source']['dateModified']/1000.0),
254+
'type': item['_type']
255+
})
256+
257+
elif item['_type'] == 'folder':
258+
folders.append({
259+
'path': item['_source']['path'].lstrip('/'),
260+
'label': item['_source']['label'],
261+
'dateCreated': datetime.datetime.fromtimestamp(item['_source']['dateCreated']/1000.0),
262+
'dateModified': datetime.datetime.fromtimestamp(item['_source']['dateModified']/1000.0),
263+
})
264+
matches.append({
265+
'path': item['_source']['path'].lstrip('/'),
266+
'label': item['_source']['label'],
267+
'dateCreated': datetime.datetime.fromtimestamp(item['_source']['dateCreated']/1000.0),
268+
'dateModified': datetime.datetime.fromtimestamp(item['_source']['dateModified']/1000.0),
269+
'type': item['_type']
270+
})
271+
return render(request, 'sra/search.html',{'folders':folders, 'files':files, 'matches':matches, 'search_term':search_term})

datastore/libs/terrain/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,10 @@ def get_contents(self, path, **kwargs):
8787
def download(self, params):
8888
url = '{0}/terrain/secured/fileio/download'.format(settings.TERRAIN_API_HOST)
8989
return self.send_request('GET', url=url, params=params, stream=True)
90+
91+
def search(self, query):
92+
url = '{0}/terrain/secured/filesystem/search'.format(
93+
settings.TERRAIN_API_HOST)
94+
payload = {'query': query,
95+
'user': 'anonymous'}
96+
return self.send_request('POST', url, data=payload).json()

datastore/templates/includes/header.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ <h1 class="page-logo-title">Data Commons</h1>
2020
<li><a href="http://www.cyverse.org/data-store">Data Store</a></li>
2121
<li><a href="http://www.cyverse.org/discovery-environment">Discovery Environment</a></li>
2222
<li><a href="http://www.cyverse.org/atmosphere">Atmosphere</a></li>
23+
<form class="navbar-form navbar-left" action="/search/">
24+
<div class="form-group">
25+
<input type="text" class="form-control" placeholder="Search" name="search_term">
26+
</div>
27+
<button type="submit" class="btn btn-default">Submit</button>
28+
</form>
2329
<li>
2430
<a href="http://www.cyverse.org" target="_self">
2531
<img id="cyverse-icon" src="{% static 'img/cyverse_icon_white.png' %}" alt="CyVerse Data Commons">
@@ -29,4 +35,4 @@ <h1 class="page-logo-title">Data Commons</h1>
2935
</div>
3036
</div>
3137
</nav>
32-
</header>
38+
</header>

0 commit comments

Comments
 (0)