<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Task.Master" Inherits="System.Web.Mvc.ViewPage<AdministratorConsole.Models.TaskController.TaskServersViewModel>" %>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        function viewTaskServer(taskServerId) {
            $.ajax({
                type: 'GET',
                url: '<%= Url.Action("TaskServerDetail", "Task") %>',
                data: {
                    taskServerId: taskServerId
                },
                cache: false,
                success: function (response) {
                    $("#modal-overlay").html(response);
                },
                complete: function () {
                    showModelDialog();
                }
            });
        }

        function updateTaskServerOrder() {
            $.ajax({
                type: 'GET',
                url: '<%= Url.Action("GetTaskServers", "Task") %>',
                data: {
                    order: $("#server-order-select").val()
                },
                cache: false,
                success: function (response) {
                    $('#task-servers-container').empty();
                    $('#task-servers-container').html(response);
                }
            });
        }
    </script>
    <div id="content-wrap">
        <% Html.RenderPartial("Navigation/_SideNavigation", Model.MenuNavigationModel); %>
        <div id="content">
	        <div class="left-floating-panel"><h1>Task Servers</h1></div>
            <% if (Model.LicenseType != LicenseType.ODP)
               { %>
                <div class="right-floating-panel total-time-container-outer">
                    <div id="total-time-container">
				        <div class="header dark">Total Time Saved</div>
			            <div class="value"><%= (Model.CompletedTasksTimeHours).ToString("000") %> hrs</div>
                    </div>
                </div>
            <% } %>
            <div class="clear"></div>
            <div id="tab-container">
                <ul class="tabs">
			        <li><a href="<%= Url.Action("TaskServers", "Task") %>" class="active">Servers</a></li>
			        <li><a href="<%= Url.Action("Configuration", "Task") %>">Configuration</a></li>
                </ul>
            </div>
            <br />
            <% if (Model.TaskProcessors.Count > 0) { %>
                <% if(!string.IsNullOrEmpty(Model.UpgradeVersionError)) { %>
                    <div class="validation-error-content left-floating-panel"><%= Model.UpgradeVersionError %></div>
                <% } %>
                <div class="left-floating-panel">
                    <ul class="legend">
                        <li><span class="task-server-container warning-server key"></span><span class="key-label">Task Server has not Checked-in in an hour</span></li>
                        <li><span class="task-server-container error-server key"></span> <span class="key-label">Task Server has not Checked-in in a day</span></li>
                        <li><span class="task-server-container bim360-server key"></span> <span class="key-label">BIM360 Token expired or missing</span></li>
                    </ul>

                </div>
                <div class="right-floating-panel">
                    <table>
                        <tr>
                            <td>Sort:&nbsp;</td>
                            <td>
                                <select id="server-order-select" onchange="updateTaskServerOrder()">
                                    <option value="ServerName" selected="selected">Server Name</option>
                                    <option value="LastCheckIn">Last Check in</option>
                                    <option value="type">Type</option>
                                </select>    
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="clear"></div>
                <br />
                <div id="task-servers-container"><% Html.RenderPartial("Partials/AllTaskServers", Model.GetAllTaskServersViewModel()); %></div>
                <br />
                <% if (Model.CurrentUser.IsAdministrator) { %>
                    <div class="left-floating-panel"><input type="button" value="Upgrade All" class="button" onclick="window.location.href = '<%= Url.Action("UpgradeTaskServers", "Task") %>';" /></div>
                <% } %>
                <div class="right-floating-panel"><input type="button" value="Unpause All" class="button" onclick="window.location.href = '<%= Url.Action("UnpauseTaskServer", "Task") %>';" /></div>
                <div class="right-floating-panel"><input type="button" value="Pause All" class="button" onclick="window.location.href = '<%= Url.Action("PauseTaskServer", "Task") %>';" /></div>
                <div class="clear"></div>
            </div>
        <% } else { %>
            <div></div>There are no Task Servers currently registered</div>
        <% } %>
    </div>
</asp:Content>
