EndpointActions.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import alt from '../alt'
  15. import EndpointSource from '../sources/EndpointSource'
  16. class EndpointActions {
  17. getEndpoints(options) {
  18. return {
  19. ...options,
  20. promise: EndpointSource.getEndpoints().then(
  21. endpoints => { this.getEndpointsCompleted(endpoints) },
  22. response => { this.getEndpointsFailed(response) }
  23. ),
  24. }
  25. }
  26. getEndpointsCompleted(endpoints) {
  27. return endpoints
  28. }
  29. getEndpointsFailed(response) {
  30. return response || true
  31. }
  32. delete(endpoint) {
  33. EndpointSource.delete(endpoint).then(
  34. () => { this.deleteSuccess(endpoint.id) },
  35. response => { this.deleteFailed(response) },
  36. )
  37. return endpoint
  38. }
  39. deleteSuccess(endpointId) {
  40. return endpointId
  41. }
  42. deleteFailed(response) {
  43. return response || true
  44. }
  45. getConnectionInfo(endpoint) {
  46. EndpointSource.getConnectionInfo(endpoint).then(
  47. connectionInfo => { this.getConnectionInfoSuccess(connectionInfo) },
  48. response => { this.getConnectionInfoFailed(response) },
  49. )
  50. return endpoint || true
  51. }
  52. getConnectionInfoSuccess(connectionInfo) {
  53. return connectionInfo
  54. }
  55. getConnectionInfoFailed(response) {
  56. return response || true
  57. }
  58. validate(endpoint) {
  59. EndpointSource.validate(endpoint).then(
  60. validation => { this.validateSuccess(validation) },
  61. response => { this.validateFailed(response) },
  62. )
  63. return endpoint
  64. }
  65. validateSuccess(validation) {
  66. return validation
  67. }
  68. validateFailed(response) {
  69. return response || true
  70. }
  71. clearValidation() {
  72. return true
  73. }
  74. update(endpoint) {
  75. return {
  76. endpoint,
  77. promise: EndpointSource.update(endpoint).then(
  78. endpointResponse => { this.updateSuccess(endpointResponse) },
  79. response => { this.updateFailed(response) },
  80. ),
  81. }
  82. }
  83. updateSuccess(endpoint) {
  84. return endpoint
  85. }
  86. updateFailed(response) {
  87. return response || true
  88. }
  89. clearConnectionInfo() {
  90. return true
  91. }
  92. add(endpoint) {
  93. return {
  94. endpoint,
  95. promise: EndpointSource.add(endpoint).then(
  96. endpointResponse => { this.addSuccess(endpointResponse) },
  97. response => { this.addFailed(response) },
  98. ),
  99. }
  100. }
  101. addSuccess(endpoint) {
  102. return endpoint
  103. }
  104. addFailed(response) {
  105. throw response
  106. }
  107. }
  108. export default alt.createActions(EndpointActions)