Subversion Repositories DevTools

Rev

Rev 6048 | Rev 6181 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
'|                                                   |
'|         ADMIN Build Status Information            |
'|                                                   |
'=====================================================
%>
<%
Option explicit
' Good idea to set when using redirect
Response.Expires = 0  ' always load the page, dont store
%>
<!--#include file="common/conf.asp"-->
<!--#include file="common/globals.asp"-->
<!--#include file="common/formating.asp"-->
<!--#include file="common/qstr.asp"-->
<!--#include file="common/common_subs.asp"-->
<!--#include file="common/_form_window_common.asp"-->
<%
'------------ ACCESS CONTROL ------------------
%>
<!--#include file="_access_control_login.asp"-->
<!--#include file="_access_control_general.asp"-->
<%
'------------ Variable Definition -------------
Dim rsQry
Dim query_string
Dim styleAlt1
Dim styleAlt2
Dim styleNow
Dim param_refreshPeriod
Dim param_inactivity
Dim param_refreshEnabled
Dim bIndefinitelyPaused
Dim buildStatus

Dim bShowProblemDaemonSets    ' Indicates if problem daemons must be shown during filtering
Dim bShowDisabledDaemons      ' Indicates if a disabled daemon must be shown during filtering
Dim bShowActiveBuilds         ' Indicates if active builds must be shown during filtering
Dim bShowIdleBuilds           ' Indicates if idle builds must be shown during filtering
Dim bShowPausedBuilds         ' Indicates if paused builds must be shown during filtering

'------------ Constants Declaration -----------
Const Min_Refresh_Time = 10         ' Seconds
Const Max_Delta = 600               ' Seconds
Const Max_DeltaBuild = 31           ' Days
'------------ Variable Init -------------------

styleAlt1="class='body_rowg1'"
styleAlt2="class='body_rowg2'"
styleNow = styleAlt1
'----------------------------------------------
%>
<%
'------------------------------------------------------------------------------
'   Populate the buildStatus dictionary
'   Get all the required data into a hash of hashes
'   It will make the following processing so much easier
'
Sub getBuildStatus
    Dim bms
    query_string = "SELECT rc.RCON_ID, " &_
                  "       rc.RTAG_ID, " &_
                  "       bm.DISPLAY_NAME, " &_
                  "       rc.DAEMON_MODE, "&_
                  "       rt.RTAG_NAME, " &_
                  "       rt.OFFICIAL, " &_
                  "       rt.BUILD_AGE, " &_
                  "       p.PROJ_ID, " &_
                  "       p.PROJ_NAME, " &_
                  "       rl.CURRENT_PKG_ID_BEING_BUILT, "&_
                  "       rl.CURRENT_RUN_LEVEL, "&_
                  "       NVL(rl.PAUSE,0) as PAUSE, " &_
                  "       TRUNC (86400*(SYSDATE - rl.KEEP_ALIVE)) as delta," &_
                  "       TO_CHAR(rl.LAST_BUILD, 'DD-MON-YYYY') as last_build," &_
                  "       TRUNC (SYSDATE - rl.LAST_BUILD) as last_build_days," &_
                  "       pkg.PKG_NAME" &_
                  " FROM RELEASE_CONFIG rc, RELEASE_TAGS rt, PROJECTS p, RUN_LEVEL rl, BUILD_MACHINE_CONFIG bm, PACKAGES pkg " &_
                  " WHERE rt.RTAG_ID = rc.RTAG_ID " &_
                  "   AND rc.bmcon_id is not null" &_
                  "   AND rt.PROJ_ID = p.PROJ_ID " &_
                  "   AND rt.OFFICIAL in ( 'N', 'R', 'C')" &_
                  "   AND rl.RCON_ID = rc.RCON_ID" &_
                  "   AND rc.bmcon_id = bm.bmcon_id(+)" &_
                  "   AND pkg.PKG_ID(+) = rl.CURRENT_PKG_ID_BEING_BUILT" &_
                  " ORDER BY p.PROJ_NAME, rt.RTAG_NAME, rc.DAEMON_MODE, bm.DISPLAY_NAME, rc.DAEMON_MODE"

    Set buildStatus = CreateObject("Scripting.Dictionary")
    Set rsQry = OraDatabase.DbCreateDynaset( query_string, ORADYN_DEFAULT )
    Do While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
        Set bms = CreateObject("Scripting.Dictionary")

        bms.Item("RCON_ID")                     = rsQry("RCON_ID")
        bms.Item("RTAG_ID")                     = rsQry("RTAG_ID")
        bms.Item("DISPLAY_NAME")                = rsQry("DISPLAY_NAME")
        bms.Item("RTAG_NAME")                   = rsQry("RTAG_NAME")
        bms.Item("DAEMON_MODE")                 = rsQry("DAEMON_MODE")
        bms.Item("OFFICIAL")                    = rsQry("OFFICIAL")
        bms.Item("BUILD_AGE")                   = NiceInt(rsQry("BUILD_AGE"), 31)
        bms.Item("PROJ_ID")                     = rsQry("PROJ_ID")
        bms.Item("PROJ_NAME")                   = rsQry("PROJ_NAME")
        bms.Item("CURRENT_PKG_ID_BEING_BUILT")  = rsQry("CURRENT_PKG_ID_BEING_BUILT")
        bms.Item("CURRENT_RUN_LEVEL")           = rsQry("CURRENT_RUN_LEVEL")
        bms.Item("PAUSE")                       = CInt(rsQry("PAUSE"))
        bms.Item("delta")                       = rsQry("delta")
        bms.Item("last_build")                  = rsQry("last_build")
        bms.Item("last_build_days")             = NiceInt(rsQry("last_build_days"), 100)
        bms.Item("PKG_NAME")                    = rsQry("PKG_NAME")

        ' Calculate some values
        bms.Item("dState") = Classify_Run_Level(bms.Item("CURRENT_RUN_LEVEL"),_
                                                bIndefinitelyPaused,_
                                                bms.Item("PAUSE"), _
                                                bms.Item("delta") ,_
                                                bms.Item("CURRENT_PKG_ID_BEING_BUILT"))

        bms.Item("dStateText") = Get_Run_Level(bms.Item("CURRENT_RUN_LEVEL"),_
                                               bIndefinitelyPaused,_
                                               bms.Item("PAUSE"))

        ' Kill package name on disabled daemons
        If bms.Item("PAUSE") = 2 Then bms.Item("PKG_NAME") = Null


        ' Add to buildStatus
        '   This is a three level hash (Project,Release, Daemon)

        Dim ProjRef, RelRef, DRef
        ProjRef = bms.Item("PROJ_NAME")
        RelRef  = bms.Item("RTAG_NAME")
        DRef    = bms.Item("DISPLAY_NAME")

        If  Not buildStatus.Exists(ProjRef) Then
            Set buildStatus(ProjRef) = CreateObject("Scripting.Dictionary")
            Set buildStatus(ProjRef).Item("data") = CreateObject("Scripting.Dictionary")
            'buildStatus(ProjRef).Item("PROJ_ID") = bms.Item("PROJ_ID")
            'buildStatus(ProjRef).Item("PROJ_NAME") = bms.Item("PROJ_NAME")

        End If

        If  Not buildStatus(ProjRef).Item("data").Exists(RelRef) Then
            Set buildStatus(ProjRef).Item("data").Item(RelRef) = CreateObject("Scripting.Dictionary")
            Set buildStatus(ProjRef).Item("data").Item(RelRef).Item("data") = CreateObject("Scripting.Dictionary")
            'buildStatus(ProjRef).Item("data").Item(RelRef).Item("RTAG_NAME") = bms.Item("RTAG_NAME")
            'buildStatus(ProjRef).Item("data").Item(RelRef).Item("RTAG_ID") = bms.Item("RTAG_ID")
        End If

        Set buildStatus(ProjRef).Item("data").Item(RelRef).Item("data").Item(DRef) = bms

        rsQry.MoveNext
    Loop
    rsQry.Close()
    Set rsQry = nothing

    ' Iterate over each deamon set and flag some of its characteristics
    '   This could be done inline, as the data is processed from the SQL source
    Dim project,release,machine
    Dim eProject,eRelease,eMachine
    For Each project in buildStatus
        Set eProject = buildStatus.Item(project)
        For Each release in eProject.Item("data")
            Set eRelease = eProject.Item("data").Item(release)
            For Each machine in eRelease.Item("data")
                Set eMachine = eRelease.Item("data").Item(machine)

                Dim dState
                dState = eMachine.Item("dState")

                If dState = "active" Then
                    If bShowActiveBuilds Then eMachine.Item("bRow_displayed") = "ShowActive"
                ElseIf dState = "idle" Then
                    If bShowIdleBuilds Then eMachine.Item("bRow_displayed") = "ShowIdle"
                ElseIf dState = "paused" Then
                    If bShowPausedBuilds Then eMachine.Item("bRow_displayed") = "ShowPaused"
                ElseIf dState = "disabled" Then
                    If bShowDisabledDaemons Then eMachine.Item("bRow_displayed") = "ShowDisabled"
                ElseIf dState = "problem" Then
                    If bShowProblemDaemonSets Then eMachine.Item("bRow_displayed") = "ShowProblem"
                    If bShowProblemDaemonSets Then eRelease.Item("bDisplay_whole_set") = true
                Else
                    eRelease.Item("bDisplay_whole_set") = true
                    eMachine.Item("bRow_displayed") = "ShowUnknownState"
                End If

                If bShowProblemDaemonSets AND eMachine.Item("BUILD_AGE") > 0 Then
                    If (eMachine.Item("last_build_days") > eMachine.Item("BUILD_AGE")) OR (eMachine.Item("last_build_days") > param_inactivity) Then
                       If dState = "active" OR dState = "idle" Then
                          eRelease.Item("bDisplay_whole_set") = true
                          eRelease.Item("bShowAge") = true
                          eMachine.Item("bRow_displayed") = "ShowInactiveWarning"
                       End If
                    End If
                End If

                If eMachine.Exists("bRow_displayed") Then
                    eRelease.Item("bDisplay_some") = true
                End If

            Next
        Next
    Next

    ' Debug the data structure
    '   Requires common/DictDump.vbs to be included to work
    'Response.Write "<br>Pretty Dictionary Display<pre>"
    'Response.Write DICToutput(buildStatus)

End Sub

'--------------------------------------------------------------------------------------------------------------------------
' Toggle row style between the two alternative styles
Sub ToggleStyleNow
   If styleNow = styleAlt1 Then
      styleNow = styleAlt2
   Else
      styleNow = styleAlt1
   End If
End Sub
'--------------------------------------------------------------------------------------------------------------------------
' Convert run level into a meaningful string
Function Get_Run_Level( nLevel, indefinitePause, astate)

   If indefinitePause Then
      Get_Run_Level = "<span class='err_alert'>Stopped</span>"
   ElseIf astate = 1 Then      ' if build daemon paused
      Get_Run_Level = "Paused"
   ElseIf astate = 2 Then      ' if build daemon disabled
      Get_Run_Level = "Disabled"
   ElseIf astate = 0 Then     ' if build daemon enabled
      If nLevel = 1 Then
         Get_Run_Level = "Cannot Continue"
      ElseIf nLevel = 2 Then
         Get_Run_Level = "Paused"
      ElseIf nLevel = 3 Then
         Get_Run_Level = "Building"
      ElseIf nLevel = 4 Then
         Get_Run_Level = "Idle"
      ElseIf nLevel = 5 Then
         Get_Run_Level = "Waiting"
      ElseIf nLevel = 6 Then
         Get_Run_Level = "Publishing"
      Else
         Get_Run_Level = "<span class='err_alert'>Unknown!</span>"
      End If
   End If
End Function

'--------------------------------------------------------------------------------------------------------------------------
' Convert run level into a meaningful filter state as a string
' Will be one of: active, idle, paused, disabled, problem, unknown
Function Classify_Run_Level( nLevel, indefinitePause, astate, nDelta, pkgId)

   If indefinitePause Then
      Classify_Run_Level = "problem"
   ElseIf astate = 1 Then                   ' if build daemon paused
      Classify_Run_Level = "paused"
   ElseIf astate = 2 Then                   ' if build daemon disabled
      Classify_Run_Level = "disabled"
   ElseIf Int(nDelta) > Max_Delta Then
      Classify_Run_Level = "problem"
   ElseIf (IsNull(pkgId)) OR (pkgId = "") Then
      Classify_Run_Level = "idle"
   ElseIf astate = 0 Then                   ' if build daemon enabled
      If nLevel = 1 Then
         Classify_Run_Level = "problem"
      ElseIf nLevel = 2 Then
         Classify_Run_Level = "paused"
      ElseIf nLevel = 3 Then
         Classify_Run_Level = "active"
      ElseIf nLevel = 4 Then
         Classify_Run_Level = "idle"
      ElseIf nLevel = 5 Then
         Classify_Run_Level = "idle"
      ElseIf nLevel = 6 Then
         Classify_Run_Level = "active"
      Else
         Classify_Run_Level = "unknown"
      End If
   End If
End Function

'--------------------------------------------------------------------------------------------------------------------------
' Convert daemon mode into a meaningful string
Function Get_Daemon_Mode( nMode )
   If nMode = "M" Then
      Get_Daemon_Mode = "Master"
   ElseIf nMode = "S" Then
      Get_Daemon_Mode = "Slave"
   Else
      Get_Daemon_Mode = "?"
   End If
End Function
'--------------------------------------------------------------------------------------------------------------------------
' Use this function to determine the state of a specified project checkbox
Function Is_Project_Checked( nProjId )
   Dim hiddenProjects_arr
   Dim hiddenProjects
   Dim str

   hiddenProjects = Request("HideProj")
   Is_Project_Checked = "checked"

   hiddenProjects_arr = Split(hiddenProjects, ",")
   For Each str in hiddenProjects_arr
      If str = nProjId Then
         Is_Project_Checked = ""
         Exit For
      End If
   Next
End Function
'--------------------------------------------------------------------------------------------------------------------------
' Use this function to set/clear the filter on/off radio button checked state
' Format of Filter Param : Filter=[problemBuilds}[,ActiveBuilds]
Function Display_Filtered(id)
   Dim filter

   Display_Filtered = ""

   filter  = Request("Filter")
   If NOT IsNull(filter) AND filter <> "" Then
      If InStr(filter, id) > 0 Then
         Display_Filtered = "checked"
      End If
   Else
      If id = "OFF" Then
         Display_Filtered = "checked"
      End If
   End If
End Function

'--------------------------------------------------------------------------------------------------------------------------
' Use this function to set/clear a filter option check box with the given ID
' If no Filter is present, then assume defaults          
Function Filter_Checked(id)
   Dim filter

   Filter_Checked = ""

   filter  = Request("Filter")
   If IsNull(filter) OR filter = "" Then
     filter="problemBuilds,activeBuilds"        ' Defaults
   End If
  If InStr(filter, id) > 0 Then
     Filter_Checked = "checked"
  End If
End Function
'--------------------------------------------------------------------------------------------------------------------------
' Test to see if a particular filter option is on
Function Filter_Is_On(id)
    If Filter_Checked(id) = "checked" Then
          Filter_Is_On = True
    Else
          Filter_Is_On = False
    End If
End Function
'--------------------------------------------------------------------------------------------------------------------------
Function Indefinitely_Paused()
   Dim rsQry2
   Dim query_string2

   Indefinitely_Paused = False

   query_string2 = " select * from run_level_schedule rls where rls.indefinite_pause = 'P'"

   Set rsQry2 = OraDatabase.DbCreateDynaset( query_string2, ORADYN_DEFAULT )
   If rsQry2.RecordCount > 0 Then
      Indefinitely_Paused = True
   End If
End Function
'--------------------------------------------------------------------------------------------------------------------------
Function PrettyDelta( delta, daemonState,pkgId )
    Dim style,nDelta
    style = ""

    If delta = "" Then delta = 0
    delta = Int(delta)
    nDelta = delta

    If (delta > Max_Delta) AND (IsNull(pkgId) OR pkgId = "") Then
      style = "style=color:Red"
      If (delta > 86400 ) Then
        Dim bdate, dd,mm,yy
        bdate = DateAdd("s", - delta,Now())
        dd = Day(bdate)
        mm = MonthName(Month(bdate),1)
        yy = Year( bdate)
        delta = dd & "-" & mm & "-" & yy
        If ( daemonState >= 2 ) Then
            style = ""
        End If
      ElseIf ( delta > 60*60 ) Then
        'Dim bdate, hh, mins, ss
        bdate = DateAdd("s", - delta,Now())
        delta = TimeValue( bdate)
        'delta = hh & ":" & mins & ":" & ss
      End If
    End If

    If style <> "" Then
        delta = "<span " & style & ">" & delta & "</span>"
    End If
    PrettyDelta = delta 
End Function

'--------------------------------------------------------------------------------------------------------------------------

%>
<%
'------------ RUN BEFORE PAGE RENDER ----------

' Default values for Auto Refresh checkbox and edit input box
param_refreshEnabled = False
param_refreshPeriod  = "0"

' Read the Refresh parameter which is of the form Refresh=<time-period>,ON|OFF
Dim param_refresh
param_refresh = Request("Refresh")
If param_refresh <> "" Then
   Dim pr_arr
   pr_arr = Split(param_refresh,",")
   param_refreshPeriod = pr_arr(0)

   ' Range check and end-stop the refresh period if necessary
   If NiceInt(param_refreshPeriod, 0)  < Min_Refresh_Time Then
      param_refreshPeriod  = CStr(Min_Refresh_Time)
   End If

   ' determine checkbox state
   If UBound(pr_arr) >= 1 Then
      If InStr(UCase(pr_arr(1)), "ON") > 0 Then
         param_refreshEnabled = True
      Else
         param_refreshEnabled = False
      End If
   End If
End If

' Read the Inactivity Period
param_inactivity = NiceInt( Request("Inactivity"), Max_DeltaBuild)
If param_inactivity  = 0 Then param_inactivity = Max_DeltaBuild


' Get indefinite pause status
bIndefinitelyPaused = Indefinitely_Paused()

' Populate display controls
bShowProblemDaemonSets = Filter_Is_On("problemBuilds")
bShowActiveBuilds      = Filter_Is_On("activeBuilds")
bShowDisabledDaemons   = Filter_Is_On("disabledDaemons")
bShowIdleBuilds        = Filter_Is_On("idleBuilds")
bShowPausedBuilds      = Filter_Is_On("pausedBuilds")

'----------------------------------------------
%>
<script language="JavaScript" type="text/javascript">
<!--

//////////////////////////////////////////////////////////////////////////////////////////////////
// This function rebuilds the query string so that it either adds or removes the specified project ID from
// the HideProj= part of it, whilst leaving the rest of the string intact. The browser location is then
// updated and the server made to re-render the page. This function must be used from the project checkboxes
// to show/hide daemon status informaton for specific projects.
//////////////////////////////////////////////////////////////////////////////////////////////////
function toggle_project( proj_id )
{
   var found = false;
   var new_url_query_string = '';
   var new_hp_list = '';

   // get the full query string
   var url_query_string = '<%=Request.ServerVariables("QUERY_STRING")%>';

   // split it into each parameter
   var qs_arr = url_query_string.split('&');
   var i_qs_arr;
   for (i_qs_arr in qs_arr)
   {
      var qs_str = qs_arr[i_qs_arr];

      if (qs_str.length > 0)
      {
         // if we have found the HideProj parameter
         if (qs_str.indexOf('HideProj') >= 0)
         {
            // Split the HideProj parameter at the = symbol in order to process the comma seperated list of project IDs
            var qs_hp_arr;
            qs_hp_arr = qs_str.split('=');
            if (qs_hp_arr.length > 1)
            {
               // Split the comma seperated list of project IDs, and iterate through each item
               var hp_arr = qs_hp_arr[1].split(',');
               var i_hp_arr;
               for (i_hp_arr in hp_arr)
               {
                  var hp_str = hp_arr[i_hp_arr];

                  // If the item matches the specified project ID and the checkbox for that project is unchecked
                  if (hp_str == proj_id)
                  {
                     found = true;
                  }
                  else
                  {
                     // retain this other project ID in the list
                     if (new_hp_list != '')
                        new_hp_list += ',';
                     new_hp_list += hp_str;
                  }
               }
            }
         }
         else
         {
            // feed the existing paramter to the new query string
            if (new_url_query_string == '')
               new_url_query_string += '?';
            else
               new_url_query_string += '&';
            new_url_query_string += qs_str
         }
      }
   }

   // If the specified project ID was not found, then that project is not currently hidden
   // and must now be hidden, so add its number to the list to hide it on the next server side
   // page render operation
   if (!found)
   {
      if (new_hp_list != '')
         new_hp_list += ',';
      new_hp_list += proj_id
   }

   // Prepare the new query string
   if (new_url_query_string == '')
      new_url_query_string += '\?';
   else
      new_url_query_string += '\&';

   new_url_query_string += 'HideProj=';
   new_url_query_string += new_hp_list;

   // reload the page with the new query string
   var url = location.pathname + new_url_query_string;
   window.location.assign(url);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// This function rebuilds the query string to either hide all projects, or unhide all projects
// fromt he display
//////////////////////////////////////////////////////////////////////////////////////////////////
function toggle_all_projects(bAll)
{
   var new_url_query_string = '';
   var list_proj_ids = '';

   // If hiding all, then find all of the project enable/disable checkboxes, get the project ID
   // values from each one and accumulate them into a comma seperated list
   if (!bAll)
   {
      var inputs = document.getElementsByTagName('input');
      var i;
      for (i = 0; i < inputs.length; i++)
      {
         var str = inputs[i].name;
         if (str.indexOf("DIS_PRJ_") >= 0)
         {
            str = str.replace("DIS_PRJ_","");
            if (list_proj_ids != '')
               list_proj_ids += ',' + str;
            else
               list_proj_ids += str;
         }
      }
   }

   // get the full query string
   var url_query_string = '<%=Request.ServerVariables("QUERY_STRING")%>';

   // split it into each parameter
   var qs_arr = url_query_string.split('&');
   var i_qs_arr;
   for (i_qs_arr in qs_arr)
   {
      var qs_str = qs_arr[i_qs_arr];

      if (qs_str.length > 0)
      {
         // if we have found the HideProj parameter
         if (qs_str.indexOf('HideProj') >= 0)
         {
            // do nothing
         }
         else
         {
            // feed the existing paramter to the new query string
            if (new_url_query_string == '')
               new_url_query_string += '?';
            else
               new_url_query_string += '&';
            new_url_query_string += qs_str
         }
      }
   }

   // Prepare the new query string, only adding the HideProj parameter if the function is being
   // used to hide all projects
   if (!bAll)
   {
      if (new_url_query_string == '')
         new_url_query_string += '\?';
      else
         new_url_query_string += '\&';

      new_url_query_string += 'HideProj=' + list_proj_ids;
   }
   // reload the page with the new query string
   var url = location.pathname + new_url_query_string;
   window.location.assign(url);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// This function rebuilds the query string so that it either adds or removes the Refresh parameter
//////////////////////////////////////////////////////////////////////////////////////////////////
function toggle_refresh()
{
   var new_url_query_string = '';

   // get the full query string
   var url_query_string = '<%=Request.ServerVariables("QUERY_STRING")%>';

   // split it into each parameter
   var qs_arr = url_query_string.split('&');
   var i_qs_arr;
   for (i_qs_arr in qs_arr)
   {
      var qs_str = qs_arr[i_qs_arr];

      if (qs_str.length > 0)
      {
         // if we have found the Refresh parameter
         if (qs_str.indexOf('Refresh') >= 0)
         {
            // do nothing
         }
         else
         {
            // feed the existing paramter to the new query string
            if (new_url_query_string == '')
               new_url_query_string += '?';
            else
               new_url_query_string += '&';
            new_url_query_string += qs_str
         }
      }
   }

   // Prepare the new query string

   if (new_url_query_string == '')
      new_url_query_string += '\?';
   else
      new_url_query_string += '\&';

   new_url_query_string += 'Refresh=';
   if (document.getElementById('refreshPeriod').value < <%=Min_Refresh_Time%>)
   {
      document.getElementById('refreshPeriod').value = <%=Min_Refresh_Time%>;
      new_url_query_string += <%=Min_Refresh_Time%>;
   }
   else
      new_url_query_string += document.getElementById('refreshPeriod').value;

   if (document.getElementById('autoRefresh').checked)
      new_url_query_string += ',ON';
   else
      new_url_query_string += ',OFF';

   // reload the page with the new query string
   var url = location.pathname + new_url_query_string;
   window.location.assign(url);
}


//////////////////////////////////////////////////////////////////////////////////////////////////
// This function rebuilds the query string to Update the Inactivity parameter
//////////////////////////////////////////////////////////////////////////////////////////////////
function toggle_inactivity()
{
   var new_url_query_string = '';

   // get the full query string
   var url_query_string = '<%=Request.ServerVariables("QUERY_STRING")%>';

   // split it into each parameter, then remove the Inactivity parameter
   var qs_arr = url_query_string.split('&');
   var qs_join = '?'
   var i_qs_arr;
   for (i_qs_arr in qs_arr)
   {
      var qs_str = qs_arr[i_qs_arr];
      if (qs_str.length > 0)
      {
         if (qs_str.indexOf('Inactivity') < 0)
         {
            // feed the existing paramter to the new query string
            new_url_query_string += qs_join + qs_str
            qs_join = '&'
         }
      }
   }

   var value = document.getElementById('inactivity').value;
   if  (value && (value != <%=Max_DeltaBuild%>))
   {
       // Prepare the new query string
        new_url_query_string += qs_join + 'Inactivity=' + value;
    }

   // reload the page with the new query string
   var url = location.pathname + new_url_query_string;
   window.location.assign(url);
}


//////////////////////////////////////////////////////////////////////////////////////////////////
// Rebuild the query string and reload the page based on the current setting of the filter
// radio buttons
//////////////////////////////////////////////////////////////////////////////////////////////////
function update_Display_Filter()
{
   var new_url_query_string = '';

   // get the full query string
   var url_query_string = '<%=Request.ServerVariables("QUERY_STRING")%>';

   // split it into each parameter
   var qs_arr = url_query_string.split('&');
   var i_qs_arr;
   for (i_qs_arr in qs_arr)
   {
      var qs_str = qs_arr[i_qs_arr];

      if (qs_str.length > 0)
      {
         // if we have found the Display parameter
         if (qs_str.indexOf('Filter') >= 0)
         {
            // do nothing
         }
         else
         {
            // feed the existing paramter to the new query string
            if (new_url_query_string == '')
               new_url_query_string += '?';
            else
               new_url_query_string += '&';
            new_url_query_string += qs_str
         }
      }
   }

   // Prepare the new query string
   var qJoiner;
   if (new_url_query_string == '')
      qJoiner = '\?';
   else
      qJoiner = '\&';

   var joiner = '';
   var filterSet = '';
   var items = new Array ("activeBuilds","disabledDaemons","idleBuilds","pausedBuilds","problemBuilds");
   for (var item in items)
   {
       if (document.getElementById(items[item]).checked)
       {
          filterSet += joiner + items[item];
          joiner = ',';
       }
   }

   if (filterSet.length > 0)
   {
       new_url_query_string += qJoiner + 'Filter=' + filterSet;
   }
   
   // reload the page with the new query string
   var url = location.pathname + new_url_query_string;
   window.location.assign(url);
}

//-->
</script>

<html>
   <head>
      <title>Release Manager</title>
      <link rel="shortcut icon" href="<%=FavIcon%>"/>
      <meta http-equiv="Pragma" content="no-cache">
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <%If param_refreshEnabled AND param_RefreshPeriod <> 0 Then%>
         <META HTTP-EQUIV=REFRESH CONTENT=<%=param_RefreshPeriod%>>
      <%End If%>
      <link rel="stylesheet" href="images/release_manager_style.css" type="text/css">
      <link rel="stylesheet" href="images/navigation.css" type="text/css">
      <script language="JavaScript" src="images/common.js"></script>
      <!--#include file="_jquery_includes.asp"-->
      <!-- DROPDOWN MENUS -->
      <!--#include file="_menu_def.asp"-->
      <script language="JavaScript1.2" src="images/popup_menu.js"></script>
   </head>
   <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" >
      <!-- HEADER -->
      <!--#include file="_header.asp"-->
      <% getBuildStatus() %>
      <!-- BODY ---->
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
         <tr>
            <td width="1" background="images/bg_home_orange.gif" valign="top">
                <!-- Monitoring Options Selection Box ---->
                 <fieldset style="padding:3px">
                    <legend class="body_scol">Display Options</legend>
                     <fieldset class="body_rowg">
                        <legend class="body_scol">Auto Refresh</legend>
                             <div class=nowrap>
                             <input name="autoRefresh" id="autoRefresh" type="checkbox" <%If param_refreshEnabled Then%>checked<%End If%> value="1" onclick='toggle_refresh()'>
                                 <input class="body_txt" style="width:3em" name="refreshPeriod" id="refreshPeriod" type="input" maxlength="3" value="<%=param_refreshPeriod%>" onchange='toggle_refresh()' > Seconds
                             </div>
                     </fieldset>
                     <fieldset class="body_rowg">
                        <legend class="body_scol">Filter</legend>
                            <div>
                                 <input name="activeBuilds" id="activeBuilds" type="checkbox" <%=Filter_Checked("activeBuilds")%> value="activeBuilds" onclick='update_Display_Filter()'>Active
                            </div>
                            <div>
                                 <input name="idleBuilds" id="idleBuilds" type="checkbox" <%=Filter_Checked("idleBuilds")%> value="idleBuilds" onclick='update_Display_Filter()'>Idle
                            </div>
                            <div>
                                 <input name="pausedBuilds" id="pausedBuilds" type="checkbox" <%=Filter_Checked("pausedBuilds")%> value="paused" onclick='update_Display_Filter()'>Paused
                            </div>
                            <div>
                                 <input name="disabledDaemons"  id="disabledDaemons"  type="checkbox" <%=Filter_Checked("disabledDaemons")%>  value="disabledDaemons"  onclick='update_Display_Filter()'>Disabled
                            </div>
                            <div class=nowrap>
                                 <input name="problemBuilds"  id="problemBuilds"  type="checkbox" <%=Filter_Checked("problemBuilds")%>  value="problemBuilds"  onclick='update_Display_Filter()'>Problem&nbsp;Daemon&nbsp;Sets
                            </div>
                     </fieldset>
                     <fieldset class="body_rowg">
                        <legend  class="body_scol">Inactivity</legend>
                                 <input class="body_txt" style="width:3em" name="inactivity" id="inactivity" type="input" maxlength="3" value="<%=param_inactivity%>" onchange='toggle_inactivity()' > Days
                     </fieldset>
                </fieldset>
            </td>
            <td width="100%" rowspan="2" align="center" valign="top" bgcolor="#EEEFEF">

               <table width="10" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                     <td width="1%"></td>
                     <td width="100%">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                           <tr>
                              <td nowrap class="form_ttl">
                                 <p>BUILD DAEMON STATUS INFORMATION</p>
                              </td>
                              <td align="right" valign="bottom"></td>
                           </tr>

                           <%If bIndefinitelyPaused Then%>
                              <tr>
                                 <td>
                                    <span class='err_alert'>
                                       <font size='2'><b>WARNING: Indefinite Pause, Build Daemons are all stopped - please contact an administrator</b></font>
                                    </span>
                                 </td>
                              </tr>
                           <%End If%>
                        </table>
                     </td>
                     <td width="1%"></td>
                  </tr>
                  <tr>
                     <td align="left" valign="top" background="images/lbox_bg_blue.gif"><img src="images/lbox_tl_cnr_b.gif" width="13" height="13"></td>
                     <td background="images/lbox_bg_blue.gif" class="lbox_ttl_w"><img src="images/h_trsp_dot.gif" width="600" height="15"></td>
                     <td align="right" valign="top" background="images/lbox_bg_blue.gif"><img src="images/lbox_tr_cnr_b.gif" width="13" height="13"></td>
                  </tr>
                  <tr>
                     <td bgcolor="#FFFFFF"><img src="images/h_trsp_dot.gif" width="10" height="100"></td>
                     <td bgcolor="#FFFFFF" valign="top">
                        <!-- MESSAGE +++++++++++++++++++++++++++++++++++++++++++++++++++ -->
                        <!--#include file="messages/_msg_inline.asp"-->
                        <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
                        <br>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                           <td width="9%" valign="top"></td>
                           <tr>
                              <td valign="middle" nowrap background="images/bg_table_col.gif" class="body_col">Project
                                 <input name="NOPRJ" id="NOPRJ" type="Button" value="All" onclick="toggle_all_projects(1)">
                                 <input name="NOPRJ" id="NOPRJ" type="Button" value="None" onclick="toggle_all_projects(0)">
                              </td>
                              <!-- Status Table Header -->
                              <td valign="middle" nowrap background="images/bg_table_col.gif" class="body_col">Release</td>
                              <td valign="middle" nowrap background="images/bg_table_col.gif" class="body_col">Release<br>Mode</td>
                              <td valign="middle" nowrap background="images/bg_table_col.gif" class="body_col">Daemon<br>Mode</td>
                              <td valign="middle" nowrap background="images/bg_table_col.gif" class="body_col">Daemon<br>Host</td>
                              <td valign="middle" nowrap background="images/bg_table_col.gif" class="body_col">Daemon<br>State</td>
                              <td valign="middle" nowrap background="images/bg_table_col.gif" class="body_col">Building<br>Package</td>
                              <td valign="middle" nowrap background="images/bg_table_col.gif" class="body_col">Last Change<br>Delta (secs)</td>
                           </tr>

                           <!-- Status Table Body -->
                           <%
                            Dim bProject_changed          ' Signals a row change due to a different project
                            Dim strProject_checked        ' Can be "" or "checked". Determines appearance of project enable checkbox
                            Dim bRelease_changed          ' signals a row change due to a different release
                            Dim bReleaseHeaderDone        ' indicates whether the release name has been rendered yet
                            Dim bProjectHeaderDone        ' Project Header done
                            Dim bShowAge                  ' Display age warning
                            Dim bToggleStyle              ' Data shown so toggle style
                            Dim bShowReleaseSep           ' Show Release Seperator

                            '   Iterate over all projects, releases and machines
                            '
                            Dim project,release,machine
                            Dim eProject,eRelease,eMachine
                            For Each project in buildStatus
                                ' Start of a new Project
                                Set eProject = buildStatus.Item(project)
                                bProjectHeaderDone = false
                                bProject_changed = true
                                bShowReleaseSep = False

                                For Each release in eProject.Item("data")
                                    '   Start of a new Release
                                    Set eRelease = eProject.Item("data").Item(release)
                                    bReleaseHeaderDone = False
                                    bRelease_changed = true
                                    bShowAge = eRelease("bShowAge")
                                    If  bToggleStyle Then Call ToggleStyleNow
                                    bToggleStyle = false

                                    For Each machine in eRelease.Item("data")
                                        '   Start of a new Machine
                                        Set eMachine = eRelease.Item("data").Item(machine)
                                        strProject_checked = Is_Project_Checked(eMachine("PROJ_ID"))

                                        ' Display Project Header - ONCE
                                        If NOT bProjectHeaderDone Then%>
                                            <tr>
                                               <td colspan='8'><img src='images/spacer.gif' width='1' height='5'></td>
                                            </tr>
                                            <tr>
                                               <td colspan='8' background='images/bg_rep_line.gif'><img src='images/spacer.gif' width='1' height='5'></td>
                                            </tr>
                                            <tr>
                                                <td nowrap class="body_rowg">
                                                    <input name='DIS_PRJ_<%=eMachine("PROJ_ID")%>' id='DIS_PRJ_<%=eMachine("PROJ_ID")%>' type='checkbox' value=1 <%=strProject_checked%> onclick=toggle_project(<%=eMachine("PROJ_ID")%>)>
                                                    <a href='rtree.asp?proj_id=<%=eMachine("PROJ_ID")%>'><%=eMachine("PROJ_NAME")%>
                                                </td>
                                            <%
                                        End If

                                        ' Consider displaying the body of this machine entry
                                        If strProject_checked = "checked" Then
                                            If eRelease.Exists("bDisplay_whole_set") OR eMachine.Exists("bRow_displayed") Then
                                                bToggleStyle = true

                                                '   Empty cell, if the project header has been displayed
                                                If bProjectHeaderDone Then
                                                    %><td nowrap class="body_rowg"></td><%
                                                End If

                                                ' Display Release Header - Once, or a filler
                                                If NOT bReleaseHeaderDone Then
                                                    bReleaseHeaderDone = True

                                                    ' Display Release seperator, if this is not the first release in the project
                                                    If bShowReleaseSep Then
                                                        %>
                                                            <tr>
                                                                <td></td>
                                                                <td colspan='7' background='images/bg_rep_line.gif'><img src='images/spacer.gif' width='1' height='1'></td>
                                                            </tr>
                                                            <tr>
                                                                <td></td>
                                                        <%
                                                    End If
                                                    ' Display the Release Header, with a marker to show aged releases
                                                    %>
                                                    <td nowrap <%=styleNow%>>
                                                        <a href='build_status.asp?rtag_id=<%=eMachine("RTAG_ID")%>' title='Last Build:<%=eMachine("last_build")%>'><%=eMachine("RTAG_NAME")%></a>
                                                    <%
                                                    If bShowAge Then
                                                    %>
                                                        <img src='images/s_warning.gif' width='14' height='13' border='0' title='No Build in this release since <%=eMachine("last_build")%>. [<%=eMachine("last_build_days")%> Days]' style='vertical-align: bottom;'>
                                                    <%
                                                    End If
                                                    %></td><%
                                                Else
                                                    %><td nowrap <%=styleNow%>></td><%
                                                End If
                                                bShowReleaseSep = true
                                                %>
                                                <td nowrap <%=styleNow%>><%=Get_Official(eMachine("OFFICIAL"))%></td>
                                                <td nowrap <%=styleNow%>><%=Get_Daemon_Mode(eMachine("DAEMON_MODE"))%></td>
                                                <td nowrap <%=styleNow%>><%=eMachine("DISPLAY_NAME")%></td>
                                                <td nowrap <%=styleNow%>><%=eMachine("dStateText")%></td>
                                                <td nowrap <%=styleNow%>><%=eMachine("PKG_NAME")%></td>
                                                <td nowrap <%=styleNow%>><%=PrettyDelta(eMachine("delta"),eMachine("PAUSE"),eMachine("PKG_NAME") )%></td>
                                                <%
                                            End If
                                            %></tr><%
                                        End If

                                        ' End of Display
                                        bRelease_changed = false
                                        bProject_changed = false
                                        bProjectHeaderDone = true
                                    Next
                                Next
                            Next
                           %>
                        </table>
                     <!-- Status Table Footer -->
                     </td>
                     <td background="images/lbox_bgside_white.gif">&nbsp;</td>
                  </tr>
                  <tr>
                     <input type="hidden" name="action" value="true">
                     <%=objPMod.ComposeHiddenTags()%>
                     <td background="images/lbox_bg_blue.gif" valign="bottom"><img src="images/lbox_bl_cnr_b.gif" width="13" height="13"></td>
                     <td background="images/lbox_bg_blue.gif"></td>
                     <td background="images/lbox_bg_blue.gif" valign="bottom" align="right"><img src="images/lbox_br_cnr_b.gif" width="13" height="13"></td>
                  </tr>
               </table>
            </td>
            <td width="1" valign="top"><img src="images/h_trsp_dot.gif" width="1" height="1"></td>
         </tr>
         <tr>
            <td valign="bottom" align="center" background="images/bg_home_orange.gif"><img src="images/img_gear.gif" width="86" height="99" vspace="20" hspace="30"></td>
            <td background="images/bg_lght_gray.gif" valign="top"><img src="images/h_trsp_dot.gif" width="1" height="350"></td>
         </tr>
      </table>
      <!-- FOOTER -->
      <!--#include file="_footer.asp"-->
   </body>
</html>