Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6113 exports to links #6138

Merged
merged 20 commits into from
Jul 25, 2023
Merged
4 changes: 2 additions & 2 deletions sirepo/package_data/static/html/simulations.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
<li data-ng-if="! item.isFolder"><a href data-ng-click="simulations.copyItem(item)"><span class="glyphicon glyphicon-duplicate sr-nav-icon"></span> Open as a New Copy</a></li>
<li data-ng-if="! simulations.fileManager.isItemExample(item)"><a href data-ng-click="simulations.renameItem(item)"><span class="glyphicon glyphicon-edit sr-nav-icon"></span> Rename</a></li>
<li data-ng-if="! simulations.fileManager.isItemExample(item)"><a href data-ng-click="simulations.moveItem(item)"><span class="glyphicon glyphicon-arrow-right sr-nav-icon"></span> Move</a></li>
<li data-ng-if="item.canExport"><a href data-ng-click="simulations.exportArchive(item, 'zip')"><span class="glyphicon glyphicon-save-file sr-nav-icon"></span> Export as Zip</a></li>
<li data-ng-if="! item.isFolder && simulations.canDownloadInputFile()"><a href data-ng-click="simulations.pythonSource(item)"><span class="glyphicon glyphicon-cloud-download sr-nav-icon"></span> {{ simulations.stringsService.formatKey('simulationSource') }}</a></li>
<li data-ng-if="item.canExport"><a data-ng-href="{{ simulations.exportArchiveUrl(item, 'zip') }}"><span class="glyphicon glyphicon-save-file sr-nav-icon"></span> Export as Zip</a></li>
<li data-ng-if="! item.isFolder && simulations.canDownloadInputFile()"><a data-ng-href="{{ simulations.pythonSourceUrl(item) }}"><span class="glyphicon glyphicon-cloud-download sr-nav-icon"></span> {{ simulations.stringsService.formatKey('simulationSource') }}</a></li>
<li data-ng-if="simulations.canDelete(item)" class="divider"></li>
<li data-ng-if="simulations.canDelete(item)"><a href data-ng-click="simulations.deleteItem(item)"><span class="glyphicon glyphicon-trash"></span> Delete</a></li>
</ul>
Expand Down
21 changes: 11 additions & 10 deletions sirepo/package_data/static/js/radia.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ SIREPO.app.directive('appHeader', function(activeSection, appState, panelState,
</div>
</app-header-right-sim-loaded>
<app-settings>
<li><a href data-ng-click="exportDmp()"><span class="glyphicon glyphicon-cloud-download"></span> Export Radia Dump</a></li>
<li><a data-ng-href="{{ exportDmpUrl() }}"><span class="glyphicon glyphicon-cloud-download"></span> Export Radia Dump</a></li>
</app-settings>
<app-header-right-sim-list>
<ul class="nav navbar-nav sr-navbar-right">
Expand All @@ -982,17 +982,18 @@ SIREPO.app.directive('appHeader', function(activeSection, appState, panelState,
</div>
`,
controller: function($scope) {
$scope.exportDmp = function() {
requestSender.newWindow('exportArchive', {
'<simulation_id>': appState.models.simulation.simulationId,
'<simulation_type>': SIREPO.APP_SCHEMA.simulationType,
'<filename>': $scope.nav.simulationName() + '.dat',
});
};
$scope.showImportModal = function() {

$scope.exportDmpUrl = () => appState.isLoaded() ?
panelState.exportArchiveUrl($scope.simulationId(), `${$scope.nav.simulationName()}.dat`) :
null;

$scope.isImported = () => (appState.models.simulation || {}).dmpImportFile;

$scope.showImportModal = () => {
$('#simulation-import').modal('show');
};
$scope.isImported = () => (appState.models.simulation || {}).dmpImportFile;

$scope.simulationId = () => appState.isLoaded() ? appState.models.simulation.simulationId : null;
}
};
});
Expand Down
44 changes: 17 additions & 27 deletions sirepo/package_data/static/js/sirepo-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,15 @@ SIREPO.app.directive('exportPythonLink', function(appState, panelState) {
reportTitle: '@',
},
template: `
<a href data-ng-click="exportPython()">Export Python Code</a>
<a data-ng-href="{{ exportPythonUrl() }}">Export Python Code</a>
`,
controller: function($scope) {
$scope.exportPython = function() {
panelState.pythonSource(
$scope.exportPythonUrl = () => {
return panelState.pythonSourceUrl(
appState.models.simulation.simulationId,
panelState.findParentAttribute($scope, 'modelKey'),
$scope.reportTitle);
$scope.reportTitle
);
};
},
};
Expand Down Expand Up @@ -2713,16 +2714,16 @@ SIREPO.app.directive('settingsMenu', function(appDataService, appState, fileMana
<ul class="dropdown-menu">
<li class="sr-settings-submenu" data-ng-transclude="appSettingsSlot"></li>
<li><a href data-ng-if="nav.modeIsDefault() && canShowDocumentationUrl()" data-ng-click="showDocumentationUrl()"><span class="glyphicon glyphicon-book"></span> Simulation Documentation URL</a></li>
<li><a href data-ng-if="::canExportArchive()" data-ng-click="exportArchive(\'zip\')"><span class="glyphicon glyphicon-cloud-download"></span> Export as ZIP</a></li>
<li data-ng-if="::canDownloadInputFile()"><a href data-ng-click="pythonSource()"><span class="glyphicon glyphicon-cloud-download sr-nav-icon"></span> {{ ::stringsService.formatKey(\'simulationSource\') }}</a></li>
<li data-ng-if="::canExportJupyter()"><a href data-ng-click="exportJupyterNotebook()"><span class="glyphicon glyphicon-cloud-download sr-nav-icon"></span> Export as Jupyter Notebook</a></li>
<li data-ng-if="::canExportMadx()" ><a href data-ng-click="pythonSource(\'madx\')"><span class="glyphicon glyphicon-cloud-download sr-nav-icon"></span> Export as MAD-X lattice</a></li>
<li><a href data-ng-if="::canExportArchive()" data-ng-href="{{ exportArchiveUrl('zip') }}"><span class="glyphicon glyphicon-cloud-download"></span> Export as ZIP</a></li>
<li data-ng-if="::canDownloadInputFile()"><a data-ng-href="{{ pythonSourceUrl() }}"><span class="glyphicon glyphicon-cloud-download sr-nav-icon"></span> {{ ::stringsService.formatKey('simulationSource') }}</a></li>
<li data-ng-if="::canExportJupyter()"><a data-ng-href="{{ exportJupyterNotebookUrl() }}"><span class="glyphicon glyphicon-cloud-download sr-nav-icon"></span> Export as Jupyter Notebook</a></li>
<li data-ng-if="::canExportMadx()" ><a data-ng-href="{{ pythonSourceUrl('madx') }}"><span class="glyphicon glyphicon-cloud-download sr-nav-icon"></span> Export as MAD-X lattice</a></li>
<li data-ng-if="canCopy()"><a href data-ng-click="copyItem()"><span class="glyphicon glyphicon-copy"></span> Open as a New Copy</a></li>
<li data-ng-if="isExample()"><a href data-target="#reset-confirmation" data-toggle="modal"><span class="glyphicon glyphicon-repeat"></span> Discard Changes to Example</a></li>
<li data-ng-if="! isExample()"><a href data-target="#delete-confirmation" data-toggle="modal"><span class="glyphicon glyphicon-trash"></span> Delete</a></li>
<li data-ng-if="hasRelatedSimulations()" class="divider"></li>
<li data-ng-if="hasRelatedSimulations()" class="sr-dropdown-submenu">
<a href><span class="glyphicon glyphicon-menu-left"></span> Related {{ ::stringsService.formatKey(\'simulationDataTypePlural\') }}</a>
<a href><span class="glyphicon glyphicon-menu-left"></span> Related {{ ::stringsService.formatKey('simulationDataTypePlural') }}</a>
<ul class="dropdown-menu">
<li data-ng-repeat="item in relatedSimulations"><a href data-ng-click="openRelatedSimulation(item)">{{ item.name }}</a></li>
</ul>
Expand Down Expand Up @@ -2766,15 +2767,12 @@ SIREPO.app.directive('settingsMenu', function(appDataService, appState, fileMana
return SIREPO.APP_SCHEMA.constants.hasJupyterExport;
};

$scope.exportJupyterNotebook = function(modelName) {
panelState.exportJupyterNotebook($scope.simulationId(), modelName);
$scope.exportArchiveUrl = extension => {
return panelState.exportArchiveUrl($scope.simulationId(), `${$scope.nav.simulationName()}.${extension}`);
};

$scope.simulationId = function () {
if (appState.isLoaded()) {
return appState.models.simulation.simulationId;
}
return null;
$scope.exportJupyterNotebookUrl = function(modelName) {
return panelState.exportJupyterNotebookUrl($scope.simulationId(), modelName);
};

$scope.copyFolder = fileManager.defaultCreationFolderPath();
Expand All @@ -2783,9 +2781,9 @@ SIREPO.app.directive('settingsMenu', function(appDataService, appState, fileMana
panelState.showModalEditor('simDoc');
};

$scope.pythonSource = function(modelName) {
panelState.pythonSource($scope.simulationId(), modelName);
};
$scope.simulationId = () => appState.isLoaded() ? appState.models.simulation.simulationId : null;

$scope.pythonSourceUrl = modelName => panelState.pythonSourceUrl($scope.simulationId(), modelName);

$scope.relatedSimulations = [];

Expand Down Expand Up @@ -2862,14 +2860,6 @@ SIREPO.app.directive('settingsMenu', function(appDataService, appState, fileMana
requestSender.localRedirectHome(item.simulationId);
};

$scope.exportArchive = function(extension) {
requestSender.newWindow('exportArchive', {
'<simulation_id>': $scope.simulationId(),
'<simulation_type>': SIREPO.APP_SCHEMA.simulationType,
'<filename>': $scope.nav.simulationName() + '.' + extension,
});
};

$scope.$on('simulationUnloaded', function() {
$scope.doneLoadingSimList = false;
});
Expand Down
65 changes: 35 additions & 30 deletions sirepo/package_data/static/js/sirepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,17 @@ SIREPO.app.factory('panelState', function(appState, requestSender, simulationQue
}
}

function urlForExport(simulationId, route, args) {
if (! simulationId) {
return null;
}
const a = {
'<simulation_id>': simulationId,
'<simulation_type>': SIREPO.APP_SCHEMA.simulationType,
};
return requestSender.formatUrl(route, {...a, ...args});
}

self.addPendingRequest = function(name, requestFunction) {
pendingRequests[name] = requestFunction;
};
Expand Down Expand Up @@ -1654,6 +1665,23 @@ SIREPO.app.factory('panelState', function(appState, requestSender, simulationQue
applyToFields('enableField', model, fieldInfo);
};

self.exportArchiveUrl = (simulationId, filename) => {
return urlForExport(simulationId, 'exportArchive', {
'<filename>': filename,
});
};

self.exportJupyterNotebookUrl = (simulationId, modelName, reportTitle) => {
const args = {};
if (modelName) {
args['<model>'] = modelName;
}
if (reportTitle) {
args['<title>'] = reportTitle;
}
return urlForExport(simulationId, 'exportJupyterNotebook', args);
};

// lazy creation/storage of field delegates
self.fieldDelegates = {};

Expand Down Expand Up @@ -1749,20 +1777,6 @@ SIREPO.app.factory('panelState', function(appState, requestSender, simulationQue
return queueItems[name] && queueItems[name].qState == 'processing' ? true : false;
};

self.exportJupyterNotebook = function(simulationId, modelName, reportTitle) {
var args = {
'<simulation_id>': simulationId,
'<simulation_type>': SIREPO.APP_SCHEMA.simulationType,
};
if (modelName) {
args['<model>'] = modelName;
}
if (reportTitle) {
args['<title>'] = reportTitle;
}
requestSender.newWindow('exportJupyterNotebook', args);
};

self.maybeSetState = function(model, state) {
if (!model) {
return;
Expand All @@ -1779,18 +1793,15 @@ SIREPO.app.factory('panelState', function(appState, requestSender, simulationQue
return 'sr-' + name + '-editor';
};

self.pythonSource = function(simulationId, modelName, reportTitle) {
var args = {
'<simulation_id>': simulationId,
'<simulation_type>': SIREPO.APP_SCHEMA.simulationType,
};
self.pythonSourceUrl = (simulationId, modelName, reportTitle) => {
const args = {};
if (modelName) {
args['<model>'] = modelName;
}
if (reportTitle) {
args['<title>'] = reportTitle;
}
requestSender.newWindow('pythonSource', args);
return urlForExport(simulationId, 'pythonSource', args);
};

self.reportNotGenerated = function(modelName) {
Expand Down Expand Up @@ -3953,18 +3964,12 @@ SIREPO.app.controller('SimulationsController', function (appState, cookieService
return fileManager.pathName(folder);
};

self.pythonSource = function(item) {
panelState.pythonSource(item.simulationId);
self.pythonSourceUrl = function(item) {
return panelState.pythonSourceUrl(item.simulationId);
};

self.exportArchive = function(item, extension) {
requestSender.newWindow(
'exportArchive',
{
'<simulation_id>': item.simulationId,
'<simulation_type>': SIREPO.APP_SCHEMA.simulationType,
'<filename>': item.name + '.' + extension,
});
self.exportArchiveUrl = function(item, extension) {
return panelState.exportArchiveUrl(item.simulationId, `${item.name}.${extension}`);
};

self.renameItem = function(item) {
Expand Down