Subversion Repositories DevTools

Rev

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

<%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
'|                                                   |
'|                   wAddDaemon                      |
'|                                                   |
'=====================================================
%>
<%
Option explicit
Response.Expires = 0
%>
<!--#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_general.asp"-->
<!--#include file="_access_control_login.asp"-->
<%
'------------ VARIABLE DEFINITION -------------
Dim rsQry, healthTag, cmdInterface, pkgOwner, isInterface, package, procDesc
Dim sMessage
Dim Query_String
Dim RecordCount
Dim bmcon_id
Dim daemon_mode
Dim gbe_buildfilter
Dim bShowEmpty
Dim bAdd
'------------ CONSTANTS DECLARATION -----------
'------------ VARIABLE INIT -------------------
sMessage = NULL

parRtag_id = Request("rtag_id")
bmcon_id = RequestDefault("bmcon_id",Request("base_bmcon_id"))
bAdd = (Request("rcon_id") = "")

Set objFormCollector = CreateObject("Scripting.Dictionary")
'------------ CONDITIONS ----------------------
'----------------------------------------------
%>
<%
'--------------------------------------------------------------------------------------------------------------------------
' Function:     GetData
' Description:  Determine the basic data for the edit session
Sub GetData

     '  Determine if any daemons have been configured in this release
     '  Will be used to determine if a new entry should be a MASTER or a SLAVE
     '
     Query_String = "select * " &_
                                " from release_config rc," &_
                                "      gbe_machtype gbe " &_
                                " where rc.rtag_id = "& parRtag_id &_
                                "   and gbe.gbe_id = rc.gbe_id"

     Set rsQry = OraDatabase.DbCreateDynaset( Query_String, cint(0))

     RecordCount = rsQry.RecordCount
     If RecordCount = 0 Then
        daemon_mode = "M"
     else   
        daemon_mode = "S"
     End If
     rsQry.Close()
     Set rsQry = Nothing


    ' Edit an existing entry
    '   May have a link into the build_machine_config - or it may not
    '   Check first
    bShowEmpty = TRUE

        If NOT bAdd Then
        Query_String = "SELECT * " &_
                       " FROM RELEASE_CONFIG rc," &_
                       "      gbe_machtype gb" &_
                       " WHERE rc.rcon_id = "& Request("rcon_id") &_
                       "   AND rc.gbe_id = gb.gbe_id"

        Set rsQry = OraDatabase.DbCreateDynaset( Query_String, cint(0))

        If rsQry.RecordCount > 0 Then
            bmcon_id        =  rsQry("bmcon_id")
            daemon_mode     =  rsQry("daemon_mode")
            gbe_buildfilter =  NiceCStr(rsQry("gbe_buildfilter"),"")
        End If

        rsQry.Close()
        Set rsQry = Nothing
    End If

    If NOT isNULL(bmcon_id) AND bmcon_id <> "" Then

        '   Extract information from the machine config
        Query_String = "SELECT * " &_
                                   " FROM build_machine_config bc, " &_
                                   "      gbe_machtype gb " &_
                                   "WHERE bc.bmcon_id = " & bmcon_id &_
                                   "  AND bc.gbe_id = gb.gbe_id"

        Set rsQry = OraDatabase.DbCreateDynaset( Query_String, cint(0))

        If rsQry.RecordCount > 0 Then
                bmcon_id        =  rsQry("bmcon_id")
                bShowEmpty      = FALSE
        End If

        rsQry.Close()
        Set rsQry = Nothing
    End If

        ' Cleanup gbe_buildfilter
    Dim regEx
    Set regEx = New RegExp
    regEx.Global = true
    regEx.IgnoreCase = True

    regEx.Pattern = "\s{2,}"

    gbe_buildfilter = Replace(gbe_buildfilter,","," ")
    gbe_buildfilter = Trim(regEx.Replace(gbe_buildfilter, " "))
End Sub

Sub InsertXrefData
        '
        '   Create a data structure (javascript) to map build machine (bmcon_id) to available platforms
        '
    Query_String = "SELECT bp.bp_name, bp.bp_id, bc2.bmcon_id" &_
            " FROM release_manager.build_platforms bp, release_manager.build_platforms_config2 bc2 " &_
            " WHERE bp.bp_id = bc2.bp_id " &_
            " ORDER BY upper(bp.bp_name)"

    Set rsQry = OraDatabase.DbCreateDynaset( Query_String, ORADYN_DEFAULT )
    While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
        Response.Write "AddXrefEntry('" & rsQry("bp_name") &"',"& rsQry("bmcon_id") & ");" & vbCrLf
       rsQry.MoveNext
    Wend
    rsQry.Close()
    Set rsQry = Nothing
End Sub


'-------------------------------------------------
' Function:     GetMachHost    
' Description:  Determine the current Display Host Information for a given BMCON_ID
'               Do not show build machines that are no longer 'allowed' unless
'               it is currently selected.
' Arguments:    abmcon_id   - A BMCON_ID
'
' Returns:      An array with 5 elements in it - to be used in creating a multicolum drop down list
'                   
Function GetMachHost (abmcon_id)
   Dim rsQry, query

   OraDatabase.Parameters.Add "bmcon_id", abmcon_id,            ORAPARM_INPUT, ORATYPE_NUMBER
   OraDatabase.Parameters.Add "rtag_id",  Request("rtag_id"),   ORAPARM_INPUT, ORATYPE_NUMBER

   query = ReadFile( rootPath & "queries\available_build_machines.sql" )

   Set rsQry = OraDatabase.DbCreateDynaset( query, ORADYN_DEFAULT )
   If (NOT rsQry.BOF) AND (NOT rsQry.EOF) Then
      GetMachHost = rsQry.GetRows()
   Else
      GetMachHost = NULL
   End If

   rsQry.Close()
   Set rsQry = Nothing

   OraDatabase.Parameters.Remove "bmcon_id"
   OraDatabase.Parameters.Remove "rtag_id"
End Function
'--------------------------------------------------------------------------------------------------------------------------
'------------ RUN BEFORE PAGE RENDER ----------

If CBool(Request("action")) Then

    If  bmcon_id = "" Then
        sMessage = "Select a Build Machine before updating the entry"
    Else

       '    Add or Update after the users edit session
       If Request("rcon_id") <> "" Then

          OraDatabase.Parameters.Add "RCON_ID",         Request("rcon_id"),         ORAPARM_INPUT, ORATYPE_NUMBER
          OraDatabase.Parameters.Add "BMCON_ID",        bmcon_id,                   ORAPARM_INPUT, ORATYPE_NUMBER
          OraDatabase.Parameters.Add "DAEMON_MODE",     Request("daemon_mode"),     ORAPARM_INPUT, ORATYPE_VARCHAR2
          OraDatabase.Parameters.Add "GBE_BUILDFILTER", Request("gbe_buildfilter"), ORAPARM_INPUT, ORATYPE_VARCHAR2

          objEH.ErrorRedirect = FALSE
          objEH.TryORA ( OraSession )
          On Error Resume Next

          OraDatabase.ExecuteSQL "BEGIN  PK_BUILDAPI.UPDATE_DAEMON_CONFIG(:RCON_ID, :BMCON_ID, :DAEMON_MODE, :GBE_BUILDFILTER);  END;"
          OraSession.CommitTrans

          objEH.CatchORA ( OraSession )

          OraDatabase.Parameters.Remove "RCON_ID"
          OraDatabase.Parameters.Remove "BMCON_ID"
          OraDatabase.Parameters.Remove "DAEMON_MODE"
          OraDatabase.Parameters.Remove "GBE_BUILDFILTER"

          If objEH.Finally Then
             Call OpenInParentWindow ("release_config.asp?rtag_id="&parRtag_id)
             Call CloseWindow()
          End If

          rsQry.Close
          Set rsQry = nothing

       Else
          OraDatabase.Parameters.Add "RTAG_ID",         Request("rtag_id"),         ORAPARM_INPUT, ORATYPE_NUMBER
          OraDatabase.Parameters.Add "BMCON_ID",        bmcon_id,                   ORAPARM_INPUT, ORATYPE_NUMBER
          OraDatabase.Parameters.Add "DAEMON_MODE",     Request("daemon_mode"),     ORAPARM_INPUT, ORATYPE_VARCHAR2
          OraDatabase.Parameters.Add "GBE_BUILDFILTER", Request("gbe_buildfilter"), ORAPARM_INPUT, ORATYPE_VARCHAR2

          objEH.ErrorRedirect = FALSE
          objEH.TryORA ( OraSession )
          On Error Resume Next

          OraDatabase.ExecuteSQL "BEGIN  PK_BUILDAPI.ADD_DAEMON_CONFIG(:RTAG_ID, :BMCON_ID, :DAEMON_MODE, :GBE_BUILDFILTER);  END;"

          objEH.CatchORA ( OraSession )

          OraDatabase.Parameters.Remove "RTAG_ID"
          OraDatabase.Parameters.Remove "BMCON_ID"
          OraDatabase.Parameters.Remove "DAEMON_MODE"
          OraDatabase.Parameters.Remove "GBE_BUILDFILTER"

          If objEH.Finally Then
             Call OpenInParentWindow ("release_config.asp?rtag_id="&parRtag_id)
             Call CloseWindow()
          End If

          rsQry.Close
          Set rsQry = nothing

       End If
    End If
End If
call GetData
'----------------------------------------------
Sub InsertJavaScript %>
<script type="text/javascript" charset="utf-8">
    var platformXref = {};
    $(document).ready(function(){

        // Function to init Platform CrossRef Data
        // Create a two dimensional associative array
        //      First level - Platform Name
        //      Second Level - BMCONID
        //
        function AddXrefEntry(platform, bmconid){
            platform = platform.toUpperCase();
            if ( ! platformXref[platform] ) {
                platformXref[platform] = {};
            }
            platformXref[platform][bmconid] = 1;
        };
        //  Function calls generated by the ASP code to create a data structure
        <%Call InsertXrefData%>

        //  Add in two special platforms. NONE and TOOLSET
        AddXrefEntry('TOOLSET', 'ALL');
        AddXrefEntry('NONE', 'ALL');

        // Initial config of visible PLATFORMS
        setbmConId();

        // Wire up the MachType selector to modify the available PLATFORMS
        $('#selBmConId').change( setbmConId );

        // Wire up the GBE_BUILDFILTER so that user changes are represented
        $('#gbe_buildfilter').change( setbmConId );

        // Update the available platforms when the user changes the GBE_MACHTYPE
        // Sanitise the value of GBE_BUILDFILTER
        // Operation relies on the fact that
        //      Hidden items will not be submitted as a part of the form
        //      Platforms supported on multiple machines will appear multiple times
        function setbmConId(  )
        {
                        console.log("Doing stuff");
            var bmConId = $('#selBmConId').children("option:selected").val();
            var table = $('#selPlat');
                        table.empty();

                        //  Parse the existing GBE_BUILDFILTER so that we can determine any platforms that are not
            //  supported on the selected build machine
            //  Convert the GBE_BUILDFILTER into an object for easy processing
                        var curFilter = {};
                        var tmpStr = $('#gbe_buildfilter').val().trim().replace(/,/g, ' ').toUpperCase();
            if ( tmpStr.length <= 0 ) {
                                tmpStr = 'NONE';
            }
                        var curFilterArray = tmpStr.split(/\s+/);
            for ( i = 0; i < curFilterArray.length; i++ ) {
                                curFilter[curFilterArray[i]] = 1;
                        }
            $('#gbe_buildfilter').val(Object.keys(curFilter).sort().join(' '));

            // Insert platforms supported on selected machine
            Object.keys(platformXref).sort().forEach(platform => {
                if ( platformXref[platform][bmConId] ||  platformXref[platform]['ALL'] ){
                    table.append(createPlatformRow(platform, curFilter[platform], undefined));
                                        delete curFilter[platform]; 
                }
            });

            // Insert platforms NOT supported on selected machine
            // Prepend in reverse order
            Object.keys(curFilter).sort().reverse().forEach(platform => {
                if ( platform ) {
                    table.prepend(createPlatformRow(platform, true, 'err_alert'));
                }
            });
        }

        // Local function to create a platform row, with checkbox
        //
        function createPlatformRow(platform, state, eClass){
            var row = $("<tr/>").addClass('body_txt selPlat').addClass(eClass);
            var td = $("<td/>");
            var item = $("<input/>").attr('type', 'checkbox').css('margin','0px 3px').prop('checked', state).change(updateGbeFilter);
            var itemText = $("<span/>").text(platform);
            if ( eClass ) {
                itemText.append(' - Not available');
            }
            td.append(item);
            td.append(itemText);
            row.append(td);
            return row;
        }

        // Update GBE_BUILDFILTER as the user selects and deselects platforms
        function updateGbeFilter(){
                        var state = this.checked;
                        var platform = $(this).parent().text().trim();
                        var idx = platform.indexOf(' - ');
            if ( idx >= 0 )
                platform = platform.substring(0, idx );

            // Add or remove item
            //  Split the string into an array
            //  Always remove the item
            //  Append the platform - if adding
            //  Sort and reform a space-seperated string
            //
                        var gbeFilter = $('#gbe_buildfilter').val().trim().split(/\s+/);
            gbeFilter = gbeFilter.filter(e => e !== platform);
            if ( state ) {
                gbeFilter.push(platform);
            }
            
            gbeFilter = gbeFilter.sort();
            $('#gbe_buildfilter').val(gbeFilter.join(' '));
        }
    });
</script>
<%End Sub
'-------------------------------------------------
%>
<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">
<link href="images/release_manager_style.css?ver=<%=VixVerNum%>" rel="stylesheet" type="text/css">
<script language="JavaScript" src="scripts/common.js?ver=<%=VixVerNum%>"></script>
<!--#include file="_jquery_includes.asp"-->
<%Call InsertJavaScript %>
</head>

<body background="images/bg_bage_0.gif" leftmargin="0" topmargin="0" onLoad="self.focus();FormName.bmcon_id.focus();">
<table width="100%"  border="0" cellspacing="0" cellpadding="10">
   <tr>
      <td bgcolor="#FFFFFF" class="body_txt">
                <%If bAdd Then%>
         Add a new DAEMON
                <%Else%>
         Edit an existing DAEMON
                <%End If%>
      </td>
   </tr>

   <%
   '-- FROM START --------------------------------------------------------------------------------------------------------------
   objFormComponent.FormName = "FormName"
   objFormComponent.FormClass = "form_tight"
   objFormComponent.Action = ScriptName
   objFormComponent.OnSubmit = "ShowProgress();"
   Call objFormComponent.FormStart()
   %>
   <tr>
      <td>
         <!-- LOCAL ERROR +++++++++++++++++++++++++++++++++++++++++++++++ -->
         <%Call Messenger ( sMessage , 3, "100%" )%>
         <!-- MESSAGE +++++++++++++++++++++++++++++++++++++++++++++++++++ -->
         <!--#include file="messages/_msg_inline.asp"-->
         <table width="50%" border="0">
            <tr>
               <td><span class="body_txt">Daemon Host</span></td>
               <td>
                  <%=objFormComponent.Combo_Multi ( "bmcon_id", GetMachHost(bmcon_id), bShowEmpty, "id=selBmConId class='body_txt'",3,"20,20,50")%>
               </td>
            </tr>
            <tr>
               <td><span class="body_txt">Daemon Mode</span></td>
               <td>
                 <select name="daemon_mode" class='body_txt'>
                   <option value=M <%=iif(daemon_mode="M","selected","")%>>Master</option>
                   <option value=S <%=iif(daemon_mode="S","selected","")%>>Slave</option>
                 </select>
               </td>
            </tr>
            <tr>
               <tr>
                  <td><span class="body_txt">GBE_BUILDFILTER</span></td>
                  <td><input id=gbe_buildfilter name="gbe_buildfilter" type="text" class="body_txt" size="120" spellcheck="false" value="<%=gbe_buildfilter%>"></td>
               </tr>
            </tr>
            <tr>
               <td><span class="body_txt nowrap">Platforms</span></td>
               <td style="border: darkgrey 1px solid">
                                <div style="overflow-y: scroll;height: 20em;">
                                        <table id=selPlat></table>
                                </div>
               </td>
            </tr>
         </table>
      </td>
   </tr>
   <tr>
      <td bgcolor=#FFFFFF>
         <table class="full_table">
            <tr>
               <td><%=ProgressBar()%></td>
               <td align="right">
                  <input name="btn" type="submit" class="form_btn" value="Add/Update">
                  <input name="btn" type="reset" class="form_btn" value="Cancel" onclick="parent.closeIFrame();">
               </td>
            </tr>
         </table>
      </td>
   </tr>
   <%=objPMod.ComposeHiddenTags()%>
   <input type="hidden" name="action" value="true">
   <input type="hidden" name="base_bmcon_id" value="<%=bmcon_id%>">
 <%If NOT bAdd Then%>
         <input type="hidden" name="rcon_id" value="<%=Request("rcon_id")%>">
 <% End If %>
   <%
   Call objFormComponent.FormEnd()
   '-- FROM END ----------------------------------------------------------------------------------------------------------------
   %>
</table>
</body>
</html>
<%
'------------ RUN AFTER PAGE RENDER -----------
Set objFormCollector = Nothing
'----------------------------------------------
Call Destroy_All_Objects
%>