index.panel.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. xBug.stores.Results = new Ext.data.JsonStore({
  2. autoDestroy: true,
  3. autoLoad: false,
  4. url : xBug.config.connector_url,
  5. listeners : {
  6. 'metachange' : function(s, meta) {
  7. var cols = [];
  8. var cMeta = s.reader.jsonData.columnMeta;
  9. var colWidth = Math.floor(xBug.grid.Results.getWidth() / cMeta.length);
  10. for (var i = 0; i < cMeta.length; i++) {
  11. cols.push({
  12. header : cMeta[i].header,
  13. dataIndex : cMeta[i].dataIndex,
  14. menuDisabled : true,
  15. width : colWidth
  16. });
  17. }
  18. xBug.grid.ResultsModel.setConfig(cols);
  19. xBug.grid.Results.reconfigure(s, xBug.grid.Results.getColumnModel());
  20. xBug.stores.Explain.loadData(s.reader.jsonData.explain);
  21. xBug.stores.Stats.loadData({stats_rows: [{total : s.reader.jsonData.total,
  22. query : s.reader.jsonData.timers.query,
  23. collector : s.reader.jsonData.timers.collector,
  24. total_collector : s.reader.jsonData.memory.total_collector
  25. }]});
  26. Ext.getCmp('xbug-sql-query').update(s.reader.jsonData.sql);
  27. },
  28. 'exception' : function(proxy, response, read, store) {
  29. var e = store.reader.jsonData.error;
  30. Ext.MessageBox.show({
  31. title: _('error')
  32. ,msg: _('xbug.error_code') + e.code+' <br /> ' + _('xbug.error_info') + e.info
  33. ,buttons: Ext.MessageBox.OK
  34. ,minWidth: 400
  35. ,maxWidth: 750
  36. ,modal: false
  37. ,width: 600
  38. });
  39. }
  40. }
  41. });
  42. xBug.grid.ResultsModel = new Ext.grid.ColumnModel({
  43. defaults: {
  44. sortable: false,
  45. menuDisabled: true,
  46. resizable : true
  47. },
  48. defaultSortable : false,
  49. });
  50. xBug.grid.Results = new Ext.grid.GridPanel ({
  51. store: xBug.stores.Results,
  52. cm : xBug.grid.ResultsModel,
  53. viewConfig: {
  54. scrollOffset: 0,
  55. emptyText : '0 Results',
  56. forceFit : true
  57. },
  58. autoWidth: true,
  59. height : 100,
  60. frame: false,
  61. title: _('xbug.results'),
  62. id : 'xbug-results-grid',
  63. listeners : {
  64. 'cellclick' : function(grid, rowIndex, columnIndex, e){
  65. // Get the Record
  66. var record = grid.getStore().getAt(rowIndex);
  67. for (var key in record.data) {
  68. var obj = record.data[key];
  69. if (obj !== null) {
  70. obj = obj.replace(/&lt;/gi, '<');
  71. obj = obj.replace(/&gt;/gi, '>');
  72. }
  73. record.data[key] = obj;
  74. }
  75. var resultGrid = new Ext.grid.PropertyGrid({
  76. title: 'Properties Grid',
  77. autoHeight: true,
  78. source: record.data,
  79. region : 'center'
  80. });
  81. var resultWindow = new Ext.Window({
  82. title: 'Row Data',
  83. closable:true,
  84. width:600,
  85. height:400,
  86. plain:true,
  87. layout: 'border',
  88. items: [resultGrid],
  89. autoScroll : true
  90. });
  91. resultWindow.show();
  92. }
  93. }
  94. });
  95. xBug.stores.Explain = new Ext.data.JsonStore({
  96. autoDestroy: true,
  97. autoLoad: false,
  98. url : xBug.config.connector_url,
  99. listeners : {
  100. 'metachange' : function(s, meta) {
  101. var cols = [];
  102. var cMeta = s.reader.jsonData.explainMeta;
  103. var colWidth = Math.floor(xBug.grid.Results.getWidth() / cMeta.length);
  104. for (var i = 0; i < cMeta.length; i++) {
  105. cols.push({
  106. header : cMeta[i].header,
  107. dataIndex : cMeta[i].dataIndex,
  108. menuDisabled : true,
  109. width: colWidth
  110. });
  111. }
  112. xBug.grid.ExplainModel.setConfig(cols);
  113. xBug.grid.Explain.reconfigure(this, xBug.grid.Explain.getColumnModel());
  114. }
  115. }
  116. });
  117. xBug.grid.ExplainModel = new Ext.grid.ColumnModel({
  118. defaults: {
  119. sortable: false,
  120. menuDisabled: true,
  121. resizable : true
  122. },
  123. defaultSortable : false
  124. });
  125. xBug.grid.Explain = new Ext.grid.GridPanel ({
  126. store: xBug.stores.Explain,
  127. cm : xBug.grid.ExplainModel,
  128. viewConfig: {
  129. emptyText : 'No Query processed'
  130. },
  131. autoWidth: true,
  132. autoHeight : true,
  133. frame: false,
  134. title: _('xbug.explain'),
  135. id : 'xbug-explain-grid',
  136. listeners : {
  137. 'reconfigure' : function(g, s, c) {
  138. },
  139. 'cellclick' : function(grid, rowIndex, columnIndex, e){
  140. // Get the Record
  141. var record = grid.getStore().getAt(rowIndex);
  142. // Get field name
  143. var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
  144. var data = record.get(fieldName);
  145. Ext.MessageBox.show({
  146. title: "Field " + fieldName + " information",
  147. msg: data,
  148. width:600,
  149. buttons: Ext.MessageBox.OK,
  150. animEl: 'mb3'
  151. });
  152. }
  153. }
  154. });
  155. xBug.stores.Stats = new Ext.data.JsonStore({
  156. autoDestroy: true,
  157. autoLoad: false,
  158. url : xBug.config.connector_url,
  159. root : 'stats_rows',
  160. fields : ['total', 'query', 'collector', 'total_collector']
  161. });
  162. xBug.grid.Stats = new Ext.grid.GridPanel ({
  163. store: xBug.stores.Stats,
  164. columns :[{header : _('xbug.row_count'), dataIndex : 'total', sortable : false, width : 120, align: 'right'},
  165. {header : _('xbug.query_time'), dataIndex : 'query', sortable : false, width : 150, align: 'right'},
  166. {header : _('xbug.collection_time'), dataIndex : 'collector', sortable : false, width : 200, align: 'right'},
  167. {header : _('xbug.collection_memory'), dataIndex : 'total_collector', sortable : false, width : 200, align: 'right'}],
  168. viewConfig: {
  169. emptyText : 'No Query processed'
  170. },
  171. autoWidth: true,
  172. autoHeight : true,
  173. frame: false,
  174. title: _('xbug.stats'),
  175. id : 'xbug-stats-grid',
  176. });
  177. xBug.panel.Index = function(config) {
  178. config = config || {};
  179. Ext.apply(config, {
  180. baseCls: 'xbug-formpanel',
  181. cls: 'container',
  182. title : '<h2>' + _('xbug.xbugquery') + '</h2>',
  183. layout : 'fit',
  184. frame : false,
  185. border: false,
  186. renderTo : 'xbug-panel-index-div',
  187. items :[{
  188. layout : 'border',
  189. width: 1200,
  190. height: 800,
  191. border : false,
  192. items : [{
  193. region: 'north',
  194. id : 'xbug-north',
  195. cls: 'modx-page-header',
  196. height: 50,
  197. html : '<p>' + _('xbug.description') + '</p>',
  198. border: false,
  199. }, {
  200. header : false,
  201. region : 'center',
  202. xtype : 'panel',
  203. id : 'xbug-center',
  204. border: false,
  205. padding: '5 5 5 5',
  206. flex : 1,
  207. width : .5,
  208. layout : {
  209. type: 'vbox',
  210. align : 'stretch'
  211. },
  212. defaultMargins : {
  213. top : 5,
  214. right : 5,
  215. bottom : 5,
  216. left: 5
  217. },
  218. items : [{
  219. xtype : 'textarea',
  220. id : 'xbug-editor-text',
  221. name : 'query',
  222. flex : 1,
  223. hideLabel: true,
  224. margin: {
  225. top: 5,
  226. right: 5,
  227. bottom : 5,
  228. left: 5
  229. },
  230. value : "<\?php\n\n$crit = $modx->newQuery('modResource');\n" +
  231. "$crit->where(array('pagetitle:!=' => 10));\n" +
  232. "return $crit;\n"
  233. }],
  234. tbar : [{
  235. xtype : 'modx-panel',
  236. items : [{
  237. 'xtype' : 'query-method-combo',
  238. fieldLabel: _('xbug.collector_method'),
  239. name: 'method',
  240. hiddenName: 'unit',
  241. anchor: '100%',
  242. }]
  243. }],
  244. bbar : [{
  245. id : 'xbug-statusbar',
  246. xtype : 'toolbar',
  247. items : [{
  248. name : 'process',
  249. text : _('xbug.process'),
  250. handler : this.processEditor
  251. }]
  252. }]
  253. }, {
  254. region : 'south',
  255. height : 300,
  256. split : true,
  257. id : 'xbug-south',
  258. border: false,
  259. items : [{
  260. xtype : 'modx-tabs',
  261. items: [
  262. xBug.grid.Results.show(),
  263. xBug.grid.Explain.show(),
  264. xBug.grid.Stats.show()
  265. ]
  266. }]
  267. }, {
  268. region : 'east',
  269. split : true,
  270. id : 'xbug-east',
  271. border : false,
  272. autoScroll : true,
  273. useSplitTips: true,
  274. minWidth : 200,
  275. maxWidth: 700,
  276. header : false,
  277. defaultMargins: {
  278. top: 5,
  279. right: 5,
  280. bottom : 5,
  281. left: 5
  282. },
  283. items : [{
  284. xtype : 'panel',
  285. border : true,
  286. emptyText : 'No query has been processed',
  287. id : 'xbug-sql-query',
  288. layout : 'fit'
  289. }]
  290. }]
  291. }], listeners : {
  292. }
  293. });
  294. xBug.panel.Index.superclass.constructor.call(this, config);
  295. }
  296. Ext.extend(xBug.panel.Index, MODx.Panel, {
  297. processEditor : function(b, e) {
  298. var q = (Ext.ux.Ace) ? Ext.getCmp('xbug-editor-ace').getValue() : Ext.getCmp('xbug-editor-text').getValue();
  299. xBug.stores.Results.load({
  300. params : {
  301. action : 'mgr/xbug/process',
  302. 'query' : q,
  303. 'collector' : Ext.getCmp('xbug-collector-method').getValue(),
  304. 'toJSON' : true
  305. }, callback : function(r, op, success) {
  306. },
  307. scope : this
  308. })
  309. }
  310. });
  311. Ext.reg('xbug-panel-index', xBug.panel.Index);
  312. xBug.combo.MethodCombo = function(config) {
  313. config = config || {};
  314. Ext.applyIf(config,{
  315. store: new Ext.data.ArrayStore({
  316. id: 0
  317. ,fields: ['collector','display']
  318. ,data: [
  319. ['getObject','getObject']
  320. ,['getCollection','getCollection']
  321. ,['getObjectGraph','getObjectGraph']
  322. ,['getCollectionGraph','getCollectionGraph']
  323. ,['SQLQuery','Pure SQL Query']
  324. ]
  325. })
  326. ,mode: 'local'
  327. ,displayField: 'display'
  328. ,valueField: 'collector',
  329. listeners : {
  330. render : function (field) {
  331. field.setValue('getCollection');
  332. }
  333. },
  334. width: '200',
  335. id : 'xbug-collector-method'
  336. });
  337. xBug.combo.MethodCombo.superclass.constructor.call(this, config);
  338. }
  339. Ext.extend(xBug.combo.MethodCombo,MODx.combo.ComboBox);
  340. Ext.reg('query-method-combo', xBug.combo.MethodCombo);
  341. Ext.QuickTips.init();
  342. Ext.apply(Ext.QuickTips.getQuickTip(), {
  343. maxWidth: 200,
  344. minWidth: 100,
  345. showDelay: 50, // Show 50ms after entering target
  346. trackMouse: true
  347. });