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, {Component, PropTypes} from 'react';
 
  17 import Dropzone from 'react-dropzone';
 
  18 import ButtonGroup from 'react-bootstrap/lib/ButtonGroup.js';
 
  19 import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar.js';
 
  20 import Button from 'react-bootstrap/lib/Button.js';
 
  21 import i18n from 'nfvo-utils/i18n/i18n.js';
 
  22 import SoftwareProductComponentsMonitoringConstants from './SoftwareProductComponentsMonitoringConstants.js';
 
  24 class SoftwareProductComponentsMonitoringView extends Component {
 
  27                 isReadOnlyMode: PropTypes.bool,
 
  28                 trapFilename: PropTypes.string,
 
  29                 pollFilename: PropTypes.string,
 
  30                 softwareProductId: PropTypes.string,
 
  32                 onDropMibFileToUpload: PropTypes.func,
 
  33                 onDeleteSnmpFile: PropTypes.func
 
  43                         <div className='vsp-component-monitoring'>
 
  44                                 {this.renderDropzoneWithType(SoftwareProductComponentsMonitoringConstants.SNMP_TRAP)}
 
  45                                 {this.renderDropzoneWithType(SoftwareProductComponentsMonitoringConstants.SNMP_POLL)}
 
  50         renderDropzoneWithType(type) {
 
  51                 let {isReadOnlyMode, trapFilename, pollFilename} = this.props;
 
  53                 if (type === SoftwareProductComponentsMonitoringConstants.SNMP_TRAP) {
 
  54                         fileName = trapFilename;
 
  57                         fileName = pollFilename;
 
  59                 let refAndName = `fileInput${type.toString()}`;
 
  60                 let typeDisplayName = this.getFileTypeDisplayName(type);
 
  63                                 className={`snmp-dropzone ${this.state.dragging ? 'active-dragging' : ''}`}
 
  64                                 onDrop={(acceptedFiles, rejectedFiles) => this.handleImport(acceptedFiles, rejectedFiles, {isReadOnlyMode, type, refAndName})}
 
  65                                 onDragEnter={() => this.handleOnDragEnter(isReadOnlyMode)}
 
  66                                 onDragLeave={() => this.setState({dragging:false})}
 
  73                                 <div className='draggable-wrapper'>
 
  74                                         <div className='section-title'>{typeDisplayName}</div>
 
  75                                         {fileName ? this.renderUploadedFileName(fileName, type) : this.renderUploadButton(refAndName)}
 
  81         renderUploadButton(refAndName) {
 
  82                 let {isReadOnlyMode} = this.props;
 
  85                                 className={`software-product-landing-view-top-block-col-upl${isReadOnlyMode ? ' disabled' : ''}`}>
 
  86                                 <div className='drag-text'>{i18n('Drag & drop for upload')}</div>
 
  87                                 <div className='or-text'>{i18n('or')}</div>
 
  88                                 <div className='upload-btn primary-btn' data-test-id={`monitoring-upload-${refAndName}`} onClick={() => this.refs[refAndName].open()}>
 
  89                                         <span className='primary-btn-text'>{i18n('Select file')}</span>
 
  95         renderUploadedFileName(filename, type) {
 
  99                                         <Button disabled>{filename}</Button>
 
 100                                         <Button className='delete-button' onClick={()=>this.props.onDeleteSnmpFile(type)}>X</Button>
 
 107         handleOnDragEnter(isReadOnlyMode) {
 
 108                 if (!isReadOnlyMode) {
 
 109                         this.setState({dragging: true});
 
 113         handleImport(files, rejectedFiles, {isReadOnlyMode, type, refAndName}) {
 
 114                 if (isReadOnlyMode) {
 
 117                 if (files.length > 0) {
 
 118                         this.setState({dragging: false});
 
 120                         let formData = new FormData();
 
 121                         formData.append('upload', file);
 
 122                         this.refs[refAndName].value = '';
 
 123                         this.props.onDropMibFileToUpload(formData, type);
 
 124                 } else if (rejectedFiles.length > 0) {
 
 125                         this.setState({dragging: false});
 
 126                         this.props.onFileUploadError();
 
 130         getFileTypeDisplayName(type) {
 
 131                 return type === SoftwareProductComponentsMonitoringConstants.SNMP_TRAP ? 'SNMP Trap' : 'SNMP Poll';
 
 136 export default SoftwareProductComponentsMonitoringView;