3
3
"use strict" ;
4
4
"use babel" ;
5
5
6
+ import path from "path" ;
7
+
8
+ const packageRoot = atom . packages . resolvePackagePath ( "build-ibmstreams" ) ;
9
+ const STREAMING_ANALYTICS_ICON_PATH = `${ packageRoot } ${ path . sep } assets${ path . sep } streaming_analytics_200x200.png` ;
10
+
6
11
export class MessageHandler {
7
12
consoleService : null ;
8
13
@@ -25,28 +30,15 @@ export class MessageHandler {
25
30
atom . notifications . addInfo ( messageOutput , { } ) ;
26
31
}
27
32
}
28
- // if (input && input.output) {
29
- // const messageText = input.output
30
- // .map(outputMsg => outputMsg.message_text)
31
- // .join("\n");
32
- // if (input.status === "building" || input.status === "waiting") {
33
- // atom.notifications.addInfo(input.status+"...", {detail: messageText});
34
- // }
35
- // } else if (typeof(input) === "string") {
36
- // this.consoleService.log(input);
37
- // if (showNotification) {
38
- // atom.notifications.addInfo(input, {});
39
- // }
40
- // }
41
33
}
42
34
43
35
handleBuildSuccess ( messageOutput : Array < any > ) {
44
36
const message = this . getLoggableMessage ( messageOutput ) ;
45
37
if ( message ) {
46
- this . consoleService . log ( message ) ;
38
+ this . consoleService . success ( message ) ;
47
39
atom . notifications . addSuccess ( "Build succeeded" , { detail : message , dismissable : true } ) ;
48
40
} else {
49
- this . consoleService . log ( "Build succeeded" ) ;
41
+ this . consoleService . success ( "Build succeeded" ) ;
50
42
atom . notifications . addSuccess ( "Build succeeded" , { dismissable : true } ) ;
51
43
}
52
44
}
@@ -63,14 +55,21 @@ export class MessageHandler {
63
55
}
64
56
65
57
handleSubmitProgressMessage ( input ) {
66
-
58
+ if ( typeof ( input ) === "string" ) {
59
+ atom . notifications . addInfo ( input , { } ) ;
60
+ }
61
+ this . consoleService . log ( input ) ;
67
62
}
68
63
69
- handleSubmitSuccess ( input ) {
70
- atom . notifications . addSuccess ( `Job ${ input . name } is ${ input . health } ` , { dismissable : true } ) ;
64
+ handleSubmitSuccess ( input , notificationButtons = [ ] ) {
65
+ let addedButtons = { } ;
66
+ if ( Array . isArray ( notificationButtons ) ) {
67
+ addedButtons . buttons = notificationButtons . map ( obj => ( { onDidClick : obj . callbackFn , text : obj . label } ) ) ;
68
+ }
69
+ atom . notifications . addSuccess ( `Job ${ input . name } is ${ input . health } ` , { ...addedButtons , dismissable : true } ) ;
71
70
72
71
if ( this . consoleService ) {
73
- this . consoleService . log ( `Job ${ input . name } is ${ input . health } ` ) ;
72
+ this . consoleService . success ( `Job ${ input . name } is ${ input . health } ` ) ;
74
73
}
75
74
}
76
75
@@ -99,9 +98,13 @@ export class MessageHandler {
99
98
}
100
99
console . error ( input ) ;
101
100
}
102
- handleSuccess ( input , detail , showNotification , showConsoleMsg ) {
101
+ handleSuccess ( input , detail , showNotification , showConsoleMsg , notificationButtons = [ ] ) {
102
+ let addedButtons = { } ;
103
+ if ( Array . isArray ( notificationButtons ) ) {
104
+ addedButtons . buttons = notificationButtons . map ( obj => ( { onDidClick : obj . callbackFn , text : obj . label } ) ) ;
105
+ }
103
106
if ( showNotification ) {
104
- atom . notifications . addSuccess ( input , { detail : detail , dismissable : true } ) ;
107
+ atom . notifications . addSuccess ( input , { ... addedButtons , detail : detail , dismissable : true } ) ;
105
108
}
106
109
if ( showConsoleMsg ) {
107
110
if ( this . consoleService ) {
@@ -118,13 +121,29 @@ export class MessageHandler {
118
121
}
119
122
120
123
showDialog ( message , detail , buttonObjs ) {
124
+
125
+ const nativeImage = require ( "electron" ) . nativeImage ;
126
+
121
127
const labels = buttonObjs . map ( obj => obj . label ) ;
122
128
const callbacks = buttonObjs . map ( obj => obj . callbackFn ) ;
123
129
let buttons = { } ;
124
130
labels . forEach ( ( label , index ) => {
125
131
buttons [ label ] = callbacks [ index ] ;
126
132
} ) ;
127
- atom . confirm ( { message : message , detailedMessage : detail , buttons : buttons } ) ;
133
+ atom . confirm (
134
+ {
135
+ message : message ,
136
+ detail : detail ,
137
+ buttons : labels ,
138
+ icon : STREAMING_ANALYTICS_ICON_PATH
139
+ } ,
140
+ ( chosen , checkboxChecked ) => {
141
+ const callback = callbacks [ chosen ] ;
142
+ if ( typeof ( callback ) === "function" ) {
143
+ return callback ( ) ;
144
+ }
145
+ }
146
+ ) ;
128
147
}
129
148
130
149
handleCredentialsMissing ( ) {
0 commit comments