garrensmith commented on a change in pull request #1045: Migrate couchdb setup 
to Redux
URL: https://github.com/apache/couchdb-fauxton/pull/1045#discussion_r164653611
 
 

 ##########
 File path: app/addons/setup/actions.js
 ##########
 @@ -0,0 +1,369 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy 
of
+// the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations 
under
+// the License.
+import FauxtonAPI from "../../core/api";
+import 'whatwg-fetch';
+import {isInvalid} from "./helpers";
+import {
+  SETUP_ADD_NODE_TO_LIST,
+  SETUP_BIND_ADDRESS_ADDITIONAL_NODE,
+  SETUP_BIND_ADDRESS_FOR_SINGLE_NODE,
+  SETUP_NODE_COUNT,
+  SETUP_PORT_ADDITIONAL_NODE,
+  SETUP_PORT_FOR_SINGLE_NODE,
+  SETUP_REMOTE_ADDRESS_ADDITIONAL_NODE,
+  SETUP_RESET_ADDITIONAL_NODE,
+  SETUP_SET_CLUSTERSTATUS,
+  SETUP_SET_PASSWORD,
+  SETUP_SET_USERNAME
+} from "./actiontypes";
+import {get, rejectFetchError} from '../../core/ajax';
+import Api from "../auth/api";
+
+
+/**
+ * @typedef {Object} CredentialObject
+ * @param {string} username The username
+ * @param {string} password The password
+ */
+
+
+/**
+ * Public functions
+ */
+
+const getFetchOpts = (method = 'GET', body) => {
+  const hasBody = method === 'POST' || method === 'PUT';
+  let headers = {'Accept': 'application/json'};
+  if (hasBody)
+    headers['Content-Type'] = 'application/json';
+  let options = {
+    credentials: 'include',
+    method,
+    headers
+  };
+
+  if (hasBody)
+    options.body = JSON.stringify(body);
+
+  return options;
+};
+
+
+export const getClusterStateFromCouch = () => dispatch => {
+  const baseUrl = FauxtonAPI.urls('cluster_setup', 'server');
+  return get(baseUrl, {
+    headers: {'Accept': 'application/json'},
+    credentials: 'include'
+  }).then(json => {
+    dispatch({
+      type: SETUP_SET_CLUSTERSTATUS,
+      options: {
+        state: json.state
+      }
+    });
+  });
+};
+
+export const finishClusterSetup = message => () => {
+  const baseUrl = FauxtonAPI.urls('cluster_setup', 'server');
+  const body = {action: 'finish_cluster'};
+  fetch(baseUrl, getFetchOpts('POST', body)).then(response => {
 
 Review comment:
   You can pass in a flag to the ajax helpers to not convert it to json

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to