Skip to content

Commit

Permalink
Merge pull request #110 from psteiwer/dev-1.7
Browse files Browse the repository at this point in the history
Dev 1.7
  • Loading branch information
psteiwer authored Dec 21, 2021
2 parents 9691c41 + ec28d88 commit 0b95545
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 18 deletions.
5 changes: 5 additions & 0 deletions PivotSubscriptions/EventLog.cls
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Property GUID As %String [ InitialExpression = {$System.Util.CreateGUID()} ];

Property RunOnce As %Boolean;

Property TableError As %Status [ InitialExpression = {$$$OK} ];

/// Takes in info about an Alert Task and logs the information to the TaskLog
ClassMethod CreateEvent(pType, pSubscriptionId, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, pRunOnce, ByRef pEvent) As %Status
{
Expand Down Expand Up @@ -160,6 +162,9 @@ Storage Default
<Value name="17">
<Value>RunOnce</Value>
</Value>
<Value name="18">
<Value>TableError</Value>
</Value>
</Data>
<DataLocation>^PivotSubscriptions.EventLogD</DataLocation>
<DefaultData>EventLogDefaultData</DefaultData>
Expand Down
12 changes: 6 additions & 6 deletions PivotSubscriptions/Subscription.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ Parameter DEFAULTGLOBAL = "^PivotSubscriptions.Sub";

Property CreatedBy As %String;

Property Pivot As %String(MAXLEN = "");
Property Pivot As %String(MAXLEN = "") [ Required ];

Property DayOfWeek As %String;
Property DayOfWeek As %String [ Required ];

Property Hour As %Integer(MAXVAL = 23, MINVAL = 0);
Property Hour As %Integer(MAXVAL = 23, MINVAL = 0) [ Required ];

Property Minute As %Integer(VALUELIST = ",0,15,30,45");
Property Minute As %Integer(VALUELIST = ",0,15,30,45") [ Required ];

Property Format As %String(VALUELIST = ",Excel,PDF");

Property Emails As %String(MAXLEN = "");
Property Emails As %String(MAXLEN = "") [ Required ];

Property Version As %String [ InitialExpression = {##class(PivotSubscriptions.Utils).GetVersion()} ];

Property Name As %String(MAXLEN = 100);
Property Name As %String(MAXLEN = 100) [ Required ];

Property CustomFilters As array Of %String(MAXLEN = "");

Expand Down
14 changes: 11 additions & 3 deletions PivotSubscriptions/Task.cls
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ ClassMethod SendEmail(pID, pSendNow As %Boolean = 0, pPivot As %String, pEmails
Set mdx=##class(%DeepSee.Utils).%GetMDXFromPivot(pPivot,.tSC,0)
Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pID)

Set tErrorTypes=##class(PivotSubscriptions.Utils).GetSettings("ErrorTypes")

// Iterate through all subscribers and send emails to each individually
For tCount=1:1:$l(pEmails,",") {
Set tEmail=$p(pEmails,",",tCount)

Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent(tEventType,pID,$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,tSubscription.RunOnce,.pEvent)
If $$$ISERR(tSC) Quit tSC
If $$$ISERR(tSC) Quit

Try {
Set tHasResults=0
Expand Down Expand Up @@ -126,7 +128,9 @@ ClassMethod SendEmail(pID, pSendNow As %Boolean = 0, pPivot As %String, pEmails
} ElseIf 'tableStatus {
// Check if both configuration settings for admin email is valid before sending error message
If validAdminEmail {
Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"TooLarge",mdx,tCustomFilter)
Set tReason="TooLarge"
Do:tErrorTypes[1 ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,tReason,mdx,tCustomFilter)
Set pEvent.TableError=$$$ERROR($$$GeneralError,tReason)
}
}

Expand All @@ -138,7 +142,11 @@ ClassMethod SendEmail(pID, pSendNow As %Boolean = 0, pPivot As %String, pEmails
Do ##class(PivotSubscriptions.Utils).WriteUnsubscribe(msg,tUnsubscribeList)
Do ##class(PivotSubscriptions.Utils).WriteEmailFooter(msg)

Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"NoResults",mdx,tCustomFilter)
If validAdminEmail {
Set tReason="NoResults"
Do:tErrorTypes[0 ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,tReason,mdx,tCustomFilter)
Set pEvent.TableError=$$$ERROR($$$GeneralError,tReason)
}
}

// Send email
Expand Down
18 changes: 15 additions & 3 deletions PivotSubscriptions/UI/ConfigurationPage.cls
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ XData contentPane [ XMLNamespace = "http://www.intersystems.com/zen" ]
<label label="Custom Emails" labelClass="sectionCaption" containerStyle="padding-top:5px;padding-bottom:5px;" />
<radioSet id="CustomFooter" label="Custom Footer" displayList="Yes,No" valueList="1,0" value="0"/>
<textarea id="CustomFooterMessage" label="Custom Footer Message" cols="50" rows="3" value="PivotSubcriptions for InterSystems IRIS Business Intelligence" />
<label label="Error Emails" labelClass="sectionCaption" containerStyle="padding-top:5px;padding-bottom:5px;" />
<radioSet id="ChangesOnly" label="New Errors Only" displayList="Yes,No" valueList="1,0" value="0"/>
<multiSelectSet id="ErrorTypes" label="Optional Error Emails:" layout="horizontal" displayList="No Data,Too Large" valueList="0,1" value="0,1"/>
</vgroup>
</hgroup>
<hgroup>
Expand Down Expand Up @@ -79,6 +82,13 @@ Method %OnAfterCreatePage() As %Status
If $G(^PivotSubscriptions.Settings("CustomFooterMessage"))'="" {
Set ..%GetComponentById("CustomFooterMessage").value=^PivotSubscriptions.Settings("CustomFooterMessage")
}
If $G(^PivotSubscriptions.Settings("ChangesOnly"))'="" {
Set ..%GetComponentById("ChangesOnly").value=^PivotSubscriptions.Settings("ChangesOnly")
}
If $G(^PivotSubscriptions.Settings("ErrorTypes"))'="" {
Set ..%GetComponentById("ErrorTypes").value=^PivotSubscriptions.Settings("ErrorTypes")
}


Quit $$$OK
}
Expand All @@ -94,19 +104,21 @@ ClientMethod ButtonClick() [ Language = javascript ]
var nodatamessage=zen('NoDataMessage').getValue();
var customfooter=zen('CustomFooter').getValue();
var customfootermessage=zen('CustomFooterMessage').getValue();
var changesonly=zen('ChangesOnly').getValue();
var errortypes=zen('ErrorTypes').getValue();

var status=zenPage.SaveConfiguration(adminemail,http,server,port,nodataemail,nodatamessage,customfooter,customfootermessage);
var status=zenPage.SaveConfiguration(adminemail,http,server,port,nodataemail,nodatamessage,customfooter,customfootermessage,changesonly,errortypes);
}
catch(ex) {
zenExceptionHandler(ex,arguments);
}
}

Method SaveConfiguration(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage, pCustomFooter, pCustomFooterMessage) As %Status [ ZenMethod ]
Method SaveConfiguration(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage, pCustomFooter, pCustomFooterMessage, pChangesOnly, pErrorTypes) As %Status [ ZenMethod ]
{
Set tSC=$$$OK

Set tSC = ##class(PivotSubscriptions.Utils).ConfigureSettings(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage, pCustomFooter, pCustomFooterMessage)
Set tSC = ##class(PivotSubscriptions.Utils).ConfigureSettings(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage, pCustomFooter, pCustomFooterMessage, pChangesOnly, pErrorTypes)

Quit tSC
}
Expand Down
26 changes: 23 additions & 3 deletions PivotSubscriptions/UI/Dialog/EditSubscription.cls
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ XData dialogBody [ XMLNamespace = "http://www.intersystems.com/zen" ]
<select id="Preset" label="Preset Schedules" displayList="Weekdays,Weekends,Twice Weekly,Three Times Weekly" valueList="0,1,2,3" onchange="zenPage.updateSchedule();"/>
<multiSelectSet id="DayOfWeek" label="Day(s) Of Week" layout="horizontal" displayList="Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday" valueList="0,1,2,3,4,5,6"/>
<hgroup>
<select id="Hour" label="Hour" displayList="00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23" valueList="0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23"/>
<select id="Minute" label="Minute" displayList="00,15,30,45" valueList="0,15,30,45"/>
<select id="Hour" label="Hour" displayList="00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23" valueList="0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23" value="12"/>
<select id="Minute" label="Minute" displayList="00,15,30,45" valueList="0,15,30,45" value="0"/>
</hgroup>
<radioSet id="Format" label="Format" displayList="Excel,PDF" valueList="Excel,PDF" value="Excel"/>
<textarea id="Emails" label="Email Addresses (Comma separated list)" cols="50" rows="2" onchange="zenPage.populateEmailList();"/>
Expand Down Expand Up @@ -140,12 +140,32 @@ ClientMethod ondialogFinish(action) As %Boolean [ Language = javascript ]
{
try {
var subscriptionid=zen('SubscriptionId').getValue();
var name=zen('SubscriptionName').getValue();
if (name=="") {
alert($$$Text('Please enter a subscription name.'));
return false;
}
var dayofweek=zen('DayOfWeek').getValue();
if (dayofweek=="") {
alert($$$Text('Please select at least 1 day of week.'));
return false;
}
var hour=zen('Hour').getValue();
if (hour=="") {
alert($$$Text('Please select an hour.'));
return false;
}
var minute=zen('Minute').getValue();
if (minute=="") {
alert($$$Text('Please select a minute.'));
return false;
}
var format=zen('Format').getValue();
var emails=zen('Emails').getValue();
var name=zen('SubscriptionName').getValue();
if (emails=="") {
alert($$$Text('Please enter at least 1 email.'));
return false;
}
var pivot=this.pivotName;
var emailtext=zen('CustomEmailText').getValue();
var runonce=zen('RunOnce').getValue();
Expand Down
4 changes: 4 additions & 0 deletions PivotSubscriptions/UI/Dialog/EventDetails.cls
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ ClassMethod DrawDetails(pEventId) As %Status
<td>Run Once</td>
<td>#(tEvent.RunOnce)#</td>
</tr>
<tr>
<td>Table Error</td>
<td>#(tEvent.TableError)#</td>
</tr>
<tr>
<td>Status</td>
<td>#($Select(tEvent.Status:"OK",1:$system.Status.GetErrorText(tEvent.Status)))#</td>
Expand Down
43 changes: 40 additions & 3 deletions PivotSubscriptions/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Class PivotSubscriptions.Utils

ClassMethod GetVersion() As %String
{
Quit "v1.6.0"
Quit "v1.7.0"
}

/// Utility method for saving and updating global variables
ClassMethod ConfigureSettings(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage, pCustomFooter, pCustomFooterMessage)
ClassMethod ConfigureSettings(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage, pCustomFooter, pCustomFooterMessage, pChangesOnly, pErrorTypes)
{
Set ^PivotSubscriptions.Settings("AdminEmail")=pAdminEmail
Set ^PivotSubscriptions.Settings("Http")=pHttp
Expand All @@ -17,6 +17,8 @@ ClassMethod ConfigureSettings(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail,
Set ^PivotSubscriptions.Settings("NoDataMessage")=pNoDataMessage
Set ^PivotSubscriptions.Settings("CustomFooter")=pCustomFooter
Set ^PivotSubscriptions.Settings("CustomFooterMessage")=pCustomFooterMessage
Set ^PivotSubscriptions.Settings("ChangesOnly")=pChangesOnly
Set ^PivotSubscriptions.Settings("ErrorTypes")=pErrorTypes

Quit $$$OK
}
Expand Down Expand Up @@ -152,6 +154,12 @@ ClassMethod WriteEmail(pSubscription As PivotSubscriptions.Subscription, pMsg As

// check subscription to see if its table has error status
If pTableStatus {
// Include link to view in Analyzer
Set tSC=##class(PivotSubscriptions.Utils).GenerateLink(.tAnalyzerURL)
If $$$ISERR(tSC) Quit
Set tAnalyzerURL=tAnalyzerURL_$system.CSP.GetDefaultApp($namespace)_"/_DeepSee.UI.Analyzer.zen?PIVOT="_pSubscription.Pivot
Do pMsg.TextData.WriteLine("<a href='"_tAnalyzerURL_"'>Click Here</a> to view the pivot table in your browser.")

// Include Subscription's custom email text
If pSubscription.CustomEmailText'="" {
Do pMsg.TextData.WriteLine(pSubscription.CustomEmailText)
Expand Down Expand Up @@ -192,10 +200,19 @@ ClassMethod WriteEmail(pSubscription As PivotSubscriptions.Subscription, pMsg As

ClassMethod TableErrorMessage(pSubscription As PivotSubscriptions.Subscription, pEmail As %String, pName As %String, pReason As %String, pMDX As %String, pCustomFilter As %String = "") As %Status
{
Set tSC=$$$OK

Set tAdminEmail=##class(PivotSubscriptions.Utils).GetSettings("AdminEmail")
Set tLog=##class(PivotSubscriptions.EventLog).CreateEvent("tableError",pSubscription.%Id(),$username,pSubscription.Pivot,pSubscription.DayOfWeek,pSubscription.Hour,pSubscription.Minute,pSubscription.Format,tAdminEmail,pName,pSubscription.RunOnce,.pEvent)

If $$$ISERR(tLog) Quit tLog

Set tSC=##class(PivotSubscriptions.Utils).LastSubscriptionStatus(.tLastStatus,pName,pEmail)
If $$$ISERR(tSC) Quit tSC
If ##class(PivotSubscriptions.Utils).GetSettings("ChangesOnly") && $$$ISERR(tLastStatus) {
Set tSC=pEvent.UpdateStatus($$$ERROR($$$GeneralError,"StatusNotChanged"))
Quit tSC
}

// Generate email
Set tServer=##class(%Net.SMTP).%New()
Expand All @@ -216,7 +233,13 @@ ClassMethod TableErrorMessage(pSubscription As PivotSubscriptions.Subscription,
} ElseIf pReason="TooLarge" {
Do tMsg.TextData.WriteLine("The pivot table is too large to be embedded.<br>")
}
Do tMsg.TextData.WriteLine("<br>Please check the <i>Subscription Manager</i>.")

// Generate Event Log Viewer URL
Set tSC=##class(PivotSubscriptions.Utils).GenerateLink(.tEventLogURL)
If $$$ISERR(tSC) Quit
Set tEventLogURL=tEventLogURL_$system.CSP.GetDefaultApp($namespace)_"/PivotSubscriptions.UI.EventLogViewer.zen"

Do tMsg.TextData.WriteLine("<br>Please check the <a href='"_tEventLogURL_"'>Event Log Viewer</a>.")
Do tMsg.TextData.WriteLine("<br/><br/>MDX Executed:")
Do tMsg.TextData.WriteLine(pMDX)
If pCustomFilter'="" {
Expand Down Expand Up @@ -245,6 +268,20 @@ ClassMethod ActionCommand(ByRef pContext As %ZEN.proxyObject) As %String
Quit tCommand
}

ClassMethod LastSubscriptionStatus(ByRef pLastStatus, pName, pEmail) As %Status
{
Set tSC=$$$OK
Set pLastStatus=$$$OK

Set tSQL="SELECT TableError From PivotSubscriptions.EventLog WHERE Name=? AND Emails=? AND ((EventType='sendSubscription') OR (EventType='sendNow')) ORDER BY ID Desc"
Set tSQLRS=##class(%SQL.Statement).%ExecDirect(,tSQL,pName,pEmail)
Do tSQLRS.%Next()
Do tSQLRS.%Next()
Set pLastStatus=tSQLRS.TableError

Quit tSC
}

ClassMethod ExecuteForSubscription(pMDX, pCustomFilter = "", ByRef pHasResults = 0) As %Status
{
Set tSC=$$$OK
Expand Down

0 comments on commit 0b95545

Please sign in to comment.