@@ -68,6 +68,105 @@ export enum AnnotationActionTypes {
68
68
CHANGE_JOB_STATUS = 'CHANGE_JOB_STATUS' ,
69
69
CHANGE_JOB_STATUS_SUCCESS = 'CHANGE_JOB_STATUS_SUCCESS' ,
70
70
CHANGE_JOB_STATUS_FAILED = 'CHANGE_JOB_STATUS_FAILED' ,
71
+ UPLOAD_JOB_ANNOTATIONS = 'UPLOAD_JOB_ANNOTATIONS' ,
72
+ UPLOAD_JOB_ANNOTATIONS_SUCCESS = 'UPLOAD_JOB_ANNOTATIONS_SUCCESS' ,
73
+ UPLOAD_JOB_ANNOTATIONS_FAILED = 'UPLOAD_JOB_ANNOTATIONS_FAILED' ,
74
+ REMOVE_JOB_ANNOTATIONS_SUCCESS = 'REMOVE_JOB_ANNOTATIONS_SUCCESS' ,
75
+ REMOVE_JOB_ANNOTATIONS_FAILED = 'REMOVE_JOB_ANNOTATIONS_FAILED' ,
76
+ UPDATE_CANVAS_CONTEXT_MENU = 'UPDATE_CANVAS_CONTEXT_MENU' ,
77
+ }
78
+
79
+ export function updateCanvasContextMenu ( visible : boolean , left : number , top : number ) : AnyAction {
80
+ return {
81
+ type : AnnotationActionTypes . UPDATE_CANVAS_CONTEXT_MENU ,
82
+ payload : {
83
+ visible,
84
+ left,
85
+ top,
86
+ } ,
87
+ } ;
88
+ }
89
+
90
+ export function removeAnnotationsAsync ( sessionInstance : any ) :
91
+ ThunkAction < Promise < void > , { } , { } , AnyAction > {
92
+ return async ( dispatch : ActionCreator < Dispatch > ) : Promise < void > => {
93
+ try {
94
+ sessionInstance . annotations . clear ( ) ;
95
+ dispatch ( {
96
+ type : AnnotationActionTypes . REMOVE_JOB_ANNOTATIONS_SUCCESS ,
97
+ payload : {
98
+ sessionInstance,
99
+ } ,
100
+ } ) ;
101
+ } catch ( error ) {
102
+ dispatch ( {
103
+ type : AnnotationActionTypes . REMOVE_JOB_ANNOTATIONS_FAILED ,
104
+ payload : {
105
+ error,
106
+ } ,
107
+ } ) ;
108
+ }
109
+ } ;
110
+ }
111
+
112
+
113
+ export function uploadJobAnnotationsAsync ( job : any , loader : any , file : File ) :
114
+ ThunkAction < Promise < void > , { } , { } , AnyAction > {
115
+ return async ( dispatch : ActionCreator < Dispatch > ) : Promise < void > => {
116
+ try {
117
+ const store = getCVATStore ( ) ;
118
+ const state : CombinedState = store . getState ( ) ;
119
+ if ( state . tasks . activities . loads [ job . task . id ] ) {
120
+ throw Error ( 'Annotations is being uploaded for the task' ) ;
121
+ }
122
+ if ( state . annotation . activities . loads [ job . id ] ) {
123
+ throw Error ( 'Only one uploading of annotations for a job allowed at the same time' ) ;
124
+ }
125
+
126
+ dispatch ( {
127
+ type : AnnotationActionTypes . UPLOAD_JOB_ANNOTATIONS ,
128
+ payload : {
129
+ job,
130
+ loader,
131
+ } ,
132
+ } ) ;
133
+
134
+ const frame = state . annotation . player . frame . number ;
135
+ await job . annotations . upload ( file , loader ) ;
136
+
137
+ // One more update to escape some problems
138
+ // in canvas when shape with the same
139
+ // clientID has different type (polygon, rectangle) for example
140
+ dispatch ( {
141
+ type : AnnotationActionTypes . UPLOAD_JOB_ANNOTATIONS_SUCCESS ,
142
+ payload : {
143
+ job,
144
+ states : [ ] ,
145
+ } ,
146
+ } ) ;
147
+
148
+ await job . annotations . clear ( true ) ;
149
+ const states = await job . annotations . get ( frame ) ;
150
+
151
+ setTimeout ( ( ) => {
152
+ dispatch ( {
153
+ type : AnnotationActionTypes . UPLOAD_JOB_ANNOTATIONS_SUCCESS ,
154
+ payload : {
155
+ job,
156
+ states,
157
+ } ,
158
+ } ) ;
159
+ } ) ;
160
+ } catch ( error ) {
161
+ dispatch ( {
162
+ type : AnnotationActionTypes . UPLOAD_JOB_ANNOTATIONS_FAILED ,
163
+ payload : {
164
+ job,
165
+ error,
166
+ } ,
167
+ } ) ;
168
+ }
169
+ } ;
71
170
}
72
171
73
172
export function changeJobStatusAsync ( jobInstance : any , status : string ) :
0 commit comments