Skip to content

Commit

Permalink
Merge pull request IDEMSInternational#8929 from N-thony/script_output
Browse files Browse the repository at this point in the history
Completing the feature of having the multiple tables (html) in output window
  • Loading branch information
conlooptechnologies authored May 21, 2024
2 parents 36408d1 + d6146ad commit f5fc35a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 66 deletions.
69 changes: 34 additions & 35 deletions instat/Model/Output/clsOutputLogger.vb
Original file line number Diff line number Diff line change
Expand Up @@ -71,52 +71,51 @@ Public Class clsOutputLogger
End Property

Public Sub AddOutput(strScript As String, strOutput As String, bAsFile As Boolean, bDisplayOutputInExternalViewer As Boolean)
'Note this always takes the last script added as corresponding script
' Note this always takes the last script added as corresponding script
If String.IsNullOrWhiteSpace(strScript) Then
Throw New Exception("Cannot find script to attach output to.")
Exit Sub
End If

'add the R script as an output element
' Add the R script as an output element
Dim rScriptElement As New clsOutputElement
rScriptElement.SetContent(strScript, OutputType.Script, "")
_outputElements.Add(rScriptElement)
'raise event for output pages
' Raise event for output pages
RaiseEvent NewOutputAdded(rScriptElement, False)


If Not String.IsNullOrEmpty(strOutput) Then
Dim outputElement As New clsOutputElement
Dim outputType As OutputType
If bAsFile Then
Dim strFileExtension As String = Path.GetExtension(strOutput).ToLower
Select Case strFileExtension
Case ".png"
outputType = OutputType.ImageOutput
Case ".html"
outputType = OutputType.HtmlOutput
Case ".txt"
outputType = OutputType.TextOutput
Case Else
MessageBox.Show("The file type to be added is currently not suported",
"Developer Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End Select
Else
outputType = OutputType.TextOutput
' Split the strOutput into an array of lines, removing empty entries
Dim arrFilesPaths() As String = strOutput.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

For Each output In arrFilesPaths
If Not String.IsNullOrEmpty(output) Then
Dim outputElement As New clsOutputElement
Dim outputType As OutputType

If bAsFile Then
Dim strFileExtension As String = Path.GetExtension(output).ToLower
Select Case strFileExtension
Case ".png"
outputType = OutputType.ImageOutput
Case ".html"
outputType = OutputType.HtmlOutput
Case ".txt"
outputType = OutputType.TextOutput
Case Else
MessageBox.Show("The file type to be added is currently not supported", "Developer Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Select
Else
outputType = OutputType.TextOutput
End If

' Add the output with its R script as another output element
outputElement.SetContent("", outputType, output)
_outputElements.Add(outputElement)
' Raise event for output pages
RaiseEvent NewOutputAdded(outputElement, bDisplayOutputInExternalViewer)
End If

'add the output with it's R script as another output element
outputElement.SetContent("", outputType, strOutput)
_outputElements.Add(outputElement)
'raise event for output pages
RaiseEvent NewOutputAdded(outputElement, bDisplayOutputInExternalViewer)

End If


Next

End Sub

Expand Down
35 changes: 4 additions & 31 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -749,22 +749,9 @@ Public Class RLink
bShowWaitDialogOverride:=Nothing)
End If

' Split the strOutput into an array of lines, removing empty entries
Dim arrFilesPaths() As String = strOutput.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

' Check if arrFilesPaths has at least one element before iterating
If arrFilesPaths.Length > 0 Then
' Iterate through each file path
For Each _path In arrFilesPaths
' Add output to logger
clsOutputLogger.AddOutput(clsRStatement.Text, _path, bAsFile:=True,
' Add output to logger
clsOutputLogger.AddOutput(clsRStatement.Text, strOutput, bAsFile:=True,
bDisplayOutputInExternalViewer:=clsRStatement.TextNoFormatting.StartsWith("view_object_data"))
Next
Else
' Add output to logger
clsOutputLogger.AddOutput(clsRStatement.Text, strOutput, bAsFile:=True,
bDisplayOutputInExternalViewer:=clsRStatement.TextNoFormatting.StartsWith("view_object_data"))
End If

' Log the script
LogScript(clsRStatement.Text.TrimEnd(vbCr, vbLf))
Expand Down Expand Up @@ -1012,22 +999,8 @@ Public Class RLink
End If
End If

If bAsFile Then
' Split the strOutput into an array of lines, removing empty entries
Dim arrFilesPaths() As String = strOutput.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
' Iterate through each HTML files
For Each _path In arrFilesPaths
' Add each HTML file as an output to clsOutputLogger
' strScriptWithComment: the script with associated comments
' _path: the path to the HTML file
' bAsFile: a boolean indicating whether the output should be treated as a file
' bDisplayOutputInExternalViewer: a boolean indicating whether to display the output in an external viewer
clsOutputLogger.AddOutput(strScriptWithComment, _path, bAsFile, bDisplayOutputInExternalViewer)
Next
Else
' If strOutput is empty or does not contain valid HTML files, add strOutput itself as an output
clsOutputLogger.AddOutput(strScriptWithComment, strOutput, bAsFile, bDisplayOutputInExternalViewer)
End If
' If strOutput is empty or does not contain valid HTML files, add strOutput itself as an output
clsOutputLogger.AddOutput(strScriptWithComment, strOutput, bAsFile, bDisplayOutputInExternalViewer)


Catch e As Exception
Expand Down

0 comments on commit f5fc35a

Please sign in to comment.