Sha256: 2110527cf3600b0c79bd04647b0eaac62eab9313612fdcef152b198e51c39515

Contents?: true

Size: 1.77 KB

Versions: 10

Compression:

Stored size: 1.77 KB

Contents

import React from 'react';
import * as sort from 'sortabular';
import { translate as __ } from 'foremanReact/common/I18n';

import api from 'foremanReact/API';

import {
  propsToSnakeCase,
  propsToCamelCase,
} from 'foremanReact/common/helpers';

import {
  EXISTING_HOST_SELECTION_INIT,
  EXISTING_HOST_SELECTION_LOAD_HOSTS_SUCCESS,
  EXISTING_HOST_SELECTION_LOAD_HOSTS_FAILURE,
  EXISTING_HOST_SELECTION_SELECTION_CHANGED,
} from './ExistingHostSelectionConstants';

export const initExistingHostSelection = (
  allHosts,
) => dispatch => {
  const initialState = {};

  initialState.alreadyUsedHosts = undefined;
  initialState.serviceId = undefined;
  initialState.selectedHosts = [];
  initialState.hostsInHostgroup = {};
  initialState.allHosts = allHosts;

  dispatch({
    type: EXISTING_HOST_SELECTION_INIT,
    payload: initialState,
  });
}

export const loadHostsOfHostgroup = (
  serviceId,
  additionalData
) => dispatch => {

  const selService = additionalData.services.filter(s => (s.id == serviceId))[0];
  const realUrl = additionalData.url.replace("__hostgroup_id__", selService.hostgroup);

  return api
    .get(realUrl, {}, {})
    .then(({ data }) =>
      dispatch({
        type: EXISTING_HOST_SELECTION_LOAD_HOSTS_SUCCESS,
        payload: {
          hosts: data.results,
          serviceId: parseInt(serviceId),
        }
      })
    )
    .catch(error => dispatch(errorHandler(EXISTING_HOST_SELECTION_LOAD_HOSTS_FAILURE, error)));
};

export const hostSelectionChanged = ({ left, right }) => ({
  type: EXISTING_HOST_SELECTION_SELECTION_CHANGED,
  payload: {
    selection: right.items,
  }
});

const errorHandler = (msg, err) => {
  const error = {
    errorMsg: __('Failed to fetch data from server.'),
    statusText: err,
  };
  return { type: msg, payload: { error } };
};

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
foreman_acd-0.9.7 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js
foreman_acd-0.9.5 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js
foreman_acd-0.9.4 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js
foreman_acd-0.9.3 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js
foreman_acd-0.9.2.3 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js
foreman_acd-0.9.2.2 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js
foreman_acd-0.9.2.1 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js
foreman_acd-0.9.2 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js
foreman_acd-0.9.1 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js
foreman_acd-0.9.0 webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js