Преглед изворни кода

- Adds edit connection functionality

George Vrancianu пре 8 година
родитељ
комит
0410991625

+ 45 - 6
src/actions/ConnectionsActions/ConnectionsActions.js

@@ -34,6 +34,7 @@ let ConnectionsActions = Reflux.createActions({
   resetSelections: {},
   newConnection: { children: ['success', 'failed'] },
   saveEndpoint: { children: ['success', 'failed'] },
+  editEndpoint: { children: ['success', 'failed'] },
   setConnection: {},
   validateConnection: { children: ['success', 'failed'] }
 })
@@ -75,6 +76,7 @@ ConnectionsActions.saveEndpoint.listen((data, secretRef) => {
   }).then(ConnectionsActions.saveEndpoint.success, ConnectionsActions.saveEndpoint.failed)
     .catch(ConnectionsActions.saveEndpoint.failed);
 })
+
 ConnectionsActions.newConnection.listen((data) => {
   if (useSecret) {
     let barbicanPayload = {
@@ -109,6 +111,11 @@ ConnectionsActions.loadConnections.listen(() => {
   }
 })
 
+ConnectionsActions.loadConnections.shouldEmit = () => {
+  let projectId = Reflux.GlobalState.userStore.currentUser.project.id
+  return typeof projectId !== "undefined"
+}
+
 ConnectionsActions.deleteConnection.listen((connection) => {
   let projectId = Reflux.GlobalState.userStore.currentUser.project.id
 
@@ -124,13 +131,45 @@ ConnectionsActions.deleteConnection.listen((connection) => {
         method: "DELETE"
       }).then(ConnectionsActions.deleteConnection.completed(connection), ConnectionsActions.deleteConnection.failed)
     } else {
+      console.log("ASDAJBHADFHBDAF")
       ConnectionsActions.deleteConnection.completed(connection)
     }
-
   }, ConnectionsActions.deleteConnection.failed)
   .catch(ConnectionsActions.deleteConnection.failed);
 })
 
+ConnectionsActions.editEndpoint.listen((connection, data) => {
+  let projectId = Reflux.GlobalState.userStore.currentUser.project.id
+  let payload = null
+  if (connection.connection_info && connection.connection_info.secret_ref) {
+    let uuidIndex = connection.connection_info.secret_ref.lastIndexOf("/")
+    let uuid = connection.connection_info.secret_ref.substr(uuidIndex + 1)
+    Api.sendAjaxRequest({
+      url: servicesUrl.barbican + "/v1/secrets/" + uuid,
+      method: "POST"
+    })
+    payload = {
+      endpoint: {
+        name: data.name,
+        description: data.description,
+        type: data.type,
+        connection_info: {
+          secret_ref: connection.connection_info.secret_ref
+        }
+      }
+    }
+  } else {
+    payload = { endpoint: data }
+  }
+
+  Api.sendAjaxRequest({
+    url: `${servicesUrl.coriolis}/${projectId}/endpoints/${connection.id}`,
+    method: "POST",
+    data: payload
+  }).then(ConnectionsActions.editEndpoint.success, ConnectionsActions.editEndpoint.failed)
+    .catch(ConnectionsActions.editEndpoint.failed);
+})
+
 
 ConnectionsActions.validateConnection.listen((endpoint, callback) => {
   let projectId = Reflux.GlobalState.userStore.currentUser.project.id
@@ -139,11 +178,11 @@ ConnectionsActions.validateConnection.listen((endpoint, callback) => {
     method: "POST",
     data: { "validate-connection": null }
   }).then(response => {
-      if (callback) {
-        callback(response)
-      }
-      ConnectionsActions.validateConnection.completed(response)
-    }, ConnectionsActions.validateConnection.failed)
+    if (callback) {
+      callback(response)
+    }
+    ConnectionsActions.validateConnection.completed(response)
+  }, ConnectionsActions.validateConnection.failed)
     .catch(ConnectionsActions.validateConnection.failed);
 })
 

+ 1 - 1
src/components/AddCloudConnection/AddCloudConnection.js

@@ -107,7 +107,7 @@ class AddCloudConnection extends Reflux.Component {
       })
       this.props.addHandle(this.state.connectionName);
     } else {
-      ConnectionsActions.saveEndpoint(this.props.connection, {
+      ConnectionsActions.editEndpoint(this.props.connection, {
         name: this.state.connectionName,
         description: this.state.description,
         type: this.state.currentCloud.name,

+ 5 - 0
src/stores/ConnectionsStore/ConnectionsStore.js

@@ -216,6 +216,7 @@ class ConnectionsStore extends Reflux.Store
     if (this.state.connections) {
       let connection = this.state.connections.filter((connection => connection.id == connectionId))[0]
       if (connection.connection_info && connection.connection_info.secret_ref) {
+        console.log("secret_ref", connection.connection_info.secret_ref)
         let index = connection.connection_info.secret_ref.lastIndexOf("/")
         let uuid = connection.connection_info.secret_ref.substr(index + 1)
 
@@ -257,10 +258,14 @@ class ConnectionsStore extends Reflux.Store
   }
 
   onDeleteConnectionCompleted(connection) {
+    console.log("DELETED", connection)
     let connections = this.state.connections
+    console.log(connections.length)
     let index = connections.indexOf(connection)
     connections.splice(index, 1)
+    console.log(connections.length)
     this.setState({ connections: connections })
+
     ConnectionsActions.assignConnectionProvider()
   }