|
| 1 | +<!-- |
| 2 | + Copyright 2017 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="watson-conversation-v1-workspace-manager"> |
| 18 | + <div id="credentials-check" class="form-row"> |
| 19 | + <div class="form-tips"> |
| 20 | + <i class="fa fa-question-circle"></i><b> Please wait: </b> Checking for bound service credentials... |
| 21 | + </div> |
| 22 | + </div> |
| 23 | + |
| 24 | + <div> |
| 25 | + <label id="node-label-message"><i class="fa fa-exclamation-triangle"></i></label> |
| 26 | + </div> |
| 27 | + |
| 28 | + <div class="form-row"> |
| 29 | + <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> |
| 30 | + <input type="text" id="node-input-name" placeholder="Name"></input> |
| 31 | + </div> |
| 32 | + |
| 33 | + <div class="form-row credentials" style="display: none;"> |
| 34 | + <label for="node-input-username"><i class="fa fa-user"></i> Username</label> |
| 35 | + <input type="text" id="node-input-username" placeholder="Username"></input> |
| 36 | + </div> |
| 37 | + <div class="form-row credentials" style="display: none;"> |
| 38 | + <label for="node-input-password"><i class="fa fa-key"></i> Password</label> |
| 39 | + <input type="password" id="node-input-password" placeholder="Password"></input> |
| 40 | + </div> |
| 41 | + |
| 42 | + <div class="form-row"> |
| 43 | + <label for="node-input-cwm-custom-mode"><i class="fa fa-book"></i> Detect: </label> |
| 44 | + <select type="text" id="node-input-cwm-custom-mode" style="display: inline-block; width: 70%;"> |
| 45 | + <option value="listWorkspaces">List Workspaces</option> |
| 46 | + <option value="getWorkspace">Get Workspace Details</option> |
| 47 | + <option value="createWorkspace">Create Workspace</option> |
| 48 | + <option value="updateWorkspace">Update Workspace</option> |
| 49 | + <option value="deleteWorkspace">Delete Workspace</option> |
| 50 | + </select> |
| 51 | + </div> |
| 52 | + |
| 53 | + <div class="form-row"> |
| 54 | + <label for="node-input-cwm-workspace-id"><i class="fa fa-book"></i> Workspace ID</label> |
| 55 | + <input type="text" id="node-input-cwm-workspace-id" placeholder=""> |
| 56 | + </div> |
| 57 | + |
| 58 | + <div class="form-row"> |
| 59 | + <label for="node-input-cwm-export-content"><i class="fa fa-book"></i> Export All Content</label> |
| 60 | + <input type="checkbox" id="node-input-cwm-export-content" placeholder=""> |
| 61 | + </div> |
| 62 | + |
| 63 | +</script> |
| 64 | + |
| 65 | +<script type="text/x-red" data-help-name="watson-conversation-v1-workspace-manager"> |
| 66 | + <p>The Conversation Workspace Manager is used to ... </p> |
| 67 | + <ul> |
| 68 | + <li>list Workspaces |
| 69 | + <p>In this mode a list of all workspaces a that you have |
| 70 | + created in the conversation services are returned on |
| 71 | + <code>msg.workspaces</code> |
| 72 | + </p> |
| 73 | + </li> |
| 74 | + <li>Get Workspace |
| 75 | + <p>In this mode all information about a workspace, |
| 76 | + optionally including all workspace content, is retrieved. |
| 77 | + The information is returned on |
| 78 | + <code>msg.workspace</code> |
| 79 | + </p> |
| 80 | + </li> |
| 81 | + <li>Create Workspace |
| 82 | + <p>In this mode, a new worskpace is created. The input json structure |
| 83 | + defining the content of the new workspace |
| 84 | + should be passed in |
| 85 | + as <code>msg.payload</code> |
| 86 | + </p> |
| 87 | + </li> |
| 88 | + <li>Update Workspace |
| 89 | + <p>In this mode, the specified worskpace is updated. The input json structure |
| 90 | + defining the content of the updates |
| 91 | + should be passed in |
| 92 | + as <code>msg.payload</code>. Only the elements need to be included |
| 93 | + in the json. Any included element will override the existing setting |
| 94 | + for the element. ie. If only updating entities, then only entities need |
| 95 | + to be included in the json. Any existing entities in the workspace will |
| 96 | + be overridden. ie. If any entity is not mentioned in the json, then it |
| 97 | + will be deleted from the workspace. |
| 98 | + </p> |
| 99 | + </li> |
| 100 | + <li>Delete Workspace |
| 101 | + <p>In this mode the selected workspace is deleted. |
| 102 | + </p> |
| 103 | + </li> |
| 104 | + </ul> |
| 105 | + |
| 106 | + <p>For more information about the conversation service, |
| 107 | + read the <a href="https://www.ibm.com/watson/developercloud/doc/conversation/index.html"> |
| 108 | + documentation</a>.</p> |
| 109 | +</script> |
| 110 | + |
| 111 | +<script type="text/javascript"> |
| 112 | + |
| 113 | + // Need to simulate a namespace, as some of the variables had started to leak across nodes |
| 114 | + function CV1WM () { |
| 115 | + } |
| 116 | + |
| 117 | + // This is the namespace for cv1wm. Currently only contains models, but more vars and functions may need to be |
| 118 | + // moved in if there is a clash with other nodes. |
| 119 | + var cv1wm = new CV1WM(); |
| 120 | + cv1wm.mode_selected = null; |
| 121 | + |
| 122 | + cv1wm.showSelectedFields = function(fields) { |
| 123 | + for (i = 0; i < fields.length; i++) { |
| 124 | + $(fields[i]).parent().show(); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + cv1wm.hideSelectedFields = function(fields) { |
| 129 | + for (i = 0; i < fields.length; i++) { |
| 130 | + $(fields[i]).parent().hide(); |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + // Function to be used at the start, as don't want to expose any fields, unless the models are |
| 135 | + // available. The models can only be fetched if the credentials are available. |
| 136 | + cv1wm.hideEverything = function () { |
| 137 | + var fields = []; |
| 138 | + |
| 139 | + fields.push('#node-input-cwm-workspace-id' |
| 140 | + + ', #node-input-cwm-export-content'); |
| 141 | + |
| 142 | + cv1wm.hideSelectedFields(fields); |
| 143 | + } |
| 144 | + |
| 145 | + cv1wm.processSelectedMethod = function(method) { |
| 146 | + var fields = []; |
| 147 | + |
| 148 | + cv1wm.hideEverything(); |
| 149 | + |
| 150 | + switch (method) { |
| 151 | + case 'getWorkspace': |
| 152 | + fields.push('#node-input-cwm-workspace-id' |
| 153 | + + ', #node-input-cwm-export-content'); |
| 154 | + break; |
| 155 | + case 'deleteWorkspace': |
| 156 | + case 'updateWorkspace': |
| 157 | + fields.push('#node-input-cwm-workspace-id'); |
| 158 | + break; |
| 159 | + case 'listWorkspaces': |
| 160 | + case 'createWorkspace': |
| 161 | + break; |
| 162 | + } |
| 163 | + cv1wm.showSelectedFields(fields); |
| 164 | + } |
| 165 | + |
| 166 | + // Register the handlers for the fields |
| 167 | + cv1wm.handlersUI = function () { |
| 168 | + $('#node-input-cwm-custom-mode').change(function() { |
| 169 | + cv1wm.mode_selected = $('#node-input-cwm-custom-mode').val(); |
| 170 | + cv1wm.processSelectedMethod(cv1wm.mode_selected); |
| 171 | + }); |
| 172 | + } |
| 173 | + |
| 174 | + // This is the on edit prepare function, which will be invoked everytime the dialog |
| 175 | + // is shown. |
| 176 | + function cv1wmoneditprepare() { |
| 177 | + cv1wm.hideEverything(); |
| 178 | + cv1wm.handlersUI(); |
| 179 | + |
| 180 | + $.getJSON('watson-conversation-v1-workspace-manager/vcap/') |
| 181 | + // for some reason the getJSON resets the vars so need to restoreFromHidden again |
| 182 | + // so again. |
| 183 | + .done(function (service) { |
| 184 | + $('.credentials').toggle(!service); |
| 185 | + }) |
| 186 | + .fail(function () { |
| 187 | + $('.credentials').show(); |
| 188 | + }).always(function () { |
| 189 | + $('#credentials-check').hide(); |
| 190 | + }); |
| 191 | + } |
| 192 | + |
| 193 | + // Save the values in the dyanmic lists to the hidden fields. |
| 194 | + function cv1wmoneditsave(){ |
| 195 | + } |
| 196 | + |
| 197 | + (function() { |
| 198 | + RED.nodes.registerType('watson-conversation-v1-workspace-manager', { |
| 199 | + category: 'IBM Watson', |
| 200 | + defaults: { |
| 201 | + name: {value: ''}, |
| 202 | + 'cwm-custom-mode': {value:"listWorkspaces"}, |
| 203 | + 'cwm-workspace-id': {value:""}, |
| 204 | + 'cwm-export-content': {value:false} |
| 205 | + }, |
| 206 | + credentials: { |
| 207 | + username: {type:'text'}, |
| 208 | + password: {type: 'password'} |
| 209 | + }, |
| 210 | + color: 'rgb(84,149,180)', |
| 211 | + inputs: 1, |
| 212 | + outputs: 1, |
| 213 | + icon: 'conversation-v1-25x25.png', |
| 214 | + paletteLabel: 'conversation workspace manager', |
| 215 | + label: function() { |
| 216 | + return this.name || 'conversation workspace manager'; |
| 217 | + }, |
| 218 | + labelStyle: function() { |
| 219 | + return this.name ? 'node_label_italic' : ''; |
| 220 | + }, |
| 221 | + oneditprepare: cv1wmoneditprepare, |
| 222 | + oneditsave: cv1wmoneditsave |
| 223 | + }); |
| 224 | + })(); |
| 225 | + |
| 226 | +</script> |
0 commit comments