Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial Commit

  • Loading branch information...
commit dba12872d2bc94d2c0f54865882ffa70851b1013 1 parent a81f1a8
Christopher Woodward cwoodward authored
131 engines/console/app/controllers/erp_app/desktop/console/base_controller.rb
View
@@ -0,0 +1,131 @@
+class ErpApp::Desktop::Console::BaseController < ErpApp::Desktop::BaseController
+ def command
+ logger.debug("command received:#{params}")
+ begin
+ result=""
+
+ # NOTE- the console uses a shared binding. this is due to the fact
+ # that binding instances are not serializable and cant be stored
+ # in a user session. Until this is resolved we use a global var.
+ # this should not pose a problem as the console should only be used
+ # in development or by a sysadmin.
+
+ # the shared binding is needed to allow for variable scope visibility
+ # across multiple requests
+ if($session_binding==nil)
+ $session_binding=binding
+ end
+
+ command_message=params[:command_message]
+ logger.debug("console session context:#{$session_binding}")
+ logger.debug("command:#{command_message}")
+
+ # here we handle any desktop console-specific command
+ # these can include non-eval related funtions
+ # or provide shortcuts to common eval expressions
+ if(command_message.match(/^-help/))
+ result = help_message
+ elsif(command_message.match(/^-clear/))
+ # this is actually handled in the console desktop application
+ #result = evaluate_command("")
+ elsif(command_message.match(/^-time/))
+ result = evaluate_command("Time.now")
+ elsif(command_message.match(/^-whoami/))
+ result = evaluate_command("current_user.login")
+ else
+ result=evaluate_command(command_message)
+ end
+
+ logger.debug("result#{result}")
+
+ result_message =result.to_s.gsub("\n", "<br />\n")
+ render :json=> {:success=>"#{result_message}<hr><br>"}
+ end
+ end
+ private
+ #****************************************************************************
+ def help_message()
+ message = "<font color='lightgray'><b>Compass Desktop Console Help<b><hr>"
+ message<< "<ul>"
+ message<< "<li>-clear : <font color='yellow'>Clear screen contents.</font></li>"
+ message<< "<li>-help : <font color='yellow'>This help list.</font></li>"
+ message<< "<li>-time : <font color='yellow'>Current time.</font></li>"
+ message<< "<li>-whoami : <font color='yellow'>Logged in as.</font></li>"
+ message<< "</ul> </font>"
+ end
+ #****************************************************************************
+ def highlight(model)
+ buffer=""
+ model.attributes.keys.sort.each do |model_attribute_key|
+ CompassLogger.debug("key:#{model_attribute_key}")
+
+ buffer<<"<font color='yellow'>#{model_attribute_key}</font> <font color='lightgray'>=</font><font color='gold'>#{model.attributes[model_attribute_key]}</font> <font color='lightgray'>, </font>"
+ end
+ return buffer
+ end
+ #****************************************************************************
+
+ def evaluate_command(command_message)
+ CompassLogger.debug("evaluate_command(#{command_message}")
+ begin
+
+ result_eval = $session_binding.eval( command_message)
+
+ if(result_eval.is_a? ActiveRecord::Base)
+ result= render_active_record_model(result_eval)
+ elsif (result_eval.is_a? Array)
+ result= render_array(result_eval)
+ elsif (result_eval.is_a? Hash)
+ result= render_hash(result_eval)
+ else
+ #result="#{result_eval.class.to_s} #{result_eval.to_s}<br>"
+ result="#{result_eval.to_s}<br>"
+ end
+
+ rescue Exception => e
+ result = "<font color='red'>#{e.to_s}</font>"
+ end
+
+ return result
+ end
+ #****************************************************************************
+ def render_active_record_model(result_eval)
+ CompassLogger.debug("render_active_record_model:#{result_eval}")
+ "<font color='YellowGreen'>#{result_eval.class} </font><br>#{highlight(result_eval)} "
+ end
+ #****************************************************************************
+ def render_array(result_eval)
+ result="#{result_eval.class.to_s}<br>"
+ CompassLogger.debug("render_array:#{result_eval}")
+ count=0
+ result_eval.each do |array_element|
+ if(array_element.is_a? ActiveRecord::Base)
+ result<< "<font color='YellowGreen'>#{array_element.class}<font color='yellow'>[</font><font color='white'>#{count}</font><font color='yellow'>]</font> </font>#{highlight(array_element)} <br><br>"
+ else
+ result<<"<font color='YellowGreen'>#{array_element.class}<font color='yellow'>[</font><font color='white'>#{count}</font><font color='yellow'>]</font> </font>#{array_element} <br><br>"
+ end
+ count=count+1
+ end
+ return result
+ end
+ #****************************************************************************
+ def render_hash(result_eval)
+ CompassLogger.debug("render_hash:#{result_eval}")
+ result="#{result_eval.class.to_s}<br>"
+ count=0
+ result_eval.keys.each do |hash_key|
+ symbol_modifier=''
+ if(hash_key.is_a? Symbol)
+ symbol_modifier=':'
+ end
+ if(hash_key.is_a? ActiveRecord::Base)
+
+ result<< "<font color='YellowGreen'>#{result_eval.class}<font color='yellow'>[</font><font color='white'>#{symbol_modifier}#{hash_key}</font><font color='yellow'>] => </font> </font>#{highlight(result_eval[hash_key])} <br>"
+ else
+ result<<"<font color='YellowGreen'>#{result_eval.class}<font color='yellow'>[</font><font color='white'>#{symbol_modifier}#{hash_key}</font><font color='yellow'>] => </font> </font>#{result_eval[hash_key]} <br>"
+ end
+ count=count+1
+ end
+ return result
+ end
+end
12 engines/console/config/routes.rb
View
@@ -0,0 +1,12 @@
+
+ActionController::Routing::Routes.draw do |map|
+
+
+
+
+ map.connect '/console/:action.:format', :controller => 'erp_app/desktop/console/base'
+
+
+end
+
+
20 engines/console/db/data_migrations/20110824020426_create_desktop_app_console.rb
View
@@ -0,0 +1,20 @@
+class CreateDesktopAppConsole
+ def self.up
+ app = DesktopApplication.create(
+ :description => 'Desktop Console',
+ :icon => 'icon-console',
+ :javascript_class_name => 'Compass.ErpApp.Desktop.Applications.Console',
+ :internal_identifier => 'console',
+ :shortcut_id => 'console-win'
+ )
+
+ #PreferenceType.iid('desktop_shortcut').preferenced_records << app
+ #PreferenceType.iid('autoload_application').preferenced_records << app
+
+ app.save
+ end
+
+ def self.down
+ DesktopApplication.destroy_all(['internal_identifier = ?','console'])
+ end
+end
BIN  engines/console/public/images/console_background.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  engines/console/public/images/icons/console/console_16x16.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  engines/console/public/images/icons/console/console_32x32.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  engines/console/public/images/icons/console/console_48x48.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 engines/console/public/javascripts/erp_app/desktop/applications/console/module.js
View
@@ -0,0 +1,180 @@
+//**************************************************
+// Compass Desktop Console
+//**************************************************
+var desktop_console_history=new Array();
+var desktop_console_history_index=0;
+//----------------------------------
+// add startsWith method to string
+String.prototype.startsWith = function (str){
+ return this.indexOf(str) == 0;
+};
+//---------------------------------
+var startup_heading="<font color='goldenrod'><b>Desktop Console Version 0.01</b>&nbsp;(<font color='white'>-help</font> for Help)</font><br>"
+//---------------------------------
+function sendCommand(destination,command){
+ update_history_panel("<font color='white'>"+command+"</font>")
+
+ if(command.startsWith("-clear")){
+ clear_history_panel(startup_heading+"<br><hr>");
+ }else{
+
+ Ext.Ajax.request({
+ url: '/erp_app/desktop/console/command',
+ params: {
+
+ command_message: command
+ },
+ success: function(response){
+ var text = response.responseText;
+ var result =Ext.JSON.decode(text)
+ update_history_panel("<font color='yellow'>"+result.success+"</font>")
+ }
+ });
+ }
+}
+//---------------------------------
+function clear_history_panel(text){
+ var panel=Ext.getCmp('console_history_panel');
+
+ panel.update(""+text+"<br>");
+
+ var d = panel.body.dom;
+ d.scrollTop = d.scrollHeight - d.offsetHeight+10;
+ panel.doLayout();
+}
+//---------------------------------
+function update_history_panel(text){
+ var panel=Ext.getCmp('console_history_panel');
+ var old = panel.body.dom.innerHTML;
+ panel.update(old+""+text+"<br>");
+
+ var d = panel.body.dom;
+ d.scrollTop = d.scrollHeight - d.offsetHeight+10;
+ panel.doLayout();
+}
+
+//---------------------------------
+var console_history_panel ={
+ xtype: 'panel',
+
+ id : 'console_history_panel',
+ region: 'center',
+ bodyStyle: "background-image:url(/images/console_background.png) !important",
+ autoScroll:true,
+ html : startup_heading
+}
+
+//---------------------------------
+
+var console_text_area ={
+ xtype: 'textarea',
+ region : 'south',
+ style: "{background-image:url(/images/console_background.png)}",
+ autoscroll: true,
+ id: "console_text_area",
+ enableKeyEvents: true,
+ listeners: {
+ afterrender: function(field) {
+ field.focus();
+ },
+
+
+ // use key-up for textarea since ENTER does not affect focus traversal
+ keyup: function(field, e){
+ //console.log("textarea keyup:"+e);
+ if (e.getKey() == e.ENTER){
+
+ sendCommand('console_text_area',field.getValue());
+ // add to history
+ desktop_console_history[desktop_console_history.length]=field.getValue().substring(0,field.getValue().length-1);
+ //update index
+ desktop_console_history_index=desktop_console_history.length
+ field.setValue("");
+ }else if (e.getKey() == e.UP){
+
+ if(desktop_console_history.length==0){
+ // no history to display
+ }else{
+ desktop_console_history_index--;
+ if(desktop_console_history_index >=0){
+
+ }
+ else{
+ desktop_console_history_index=desktop_console_history.length-1
+ }
+ field.setValue(desktop_console_history[desktop_console_history_index]);
+ }
+
+ }else if (e.getKey() == e.DOWN){
+
+ if(desktop_console_history.length==0){
+ // no history to display
+ }else{
+ desktop_console_history_index++;
+ if(desktop_console_history_index >=(desktop_console_history.length)){
+ desktop_console_history_index=0
+ }
+ else{
+ //desktop_console_history_index=desktop_console_history.length-1
+ }
+ field.setValue(desktop_console_history[desktop_console_history_index]);
+ }
+ }
+ }
+
+ }
+}
+//---------------------------------
+var console_panel={
+ xtype: 'panel',
+ layout: 'border',
+ items :[ console_history_panel,console_text_area]
+
+}
+
+//---------------------------------
+
+Ext.define("Compass.ErpApp.Desktop.Applications.Console",{
+ extend:"Ext.ux.desktop.Module",
+ id:'console-win',
+ init : function(){
+ this.launcher = {
+ text: 'Desktop Console',
+ iconCls:'console_icon',
+ handler: this.createWindow,
+ scope: this
+ }
+ },
+
+ createWindow : function(){
+ var desktop = this.app.getDesktop();
+ var win = desktop.getWindow('console');
+ if(!win){
+ win = desktop.createWindow({
+ id: 'console',
+ title:'Desktop Console',
+ width:1000,
+ height:670,
+ iconCls: 'console_icon',
+ shim:false,
+ animCollapse:false,
+ resizable : false,
+ constrainHeader:true,
+ layout: 'fit',
+ items:[console_panel]
+ ,
+ tools:[
+ {
+ type:'help',
+ tooltip: 'about',
+ handler: function(event, toolEl, panel){
+ Ext.Msg.alert("About","<center><b>Desktop Console</b><br><i>Version 0.01</i>")
+ }
+ }]
+
+ });
+ }
+ win.show();
+ sendCommand('console_text_area',"Rails.version ");
+ }
+});
7 engines/console/public/stylesheets/erp_app/desktop/applications/console/console.css
View
@@ -0,0 +1,7 @@
+.console_icon-desktop-icon{
+ background-image: url(/images/icons/console/console.png) !important;
+}
+
+.console_icon {
+ background-image: url(/images/icons/console/console_16x16.png) !important;
+}
BIN  engines/erp_app/public/javascripts/erp_app/ckeditor/plugins/syntax_highlighter/images/Thumbs.db
View
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.