Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
GilbertCherrie committed Oct 13, 2022
1 parent 3f74d5d commit 8525f7b
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 13 deletions.
69 changes: 66 additions & 3 deletions app/javascript/components/order-service-form/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ const checkBoxes = [];
let hasTime = false;
let stopSubmit = false;
let invalidDateFields = [];
const dynamicFields = [];
const refreshFields = [];

const buildTextBox = (field, validate) => {
let component = {};
console.log(field);
// if (field.dialog_field_responders.length > 0) {
// field.dialog_field_responders.forEach((tempField) => {
// console.log(tempField);
// dynamicFields.forEach((fieldToRefresh) => {
// if (fieldToRefresh.field === tempField) {
// console.log(fieldToRefresh);
// }
// });
// });
// }

if (field.options.protected) {
component = {
component: 'password-field',
Expand All @@ -35,6 +49,51 @@ const buildTextBox = (field, validate) => {
initialValue: field.default_value,
description: field.description,
validate,
// resolveProps: (props, { meta, input }, formOptions) => {
// console.log(props);
// console.log(meta);
// console.log(input);
// console.log(formOptions);
// if (!formOptions.pristine) {
// if (field.dialog_field_responders.length > 0) {
// field.dialog_field_responders.forEach((tempField) => {
// console.log(tempField);
// dynamicFields.forEach((fieldToRefresh) => {
// if (fieldToRefresh.field === tempField) {
// const refreshData = {
// action: 'refresh_dialog_fields',
// resource: {
// dialog_fields: {
// // credential: null,
// hosts: 'localhost0',
// // param_provider_id: '38',
// // param_miq_username: 'admin',
// // param_miq_password: 'smartvm',
// // check_box_1: 't',
// // dropdown_list_1_1: null,
// // textarea_box_1: '',
// // date_time_control_1: '2022-10-12T20:50:45.180Z',
// // date_time_control_2: '2022-10-12T20:50:45.180Z',
// // date_control_1: '2022-10-12',
// // date_control_2_1: '2022-09-27',
// },
// fields: ['credential'],
// resource_action_id: '2018',
// target_id: '14',
// target_type: 'service_template',
// real_target_type: 'ServiceTemplate',
// },
// };
// fieldToRefresh.values = API.post(`/api/service_dialogs/10`, refreshData).then((data) => {
// console.log(data);
// });
// console.log(fieldToRefresh);
// }
// });
// });
// }
// }
// },
};
}
return component;
Expand Down Expand Up @@ -69,6 +128,8 @@ const buildCheckBox = (field, validate) => ({
const buildDropDownList = (field, validate) => {
let options = [];
let placeholder = __('<Choose>');
let start;

field.values.forEach((value) => {
if (value[0] === null) {
value[0] = null;
Expand All @@ -78,7 +139,11 @@ const buildDropDownList = (field, validate) => {
options.push({ value: value[0] !== null ? String(value[0]) : null, label: value[1] });
});

let start;
// if (field.dynamic) {
// dynamicFields.push({ field: field.name, id: field.id, values: options });
// console.log(dynamicFields);
// }

if (options[0].value === null) {
start = options.shift();
}
Expand Down Expand Up @@ -356,7 +421,6 @@ const handleTimePickerSubmit = (submitData) => {
// Add field label to list of invalid date fields
invalidDateFields.push(dateField.label);
}
// Set state of invalid date fields once done looping through all fields
});
}
}
Expand Down Expand Up @@ -391,7 +455,6 @@ const handleDatePickerSubmit = (submitData) => {
// Add field label to list of invalid date fields
invalidDateFields.push(dateField.label);
}
// Set state of invalid date fields once done looping through all fields
});
}
}
Expand Down
24 changes: 16 additions & 8 deletions app/javascript/components/order-service-form/index.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { useState, useEffect } from 'react';
// import MiqFormRenderer from '@@ddf';
import PropTypes from 'prop-types';
import MiqFormRenderer, { useFormApi } from '@@ddf';
// import { componentTypes, validatorTypes } from '@data-driven-forms/react-form-renderer';
import { Button } from 'carbon-components-react';
import { FormSpy } from '@data-driven-forms/react-form-renderer';
import createSchema from './order-service-form.schema';
Expand All @@ -17,8 +15,7 @@ const OrderServiceForm = ({
// eslint-disable-next-line no-unused-vars
isLoading, initialValues, fields, hasTime, showPastDates, showPastDatesFieldErrors, dateErrorFields, checkBoxes, dates,
}, setState] = useState({
// isLoading: !!dialogId,
isLoading: false,
isLoading: true,
fields: [],
hasTime: false,
showPastDates: [],
Expand All @@ -28,11 +25,23 @@ const OrderServiceForm = ({
dates: [],
});
const [showDateError, setShowDateError] = useState([]);
// const [dynamicFieldValues, setDynamicFieldValues] = useState({});

// console.log(dialogId);
// console.log(resourceActionId);
// console.log(targetId);
// console.log(targetType);
// console.log(apiSubmitEndpoint);
// console.log(apiAction);
// console.log(openUrl);
// console.log(realTargetType);
// console.log(finishSubmitEndpoint);

useEffect(() => {
API.get(`/api/service_dialogs/${dialogId}?resource_action_id=${resourceActionId}&target_id=${targetId}&target_type=${targetType}`)
.then((data) => {
buildFields(data, setState);
console.log(data);
});
}, []);

Expand Down Expand Up @@ -136,11 +145,10 @@ OrderServiceForm.propTypes = {
targetId: PropTypes.number.isRequired,
targetType: PropTypes.string.isRequired,
apiSubmitEndpoint: PropTypes.string.isRequired,
apiAction: PropTypes.string.isRequired,
openUrl: PropTypes.bool.isRequired,
};

OrderServiceForm.defaultProps = {
// dialogId: undefined,
realTargetType: PropTypes.string.isRequired,
finishSubmitEndpoint: PropTypes.string.isRequired,
};

export default OrderServiceForm;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { componentTypes } from '@@ddf';

const showDateErrorFields = (fields) => {
console.log(fields);
let invalidFields;
fields.forEach((field) => {
if (invalidFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefr
vm.isValid = false;

function refreshField(field) {
console.log(field);
// API.post(field.href).then((data) => {
// console.log(data);
// });
var idList = {
dialogId: dialogId,
resourceActionId: resourceActionId,
Expand Down
6 changes: 6 additions & 0 deletions app/javascript/oldjs/services/dialog_field_refresh_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ ManageIQ.angular.app.service('dialogFieldRefreshService', ['API', 'DialogData',
},
};

console.log(data);
console.log(angular.toJson(data));

console.log(url);
console.log(idList.dialogId);

return API.post(url + idList.dialogId, angular.toJson(data))
.then(function(response) {
// FIXME: API requests don't actually count towards $.active
Expand Down
Loading

0 comments on commit 8525f7b

Please sign in to comment.