/WebSolution/WebApplication1/scripts/ngConstellation-1.8.0.js

https://gitlab.com/psyked/Promethee · JavaScript · 225 lines · 213 code · 1 blank · 11 comment · 7 complexity · b59ce0b692ce8d870986b713571d649d MD5 · raw file

  1. /*
  2. * Constellation Platform 1.8
  3. * Web site: http://www.myConstellation.io
  4. * Copyright (C) 2014-2016 - Sebastien Warin <http://sebastien.warin.fr>
  5. * All Rights Reserved.
  6. *
  7. * NOTICE: All information contained herein is, and remains the property of Sebastien Warin.
  8. * The intellectual and technical concepts contained herein are proprietary to Sébastien Warin.
  9. * Dissemination of this information or reproduction of this material is strictly forbidden
  10. * unless prior written permission is obtained from Sébastien Warin.
  11. */
  12. angular.module('ngConstellation', ['ng'])
  13. .constant('CONSTELLATION_VERSION', '1.8.0')
  14. .constant('MODULE_VERSION', '1.8.0')
  15. .value('$', $)
  16. .factory('constellationConsumer', ['$', '$rootScope', function ($, $rootScope) {
  17. var constellationProxy = {
  18. constellationClient: null,
  19. onConnectionStateChangedCallback: null,
  20. intializeClient: function (serverUri, accessKey, friendlyName) {
  21. constellationProxy.constellationClient = $.signalR.createConstellationConsumer(serverUri, accessKey, friendlyName);
  22. constellationProxy.constellationClient.connection.stateChanged(function (change) {
  23. if (constellationProxy.onConnectionStateChangedCallback != null) {
  24. constellationProxy.onConnectionStateChangedCallback(change);
  25. }
  26. });
  27. },
  28. connect: function () {
  29. constellationProxy.constellationClient.connection.start();
  30. },
  31. onConnectionStateChanged: function (callback) {
  32. constellationProxy.onConnectionStateChangedCallback = callback;
  33. },
  34. onReceiveMessage: function (callback) {
  35. return constellationProxy.constellationClient.client.onReceiveMessage(callback);
  36. },
  37. onUpdateStateObject: function (callback) {
  38. return constellationProxy.constellationClient.client.onUpdateStateObject(callback);
  39. },
  40. requestStateObjects: function (sentinelName, packageName, name, type) {
  41. return constellationProxy.constellationClient.server.requestStateObjects(sentinelName, packageName, name, type);
  42. },
  43. sendMessage: function (scope, key, data) {
  44. return constellationProxy.constellationClient.server.sendMessage(scope, key, data);
  45. },
  46. sendMessageWithSaga: function (scope, key, data, callback) {
  47. return constellationProxy.constellationClient.server.sendMessageWithSaga(scope, key, data, callback);
  48. },
  49. subscribeMessages: function (group) {
  50. return constellationProxy.constellationClient.server.subscribeMessages(group);
  51. },
  52. subscribeStateObjects: function (sentinelName, packageName, name, type) {
  53. return constellationProxy.constellationClient.server.subscribeStateObjects(sentinelName, packageName, name, type);
  54. },
  55. unSubscribeMessages: function (group) {
  56. return constellationProxy.constellationClient.server.unSubscribeMessages(group);
  57. },
  58. unSubscribeStateObjects: function (sentinelName, packageName, name, type) {
  59. return constellationProxy.constellationClient.server.unSubscribeStateObjects(sentinelName, packageName, name, type);
  60. },
  61. requestSubscribeStateObjects: function (sentinelName, packageName, name, type) {
  62. return constellationProxy.constellationClient.server.requestSubscribeStateObjects(sentinelName, packageName, name, type);
  63. },
  64. };
  65. return constellationProxy;
  66. }])
  67. .factory('constellationController', ['$', '$rootScope', function ($, $rootScope) {
  68. var constellationProxy = {
  69. constellationClient: null,
  70. onConnectionStateChangedCallback: null,
  71. intializeClient: function (serverUri, accessKey, friendlyName) {
  72. constellationProxy.constellationClient = $.signalR.createConstellationController(serverUri, accessKey, friendlyName);
  73. constellationProxy.constellationClient.connection.stateChanged(function (change) {
  74. if (constellationProxy.onConnectionStateChangedCallback != null) {
  75. constellationProxy.onConnectionStateChangedCallback(change);
  76. }
  77. });
  78. },
  79. connect: function () {
  80. constellationProxy.constellationClient.connection.start();
  81. },
  82. onConnectionStateChanged: function (callback) {
  83. constellationProxy.onConnectionStateChangedCallback = callback;
  84. },
  85. onReceiveLogMessage: function (callback) {
  86. return constellationProxy.constellationClient.client.onReceiveLogMessage(callback);
  87. },
  88. onUpdateSentinel: function (callback) {
  89. return constellationProxy.constellationClient.client.onUpdateSentinel(callback);
  90. },
  91. onUpdateSentinelsList: function (callback) {
  92. return constellationProxy.constellationClient.client.onUpdateSentinelsList(callback);
  93. },
  94. onReportPackageState: function (callback) {
  95. return constellationProxy.constellationClient.client.onReportPackageState(callback);
  96. },
  97. onReportPackageUsage: function (callback) {
  98. return constellationProxy.constellationClient.client.onReportPackageUsage(callback);
  99. },
  100. onUpdatePackageList: function (callback) {
  101. return constellationProxy.constellationClient.client.onUpdatePackageList(callback);
  102. },
  103. onUpdatePackageDescriptor: function (callback) {
  104. return constellationProxy.constellationClient.client.onUpdatePackageDescriptor(callback);
  105. },
  106. addToControlGroup: function (group) {
  107. return constellationProxy.constellationClient.server.addToControlGroup(group);
  108. },
  109. purgeStateObjects: function (sentinelName, packageName, name, type) {
  110. return constellationProxy.constellationClient.server.purgeStateObjects(sentinelName, packageName, name, type);
  111. },
  112. reloadServerConfiguration: function (deployConfiguration) {
  113. return constellationProxy.constellationClient.server.reloadServerConfiguration(deployConfiguration);
  114. },
  115. reload: function (sentinelName, packageName) {
  116. return constellationProxy.constellationClient.server.reload(sentinelName, packageName);
  117. },
  118. removeToControlGroup: function (group) {
  119. return constellationProxy.constellationClient.server.removeToControlGroup(group);
  120. },
  121. requestPackageDescriptor: function (packageName) {
  122. return constellationProxy.constellationClient.server.requestPackageDescriptor(packageName);
  123. },
  124. requestPackagesList: function (sentinelName) {
  125. return constellationProxy.constellationClient.server.requestPackagesList(sentinelName);
  126. },
  127. requestSentinelUpdates: function () {
  128. return constellationProxy.constellationClient.server.requestSentinelUpdates();
  129. },
  130. requestSentinelsList: function () {
  131. return constellationProxy.constellationClient.server.requestSentinelsList();
  132. },
  133. restart: function (sentinelName, packageName) {
  134. return constellationProxy.constellationClient.server.restart(sentinelName, packageName);
  135. },
  136. start: function (sentinelName, packageName) {
  137. return constellationProxy.constellationClient.server.start(sentinelName, packageName);
  138. },
  139. stop: function (sentinelName, packageName) {
  140. return constellationProxy.constellationClient.server.stop(sentinelName, packageName);
  141. },
  142. updatePackageSettings: function (sentinelName, packageName) {
  143. return constellationProxy.constellationClient.server.updatePackageSettings(sentinelName, packageName);
  144. }
  145. };
  146. return constellationProxy;
  147. }])
  148. .factory('constellationManagement', ['$http', function ($http) {
  149. var constellationProxy = {
  150. urlBase: null,
  151. globalTimestamp: new Date().getTime(),
  152. intializeClient: function (serverUri, accessKey, friendlyName) {
  153. constellationProxy.urlBase = serverUri + "/rest/management/";
  154. $http.defaults.headers.common['SentinelName'] = 'Management';
  155. $http.defaults.headers.common['PackageName'] = friendlyName;
  156. $http.defaults.headers.common['AccessKey'] = accessKey;
  157. },
  158. getRequestUri: function (method, timestamp) {
  159. if(timestamp == undefined) {
  160. timestamp = new Date().getTime();
  161. }
  162. return constellationProxy.urlBase + method + "?t=" + timestamp;
  163. },
  164. checkAccess: function () {
  165. return $http.get(constellationProxy.getRequestUri("CheckAccess"));
  166. },
  167. getServerVersion: function () {
  168. return $http.get(constellationProxy.getRequestUri("GetServerVersion"));
  169. },
  170. getPackages: function () {
  171. return $http.get(constellationProxy.getRequestUri("GetPackages"));
  172. },
  173. getPackage: function (packageName) {
  174. return $http.get(constellationProxy.getRequestUri("GetPackage"), { params: { package: packageName } });
  175. },
  176. getPackageIcon: function (packageName) {
  177. return $http.get(constellationProxy.getPackageIconUri(packageName));
  178. },
  179. getPackageIconUri: function (packageName) {
  180. var encodeQueryParameter = function (data) {
  181. var ret = [];
  182. for (var d in data)
  183. ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]));
  184. return ret.join("&");
  185. }
  186. return constellationProxy.getRequestUri("GetPackageIcon", constellationProxy.globalTimestamp) + "&" + encodeQueryParameter({
  187. package: packageName,
  188. SentinelName: $http.defaults.headers.common['SentinelName'],
  189. PackageName: $http.defaults.headers.common['PackageName'],
  190. AccessKey: $http.defaults.headers.common['AccessKey']
  191. });
  192. },
  193. getServerConfiguration: function () {
  194. return $http.get(constellationProxy.getRequestUri("GetServerConfiguration"));
  195. },
  196. setServerConfiguration: function (configuration) {
  197. return $http.post(constellationProxy.getRequestUri("SetServerConfiguration"), configuration);
  198. },
  199. getLicense: function () {
  200. return $http.get(constellationProxy.getRequestUri("GetLicense"));
  201. },
  202. setLicense: function (license) {
  203. return $http.post(constellationProxy.getRequestUri("SetLicense"), license);
  204. },
  205. getSentinels: function () {
  206. return $http.get(constellationProxy.getRequestUri("GetSentinels"));
  207. },
  208. addSentinel: function (sentinelName, credential, reloadAfter) {
  209. return $http.get(constellationProxy.getRequestUri("AddSentinel"),
  210. {
  211. params:
  212. {
  213. sentinel: sentinelName,
  214. credential: credential,
  215. reload: reloadAfter
  216. }
  217. });
  218. },
  219. getCredentials: function () {
  220. return $http.get(constellationProxy.getRequestUri("GetCredentials"));
  221. }
  222. };
  223. return constellationProxy;
  224. }]);