Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/core/darkconsole/behavior-dark-console.js
- This file was moved from webroot/rsrc/js/core/behavior-dark-console.js.
| /** | /** | ||||
| * @provides javelin-behavior-dark-console | * @provides javelin-behavior-dark-console | ||||
| * @requires javelin-behavior | * @requires javelin-behavior | ||||
| * javelin-stratcom | * javelin-stratcom | ||||
| * javelin-util | * javelin-util | ||||
| * javelin-dom | * javelin-dom | ||||
| * javelin-request | * javelin-request | ||||
| * phabricator-keyboard-shortcut | * phabricator-keyboard-shortcut | ||||
| * phabricator-darklog | |||||
| * phabricator-darkmessage | |||||
| */ | */ | ||||
| JX.behavior('dark-console', function(config, statics) { | JX.behavior('dark-console', function(config, statics) { | ||||
| // Do first-time setup. | // Do first-time setup. | ||||
| function setup_console() { | function setup_console() { | ||||
| init_console(config.visible); | init_console(config.visible); | ||||
| ▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | JX.behavior('dark-console', function(config, statics) { | ||||
| function draw_panel() { | function draw_panel() { | ||||
| var data = statics.cache[statics.req.current]; | var data = statics.cache[statics.req.current]; | ||||
| var tclass = JX.Stratcom.getData(statics.tab.current)['class']; | var tclass = JX.Stratcom.getData(statics.tab.current)['class']; | ||||
| var html = data.panel[tclass]; | var html = data.panel[tclass]; | ||||
| var div = JX.$N('div', {className: 'dark-console-panel-core'}, JX.$H(html)); | var div = JX.$N('div', {className: 'dark-console-panel-core'}, JX.$H(html)); | ||||
| JX.DOM.setContent(statics.el.panel, div); | JX.DOM.setContent(statics.el.panel, div); | ||||
| var params = { | |||||
| panel: tclass | |||||
| }; | |||||
| JX.Stratcom.invoke('darkconsole.draw', null, params); | |||||
| } | } | ||||
| function install_shortcut() { | function install_shortcut() { | ||||
| var desc = 'Toggle visibility of DarkConsole.'; | var desc = 'Toggle visibility of DarkConsole.'; | ||||
| new JX.KeyboardShortcut('`', desc) | new JX.KeyboardShortcut('`', desc) | ||||
| .setHandler(function() { | .setHandler(function() { | ||||
| statics.visible = !statics.visible; | statics.visible = !statics.visible; | ||||
| Show All 25 Lines | if (config.quicksand && statics.quicksand_key) { | ||||
| statics.quicksand_color = null; | statics.quicksand_color = null; | ||||
| } | } | ||||
| config.key = config.key || statics.root.getAttribute('data-console-key'); | config.key = config.key || statics.root.getAttribute('data-console-key'); | ||||
| if (!('color' in config)) { | if (!('color' in config)) { | ||||
| config.color = statics.root.getAttribute('data-console-color'); | config.color = statics.root.getAttribute('data-console-color'); | ||||
| } | } | ||||
| add_request(config); | add_request(config); | ||||
| /* -( Realtime Panel )----------------------------------------------------- */ | |||||
| if (!statics.realtime) { | |||||
| statics.realtime = true; | |||||
| var realtime_log = new JX.DarkLog(); | |||||
| var realtime_id = 'dark-console-realtime-log'; | |||||
| JX.Stratcom.listen('darkconsole.draw', null, function(e) { | |||||
| var data = e.getData(); | |||||
| if (data.panel != 'DarkConsoleRealtimePlugin') { | |||||
| return; | |||||
| } | |||||
| var node = JX.$(realtime_id); | |||||
| realtime_log.setNode(node); | |||||
| }); | |||||
| // If the panel is initially visible, try rendering. | |||||
| try { | |||||
| var node = JX.$(realtime_id); | |||||
| realtime_log.setNode(node); | |||||
| } catch (exception) { | |||||
| // Ignore. | |||||
| } | |||||
| var leader_log = function(event_name, type, is_leader, details) { | |||||
| var parts = []; | |||||
| if (is_leader === true) { | |||||
| parts.push('+'); | |||||
| } else if (is_leader === false) { | |||||
| parts.push('-'); | |||||
| } else { | |||||
| parts.push('~'); | |||||
| } | |||||
| parts.push('[Leader/' + event_name + ']'); | |||||
| if (type) { | |||||
| parts.push('(' + type + ')'); | |||||
| } | |||||
| if (details) { | |||||
| parts.push(details); | |||||
| } | |||||
| parts = parts.join(' '); | |||||
| var message = new JX.DarkMessage() | |||||
| .setMessage(parts); | |||||
| realtime_log.addMessage(message); | |||||
| }; | |||||
| JX.Leader.listen('onReceiveBroadcast', function(message, is_leader) { | |||||
| var json = JX.JSON.stringify(message.data); | |||||
| leader_log('onReceiveBroadcast', message.type, is_leader, json); | |||||
| }); | |||||
| JX.Leader.listen('onBecomeLeader', function() { | |||||
| leader_log('onBecomeLeader'); | |||||
| }); | |||||
| } | |||||
| }); | }); | ||||