summaryrefslogtreecommitdiffstats
path: root/src/generic-components/input/ToggleInput.jsx
blob: f68758a82c162228e743242665952dd083159ee6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
 * Copyright © 2017-2018 Amdocs
 * ================================================================================
 * 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=========================================================
 */
import React from 'react';
import { PropTypes } from 'prop-types';

export default
class ToggleInput extends React.Component {

  static propTypes = {
    label: PropTypes.node,
    value: PropTypes.bool,
    onChange: PropTypes.func,
    disabled: PropTypes.bool
  }

  static defaultProps = {
    value: false,
    label: ''
  }

  state = {
    value: this.props.value
  }

  status() {
    return this.state.value ? 'on' : 'off';
  }

  render() {
    let {label, disabled} = this.props;
    let checked = this.status() === 'on';
    return (
      <div className='toggle-input-wrapper form-group'
           onClick={!disabled && this.click}>
        <div className='toggle-input-label'>{label}</div>
        <div className='toggle-switch'>
          <input className='toggle toggle-round-flat' type='checkbox'
                 checked={checked} readOnly/>
          <label></label>
        </div>
      </div>
    );
  }

  click = () => {
    let value = !this.state.value;
    this.setState({value});

    let onChange = this.props.onChange;
    if (onChange) {
      onChange(value);
    }
  }

  getValue() {
    return this.state.value;
  }
}
81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
{
  "metadata": {
    "template_author": "Brinda Santh Muthuramalingam",
    "author-email": "brindasanth@in.ibm.com",
    "user-groups": "ADMIN, OPERATION",
    "template_name": "baseconfiguration",
    "template_version": "1.0.0",
    "template_tags": "brinda, tosca"
  },
  "imports": [
    {
      "file": "Definitions/data_types.json"
    },
    {
      "file": "Definitions/relationship_types.json"
    },
    {
      "file": "Definitions/artifact_types.json"
    },
    {
      "file": "Definitions/node_types.json"
    },
    {
      "file": "Definitions/policy_types.json"
    }
  ],
  "topology_template": {
    "inputs": {
      "request-id": {
        "required": true,
        "type": "string"
      },
      "action-name": {
        "required": true,
        "type": "string"
      },
      "scope-type": {
        "required": true,
        "type": "string"
      },
      "hostname": {
        "required": true,
        "type": "string"
      }
    },
    "node_templates": {
      "resource-assignment-process": {
        "type": "dg-generic",
        "properties": {
          "content": {
            "get_artifact": [
              "SELF",
              "dg-resource-assignment-process"
            ]
          },
          "dependency-node-templates": [
            "resource-assignment"
          ]
        },
        "artifacts": {
          "dg-resource-assignment-process": {
            "type": "artifact-directed-graph",
            "file": "Plans/CONFIG_ResourceAssignment_1.0.0.xml"
          }
        }
      },
      "activate-process": {
        "type": "dg-generic",
        "properties": {
          "content": {
            "get_artifact": [
              "SELF",
              "dg-activate-process"
            ]
          },
          "dependency-node-templates": [
            "activate-jython"
          ]
        },
        "artifacts": {
          "dg-activate-process": {
            "type": "artifact-directed-graph",
            "file": "Plans/CONFIG_ActivateNetconf_1.0.0.xml"
          }
        }
      },
      "assign-activate-process": {
        "type": "dg-generic",
        "properties": {
          "content": {
            "get_artifact": [
              "SELF",
              "dg-assign-activate-process"
            ]
          },
          "dependency-node-templates": [
            "resource-assignment",
            "activate-jython"
          ]
        },
        "artifacts": {
          "dg-assign-activate-process": {
            "type": "artifact-directed-graph",
            "file": "Plans/CONFIG_AssignActivateNetconf_1.0.0.xml"
          }
        }
      },
      "resource-assignment": {
        "type": "component-resource-assignment",
        "interfaces": {
          "ResourceAssignmentComponent": {
            "operations": {
              "process": {
                "inputs": {
                  "action-name": {
                    "get_input": "action-name"
                  },
                  "resource-type": "vnf-type",
                  "request-id": {
                    "get_input": "request-id"
                  },
                  "resource-id": {
                    "get_input": "hostname"
                  },
                  "artifact-prefix-names": [
                    "baseconfig"
                  ]
                },
                "outputs": {
                  "resource-assignment-params": {
                    "get_attribute": [
                      "SELF",
                      "assignment-params"
                    ]
                  },
                  "status": "success"
                }
              }
            }
          }
        },
        "artifacts": {
          "baseconfig-template": {
            "type": "artifact-template-velocity",
            "file": "Templates/baseconfig-template.vtl"
          },
          "baseconfig-mapping": {
            "type": "artifact-mapping-resource",
            "file": "Definitions/baseconfig-mapping.json"
          }
        }
      },
      "resource-assignment-py": {
        "type": "component-resource-assignment",
        "interfaces": {
          "ResourceAssignmentComponent": {
            "operations": {
              "process": {
                "implementation": {
                  "primary": "component-script"
                },
                "inputs": {
                  "action-name": {
                    "get_input": "action-name"
                  }
                },
                "outputs": {
                  "resource-assignment-params": "",
                  "status": ""
                }
              }
            }
          }
        },
        "artifacts": {
          "component-script": {
            "type": "artifact-script-jython",
            "file": "Scripts/python/SamplePythonComponentNode.py"
          }
        }
      },
      "activate-jython": {
        "type": "component-jython-executor",
        "interfaces": {
          "JythonExecutorComponent": {
            "operations": {
              "process": {
                "implementation": {
                  "primary": "component-script"
                },
                "inputs": {
                  "instance-dependencies": [
                    "json-parser-service",
                    "netconf-rpc-service"
                  ]
                },
                "outputs": {
                  "response-data": "",
                  "status": ""
                }
              }
            }
          }
        },
        "artifacts": {
          "component-script": {
            "type": "artifact-script-jython",
            "file": "Scripts/python/SamplePythonComponentNode.py"
          }
        }
      },
      "activate-netconf": {
        "type": "component-netconf-executor",
        "interfaces": {
          "NetconfExecutorComponent": {
            "operations": {
              "process": {
                "implementation": {
                  "primary": "component-script"
                },
                "inputs": {
                  "instance-dependencies": [
                    "json-parser-service",
                    "netconf-rpc-service"
                  ]
                },
                "outputs": {
                  "response-data": "",
                  "status": ""
                }
              }
            }
          }
        },
        "requirements": {
          "netconf-connection": {
            "capability": "netconf",
            "node": "sample-netconf-device",
            "relationship": "tosca.relationships.ConnectsTo"
          }
        },
        "artifacts": {
          "component-script": {
            "type": "artifact-script-jython",
            "file": "Scripts/python/DefaultGetNetConfig.py"
          }
        }
      },
      "sample-netconf-device": {
        "type": "vnf-netconf-device",
        "capabilities": {
          "netconf": {
            "properties": {
              "login-key": "sample-key",
              "login-account": "sample-account",
              "target-ip-address": "localhost",
              "port-number": 830,
              "connection-time-out": 30
            }
          }
        }
      }
    },
    "workflows": {
      "resource-assignment": {
        "inputs": {
          "resource-assignment-properties": {
            "required": true,
            "type": "dt-resource-assignment-properties"
          }
        },
        "steps": {
          "call-resource-assignment": {
            "description": "Resource Assignment Workflow",
            "target": "resource-assignment-process",
            "activities": [
              {
                "call_operation": "CONFIG.ResourceAssignment"
              }
            ]
          }
        }
      },
      "activate": {
        "inputs": {
          "request-id": {
            "required": true,
            "type": "string"
          },
          "action-name": {
            "required": true,
            "type": "string"
          },
          "scope-type": {
            "required": true,
            "type": "string"
          },
          "hostname": {
            "required": true,
            "type": "string"
          }
        },
        "steps": {
          "activate-process": {
            "description": "Netconf Activation Workflow",
            "target": "activate-process",
            "activities": [
              {
                "call_operation": "CONFIG.ActivateProcess"
              }
            ]
          }
        }
      },
      "assign-activate": {
        "inputs": {
          "assign-activate-properties": {
            "required": true,
            "type": "dt-assign-activate-properties"
          }
        },
        "steps": {
          "activate-process": {
            "description": "Resource Assign and Netconf Activation Workflow",
            "target": "assign-activate-process",
            "activities": [
              {
                "call_operation": "CONFIG.AssignActivateProcess"
              }
            ]
          }
        }
      }
    }
  }
}