Quintiq file version 2.0
#parent: #root
Method ApplyConfigurationQuery (
  KpiQuery kpiQuery
) id:Method_FormKpiQueryTrack_ApplyConfigurationQuery
{
  #keys: '[146874.0.1482344455]'
  Body:
  [*
    // Applies the configuration query from a KpiQuery to radio button groups, List, checkbox and selector.
    // Query parameters
    DataHolderTimespan.Data(  kpiQuery.Timespan() );
    DataHolderDateTimeFrom.Data( kpiQuery.DateTimeFrom() );
    DataHolderDateTimeTo.Data( kpiQuery.DateTimeTo() );
    DataHolderSnapshotsLimit.Data( kpiQuery.SnapshotLimit() );
    
    // Label filtering
    DataHolderEnableLabelFiltering.Data( kpiQuery.IsLabelFilteringEnabled() );
    // Reset the selection
    DataHolderLabelFilters.Data().Flush();
    
    traverse( kpiQuery.LabelFilters().Tokenize( "," ), Elements, labelvalue )
    {
      value := select( KpiTracker, Label.Value, lv, lv.Value() = labelvalue );
      if( not isnull( value ) )
      {
        DataHolderLabelFilters.Data().Add( value );
      }
    }
    
    // Kpi selection
    DataHolderMetaDatas.Data().Flush();
    traverse( kpiQuery.MetaDatas().Tokenize( "," ), Elements, metadata )
    {
      value := select( KpiTracker, MetaData, md, md.DisplayName() = metadata );
      if( not isnull( value ) )
      {
        DataHolderMetaDatas.Data().Add( value );
      }
    }
    
    // Series selection
    kpiLabel := select( KpiTracker, Label, label, label.Name() = kpiQuery.SeriesSelection() );
    DataHolderSeriesSelection.Data( guard( kpiLabel, null( KpiLabel ) ) );
    DataHolderEnableLastSnapshots.Data( kpiQuery.IsOnlyLastSnapshotEnabled() );
    DataHolderTimetype.Data( kpiQuery.Timetype() );
  *]
}
