// Copyright 2021 99cloud // // 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 React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Badge, Row, Col, Card, Descriptions } from 'antd'; import { inject, observer } from 'mobx-react'; import adminInstance from 'src/asset/image/adminInstance.svg'; import adminVolume from 'src/asset/image/adminVolume.svg'; import { Link } from 'react-router-dom'; import adminNetwork from 'src/asset/image/adminNetwork.svg'; import adminImage from 'src/asset/image/adminImage.svg'; import adminSecurityGroup from 'src/asset/image/adminSecurityGroup.svg'; import adminRouter from 'src/asset/image/adminRouter.svg'; import styles from '../style.less'; const card = [ { key: 'serviceNum', label: t('Instance'), avatar: adminInstance, to: '/compute/instance-admin', }, { key: 'volumeNum', label: t('Volume'), avatar: adminVolume, to: '/storage/volume-admin', }, ]; const smallCard = [ { key: 'networkNum', label: t('Network'), avatar: adminNetwork, to: '/network/networks-admin', }, { key: 'imageNum', label: t('Image'), avatar: adminImage, to: '/compute/image-admin', }, { key: 'routerNum', label: t('Router'), avatar: adminRouter, to: '/network/router-admin', }, { key: 'securityGroupNum', label: t('Security Group'), avatar: adminSecurityGroup, to: '/network/security-group-admin', }, ]; const instanceColors = { active: { color: '#52C41A', text: t('Active Status') }, error: { color: '#E8684A', text: t('Error') }, shutoff: { color: '#E6F2E0', text: t('Shutoff') }, other: { color: '#F6B23D', text: t('Others') }, }; const volumeColors = { active: { color: '#52C41A', text: t('Attaching') }, error: { color: '#E8684A', text: t('Error') }, unattache: { color: '#E6F2E0', text: t('Unattached') }, other: { color: '#F6B23D', text: t('Others') }, }; class virtualResourceInfo extends Component { componentDidMount() { this.props.store.getVirtualResource(); } renderStatusColor(resource, resourceKey) { let colors = null; switch (resourceKey) { case 'volumeNum': colors = volumeColors; break; default: colors = instanceColors; break; } // resource === 'serviceNum' return Object.keys(colors).map((key) => ( {resource ? resource[key] : 0} )); } renderCard() { const { virtualResource } = this.props.store; return ( {card.map((item) => ( avatar {item.label} {virtualResource[item.key] ? virtualResource[item.key].all : null} {virtualResource[item.key] ? this.renderStatusColor( virtualResource[item.key], item.key ) : null} ))} ); } renderSmallCard() { const { virtualResource } = this.props.store; return ( {smallCard.map((item) => ( avatar {item.label} {virtualResource[item.key]} ))} ); } render() { const { virtualResourceLoading } = this.props.store; return (
{this.renderCard()} {/* {this.renderSmallCard()} */}
); } } virtualResourceInfo.propTypes = { store: PropTypes.object.isRequired, }; export default inject('rootStore')(observer(virtualResourceInfo));