Skip to content

Commit cda0fe4

Browse files
committed
Merge branch 'edge'
2 parents 85c297c + ace4a50 commit cda0fe4

File tree

3 files changed

+145
-7
lines changed

3 files changed

+145
-7
lines changed

datastore/apps/sra/static/sra/js/app.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,67 @@ if (!Array.prototype.map) {
7171
};
7272
}
7373

74+
if (!Array.prototype.indexOf) {
75+
Array.prototype.indexOf = function(searchElement, fromIndex) {
76+
var k;
77+
// 1. Let O be the result of calling ToObject passing
78+
// the this value as the argument.
79+
if (null === this || undefined === this) {
80+
throw new TypeError('"this" is null or not defined');
81+
}
82+
var O = Object(this);
83+
// 2. Let lenValue be the result of calling the Get
84+
// internal method of O with the argument "length".
85+
// 3. Let len be ToUint32(lenValue).
86+
var len = O.length >>> 0;
87+
// 4. If len is 0, return -1.
88+
if (len === 0) {
89+
return -1;
90+
}
91+
// 5. If argument fromIndex was passed let n be
92+
// ToInteger(fromIndex); else let n be 0.
93+
var n = +fromIndex || 0;
94+
if (Math.abs(n) === Infinity) {
95+
n = 0;
96+
}
97+
// 6. If n >= len, return -1.
98+
if (n >= len) {
99+
return -1;
100+
}
101+
// 7. If n >= 0, then Let k be n.
102+
// 8. Else, n<0, Let k be len - abs(n).
103+
// If k is less than 0, then let k be 0.
104+
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
105+
// 9. Repeat, while k < len
106+
while (k < len) {
107+
// a. Let Pk be ToString(k).
108+
// This is implicit for LHS operands of the in operator
109+
// b. Let kPresent be the result of calling the
110+
// HasProperty internal method of O with argument Pk.
111+
// This step can be combined with c
112+
// c. If kPresent is true, then
113+
// i. Let elementK be the result of calling the Get
114+
// internal method of O with the argument ToString(k).
115+
// ii. Let same be the result of applying the
116+
// Strict Equality Comparison Algorithm to
117+
// searchElement and elementK.
118+
// iii. If same is true, return k.
119+
if (k in O && O[k] === searchElement) {
120+
return k;
121+
}
122+
k++;
123+
}
124+
return -1;
125+
};
126+
}
127+
128+
if (!String.prototype.startsWith) {
129+
String.prototype.startsWith = function(searchString, position){
130+
position = position || 0;
131+
return this.substr(position, searchString.length) === searchString;
132+
};
133+
}
134+
74135
(function(window, angular, $) {
75136
"use strict";
76137

@@ -97,4 +158,4 @@ if (!Array.prototype.map) {
97158
'COMMUNITY': '/iplant/home/shared'
98159
});
99160

100-
})(window, angular);
161+
})(window, angular);

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

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
});
6161
};
6262

63-
service.getItemMetadata = function(itemId, download=false) {
64-
return $http.get(djangoUrl.reverse('api_metadata', {'item_id': itemId}), {'download': download})
63+
service.getItemMetadata = function(itemId) {
64+
return $http.get(djangoUrl.reverse('api_metadata', {'item_id': itemId}))
6565
.then(
6666
function (resp) {
6767
return resp.data;
@@ -140,7 +140,7 @@
140140
curated: DcrPaths.CURATED
141141
}
142142

143-
$scope.sortType = 'label'; // set the default sort type
143+
$scope.sortType = 'label'; // set the default sort type
144144
$scope.sortDir = 'ASC'; // set the default sort order
145145

146146
$scope.browse = function($event, item, page) {
@@ -175,12 +175,16 @@
175175
$scope.model.display.hasMetadata = true
176176

177177
if ($scope.model.metadata.Rights.value === 'ODC PDDL') {
178+
$scope.model.display.rightsUrl = 'http://www.opendatacommons.org/licenses/pddl/1.0/'
178179
$scope.model.display.Rights = 'This data is made available under the Public Domain Dedication and License v1.0 whose full text can be found at <a href="http://www.opendatacommons.org/licenses/pddl/1.0/"> http://www.opendatacommons.org/licenses/pddl/1.0/ </a>';
179180
} else if ($scope.model.metadata.Rights.value === 'CC0') {
181+
$scope.model.display.rightsUrl = 'https://creativecommons.org/share-your-work/public-domain/cc0/'
180182
$scope.model.display.Rights = '<a rel="license" href="https://creativecommons.org/share-your-work/public-domain/cc0/"><img alt="Creative Commons License Badge" style="border-width:0" src="' + window.location.origin + '/static/img/CC0.png"/></a><br />This work is available in the public domain under the <a rel="license" href="https://creativecommons.org/share-your-work/public-domain/cc0/">Creative Commons CC0 agreement</a>.';
181183
} else if ($scope.model.metadata.Rights.value === 'CC-BY') {
184+
$scope.model.display.rightsUrl = 'http://creativecommons.org/licenses/by/4.0/'
182185
$scope.model.display.Rights = '<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License Badge" style="border-width:0" src="' + window.location.origin + '/static/img/CCBY.png"/></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.';
183186
} else {
187+
$scope.model.display.rightsUrl = $scope.model.metadata.Rights.value
184188
$scope.model.display.Rights = $scope.model.metadata.Rights.value
185189
}
186190

@@ -201,6 +205,75 @@
201205
$scope.model.display.alreadyDisplayed.push('Publisher', 'Publication Year', 'DOI')
202206
}
203207

208+
/* 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+
}
220+
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+
}
232+
var data = {
233+
"@context": "http://schema.org",
234+
"@type": "Dataset",
235+
"sameAs": window.location.href,
236+
"includedInDataCatalog": "http://datacommons.cyverse.org/",
237+
};
238+
239+
var assignTo = $scope.maybeAssign(data);
240+
241+
assignTo('url', function() {
242+
return ($scope.getValue($scope.model.metadata, ['Identifier', 'value']))
243+
? 'https://doi.org/' + $scope.model.metadata.Identifier.value
244+
: null
245+
})
246+
assignTo('name', $scope.getValue($scope.model.metadata, ['Title', 'value']))
247+
assignTo('description', $scope.getValue($scope.model.metadata, ['Description', 'value']))
248+
assignTo('keywords', $scope.getValue($scope.model.metadata, ['Subject', 'value']))
249+
assignTo('license', $scope.getValue($scope.model.display, ['rightsUrl']))
250+
assignTo('identifier', function() {
251+
return ($scope.getValue($scope.model.metadata, ['Identifier', 'value']))
252+
? 'DOI: ' + $scope.model.metadata.Identifier.value
253+
: null
254+
})
255+
assignTo('citation', $scope.getValue($scope.model.display, ['readableCitation']))
256+
assignTo('creator', function() {
257+
return ($scope.getValue($scope.model.metadata, ['Creator', 'value']))
258+
? {
259+
"type": "Person",
260+
"name": $scope.model.metadata.Creator.value
261+
}
262+
: null
263+
})
264+
assignTo('datePublished', $scope.getValue($scope.model.metadata, ['Publication Year', 'value']))
265+
assignTo('publisher', function() {
266+
return ($scope.getValue($scope.model.metadata, ['Publisher', 'value']))
267+
? {
268+
"type": "Organization",
269+
"name": $scope.model.metadata.Publisher.value
270+
}
271+
: null
272+
})
273+
assignTo('contributor', $scope.getValue($scope.model.metadata, ['Contributor', 'value']))
274+
275+
angular.element(document.querySelector('#schemaTags')).html(JSON.stringify(data))
276+
204277

205278
}
206279
})
@@ -210,7 +283,7 @@
210283
$scope.model.collection = null;
211284
$scope.model.pagination.show = false;
212285
if (item.type === 'dir') {
213-
promises.push($scope.getContents(item.path, page));
286+
promises.push($scope.getContents(item.path, page, $scope.sortType, $scope.sortDir));
214287
}
215288

216289
/* reset preview */
@@ -234,7 +307,7 @@
234307
});
235308
};
236309

237-
$scope.getContents = function(path, page, sortType='label', sortDir='ASC') {
310+
$scope.getContents = function(path, page, sortType, sortDir) {
238311
return DcrFileService.getListItem(path, page, sortType, sortDir).then(
239312
function(results) {
240313
$scope.model.collection = results;

datastore/apps/sra/static/sra/templates/main.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ <h2 ng-if="model.item.label=='Community Data' || model.item.label=='curated'">
3232
</tr>
3333
</table>
3434
</script>
35-
</div>
35+
</div>
36+
37+
38+
<script type="application/ld+json" id="schemaTags">
39+
</script>

0 commit comments

Comments
 (0)