authority_service.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Authority rule service.
  3. */
  4. angular.module('sentinelDashboardApp').service('AuthorityRuleService', ['$http', function ($http) {
  5. this.queryMachineRules = function(app, ip, port) {
  6. var param = {
  7. app: app,
  8. ip: ip,
  9. port: port
  10. };
  11. return $http({
  12. url: '/authority/rules',
  13. params: param,
  14. method: 'GET'
  15. });
  16. };
  17. this.addNewRule = function(rule) {
  18. return $http({
  19. url: '/authority/rule',
  20. data: rule,
  21. method: 'POST'
  22. });
  23. };
  24. this.saveRule = function (entity) {
  25. return $http({
  26. url: '/authority/rule/' + entity.id,
  27. data: entity,
  28. method: 'PUT'
  29. });
  30. };
  31. this.deleteRule = function (entity) {
  32. return $http({
  33. url: '/authority/rule/' + entity.id,
  34. method: 'DELETE'
  35. });
  36. };
  37. this.checkRuleValid = function checkRuleValid(rule) {
  38. if (rule.resource === undefined || rule.resource === '') {
  39. alert('资源名称不能为空');
  40. return false;
  41. }
  42. if (rule.limitApp === undefined || rule.limitApp === '') {
  43. alert('流控针对应用不能为空');
  44. return false;
  45. }
  46. if (rule.strategy === undefined) {
  47. alert('必须选择黑白名单模式');
  48. return false;
  49. }
  50. return true;
  51. };
  52. }]);