<%@ Page Language="c#" CodeBehind="jobdetails.aspx.cs" AutoEventWireup="false" Inherits="edu.jhu.Cas.Web.jobdetails" %>

<%@ Register TagPrefix="uc1" TagName="Trailer" Src="Trailer.ascx" %>
<%@ Register TagPrefix="uc2" TagName="Header" Src="top.ascx" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="edu.jhu.Cas.Util" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>CasJobs</title>
    <link href="cjobs.css" rel="stylesheet" />
    <script src="scripts/codemirror.js"></script>
    <script src="scripts/tsql.js"></script>
</head>
<body style="width: 100%;">
    <%if (!noheaders) { %><uc2:Header ID="Header" runat="server" />
    <%} %>
    <h2>
        '<%=null==job?"job":job.TaskName%>' Details</h2>
    <%if (null != job && (job.Status == QUERY_STATUS.READY || job.Status == QUERY_STATUS.STARTED ||
                        job.Status == QUERY_STATUS.CANCEL_PENDING)) {%>
    <p>
        <i>This page will automatically refresh every 30 seconds</i></p>
    <%if (job.Status == QUERY_STATUS.READY) {%>
    There are <b>
        <%=position%></b> jobs ahead of this one in the <b>
            <%=job.Target%></b> queue.
    <%}%>
    <meta http-equiv="Refresh" content='30;' url=''>
    <%}%>
    <p>
        <%=lmessage%></p>
    <%if (job == null) {%>
    <p>
        You probably do not have permission to view this job.</p>
    <%} else {%>
    <form runat="server" method="post">
    <p>
        <td align="center">
            <% if (job.Created_Table != null && job.Created_Table.Length > 0 && (job.Status == 4 || job.Status == 5)) {%>
            <!--  <p><i>This query created a MyDB table called <a title="Show me this table" href="mydb.aspx?tableName=<%=job.Created_Table%>"><%=job.Created_Table%></a></i></p>-->
            <%}%>
            <% if (job.Status < 2) {%>
            <input type="button" value="Cancel" onclick="window.open('cancelJob.aspx?id=<%=job.JobID%>','_top','');" />
            <%} else {
                   string s = "submitjob.aspx?resubmit=true&taskname=" + Server.UrlEncode(job.TaskName) + "&targest=" + Server.UrlEncode(job.Target);
       %>
            <input type="button" value="Resubmit Job" onclick="window.open('<%=s %>','_top','');" />
            <%}%>
        </td>
    </p>
    <table>
        <tr>
            <th>
                JobID
            </th>
            <th>
                TaskName
            </th>
            <th>
                Context
            </th>
            <th>
                Queue
            </th>
            <th>
                Submitted
            </th>
            <th>
                Started
            </th>
            <th>
                Finished
            </th>
            <th>
                Status
            </th>
        </tr>
        <tr>
            <td>
                <%=job.JobID%>
            </td>
            <td>
                <%=job.TaskName%>
            </td>
            <td>
                <%=job.Target%>
            </td>
            <td>
                <%=job.Estimate%>
            </td>
            <td>
                <%=job.TimeSubmit%>
            </td>
            <td>
                <%=GetDate(job.TimeStart)%>
            </td>
            <td>
                <%=GetDate(job.TimeEnd)%>
            </td>
            <td>
                <%=jobServ.getStatusHTML(wsid,job.Status)%>
            </td>
        </tr>
        <tr>
            <th colspan="1">
                Executed on
            </th>
            <th colspan="1">
                Rows
            </th>
            <th colspan="6">
                Message
            </th>
        </tr>
        <tr>
            <td colspan="1">
                <%=job.HostIP.Trim()%>
            </td>
            <td colspan="1">
                <%=job.Rows%>
            </td>
            <td colspan="6" rowspan="2">
                <textarea readonly="readonly" style="width: 100%" cols="8" rows="2"> <%=job.Message != null?job.Message:"No Message"%></textarea>
            </td>
        </tr>
        <tr>
            <th colspan="2">
                Query
            </th>
        </tr>
        <tr>
            <td class="center" colspan="8">
                <textarea readonly="readonly" id="queryArea" style="width: 100%" cols="80" rows="20"><%=job.Query%></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="7" />
        </tr>
        <%if (admin) {%>
        <tr>
            <tr>
                <th colspan="2">
                    Modified Query
                </th>
            </tr>
            <tr>
                <td class="center" colspan="8">
                    <textarea readonly="readonly" id="mQueryArea" style="width: 100%" cols="80" rows="20"><%=job.ModifiedQuery%></textarea>
                </td>
            </tr>
        </tr>
        <%}%>
    </table>
    </form>
    <%} // end if job ==null%>
    <%if (!noheaders) { %><uc1:Trailer ID="Trailer1" runat="server" cvsTag="$Name$" cvsRev="$Revision: 126008 $">
    </uc1:Trailer>
    <%} %>
    <script>
        var a = document.getElementById('queryArea');
        var myCodeMirror = CodeMirror.fromTextArea(a, {
            lineNumbers: false,
            matchBrackets: false,
            readOnly: true,
            mode: "text/x-tsql"
        });
        var a = document.getElementById('mQueryArea');
        if (a) {
            var myCodeMirror2 = CodeMirror.fromTextArea(a, {
                lineNumbers: false,
                matchBrackets: false,
                readOnly: true,
                mode: "text/x-tsql"
            });
        }
    </script>
</body>
</html>
