Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==========================================================================
  2. // Project:   McsDebugger.DebugNodeView
  3. // Copyright: ©2010 My Company, Inc.
  4. // ==========================================================================
  5. /*globals McsDebugger */
  6.  
  7. /** @class
  8.  
  9.   (Document Your View Here)
  10.  
  11.   @extends SC.View
  12. */
  13. McsDebugger.DebugNodeView = SC.View.extend(
  14. /** @scope McsDebugger.DebugNodeView.prototype */ {
  15.  
  16.     classNames: ['debug-node-view'],
  17.    
  18.     displayProperties: 'debugNode displayDialogElement'.w(),
  19.    
  20.     displayDialogElement: SC.Object.create({
  21.         'Incoming Request'                      : YES,
  22.         'Incoming Request/Header'               : YES,
  23.         'Incoming Request/Attributes'           : YES,
  24.         'Incoming Request/Other Information'    : YES,
  25.        
  26.         'Outgoing Request'                      : YES,
  27.         'Outgoing Request/Header'               : YES,
  28.         'Outgoing Request/Attributes'           : YES,
  29.         'Outgoing Request/Other Information'    : YES,
  30.        
  31.         'Incoming Response'                     : YES,
  32.         'Incoming Response/Header'              : YES,
  33.         'Incoming Response/Other Information'   : YES,
  34.        
  35.         'Outgoing Response'                     : YES,
  36.         'Outgoing Response/Header'              : YES,
  37.         'Outgoing Request/Other Information'    : YES
  38.     }),
  39.    
  40.     /*
  41.      * erichocean: you should use an array and then .join('') at the end of render()
  42.      * erichocean: use SC.Benchmark to time your render() methods
  43.      */
  44.     _renderPayload: function(payload, context) {   
  45.         var columnCount = 3;   
  46.         var table = context.begin('table');
  47.        
  48.         table.begin('thead').begin('tr').begin('th').attr('colspan', columnCount).addClass('name').push(payload.content.name).end().end().end();
  49.  
  50.         var tbody = table.begin('tbody');      
  51.  
  52.         this._renderHTTPDialogElement(payload.content.incomingRequest.request, 'Incoming Request', YES, tbody, columnCount);
  53.         this._renderHTTPDialogElement(payload.content.outgoingRequest.request, 'Outgoing Request', YES, tbody, columnCount);
  54.         this._renderHTTPDialogElement(payload.content.incomingResponse.response, 'Incoming Response', NO, tbody, columnCount);
  55.         this._renderHTTPDialogElement(payload.content.outgoingResponse.response, 'Outgoing Response', NO, tbody, columnCount);
  56.  
  57.         tbody.end();       
  58.         table.end();
  59.     },
  60.    
  61.     _renderHTTPDialogElement: function(element, caption, isRequest, tbody, columnCount) {              
  62.         tbody.begin('tr').begin('th').attr('colspan', columnCount).addClass('caption').push(caption).end().end();
  63.        
  64.         if (!this.get('displayDialogElement').get(caption)) return;
  65.  
  66.         var zebra = {
  67.             cur: undefined,
  68.                
  69.             next: function() {
  70.                 this.cur = ((this.cur === 'even') ? 'odd' : 'even');
  71.                 return this.cur;
  72.             },
  73.            
  74.             reset: function() {
  75.                 this.cur = undefined;
  76.             }
  77.         };
  78.                
  79.        
  80.            
  81.         tbody.begin('tr').begin('th').attr('colspan', columnCount).addClass('caption').addClass('subcaption').push(caption+'/Header').end().end();
  82.  
  83.         if (this.get('displayDialogElement').get(caption+'/Header')) {
  84.        
  85.             element.headers.forEach(function(header) {         
  86.                 if (header.isSCArray) {
  87.                     var cookies = header.objectAt(0);
  88.                    
  89.                     var tr = tbody.begin('tr').addClass(zebra.next());
  90.                     tr.begin('th').attr('colspan', 1).attr('rowspan', cookies.get('length')).push('cookies').end();            
  91.                                    
  92.                     cookies.forEach(function(cookie) {
  93.                         if (tr == null) {
  94.                             tr = tbody.begin('tr').addClass(zebra.next());
  95.                         }
  96.                        
  97.                         tr.begin('td').attr('colspan', 1).push(cookie.name).end();
  98.                         tr.begin('td').attr('colspan', (columnCount - 2)).push(cookie.value).end();
  99.                         tr.end();
  100.                        
  101.                         tr = null;
  102.                     });            
  103.                 } else {
  104.                     var index = header.indexOf(':');           
  105.                    
  106.                     tbody.begin('tr').addClass(zebra.next())
  107.                         .begin('th').attr('colspan', 1).push(header.substring(0, index)).end()
  108.                         .begin('td').attr('colspan', (columnCount - 1)).push(header.substring(index + 1)).end()
  109.                     .end();
  110.                 }          
  111.             });
  112.        
  113.         }
  114.  
  115.        
  116.        
  117.         if (isRequest) {       
  118.             tbody.begin('tr').begin('th').attr('colspan', columnCount).addClass('caption').addClass('subcaption').push(caption+'/Attributes').end().end();
  119.    
  120.             if (this.get('displayDialogElement').get(caption+'/Attributes')) {
  121.            
  122.                 element.attributes.forEach(function(attribute) {           
  123.                     tbody.begin('tr').addClass(zebra.next())
  124.                         .begin('th').attr('colspan', 1).push(attribute.@name).end()
  125.                         .begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*attribute.#text*/).end()
  126.                     .end();
  127.                 });
  128.  
  129.             }
  130.         }
  131.            
  132.    
  133.         tbody.begin('tr').begin('th').attr('colspan', columnCount).addClass('caption').addClass('subcaption').push(caption+'/Other Information').end().end();
  134.  
  135.         if (this.get('displayDialogElement').get(caption+'/Other Information')) {
  136.    
  137.             if (isRequest) {
  138.                 var tr = tbody.begin('tr').addClass(zebra.next());     
  139.                 tr.begin('th').attr('colspan', 1).push('Runtime (msec)').end();
  140.                 tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.runtime.#text*/).end();    
  141.                 tr.end();
  142.        
  143.                 tr = tbody.begin('tr').addClass(zebra.next());     
  144.                 tr.begin('th').attr('colspan', 1).push('Request URI').end();
  145.                 tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.request-uri*/).end();      
  146.                 tr.end();
  147.        
  148.                 tr = tbody.begin('tr').addClass(zebra.next());     
  149.                 tr.begin('th').attr('colspan', 1).push('Path Info').end();
  150.                 tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.path-info*/).end();    
  151.                 tr.end();
  152.                
  153.                 tr = tbody.begin('tr').addClass(zebra.next());     
  154.                 tr.begin('th').attr('colspan', 1).push('Servlet Path').end();
  155.                 tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.servlet-path*/).end();     
  156.                 tr.end();
  157.        
  158.                 tr = tbody.begin('tr').addClass(zebra.next());     
  159.                 tr.begin('th').attr('colspan', 1).push('Query String').end();
  160.                 tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.query-string*/).end();     
  161.                 tr.end();
  162.                
  163.                 tr = tbody.begin('tr').addClass(zebra.next());
  164.                 tr.begin('th').attr('colspan', 1).push('Method').end();
  165.                 tr.begin('td').attr('colspan', (columnCount - 1)).push(element.method).end();      
  166.                 tr.end();
  167.             } else {
  168.                 //console.log(element);
  169.             }
  170.            
  171.         }
  172.        
  173.         tbody.end();
  174.     },
  175.    
  176.     render: function(context, firstTime) {
  177.         var debugNode = this.get('debugNode');
  178.        
  179.         if (debugNode != null) {
  180.             try {
  181.                 this._renderPayload(debugNode.get('payloadObject'), context);
  182.             } catch (ex) {
  183.                 alert('Error rendering DebugNode: ' + ex);
  184.             }
  185.         }
  186.        
  187.         sc_super();
  188.     },
  189.    
  190.     mouseDown: function(evt) {
  191.         var caption = evt.target.textContent;
  192.  
  193.         if (!SC.none(this.get('displayDialogElement').get(caption))) {
  194.             this.get('displayDialogElement').set(caption, !this.get('displayDialogElement').get(caption));     
  195.             this.notifyPropertyChange('displayDialogElement');
  196.         }
  197.        
  198.         return YES;
  199.     }
  200.  
  201. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement