@@ -11,6 +11,7 @@ import {UploadFile, UploadResponse} from '../../../../bellows/shared/model/uploa
1111import { LexiconProjectService } from '../../core/lexicon-project.service' ;
1212import { Rights } from '../../core/lexicon-rights.service' ;
1313import { LexiconUtilityService } from '../../core/lexicon-utility.service' ;
14+ import { RecordingStateService } from '../recording-state.service' ;
1415
1516export class FieldAudioController implements angular . IController {
1617 dcFilename : string ;
@@ -21,18 +22,27 @@ export class FieldAudioController implements angular.IController {
2122 showAudioUpload : boolean = false ;
2223 showAudioRecorder : boolean = false ;
2324
25+ private uploading$ : angular . IDeferred < void > ;
26+
2427 static $inject = [ '$filter' , '$state' ,
2528 'Upload' , 'modalService' ,
2629 'silNoticeService' , 'sessionService' ,
27- 'lexProjectService' , '$scope'
30+ 'lexProjectService' , '$scope' , '$q' , 'recordingStateService'
2831 ] ;
29- constructor ( private $filter : angular . IFilterService , private $state : angular . ui . IStateService ,
30- private Upload : any , private modalService : ModalService ,
31- private notice : NoticeService , private sessionService : SessionService ,
32- private lexProjectService : LexiconProjectService , private $scope : angular . IScope ) {
33-
34- this . $scope . $watch ( ( ) => this . dcFilename , ( ) => this . showAudioRecorder = false ) ;
35- }
32+ constructor (
33+ private $filter : angular . IFilterService ,
34+ private $state : angular . ui . IStateService ,
35+ private Upload : angular . angularFileUpload . IUploadService ,
36+ private modalService : ModalService ,
37+ private notice : NoticeService ,
38+ private sessionService : SessionService ,
39+ private lexProjectService : LexiconProjectService ,
40+ private $scope : angular . IScope ,
41+ private $q : angular . IQService ,
42+ private recordingStateService : RecordingStateService ,
43+ ) {
44+ this . $scope . $watch ( ( ) => this . dcFilename , ( ) => this . showAudioRecorder = false ) ;
45+ }
3646
3747 hasAudio ( ) : boolean {
3848 if ( this . dcFilename == null ) {
@@ -101,14 +111,17 @@ export class FieldAudioController implements angular.IController {
101111 }
102112
103113 this . notice . setLoading ( 'Uploading ' + file . name + '...' ) ;
104- this . Upload . upload ( {
114+ this . uploading$ = this . $q . defer < void > ( ) ;
115+ this . recordingStateService . startUploading ( this . uploading$ . promise ) ;
116+ return this . Upload . upload < any > ( {
117+ method : 'POST' ,
105118 url : '/upload/audio' ,
106119 data : {
107120 file,
108121 previousFilename : this . dcFilename ,
109122 recordedInBrowser : recordedInBrowser
110123 }
111- } ) . then ( ( response : UploadResponse ) => {
124+ } ) . then ( ( response ) => {
112125 this . notice . cancelLoading ( ) ;
113126 const isUploadSuccess = response . data . result ;
114127 if ( isUploadSuccess ) {
@@ -143,7 +156,7 @@ export class FieldAudioController implements angular.IController {
143156
144157 ( evt : ProgressEvent ) => {
145158 this . notice . setPercentComplete ( Math . floor ( 100.0 * evt . loaded / evt . total ) ) ;
146- } ) ;
159+ } ) . finally ( ( ) => this . uploading$ . resolve ( ) ) ;
147160 } ) ;
148161 }
149162
@@ -170,6 +183,9 @@ export class FieldAudioController implements angular.IController {
170183 return filename . substr ( filename . indexOf ( '_' ) + 1 ) ;
171184 }
172185
186+ $onDestroy ( ) {
187+ this . uploading$ ?. resolve ( ) ;
188+ }
173189}
174190
175191export const FieldAudioComponent : angular . IComponentOptions = {
0 commit comments