UNPKG

node-red-trexmes-commands

Version:

A node-red node to execute commands for Trex Mes Systems

527 lines (488 loc) 25.1 kB
<style> .trexmes-cmd-form-row>label { width: 125px !important; } .trexmes-cmd-form-row>select { width: 70% !important; } div.form-row.trexmes-cmd-form-row > input[type="checkbox"]{ width: unset; margin-top: -2px; } div.form-row.trexmes-cmd-form-row > .form-tips { width: calc(100% - 35px); } .trexmes-cmd-row-item { margin: 2px 4px 2px 2px; } .trexmes-cmd-row { flex-wrap: wrap; } .trexmes-cmd-hide-row { display: none !important; } div.form-row.trexmes-cmd-form-row > .form-tips { width: calc(100% - 35px); } .trexmes-cmd-row-item { /* margin: 2px 4px 2px 2px; */ margin: 0px 4px 0px 2px; } .trexmes-cmd-row { flex-wrap: wrap; } ol .trexmes-cmd-row > .trexmes-cmd-row-item input[type="checkbox"] { width: 15px; margin-left: 4px; margin-top: -1px; margin-right: 20px; } ol .trexmes-cmd-row > .trexmes-cmd-row-item label { margin-top: 2px; margin-bottom: 0px; } </style> <script type="text/html" data-template-name="trexMes-CN"> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-name" ><i class="fa fa-tag"></i><span data-i18n="trexMes-CMD.connection.label.name"></span></label> <input type="text" id="node-config-input-name" data-i18n="[placeholder]trexMes-CMD.connection.label.name_ph"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-server"><i class="fa fa-server"></i> <span data-i18n="trexMes-CMD.connection.label.server"></span></label> <input type="text" id="node-config-input-server" data-i18n="[placeholder]trexMes-CMD.connection.label.server_ph"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-port"><i class="fa fa-random"></i> <span data-i18n="trexMes-CMD.connection.label.port"></span></label> <input type="text" id="node-config-input-port" data-i18n="[placeholder]trexMes-CMD.connection.label.port"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-username"><i class="fa fa-user"></i> <span data-i18n="trexMes-CMD.connection.label.username"></span></label> <input type="text" id="node-config-input-username"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-password"><i class="fa fa-lock"></i> <span data-i18n="trexMes-CMD.connection.label.password"></label> <input type="password" id="node-config-input-password"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-domain"><i class="fa fa-user"></i> <span data-i18n="trexMes-CMD.connection.label.domain"></label> <input type="text" id="node-config-input-domain"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-database"><i class="fa fa-database"></i> <span data-i18n="trexMes-CMD.connection.label.database"></label> <input type="text" id="node-config-input-database"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-companyId"><i class="fa fa-building"></i> <span data-i18n="trexMes-CMD.connection.label.companyId"></label> <input type="text" id="node-config-input-companyId"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-cperiodId"><i class="fa fa-building"></i> <span data-i18n="trexMes-CMD.connection.label.cperiodId"></label> <input type="text" id="node-config-input-cperiodId"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-userId"><i class="fa fa-user-md"></i> <span data-i18n="trexMes-CMD.connection.label.userId"></label> <input type="text" id="node-config-input-userId"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-tdsVersion"><i class="fa fa-list"></i> <span data-i18n="trexMes-CMD.connection.label.tds.title"></label> <select id="node-config-input-tdsVersion"> <option value="7_4" data-i18n="trexMes-CMD.connection.label.tds.v7_4"></option> <option value="7_3_B" data-i18n="trexMes-CMD.connection.label.tds.v7_3_b"></option> <option value="7_3_A" data-i18n="trexMes-CMD.connection.label.tds.v7_3_a"></option> <option value="7_2" data-i18n="trexMes-CMD.connection.label.tds.v7_2"></option> <option value="7_1" data-i18n="trexMes-CMD.connection.label.tds.v7_1"></option> </select> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-encyption"><i class="fa fa-lock"></i> <span data-i18n="trexMes-CMD.connection.label.encryption"></label> <input type="checkbox" id="node-config-input-encyption"> <div class="form-tips" data-i18n="trexMes-CMD.connection.label.encryption_tip"></div> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-trustServerCertificate"><i class="fa fa-lock"></i> Trust Certificate?</label> <input type="checkbox" id="node-config-input-trustServerCertificate"> <div class="form-tips">If unchecked, SQL Server will try to validate the server SSL certificate and will terminate the connection if validation fails</div> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-useUTC"><i class="fa fa-clock-o"></i> <span data-i18n="trexMes-CMD.connection.label.utc"></label> <input type="checkbox" id="node-config-input-useUTC"> <div class="form-tips" data-i18n="trexMes-CMD.connection.label.utc_tip"></div> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-connectTimeout"><i class="fa fa-clock-o"></i> <span data-i18n="trexMes-CMD.connection.label.connect_timeout"></label> <input type="text" id="node-config-input-connectTimeout"> <div class="form-tips" data-i18n="trexMes-CMD.connection.label.connect_timeout_tip"></div> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-requestTimeout"><i class="fa fa-clock-o"></i> <span data-i18n="trexMes-CMD.connection.label.request_timeout"></label> <input type="text" id="node-config-input-requestTimeout"> <div class="form-tips" data-i18n="trexMes-CMD.connection.label.request_timeout_tip"></div> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-cancelTimeout"><i class="fa fa-clock-o"></i> <span data-i18n="trexMes-CMD.connection.label.cancel_timeout"></label> <input type="text" id="node-config-input-cancelTimeout"> <div class="form-tips"data-i18n="trexMes-CMD.connection.label.cancel_timeout_tip"></div> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-pool"><i class="icon-bookmark"></i> <span data-i18n="trexMes-CMD.connection.label.max_pool_size"></label> <input type="text" id="node-config-input-pool" data-i18n="[placeholder]trexMes-CMD.connection.label.max_pool_size"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-parseJSON"><i class="fa fa-file-o"></i> <span data-i18n="trexMes-CMD.connection.label.parse_json"></label> <input type="checkbox" id="node-config-input-parseJSON"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-enableArithAbort" data-i18n="[title]trexMes-CMD.connection.label.arith_abort_tooltip"><i class="fa fa-times"></i> <span data-i18n="trexMes-CMD.connection.label.arith_abort"></label> <input type="checkbox" id="node-config-input-enableArithAbort" checked data-i18n="[title]trexMes-CMD.connection.label.arith_abort_tooltip"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-config-input-readOnlyIntent"><i class="fa fa-square-o"></i> <span data-i18n="trexMes-CMD.connection.label.read_only_intent"></label> <input type="checkbox" id="node-config-input-readOnlyIntent"> </div> </script> <script type="text/javascript"> RED.nodes.registerType('trexMes-CN', { category: 'config', color: '#C0DEED', defaults: { tdsVersion: { value: '7_4' }, name: { value: '' }, server: { value: '', required: true }, port: { value: '1433' }, encyption: { value: true }, trustServerCertificate: { value: true }, database: { value: '', required: false // database can be left blank but user should use full name in queries or a USE DB statment }, companyId: { value: 0, required: true }, cperiodId: { value: 0, required: true }, userId: { value: 0, required: true }, useUTC: { value: true }, connectTimeout: { value: '15000' }, requestTimeout: { value: '15000' }, cancelTimeout: { value: '5000' }, pool: { value: '5' }, parseJSON: { value: false }, enableArithAbort: { value: true }, readOnlyIntent: { value: false } }, inputs: 0, outputs: 0, credentials: { username: { type: 'text' }, password: { type: 'password' }, domain: { type: 'text' } }, label: function () { if (this.name) { return this.name; } let n = 'trexMes-CN'; if (this.server) { n = this.server; if (this.database) { n += '.' + this.database; } } return n; }, oneditresize: function (size) { $('div.form-row.trexmes-cmd-form-row > .form-tips').css('maxWidth', 'unset'); } }); </script> <script type="text/html" data-template-name="trexMes-CMD"> <div class="form-row trexmes-cmd-form-row"> <label for="node-input-trexmesCN"><i class="fa fa-globe"></i> <span data-i18n="trexMes-CMD.node.label.connection"></label> <input type="text" id="node-input-trexmesCN"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="trexMes-CMD.node.label.name"></span></label> <input type="text" id="node-input-name" data-i18n="[placeholder]trexMes-CMD.node.label.name"> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-input-modeOpt"><i class="fa fa-list-ul"></i> <span data-i18n="trexMes-CMD.node.label.query_mode"></span></label> <input type="hidden" id="node-input-modeOptType"> <input type="text" id="node-input-modeOpt" style="width: 70%" data-i18n="[placeholder]trexMes-CMD.node.label.query_mode"> </div> <label for="node-input-getOpenJobs-filter" id="node-input-label-getOpenJobs-filter" style="display:none"><i class="fa fa-filter"></i><span data-i18n="trexMes-CMD.node.label.getOpenJobs-filter"></span></label> <div class="form-row trexmes-cmd-form-row" id="node-input-getOpenJobs-filter" style="display:none"> <label for="node-input-isShowingOnlyJobsToCome" style="width: 70%"><span data-i18n="trexMes-CMD.node.label.isShowingOnlyJobsToCome"></span></label> <input type="checkbox" id="node-input-isShowingOnlyJobsToCome" style="width: 30%" data-i18n="[placeholder]trexMes-CMD.node.label.isShowingOnlyJobsToCome"> <br> <label for="node-input-isShowingOnlyPassedJobs" style="width: 70%"><span data-i18n="trexMes-CMD.node.label.isShowingOnlyPassedJobs"></span></label> <input type="checkbox" id="node-input-isShowingOnlyPassedJobs" style="width: 30%" data-i18n="[placeholder]trexMes-CMD.node.label.isShowingOnlyPassedJobs"> <br> <label for="node-input-isShowingSameStationGroupJobs" style="width: 70%"><span data-i18n="trexMes-CMD.node.label.isShowingSameStationGroupJobs"></span></label> <input type="checkbox" id="node-input-isShowingSameStationGroupJobs" style="width: 30%" data-i18n="[placeholder]trexMes-CMD.node.label.isShowingSameStationGroupJobs"> <br> <label for="node-input-isShowingSameWorkCenterJobs" style="width: 70%"><span data-i18n="trexMes-CMD.node.label.isShowingSameWorkCenterJobs"></span></label> <input type="checkbox" id="node-input-isShowingSameWorkCenterJobs" style="width: 30%" data-i18n="[placeholder]trexMes-CMD.node.label.isShowingSameWorkCenterJobs"> <br> <label for="node-input-isProducedQuantityConditionDisabled" style="width: 70%"><span data-i18n="trexMes-CMD.node.label.isProducedQuantityConditionDisabled"></span></label> <input type="checkbox" id="node-input-isProducedQuantityConditionDisabled" style="width: 30%" data-i18n="[placeholder]trexMes-CMD.node.label.isProducedQuantityConditionDisabled"> <br> <label for="node-input-isLineProduction" style="width: 70%"><span data-i18n="trexMes-CMD.node.label.isLineProduction"></span></label> <input type="checkbox" id="node-input-isLineProduction" style="width: 30%" data-i18n="[placeholder]trexMes-CMD.node.label.isLineProduction"> <br> <label for="node-input-isFinishingPlanWhenCompleted" style="width: 70%"><span data-i18n="trexMes-CMD.node.label.isFinishingPlanWhenCompleted"></span></label> <input type="checkbox" id="node-input-isFinishingPlanWhenCompleted" style="width: 30%" data-i18n="[placeholder]trexMes-CMD.node.label.isFinishingPlanWhenCompleted"> <br> <label for="node-input-isCheckingPreviousOperationProductionControl" style="width: 70%"><span data-i18n="trexMes-CMD.node.label.isCheckingPreviousOperationProductionControl"></span></label> <input type="checkbox" id="node-input-isCheckingPreviousOperationProductionControl" style="width: 30%" data-i18n="[placeholder]trexMes-CMD.node.label.isCheckingPreviousOperationProductionControl"> <br> <label for="node-input-isCheckingPreviousOperationWorkingControl" style="width: 70%"><span data-i18n="trexMes-CMD.node.label.isCheckingPreviousOperationWorkingControl"></span></label> <input type="checkbox" id="node-input-isCheckingPreviousOperationWorkingControl" style="width: 30%" data-i18n="[placeholder]trexMes-CMD.node.label.isCheckingPreviousOperationWorkingControl"> </div> <div class="form-row trexmes-cmd-form-row node-text-editor-row" style="min-height: 60px; margin-top: -6px;"> <label for="node-json-param-editor" style="width: 100% !important;"><i class="fa fa-tag"></i> <span data-i18n="trexMes-CMD.node.label.editor"></span></label> <div style="height: 60px;" class="node-text-editor" id="node-json-param-editor" ></div> </div> <div class="form-row trexmes-cmd-form-row"> <label for="node-input-throwErrors"><i class="fa fa-exclamation"></i> <span data-i18n="trexMes-CMD.node.label.error_handling"></label> <select id="node-input-throwErrors" style="width: 70%"> <option value="0" data-i18n="trexMes-CMD.node.label.error_handling_send_in_msg"></option> <option value="1" data-i18n="trexMes-CMD.node.label.error_handling_throw"></option> </select> </div> </script> <script type="text/javascript"> /* eslint-disable spaced-comment */ /* eslint-disable space-before-function-paren */ (function() { RED.nodes.registerType('trexMes-CMD', { category: 'trexmes', color: '#3FADB5', defaults: { trexmesCN: { type: 'trexMes-CN' }, name: { value: '' }, throwErrors: { value: 1 //0=original (for compatibility), 1=throw errors for catch node }, query: { value: '' }, modeOptType: { value: '1|Load Job Plan' }, isShowingOnlyJobsToCome: { value: false }, isShowingOnlyPassedJobs: { value: false }, isShowingSameStationGroupJobs: { value: false }, isShowingSameStationGroupJobs: { value: false }, isShowingSameWorkCenterJobs: { value: false }, isProducedQuantityConditionDisabled: { value: false }, isLineProduction: { value: false }, isFinishingPlanWhenCompleted: { value: false }, isCheckingPreviousOperationProductionControl: { value: false }, isCheckingPreviousOperationWorkingControl: { value: false } }, inputs: 1, outputs: 1, icon: "trex.png", label: function () { let optType = undefined; let splitted = this.modeOptType.split('|'); if(splitted.length > 1) { optType = splitted[1]; } return (this.name || optType) || 'TrexMes-CMD'; }, labelStyle: function () { return this.name ? 'node_label_italic' : ''; }, oneditprepare: function () { const node = this; if (node.query.trim().length === 0) { node.query = '{ "WorkstationId": 10 , "PlanId": 123 }'; node.query = JSON.stringify(JSON.parse(node.query),null, 2); } //create the query editor this.editor = RED.editor.createEditor({ id: 'node-json-param-editor', mode: 'ace/mode/json', value: node.query, // $("#node-input-query").val() readOnly: true }); //create typedInput widgets const modeField = $('#node-input-modeOpt').typedInput({ types: [ { value: '1|Load Job Plan', label: 'Load Job Plan', hasValue: false }, { value: '4|Finish Production', label: 'Finish Production', hasValue: false }, { value: '5|Start Stoppage', label: 'Start Stoppage', hasValue: false }, { value: '6|Change Stoppage', label: 'Change Stoppage', hasValue: false }, { value: '7|Finish Stoppage', label: 'Finish Stoppage', hasValue: false }, { value: '9|Login Employee', label: 'Login Employee', hasValue: false }, { value: '10|Logout Employee', label: 'Logout Employee', hasValue: false }, { value: '13|Shifted Shift', label: 'Shifted Shift', hasValue: false }, { value: '14|Start Test Mode', label: 'Start Test Mode', hasValue: false }, { value: '15|Finish Test Mode', label: 'Finish Test Mode', hasValue: false }, { value: '16|Create Deffect', label: 'Create Deffect', hasValue: false }, { value: '100|Get Open Jobs', label: 'Get Open Jobs', hasValue: false }, { value: '101|Get StopCause List', label: 'Get StopCause List', hasValue: false }, { value: '102|Get PWorkstation List', label: 'Get PWorkstation List', hasValue: false }, { value: '103|Get Station Status', label: 'Get Station Status', hasValue: false }, { value: '104|Get Employee List', label: 'Get Employee List', hasValue: false } ], typeField: $('#node-input-modeOptType'), default: 'Load Job Plan' }); //show expected data sample modeField.on('change', function() { const operationMode = $(this).typedInput('type'); $("#node-input-label-getOpenJobs-filter").hide(); $("#node-input-getOpenJobs-filter").hide(); let data = '{}'; if(operationMode.startsWith('1|')) { // Load Job Plan data = '{ "WorkstationId": 10 , "PlanId": 123 }'; } else if(operationMode.startsWith('4|')) { //Finish Production data = '{ "WorkstationId": 10 }'; } else if(operationMode.startsWith('5|')) { //Start Stoppage data = '{ "WorkstationId": 10 , "StoppageCauseId": 11 }'; } else if(operationMode.startsWith('6|')) { //Change Stoppage data = '{ "WorkstationId": 10 , "StoppageCauseId": 11 }'; } else if(operationMode.startsWith('7|')) { //Finish Stoppage data = '{ "WorkstationId": 10 }'; } else if(operationMode.startsWith('9|')) { //Login Employee data = '{ "WorkstationId": 10, "EmployeeId": 11 }'; } else if(operationMode.startsWith('10|')) { //Logout Employee data = '{ "WorkstationId": 10, "EmployeeId": 11 }'; } else if(operationMode.startsWith('13|')) { //Shifted Shift data = '{ "WorkstationId": 10, "LineId": 11 }'; } else if(operationMode.startsWith('14|')) { //Start Test Mode data = '{ "WorkstationId": 10, "StoppageCauseId": 11 }'; } else if(operationMode.startsWith('15|')) { //Finish Test Mode data = '{ "WorkstationId": 10 }'; } else if(operationMode.startsWith('16|')) { //Create Deffect data = '{ "WorkstationId": 10, "JobOrderId": 123456, "DefectId": 11,"StockId": 12, "Quantity": 15.5 }'; } else if(operationMode.startsWith('100|')) { //Get Open Jobs data = '{ "WorkstationId": 10 }'; $("#node-input-label-getOpenJobs-filter").show(); $("#node-input-getOpenJobs-filter").show(); } else if(operationMode.startsWith('101|')) { //Get StopCause List data = '{ "WorkstationId": 10 }'; } else if(operationMode.startsWith('102|')) { //Get PWorkstation List data = '{}'; } else if(operationMode.startsWith('103|')) { //Get Station Status data = '{ "WorkstationId": 10 }'; } else if(operationMode.startsWith('104|')) { //Get Employee List data = '{}'; } node.editor.setValue(JSON.stringify(JSON.parse(data),null, 2)); }); $('#node-input-throwErrors')[0].selectedIndex = this.throwErrors ? this.throwErrors : 0; if(this.modeOptType.startsWith("100|")) { $("#node-input-label-getOpenJobs-filter").show(); $("#node-input-getOpenJobs-filter").show(); } else { $("#node-input-label-getOpenJobs-filter").hide(); $("#node-input-getOpenJobs-filter").hide(); } }, oneditsave: function () { const node = this; node.query = this.editor.getValue(); this.editor.destroy(); }, oneditresize: function (size) { const rows = $('#dialog-form>div:not(.node-text-editor-row)'); let height = $('#dialog-form').height(); let row; for (let i = 0; i < rows.size(); i++) { row = $(rows[i]); if (row && row.is(':hidden')) continue; height -= row.outerHeight(true); } const editorRow = $('#dialog-form>div.node-text-editor-row'); height -= (parseInt(editorRow.css('marginTop')) + parseInt(editorRow.css('marginBottom'))); const h = Math.max(height, 60); $('.node-text-editor').css('height', h + 'px'); this.editor.resize(); } }); })(); </script>