import { Component } from '@angular/core' ; import { Inject } from '@angular/core' ; import { ZipkinService , Trace } from './../zipkin/zipkin' ; import * as moment from 'moment' ; export class TraceGroup { constructor ( public key , public traces , public name , public color , public spans ) { } } @ Component ( { selector : 'tracegrouplist' , template : require ( './tracegrouplist.component.html' ) } ) export class TraceGroupListComponent { constructor ( @ Inject ( ZipkinService ) private zipkin ) { } getGroupedTraces ( ) { let traces = this . zipkin . traces || [ ] ; let groups = { } ; traces . forEach ( trace => { let key = trace . name + trace . color ; let arr = groups [ key ] || [ ] ; arr . push ( trace ) ; groups [ key ] = arr ; } ) ; let res = [ ] ; for ( let key in groups ) { let traces = groups [ key ] ; res . push ( new TraceGroup ( key , traces , traces [ 0 ] . name , traces [ 0 ] . color , traces [ 0 ] . spans . length ) ) ; } return res ; } formatTime ( date ) { return moment ( date ) . format ( 'HH:mm' ) ; } formatDate ( date ) { return moment ( date ) . format ( 'YYYY-MM-DD' ) ; } }