From 0b7c1a5b671a9874b5e1b740eadac49f2a8ccd7f Mon Sep 17 00:00:00 2001 From: "J. Ritchie Carroll" Date: Mon, 2 Dec 2019 01:42:45 -0500 Subject: [PATCH] Added ability to import and export config --- .../wwwroot/AddSynchrophasorDeviceDev.cshtml | 198 +++++++++++++++--- 1 file changed, 166 insertions(+), 32 deletions(-) diff --git a/Source/Applications/openHistorian/openHistorian/wwwroot/AddSynchrophasorDeviceDev.cshtml b/Source/Applications/openHistorian/openHistorian/wwwroot/AddSynchrophasorDeviceDev.cshtml index e0b8e50c17..744a1cd1e5 100644 --- a/Source/Applications/openHistorian/openHistorian/wwwroot/AddSynchrophasorDeviceDev.cshtml +++ b/Source/Applications/openHistorian/openHistorian/wwwroot/AddSynchrophasorDeviceDev.cshtml @@ -1027,37 +1027,32 @@ } cell.serializeCell = function () { - var voltages = []; - var currents = []; - - self.voltages().forEach(function (voltage) { - voltages.push({ - id: voltage.ID, - label: voltage.Label(), - originalLabel: voltage.OriginalLabel, - phase: voltage.Phase(), - nominalVoltage: voltage.NominalVoltage(), - enabled: voltage.Enabled() - }); - }); - - self.currents().forEach(function (current) { - currents.push({ - id: current.ID, - label: current.Label(), - originalLabel: current.OriginalLabel, - phase: current.Phase(), - associatedVoltage: current.AssociatedVoltage(), - enabled: current.Enabled() + var phasorDefinitions = []; + + cell.PhasorDefinitions.forEach(function (phasorDefinition) { + const isVoltage = phasorDefinition.PhasorType.toLowerCase() === "voltage"; + + phasorDefinitions.push({ + ID: phasorDefinition.ID, + Label: phasorDefinition.Label(), + PhasorType: phasorDefinition.PhasorType, + Phase: phasorDefinition.Phase(), + DestinationPhasorID: isVoltage ? phasorDefinition.DestinationPhasorID : phasorDefinition.Current.AssociatedVoltage(), + NominalVoltage: isVoltage ? phasorDefinition.Voltage.NominalVoltage() : phasorDefinition.Current.AssociatedNominalVoltage(), + SourceIndex: phasorDefinition.SourceIndex }); }); return { - idLabel: cell.IDLabel(), - acronym: cell.Acronym, - originalAcronym: cell.OriginalAcronym(), - voltages: voltages, - currents: currents + ID: cell.ID, + ParentID: cell.ParentID, + IDCode: cell.IDCode, + StationName: self.configFrame().Cells.length === 1 ? self.deviceName() : cell.IDLabel(), + IDLabel: cell.IDLabel(), + FrequencyDefinition: cell.FrequencyDefinition, + PhasorDefinitions: phasorDefinitions, + AnalogDefinitions: cell.AnalogDefinitions, + DigitalDefinitions: cell.DigitalDefinitions }; }; } @@ -1324,7 +1319,8 @@ }; self.serializeConfiguration = function () { - const cells = self.configFrame().Cells; + const configFrame = self.configFrame(); + const cells = configFrame.Cells; var serializedCells = []; if (cells) { @@ -1334,10 +1330,63 @@ } return { - configuration: serializedCells + IDCode: configFrame.IDCode, + StationName: self.deviceName(), + IDLabel: self.deviceAcronym(), + FrameRate: configFrame.FrameRate, + ConnectionString: configFrame.ConnectionString, + ProtocolID: configFrame.ProtocolID, + Cells: serializedCells }; }; + self.saveConfiguration = function (fileName) { + const data = JSON.stringify(self.serializeConfiguration(), null, 2); + const anchor = $("#saveConfigurationFileLink"); + + if (typeof anchor[0].download != "undefined") { + anchor.attr("href", "data:text/json;charset=utf-8," + encodeURIComponent(data)); + anchor.attr("download", fileName); + anchor[0].click(); + } else { + if (isIE) + window.navigator.msSaveBlob(new Blob([data]), fileName); + else + window.open("data:text/json;charset=utf-8," + encodeURIComponent(data), "_blank", ""); + } + }; + + self.loadConfiguration = function (fileBlob) { + var reader = new FileReader(); + + reader.onload = function () { + if (!self.phasorHubIsConnected()) + return; + + const configFrame = JSON.parse(reader.result); + + self.voltages.removeAll(); + self.currents.removeAll(); + + $("#responsiveTableDiv").show(); + $("[id=voltageRow]").css("visibility", "hidden"); + $("[id=currentRow]").css("visibility", "hidden"); + $("#bulkSelectionButtons").hide(); + showLoadingLabel(); + + self.configFrameDetails("Loading..."); + + self.loadConfigFrame(configFrame); + } + + reader.onloadend = function () { + if (reader.error && reader.error.message) + showErrorMessage("Failed to load configuration: " + reader.error.message); + }; + + reader.readAsText(fileBlob); + }; + // Validations self.deviceAcronym.extend({ required: true, @@ -2989,6 +3038,24 @@ connectionStatusWindow.scrollTop(connectionStatusWindow[0].scrollHeight); } + function showSaveConfigurationFileNameDialog() { + $("#saveConfigurationFileNameDialog").toggle(); + + if ($("#saveConfigurationFileNameDialog").is(":visible")) { + $("#inputConfigurationFileName").val(viewModel.deviceAcronym() + ".json"); + $("#inputConfigurationFileName").focus(); + } + } + + function showLoadConfigurationFileNameDialog() { + $("#loadConfigurationFileName").trigger("click"); + } + + function loadConfigurationFile(event) { + viewModel.loadConfiguration(event.target.files[0]); + $("#loadConfigurationFileName").val(""); + } + // Page initialization function $(function () { $("#tabs").tabs({ @@ -3292,6 +3359,43 @@ $("#inputConfigFile").tooltip("hide"); }); + + // Setup save configuration file name dialog functionality + $("#saveConfigurationFile").click(function() { + $("#saveConfigurationFileNameDialog").hide(); + + var fileName = notNull($("#inputConfigurationFileName").val()); + + if (fileName.length === 0) + fileName = viewModel.deviceAcronym() + ".json"; + + if (!fileName.endsWith(".json")) + fileName += ".json"; + + viewModel.saveConfiguration(fileName); + }); + + // Make enter key auto-click save + $("#inputConfigurationFileName").keyup(function(event) { + if (event.keyCode === 13) + $("#saveConfigurationFile").click(); + }); + + // Auto-select all text on focus + $("#inputConifgurationFileName").focus(function() { + $(this).select(); + }); + + // Prevent default form submission when user presses enter + $("#saveConfigurationFileNameDialog").submit(function() { + return false; + }); + + // Auto-hide pop-up form when user clicks outside form area + $("#saveConfigurationFileNameDialog").focusout(function() { + if (!$("#saveConfigurationFileNameDialog").is(":hover") && !$("#saveConfigurationFileNameDialogButton").is(":hover")) + $("#saveConfigurationFileNameDialog").hide(); + }); resizePageElements(); @@ -3390,7 +3494,7 @@
-
+
@@ -3418,7 +3522,7 @@ {
} @@ -3439,6 +3543,28 @@
+ @if (userIsEditor) + { +
+ +
+
+
+
+ +
+ + + + +
+
+
+
+ + } @@ -3463,7 +3589,15 @@ - + @if (userIsEditor) + { +
+ +
+ + }