api_service.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var app = angular.module('sentinelDashboardApp');
  2. app.service('GatewayApiService', ['$http', function ($http) {
  3. this.queryApis = function (app, ip, port) {
  4. var param = {
  5. app: app,
  6. ip: ip,
  7. port: port
  8. };
  9. return $http({
  10. url: '/gateway/api/list.json',
  11. params: param,
  12. method: 'GET'
  13. });
  14. };
  15. this.newApi = function (api) {
  16. return $http({
  17. url: '/gateway/api/new.json',
  18. data: api,
  19. method: 'POST'
  20. });
  21. };
  22. this.saveApi = function (api) {
  23. return $http({
  24. url: '/gateway/api/save.json',
  25. data: api,
  26. method: 'POST'
  27. });
  28. };
  29. this.deleteApi = function (api) {
  30. var param = {
  31. id: api.id,
  32. app: api.app
  33. };
  34. return $http({
  35. url: '/gateway/api/delete.json',
  36. params: param,
  37. method: 'POST'
  38. });
  39. };
  40. this.checkApiValid = function (api, apiNames) {
  41. if (api.apiName === undefined || api.apiName === '') {
  42. alert('API名称不能为空');
  43. return false;
  44. }
  45. if (api.predicateItems == null || api.predicateItems.length === 0) {
  46. // Should never happen since no remove button will display when only one predicateItem.
  47. alert('至少有一个匹配规则');
  48. return false;
  49. }
  50. for (var i = 0; i < api.predicateItems.length; i++) {
  51. var predicateItem = api.predicateItems[i];
  52. var pattern = predicateItem.pattern;
  53. if (pattern === undefined || pattern === '') {
  54. alert('匹配串不能为空,请检查');
  55. return false;
  56. }
  57. }
  58. if (apiNames.indexOf(api.apiName) !== -1) {
  59. alert('API名称(' + api.apiName + ')已存在');
  60. return false;
  61. }
  62. return true;
  63. };
  64. }]);