2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import React from 'react';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
19 import Modal from 'nfvo-components/modal/Modal.jsx';
20 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
21 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
23 import LicenseKeyGroupsEditor from './LicenseKeyGroupsEditor.js';
24 import InputOptions, {other as optionInputOther} from 'nfvo-components/input/inputOptions/InputOptions.jsx';
25 import {optionsInputValues} from './LicenseKeyGroupsConstants';
27 class LicenseKeyGroupsListEditorView extends React.Component {
29 vendorName: React.PropTypes.string,
30 licenseModelId: React.PropTypes.string.isRequired,
31 licenseKeyGroupsList: React.PropTypes.array,
32 isReadOnlyMode: React.PropTypes.bool.isRequired,
33 isDisplayModal: React.PropTypes.bool,
34 isModalInEditMode: React.PropTypes.bool,
35 onAddLicenseKeyGroupClick: React.PropTypes.func,
36 onEditLicenseKeyGroupClick: React.PropTypes.func,
37 onDeleteLicenseKeyGroupClick: React.PropTypes.func
40 static defaultProps = {
41 licenseKeyGroupsList: []
49 let {licenseModelId, vendorName, isReadOnlyMode, isDisplayModal, isModalInEditMode, version} = this.props;
50 let {onAddLicenseKeyGroupClick} = this.props;
51 const {localFilter} = this.state;
54 <div className='license-key-groups-list-editor'>
56 title={i18n('License Key Groups', {vendorName})}
57 plusButtonTitle={i18n('Add License Key Group')}
58 onAdd={onAddLicenseKeyGroupClick}
59 filterValue={localFilter}
60 onFilter={value => this.setState({localFilter: value})}
61 isReadOnlyMode={isReadOnlyMode}>
62 {this.filterList().map(licenseKeyGroup => (this.renderLicenseKeyGroupListItem(licenseKeyGroup, isReadOnlyMode)))}
64 <Modal show={isDisplayModal} bsSize='large' animation={true} className='onborading-modal license-key-groups-modal'>
66 <Modal.Title>{`${isModalInEditMode ? i18n('Edit License Key Group') : i18n('Create New License Key Group')}`}</Modal.Title>
71 <LicenseKeyGroupsEditor version={version} licenseModelId={licenseModelId} isReadOnlyMode={isReadOnlyMode}/>
81 let {licenseKeyGroupsList} = this.props;
82 let {localFilter} = this.state;
83 if (localFilter.trim()) {
84 const filter = new RegExp(escape(localFilter), 'i');
85 return licenseKeyGroupsList.filter(({name = '', description = '', operationalScope = '', type = ''}) => {
86 return escape(name).match(filter) || escape(description).match(filter) || escape(this.extractValue(operationalScope)).match(filter) || escape(type).match(filter);
90 return licenseKeyGroupsList;
94 renderLicenseKeyGroupListItem(licenseKeyGroup, isReadOnlyMode) {
95 let {id, name, description, operationalScope, type} = licenseKeyGroup;
96 let {onEditLicenseKeyGroupClick, onDeleteLicenseKeyGroupClick} = this.props;
100 onSelect={() => onEditLicenseKeyGroupClick(licenseKeyGroup)}
101 onDelete={() => onDeleteLicenseKeyGroupClick(licenseKeyGroup)}
102 className='list-editor-item-view'
103 isReadOnlyMode={isReadOnlyMode}>
104 <div className='list-editor-item-view-field'>
105 <div className='title'>{i18n('Name')}</div>
106 <div className='text name'>{name}</div>
109 <div className='list-editor-item-view-field'>
110 <div className='title'>{i18n('Operational Scope')}</div>
111 <div className='text operational-scope'>{operationalScope && this.getOperationalScopes(operationalScope)}</div>
113 <div className='title'>{i18n('Type')}</div>
114 <div className='text type'>{InputOptions.getTitleByName(optionsInputValues, type)}</div>
116 <div className='list-editor-item-view-field'>
117 <div className='title'>{i18n('Description')}</div>
118 <div className='text description'>{description}</div>
120 </ListEditorItemView>
124 getOperationalScopes(operationalScope) {
125 if(operationalScope.choices.toString() === i18n(optionInputOther.OTHER) && operationalScope.other !== '') {
126 return operationalScope.other;
129 let allOpScopes = '';
130 for (let opScope of operationalScope.choices) {
131 allOpScopes += allOpScopes === '' ? InputOptions.getTitleByName(optionsInputValues, opScope) : `, ${InputOptions.getTitleByName(optionsInputValues, opScope)}`;
138 if (item === undefined) {
140 } //TODO fix it later
142 return item ? item.choice === optionInputOther.OTHER ? item.other : InputOptions.getTitleByName(optionsInputValues, item.choice) : '';
146 export default LicenseKeyGroupsListEditorView;
148 export function generateConfirmationMsg(licenseKeyGroupToDelete) {
149 let name = licenseKeyGroupToDelete ? licenseKeyGroupToDelete.name : '';
150 let msg = i18n('Are you sure you want to delete "{name}"?', {name});
151 let subMsg = licenseKeyGroupToDelete.referencingFeatureGroups
152 && licenseKeyGroupToDelete.referencingFeatureGroups.length > 0 ?
153 i18n('This license key group is associated with one or more feature groups') :