8
8
* Table of selectable sandbox uploaded layers
9
9
*/
10
10
angular . module ( 'sandbox-list-directive' , [ 'lists-service' , 'map-service' ] )
11
- . directive ( 'sandboxList' , [ '$http' , '$timeout' , 'SandboxService' , 'MapService' ,
12
- function ( $http , $timeout , SandboxService , MapService ) {
11
+ . directive ( 'sandboxList' , [ '$http' , '$timeout' , 'SandboxService' , 'MapService' , 'BiocacheService' ,
12
+ function ( $http , $timeout , SandboxService , MapService , BiocacheService ) {
13
13
14
14
var sortType = 'updated' ;
15
15
var sortReverse = false ;
61
61
MapService . add ( scope . selection ) ;
62
62
} ;
63
63
64
- SandboxService . list ( $SH . userId ) . then ( function ( data ) {
65
- scope . setItems ( data ) ;
66
- } ) ;
64
+ // add spatial-service sandbox uploads
65
+ if ( $SH . sandboxSpatialServiceUrl && $SH . sandboxSpatialServiceUrl !== '' ) {
66
+ BiocacheService . userUploads ( $SH . userId , $SH . sandboxSpatialServiceUrl ) . then ( function ( data ) {
67
+ if ( data . totalRecords === 0 ) {
68
+ return ;
69
+ }
70
+
71
+ // add bs and ws to each item
72
+ var items = data . facetResults [ 0 ] . fieldResult ;
73
+ items . forEach ( function ( item ) {
74
+ item . bs = $SH . sandboxSpatialServiceUrl ;
75
+ item . ws = $SH . sandboxSpatialUiUrl ;
76
+ // get dataset_name and last_load_date
77
+ BiocacheService . searchForOccurrences ( {
78
+ qid : item . fq , // skip qid registration for this one-off query
79
+ bs : item . bs ,
80
+ ws : item . ws
81
+ } , [ ] , 0 , 0 , 'datasetName,lastProcessedDate' ) . then ( function ( data ) {
82
+ if ( data . totalRecords > 0 ) {
83
+ // handle facets returning in a different order
84
+ var order = data . facetResults [ 0 ] . fieldName === 'datasetName' ? 0 : 1 ;
85
+ item . label = data . facetResults [ order === 0 ? 0 : 1 ] . fieldResult [ 0 ] . label ;
86
+ item . date = data . facetResults [ order === 0 ? 1 : 0 ] . fieldResult [ 0 ] . label ;
87
+
88
+ // format the date so that it is sortable. It is currently a string, e.g. "2010-11-01T00:00:00Z"
89
+ item . date = new Date ( item . date ) . toISOString ( ) . slice ( 0 , 10 ) ;
90
+
91
+ var a = item . fq . substring ( item . fq . indexOf ( ":" ) + 1 ) ;
92
+ scope . sandboxItems . push ( {
93
+ ws : item . ws ,
94
+ bs : item . bs ,
95
+ uid : item . fq . substring ( item . fq . indexOf ( ":" ) + 1 ) ,
96
+ name : item . label ,
97
+ lastUpdated : item . date ,
98
+ numberOfRecords : item . count ,
99
+ selected : false
100
+ } )
101
+ }
102
+ } ) ;
103
+ } ) ;
104
+ } ) ;
105
+ }
106
+
107
+ // add items from the deprecated sandbox
108
+ if ( $SH . sandboxServiceUrl && $SH . sandboxUrl ) {
109
+ SandboxService . list ( $SH . userId ) . then ( function ( data ) {
110
+ scope . setItems ( data ) ;
111
+ } ) ;
112
+ }
67
113
68
114
scope . $watch ( 'sandboxItems' , function ( ) {
69
115
} , true ) ;
116
162
117
163
118
164
} ] )
119
- } ( angular ) ) ;
165
+ } ( angular ) ) ;
0 commit comments