|
11 | 11 | var inspector; |
12 | 12 |
|
13 | 13 | function processMainIncomingMessage(msg) { |
14 | | - console.log('Devpanel Processing Message', msg); |
15 | | - if (msg.msgType === 'context') { |
16 | | - displayMessage('Looks like a Solidus page!'); |
17 | | - //Check if there is an initialized InspectorJSON that hasn't been destroyed |
18 | | - if ((inspector instanceof InspectorJSON) && (inspector.page)) { |
19 | | - inspector.view(msg.msg); |
20 | | - } else { |
21 | | - inspector = new InspectorJSON({ |
22 | | - element: 'pagecontext', |
23 | | - url: msg.msg.url.path, |
24 | | - json: msg.msg |
25 | | - }); |
26 | | - } |
27 | | - } else if (msg.msgType === 'error') { |
28 | | - if (inspector instanceof InspectorJSON) { |
29 | | - inspector.destroy(); |
30 | | - } |
31 | | - displayMessage(msg.msg); |
32 | | - } else if (msg.msgType === 'status') { |
33 | | - displayMessage(msg.msg); |
| 14 | + switch(msg.msgType) { |
| 15 | + case 'context': |
| 16 | + setupInspector(msg.msg); |
| 17 | + break; |
| 18 | + case 'error': |
| 19 | + destroyInspector(); |
| 20 | + showAlert(msg.msg, 'Error:'); |
| 21 | + //activateTab('info'); |
| 22 | + break; |
| 23 | + case 'status': |
| 24 | + updateStatus(msg.msg); |
| 25 | + break; |
| 26 | + default: |
| 27 | + console.log('Unhandled Message', msg); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +function setupInspector(context) { |
| 32 | + if ((inspector instanceof InspectorJSON) && (inspector.page)) { |
| 33 | + inspector.view(context); |
34 | 34 | } else { |
35 | | - console.log('Message Not Processed', msg); |
| 35 | + inspector = new InspectorJSON({ |
| 36 | + element: 'pagecontext', |
| 37 | + url: context.url.path, |
| 38 | + json: context |
| 39 | + }); |
36 | 40 | } |
37 | 41 | } |
38 | 42 |
|
39 | | -function displayMessage(msg) { |
40 | | - document.querySelector('#messageholder').innerHTML = msg; |
41 | | - console.log('Updated Panel With Message', msg); |
| 43 | +function destroyInspector() { |
| 44 | + if (inspector instanceof InspectorJSON) { |
| 45 | + inspector.destroy(); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +function createAlert(info, label, alertClass) { //Create a Bootstrap HTML alert |
| 50 | + var infoClass = alertClass?alertClass:'alert-info'; |
| 51 | + var infoLabel = label?'<strong>' + label +'</strong> ':''; |
| 52 | + return '<div class="alert ' + infoClass + |
| 53 | + ' alert-dismissible" role="alert"><button type="button" class="close"' + |
| 54 | + ' data-dismiss="alert"><span aria-hidden="true">×</span>' + |
| 55 | + '<span class="sr-only">Close</span></button>' + infoLabel + info + '</div>'; |
| 56 | +} |
| 57 | + |
| 58 | +function showAlert(message, label, alertClass){ //Show an alert |
| 59 | + var theAlert = createAlert(message, label, alertClass); |
| 60 | + document.querySelector('#messageholder').innerHTML += theAlert; |
| 61 | +} |
| 62 | + |
| 63 | +function updateStatus(status) { //Update status panel in footer |
| 64 | + document.querySelector('#pluginstatus').innerHTML = status; |
42 | 65 | } |
43 | 66 |
|
44 | 67 | var socket = io('http://localhost:8081'); |
|
0 commit comments