Skip to content

Commit b20cc41

Browse files
authored
Merge pull request #40 from IBMStreams/develop
Develop
2 parents eddcd23 + 959324f commit b20cc41

File tree

6 files changed

+456
-241
lines changed

6 files changed

+456
-241
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ This is the initial public release. For best results you should also install th
1111

1212
### Setup Instructions
1313
#### Build - Streaming Analytics Credentials
14-
The <b>build-ibmstreams</b> package requires a running IBM Streaming Analytics service. SPL applications will be built and deployed on this service. If you need to create one, start <a href="https://console.bluemix.net/catalog/services/streaming-analytics" rel="noopener" target="_blank">here</a> and follow the instructions to create an account.
14+
The <b>build-ibmstreams</b> package requires a running IBM Streaming Analytics service. SPL applications will be built and deployed on this service. If you need to create one, start <a href="https://cloud.ibm.com/catalog/services/streaming-analytics" rel="noopener" target="_blank">here</a> and follow the instructions to create an account.
1515

1616
<b>Note:</b>The service needs to support V2 of the rest api.
1717

18-
Once you have an account go to your <a href="https://console.bluemix.net/dashboard/apps" rel="noopener" target="_blank">dashboard</a> and select the Streaming Analytic service you want to use. You need to make sure it is running and then copy your credentials to the clipboard. To get your credentials select <b>Service Credentials</b> from the actions on the left. From the credentials page, press <b>View credentials</b> for the one you want to use and press the copy button in the upper right side of the credentials to copy them to the clipboard.
18+
Once you have an account go to your <a href="https://cloud.ibm.com/resources?groups=resource-instance" rel="noopener" target="_blank">dashboard</a> and select the Streaming Analytics service you want to use. You need to make sure it is running and then copy your credentials to the clipboard. To get your credentials select <b>Service Credentials</b> from the actions on the left. From the credentials page, press <b>View credentials</b> for the one you want to use and press the copy button in the upper right side of the credentials to copy them to the clipboard.
1919

2020
In Atom there is a setting in the <b>build-ibmstreams</b> package for the credentials. Go to <b>Atom->Preferences->Packages</b> and press the <b>Settings</b> button on the <b>build-ibmstreams</b> package and paste your credentials into the setting.
2121
![](./images/atomcredssetting.png)
2222

2323

2424
### SPL Application build
25-
![](./images/build.gif)
25+
![](./images/build.gif)

lib/LintHandler.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export class LintHandler {
5757
location: {
5858

5959
file: absolutePath,
60-
position: [[parts[2]-1,parts[3]-1],[parts[2]-1,parts[3]]], // 0-indexed
60+
position: [
61+
[parseInt(parts[2])-1 ,parseInt(parts[3])-1],
62+
[parseInt(parts[2])-1,parseInt(parts[3])]
63+
], // 0-indexed
6164
},
6265
excerpt: parts[4],
6366
description: parts[5],
@@ -67,6 +70,9 @@ export class LintHandler {
6770

6871
this.linter.setAllMessages(convertedMessages);
6972

73+
if (Array.isArray(convertedMessages) && convertedMessages.length > 0) {
74+
atom.workspace.open("atom://nuclide/diagnostics");
75+
}
7076
}
7177
}
7278
}

lib/MessageHandler.js

Lines changed: 115 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -3,166 +3,151 @@
33
"use strict";
44
"use babel";
55

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-
116
export class MessageHandler {
127
consoleService: null;
138

149
constructor(service) {
1510
this.consoleService = service;
1611
}
1712

18-
handleBuildProgressMessage(messageOutput: Array<any> | string, showNotification?: boolean) {
19-
if (Array.isArray(messageOutput)) {
20-
const message = this.getLoggableMessage(messageOutput);
21-
if (message) {
22-
this.consoleService.log(message);
23-
if (showNotification) {
24-
atom.notifications.addInfo("building...", {detail: message});
25-
}
26-
}
27-
} else if (typeof(messageOutput) === "string") {
28-
this.consoleService.log(messageOutput);
29-
if (showNotification) {
30-
atom.notifications.addInfo(messageOutput, {});
31-
}
13+
handleInfo(
14+
message,
15+
{
16+
detail = null,
17+
description = null,
18+
showNotification = true,
19+
showConsoleMessage = true,
20+
notificationAutoDismiss = true,
21+
notificationButtons = []
22+
} = {}
23+
) {
24+
const addedButtons = this.processButtons(notificationButtons);
25+
const detailMessage = this.joinMessageArray(detail);
26+
27+
if (showConsoleMessage) {
28+
this.consoleService.log(`${message}${detailMessage ? "\n"+detailMessage: ""}`);
3229
}
33-
}
34-
35-
handleBuildSuccess(messageOutput: Array<any>) {
36-
const message = this.getLoggableMessage(messageOutput);
37-
if (message) {
38-
this.consoleService.success(message);
39-
atom.notifications.addSuccess("Build succeeded", {detail: message, dismissable: true});
40-
} else {
41-
this.consoleService.success("Build succeeded");
42-
atom.notifications.addSuccess("Build succeeded", {dismissable: true});
30+
if (showNotification && typeof(message) === "string") {
31+
const notificationOptions = {
32+
...addedButtons,
33+
dismissable: !notificationAutoDismiss,
34+
detail: detailMessage ? detailMessage : "",
35+
description: description ? description : ""
36+
};
37+
return atom.notifications.addInfo(message, notificationOptions);
4338
}
4439
}
4540

46-
handleBuildFailure(messageOutput: Array<any>) {
47-
const message = this.getLoggableMessage(messageOutput);
48-
if (message) {
41+
handleError(
42+
message,
43+
{
44+
detail,
45+
description,
46+
stack,
47+
showNotification = true,
48+
showConsoleMessage = true,
49+
consoleErrorLog = true,
50+
notificationAutoDismiss = false,
51+
notificationButtons = []
52+
} = {}
53+
) {
54+
const addedButtons = this.processButtons(notificationButtons);
55+
const detailMessage = this.joinMessageArray(detail);
56+
const stackMessage = this.joinMessageArray(stack);
57+
58+
if (consoleErrorLog) {
59+
if (stack) {
60+
console.error(message, stack);
61+
} else {
62+
console.error(message);
63+
}
64+
}
65+
if (showConsoleMessage) {
4966
this.consoleService.error(message);
50-
atom.notifications.addError("Build failed", {detail: message, dismissable: true});
51-
} else {
52-
this.consoleService.error("Build failed");
53-
atom.notifications.addError("Build failed", {dismissable: true});
67+
if (typeof(detailMessage) === "string" && detailMessage.length > 0) {
68+
this.consoleService.error(detailMessage);
69+
}
5470
}
55-
}
56-
57-
handleSubmitProgressMessage(input) {
58-
if (typeof(input) === "string") {
59-
atom.notifications.addInfo(input, {});
71+
if (showNotification && typeof(message) === "string") {
72+
const notificationOptions = {
73+
...addedButtons,
74+
dismissable: !notificationAutoDismiss,
75+
detail: detailMessage ? detailMessage : "",
76+
stack: stackMessage ? stackMessage: "",
77+
description: description ? description : ""
78+
};
79+
return atom.notifications.addError(message, notificationOptions);
6080
}
61-
this.consoleService.log(input);
6281
}
6382

64-
handleSubmitSuccess(input, notificationButtons = []) {
65-
let addedButtons = {};
66-
if (Array.isArray(notificationButtons)) {
67-
addedButtons.buttons = notificationButtons.map(obj => ({onDidClick: obj.callbackFn, text: obj.label}));
83+
handleSuccess(
84+
message,
85+
{
86+
detail = null,
87+
description = null,
88+
showNotification = true,
89+
showConsoleMessage = true,
90+
notificationAutoDismiss = false,
91+
notificationButtons = []
92+
} = {}
93+
) {
94+
const addedButtons = this.processButtons(notificationButtons);
95+
const detailMessage = this.joinMessageArray(detail);
96+
97+
if (showConsoleMessage) {
98+
this.consoleService.log(`${message}${detailMessage ? "\n"+detailMessage: ""}`);
6899
}
69-
atom.notifications.addSuccess(`Job ${input.name} is ${input.health}`, {...addedButtons, dismissable: true});
70-
71-
if (this.consoleService) {
72-
this.consoleService.success(`Job ${input.name} is ${input.health}`);
100+
if (showNotification && typeof(message) === "string") {
101+
const notificationOptions = {
102+
...addedButtons,
103+
dismissable: !notificationAutoDismiss,
104+
detail: detailMessage ? detailMessage : "",
105+
description: description ? description : ""
106+
};
107+
return atom.notifications.addSuccess(message, notificationOptions);
73108
}
74109
}
75110

76-
handleSubmitFailure(input) {
77-
const errorString = input.errors.map(err => err.message).join("\n");
78-
atom.notifications.addError(`Job submission failed`, {detail: errorString, dismissable: true});
79-
80-
if (this.consoleService) {
81-
this.consoleService.error(`Job submission failed\n${errorString}`);
82-
}
83-
}
84-
handleError(input, notificationButtons = []) {
85-
let addedButtons = {};
86-
if (Array.isArray(notificationButtons)) {
87-
addedButtons.buttons = notificationButtons.map(obj => ({onDidClick: obj.callbackFn, text: obj.label}));
88-
}
89-
if (typeof(input) === "string") {
90-
atom.notifications.addError(input, {...addedButtons, dismissable: true});
91-
this.consoleService.error(input);
92-
} else if (input.message) {
93-
atom.notifications.addError(
94-
input.message,
95-
{...addedButtons, dismissable: true, detail: input.stack, stack: input.stack}
96-
);
97-
this.consoleService.error(input.message);
98-
}
99-
console.error(input);
100-
}
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-
}
106-
if (showNotification) {
107-
atom.notifications.addSuccess(input, {...addedButtons, detail: detail, dismissable: true});
108-
}
109-
if (showConsoleMsg) {
110-
if (this.consoleService) {
111-
this.consoleService.success(`${input}\n${detail}`);
112-
}
113-
}
114-
}
115-
116-
handleWarning(message) {
117-
if (message && typeof(message) === "string") {
118-
this.consoleService.warn(message);
119-
atom.notifications.addWarning(message, {});
120-
}
121-
}
122-
123-
showDialog(message, detail, buttonObjs) {
124-
125-
const nativeImage = require("electron").nativeImage;
126-
127-
const labels = buttonObjs.map(obj => obj.label);
128-
const callbacks = buttonObjs.map(obj => obj.callbackFn);
129-
let buttons = {};
130-
labels.forEach((label, index) => {
131-
buttons[label] = callbacks[index];
132-
});
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-
);
147-
}
148-
149-
handleCredentialsMissing() {
150-
atom.notifications.addError(
111+
handleCredentialsMissing(errorNotification) {
112+
const n = atom.notifications.addError(
151113
"Copy and paste the Streaming Analytics service credentials into the build-ibmstreams package settings page.",
152114
{
153115
dismissable: true,
154116
buttons: [{
155117
text: "Open package settings",
156-
onDidClick: () => {atom.workspace.open("atom://config/packages/build-ibmstreams")}
118+
onDidClick: () => {
119+
this.dismissNotification(errorNotification);
120+
this.dismissNotification(n);
121+
atom.workspace.open("atom://config/packages/build-ibmstreams");
122+
}
157123
}]
158124
}
159125
);
126+
return n;
127+
}
128+
129+
processButtons(btns) {
130+
let buttons = {};
131+
if (Array.isArray(btns)) {
132+
buttons.buttons = btns.map(obj => ({onDidClick: obj.callbackFn, text: obj.label}));
133+
}
134+
return buttons;
135+
}
136+
137+
joinMessageArray(msgArray) {
138+
if (Array.isArray(msgArray)) {
139+
return msgArray.join("\n").trimRight();
140+
}
141+
return msgArray;
142+
}
143+
144+
dismissNotification(notification) {
145+
if (notification && typeof(notification.dismiss) === "function") {
146+
notification.dismiss();
147+
}
160148
}
161149

162150
getLoggableMessage(messages: Array<any>) {
163-
return messages
164-
.map(outputMsg => outputMsg.message_text)
165-
.join("\n")
166-
.trimRight();
151+
return this.joinMessageArray(messages.map(outputMsg => outputMsg.message_text));
167152
}
168153
}

0 commit comments

Comments
 (0)