Work on Expensify reports

This commit is contained in:
Rick Falkvinge
2018-02-11 11:16:08 +01:00
parent d61bd346c7
commit b315a514c0
7 changed files with 59 additions and 34 deletions
+8 -1
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Swarmops.Common;
@@ -48,7 +49,13 @@ namespace Swarmops.Logic.Cache
_cache.Remove (guidString);
}
}
public static void SetProgress(string guid, int progress)
{
GuidCache.Set(guid + "-Progress", progress.ToString(CultureInfo.InvariantCulture));
}
private static void ConditionalGarbageCollect()
{
+1
View File
@@ -42,6 +42,7 @@ namespace Swarmops.Frontend.Automation
// if the progress object doesn't exist, assume it hasn't been initialized yet
return new AjaxCallResult {Success = false};
}
}
}
+9 -6
View File
@@ -78,18 +78,21 @@
<%=this.ClientID%>_nextPollTimer = null;
SwarmopsJS.ajaxCall(
"/Automation/Json-ByGuid.aspx/GetProgress",
"/Automation/Json-ByGuid.aspx/GetNonsocketProgress",
{ guid: '<%= this.Guid%>' },
function(result) {
// Call our ordinary progress updater from the poller
if (result.Success) {
progressUpdateCallback_<%=this.GuidToken%>(result.d);
// Call our ordinary progress updater from the poller
// If the progress is less than 100, schedule another poll
progressUpdateCallback_<%=this.GuidToken%>(result.DisplayMessage);
if (result.d < 100) {
<%=this.ClientID%>_nextPollTimer = setTimeout(function() { <%= this.ClientID%>_progressFallbackPoll(); }, 2500);
// If the progress is less than 100, schedule another poll
if (result.DisplayMessage < 100) {
<%=this.ClientID%>_nextPollTimer = setTimeout(function() { <%= this.ClientID%>_progressFallbackPoll(); }, 2500);
}
}
}
);
+2 -2
View File
@@ -11,8 +11,8 @@ namespace Swarmops.Frontend.Controls.v5.Base
{
protected void Page_Load(object sender, EventArgs e)
{
_guid = string.Empty;
this.Header = Resources.Global.Global_ProcessingFile + "...";
_guid = System.Guid.NewGuid().ToString();
this.Header = Resources.Global.Global_ProcessingFile;
}
protected string GuidToken
+13 -13
View File
@@ -95,25 +95,25 @@
$('#divExpensifyResults').slideUp();
expensifyProcessingHalfway = false;
<%=this.ProgressExpensify.ClientID%>_begin(); // starts listening / polling for progress
SwarmopsJS.ajaxCall
("/Pages/v5/Financial/FileExpenseClaim.aspx/InitializeExpensifyProcessing",
{ guid: '<%= this.UploadExpensify.GuidString%>' },
{
guidFiles: '<%= this.UploadExpensify.GuidString%>',
guidProgress: '<%= this.ProgressExpensify.Guid%>'
},
function(result) {
if (result.Success) {
setTimeout(function() { updateExpensifyProgress(); }, 3000);
}
});
}
function updateExpensifyProgress() {
// This is a fallback for when the master page's Progress over socket doesn't work.
// We're polling every three seconds just to make sure to give the user some feedback.
}
function onExpensify
</script>
@@ -168,6 +168,9 @@
<div title="<img src='/Images/Icons/expensify-icon-official.png' width='40' height='40' style='padding-top:12px'>">
<div id="divExpensifyResults" style="display:none; margin-bottom:10px">
<Swarmops5:ProgressBarFake ID="ProgressExpensifyFake" runat="server"/>
<h2><asp:Label ID="LabelProcessingComplete" runat="server" /></h2>
<div id="divExpensifyProgressFake" style="width:100%"></div>
@@ -198,11 +201,8 @@
<br clear="all"/>
</div>
<div id="DivProcessing" style="display:none">
<h2><asp:Label runat="server" ID="LabelProcessing" /></h2>
<div id="DivProgressProcessing" style="width:100%"></div>
</div>
<Swarmops5:ProgressBar ID="ProgressExpensify" runat="server" OnClientProgressHalfwayCallback="onExpensifyProgressHalfway" OnClientProgressCompleteCallback="onExpensifyProgressComplete"/>
</div>
</div>
@@ -174,7 +174,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
[WebMethod(true)]
public static AjaxCallResult InitializeExpensifyProcessing(string guid)
public static AjaxCallResult InitializeExpensifyProcessing(string guidFiles, string guidProgress)
{
// Start an async thread that does all the work, then return
@@ -184,7 +184,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
ProcessThreadArguments args = new ProcessThreadArguments
{
Guid = guid,
GuidFiles = guidFiles,
GuidProgress = guidProgress,
Organization = authData.CurrentOrganization,
CurrentUser = authData.CurrentUser
};
@@ -197,7 +198,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
private class ProcessThreadArguments
{
public string Guid { get; set; }
public string GuidFiles { get; set; }
public string GuidProgress { get; set; }
public Organization Organization { get; set; }
public Person CurrentUser { get; set; }
}
@@ -211,13 +213,14 @@ namespace Swarmops.Frontend.Pages.v5.Financial
private static void ProcessExpensifyUploadThread(object args)
{
string guid = ((ProcessThreadArguments) args).Guid;
string guidProgress = ((ProcessThreadArguments) args).GuidProgress;
string guidFiles = ((ProcessThreadArguments)args).GuidFiles;
Person currentUser = ((ProcessThreadArguments) args).CurrentUser;
Organization organization = ((ProcessThreadArguments) args).Organization;
Documents documents = Documents.RecentFromDescription(guid);
GuidCache.Set(guid + "-Progress", 1); // to make sure results aren't repeated from last file
GuidCache.Set(guid + "-Result", UploadBankFiles.ImportResultsCategory.Bad);
Documents documents = Documents.RecentFromDescription(guidFiles);
GuidCache.SetProgress(guidProgress, 1); // to make sure results aren't repeated from last file
GuidCache.Set(guidProgress + "-UploadResult", UploadBankFiles.ImportResultsCategory.Bad);
// default - this is what happens if exception
if (documents.Count != 1)
@@ -295,7 +298,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
// Set progress to complete
// Abort
GuidCache.Set(guid + "-Progress", 100); // terminate progress bar
GuidCache.Set(guidProgress, 100); // terminate progress bar
throw new BarfException();
}
@@ -375,6 +378,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
throw new BarfException(); // TODO: ASK USER
}
GuidCache.SetProgress(guidProgress, 10);
// We now need to get all the receipt images. This is a little tricky as we don't have the URL
// of the receipt directly, we only have the URL of a webpage that contains JavaScript code
// to fetch the receipt image.
@@ -385,10 +390,10 @@ namespace Swarmops.Frontend.Pages.v5.Financial
// Get all receipts
for (int loop = 0; loop < recordList.Count; loop++)
{
GuidCache.SetProgress(guidProgress, loop * 90 / recordList.Count + 10);
using (WebClient client = new WebClient())
{
string receiptResource = client.DownloadString(recordList[loop].ReceiptUrl);
+11 -2
View File
@@ -219,6 +219,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelBankAccount;
/// <summary>
/// ProgressExpensifyFake control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.v5.Base.ProgressBarFake ProgressExpensifyFake;
/// <summary>
/// LabelProcessingComplete control.
/// </summary>
@@ -283,12 +292,12 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
protected global::System.Web.UI.WebControls.Label LabelExpensifyCsv;
/// <summary>
/// LabelProcessing control.
/// ProgressExpensify 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 LabelProcessing;
protected global::Swarmops.Frontend.Controls.v5.Base.ProgressBar ProgressExpensify;
}
}