66*
77***************************************************************************************************/
88
9- var ImportFormCtrl = function ( $scope , $http , ConfigurationService , flash , AccountService , GraphService , Ns , Upload , ImportRdfService , ServerErrorResponse , Helpers ) {
9+ var ImportFormCtrl = function ( $scope , $http , $q , $timeout , ConfigurationService , flash , AccountService , GraphService , Ns , Upload , ImportRdfService , ServerErrorResponse , Helpers ) {
1010
1111 var currentAccount = AccountService . getAccount ( ) ;
1212
@@ -79,7 +79,7 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
7979 if ( $scope . sourceType . value == 'file' ) {
8080 $scope . newTarget = {
8181 prefix : "RdfImport" ,
82- label : $scope . importRdf . source ,
82+ label : "Import form " + $scope . importRdf . source . length + " files" ,
8383 description : "Import from file " + $scope . importRdf . source ,
8484 } ;
8585 }
@@ -138,29 +138,57 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
138138
139139 /**
140140 For File Import
141- **/
142- $scope . $watch ( 'importFile.files' , function ( ) {
143- if ( $scope . importFile != undefined )
144- $scope . upload ( $scope . importFile . files ) ;
145- } ) ;
146-
147- $scope . upload = function ( files ) {
148- if ( files && files . length ) {
149- for ( var i = 0 ; i < files . length ; i ++ ) {
150- var file = files [ i ] ;
151- Upload . upload ( {
152- url : 'UploadServlet' ,
153- file : file
154- } ) . progress ( function ( evt ) {
155- var progressPercentage = parseInt ( 100.0 * evt . loaded / evt . total ) ;
156- flash . success = 'progress: ' + parseInt ( 100.0 * evt . loaded / evt . total ) + '% file :' + evt . config . file . name ;
157- } ) . success ( function ( data , status , headers , config ) {
158- $scope . importRdf . source = config . file . name ;
159- $scope . updateNewTargetInfo ( ) ;
141+ **/
142+ $scope . uploadSuceed = function ( ) {
143+
144+ return ( $scope . sourceType . value == 'file' && $scope . importRdf . source != null )
145+ }
146+
147+ $scope . uploadFiles = function ( files , errFiles ) {
148+
149+ $scope . errFiles = errFiles ;
150+ var promises = [ ] ;
151+
152+ angular . forEach ( files , function ( file ) {
153+
154+ var deferred = $q . defer ( ) ;
155+ file . upload = Upload . upload ( {
156+ url : 'UploadServlet' ,
157+ data : { file : file }
160158 } ) ;
161- }
162- }
163- } ;
159+
160+ file . upload . then ( function ( response ) {
161+ $timeout ( function ( ) {
162+ deferred . resolve ( file . name ) ;
163+ } ) ;
164+ } , function ( response ) {
165+ if ( response . status > 0 )
166+ flash . error = response . status + ': ' + response . data ;
167+ } , function ( evt ) {
168+ var progressPercentage = parseInt ( 100.0 * evt . loaded / evt . total ) ;
169+ flash . success = 'progress: ' + parseInt ( 100.0 * evt . loaded / evt . total ) + '% file :' + file . name ;
170+ // file.progress = Math.min(100, parseInt(100.0 *
171+ // evt.loaded / evt.total));
172+ } ) ;
173+
174+ promises . push ( deferred . promise ) ;
175+ } ) ; // foreach
176+
177+ $q . all ( promises ) . then (
178+ // results: an array of data objects from each deferred.resolve(data) call
179+ function ( results ) {
180+ flash . success = 'Uploaded: ' + results ;
181+ $scope . importRdf . source = results ;
182+ $scope . updateNewTargetInfo ( ) ;
183+ } ,
184+ // error
185+ function ( response ) {
186+ console . log ( response ) ;
187+ }
188+ ) ;
189+ }
190+
191+
164192
165193 $scope . isImporting = function ( ) {
166194 return importing ;
@@ -197,8 +225,6 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
197225 //success
198226 function ( response ) {
199227
200- console . log ( response ) ;
201-
202228 var imported = response . data . import ;
203229
204230 var meta = {
@@ -210,7 +236,6 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
210236 // update the metadata of the graph
211237 GraphService . addContribution ( meta ) . then (
212238 function ( response ) {
213- console . log ( response ) ;
214239 flash . success = "successfully imported " + imported . triples + " triples" ;
215240 $scope . resetValues ( ) ;
216241 } ,
@@ -232,7 +257,6 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
232257
233258 initialise ( ) ;
234259
235- $scope . importFile . files = null ;
236260 $scope . urlForm . $setPristine ( ) ;
237261 $scope . fileForm . $setPristine ( ) ;
238262 $scope . endpointForm . $setPristine ( ) ;
0 commit comments