@@ -16,6 +16,7 @@ import { openPerspectivePropertiesModal } from "ducks/perspectiveProperties";
16
16
import { openRoles } from "ducks/roles" ;
17
17
import { openSaveDictionaryModal } from "ducks/saveDictionary" ;
18
18
import { openStatistics } from "ducks/statistics" ;
19
+ import { openUploadModal , updateUploadModal } from "ducks/upload" ;
19
20
import TranslationContext from "Layout/TranslationContext" ;
20
21
21
22
const queryPerspectivePath = gql `
@@ -34,6 +35,7 @@ export const queryAvailablePerspectives = gql`
34
35
query availablePerspectives($dictionary_id: LingvodocID!) {
35
36
dictionary(id: $dictionary_id) {
36
37
id
38
+ category
37
39
perspectives {
38
40
id
39
41
parent_id
@@ -46,6 +48,14 @@ export const queryAvailablePerspectives = gql`
46
48
}
47
49
` ;
48
50
51
+ const uploadPerspective = gql `
52
+ mutation uploadPerspective($id: LingvodocID!, $debugFlag: Boolean) {
53
+ tsakorpus(perspective_id: $id, debug_flag: $debugFlag) {
54
+ triumph
55
+ }
56
+ }
57
+ ` ;
58
+
49
59
const license_dict_translator = getTranslation => ( {
50
60
proprietary : [ getTranslation ( "Proprietary" ) , null ] ,
51
61
"cc-by-4.0" : [ "CC-BY-4.0" , "https://creativecommons.org/licenses/by/4.0/legalcode" ] ,
@@ -57,6 +67,35 @@ const license_dict_translator = getTranslation => ({
57
67
* Perspective breadcrumb component.
58
68
*/
59
69
class PerspectivePath extends React . Component {
70
+ constructor ( props ) {
71
+ super ( props ) ;
72
+
73
+ this . state = {
74
+ uploading : false
75
+ } ;
76
+
77
+ this . uploadPerspectiveWrapper = this . uploadPerspectiveWrapper . bind ( this ) ;
78
+ } ;
79
+
80
+ uploadPerspectiveWrapper ( ) {
81
+ const { id, actions, uploadPerspective} = this . props ;
82
+
83
+ this . setState ( { uploading : true } ) ;
84
+
85
+ uploadPerspective ( {
86
+ variables : { id }
87
+ } ) . then (
88
+ ( { data } ) => {
89
+ this . setState ( { uploading : false } ) ;
90
+ actions . updateUploadModal ( data . tsakorpus . triumph ? false : null ) ;
91
+ } ,
92
+ ( ) => {
93
+ this . setState ( { uploading : false } ) ;
94
+ actions . updateUploadModal ( null ) ;
95
+ }
96
+ )
97
+ }
98
+
60
99
render ( ) {
61
100
/* eslint-disable no-shadow */
62
101
const {
@@ -88,6 +127,7 @@ class PerspectivePath extends React.Component {
88
127
const dictionary_id_tree = tree [ 1 ] . id ;
89
128
90
129
const {
130
+ category,
91
131
perspectives,
92
132
additional_metadata : { license }
93
133
} = queryAvailablePerspectives . dictionary ;
@@ -108,6 +148,7 @@ class PerspectivePath extends React.Component {
108
148
const roles_str = this . context ( "Roles" ) . toLowerCase ( ) ;
109
149
const properties_str = this . context ( "Properties" ) . toLowerCase ( ) ;
110
150
const statistics_str = this . context ( "Statistics" ) . toLowerCase ( ) ;
151
+ const upload_str = this . context ( "Upload" ) . toLowerCase ( ) ;
111
152
112
153
return (
113
154
< Header as = "h2" className = { className } >
@@ -171,6 +212,20 @@ class PerspectivePath extends React.Component {
171
212
actions . openStatistics ( id , "perspective" , `'${ T ( e . translations ) } ' ${ statistics_str } ` )
172
213
}
173
214
/>
215
+ { user . id !== undefined && category == 1 && (
216
+ < Dropdown . Item
217
+ key = "upload"
218
+ icon = { < i className = "lingvo-icon lingvo-icon_published" /> }
219
+ text = { this . context ( "Upload" ) }
220
+ onClick = { ( ) =>
221
+ actions . openUploadModal (
222
+ id ,
223
+ `'${ T ( e . translations ) } ' ${ upload_str } ` ,
224
+ this . state . uploading ,
225
+ this . uploadPerspectiveWrapper )
226
+ }
227
+ />
228
+ ) }
174
229
</ Dropdown . Menu >
175
230
</ Dropdown >
176
231
) : index === tree . length - 2 ? (
@@ -285,6 +340,7 @@ PerspectivePath.propTypes = {
285
340
dictionary_id : PropTypes . array . isRequired ,
286
341
queryPerspectivePath : PropTypes . object . isRequired ,
287
342
queryAvailablePerspectives : PropTypes . object . isRequired ,
343
+ uploadPerspective : PropTypes . func . isRequired ,
288
344
mode : PropTypes . string . isRequired ,
289
345
className : PropTypes . string ,
290
346
actions : PropTypes . object . isRequired ,
@@ -310,7 +366,9 @@ export default compose(
310
366
openPerspectivePropertiesModal,
311
367
openRoles,
312
368
openSaveDictionaryModal,
313
- openStatistics
369
+ openStatistics,
370
+ openUploadModal,
371
+ updateUploadModal
314
372
} ,
315
373
dispatch
316
374
)
@@ -323,5 +381,6 @@ export default compose(
323
381
graphql ( queryAvailablePerspectives , {
324
382
name : "queryAvailablePerspectives" ,
325
383
options : props => ( { variables : { dictionary_id : props . dictionary_id } } )
326
- } )
384
+ } ) ,
385
+ graphql ( uploadPerspective , { name : "uploadPerspective" } )
327
386
) ( PerspectivePath ) ;
0 commit comments