From 021199a2f4e9acfe78ad306303a5af4dc0aad968 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 5 Jul 2019 14:23:20 +0000 Subject: [PATCH] --- Controllers/CustomerController.cs | 4 +- util/RfMail.cs | 53 +++--- wwwroot/js/app.purchases.js | 266 ++++++++++++++++-------------- 3 files changed, 172 insertions(+), 151 deletions(-) diff --git a/Controllers/CustomerController.cs b/Controllers/CustomerController.cs index 9425e89..54665af 100644 --- a/Controllers/CustomerController.cs +++ b/Controllers/CustomerController.cs @@ -93,6 +93,8 @@ namespace rockfishCore.Controllers public IEnumerable GetActiveSubsForSites([FromRoute] long id) { + long EpochNow = DateUtil.NowAsEpoch(); + var res = from c in _context.Site .Where(c => c.CustomerId.Equals(id)).OrderBy(c => c.Name) select new dtoNameIdChildrenItem @@ -108,7 +110,7 @@ namespace rockfishCore.Controllers { var subs = from c in _context.Purchase .Where(c => c.SiteId.Equals(child.id)) - .Where(c => c.CancelDate == null) + .Where(c => c.CancelDate == null || c.CancelDate > EpochNow) .OrderByDescending(c => c.PurchaseDate) select new dtoNameIdItem { diff --git a/util/RfMail.cs b/util/RfMail.cs index 2437be3..51e2897 100644 --- a/util/RfMail.cs +++ b/util/RfMail.cs @@ -328,45 +328,48 @@ namespace rockfishCore.Util quoted.WriteLine("On {0}, {1} wrote:", message.Date.ToString("f"), name); - //TODO: get text message just like in reader here for html only message - //sometimes body text is empty. - /* - var theBody = m.GetTextBody(MimeKit.Text.TextFormat.Plain); + //Try to get the original message text and format it as > quoted + + var theBody = message.GetTextBody(MimeKit.Text.TextFormat.Plain); if (theBody == null) { - //might be an html email, try to get the text anyway - var ht = m.HtmlBody; + //No text body so go with the new method to extract the text part + // might be an html email, try to get the text anyway + var ht = message.HtmlBody; if (!string.IsNullOrWhiteSpace(ht)) { - theBody = "**** HTML-ONLY MESSAGE ****"; - theBody += "\r\n=-=-=-=- TEXT CONVERSION =-=-=-=-\r\n"; - theBody += StripHTML(ht, true); - theBody += "\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"; - theBody += "\r\n=-=-=-=- SOURCE HTML =-=-=-=-\r\n"; - theBody += ht; - theBody += "\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"; - theBody += "\r\n******* END MESSAGE *******"; + + theBody = StripHTML(ht, true); + theBody += "> "; + theBody = theBody.Replace("\r\n", "\r\n> ").Trim().TrimEnd('>'); + theBody ="\r\n"+theBody;//descend the first line under the On you wrote bit + } else { - theBody = "NO MESSAGE BODY WAS FOUND NEITHER HTML NOR TEXT"; + theBody = "> Source Message Empty"; } + + quoted.WriteLine(theBody); } - sb.AppendLine(theBody); - */ - - - using (var reader = new StringReader(message.TextBody)) + else { - string line; - - while ((line = reader.ReadLine()) != null) + //has a text body so go with old method + using (var reader = new StringReader(message.TextBody)) { - quoted.Write("> "); - quoted.WriteLine(line); + string line; + + while ((line = reader.ReadLine()) != null) + { + quoted.Write("> "); + quoted.WriteLine(line); + } } } + + + reply.Body = new TextPart("plain") { Text = replyBody + "\r\n\r\n\r\n" + quoted.ToString() diff --git a/wwwroot/js/app.purchases.js b/wwwroot/js/app.purchases.js index f8913ed..1b5d18d 100644 --- a/wwwroot/js/app.purchases.js +++ b/wwwroot/js/app.purchases.js @@ -7,139 +7,155 @@ /*global $, app */ -app.purchases = (function () { - 'use strict'; - //---------------- BEGIN MODULE SCOPE VARIABLES -------------- - var +app.purchases = (function() { + "use strict"; + //---------------- BEGIN MODULE SCOPE VARIABLES -------------- + var configMap = { + //main_html: '', - configMap = { - //main_html: '', + settable_map: {} + }, + stateMap = { + $append_target: null + }, + onSubmit, + loadList, + configModule, + initModule; + //----------------- END MODULE SCOPE VARIABLES --------------- - settable_map: {} - }, - stateMap = { - $append_target: null - }, - onSubmit, loadList, configModule, initModule; - //----------------- END MODULE SCOPE VARIABLES --------------- + //------------------- BEGIN UTILITY METHODS ------------------ + loadList = function() { + var epochNow = Math.round(new Date().getTime() / 1000); - //------------------- BEGIN UTILITY METHODS ------------------ - loadList = function () { - //---- - //fetch - app.api.get('site/' + stateMap.id + '/purchases', function (res) { - if (res.error) { - $.gevent.publish('app-show-error',res.msg); - } else { - //get the list ul - var $appList = $('#rf-list'); - $appList.empty(); - $.each(res, function (i, obj) { + //---- + //fetch + app.api.get("site/" + stateMap.id + "/purchases", function(res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } else { + //get the list ul + var $appList = $("#rf-list"); + $appList.empty(); + $.each(res, function(i, obj) { + //bugbug: don't just check for the presence of a cancel date but also is it in the past otherwise it's not cancelled + if (obj.cancelDate && obj.cancelDate < epochNow) { + $appList.append( + "
  • ' + + // app.utilB.genListColumn(app.utilB.epochToShortDate(obj.purchaseDate)) + + // ' ' + + "" + + app.utilB.genListColumn(obj.name) + + " cancelled " + + app.utilB.genListColumn( + app.utilB.epochToShortDate(obj.cancelDate) + ) + + "" + + "
  • " + ); + } else { + $appList.append( + '
  • ' + + // app.utilB.genListColumn(app.utilB.epochToShortDate(obj.purchaseDate)) + + // ' ' + + app.utilB.genListColumn(obj.name) + + " expires " + + app.utilB.genListColumn( + app.utilB.epochToShortDate(obj.expireDate) + ) + + "
  • " + ); - if (obj.cancelDate) { - $appList.append("
  • " + - // app.utilB.genListColumn(app.utilB.epochToShortDate(obj.purchaseDate)) + - // ' ' + - ""+ - app.utilB.genListColumn(obj.name) + - " cancelled " + - app.utilB.genListColumn(app.utilB.epochToShortDate(obj.cancelDate)) + - ""+ - "
  • "); - } else { - $appList.append("
  • " + - // app.utilB.genListColumn(app.utilB.epochToShortDate(obj.purchaseDate)) + - // ' ' + - app.utilB.genListColumn(obj.name) + - " expires " + - app.utilB.genListColumn(app.utilB.epochToShortDate(obj.expireDate)) + - "
  • "); - - // - } - - - - - }); - } + // + } }); - //------ + } + }); + //------ + }; + //-------------------- END UTILITY METHODS ------------------- + + //--------------------- BEGIN DOM METHODS -------------------- + + // Begin private DOM methods + + // End private DOM methods + //---------------------- END DOM METHODS --------------------- + + //------------------- BEGIN EVENT HANDLERS ------------------- + + //-------------------- END EVENT HANDLERS -------------------- + + //------------------- BEGIN PUBLIC METHODS ------------------- + //CONFIGMODULE + // + configModule = function(context) { + stateMap.context = context.context; + if (stateMap.context.params.id) { + stateMap.id = stateMap.context.params.id; } - //-------------------- END UTILITY METHODS ------------------- + }; - //--------------------- BEGIN DOM METHODS -------------------- + // Begin public method /initModule/ + // Example : app.customer.initModule( $('#div_id') ); + // Purpose : directs the module to being offering features + // Arguments : $container - container to use + // Action : Provides interface + // Returns : none + // Throws : none + // + initModule = function($container) { + if (typeof $container === "undefined") { + $container = $("#app-shell-main-content"); + } + stateMap.sortOrder = "d"; + $container.html(Handlebars.templates["app.purchases"]({})); + if (!stateMap.id) { + throw "app.purchases.js::initModule - There is no stateMap.id!"; + } - - - // Begin private DOM methods - - - - // End private DOM methods - //---------------------- END DOM METHODS --------------------- - - //------------------- BEGIN EVENT HANDLERS ------------------- - - - - - //-------------------- END EVENT HANDLERS -------------------- - - //------------------- BEGIN PUBLIC METHODS ------------------- - //CONFIGMODULE - // - configModule = function (context) { - stateMap.context = context.context; - if (stateMap.context.params.id) { - stateMap.id = stateMap.context.params.id; + app.api.get("site/" + stateMap.id, function(res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } else { + //Context menu + app.nav.contextClear(); + app.nav.contextAddLink( + "purchaseEdit/new/" + stateMap.id, + "New", + "plus" + ); + app.nav.contextAddLink( + "customerEdit/" + res.customerId, + "Customer", + "account" + ); + app.nav.contextAddLink( + "customerSiteEdit/" + stateMap.id + "/" + res.customerId, + "Site", + "city" + ); + if (stateMap.id) { + loadList(); } - }; + } + }); + }; + // End public method /initModule/ - // Begin public method /initModule/ - // Example : app.customer.initModule( $('#div_id') ); - // Purpose : directs the module to being offering features - // Arguments : $container - container to use - // Action : Provides interface - // Returns : none - // Throws : none - // - initModule = function ($container) { - if (typeof $container === 'undefined') { - $container = $('#app-shell-main-content'); - } - stateMap.sortOrder = 'd'; - $container.html(Handlebars.templates['app.purchases']({})); - - if (!stateMap.id) { - throw ('app.purchases.js::initModule - There is no stateMap.id!'); - } - - app.api.get('site/' + stateMap.id, function (res) { - if (res.error) { - $.gevent.publish('app-show-error',res.msg); - } else { - - //Context menu - app.nav.contextClear(); - app.nav.contextAddLink('purchaseEdit/new/' + stateMap.id, "New", "plus"); - app.nav.contextAddLink("customerEdit/" + res.customerId, "Customer", "account"); - app.nav.contextAddLink("customerSiteEdit/" + stateMap.id + '/' + res.customerId, "Site", "city"); - if (stateMap.id) { - loadList(); - } - } - }); - }; - // End public method /initModule/ - - - - // return public methods - return { - configModule: configModule, - initModule: initModule - }; - //------------------- END PUBLIC METHODS --------------------- -}()); \ No newline at end of file + // return public methods + return { + configModule: configModule, + initModule: initModule + }; + //------------------- END PUBLIC METHODS --------------------- +})();