11const DatabusConstants = require ( "../../utils/databus-constants" ) ;
22const DatabusUtils = require ( "../../utils/databus-utils" ) ;
3-
43// hinzufügen eines Controllers zum Modul
54function FileBrowserController ( $http , $scope ) {
65
@@ -10,7 +9,7 @@ function FileBrowserController($http, $scope) {
109 ctrl . activeTab = 0 ;
1110 ctrl . $scope = $scope ;
1211
13- ctrl . $onInit = function ( ) {
12+ ctrl . $onInit = function ( ) {
1413
1514 ctrl . lastRequestRevision = 0 ;
1615 ctrl . tableLimit = 20 ;
@@ -20,24 +19,56 @@ function FileBrowserController($http, $scope) {
2019 ctrl . queryResult = { } ;
2120 }
2221
23- ctrl . sortBy = function ( property ) {
22+ ctrl . loadPreview = async function ( binding ) {
23+ binding . preview = { state : 'loading' , value : null } ;
24+
25+ try {
26+ const params = new URLSearchParams ( {
27+ url : binding . file . value ,
28+ compression : binding . compression ?. value || ''
29+ } ) ;
30+
31+ const res = await fetch ( '/app/file/preview?' + params . toString ( ) , {
32+ credentials : 'same-origin'
33+ } ) ;
34+
35+ if ( ! res . ok ) throw new Error ( 'Network error' ) ;
36+
37+ const data = await res . json ( ) ;
38+ if ( data . preview != null ) {
39+ binding . preview . state = 'success' ;
40+ binding . preview . value = data . preview ;
41+ } else {
42+ binding . preview . state = 'error' ;
43+ binding . preview . value = 'Preview could not be loaded' ;
44+ }
45+
46+ } catch ( e ) {
47+ binding . preview . state = 'error' ;
48+ binding . preview . value = 'Preview could not be loaded' ;
49+ }
50+
51+ if ( ! ctrl . $scope . $root . $$phase ) ctrl . $scope . $apply ( ) ;
52+ } ;
53+
54+ ctrl . sortBy = function ( property ) {
2455
2556
26- if ( ctrl . sortProperty == property ) {
57+ if ( ctrl . sortProperty == property ) {
2758 ctrl . sortReverse = ! ctrl . sortReverse ;
2859 }
2960 ctrl . sortProperty = property ;
3061 }
3162
32- ctrl . getCellValues = function ( binding , column ) {
63+ ctrl . getCellValues = function ( binding , column ) {
3364
34- if ( binding [ column . field ] == undefined ) {
65+ if ( binding [ column . field ] == undefined ) {
3566 return "" ;
3667 }
37-
68+
3869 var value = binding [ column . field ] . value ;
3970
40- if ( column . uriToName ) {
71+ if ( column . uriToName ) {
4172 value = DatabusUtils . uriToName ( value ) ;
4273 }
4374
@@ -46,32 +77,32 @@ function FileBrowserController($http, $scope) {
4677
4778 }
4879
49- ctrl . formatUploadSize = function ( size ) {
80+ ctrl . formatUploadSize = function ( size ) {
5081 return DatabusUtils . formatFileSize ( size ) ;
5182 } ;
5283
53- ctrl . createRelativeUri = function ( url ) {
84+ ctrl . createRelativeUri = function ( url ) {
5485 var u = new URL ( url ) ;
5586 return u . pathname ;
5687 }
5788
58- ctrl . formatVariant = function ( value ) {
89+ ctrl . formatVariant = function ( value ) {
5990 var variants = value . split ( ', ' ) ;
6091 value = "" ;
61- for ( variant of variants ) {
62- if ( variant != undefined && variant != "" ) {
92+ for ( variant of variants ) {
93+ if ( variant != undefined && variant != "" ) {
6394 value += variant + ", " ;
6495 }
6596 }
6697
67- if ( value == "" ) {
98+ if ( value == "" ) {
6899 return "none" ;
69100 }
70101
71102 return value . substr ( 0 , value . length - 2 ) ;
72103 }
73104
74- ctrl . querySparql = async function ( query ) {
105+ ctrl . querySparql = async function ( query ) {
75106
76107 ctrl . isLoading = true ;
77108 ctrl . totalSize = 0 ;
@@ -84,11 +115,11 @@ function FileBrowserController($http, $scope) {
84115 url : DatabusConstants . DATABUS_SPARQL_ENDPOINT_URL ,
85116 data : "format=json&query=" + encodeURIComponent ( query ) ,
86117 headers : {
87- "Content-type" : "application/x-www-form-urlencoded"
118+ "Content-type" : "application/x-www-form-urlencoded"
88119 } ,
89120 }
90121
91- var updateResponse = await ctrl . $http ( req ) ;
122+ var updateResponse = await ctrl . $http ( req ) ;
92123
93124 var data = updateResponse . data ;
94125
@@ -99,29 +130,29 @@ function FileBrowserController($http, $scope) {
99130
100131 ctrl . queryResult . uriList = "" ;
101132
102- for ( var b in ctrl . queryResult . bindings ) {
133+ for ( var b in ctrl . queryResult . bindings ) {
103134 var binding = ctrl . queryResult . bindings [ b ] ;
104135 binding . size . numericalValue = parseInt ( binding . size . value ) ;
105136 ctrl . queryResult . uriList += binding . file . value + "\n" ;
106137
107- if ( binding . variant != undefined ) {
108- binding . variant . value = ctrl . formatVariant ( binding . variant . value ) ;
138+ if ( binding . variant != undefined ) {
139+ binding . variant . value = ctrl . formatVariant ( binding . variant . value ) ;
109140 }
110-
111-
141+
142+
112143
113144
114145 ctrl . totalSize += binding . size . numericalValue ;
115146 ctrl . numFiles ++ ;
116147 }
117148
118149 ctrl . totalSize = ctrl . formatUploadSize ( ctrl . totalSize ) ;
119-
120- if ( ! $scope . $root . $$phase ) {
150+
151+ if ( ! $scope . $root . $$phase ) {
121152 ctrl . $scope . $apply ( ) ;
122153 }
123154
124- } catch ( e ) {
155+ } catch ( e ) {
125156 console . log ( e ) ;
126157 }
127158 }
@@ -131,13 +162,22 @@ function FileBrowserController($http, $scope) {
131162 * using the query builders
132163 * @return {[type] } [description]
133164 */
134- ctrl . $doCheck = function ( ) {
165+ ctrl . $doCheck = function ( ) {
135166
136- if ( ctrl . query != ctrl . fileQuery ) {
167+ if ( ctrl . query != ctrl . fileQuery ) {
137168 ctrl . fileQuery = ctrl . query ;
138169 ctrl . querySparql ( ctrl . fullQuery ) ;
139170 }
140171 }
172+
173+ function decodeBz2 ( uint8array ) {
174+ try {
175+ const decompressed = decompress ( uint8array ) ;
176+ return new TextDecoder ( ) . decode ( decompressed ) ;
177+ } catch ( e ) {
178+ return null ;
179+ }
180+ }
141181}
142182
143183
0 commit comments