/*-
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* 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.
* ============LICENSE_END============================================
* ===================================================================
*
*/
import React from 'react'
import Button from 'react-bootstrap/Button';
import Modal from 'react-bootstrap/Modal';
import './OperationalPolicy.css'
import styled from 'styled-components';
const ModalStyled = styled(Modal)`
background-color: transparent;
`
export default class OperationalPolicyModal extends React.Component {
state = {
show: true,
loopCache: this.props.loopCache,
};
allPolicies = [];
policyIds = [];
constructor(props, context) {
super(props, context);
this.handleClose = this.handleClose.bind(this);
this.initPolicySelect = this.initPolicySelect.bind(this);
this.initPolicySelect();
}
handleClose() {
this.setState({ show: false });
this.props.history.push('/')
}
initPolicySelect() {
if (this.allPolicies['operational_policy'] === undefined || this.allPolicies['operational_policy'] === null) {
this.allPolicies = this.state.loopCache.getOperationalPolicyConfigurationJson();
}
// Provision all policies ID first
if (this.policyIds.length === 0 && this.allPolicies['operational_policy'] !== undefined) {
for (let i = 0; i < this.allPolicies['operational_policy']['policies'].length; i++) {
this.policyIds.push(this.allPolicies['operational_policy']['policies'][i]['id']);
}
}
}
renderPolicyIdSelect() {
return (
);
}
serializeElement(element) {
var o = {};
element.serializeArray().forEach(function () {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
// When we change the name of a policy
isDuplicatedId(event) {
// update policy id structure
var formNum = document.getElementById(event.target).closest('.formId').attr('id').substring(6);
var policyId = document.getElementById(event.target).val();
if (this.policyIds.includes(policyId)) {
console.log("Duplicated ID, cannot proceed");
return true;
} else {
this.duplicated = false;
this.policyIds.splice(this.policyIds.indexOf(document.getElementById("#formId" + formNum + " #id").val()), 1);
this.policyIds.push(document.getElementById(event.target).val());
// Update the tab now
document.getElementById("#go_properties_tab" + formNum).text(document.getElementById(event.target).val());
}
}
configureComponents() {
console.log("Load properties to op policy");
// Set the header
document.getElementsByClassName('form-control').forEach(function () {
this.val(this.allPolicies['operational_policy']['controlLoop'][this.id]);
});
// Set the sub-policies
this.allPolicies['operational_policy']['policies'].forEach(function (opPolicyElemIndex, opPolicyElemValue) {
/* var formNum = add_one_more();
forEach(document.getElementsByClassName('policyProperties').find('.form-control'), function(opPolicyPropIndex, opPolicyPropValue) {
$("#formId" + formNum + " .policyProperties").find("#" + opPolicyPropValue.id).val(
allPolicies['operational_policy']['policies'][opPolicyElemIndex][opPolicyPropValue.id]);
});
// Initial TargetResourceId options
initTargetResourceIdOptions(allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target']['type'], formNum);
$.each($('.policyTarget').find('.form-control'), function(opPolicyTargetPropIndex, opPolicyTargetPropValue) {
$("#formId" + formNum + " .policyTarget").find("#" + opPolicyTargetPropValue.id).val(
allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target'][opPolicyTargetPropValue.id]);
});
// update the current tab label
$("#go_properties_tab" + formNum).text(
allPolicies['operational_policy']['policies'][opPolicyElemIndex]['id']);
// Check if there is a guard set for it
$.each(allPolicies['guard_policies'], function(guardElemId, guardElemValue) {
if (guardElemValue.recipe === $($("#formId" + formNum + " #recipe")[0]).val()) {
// Found one, set all guard prop
$.each($('.guardProperties').find('.form-control'), function(guardPropElemIndex,
guardPropElemValue) {
guardElemValue['id'] = guardElemId;
$("#formId" + formNum + " .guardProperties").find("#" + guardPropElemValue.id).val(
guardElemValue[guardPropElemValue.id]);
});
iniGuardPolicyType(guardElemId, formNum);
// And finally enable the flag
$("#formId" + formNum + " #enableGuardPolicy").prop("checked", true);
}
});*/
});
}
render() {
return (
Operational policies