Address reviewer feedback
This commit is contained in:
parent
a08a9cb593
commit
ab3fd49a8c
|
@ -136,7 +136,7 @@ end function
|
|||
sub clearScenes()
|
||||
if m.content <> invalid then m.content.removeChildrenIndex(m.content.getChildCount(), 0)
|
||||
for each group in m.groups
|
||||
if group.subtype() = "JFScreen"
|
||||
if LCase(group.subtype()) = "jfscreen"
|
||||
group.callFunc("OnScreenHidden")
|
||||
end if
|
||||
end for
|
||||
|
|
|
@ -23,8 +23,10 @@ sub loadLibraries()
|
|||
m.top.findNode("homeRows").callFunc("loadLibraries")
|
||||
end sub
|
||||
|
||||
' JFScreen hook that gets ran as needed.
|
||||
' Used to update the foces, the state of the data, and tells the server about the device profile
|
||||
sub OnScreenShown()
|
||||
if m.top.lastFocus <> invalid
|
||||
if isValid(m.top.lastFocus)
|
||||
m.top.lastFocus.setFocus(true)
|
||||
else
|
||||
m.top.setFocus(true)
|
||||
|
@ -42,6 +44,8 @@ sub OnScreenShown()
|
|||
end if
|
||||
end sub
|
||||
|
||||
' Triggered by m.postTask after completing a post.
|
||||
' Empty the task data when finished.
|
||||
sub postFinished()
|
||||
m.postTask.unobserveField("responseCode")
|
||||
m.postTask.callFunc("empty")
|
||||
|
|
|
@ -205,15 +205,18 @@ sub radioSettingChanged()
|
|||
set_user_setting(selectedSetting.settingName, m.radioSetting.content.getChild(m.radioSetting.checkedItem).id)
|
||||
end sub
|
||||
|
||||
' JFScreen hook that gets ran as needed.
|
||||
' Assumes settings were changed and they affect the device profile.
|
||||
' Posts a new device profile to the server using the task thread
|
||||
sub OnScreenHidden()
|
||||
' some settings affect the device profile.
|
||||
' assume there were changes and always post device profile when leaving the settings screen
|
||||
m.postTask.arrayData = getDeviceCapabilities()
|
||||
m.postTask.apiUrl = "/Sessions/Capabilities/Full"
|
||||
m.postTask.control = "RUN"
|
||||
m.postTask.observeField("responseCode", "postFinished")
|
||||
end sub
|
||||
|
||||
' Triggered by m.postTask after completing a post.
|
||||
' Empty the task data when finished.
|
||||
sub postFinished()
|
||||
m.postTask.unobserveField("responseCode")
|
||||
m.postTask.callFunc("empty")
|
||||
|
|
|
@ -1,30 +1,35 @@
|
|||
import "pkg:/source/api/baserequest.brs"
|
||||
import "pkg:/source/utils/misc.brs"
|
||||
|
||||
sub init()
|
||||
m.top.functionName = "postItems"
|
||||
end sub
|
||||
|
||||
' Main function for PostTask.
|
||||
' Posts either an array of data
|
||||
' or a string of data to an API endpoint.
|
||||
' Saves the response information
|
||||
sub postItems()
|
||||
if m.top.apiUrl <> ""
|
||||
if m.top.arrayData.count() > 0 and m.top.stringData = ""
|
||||
print "PostTask Started - Posting array to " + m.top.apiUrl
|
||||
req = APIRequest(m.top.apiUrl)
|
||||
req.SetRequest("POST")
|
||||
httpResponse = asyncPost(req, FormatJson(m.top.arrayData))
|
||||
m.top.responseCode = httpResponse
|
||||
print "PostTask Finished. " + m.top.apiUrl + " Response = " + httpResponse.toStr()
|
||||
else if m.top.arrayData.count() = 0 and m.top.stringData <> ""
|
||||
print "PostTask Started - Posting string(" + m.top.stringData + ") to " + m.top.apiUrl
|
||||
req = APIRequest(m.top.apiUrl)
|
||||
req.SetRequest("POST")
|
||||
httpResponse = asyncPost(req, m.top.stringData)
|
||||
m.top.responseCode = httpResponse
|
||||
print "PostTask Finished. " + m.top.apiUrl + " Response = " + httpResponse.toStr()
|
||||
else
|
||||
print "ERROR processing data for PostTask"
|
||||
end if
|
||||
else
|
||||
if m.top.apiUrl = ""
|
||||
print "ERROR in PostTask. Invalid API URL provided"
|
||||
return
|
||||
end if
|
||||
if m.top.arrayData.count() > 0 and m.top.stringData = ""
|
||||
print "PostTask Started - Posting array to " + m.top.apiUrl
|
||||
req = APIRequest(m.top.apiUrl)
|
||||
req.SetRequest("POST")
|
||||
httpResponse = asyncPost(req, FormatJson(m.top.arrayData))
|
||||
m.top.responseCode = httpResponse
|
||||
print "PostTask Finished. " + m.top.apiUrl + " Response = " + httpResponse.toStr()
|
||||
else if m.top.arrayData.count() = 0 and m.top.stringData <> ""
|
||||
print "PostTask Started - Posting string(" + m.top.stringData + ") to " + m.top.apiUrl
|
||||
req = APIRequest(m.top.apiUrl)
|
||||
req.SetRequest("POST")
|
||||
httpResponse = asyncPost(req, m.top.stringData)
|
||||
m.top.responseCode = httpResponse
|
||||
print "PostTask Finished. " + m.top.apiUrl + " Response = " + httpResponse.toStr()
|
||||
else
|
||||
print "ERROR processing data for PostTask"
|
||||
end if
|
||||
end sub
|
||||
|
||||
|
@ -41,7 +46,7 @@ function asyncPost(req, data = "" as string) as integer
|
|||
resp = wait(m.top.timeoutSeconds * 1000, req.GetMessagePort())
|
||||
|
||||
respString = resp.GetString()
|
||||
if respString <> invalid and respString <> ""
|
||||
if isValidAndNotEmpty(respString)
|
||||
m.top.responseBody = ParseJson(respString)
|
||||
print "m.top.responseBody=", m.top.responseBody
|
||||
end if
|
||||
|
|
Loading…
Reference in New Issue
Block a user