Subversion Repositories DevTools

Rev

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

<%
'===============================================================
'                    Version Browser
'===============================================================
%>
<!--#include file="class/classSortHelper.asp"-->
<%
'------------ Variable Definition -------------
Dim parFLpkg_version, parFLuser_name
Dim imgLock, fieldRelease_Date, fieldReleased_By, fieldDownloadFullReleaseNotes
Dim rsVB
Dim imgPointer
Dim URLstring
Dim pvidName
Dim idxName
Dim filterInUse
Dim hideRipple
Dim rippleFilter
Dim DestroyPackage
Dim CanDestroyProjectPackage
Dim CanDestroyPackage
'------------ Constants Declaration -----------
Const IMG_PONTER = "<img src='images/i_pointer.gif' width='6' height='11' hspace='3'>"
Const IMG_OFFICIAL = "<img src='images/i_locked.gif' width='7' height='10' hspace='5' vspace='2' title='Package has been Released'>"
Const IMG_PENDING = "<img src='icons/i_pending.gif' width='7' height='10' hspace='5' vspace='2' title='Package pending autobuild'>"
Const IMG_NOT_OFFICIAL = "<img src='images/spacer.gif' width='7' height='10' hspace='5' vspace='2' title='Package not yet released'>"
Const IMG_NOT_BUILDABLE = "<img src='icons/s_unbuildable.png' width='14' height='14' hspace='5' vspace='0' title='Package is not buildable'>"
Const IMG_DOWNLOAD = "<img src='images/i_download_small.gif' alt='Download full release notes.' width='16' height='16' hspace='2' border='0'>"
'------------ Variable Init -------------------
If Request("filter_reset") <> "" Then 
    parFLpkg_version = "*"
    parFLuser_name   = "*"
    filterInUse = FALSE
Else
    parFLpkg_version = RequestDefault( "FLpkg_version", "*" )
    parFLuser_name   = RequestDefault( "FLuser_name","*" )
    filterInUse = Is_Filter_In_Use ( "FLpkg_version, FLuser_name" )
End If

If Request("hideRipple") = "True" Then 
    hideRipple = True
    rippleFilter = "AND PV.BUILD_TYPE != 'Y'"
Else
    hideRipple = False
    rippleFilter = ""
End If

'----------------------------------------------
%>
<%
'-----------------------------------------------------------------------------------------------------------------------------------
Function Get_All_Versions ( nPkg_id )
    Get_All_Versions = _
    " SELECT DISTINCT PV.PV_ID," &_
    "   PV.PKG_VERSION," &_
    "   PV.DLOCKED," &_
    "   PV.MODIFIED_STAMP," &_
    "   USR.FULL_NAME," &_
    "   usr.user_name," &_
    "   USR.USER_EMAIL," &_
    "   PV.COMMENTS," &_
    "   PV.PKG_LABEL," &_
    "   PV.IS_PATCH," &_
    "   PV.RELEASE_NOTES_INFO," &_
    "   PV.BUILD_TYPE," &_
    "   pv.CREATOR_ID," &_
    "   pv.OWNER_ID," &_
    "   pv.BUILD_TYPE," &_
    "   NVL2(rc.rtag_id,1,0) as inuse," &_
    "   trunc(SYSDATE - pv.CREATED_STAMP + 0.5) as age" &_
    " FROM PACKAGE_VERSIONS PV," &_
    "      USERS USR,"&_
    "      RELEASE_CONTENT rc" &_
    " WHERE PV.MODIFIER_ID = USR.USER_ID(+) " &_
    "   AND PV.PKG_ID = :PKG_ID" &_
    "   AND pv.pv_id = rc.pv_id(+)" &_
    "    /*-- Manual Filter --*/" &_
    "    "& Construct_Filter ( parFLpkg_version, "pv.pkg_version" ) &_
    "    "& Construct_Filter ( parFLuser_name, "usr.user_name" ) &_
    "    "& rippleFilter &_
    "    /*------------------*/"
    
    Get_All_Versions = Replace( Get_All_Versions, ":PKG_ID", nPkg_id)
End Function
'-----------------------------------------------------------------------------------------------------------------------------------
Function Construct_Filter ( sPar_val, sCol_name )
    Select Case sPar_val
    Case Empty
        Construct_Filter = "AND "& sCol_name &" IS NULL"
        
    Case "*"
        Construct_Filter = ""
        
    Case Else
        If InStr( sPar_val, "*") > 0 Then
            ' Asterisk found in string. Use LIKE
            Construct_Filter = "AND "& sCol_name &" LIKE '"& Replace( sPar_val, "*", "%" ) &"'"
        Else
            ' No asterisk. Use =
            Construct_Filter = "AND "& sCol_name &" = '"& sPar_val &"'"
        End If
        
    End Select
    
End Function
'-----------------------------------------------------------------------------------------------------------------------------------
Function Is_Filter_In_Use ( sFilters )
    Dim filters, filterName
    Is_Filter_In_Use = FALSE
    
    filters = Split( Replace( sFilters, " ", "" ), "," )
    
    For Each filterName In filters
        If Request( filterName ) <> "*" Then 
            Is_Filter_In_Use = TRUE
            Exit For
        End If
    Next
    
End Function
'-----------------------------------------------------------------------------------------------------------------------------------
%>
<!--#include file="_jquery_includes.asp"-->
<script language="JavaScript" type="text/JavaScript">
function useThisVersion (pkgName, pkgVersion, rtagId, oldPvid, newPvid) {
    console.log("useThisVersion:", pkgName, pkgVersion);
    debugger;
    //alert ("Use this version");
    $( "#dialog-confirm" ).dialog({
      position: { my: "top", at: "top+100", of: window },
      modal: true,
      draggable: true,
      resizable: true,
      dialogClass: "rounded_box",
      height:250,
      width:350,
      buttons: {
        "Direct": function() {
          window.opener.document.location="_new_version.asp?OLDpv_id=" + oldPvid + "&rtag_id=" + rtagId + "&pv_id=" + newPvid
          self.close();
          $( this ).dialog( "close" );
        },
        "Pending": function() {
          window.opener.document.location="_new_version.asp?OLDpv_id=" + oldPvid + "&rtag_id=" + rtagId + "&pv_id=" + newPvid + '&iMode=pending';
          self.close();
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      },
      open: function() {
          $(this).siblings('.ui-dialog-buttonpane').find('button:eq(2)').focus(); 
      }
    });

    return false;
}

//  Scroll to package
//  Order of preference
//      index   - location of last package deleted
//      index-1 - Near last pakage deleted
//      pvid    - PVID being viewed
//      oldPVID - PVID Deleted
function scrollToPvId() {
    var oldpvid = Number('<%=parOLDpv_id%>');
    var pvid    = Number('<%=parPv_id%>'); 
    var idx     = Number('<%=parIndex%>');
    var els = $();

    if (idx > 0) {
        els = $('[data-idx='+idx+']');
        if (els.length==0) {
            els = $('[data-idx='+(idx-1)+']');
        }
    }

    if (els.length==0) els = $('[data-pvid='+pvid+']');
    if (els.length==0) els = $('[data-pvid='+oldpvid+']');
    if (els.length) {
        els[0].scrollIntoView();
        els.addClass('highlightRow');
    }
}

//  Set the height of the two areas in the History Window
//  Note: Divs may not always be available.
function setLayerHeight () {
    try {
        var h = screen.height;
        MM_findObj("LayerVersions").style.height = (h-300)/2 +"px";
        MM_findObj("LayerDetails").style.height = (h-300)/2 +"px";
    } catch(e) {
    }
}
   
//  Attach events   
$(document).ready(function() {

    //  This function is invoked when the user clicks within a row
    //  The click will re-load and reposition the version history to the selected version
    //  The problem is that the 'Destroy Version' interacts with this.
    //  Also the mailto operation interacts with this
    //  Solution: The DestroyVersion is an image within a 'td'. 
    //            If the 'td' has a class of nogo, then don't navigate
    $('.selectVersion').on('click', function () {

        if ($(event.target).closest('td').hasClass('nogo') || $(event.target).closest('span').hasClass('mailto') ) {
            return;
        }

        var tr = $(this).closest('tr');
        var pvid = $(tr).data('pvid');
        var isaPatch = $(tr).hasClass('isaPatch');
        var URLstring = <%="'" & Persists_Query_String_Trim( "","index,pv_id" ) & "'" %>;
        var script;

        if ( isaPatch ) {
            script = '_wform_versions_history_release_notes.asp';
        } else {
            script = <%= "'" & scriptName & "'" %>
        }
        URLstring = script + '?' + URLstring + 'pv_id=' + pvid;
        location.href = URLstring; 
    });

    //  This function will add a listener to allow a user to download the Release Notes
    //  If the target does not exist, then it will redirect to a 404 error :(
    $('.downloadNotes').on('click', function (){
        var notes = $(this).data('rnote');
        var tr = $(this).closest('tr');
        var pvid = $(tr).data('pvid');
        var URLstring = <%="'" & HTTP_PKG_ARCHIVE & "'" %> + notes;

        //  Open in a new window
        window.open(URLstring, '_blank');
    });

    //  Add a listener for destroyVersion events
    $('.destroyVersion').on('click', function (){
    var tr = $(this).closest('tr');
    var pvid = $(tr).data('pvid');
    var idx = $(tr).data('idx');

    var data = {
        pv_id       : pvid,
        bfile       : "<%=ScriptName%>",
        rtag_id     : "<%=parRtag_id%>",
        FLuser_name : "<%=parFLuser_name%>",
        FLpkg_version : "<%=parFLpkg_version%>",
        rfile       : "<%=parRfile%>",
        pkg_id      : "<%=parPkg_id%>",
        OLDpv_id    : "<%=parOLDpv_id%>",
        index       : idx };
    var param = $.param(data);
    MM_openVixIFrame('_destroy_package.asp?' + param, 'Destroy Package Version')
    });

});

//# sourceURL=_version_browser_1.asp
</script>
<style type="text/css">
    table.stdBrown {border:inherit}
    table.stdBrown tbody tr.highlightRow {background-color : #FAF3d9}
        table.stdBrown tbody tr {vertical-align:top}
        table.stdBrown tbody tr td {padding-right: 2px}
        table.stdBrown thead th {background-color : #cac5b8;padding-right: 0em;vertical-align:top}
        table.stdBrown>tbody>tr>:nth-child(1) {background-color: #cac5b8; padding-right: 0em;}
        table.stdBrown>tbody>tr>:nth-child(2) {padding-right: 0em;}
        .pkgTitle {background-color : #cac5b8}
        }
</style>
      <!--------------- ACTION BUTTONS -------------------------->
      <div  style="width:100vw;">
      <form name="filter" method="get" action="<%=scriptName%>">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="1" valign="middle" class='bg_dialog'><img src="images/spacer.gif" width="5" height="35"></td>
          <td width="100%" valign="middle" class='bg_dialog'><%
          Dim bEnableUse : bEnableUse = FALSE
          If Request("rtag_id") = ""  OR  _
             Request("pv_id") = "" OR _
             parOLDpv_id = ParPv_id OR _
             bIsPatch OR _
             (NOT bCanInsertPkg) OR _
             (NOT objAccessControl.UserLogedIn) OR _
             (NOT releaseIsWritable(ReleaseMode))  _
          Then
                bEnableUse = FALSE
          Else
                bEnableUse = TRUE
          End If

          If bEnableUse Then
          %>
          <div id='dialog-confirm' title="Confirm version change" style="display:none">
          <p>Replace the current version of package <%=sPkg_Name%> with Version <%=sPkg_Version%>.
          <p>The new version may be added directly into the release or the change may be made pending. 
          </div>
          <%
            Response.write "<a href=';' onClick='return useThisVersion("""& sPkg_Name &""","""& sPkg_Version & """,""" & parRtag_id & ""","""& parOLDpv_id & """,""" & parPv_id & """);'><img src='images/abtn_use_this_version.gif' title='Use this version in project release.' width='107' height='25' hspace='1' border='0'></a>"
          Else
            Response.write "<img src='images/abtn_use_this_version_off.gif' width='108' height='26' hspace='1' border='0'>"
          End If
          
          Response.write "<img src='images/spacer.gif' width='25' height='25'>"
          If filterInUse Then
            Response.write "<input type='image' name='btn' src='images/abtn_filter_on.gif' width='25' height='25' border='0' title='Apply filter. (Filter is in use!)'>"
          Else
            Response.write "<input type='image' name='btn' src='images/abtn_filter.gif' width='25' height='25' border='0' title='Apply filter'>"
          End If
          Response.write "<span class=pointer  onClick=""location.href='"& scriptName &"?"& Persists_Query_String( "filter_reset=true" ) &"'""><img src='images/abtn_remove_filter.gif' title='Remove filter' width='25' height='25' hspace='2' border='0'></span>"

          Response.write "<img src='images/spacer.gif' width='25' height='25'>"
          Response.write "<span class=pointer onClick=""location.href='"& scriptName &"?"& Persists_Query_String( "hideRipple=" & not hideRipple ) &"'"">"
              If hideRipple Then
                Response.write "<img src='images/RippleSquareOff.gif' width='25' height='25' border='0' title='Rippled Versions Hidden. Toggle'>"
              Else
                Response.write "<img src='images/RippleSquare.gif' width='25' height='25' border='0' title='Rippled Versions Shown. Toggle'>"
              End If
          Response.write "</span>"

          %></td>
          <td width="1" valign="middle" class='bg_dialog pointer' onClick="window.opener.document.location='dependencies.asp?pv_id=<%=parPv_id%>';self.close();"><img src="images/abtn_open.gif" width="46" height="25" hspace="5" border="0" alt="Open In Parent Window."></td>
          <td width="1" valign="middle" class='bg_dialog pointer' onClick="self.close();"><img src="images/abtn_close.gif" width="46" height="25" hspace="5" border="0" alt="Close this window."></td>
        </tr>
      </table>
      <!--------------------- CAPTION ---------------------------->
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="lbox_ttl_b pkgTitle" align="center"><%=sPkg_Name%></td>
        </tr>
      </table>
      <!------------------ VERSION LIST -------------------------->
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class='bg_dialog'> 
            <div id="LayerVersions" style="height: 350px; width:100vw; overflow: auto;" name="LayerVersions"> 
              <table width="100%" border="0" cellspacing="1" cellpadding="2" class=stdBrown>
                <thead>
                  <th width="1" nowrap></th>
                  <th width="1" nowrap>&nbsp;</th>
                  <th width="1" nowrap>Version&nbsp;&nbsp;<br><input name="FLpkg_version" type="text" class="form_ifilter" value="<%=parFLpkg_version%>" size="15"></th>
                  <th width="1" nowrap>Last Mod. Date&nbsp;&nbsp;</th>
                  <th width="100%" nowrap>Reason for this version</th>
                  <th width="1" nowrap>Last Modified&nbsp;&nbsp;<br><input name="FLuser_name" type="text" class="form_ifilter" value="<%=parFLuser_name%>" size="15"></th>
                  <th width="1" nowrap></th>
                  <th width="1" nowrap></th>
                </thead>
                <%
                Dim aVersions, lastRow, i, objSortHelper, idx, rowClass

                Set rsVB = OraDatabase.DbCreateDynaset( Get_All_Versions ( parPkg_id ), cint(0))
                
                ' Descending order
                If rsVB.RecordCount > 0 Then
                aVersions = rsVB.GetRows()
                lastRow = UBound( aVersions, 2 )
                
                Set objSortHelper = New SortHelper
                
                
                ' Sort versions
                Call objSortHelper.VersionSort( aVersions, 0, lastRow, rsVB.FieldIndex("pkg_version") )
                CanDestroyProjectPackage = canShowControlInProject ( "DestroyPackage" )
                
                ' Descending order
                idx = 0
                For i = lastRow To 0 Step -1
                    idx = idx + 1

                %>
                <%  ' Highlight row case
                    imgPointer = ""
                    rowClass = "pointer selectVersion "
                    If CStr( aVersions( rsVB.FieldIndex("pv_id"), i ) ) = parPv_id Then
                        rowClass = rowClass & " highlightRow" 
                        imgPointer = IMG_PONTER
                    End If
                    
                    ' Official/Unofficial case
                    imgLock = IMG_NOT_OFFICIAL
                    'fieldRelease_Date = ""
                    'fieldReleased_By = ""
                    If (aVersions( rsVB.FieldIndex("build_type"), i ) = "U")  Then
                        imgLock = IMG_NOT_BUILDABLE
                    ElseIf (aVersions( rsVB.FieldIndex("dlocked"), i ) = "Y")  Then
                        imgLock = IMG_OFFICIAL
                    ElseIf (aVersions( rsVB.FieldIndex("dlocked"), i ) = "A") Then 
                        imgLock = IMG_PENDING
                    End If
                    
                    fieldRelease_Date = DisplayShortDateTime ( aVersions( rsVB.FieldIndex("modified_stamp"), i ) )
                    fieldReleased_By = emailField(enum_imgUser & aVersions( rsVB.FieldIndex("full_name"), i ), aVersions( rsVB.FieldIndex("user_email"), i ))
                    
                    ' Full Release Notes availability
                    fieldDownloadFullReleaseNotes = ""
                    If NOT IsNull( aVersions( rsVB.FieldIndex("release_notes_info"), i ) ) OR ( InStr( aVersions( rsVB.FieldIndex("release_notes_info"), i ), "MGS:") < 1)  Then
                        fieldDownloadFullReleaseNotes = "<img src='images/i_download_small.gif' title='Download full release notes.' width='16' height='16' hspace='2' border='0' class='pointer downloadNotes' data-rnote='"&aVersions( rsVB.FieldIndex("release_notes_info"), i )&"'>"
                    End If
                    
                    pvidName = "PVID_"& aVersions( rsVB.FieldIndex("pv_id"), i )
                    idxName = "IDX_" & idx
                    If aVersions( rsVB.FieldIndex("is_patch"), i ) = "Y" Then
                        rowClass = rowClass & " isaPatch" 
                    End If
                    
                    ' User can try to delete package iff
                    '   Have suffiecient access (unusual)
                    '   They created it or own it
                    '   The version is not in use by any release (allow to be in pending or WIP)
                    '   [Not at the moment] The package was created less than xxxx days ago
                    '   Is not locked or [Not at the moment] Approved for Autobuild
                    CanDestroyPackage = CanDestroyProjectPackage
                    If NOT CanDestroyPackage Then
                        If (objAccessControl.UserId = aVersions( rsVB.FieldIndex("CREATOR_ID"), i )) OR (objAccessControl.UserId = aVersions( rsVB.FieldIndex("OWNER_ID"), i ))Then
                            If aVersions( rsVB.FieldIndex("inuse"), i ) = 0 Then
                                'If aVersions( rsVB.FieldIndex("age") , i ) < 1000 Then
                                    If aVersions( rsVB.FieldIndex("dlocked"), i ) <> "Y" Then
                                        'If aVersions( rsVB.FieldIndex("dlocked"), i ) <> "A" Then
                                            CanDestroyPackage = true
                                        'End If
                                    End If
                                'End If
                            End If
                        End If
                    End If
                    
                    ' Set destroy package action
                    If CanDestroyPackage Then
                        DestroyPackage = "<span class='destroyVersion'"&_
                                         " title='Destroy this version of the package.'> "&_
                                         " <img src='icons/i_destroy_package_sml.gif' width='15' height='15' border='0' ><span>"
                    Else
                        DestroyPackage = ""
                    End If
                %>
                <tr id='<%=idxName%>' data-idx='<%=idx%>' data-pvid='<%=CStr( aVersions( rsVB.FieldIndex("pv_id"), i ) )%>' class='<%=rowClass%>'> 
                  <td align="center"><%=imgPointer%></td>
                  <td align="center" ><%=imgLock%></td>
                  <td nowrap ><a class="txt_linked"><%=aVersions( rsVB.FieldIndex("pkg_version"), i )%></a></td>
                  <td nowrap ><%=fieldRelease_Date%></td>
                  <td ><%=NewLine_To_BR ( To_HTML( aVersions( rsVB.FieldIndex("comments"), i ) ) )%></td>
                  <td nowrap ><%=fieldReleased_By%></td>
                  <td align="center" class="nogo" ><%=fieldDownloadFullReleaseNotes%></td>
                  <td align="center" class="nogo" ><%=DestroyPackage%></td>
                </tr>
                <%
                Next
                End If
                %>
              </table>
            </div></td>
        </tr>
      </table> 
      <input type="hidden" name="rtag_id" value="<%=parRtag_id%>">
      <input type="hidden" name="pkg_id" value="<%=parPkg_id%>">
      <input type="hidden" name="rfile" value="<%=parRfile%>">
      <input type="hidden" name="OLDpv_id" value="<%=parOLDpv_id%>">
      <input type="hidden" name="pv_id" value="<%=parPv_id%>">
      <input type="hidden" name="filter_reset" value="">
      </form>
      </div>