diff options
Diffstat (limited to 'src/editAttributes')
-rw-r--r-- | src/editAttributes/AppStore.js | 56 | ||||
-rw-r--r-- | src/editAttributes/Application.jsx | 42 | ||||
-rw-r--r-- | src/editAttributes/EditAttributeActions.js | 97 | ||||
-rw-r--r-- | src/editAttributes/EditAttributeConstants.js | 50 | ||||
-rw-r--r-- | src/editAttributes/EditAttributeReducer.js | 56 | ||||
-rw-r--r-- | src/editAttributes/EditAttributes.jsx | 116 | ||||
-rw-r--r-- | src/editAttributes/changeAttributeForm/ChangeAttributeForm.jsx | 161 | ||||
-rw-r--r-- | src/editAttributes/changeAttributeForm/ChangeAttributeFormConstants.js | 46 | ||||
-rw-r--r-- | src/editAttributes/changeAttributeForm/ChangeAttributeFormReducer.js | 38 | ||||
-rw-r--r-- | src/editAttributes/changeAttributeForm/validate.js | 51 | ||||
-rw-r--r-- | src/editAttributes/index.html | 12 | ||||
-rw-r--r-- | src/editAttributes/main.app.jsx | 38 | ||||
-rw-r--r-- | src/editAttributes/networking/NetworkCalls.js | 37 | ||||
-rw-r--r-- | src/editAttributes/networking/NetworkConstants.js | 39 | ||||
-rw-r--r-- | src/editAttributes/networking/NetworkUtils.js | 34 |
15 files changed, 873 insertions, 0 deletions
diff --git a/src/editAttributes/AppStore.js b/src/editAttributes/AppStore.js new file mode 100644 index 0000000..cc626a0 --- /dev/null +++ b/src/editAttributes/AppStore.js @@ -0,0 +1,56 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +import {combineReducers, createStore, compose, applyMiddleware} from 'redux'; +import thunkMiddleware from 'redux-thunk'; +import {reducer as formReducer} from 'redux-form'; + +import SetAttributeReducer from './EditAttributeReducer.js'; + +function createCompose() { + if (window.devToolsExtension) { + return compose( + applyMiddleware(thunkMiddleware), + window.devToolsExtension()); + } + else { + return applyMiddleware(thunkMiddleware); + } +} + +export const storeCreator = (initialState) => createStore( + combineReducers({ + setAttributes: SetAttributeReducer, + form: formReducer + }), + initialState, + createCompose() +); + + +const store = storeCreator(); + +export default store; + diff --git a/src/editAttributes/Application.jsx b/src/editAttributes/Application.jsx new file mode 100644 index 0000000..99a4d8d --- /dev/null +++ b/src/editAttributes/Application.jsx @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +import React, {Component} from 'react'; +import {Provider} from 'react-redux'; +import store from 'editAttributes/AppStore.js'; + + +class Application extends Component { + + render() { + return ( + <Provider store={store}> + {this.props.children} + </Provider> + ); + } +} + +export default Application; diff --git a/src/editAttributes/EditAttributeActions.js b/src/editAttributes/EditAttributeActions.js new file mode 100644 index 0000000..871260a --- /dev/null +++ b/src/editAttributes/EditAttributeActions.js @@ -0,0 +1,97 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +import NetworkCalls from './networking/NetworkCalls.js'; +import { + POST, + BACKEND_POST_HEADER, + CREDENTIALS +} from './networking/NetworkConstants.js'; +import { + createEditEntityAttributeRequestObject +} from './networking/NetworkUtils.js'; +import { + setAttributesActionTypes, + EDIT_ENTITY_ATTRIBUTES_URL, + RESPONSE_CODE_SUCCESS, + RESPONSE_CODE_NOT_AUTHORIZED, + RESPONSE_MESSAGE_SUCCESS, + RESPONSE_MESSAGE_NOT_AUTHORIZED, + RESPONSE_MESSAGE_FAILURE, + RESPONSE_MESSAGE_NETWORK_ERROR +} from './EditAttributeConstants.js'; + +function errorReturnedEvent(errorMsg) { + return { + type: setAttributesActionTypes.SET_ATTRIBUTE_ERROR, + data: {errorMsg: errorMsg} + }; +} + +function successReturnedEvent() { + return { + type: setAttributesActionTypes.SET_ATTRIBUTE_SUCCESS, + data: {successMsg: RESPONSE_MESSAGE_SUCCESS} + }; +} + +function clearFeedbackMessageEvent() { + return { + type: setAttributesActionTypes.CLEAR_FEEDBACK_MESSAGE, + data: {} + }; +} + +export function clearFeebackMessage() { + return dispatch => { + dispatch(clearFeedbackMessageEvent()); + }; +} + +export function requestEditEntityAttributes(entityURI, entityAttributes) { + + let postBody = JSON.stringify( + createEditEntityAttributeRequestObject(entityURI, entityAttributes)); + return dispatch => { + return NetworkCalls.fetchRequest(EDIT_ENTITY_ATTRIBUTES_URL, + CREDENTIALS, POST, BACKEND_POST_HEADER, postBody).then( + (responseJson) => { + if (responseJson) { + if (responseJson.resultCode === RESPONSE_CODE_SUCCESS) { + dispatch(successReturnedEvent()); + } else if (responseJson.resultCode === RESPONSE_CODE_NOT_AUTHORIZED) { + dispatch(errorReturnedEvent(RESPONSE_MESSAGE_NOT_AUTHORIZED)); + } else { + dispatch(errorReturnedEvent(RESPONSE_MESSAGE_FAILURE)); + } + } + } + ).catch( + () => { + dispatch(errorReturnedEvent(RESPONSE_MESSAGE_NETWORK_ERROR)); + } + ); + }; +} diff --git a/src/editAttributes/EditAttributeConstants.js b/src/editAttributes/EditAttributeConstants.js new file mode 100644 index 0000000..3371091 --- /dev/null +++ b/src/editAttributes/EditAttributeConstants.js @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +import keyMirror from 'utils/KeyMirror.js'; +import { + BASE_URL +} from './networking/NetworkConstants.js'; + +export const SET_ATTRIBUTE_TITLE = 'A&AI'; +export const ATTRIBUTE_MODIFICATION = 'ATTRIBUTE MODIFICATION'; + + + +export const EDIT_ENTITY_ATTRIBUTES_URL = BASE_URL + '/editEntity/editAttributes'; + +export const RESPONSE_CODE_SUCCESS = 200; +export const RESPONSE_CODE_NOT_AUTHORIZED = 403; + +export const RESPONSE_MESSAGE_SUCCESS = 'Success'; +export const RESPONSE_MESSAGE_NOT_AUTHORIZED = 'User not authorized'; +export const RESPONSE_MESSAGE_FAILURE = 'Failed to update entity'; +export const RESPONSE_MESSAGE_NETWORK_ERROR = 'Network error'; + +export const setAttributesActionTypes = keyMirror({ + SET_ATTRIBUTE_ERROR: null, + SET_ATTRIBUTE_SUCCESS: null, + CLEAR_FEEDBACK_MESSAGE: null +}); diff --git a/src/editAttributes/EditAttributeReducer.js b/src/editAttributes/EditAttributeReducer.js new file mode 100644 index 0000000..5c55435 --- /dev/null +++ b/src/editAttributes/EditAttributeReducer.js @@ -0,0 +1,56 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +import {setAttributesActionTypes} from './EditAttributeConstants.js'; +import { + MESSAGE_LEVEL_SUCCESS, + MESSAGE_LEVEL_DANGER +} from 'utils/GlobalConstants.js'; + +export default (state = {}, action) => { + switch (action.type) { + case setAttributesActionTypes.SET_ATTRIBUTE_ERROR: + return { + ...state, + feedbackMsgText: action.data.errorMsg, + feedbackMsgSeverity: MESSAGE_LEVEL_DANGER + }; + + case setAttributesActionTypes.SET_ATTRIBUTE_SUCCESS: + return { + ...state, + feedbackMsgText: action.data.successMsg, + feedbackMsgSeverity: MESSAGE_LEVEL_SUCCESS + }; + + case setAttributesActionTypes.CLEAR_FEEDBACK_MESSAGE: + return { + ...state, + feedbackMsgText: '', + feedbackMsgSeverity: '' + }; + } + return state; +}; diff --git a/src/editAttributes/EditAttributes.jsx b/src/editAttributes/EditAttributes.jsx new file mode 100644 index 0000000..ab2d391 --- /dev/null +++ b/src/editAttributes/EditAttributes.jsx @@ -0,0 +1,116 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +import React, {Component} from 'react'; +import {connect} from 'react-redux'; +import i18n from 'utils/i18n/i18n'; + +import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx'; +import { + clearFeebackMessage, + requestEditEntityAttributes +} from './EditAttributeActions.js'; +import { + SET_ATTRIBUTE_TITLE, + ATTRIBUTE_MODIFICATION +} from './EditAttributeConstants.js'; +import ChangeAttributeForm from 'editAttributes/changeAttributeForm/ChangeAttributeForm.jsx'; +import {NO_VALUE_SELECTED} from 'editAttributes/changeAttributeForm/ChangeAttributeFormConstants.js'; + +let mapStateToProps = ({setAttributes}) => { + let { + feedbackMsgText = '', + feedbackMsgSeverity = '' + } = setAttributes; + + return { + feedbackMsgText, + feedbackMsgSeverity + }; +}; + +let mapActionToProps = (dispatch) => { + return { + handleSubmit: (values) => { + let uri = values.uri; + let attrMap = new Map(); + attrMap.set('provStatus', 'prov-status'); + attrMap.set('inMaint', 'in-maint'); + attrMap.set('isClosedLoopDisabled', 'is-closed-loop-disabled'); + + let attributes = {}; + let valueString = JSON.stringify(values); + JSON.parse(valueString, (key, value) => { + if(value !== NO_VALUE_SELECTED) { + let formattedKey = attrMap.get(key); + if(formattedKey !== undefined) { + attributes = { + ...attributes, [formattedKey]: value + }; + } + return value; + } + }); + + dispatch(requestEditEntityAttributes(uri, attributes)); + }, + clearFeedbackMessage: () => { + dispatch(clearFeebackMessage()); + } + }; +}; + +class SetAttribute extends Component { + render() { + let { + feedbackMsgText, + feedbackMsgSeverity, + handleSubmit, + clearFeedbackMessage} = this.props; + return ( + <div> + <div className='header'> + <div className='application-title'>{i18n(SET_ATTRIBUTE_TITLE)}</div> + </div> + <div className='secondary-header'> + <span + className='secondary-title'>{i18n(ATTRIBUTE_MODIFICATION)}</span> + <InlineMessage level={feedbackMsgSeverity} + messageTxt={feedbackMsgText}/> + </div> + + <ChangeAttributeForm + onSubmit={(values) => { + handleSubmit(values); + }} + buttonSelected={() => { + clearFeedbackMessage(); + }}/> + </div> + ); + } +} + +export default connect(mapStateToProps, mapActionToProps)(SetAttribute); diff --git a/src/editAttributes/changeAttributeForm/ChangeAttributeForm.jsx b/src/editAttributes/changeAttributeForm/ChangeAttributeForm.jsx new file mode 100644 index 0000000..34ba98d --- /dev/null +++ b/src/editAttributes/changeAttributeForm/ChangeAttributeForm.jsx @@ -0,0 +1,161 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +import React, {Component} from 'react'; +import {Field, Fields, reduxForm, propTypes} from 'redux-form'; +import i18n from 'utils/i18n/i18n'; + +import { + LABEL_NODE_URI, + LABEL_PROV_STATUS, + LABEL_ATTRIBUTES, + LABEL_IN_MAINT, + LABEL_IS_CLOSED_LOOP, + BUTTON_SUBMIT, + BUTTON_CLEAR, + NO_VALUE_SELECTED, + PREPROV, + NVTPROV, + DECOM, + PROV, + CAPPED, + RETIRED, + TRUE, + FALSE +} from './ChangeAttributeFormConstants.js'; +import validate from './validate.js'; + +class ChangeAttributeForm extends Component { + + static propTypes = { + ...propTypes + }; + + renderTextField = ({input, label, type, meta: {touched, error}}) => ( + <div className='attribute-field'> + <label>{label}</label> + <div> + <input {...input} placeholder={label} type={type} + onBlur={() => input.value === '' ? input.onBlur(' ') : input.onBlur()}/> + {touched && ((error && <span className='error-message'>{error}</span>))} + </div> + </div> + ); + + + booleanOptions = [ + <option value={NO_VALUE_SELECTED}>{i18n(NO_VALUE_SELECTED)}</option>, + <option value='true'>{i18n(TRUE)}</option>, + <option value='false'>{i18n(FALSE)}</option> + ]; + + provStatusOptions = [ + <option value={NO_VALUE_SELECTED}>{i18n(NO_VALUE_SELECTED)}</option>, + <option value={PREPROV}>{PREPROV}</option>, + <option value={NVTPROV}>{NVTPROV}</option>, + <option value={PROV}>{PROV}</option>, + <option value={CAPPED}>{CAPPED}</option>, + <option value={DECOM}>{DECOM}</option>, + <option value={RETIRED}>{RETIRED}</option> + ]; + + renderAttributeFields = (fields) => ( + <div> + <div className='centre'> + {(fields.provStatus.meta.touched || + fields.inMaint.meta.touched || + fields.isClosedLoopDisabled.meta.touched) && + fields.provStatus.meta.error && + <span className='error-message'>{fields.provStatus.meta.error}</span>} + </div> + <div className='attribute-field'> + <label>{LABEL_PROV_STATUS}</label> + <div> + <select {...fields.provStatus.input}> + {this.provStatusOptions} + </select> + </div> + </div> + <div className='attribute-field'> + <label>{LABEL_IN_MAINT}</label> + <div> + <select {...fields.inMaint.input}> + {this.booleanOptions} + </select> + </div> + </div> + <div className='attribute-field'> + <label>{LABEL_IS_CLOSED_LOOP}</label> + <div> + <select {...fields.isClosedLoopDisabled.input}> + {this.booleanOptions} + </select> + </div> + </div> + </div> + ); + + render() { + const { + handleSubmit, + buttonSelected, + pristine, + reset, + submitting} = this.props; + + return ( + <form onSubmit={handleSubmit}> + <Field name='uri' type='text' component={this.renderTextField} + label={i18n(LABEL_NODE_URI)}/> + <div className='centre'><h2>{i18n(LABEL_ATTRIBUTES)}</h2></div> + <Fields names={['provStatus', 'inMaint', 'isClosedLoopDisabled']} + component={this.renderAttributeFields}/> + <div className='centre'> + <button type='submit' + disabled={pristine || submitting} + onClick={() => { + buttonSelected(); + }}> + {i18n(BUTTON_SUBMIT)} + </button> + <button type='button' + disabled={pristine || submitting} + onClick={() => { + reset(); + buttonSelected(); + }}> + {i18n(BUTTON_CLEAR)} + </button> + </div> + </form> + ); + } +} + +export default reduxForm({ + form: 'changeAttributeForm', + validate +})(ChangeAttributeForm); + diff --git a/src/editAttributes/changeAttributeForm/ChangeAttributeFormConstants.js b/src/editAttributes/changeAttributeForm/ChangeAttributeFormConstants.js new file mode 100644 index 0000000..02e8996 --- /dev/null +++ b/src/editAttributes/changeAttributeForm/ChangeAttributeFormConstants.js @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +export const LABEL_NODE_URI = 'Target Entity URI'; +export const LABEL_PROV_STATUS = 'prov-status'; +export const LABEL_IN_MAINT = 'in-maint'; +export const LABEL_IS_CLOSED_LOOP = 'is-closed-loop-disabled'; +export const LABEL_ATTRIBUTES = 'ATTRIBUTES'; + +export const BUTTON_SUBMIT = 'Submit'; +export const BUTTON_CLEAR = 'Clear'; + +export const NO_VALUE_SELECTED = 'No Value Selected'; +export const PREPROV = 'PREPROV'; +export const NVTPROV = 'NVTPROV'; +export const PROV = 'PROV'; +export const CAPPED = 'CAPPED'; +export const DECOM = 'DECOM'; +export const RETIRED = 'RETIRED'; +export const TRUE = 'TRUE'; +export const FALSE = 'FALSE'; + +export const ERROR_MISSING_ATTR = 'At least one attribute must be set'; +export const ERROR_REQUIRED = 'Required'; diff --git a/src/editAttributes/changeAttributeForm/ChangeAttributeFormReducer.js b/src/editAttributes/changeAttributeForm/ChangeAttributeFormReducer.js new file mode 100644 index 0000000..0778a0e --- /dev/null +++ b/src/editAttributes/changeAttributeForm/ChangeAttributeFormReducer.js @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +/*import { combineReducers } from 'redux' + import { reducer as formReducer } from 'redux-form' + + + + const reducer = combineReducers({ + form: formReducer.validation({ + changeAttributeForm: validate + }) + }); + + export default reducer; + */ diff --git a/src/editAttributes/changeAttributeForm/validate.js b/src/editAttributes/changeAttributeForm/validate.js new file mode 100644 index 0000000..d6a8d99 --- /dev/null +++ b/src/editAttributes/changeAttributeForm/validate.js @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +import i18n from 'utils/i18n/i18n'; + +import { + ERROR_MISSING_ATTR, + ERROR_REQUIRED, + NO_VALUE_SELECTED +} from './ChangeAttributeFormConstants.js'; + +const validate = (values) => { + const errors = {}; + + if (!values.uri || values.uri.replace(/\s/g, '') === '') { + errors.uri = i18n(ERROR_REQUIRED); + } + if ((!values.provStatus || values.provStatus === NO_VALUE_SELECTED) && + (!values.inMaint || values.inMaint === NO_VALUE_SELECTED) && + (!values.isClosedLoopDisabled || + values.isClosedLoopDisabled === + NO_VALUE_SELECTED)) { + errors.provStatus = i18n(ERROR_MISSING_ATTR); + } + + return errors; +}; + +export default validate; diff --git a/src/editAttributes/index.html b/src/editAttributes/index.html new file mode 100644 index 0000000..45c0d04 --- /dev/null +++ b/src/editAttributes/index.html @@ -0,0 +1,12 @@ +<html> +<head> + <meta charset="utf-8"> + <title>Edit Attributes</title> +</head> + +<body> +<div id="set-attribute-app"></div> +</body> + +<script src="editAttributesBundle.js"></script> +</html> diff --git a/src/editAttributes/main.app.jsx b/src/editAttributes/main.app.jsx new file mode 100644 index 0000000..b760db0 --- /dev/null +++ b/src/editAttributes/main.app.jsx @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +import React from 'react'; +import ReactDOM from 'react-dom'; + +import 'resources/scss/bootstrap.scss'; +import 'resources/css/font-awesome.min.css'; +import 'resources/scss/style.scss'; + +import Application from './Application.jsx'; +import SetAttribute from './EditAttributes.jsx'; + +ReactDOM.render( + <Application><SetAttribute /></Application>, + document.getElementById('set-attribute-app')); diff --git a/src/editAttributes/networking/NetworkCalls.js b/src/editAttributes/networking/NetworkCalls.js new file mode 100644 index 0000000..a107aa6 --- /dev/null +++ b/src/editAttributes/networking/NetworkCalls.js @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +export default { + fetchRequest(URL, CREDENTIALS, METHOD, HEADER, BODY) { + return fetch(URL, { + credentials: CREDENTIALS, + method: METHOD, + headers: HEADER, + body: BODY + }).then( + (response) => response.json() + ); + } +}; diff --git a/src/editAttributes/networking/NetworkConstants.js b/src/editAttributes/networking/NetworkConstants.js new file mode 100644 index 0000000..d20882d --- /dev/null +++ b/src/editAttributes/networking/NetworkConstants.js @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + +export const POST = 'POST'; +export const POST_HEADER = { + 'Accept': 'application/json' +}; +export const BACKEND_POST_HEADER = { + 'Accept': 'application/json', + 'Content-Type': 'application/json' +}; +export const CREDENTIALS = 'same-origin'; +export const ERROR_RETRIEVING_DATA = 'Error fetching data from server'; +const BACKEND_IP_ADDRESS = document.location.hostname; +const BACKEND_PORT_NUMBER = window.location.port; +const PROTOCOL = window.location.protocol; +export const BASE_URL = PROTOCOL + '//' + BACKEND_IP_ADDRESS + ':' + BACKEND_PORT_NUMBER; diff --git a/src/editAttributes/networking/NetworkUtils.js b/src/editAttributes/networking/NetworkUtils.js new file mode 100644 index 0000000..8fa50b8 --- /dev/null +++ b/src/editAttributes/networking/NetworkUtils.js @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START=================================================== + * SPARKY (AAI UI service) + * ============================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * 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===================================================== + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ + + +export function createEditEntityAttributeRequestObject(uri, attributes) { + return { + 'entity-uri': uri, + 'attributes': { + ...attributes + } + }; +} |