File tree Expand file tree Collapse file tree 4 files changed +51
-6
lines changed
components/translate-dialog Expand file tree Collapse file tree 4 files changed +51
-6
lines changed Original file line number Diff line number Diff line change 3
3
module Maglev
4
4
module Api
5
5
class PageTranslationsController < ::Maglev ::ApiController
6
+ before_action :set_page
7
+
8
+ def index
9
+ translations = @page . translations_for ( :sections , params [ :locale ] )
10
+ render json : { translated : translations &.size . to_i > 0 }
11
+ end
12
+
6
13
def create
7
- @page = translate_page ( resources . find ( params [ :page_id ] ) )
14
+ translate_page ( @page )
15
+ head :ok
8
16
end
9
17
10
18
private
11
19
20
+ def set_page
21
+ @page ||= resources . find ( params [ :page_id ] )
22
+ end
23
+
12
24
def translate_page ( page )
13
25
services . translate_page . call (
14
26
page : page ,
Original file line number Diff line number Diff line change 39
39
export default {
40
40
name: ' TranslateDialog' ,
41
41
data () {
42
- return { submitState: ' default' }
42
+ return { submitState: ' default' , pollingSubmission : false , pollingInterval : null }
43
43
},
44
44
computed: {
45
45
localeName () {
@@ -49,17 +49,45 @@ export default {
49
49
return this .$t (` support.locales.${ this .currentDefaultLocale } ` )
50
50
}
51
51
},
52
+ unmounted () {
53
+ if (this .pollingInterval ) clearInterval (this .pollingInterval )
54
+ },
52
55
methods: {
53
56
translate () {
54
57
this .submitState = ' inProgress'
55
58
this .services .page .translate (this .currentPage .id , this .currentLocale )
56
- .then (() => {
57
- // Force a refresh
58
- this .$nextTick (() => { this .$router .go (0 ) })
59
+ .then (() => {
60
+ this .pollingSubmission = true
61
+ // Force a refresh
62
+ // this.$nextTick(() => { this.$router.go(0) })
59
63
})
60
64
.catch (() => {
61
65
this .submitState = ' fail'
62
66
})
67
+ },
68
+ isTranslated () {
69
+ this .services .page .isTranslated (this .currentPage .id , this .currentLocale )
70
+ .then ((translated ) => {
71
+ if (translated) {
72
+ this .pollingSubmission = false
73
+ // Force a refresh
74
+ this .$nextTick (() => { this .$router .go (0 ) })
75
+ }
76
+ })
77
+ .catch (() => {
78
+ this .pollingSubmission = false
79
+ this .submitState = ' fail'
80
+ })
81
+ }
82
+ },
83
+ watch: {
84
+ pollingSubmission (newValue , oldValue ) {
85
+ if (! newValue) {
86
+ if (this .pollingInterval ) clearInterval (this .pollingInterval )
87
+ return
88
+ }
89
+
90
+ this .pollingInterval = setInterval (() => this .isTranslated (), 1000 )
63
91
}
64
92
}
65
93
}
Original file line number Diff line number Diff line change @@ -97,6 +97,11 @@ export default (api) => ({
97
97
return api . post ( `/pages/${ id } /translations` , { locale } ) . then ( ( { data } ) => data )
98
98
} ,
99
99
100
+ isTranslated : ( id , locale ) => {
101
+ console . log ( '[PageService] Checking if page is translated #' , id , locale )
102
+ return api . get ( `/pages/${ id } /translations` , { params : { locale } } ) . then ( ( { data } ) => data . translated )
103
+ } ,
104
+
100
105
destroy : ( id ) => {
101
106
console . log ( '[PageService] Destroying page #' , id )
102
107
return api . destroy ( `/pages/${ id } ` )
Original file line number Diff line number Diff line change 9
9
resource :site , only : :show
10
10
resources :pages do
11
11
resources :clones , controller : :page_clones , only : :create
12
- resources :translations , controller : :page_translations , only : %i[ create ]
12
+ resources :translations , controller : :page_translations , only : %i[ index create ]
13
13
end
14
14
resources :assets
15
15
resource :publication , only : %i[ show create ]
You can’t perform that action at this time.
0 commit comments