summaryrefslogtreecommitdiffstats
path: root/docs/templates
AgeCommit message (Expand)AuthorFilesLines
2019-06-01Improve security section of release notesKrzysztof Opasiak1-14/+24
2018-04-04Provide structure for VNFsRich Bennett1-0/+29
2017-11-09Restore MultiVIM project & remove apiexamplesRich Bennett6-1487/+0
2017-10-27Merge "Align references to MSB project repo"Gregory Glover1-0/+2
2017-10-27Align references to MSB project repoRich Bennett1-0/+2
2017-10-26Remove http domain directiveRich Bennett2-11/+0
2017-10-20Connect Guides and Release Notes to Project infoRich Bennett1-1/+1
2017-10-18Update Copyright and Licensing markingsRich Bennett2-4/+4
2017-10-18Fix basic tox warningsMorgan Richomme1-427/+332
2017-10-16Improve Release Notes and Template referencesRich Bennett2-0/+0
2017-10-16Sync logging-analytics update release note listRich Bennett1-0/+2
2017-10-10Improve templates and add references in guidesRich Bennett44-279/+1925
2017-09-18Updates to templates based on Webinar FeedbackRich Bennett9-24/+23
2017-09-18Remove linkcheck and add API examplesRich Bennett1-3/+20
2017-09-13Enhancement and additions for webinarRich Bennett26-104/+260
2017-08-24Update How To Guide & Git submodulesRich Bennett1-0/+25
2017-08-16Updates to How to GuideRich Bennett2-2/+16
2017-08-07[DOC-24] Add Component Template, Sphinx 1.6.3Rich Bennett5-38/+68
2017-07-19[DOC-23]Initial structure and Documentation GuideRich Bennett2-0/+38
weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*!
 * Copyright (C) 2017 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.
 */
import { actionTypes } from './PlainDataReducerConstants.js';
import Validator from 'nfvo-utils/Validator.js';
import forOwn from 'lodash/forOwn.js';
import { other as optionInputOther } from 'nfvo-components/input/validation/InputOptions.jsx';

function updateDataAndValidateReducer(state = {}, action) {
    let genericFieldInfoCopy;
    switch (action.type) {
        case actionTypes.DATA_CHANGED:
            let changed = action.deltaData;
            if (!action.formName || state.formName !== action.formName) {
                return { ...state };
            }
            genericFieldInfoCopy = { ...state.genericFieldInfo };
            forOwn(changed, (value, key) => {
                if (state.genericFieldInfo[key]) {
                    let result = Validator.validate(
                        key,
                        value,
                        state.genericFieldInfo[key].validations,
                        state,
                        action.customValidations
                    );
                    genericFieldInfoCopy[key] = {
                        ...genericFieldInfoCopy[key],
                        isValid: result.isValid,
                        errorText: result.errorText
                    };
                }
            });
            return {
                ...state,
                formReady: null,
                data: {
                    ...state.data,
                    ...action.deltaData
                },
                genericFieldInfo: genericFieldInfoCopy
            };
        case actionTypes.VALIDATE_FORM:
            if (!action.formName || state.formName !== action.formName) {
                return { ...state };
            }
            genericFieldInfoCopy = { ...state.genericFieldInfo };
            let formReady = true;
            forOwn(state.genericFieldInfo, (value, key) => {
                let val = state.data && state.data[key] ? state.data[key] : '';
                let result = Validator.validate(
                    key,
                    val,
                    state.genericFieldInfo[key].validations,
                    state,
                    {}
                );
                if (val.choice !== undefined) {
                    result = Validator.validate(
                        key,
                        val.choice,
                        state.genericFieldInfo[key].validations,
                        state,
                        {}
                    );
                }
                if (
                    val.choice !== undefined &&
                    val.choice === optionInputOther.OTHER
                ) {
                    result = Validator.validate(
                        key,
                        val.other,
                        state.genericFieldInfo[key].validations,
                        state,
                        {}
                    );
                }
                genericFieldInfoCopy[key] = {
                    ...genericFieldInfoCopy[key],
                    isValid: result.isValid,
                    errorText: result.errorText
                };
                if (!result.isValid) {
                    formReady = false;
                }
            });
            return {
                ...state,
                formReady,
                genericFieldInfo: genericFieldInfoCopy
            };
        case actionTypes.VALIDATE_DATA:
            let specificFields = action.data;
            if (!action.formName || state.formName !== action.formName) {
                return { ...state };
            }
            genericFieldInfoCopy = { ...state.genericFieldInfo };
            forOwn(specificFields, (value, key) => {
                let result = Validator.validate(
                    key,
                    value,
                    state.genericFieldInfo[key].validations,
                    state,
                    action.customValidations
                );
                genericFieldInfoCopy[key] = {
                    ...genericFieldInfoCopy[key],
                    isValid: result.isValid,
                    errorText: result.errorText
                };
            });
            return {
                ...state,
                formReady: null,
                genericFieldInfo: genericFieldInfoCopy
            };
        default:
            return state;
    }
}

export function createPlainDataReducer(loadReducer) {
    return (state = {}, action) => {
        if (
            action.type === actionTypes.VALIDATE_DATA ||
            action.type === actionTypes.VALIDATE_FORM ||
            action.type === actionTypes.DATA_CHANGED
        ) {
            return updateDataAndValidateReducer(state, action);
        } else {
            return loadReducer(state, action);
        }
    };
}