I have a popup that I want to close after clicking the import button and successfully importing records.
The popup is intended to work as follows:
def runAction(self, event):
logger = system.util.getLogger('state_export')
try:
params = { 'Type': 'states' }
system.perspective.openPopup("ImportFile", "GlobalComponents/Modals/ImportFile", params)
except Exception as e:
gpa.frontEnd.localUI.throwError(str(e))
- When the Import button in the window is clicked, the popup opens, receiving the 'ImportFile' ID and the 'states' parameter.
def runAction(self, event):
logger = system.util.getLogger('importFile')
system.perspective.print('testing import file')
try:
csvFile = self.parent.parent.getChild("FileUpload").custom.configCSV
csvDS = self.parent.parent.getChild("FileUpload").custom.csvDict
eqPath = self.view.params.EqPath
payload = { 'csvString': csvFile, 'csvDS': csvDS, 'EqPath': eqPath }
type_mapping = {
'states': 'importStates',
'modes': 'importModes',
'scrapCategory': 'importScrapCategory',
'scrapReasons': 'importScrapReasons',
'materials': 'importMaterials',
'sites': 'importSites',
'areas': 'importAreas',
'lines': 'importLines',
'cells': 'importCells',
'attributes': 'importAttributes',
'productcodes': 'importProductCodes'
}
messageType = str(type_mapping[str(self.view.params.Type)])
system.perspective.print(messageType)
if messageType:
system.perspective.sendMessage(messageType, payload)
self.parent.parent.getChild("FileUpload").custom.configCSV = ''
system.dataset.clearDataset(self.parent.parent.getChild("FileUpload").custom.csvDict)
except Exception as e:
logger.warn('There was an error: ' + str(e))
- When the user clicks the 'Import' button in the popup, the onClick event maps type_mapping['states'] to the 'importStates' message handler name and uses it as a parameter in system.perspective.sendMessage().
def onMessageReceived(self, payload):
logger = system.util.getLogger("insertStates_message")
try:
system.perspective.print('test')
csvString = payload.get("csvString")
csvDict = payload.get("csvDS")
pyData = system.dataset.toPyDataSet(csvDict)
existingData = system.dataset.toPyDataSet(self.view.custom.Data)
for row in pyData:
system.perspective.print(row["AltCode"])
if any(r["ReasonCode"] == row["ReasonCode"] and r["LineID"] == row["LineID"] for r in existingData):
# If the combination already exists, log and continue to the next row
logger.warn("Combination of ReasonCode {} and LineID {} already exists.".format(row["ReasonCode"], row["LineID"]))
continue
# If the combination doesn't exist, insert the new record
params = {
"AltCode": row["AltCode"],
"OperatorSelectable": row["OperatorSelectable"],
"SubReasonOf": row["SubReasonOf"],
"StateID": 0,
"LineID": self.view.params.ID,
"Description": row["Description"],
"DowntimeCategoryCode": row["DowntimeCategoryCode"],
"DisplayColor": row["DisplayColor"],
"PlannedDowntime": row["PlannedDowntime"],
"ReasonCode": row["ReasonCode"],
"RecordDowntime": row["RecordDowntime"],
"IconPath": row["IconPath"],
"StateTypeID": row["StateTypeID"]
}
system.perspective.print(params)
gpa.frontEnd.localUI.throwSuccess("adding the line state")
res = mes.config.sp.addEditLineState(params)
gpa.frontEnd.localUI.throwSuccess("res = " + str(res))
if str(res) is not "Success":
raise ValueError('Sproc call failed for row {}. Result: {}'.format(row, str(res)))
system.perspective.sendMessage('refreshTree')
system.perspective.sendMessage('refreshStatesTable')
system.perspective.closePopup("ImportFile")
except Exception as e:
errorParams = {
"ModalName": "ErrorModal",
"ErrorMessage": str(e),
}
system.perspective.openPopup("ErrorModal", "GlobalComponents/Modals/ErrorModal", errorParams)
logger.warn('There was an error: ' + str(e))
- The
importStates
message handler executes a sproc call and closes the ImportFile popup.
The sproc seems to be executed, and the other sendMessage() commands seem to be executed, but the popup is not closing from the system.perspective.closePopup("ImportFile")
call. I'm not sure what could be causing this, but I'm certain the message handler is executing because the sproc is being executed, and the sproc is only referenced inside of this message handler and nowhere else.