@@ -4,13 +4,15 @@ import Configuration from '../config/environment';
4
4
5
5
export default Ember . Component . extend ( {
6
6
7
- classNames : Ember . String . w ( 'ui right internal rail stage-details ' ) ,
7
+ classNames : Ember . String . w ( 'ui right internal rail info-box ' ) ,
8
8
9
9
pipeline : Ember . inject . service ( ) ,
10
10
store : Ember . inject . service ( ) ,
11
11
session : Ember . inject . service ( ) ,
12
12
notify : Ember . inject . service ( ) ,
13
13
14
+ aceEditor : null ,
15
+
14
16
willPullRequest : Ember . computed . equal ( 'commitOption.option' , 'pull_request' ) ,
15
17
editorAction : Ember . computed ( 'definition' , function ( ) {
16
18
let definition = this . get ( 'definition' ) ;
@@ -27,9 +29,43 @@ export default Ember.Component.extend({
27
29
} ,
28
30
29
31
didRender ( ) {
30
- if ( this . $ ( 'input[name="commitOption "][checked="checked"]' ) . length === 0 ) {
32
+ if ( this . $ ( 'input[name="commit-option "][checked="checked"]' ) . length === 0 ) {
31
33
let commitOption = this . get ( 'commitOption.option' ) ;
32
- this . $ ( `input[name="commitOption"][value="${ commitOption } "]` ) . attr ( "checked" , "checked" )
34
+ this . $ ( `input[name="commit-option"][value="${ commitOption } "]` ) . attr ( "checked" , "checked" ) ;
35
+ }
36
+ this . aceEditorInit ( ) ;
37
+ } ,
38
+
39
+ willDestroyElement ( ) {
40
+ this . removeObserver ( 'definition.content' , this , this . aceEditorContentChange ) ;
41
+ if ( this . aceEditor ) {
42
+ this . aceEditor . destroy ( ) ;
43
+ this . aceEditor . container . remove ( ) ;
44
+ }
45
+ } ,
46
+
47
+ aceEditorInit ( ) {
48
+ let textEditor = this . $ ( "div#definition-content" ) ;
49
+ if ( textEditor . length && ! textEditor . hasClass ( 'ace_editor' ) ) {
50
+ let editorID = textEditor . attr ( 'id' ) ;
51
+ this . aceEditor = ace . edit ( editorID ) ;
52
+ this . aceEditor . getSession ( ) . setTabSize ( 2 ) ;
53
+ this . aceEditor . getSession ( ) . setMode ( "ace/mode/yaml" ) ;
54
+ this . aceEditor . on ( 'change' , ( ) => {
55
+ this . set ( 'definition.content' , this . aceEditor . getSession ( ) . getValue ( ) ) ;
56
+ } ) ;
57
+ this . aceEditor . $blockScrolling = Infinity ;
58
+ this . addObserver ( 'definition.content' , this , this . aceEditorContentChange ) ;
59
+ this . notifyPropertyChange ( 'definition.content' ) ;
60
+ }
61
+ } ,
62
+
63
+ aceEditorContentChange ( ) {
64
+ if ( ! this . get ( 'definition.content' ) ) {
65
+ this . aceEditor . getSession ( ) . setValue ( '' ) ;
66
+ }
67
+ else if ( this . aceEditor . getSession ( ) . getValue ( ) !== this . get ( 'definition.content' ) ) {
68
+ this . aceEditor . getSession ( ) . setValue ( this . get ( 'definition.content' ) ) ;
33
69
}
34
70
} ,
35
71
@@ -85,10 +121,8 @@ export default Ember.Component.extend({
85
121
} ,
86
122
87
123
definitionFetcher : task ( function * ( ajaxOptions ) {
88
- yield Ember . $ . ajax ( ajaxOptions )
89
- . then ( ( definition ) => {
90
- this . serializeDefinition ( definition ) ;
91
- } ) ;
124
+ let definition = yield Ember . $ . ajax ( ajaxOptions ) ;
125
+ this . serializeDefinition ( definition ) ;
92
126
} ) . drop ( ) ,
93
127
94
128
definitionUpdater : task ( function * ( ajaxOptions ) {
@@ -107,6 +141,7 @@ export default Ember.Component.extend({
107
141
let action = this . get ( 'editorAction' ) . toLowerCase ( ) ;
108
142
yield Ember . $ . ajax ( ajaxOptions )
109
143
. then ( ( definition ) => {
144
+ this . get ( 'model' ) . reload ( ) ;
110
145
this . get ( 'notify' ) . success ( `Successfully ${ action } d the definition file for the pipeline` ) ;
111
146
this . serializeDefinition ( definition ) ;
112
147
} , ( res ) => {
0 commit comments