1- import { Component , EventEmitter , OnInit , OnDestroy } from '@angular/core' ;
1+ import { Component , EventEmitter , OnInit , OnDestroy , ViewChild } from '@angular/core' ;
22import { Observable } from 'rxjs/Observable' ;
33import { Response } from '@angular/http' ;
44import { MarkLogicService } from '../marklogic' ;
@@ -26,6 +26,8 @@ export class HomeComponent implements OnInit, OnDestroy {
2626 requests : any ;
2727 currentUri : string ;
2828 currentLine : number ;
29+ currentRequest : any ;
30+ currentStackPosition : number ;
2931 showLine : number ;
3032 currentExpression : string ;
3133 fileText : string ;
@@ -43,6 +45,8 @@ export class HomeComponent implements OnInit, OnDestroy {
4345
4446 breakpointsSet : boolean = false ;
4547
48+ @ViewChild ( 'consoleInputCtrl' ) consoleInputCtrl ;
49+
4650 codeMirrorConfig = {
4751 lineNumbers : true ,
4852 indentWithTabs : true ,
@@ -82,37 +86,51 @@ export class HomeComponent implements OnInit, OnDestroy {
8286 this . router . navigate ( [ 'login' ] ) ;
8387 }
8488
85- this . marklogic . getServers ( ) . subscribe ( ( servers : any ) => {
86- this . appservers = servers ;
87- if ( this . appserverName ) {
88- let server = _ . find ( this . appservers , ( appserver ) => { return appserver . name === this . appserverName ; } ) ;
89- if ( server ) {
90- this . selectedServer = server ;
91- this . showFiles ( ) ;
92- this . getRequests ( ) ;
93- this . getBreakpoints ( ) ;
89+ if ( ! this . appservers || ! this . selectedServer ) {
90+ this . marklogic . getServers ( ) . subscribe ( ( servers : any ) => {
91+ this . appservers = servers ;
92+ if ( this . appserverName ) {
93+ let server = _ . find ( this . appservers , ( appserver ) => { return appserver . name === this . appserverName ; } ) ;
94+ if ( server ) {
95+ this . selectedServer = server ;
96+ this . showFiles ( ) ;
97+ this . getRequests ( ) ;
98+ this . getBreakpoints ( ) ;
99+ }
94100 }
95- }
96101
97- if ( this . requestId ) {
98- this . getStack ( this . requestId ) ;
99- } else {
100- this . fileBreakpoints = null ;
101- this . currentLine = null ;
102- this . showLine = null ;
103- this . currentUri = null ;
104- }
102+ this . updateStack ( ) ;
103+ } ,
104+ ( ) => {
105+ this . router . navigate ( [ 'login' ] ) ;
106+ } ) ;
107+ }
108+ else {
109+ this . getRequests ( ) ;
110+ this . updateStack ( ) ;
111+ }
112+ } ) ;
105113
106- if ( ! this . welcomeShown && localStorage . getItem ( '_show_welcome_' ) !== 'false' ) {
107- this . showWelcome ( ) ;
108- this . welcomeShown = true ;
109- }
114+ if ( ! this . welcomeShown && localStorage . getItem ( '_show_welcome_' ) !== 'false' ) {
115+ this . showWelcome ( ) ;
116+ this . welcomeShown = true ;
117+ }
110118
111- } ,
112- ( ) => {
113- this . router . navigate ( [ 'login' ] ) ;
119+ }
120+
121+ updateStack ( ) {
122+ if ( this . requestId ) {
123+ this . marklogic . getRequest ( this . selectedServer . id , this . requestId ) . subscribe ( ( request ) => {
124+ this . currentRequest = request ;
125+ this . getStack ( this . requestId ) ;
114126 } ) ;
115- } ) ;
127+ } else {
128+ this . currentRequest = null ;
129+ this . fileBreakpoints = null ;
130+ this . currentLine = null ;
131+ this . showLine = null ;
132+ this . currentUri = null ;
133+ }
116134 }
117135
118136 showWelcome ( ) {
@@ -161,8 +179,7 @@ export class HomeComponent implements OnInit, OnDestroy {
161179 this . marklogic . getStack ( requestId ) . subscribe ( ( stack : any ) => {
162180 this . stack = stack ;
163181 if ( this . stack && this . stack . frames && this . stack . frames . length > 0 ) {
164- const frame = this . stack . frames [ 0 ] ;
165- this . showFile ( frame . uri , frame . line ) ;
182+ this . showFile ( this . stack . frames [ 0 ] , 0 ) ;
166183 }
167184 } , ( ) => {
168185 this . router . navigate ( [ 'server' , this . appserverName ] ) ;
@@ -178,9 +195,21 @@ export class HomeComponent implements OnInit, OnDestroy {
178195 hasVariables ( ) {
179196 return this . stack &&
180197 this . stack . frames &&
181- this . stack . frames [ 0 ] &&
182- this . stack . frames [ 0 ] . variables &&
183- this . stack . frames [ 0 ] . variables . length > 0 ;
198+ this . stack . frames [ this . currentStackPosition ] &&
199+ (
200+ (
201+ this . stack . frames [ this . currentStackPosition ] . variables &&
202+ this . stack . frames [ this . currentStackPosition ] . variables . length > 0
203+ ) ||
204+ (
205+ this . stack . frames [ this . currentStackPosition ] . externalVariables &&
206+ this . stack . frames [ this . currentStackPosition ] . externalVariables . length > 0
207+ ) ||
208+ (
209+ this . stack . frames [ this . currentStackPosition ] . globalVariables &&
210+ this . stack . frames [ this . currentStackPosition ] . globalVariables . length > 0
211+ )
212+ ) ;
184213 }
185214
186215 debugRequest ( requestId ) {
@@ -356,18 +385,48 @@ export class HomeComponent implements OnInit, OnDestroy {
356385 } ) ;
357386 }
358387
359- showFile ( uri : string , line : number ) {
388+ showEval ( frame , index : number ) {
360389 this . currentLine = null ;
361390 this . showLine = null ;
362- this . marklogic . getFile ( this . selectedServer . id , uri ) . subscribe ( ( txt : any ) => {
363- this . currentUri = uri ;
364- this . fileText = txt ;
365- this . currentLine = line ;
391+ if ( this . currentRequest ) {
392+ this . currentUri = '/eval' ;
393+ this . fileText = this . currentRequest . requestText ;
394+ this . currentLine = frame . line ;
395+ this . currentStackPosition = index ;
366396 this . getBreakpoints ( ) ;
367397 if ( this . stack . expressions && this . stack . expressions . length > 0 ) {
368- this . currentExpression = this . stack . expressions [ 0 ] . expressionSource ;
398+ if ( index === 0 ) {
399+ this . currentExpression = this . stack . expressions [ index ] . expressionSource ;
400+ }
401+ else {
402+ this . currentExpression = null ;
403+ }
369404 }
370- } ) ;
405+ }
406+ }
407+
408+ showFile ( frame : any , index : number ) {
409+ if ( frame . uri === '/eval' ) {
410+ this . showEval ( frame , index ) ;
411+ } else {
412+ this . currentLine = null ;
413+ this . showLine = null ;
414+ this . marklogic . getFile ( this . selectedServer . id , frame . uri ) . subscribe ( ( txt : any ) => {
415+ this . currentUri = frame . uri ;
416+ this . fileText = txt ;
417+ this . currentLine = frame . line ;
418+ this . currentStackPosition = index ;
419+ this . getBreakpoints ( ) ;
420+ if ( this . stack . expressions && this . stack . expressions . length > 0 ) {
421+ if ( index === 0 ) {
422+ this . currentExpression = this . stack . expressions [ index ] . expressionSource ;
423+ }
424+ else {
425+ this . currentExpression = null ;
426+ }
427+ }
428+ } ) ;
429+ }
371430 }
372431
373432 consoleKeyPressed ( $event : KeyboardEvent ) {
@@ -426,7 +485,23 @@ export class HomeComponent implements OnInit, OnDestroy {
426485 } ) ;
427486 }
428487
429- clearConsole ( ) {
488+ clearConsole ( $event : MouseEvent ) {
430489 this . consoleOutput = [ ] ;
490+ $event . preventDefault ( ) ;
491+ $event . stopPropagation ( ) ;
492+ }
493+
494+ focusConsole ( $event ) {
495+ this . consoleInputCtrl . nativeElement . focus ( ) ;
496+ }
497+
498+ getRequestName ( request ) {
499+ let name ;
500+ if ( request . requestKind === 'eval' ) {
501+ name = 'eval' ;
502+ } else {
503+ name = ( request . requestRewrittenText || request . requestText ) ;
504+ }
505+ return name ;
431506 }
432507}
0 commit comments