35c9fe670d1be2825fef4b8afb66e1b3dc623522
[ccsdk/distribution.git] / dgbuilder / nodes / dge / dgelogic / switchNode.html
1 <!--
2   Copyright 2013 IBM Corp.
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 or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 -->
16
17 <script type="text/x-red" data-template-name="switchNode">
18     <div class="form-row">
19         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
20         <input type="text" id="node-input-name" placeholder="Name">
21     </div>
22     <div class="form-row">
23         <label for="node-input-xml"><i class="fa fa-wrench"></i> Node XML</label>
24         <input type="hidden" id="node-input-xml" autofocus="autofocus">
25         <div style="height: 450px;" class="node-text-editor" id="node-input-xml-editor" onkeyup="resetStatus()" ></div>
26     </div>
27     <div class="form-row">
28     <a href="#" class="btn btn-mini" id="node-input-validate" style="margin-top: 4px;"><b>Validate XML</b></a>
29      <a href="#" class="btn btn-mini" id="node-input-show-sli-values" style="margin-top: 4px;"><b>Show Values</b></a> 
30     <input type="hidden" id="node-input-comments">
31     <a href="#" class="btn btn-mini" id="node-input-btnComments" style="margin-top: 4px;"><b>Add Comments</b></a>
32     <div id="node-validate-result" class="form-tips" style="float:right;font-size:10px"></div>
33     </div>
34     <div class="form-tips">See the Info tab for help using this node.</div>
35 </script>
36
37 <script type="text/x-red" data-help-name="switchNode">
38         <p>A switch node.</p>
39         <p>First line of XML must contain opening tag.</p>
40         <p>Do not include closing tag - it will be automatically generated.</p>
41
42 <div class="section">
43 <h4><a name="Switch_node"></a>Switch node</h4>
44 <div class="section">
45 <h5><a name="Description"></a>Description</h5>
46 <p>A <b>switch</b> node is used to make a decision based on its <b>test</b> attribute.</p></div>
47 <div class="section">
48 <h5><a name="Attributes"></a>Attributes</h5>
49 <table border="1" class="table table-striped">
50 <tr class="a">
51 <td align="center"><b>test</b></td>
52 <td align="left">Condition to test</td></tr></table></div>
53 <div class="section">
54 <h5><a name="Parameters"></a>Parameters</h5>
55 <p>None</p></div>
56 <div class="section">
57 <h5><a name="Outcomes"></a>Outcomes</h5>
58 <p>Depends on the <b>test</b> condition</p></div>
59 <div class="section">
60 <h5><a name="Example"></a>Example</h5>
61 <div class="source">
62 <pre>&lt;switch test=&quot;$uni-cir-units&quot;&gt;
63   &lt;outcome value=&quot;Mbps&quot;&gt;
64     &lt;reserve plugin=&quot;org.onap.ccsdk.sli.resource.samplesvc.SampleServiceResource&quot;
65                          resource=&quot;ase-port&quot;
66                          key=&quot;resource-emt-clli == $edge-device-clli and speed &gt;= $uni-cir-value&quot;
67                          pfx=&quot;asePort&quot;&gt;
68
69       &lt;outcome value=&quot;success&quot;&gt;
70             &lt;return status=&quot;success&quot;&gt;
71                   &lt;parameter name=&quot;uni-circuit-id&quot; value=&quot;$asePort.uni_circuit_id&quot; /&gt;
72                 &lt;/return&gt;
73       &lt;/outcome&gt;
74       &lt;outcome value=&quot;Other&quot;&gt;
75         &lt;return status=&quot;failure&quot;&gt;
76           &lt;parameter name=&quot;error-code&quot; value=&quot;1010&quot; /&gt;
77           &lt;parameter name=&quot;error-message&quot; value=&quot;No ports found that match criteria&quot; /&gt;
78         &lt;/return&gt;
79       &lt;/outcome&gt;
80     &lt;/reserve&gt;
81   &lt;/outcome&gt;
82   &lt;outcome value=&quot;Gbps&quot;&gt;
83     &lt;reserve plugin=&quot;org.onap.ccsdk.sli.resource.samplesvc.SampleServiceResource&quot;
84                          resource=&quot;ase-port&quot;
85                          key=&quot;resource-emt-clli == $edge-device-clli and speed &gt;= $uni-cir-value*1000&quot;
86                          pfx=&quot;asePort&quot;&gt;
87
88       &lt;outcome value=&quot;success&quot;&gt;
89             &lt;return status=&quot;success&quot;&gt;
90                   &lt;parameter name=&quot;uni-circuit-id&quot; value=&quot;$asePort.uni_circuit_id&quot; /&gt;
91                 &lt;/return&gt;
92       &lt;/outcome&gt;
93       &lt;outcome value=&quot;Other&quot;&gt;
94         &lt;return status=&quot;failure&quot;&gt;
95           &lt;parameter name=&quot;error-code&quot; value=&quot;1010&quot; /&gt;
96           &lt;parameter name=&quot;error-message&quot; value=&quot;No ports found that match criteria&quot; /&gt;
97         &lt;/return&gt;
98       &lt;/outcome&gt;
99     &lt;/reserve&gt;
100   &lt;/outcome&gt;    
101 &lt;/switch&gt;</pre></div></div></div></div>
102
103 </script>
104
105
106 <script type="text/javascript">
107     RED.nodes.registerType('switchNode',{
108         color:"#fdd0a2",
109         category: 'DGElogic',
110         defaults: {
111             name: {value:"switch"},
112             xml: {value:"<switch test=''>\n"},
113             comments:{value:""},        
114             outputs: {value:1}
115         },
116         inputs:1,
117         outputs:1,
118         icon: "arrow-in.png",
119         label: function() {
120             return this.name;
121         },
122         oneditprepare: function() {
123             $( "#node-input-outputs" ).spinner({
124                 min:1
125             });
126
127
128              var comments = $( "#node-input-comments").val();
129              if(comments != null){
130                 comments = comments.trim();
131                 if(comments != ''){
132                         $("#node-input-btnComments").html("<span style='color:blue;'><b>View Comments</b></span>");
133                 }
134              }
135
136             function functionDialogResize(ev,ui) {
137                 $("#node-input-xml-editor").css("height",(ui.size.height-275)+"px");
138             };
139
140             $( "#dialog" ).dialog( "option", "width", 1200 );
141             $( "#dialog" ).dialog( "option", "height", 750 );
142             $( "#dialog" ).on("dialogresize", functionDialogResize);
143             $( "#dialog" ).one("dialogopen", function(ev) {
144                 var size = $( "#dialog" ).dialog('option','sizeCache-function');
145                 //To increase the width of dialogbox
146                 //$(".ui-dialog.ui-widget.ui-widget-content.ui-corner-all.ui-front.ui-dialog-buttons.ui-draggable.ui-resizable").css("width","1400px");
147                 if (size) {
148                     functionDialogResize(null,{size:size});
149                 }
150             });
151
152             /* close dialog when ESC is pressed and released */ 
153             $( "#dialog" ).keyup(function(event){
154                 if(event.which == 27 ) {
155                         $("#node-dialog-cancel").click();
156                 }
157             }); 
158
159             $( "#dialog" ).one("dialogclose", function(ev,ui) {
160                 var height = $( "#dialog" ).dialog('option','height');
161                 $( "#dialog" ).off("dialogresize",functionDialogResize);
162             });
163             var that = this;
164             require(["orion/editor/edit"], function(edit) {
165                 that.editor = edit({
166                     parent:document.getElementById('node-input-xml-editor'),
167                     lang:"html",
168                     contents: $("#node-input-xml").val()
169                 });
170                 RED.library.create({
171                     url:"functions", // where to get the data from
172                     type:"function", // the type of object the library is for
173                     editor:that.editor, // the field name the main text body goes to
174                     fields:['name','outputs']
175                 });
176                 $("#node-input-name").focus();
177                 $("#node-input-validate").click(function(){
178                                 console.log("validate clicked.");
179                                 //console.dir(that.editor);
180                                 //console.log("getText:" + that.editor.getText());
181                                 var val = that.editor.getText();
182                                 validateXML(val); 
183                 });
184                 $("#node-input-show-sli-values").click(function(){
185                                 console.log("SLIValues clicked.");
186                                 showValuesBox(that.editor,sliValuesObj);
187                 });
188
189             });
190             //for click of add comments button
191             $("#node-input-btnComments").click(function(e){
192                         showCommentsBox();
193             }); 
194         },
195         oneditsave: function() {
196             $("#node-input-xml").val(this.editor.getText());
197                 var resp=validateXML(this.editor.getText());
198                 if(resp){
199                         this.status = {fill:"green",shape:"dot",text:"OK"};
200                 }else{
201                         this.status = {fill:"red",shape:"dot",text:"ERROR"};
202                 }       
203                 delete this.editor;
204         }
205     });
206
207 function encodeTestStr(xmlStr){
208         var updatedXmlStr=xmlStr;
209         if(updatedXmlStr != null){
210                 var testCondition = getAttributeValue(xmlStr,"test");
211                 if(testCondition != null && testCondition != ''){
212                         if(testCondition.indexOf("&lt;") == -1){
213                                 testCondition=testCondition.replace(/</g,"&lt;");
214                         }
215                         updatedXmlStr="<switch test=\"" + testCondition + "\" >";
216                 }
217         }
218         return updatedXmlStr;
219 }
220
221 function decodeTestStr(xmlStr){
222         var updatedXmlStr=xmlStr;
223         if(updatedXmlStr != null){
224                 var testCondition = getAttributeValue(xmlStr,"test");
225                 if(testCondition != null && testCondition != ''){
226                         testCondition=testCondition.replace(/&lt;/g,"<");
227                         updatedXmlStr="<switch test=\"" + testCondition + "\" >";
228                 }
229         }
230         return updatedXmlStr;
231 }
232 </script>