chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Quintiq file version 2.0
#parent: DataHolderPeriods
Response OnDataChanged () id:Response_BaseFormCapacityPlanning_DataHolderPeriods_OnDataChanged
{
  #keys: '[136682.2.891024112]'
  CanBindMultiple: false
  DefinitionID: 'Responsedef_WebComponent_OnDataChanged'
  QuillAction
  {
    Body:
    [*
      //Zoom based on selected granularity in navigation panel
      data :=  ApplicationMacroPlanner.DataHolderPeriods().Data().Copy(); // refer to global dataholder as this.Data seems referring to old data 
      totalfutureperiods := counter( data, Elements, period, true, not period.IsHistorical() ); 
      level :=1;
      // when total period more than 10, zoomlevel will be 10% of the total future periods bucket 
      if ( totalfutureperiods > 10 )
      {
        level := floor( 0.1 * totalfutureperiods ) ;  
      }
      // sort by time unit level, 1-Hour, 2-Day, 3-Week, 4-Month, 5-Quarter, 6-Year
      timeunits := selectuniquevalues( data, Elements, period, true, [String]period.TimeUnitLevel() + "-" + period.TimeUnit() ); 
      timeunits := selectsortedset( timeunits, Elements, e, true, e.Tokenize( "-" ).Element( 0 ) );// tokenized to sort by time unit level from Day->Week->Month->Quarter->Year  
      customzoomrange := JSON::Array();
      
      traverse( timeunits, Elements, element )
      {
        timeunit := element.Tokenize( "-" ).Element( 1 );
          
        isquarter := timeunit = Translations::MP_GlobalParameters_Quarter();
        size := counter( data, Elements, period, true, not period.IsHistorical() and period.TimeUnit() = timeunit );
        maxloop := size/ level;
        unit := ifexpr( isquarter, Translations::MP_GlobalParameters_Month(), timeunit ) ; //Quarter is not supported, replace with month
        //minimum keep 2 buckets - if zoom in
        for ( i := 2; i <= maxloop; i++ )
        {
          loop := i;
          
          if ( i > 2 )
          {
             loop := loop * level;
          }
          
          loop := loop * ifexpr( isquarter, 3, 1 ) // time 3 if is in quarter, default * 1;
          // Core Tech granularity is plural thus we add "s" to it
          zoomLevel := unit + "s";
          zoom1 := JSON::Object();
          zoom1.Add( 'unit', zoomLevel );
          zoom1.Add( 'count', loop );
          customzoomrange.Add( zoom1);
        }
      }
      
      GanttChartCapacityPlanning.NavigationRange( customzoomrange.Build() );
      
      //Snap to gantt chart
      Form.SnapToGanttChart();
    *]
    GroupServerCalls: false
  }
}