-
Notifications
You must be signed in to change notification settings - Fork 539
/
send.ts
102 lines (92 loc) · 3.68 KB
/
send.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
module Camel {
export function SendMessageController($scope, workspace:Workspace, localStorage) {
var LANGUAGE_FORMAT_PREFERENCE = "defaultLanguageFormat";
var sourceFormat = workspace.getLocalStorage(LANGUAGE_FORMAT_PREFERENCE) || "javascript";
$scope.message = "";
// TODO Remove this if possible
$scope.codeMirror = undefined;
var options = {
mode: {
name: sourceFormat
},
// Quick hack to get the codeMirror instance.
onChange: function(codeMirror) {
if(!$scope.codeMirror) {
$scope.codeMirror = codeMirror;
}
}
};
$scope.codeMirrorOptions = CodeEditor.createEditorSettings(options);
$scope.headers = [];
$scope.addHeader = () => {
$scope.headers.push({name: "", value: ""});
};
// lets add a default header
$scope.addHeader();
$scope.removeHeader = (header) => {
$scope.headers = $scope.headers.remove(header);
};
// TODO Find out what this does
$scope.$watch('workspace.selection', function () {
workspace.moveIfViewInvalid();
});
/** save the sourceFormat in preferences for later
* Note, this would be controller specific preferences and not the global, overriding, preferences */
// TODO Use ng-selected="changeSourceFormat()" - Although it seemed to fire multiple times..
$scope.$watch('codeMirrorOptions.mode.name', function(newValue, oldValue) {
workspace.setLocalStorage(LANGUAGE_FORMAT_PREFERENCE, newValue)
});
var sendWorked = () => {
$scope.message = "";
notification("success", "Message sent!");
};
$scope.autoFormat = () => {
setTimeout(() => {
CodeEditor.autoFormatEditor($scope.codeMirror);
}, 50);
};
$scope.sendMessage = () => {
var body = $scope.message;
var selection = workspace.selection;
if (selection) {
var mbean = selection.objectName;
if (mbean) {
var headers = null;
if ($scope.headers.length) {
headers = {};
angular.forEach($scope.headers, (object) => {
var key = object.name;
if (key) {
headers[key] = object.value;
}
});
}
var jolokia = workspace.jolokia;
// if camel then use a different operation on the camel context mbean
var callback = onSuccess(sendWorked);
if (selection.domain === "org.apache.camel") {
var uri = selection.title;
mbean = getSelectionCamelContextMBean(workspace);
if (mbean) {
if (headers) {
jolokia.execute(mbean, "sendBodyAndHeaders(java.lang.String, java.lang.Object, java.util.Map)", uri, body, headers, callback);
} else {
jolokia.execute(mbean, "sendStringBody(java.lang.String, java.lang.String)", uri, body, callback);
}
} else {
notification("error", "Could not find CamelContext MBean!");
}
} else {
var user = localStorage["activemqUserName"];
var pwd = localStorage["activemqPassword"];
if (headers) {
jolokia.execute(mbean, "sendTextMessage(java.util.Map, java.lang.String, java.lang.String, java.lang.String)", headers, body, user, pwd, callback);
} else {
jolokia.execute(mbean, "sendTextMessage(java.lang.String, java.lang.String, java.lang.String)", body, user, pwd, callback);
}
}
}
}
};
}
}