Added ProgressBar control

This commit is contained in:
Rick Falkvinge
2018-02-07 15:23:48 +01:00
parent 31a6a821b8
commit 72734a2b6e
8 changed files with 283 additions and 0 deletions
+104
View File
@@ -0,0 +1,104 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ProgressBar.ascx.cs" CodeFile="ProgressBar.ascx.cs" Inherits="Swarmops.Frontend.Controls.v5.Base.ProgressBar" %>
<script type="text/javascript" language="javascript">
function <%=this.ClientID%>_show() {
$('#Div_<%=this.ClientID %>_Encapsulation').show();
}
function <%=this.ClientID%>_fadeIn() {
$('#Div_<%=this.ClientID %>_Encapsulation').slideDown().fadeIn();
}
function <%=this.ClientID%>_fadeOut() {
$('#Div_<%=this.ClientID %>_Encapsulation').slideUp().fadeOut();
}
function <%=this.ClientID%>_hide() {
$('#Div_<%=this.ClientID %>_Encapsulation').hide();
}
function <%=this.ClientID%>_reset() {
$('#Div_<%=this.ClientID %>_ProgressBar').progressbar({ value: 0 });
}
function <%=this.ClientID%>_begin() {
$('#Div_<%=this.ClientID %>_ProgressBar').progressbar({ value: 0, max: 100 });
<%=this.ClientID%>_nextPollTimer = setTimeout(function() { <%= this.ClientID%>_progressFallbackPoll(); }, 2500);
}
function progressUpdateCallback_<%=this.GuidToken%>(newProgress)
{
// This function primarily gets called via a socket handler invoked on the master page, but also from our fallback polling.
if (newProgress > <%=this.ClientID%>_lastProgress) {
$("#Div_<%=this.ClientID %>_ProgressBar .progressbar-value").animate(
{
width: "100%"
}, { queue: false });
if (<%=this.ClientID%>_lastProgress < 50 && newProgress >= 50) {
// check for halfway callback
<% if (!String.IsNullOrEmpty(this.OnClientProgressHalfwayCallback)) { %>
<%=this.OnClientProgressHalfwayCallback%>('<%=this.Guid%>');
<% } %>
}
if (<%=this.ClientID%>_lastProgress < 100 && newProgress >= 100) {
// check for completion callback
<% if (!String.IsNullOrEmpty(this.OnClientProgressCompleteCallback)) { %>
<%=this.OnClientProgressCompleteCallback%>('<%=this.Guid%>');
<% } %>
// cancel any outstanding timer
if (<%=this.ClientID%>_nextPollTimer != null) {
clearTimeout(<%=this.ClientID%>_nextPollTimer);
<%=this.ClientID%>_nextPollTimer = null;
}
}
<%=this.ClientID%>_lastProgress = newProgress;
}
}
var <%=this.ClientID%>_lastProgress = 0;
var <%=this.ClientID%>_nextPollTimer = null;
function <%= this.ClientID%>_progressFallbackPoll() {
<%=this.ClientID%>_nextPollTimer = null;
SwarmopsJS.ajaxCall(
"/Automation/Json-ByGuid.aspx/GetProgress",
{ guid: '<%= this.Guid%>' },
function(result) {
// Call our ordinary progress updater from the poller
progressUpdateCallback_<%=this.GuidToken%>(result.d);
// If the progress is less than 100, schedule another poll
if (result.d < 100) {
<%=this.ClientID%>_nextPollTimer = setTimeout(function() { <%= this.ClientID%>_progressFallbackPoll(); }, 2500);
}
}
);
}
</script>
<div id="Div_<%=this.ClientID %>_Encapsulation" style="display:none"> <!-- hidden by default -->
<h2><asp:Label runat="server" ID="LabelProcessingHeader" /></h2>
<div id="Div_<%=this.ClientID %>_ProgressBar" style="width:100%"></div>
</div>
+53
View File
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Swarmops.Frontend.Controls.v5.Base
{
public partial class ProgressBar : ControlV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
_guid = string.Empty;
this.Header = Resources.Global.Global_ProcessingFile + "...";
}
protected string GuidToken
{
get { return _guid.Replace("-", "_"); } // creates a valid JS token
}
public string Guid
{
get { return _guid; }
set
{
if (!value.Contains("-") || value.Length != 36)
{
throw new FormatException("This doesn't look like a valid GUID: " + value);
}
_guid = value;
}
}
public string OnClientProgressHalfwayCallback { get; set; }
public string OnClientProgressCompleteCallback { get; set; }
public string Header
{
get { return _header; }
set
{
_header = value;
this.LabelProcessingHeader.Text = value;
}
}
private string _guid;
private string _header;
}
}
+24
View File
@@ -0,0 +1,24 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Swarmops.Frontend.Controls.v5.Base {
public partial class ProgressBar {
/// <summary>
/// LabelProcessingHeader control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelProcessingHeader;
}
}
@@ -0,0 +1,31 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ProgressBarFake.ascx.cs" CodeFile="ProgressBarFake.ascx.cs" Inherits="Swarmops.Frontend.Controls.v5.Base.ProgressBarFake" %>
<script type="text/javascript" language="javascript">
function <%=this.ClientID%>_show() {
$('#Div_<%=this.ClientID %>_Encapsulation').show();
$('#Div_<%=this.ClientID %>_ProgressBar').progressbar({ value: 0, max: 100 });
$('#Div_<%=this.ClientID %>_ProgressBar').progressbar({ value: 100 });
}
function <%=this.ClientID%>_fadeIn() {
$('#Div_<%=this.ClientID %>_Encapsulation').slideDown().fadeIn();
$('#Div_<%=this.ClientID %>_ProgressBar').progressbar({ value: 0, max: 100 });
$('#Div_<%=this.ClientID %>_ProgressBar').progressbar({ value: 100 });
}
function <%=this.ClientID%>_fadeOut() {
$('#Div_<%=this.ClientID %>_Encapsulation').slideUp().fadeOut();
}
function <%=this.ClientID%>_hide() {
$('#Div_<%=this.ClientID %>_Encapsulation').hide();
}
</script>
<div id="Div_<%=this.ClientID %>_Encapsulation" style="display:none"> <!-- hidden by default -->
<h2><asp:Label runat="server" ID="LabelProcessingHeader" /></h2>
<div id="Div_<%=this.ClientID %>_ProgressBar" style="width:100%"></div>
</div>
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Swarmops.Frontend.Controls.v5.Base
{
public partial class ProgressBarFake : ControlV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
this.Header = Resources.Global.Global_ProcessingFile + "...";
}
public string Header
{
get { return _header; }
set
{
_header = value;
this.LabelProcessingHeader.Text = value;
}
}
private string _header;
}
}
+24
View File
@@ -0,0 +1,24 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Swarmops.Frontend.Controls.v5.Base {
public partial class ProgressBarFake {
/// <summary>
/// LabelProcessingHeader control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelProcessingHeader;
}
}
+16
View File
@@ -128,6 +128,20 @@
<Compile Include="Controls\v5\Base\AjaxDropDown.ascx.designer.cs">
<DependentUpon>AjaxDropDown.ascx</DependentUpon>
</Compile>
<Compile Include="Controls\v5\Base\ProgressBarFake.ascx.cs">
<DependentUpon>ProgressBarFake.ascx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Controls\v5\Base\ProgressBarFake.ascx.designer.cs">
<DependentUpon>ProgressBarFake.ascx</DependentUpon>
</Compile>
<Compile Include="Controls\v5\Base\ProgressBar.ascx.cs">
<DependentUpon>ProgressBar.ascx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Controls\v5\Base\ProgressBar.ascx.designer.cs">
<DependentUpon>ProgressBar.ascx</DependentUpon>
</Compile>
<Compile Include="Controls\v5\Swarm\ImpersonationWarningBox.ascx.cs">
<DependentUpon>ImpersonationWarningBox.ascx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
@@ -776,6 +790,8 @@
<Compile Include="Controls\v5\Base\WebUserControlTest.ascx.designer.cs">
<DependentUpon>WebUserControlTest.ascx</DependentUpon>
</Compile>
<Content Include="Controls\v5\Base\ProgressBarFake.ascx" />
<Content Include="Controls\v5\Base\ProgressBar.ascx" />
<Content Include="Controls\v5\Financial\ComboBudgets.ascx" />
<Content Include="Controls\v5\Financial\ComboIncomeCostType.ascx" />
<Content Include="Controls\v5\Financial\CurrencyTextBox.ascx" />
+2
View File
@@ -44,6 +44,8 @@
<add tagPrefix="Swarmops5" tagName="ModalDialog" src="~/Controls/v5/Base/ModalDialog.ascx" />
<add tagPrefix="Swarmops5" tagName="MainMenu" src="~/Controls/v5/Base/MainMenu.ascx" />
<add tagPrefix="Swarmops5" tagName="TreePositions" src="~/Controls/v5/Swarm/TreePositions.ascx" />
<add tagPrefix="Swarmops5" tagName="ProgressBar" src="~/Controls/v5/Base/ProgressBar.ascx" />
<add tagPrefix="Swarmops5" tagName="ProgressBarFake" src="~/Controls/v5/Base/ProgressBarFake.ascx" />
</controls>
</pages>
</system.web>