2121
2222 // define variables to represent
2323 var controlsContainer ,
24- templatesContainer ,
25- traceSetupTemplate ,
26- customRecordingAdderTemplate
24+ templatesContainer
2725
2826 // once the DOM has loaded, initialize the template/container variables
2927 $ ( document ) . ready ( function ( ) {
3028 controlsContainer = $ ( '#recording-controls' )
3129 templatesContainer = controlsContainer . find ( '[data-role=templates-container]' )
32- traceSetupTemplate = templatesContainer . find ( '[data-role=trace-setup]' )
33- customRecordingAdderTemplate = templatesContainer . find ( '[data-role=custom-recording-adder]' )
34- recordingTemplate = templatesContainer . find ( '[data-role=recording-template]' )
3530 } )
3631
3732 var traceCoverageUpdateRequests = new Bacon . Bus ( )
393388 // the AJAX operation of POSTing a /recording/start request to the
394389 // server in order to obtain a recording id.
395390 // ----------------------------------------------------------------
396- function CustomRecordingAdder ( recorderId , $widgetContainer ) {
391+ function CustomRecordingAdder ( $adderButton , $recordingsList ) {
397392
398- var button = this . $element = customRecordingAdderTemplate . clone ( )
399-
400- button . click ( function ( ) {
393+ $adderButton . click ( function ( ) {
401394 TraceAPI . requestNewRecording ( function ( recordingData , error ) {
402395 if ( error ) alert ( "failed to start a new recording because: " + error )
403396 else addNewRecording ( recordingData , true )
409402
410403 var toShow = testRecording . widget . $ui
411404 . hide ( )
412- . appendTo ( $widgetContainer )
405+ . appendTo ( $recordingsList )
413406
414407 toShow [ animate ? 'slideDown' : 'show' ] ( )
415408
428421 // End CustomRecordingAdder class definition
429422
430423 // -------------------------------------------------------------------
431- // TraceRecordingControlsWidget
424+ // Create wiring for the page's sidebar.
432425 //
433- // Creates wiring that is responsible for starting/ending traces, and
434- // sets up secondary controls that add recordings etc. It also creates
435- // a recordings manager, so that for whichever recording is selected,
436- // it will request the data for that recording and fire it as a 'data
437- // update' event .
426+ // The sidebar includes a legend for the 'all activity' and 'overlaps'
427+ // colors, and the ability to change those colors; a timing window filter,
428+ // which lets users see trace data within a given time window; a list
429+ // of user-added recordings, and a button for adding new ones; and buttons
430+ // for starting and ending a trace .
438431 // -------------------------------------------------------------------
439- function TraceRecordingControlsWidget ( ) {
440- var newTraceArea = traceSetupTemplate . clone ( ) . appendTo ( controlsContainer ) ,
432+
433+ $ ( document ) . ready ( function ( ) {
434+ var controlsContainer = $ ( '#recording-controls' ) ,
435+ newTraceArea = controlsContainer . find ( '.trace-setup-area' ) ,
441436 newTraceButton = newTraceArea . find ( '[data-role=new-trace]' ) . hide ( ) ,
442437 connectionWaitingText = newTraceArea . find ( '[data-role=connection-waiting]' ) . hide ( ) ,
443438 endTraceButton = newTraceArea . find ( '[data-role=end-trace]' ) . hide ( ) ,
444- recordingControls = $ ( '#recording-controls' ) ,
445- self = this
446-
439+ recordingControls = $ ( '#recording-controls' )
447440
448441 Trace . allActivityRecordingId = createAllActivityRecording ( controlsContainer )
449442
450443 // Add a Recording/Widget for the "all activity"/"latest XXX"
451- var timeWindowsController = createRecentRecording ( controlsContainer )
444+ var timeWindowsController = createRecentRecording ( controlsContainer . find ( '.timingFilterArea' ) )
452445
453446 var legendMultiplesKey = setupOverlapsRecording ( controlsContainer )
454447
461454 return legend
462455 }
463456
464- // Create a button that will add new "custom" recordings
465- var customRecordingAdder = new CustomRecordingAdder ( self . recorderId , controlsContainer )
466- customRecordingAdder . $element . appendTo ( controlsContainer )
457+ // Set up a button that will add new "custom" recordings
458+ var customRecordingAdder = new CustomRecordingAdder (
459+ controlsContainer . find ( '.recording-adder-button' ) ,
460+ controlsContainer . find ( '.recordingsList' ) )
467461
462+ // Load any existing user-created recordings from the server, adding them to the UI
468463 TraceAPI . requestRecordings ( function ( recordings , error ) {
469464 if ( error ) { console . error ( 'failed to load recordings' ) }
470465 else {
471466 recordings . forEach ( function ( rec ) { customRecordingAdder . addNewRecording ( rec , false ) } )
472467 }
473468 } )
474-
475- // forward all coverageRecordEvents from the recordingManager to the `coverageRecordEvents` bus
476- // coverageRecordEvents.plug( Trace.coverageRecordEvents )
477469
478- var traceRunningBus = new Bacon . Bus ( ) ,
479- traceRunningProp = traceRunningBus . toProperty ( ) . assign ( controlsContainer , 'attr' , 'trace-running' )
470+ // assign the 'trace-running' attribute to the controlsContainer, depending on the trace state
471+ Trace . running . assign ( controlsContainer , 'attr' , 'trace-running' )
480472
481473 /*
482474 * Load the current trace status and set the UI accordingly.
489481 newTraceButton . show ( )
490482 connectionWaitingText . hide ( )
491483 endTraceButton . hide ( ) . overlay ( 'ready' )
492- traceRunningBus . push ( false )
493484 break
494485 case 'connecting' :
495486 newTraceButton . hide ( )
500491 newTraceButton . hide ( )
501492 connectionWaitingText . hide ( )
502493 endTraceButton . show ( ) . overlay ( 'ready' )
503- traceRunningBus . push ( true )
504494 break
505495 case 'ending' :
506496 newTraceButton . hide ( )
528518 newTraceButton . hide ( )
529519 connectionWaitingText . slideUp ( )
530520 endTraceButton . slideDown ( )
531- traceRunningBus . push ( true )
532521 break
533522 case 'finished' :
534523 newTraceButton . slideDown ( )
535524 connectionWaitingText . hide ( )
536525 endTraceButton . slideUp ( )
537526 endTraceButton . overlay ( 'ready' )
538- traceRunningBus . push ( false )
539527 break
540528 case 'deleted' :
541529 alert ( 'This trace has been deleted. You will be redirected to the home screen' )
558546 TraceAPI . requestEnd ( )
559547 } )
560548
561- }
562- exports . TraceRecordingControlsWidget = TraceRecordingControlsWidget
563- // End TraceRecordingControlsWidget class definition
564-
549+ } )
565550
566551} ( this ) ) ;
0 commit comments