EndpointActions.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. // @flow
  15. import alt from '../alt'
  16. import EndpointSource from '../sources/EndpointSource'
  17. class EndpointActions {
  18. getEndpoints(options) {
  19. return {
  20. ...options,
  21. promise: EndpointSource.getEndpoints().then(
  22. endpoints => { this.getEndpointsCompleted(endpoints) },
  23. response => { this.getEndpointsFailed(response) }
  24. ),
  25. }
  26. }
  27. getEndpointsCompleted(endpoints) {
  28. return endpoints
  29. }
  30. getEndpointsFailed(response) {
  31. return response || true
  32. }
  33. delete(endpoint) {
  34. EndpointSource.delete(endpoint).then(
  35. () => { this.deleteSuccess(endpoint.id) },
  36. response => { this.deleteFailed(response) },
  37. )
  38. return endpoint
  39. }
  40. deleteSuccess(endpointId) {
  41. return endpointId
  42. }
  43. deleteFailed(response) {
  44. return response || true
  45. }
  46. getConnectionInfo(endpoint) {
  47. EndpointSource.getConnectionInfo(endpoint).then(
  48. connectionInfo => { this.getConnectionInfoSuccess(connectionInfo) },
  49. response => { this.getConnectionInfoFailed(response) },
  50. )
  51. return endpoint || true
  52. }
  53. getConnectionInfoSuccess(connectionInfo) {
  54. return connectionInfo
  55. }
  56. getConnectionInfoFailed(response) {
  57. return response || true
  58. }
  59. validate(endpoint) {
  60. EndpointSource.validate(endpoint).then(
  61. validation => { this.validateSuccess(validation) },
  62. response => { this.validateFailed(response) },
  63. )
  64. return endpoint
  65. }
  66. validateSuccess(validation) {
  67. return validation
  68. }
  69. validateFailed(response) {
  70. return response || true
  71. }
  72. clearValidation() {
  73. return true
  74. }
  75. update(endpoint) {
  76. return {
  77. endpoint,
  78. promise: EndpointSource.update(endpoint).then(
  79. endpointResponse => { this.updateSuccess(endpointResponse) },
  80. response => { this.updateFailed(response) },
  81. ),
  82. }
  83. }
  84. updateSuccess(endpoint) {
  85. return endpoint
  86. }
  87. updateFailed(response) {
  88. return response || true
  89. }
  90. clearConnectionInfo() {
  91. return true
  92. }
  93. add(endpoint) {
  94. return {
  95. endpoint,
  96. promise: EndpointSource.add(endpoint).then(
  97. endpointResponse => { this.addSuccess(endpointResponse) },
  98. response => { this.addFailed(response) },
  99. ),
  100. }
  101. }
  102. addSuccess(endpoint) {
  103. return endpoint
  104. }
  105. addFailed(response) {
  106. throw response
  107. }
  108. }
  109. export default alt.createActions(EndpointActions)