compass_ae_console 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/GPL-3-LICENSE +674 -0
- data/README.md +5 -0
- data/Rakefile +30 -0
- data/app/controllers/compass_ae_console/erp_app/desktop/base_controller.rb +142 -0
- data/config/routes.rb +3 -0
- data/db/data_migrations/20110824020426_create_desktop_app_console.rb +19 -0
- data/lib/compass_ae_console.rb +8 -0
- data/lib/compass_ae_console/engine.rb +10 -0
- data/lib/compass_ae_console/version.rb +3 -0
- data/public/images/console_background.png +0 -0
- data/public/javascripts/erp_app/desktop/applications/compass_ae_console/module.js +180 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +42 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +8 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/spec.rb +27 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/spec_helper.rb +60 -0
- metadata +165 -0
data/README.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
![Logo](http://github.com/portablemind/compass_agile_enterprise/raw/master/erp_app/public/images/art/compass-logo-1-medium.png)
|
2
|
+
|
3
|
+
#Compass Console
|
4
|
+
|
5
|
+
Compass Console is an application that sits on top of the Compass AE framework that allows the user to interact with their rails application with a simulated rails console.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'CompassAeConsole'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
28
|
+
require "rspec/core/rake_task"
|
29
|
+
RSpec::Core::RakeTask.new(:spec)
|
30
|
+
task :default => :spec
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module CompassAeConsole
|
2
|
+
module ErpApp
|
3
|
+
module Desktop
|
4
|
+
class BaseController < ::ErpApp::Desktop::BaseController
|
5
|
+
def command
|
6
|
+
logger.debug("command received:#{params}")
|
7
|
+
begin
|
8
|
+
result=""
|
9
|
+
|
10
|
+
# NOTE- the console uses a shared binding. this is due to the fact
|
11
|
+
# that binding instances are not serializable and cant be stored
|
12
|
+
# in a user session. Until this is resolved we use a global var.
|
13
|
+
# this should not pose a problem as the console should only be used
|
14
|
+
# in development or by a sysadmin.
|
15
|
+
|
16
|
+
# the shared binding is needed to allow for variable scope visibility
|
17
|
+
# across multiple requests
|
18
|
+
if($session_binding==nil)
|
19
|
+
$session_binding=binding
|
20
|
+
end
|
21
|
+
|
22
|
+
command_message=params[:command_message]
|
23
|
+
logger.debug("console session context:#{$session_binding}")
|
24
|
+
logger.debug("command:#{command_message}")
|
25
|
+
|
26
|
+
# here we handle any desktop console-specific command
|
27
|
+
# these can include non-eval related funtions
|
28
|
+
# or provide shortcuts to common eval expressions
|
29
|
+
result = case command_message
|
30
|
+
when /^-help/
|
31
|
+
help_message
|
32
|
+
when /^-clear/
|
33
|
+
#this is actually handled in the console desktop application
|
34
|
+
#evaluate_command("")
|
35
|
+
when /^-time/
|
36
|
+
evaluate_command("Time.now")
|
37
|
+
when /^-whoami/
|
38
|
+
evaluate_command("current_user.username")
|
39
|
+
else
|
40
|
+
evaluate_command(command_message)
|
41
|
+
end
|
42
|
+
|
43
|
+
logger.debug("result#{result}")
|
44
|
+
|
45
|
+
result_message =result.to_s.gsub("\n", "<br />\n")
|
46
|
+
render :json=> {:success=>"#{result_message}<hr><br>"}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
private
|
50
|
+
#****************************************************************************
|
51
|
+
def help_message()
|
52
|
+
message = "<font color='lightgray'><b>Compass Desktop Console Help<b><hr>"
|
53
|
+
message<< "<ul>"
|
54
|
+
message<< "<li>-clear : <font color='yellow'>Clear screen contents.</font></li>"
|
55
|
+
message<< "<li>-help : <font color='yellow'>This help list.</font></li>"
|
56
|
+
message<< "<li>-time : <font color='yellow'>Current time.</font></li>"
|
57
|
+
message<< "<li>-whoami : <font color='yellow'>Logged in as.</font></li>"
|
58
|
+
message<< "</ul> </font>"
|
59
|
+
end
|
60
|
+
#****************************************************************************
|
61
|
+
def highlight_class(klass)
|
62
|
+
klass.columns.map do |column|
|
63
|
+
"<font color='yellow'>#{column.name}</font><font color='lightgray'>:</font><font color='gold'>#{column.type}</font>"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def hightlight_instance(instance)
|
68
|
+
buffer=""
|
69
|
+
instance.attributes.keys.sort.each do |model_attribute_key|
|
70
|
+
ErpTechSvcs::Util::CompassLogger.debug("key:#{model_attribute_key}")
|
71
|
+
|
72
|
+
buffer<<"<font color='yellow'>#{model_attribute_key}</font> <font color='lightgray'>=</font><font color='gold'>#{instance.attributes[model_attribute_key]}</font> <font color='lightgray'>, </font>"
|
73
|
+
end
|
74
|
+
return buffer
|
75
|
+
end
|
76
|
+
#****************************************************************************
|
77
|
+
|
78
|
+
def evaluate_command(command_message)
|
79
|
+
ErpTechSvcs::Util::CompassLogger.debug("evaluate_command(#{command_message}")
|
80
|
+
begin
|
81
|
+
result_eval = $session_binding.eval(command_message)
|
82
|
+
if(result_eval.respond_to?("superclass") && result_eval.superclass == ActiveRecord::Base)
|
83
|
+
result = render_active_record_model(result_eval)
|
84
|
+
elsif (result_eval.is_a? Array)
|
85
|
+
result = render_array(result_eval)
|
86
|
+
elsif (result_eval.is_a? Hash)
|
87
|
+
result = render_hash(result_eval)
|
88
|
+
else
|
89
|
+
#result="#{result_eval.class.to_s} #{result_eval.to_s}<br>"
|
90
|
+
result = "#{result_eval.to_s}<br>"
|
91
|
+
end
|
92
|
+
|
93
|
+
rescue Exception => e
|
94
|
+
result = "<font color='red'>#{e.to_s}</font>"
|
95
|
+
end
|
96
|
+
|
97
|
+
result
|
98
|
+
end
|
99
|
+
#****************************************************************************
|
100
|
+
def render_active_record_model(result_eval)
|
101
|
+
ErpTechSvcs::Util::CompassLogger.debug("render_active_record_model:#{result_eval}")
|
102
|
+
"<font color='YellowGreen'>#{result_eval.class} </font><br>#{highlight_class(result_eval)} "
|
103
|
+
end
|
104
|
+
#****************************************************************************
|
105
|
+
def render_array(result_eval)
|
106
|
+
result="#{result_eval.class.to_s}<br>"
|
107
|
+
ErpTechSvcs::Util::CompassLogger.debug("render_array:#{result_eval}")
|
108
|
+
count=0
|
109
|
+
result_eval.each do |array_element|
|
110
|
+
if(array_element.is_a? ActiveRecord::Base)
|
111
|
+
result<< "<font color='YellowGreen'>#{array_element.class}<font color='yellow'>[</font><font color='white'>#{count}</font><font color='yellow'>]</font> </font>#{hightlight_instance(array_element)} <br><br>"
|
112
|
+
else
|
113
|
+
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>"
|
114
|
+
end
|
115
|
+
count=count+1
|
116
|
+
end
|
117
|
+
result
|
118
|
+
end
|
119
|
+
#****************************************************************************
|
120
|
+
def render_hash(result_eval)
|
121
|
+
ErpTechSvcs::Util::CompassLogger.debug("render_hash:#{result_eval}")
|
122
|
+
result="#{result_eval.class.to_s}<br>"
|
123
|
+
count=0
|
124
|
+
result_eval.keys.each do |hash_key|
|
125
|
+
symbol_modifier=''
|
126
|
+
if(hash_key.is_a? Symbol)
|
127
|
+
symbol_modifier=':'
|
128
|
+
end
|
129
|
+
if(hash_key.is_a? ActiveRecord::Base)
|
130
|
+
|
131
|
+
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>"
|
132
|
+
else
|
133
|
+
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>"
|
134
|
+
end
|
135
|
+
count=count+1
|
136
|
+
end
|
137
|
+
result
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end#end BaseController
|
141
|
+
end#end ErpApp
|
142
|
+
end#end Console
|
data/config/routes.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateDesktopAppConsole
|
2
|
+
def self.up
|
3
|
+
app = DesktopApplication.create(
|
4
|
+
:description => 'Compass Console',
|
5
|
+
:icon => 'icon-console',
|
6
|
+
:javascript_class_name => 'Compass.ErpApp.Desktop.Applications.CompassAeConsole',
|
7
|
+
:internal_identifier => 'compass_ae_console',
|
8
|
+
:shortcut_id => 'compass_console-win'
|
9
|
+
)
|
10
|
+
|
11
|
+
app.preference_types << PreferenceType.iid('desktop_shortcut')
|
12
|
+
app.preference_types << PreferenceType.iid('autoload_application')
|
13
|
+
app.save
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
DesktopApplication.destroy_all(['internal_identifier = ?','compass_ae_console'])
|
18
|
+
end
|
19
|
+
end
|
Binary file
|
@@ -0,0 +1,180 @@
|
|
1
|
+
//**************************************************
|
2
|
+
// Compass Desktop Console
|
3
|
+
//**************************************************
|
4
|
+
var desktop_console_history=new Array();
|
5
|
+
var desktop_console_history_index=0;
|
6
|
+
//----------------------------------
|
7
|
+
// add startsWith method to string
|
8
|
+
String.prototype.startsWith = function (str){
|
9
|
+
return this.indexOf(str) == 0;
|
10
|
+
};
|
11
|
+
//---------------------------------
|
12
|
+
var startup_heading="<font color='goldenrod'><b>Compass Console Version 0.01</b> (<font color='white'>-help</font> for Help)</font><br>"
|
13
|
+
//---------------------------------
|
14
|
+
function sendCommand(destination,command){
|
15
|
+
update_history_panel("<font color='white'>"+command+"</font>")
|
16
|
+
|
17
|
+
if(command.startsWith("-clear")){
|
18
|
+
clear_history_panel(startup_heading+"<br><hr>");
|
19
|
+
}else{
|
20
|
+
|
21
|
+
Ext.Ajax.request({
|
22
|
+
url: '/compass_ae_console/erp_app/desktop/command',
|
23
|
+
params: {
|
24
|
+
|
25
|
+
command_message: command
|
26
|
+
},
|
27
|
+
success: function(response){
|
28
|
+
var text = response.responseText;
|
29
|
+
var result =Ext.JSON.decode(text)
|
30
|
+
update_history_panel("<font color='yellow'>"+result.success+"</font>")
|
31
|
+
}
|
32
|
+
});
|
33
|
+
}
|
34
|
+
}
|
35
|
+
//---------------------------------
|
36
|
+
function clear_history_panel(text){
|
37
|
+
var panel=Ext.getCmp('console_history_panel');
|
38
|
+
|
39
|
+
panel.update(""+text+"<br>");
|
40
|
+
|
41
|
+
var d = panel.body.dom;
|
42
|
+
d.scrollTop = d.scrollHeight - d.offsetHeight+10;
|
43
|
+
panel.doLayout();
|
44
|
+
}
|
45
|
+
//---------------------------------
|
46
|
+
function update_history_panel(text){
|
47
|
+
var panel=Ext.getCmp('console_history_panel');
|
48
|
+
var old = panel.body.dom.innerHTML;
|
49
|
+
panel.update(old+""+text+"<br>");
|
50
|
+
|
51
|
+
var d = panel.body.dom;
|
52
|
+
d.scrollTop = d.scrollHeight - d.offsetHeight+10;
|
53
|
+
panel.doLayout();
|
54
|
+
}
|
55
|
+
|
56
|
+
//---------------------------------
|
57
|
+
var console_history_panel ={
|
58
|
+
xtype: 'panel',
|
59
|
+
|
60
|
+
id : 'console_history_panel',
|
61
|
+
region: 'center',
|
62
|
+
bodyStyle: "background-image:url(/images/console_background.png) !important",
|
63
|
+
autoScroll:true,
|
64
|
+
html : startup_heading
|
65
|
+
}
|
66
|
+
|
67
|
+
//---------------------------------
|
68
|
+
|
69
|
+
var console_text_area ={
|
70
|
+
xtype: 'textarea',
|
71
|
+
region : 'south',
|
72
|
+
style: "{background-image:url(/images/console_background.png)}",
|
73
|
+
autoscroll: true,
|
74
|
+
id: "console_text_area",
|
75
|
+
enableKeyEvents: true,
|
76
|
+
listeners: {
|
77
|
+
afterrender: function(field) {
|
78
|
+
field.focus();
|
79
|
+
},
|
80
|
+
|
81
|
+
|
82
|
+
// use key-up for textarea since ENTER does not affect focus traversal
|
83
|
+
keyup: function(field, e){
|
84
|
+
//console.log("textarea keyup:"+e);
|
85
|
+
if (e.getKey() == e.ENTER){
|
86
|
+
|
87
|
+
sendCommand('console_text_area',field.getValue());
|
88
|
+
// add to history
|
89
|
+
desktop_console_history[desktop_console_history.length]=field.getValue().substring(0,field.getValue().length-1);
|
90
|
+
//update index
|
91
|
+
desktop_console_history_index=desktop_console_history.length
|
92
|
+
field.setValue("");
|
93
|
+
}else if (e.getKey() == e.UP){
|
94
|
+
|
95
|
+
if(desktop_console_history.length==0){
|
96
|
+
// no history to display
|
97
|
+
}else{
|
98
|
+
desktop_console_history_index--;
|
99
|
+
if(desktop_console_history_index >=0){
|
100
|
+
|
101
|
+
}
|
102
|
+
else{
|
103
|
+
desktop_console_history_index=desktop_console_history.length-1
|
104
|
+
}
|
105
|
+
field.setValue(desktop_console_history[desktop_console_history_index]);
|
106
|
+
}
|
107
|
+
|
108
|
+
}else if (e.getKey() == e.DOWN){
|
109
|
+
|
110
|
+
if(desktop_console_history.length==0){
|
111
|
+
// no history to display
|
112
|
+
}else{
|
113
|
+
desktop_console_history_index++;
|
114
|
+
if(desktop_console_history_index >=(desktop_console_history.length)){
|
115
|
+
desktop_console_history_index=0
|
116
|
+
}
|
117
|
+
else{
|
118
|
+
//desktop_console_history_index=desktop_console_history.length-1
|
119
|
+
}
|
120
|
+
field.setValue(desktop_console_history[desktop_console_history_index]);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
}
|
127
|
+
//---------------------------------
|
128
|
+
var console_panel={
|
129
|
+
xtype: 'panel',
|
130
|
+
layout: 'border',
|
131
|
+
items :[ console_history_panel,console_text_area]
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
//---------------------------------
|
136
|
+
|
137
|
+
Ext.define("Compass.ErpApp.Desktop.Applications.CompassAeConsole",{
|
138
|
+
extend:"Ext.ux.desktop.Module",
|
139
|
+
id:'compass_console-win',
|
140
|
+
init : function(){
|
141
|
+
this.launcher = {
|
142
|
+
text: 'Compass Console',
|
143
|
+
iconCls:'icon-console',
|
144
|
+
handler: this.createWindow,
|
145
|
+
scope: this
|
146
|
+
}
|
147
|
+
},
|
148
|
+
|
149
|
+
createWindow : function(){
|
150
|
+
var desktop = this.app.getDesktop();
|
151
|
+
var win = desktop.getWindow('console');
|
152
|
+
if(!win){
|
153
|
+
win = desktop.createWindow({
|
154
|
+
id: 'console',
|
155
|
+
title:'Compass Console',
|
156
|
+
width:1000,
|
157
|
+
height:670,
|
158
|
+
iconCls: 'console_icon',
|
159
|
+
shim:false,
|
160
|
+
animCollapse:false,
|
161
|
+
resizable : false,
|
162
|
+
constrainHeader:true,
|
163
|
+
layout: 'fit',
|
164
|
+
items:[console_panel]
|
165
|
+
,
|
166
|
+
tools:[
|
167
|
+
{
|
168
|
+
type:'help',
|
169
|
+
tooltip: 'about',
|
170
|
+
handler: function(event, toolEl, panel){
|
171
|
+
Ext.Msg.alert("About","<center><b>Compass Console</b><br><i>Version 0.01</i>")
|
172
|
+
}
|
173
|
+
}]
|
174
|
+
|
175
|
+
});
|
176
|
+
}
|
177
|
+
win.show();
|
178
|
+
sendCommand('console_text_area',"Rails.version ");
|
179
|
+
}
|
180
|
+
});
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require_tree .
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|