blob: 61d19d9e7aa17bd6e75c1b343b1244a2f6272b64 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import React from 'react';
17import {connect} from 'react-redux';
AviZi280f8012017-06-09 02:39:56 +030018import Input from 'nfvo-components/input/validation/InputWrapper.jsx';
Michael Landoefa037d2017-02-19 12:57:33 +020019
20import LicenseModelActionHelper from './onboarding/licenseModel/LicenseModelActionHelper.js';
21import LicenseAgreementListEditor from './onboarding/licenseModel/licenseAgreement/LicenseAgreementListEditor.js';
22import LicenseAgreementActionHelper from './onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js';
23import FeatureGroupListEditor from './onboarding/licenseModel/featureGroups/FeatureGroupListEditor.js';
24import FeatureGroupsActionHelper from './onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
25import LicenseKeyGroupsListEditor from './onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsListEditor.js';
26import LicenseKeyGroupsActionHelper from './onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
27import EntitlementPoolsListEditor from './onboarding/licenseModel/entitlementPools/EntitlementPoolsListEditor.js';
28import EntitlementPoolsActionHelper from './onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
29import SoftwareProductLandingPage from './onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js';
30import SoftwareProductDetails from './onboarding/softwareProduct/details/SoftwareProductDetails.js';
AviZi280f8012017-06-09 02:39:56 +030031import Onboard from './onboarding/onboard/Onboard.js';
Michael Landoefa037d2017-02-19 12:57:33 +020032import SoftwareProductActionHelper from './onboarding/softwareProduct/SoftwareProductActionHelper.js';
33import FlowsListEditor from './flows/FlowsListEditor.js';
34import FlowsActions from './flows/FlowsActions.js';
35
36
37const mapStateToProps = ({licenseModelList}) => {
38 return {licenseModelList};
39};
40
41
42const mapActionsToProps = dispatch => {
43 return {
44 onBootstrapped: () => LicenseModelActionHelper.fetchLicenseModels(dispatch),
45 onLicenseAgreementListEditor: licenseModelId => LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId}),
46 onFeatureGroupsListEditor: licenseModelId => FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId}),
47 onLicenseKeyGroupsListEditor: licenseModelId =>LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId}),
48 onEntitlementPoolsListEditor: licenseModelId => EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId}),
49 onOnboardingCatalog: () => SoftwareProductActionHelper.fetchSoftwareProductList(dispatch),
50 onSoftwareProductDetails: () => SoftwareProductActionHelper.fetchSoftwareProductCategories(dispatch),
51 onFlowsListEditor: () => FlowsActions.fetchFlows(dispatch)
52 };
53};
54
55class ModuleOptions extends React.Component {
56
57 static propTypes = {
58 onBootstrapped: React.PropTypes.func.isRequired,
59 onLicenseAgreementListEditor: React.PropTypes.func.isRequired,
60 onFeatureGroupsListEditor: React.PropTypes.func.isRequired,
61 onLicenseKeyGroupsListEditor: React.PropTypes.func.isRequired,
62 onEntitlementPoolsListEditor: React.PropTypes.func.isRequired,
63 onOnboardingCatalog: React.PropTypes.func.isRequired,
64 onSoftwareProductDetails: React.PropTypes.func.isRequired,
65 };
66
67 state = {
68 currentModule: localStorage.getItem('default-module'),
69 licenseModelId: localStorage.getItem('default-license-model-id')
70 };
71
72 componentDidMount() {
73 this.props.onBootstrapped();
74 }
75
76 render() {
77 let {currentModule, licenseModelId} = this.state;
78 let {licenseModelList} = this.props;
79 return (
80 <div style={{marginTop:20}}>
81 <Input
82 name='licenseModel'
83 value={licenseModelId}
84 ref='licenseModelId'
85 type='select'
86 onChange={this.handleLicenseModelIdChange}
87 className='inner-pagination select-input'>
88 <option value='' key={null}>Select License Model</option>
89 {
90 licenseModelList.map(({id, vendorName}) => <option value={id} key={id}>{`${vendorName} License Model`}</option>)
91 }
92 </Input>
93 <Input
94 name='currentView'
95 value={currentModule}
96 ref='selectedModule'
97 type='select'
98 onChange={this.handleModuleSelection}
99 className='inner-pagination select-input'>
100 <option value=''>Select Module</option>
101 <option value='EntitlementPoolsListEditor'>Entitlement Pools</option>
102 <option value='LicenseAgreementListEditor'>License Agreements</option>
103 <option value='FutureGroupListEditor'>Feature Groups</option>
104 <option value='LicenseKeyGroupsListEditor'>License Key Groups</option>
105 <option value='SoftwareProductLanding'>Software Product Landing</option>
106 <option value='SoftwareProductDetails'>Software Product Details</option>
107 <option value='OnboardingCatalog'>Onboarding Catalog</option>
108 <option value='Flows'>Flows</option>
109 </Input>
110 <div className='sub-module-view' style={{paddingTop: 10, margin: 4, borderTop: '1px solid silver'}}>
111 {this.renderModule(currentModule)}
112 </div>
113 </div>
114 );
115 }
116
117 renderModule(currentModule) {
118 const {licenseModelId} = this.state;
119 if (!licenseModelId) {
120 return;
121 }
122
123 switch (currentModule) {
124 case 'LicenseAgreementListEditor':
125 this.props.onLicenseAgreementListEditor(licenseModelId);
126 return <LicenseAgreementListEditor licenseModelId={licenseModelId}/>;
127 case 'FutureGroupListEditor':
128 this.props.onFeatureGroupsListEditor(licenseModelId);
129 return <FeatureGroupListEditor licenseModelId={licenseModelId}/>;
130 case 'EntitlementPoolsListEditor':
131 this.props.onEntitlementPoolsListEditor(licenseModelId);
132 return <EntitlementPoolsListEditor licenseModelId={licenseModelId}/>;
133 case 'LicenseKeyGroupsListEditor':
134 this.props.onLicenseKeyGroupsListEditor(licenseModelId);
135 return <LicenseKeyGroupsListEditor licenseModelId={licenseModelId}/>;
136 case 'SoftwareProductLanding':
137 return <SoftwareProductLandingPage licenseModelId={licenseModelId}/>;
138 case 'SoftwareProductDetails':
139 this.props.onSoftwareProductDetails(licenseModelId);
140 return <SoftwareProductDetails licenseModelId={licenseModelId}/>;
141 case 'OnboardingCatalog':
142 this.props.onOnboardingCatalog();
AviZi280f8012017-06-09 02:39:56 +0300143 return <Onboard/>;
Michael Landoefa037d2017-02-19 12:57:33 +0200144 case 'Flows':
145 this.props.onFlowsListEditor();
146 return <FlowsListEditor/>;
147 default:
148 return;
149 }
150 }
151
152 handleModuleSelection = () => {
153 let selectedModule = this.refs.selectedModule.getValue();
154 localStorage.setItem('default-module', selectedModule);
155 this.setState({currentModule: selectedModule});
156 }
157
158 handleLicenseModelIdChange = () => {
159 let licenseModelId = this.refs.licenseModelId.getValue();
160 localStorage.setItem('default-license-model-id', licenseModelId);
161 this.setState({licenseModelId});
162 }
163}
164
165export default connect(mapStateToProps, mapActionsToProps)(ModuleOptions);