Skip to content

Download code view content #188

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

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions electron/app/js/ipcRendererPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ contextBridge.exposeInMainWorld(
send: (channel, ...args) => {
const validChannels = [
'close-window',
'download-file',
'new-project',
'open-project',
'window-app-quit',
Expand Down
28 changes: 28 additions & 0 deletions electron/app/js/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {getCredentialPassphrase} = require('./promptUtils');
const {copyFile, mkdir, readFile, writeFile} = require('fs/promises');
const path = require('path');
const uuid = require('uuid');
const { EOL } = require('os');

const model = require('./model');
const modelProperties = require('./modelProperties');
Expand Down Expand Up @@ -972,6 +973,32 @@ function getProjectFileName(dialogReturnedFileName) {
return result;
}

function downloadFile(targetWindow, lines, fileType, format, formatName) {
const title = i18n.t('dialog-saveTitle', {type: fileType});
const filterName = i18n.t('dialog-saveFilterLabel', {type: formatName});

dialog.showSaveDialog(targetWindow, {
title: title,
message: title,
filters: [
{name: filterName, extensions: [format]}
],
properties: [
'createDirectory',
'showOverwriteConfirmation'
]
}).then(saveResponse => {
if (saveResponse.filePath) {
const contents = lines.join(EOL);
writeFile(saveResponse.filePath, contents, { encoding: 'utf8' })
.catch(err => {
dialog.showErrorBox(title,
i18n.t('dialog-saveFileErrorMessage', { file: saveResponse.filePath, error: err }));
});
}
});
}

module.exports = {
chooseArchiveFile,
chooseModelFile,
Expand All @@ -980,6 +1007,7 @@ module.exports = {
closeProject,
confirmProjectFile,
createNewProject,
downloadFile,
getModelFileContent,
getWindowForProject,
exportArchiveFile,
Expand Down
3 changes: 3 additions & 0 deletions electron/app/locales/en/electron.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
"dialog-createNewProjectTitle": "Create WebLogic Kubernetes Toolkit Project",
"dialog-projectSaveFileLocationNotWritableTitle": "Project Directory Not Writable",
"dialog-projectSaveFileLocationNotWritableError": "The {{projectFileDirectory}} directory chosen to write the new project file is not writable by the current process.",
"dialog-saveTitle": "Save {{type}}",
"dialog-saveFilterLabel": "{{type}} Files",
"dialog-saveFileErrorMessage": "Unable to save {{file}}: {{error}}",

"dialog-openProjectWindowPrompt": "Choose the window where the project should be opened.",
"dialog-chooseDomainHome": "Select the Domain Home directory to use",
Expand Down
4 changes: 4 additions & 0 deletions electron/app/locales/en/webui.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"script-sh-label": "sh Script",
"script-ps1-label": "Powershell Script",
"script-cmd-label": "Windows CMD Script",
"script-button-download": "Download",
"script-file-type-label": "{{type}} {{subType}}",
"script-resource-file-format": "Resource",

"kubectl-form-name": "Kubernetes Client Configuration",
"kubectl-title": "Configure the Kubernetes Client",
Expand Down Expand Up @@ -229,6 +232,7 @@
"image-code-primary-image-script-no-content": "Create New Primary Image is turned off so no content to show.",
"image-code-auxiliary-image-script-no-content": "Create New Auxiliary Image is turned off so no content to show.",
"image-code-not-creating-images-no-content": "This project is not configured to create any images so no content to show.",
"image-code-script-title": "{{type}} Script",

"image-design-form-name": "Image",
"image-design-form-primary-tab-name": "Primary Image",
Expand Down
5 changes: 5 additions & 0 deletions electron/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ class Main {
await currentWindow.close();
});

ipcMain.on('download-file', (event, lines, fileType, fileFormat, fileFormatName) => {
const window = event.sender.getOwnerBrowserWindow();
return project.downloadFile(window, lines, fileType, fileFormat, fileFormatName);
});

// eslint-disable-next-line no-unused-vars
ipcMain.on('skip-quickstart-at-startup', async (event) => {
userSettings.setSkipQuickstartAtStartup(true);
Expand Down
31 changes: 31 additions & 0 deletions webui/src/js/viewModels/domain-code-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,37 @@ function (accUtils, ko, project, K8sDomainScriptGenerator, K8sDomainConfigMapGen
};

this.renderScript(this.selectedSubview());

this.downloadInstaller = () => {
const format = this.shellScriptType();
const generator = new K8sDomainScriptGenerator(format);
const lines = generator.generate();
const fileType = i18n.t('script-file-type-label', {
type: i18n.t('nav-domain'),
subType: i18n.t('domain-code-script-title')
});
const formatLabel = this.shellLabelMapper(format + '-label');

window.api.ipc.send('download-file', lines, fileType, format, formatLabel);
};

this.downloadComponentResource = () => {
const generator = this.getDomainResourceGenerator();
const lines = generator.generate();
const fileType = i18n.t('domain-code-domain-resource-title');
const formatLabel = this.shellLabelMapper('resource-file-format');

window.api.ipc.send('download-file', lines, fileType, 'yaml', formatLabel);
};

this.downloadConfigMap = () => {
const generator = this.k8sConfigMapGenerator;
const lines = generator.generate();
const fileType = i18n.t('domain-code-configmap-resource-title');
const formatLabel = this.shellLabelMapper('resource-file-format');

window.api.ipc.send('download-file', lines, fileType, 'yaml', formatLabel);
};
}

return DomainCodeViewModel;
Expand Down
12 changes: 12 additions & 0 deletions webui/src/js/viewModels/image-code-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ function(accUtils, ko, i18n, project, ImageScriptGenerator, ArrayDataProvider) {
};

this.codeText = ko.observable();

this.downloadScript = () => {
const format = this.codeViewScriptLanguage();
const generator = new ImageScriptGenerator(format);
const auxiliary = this.selectedSubview() === 'auxiliaryImageScript';
const lines = auxiliary ? generator.generateAuxiliary() : generator.generatePrimary();
const typeName = this.labelMapper(auxiliary ? 'auxiliary-image-script-tab' : 'primary-image-script-tab');
const fileType = i18n.t('image-code-script-title', {type: typeName});
const formatLabel = this.shellLabelMapper(format + '-label');

window.api.ipc.send('download-file', lines, fileType, format, formatLabel);
};
}

/*
Expand Down
32 changes: 32 additions & 0 deletions webui/src/js/viewModels/ingress-code-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,38 @@ function(accUtils, ko, i18n, project, IngressInstallScriptGenerator, IngressRout
const lines = generator.generate();
this.ingressRoutesYamlText(lines.join('\n'));
};

this.downloadInstaller = () => {
const format = this.shellScriptType();
const generator = new IngressInstallScriptGenerator(format);
const lines = generator.generate();
const fileType = i18n.t('script-file-type-label', {
type: i18n.t('nav-ingress'),
subType: i18n.t('ingress-code-install-script-title')
});
const formatLabel = this.shellLabelMapper(format + '-label');

window.api.ipc.send('download-file', lines, fileType, format, formatLabel);
};

this.downloadAddRoutesScript = () => {
const format = this.shellScriptType();
const generator = new IngressRoutesScriptGenerator(format);
const lines = generator.generate();
const fileType = i18n.t('ingress-code-add-routes-script-title');
const formatLabel = this.shellLabelMapper(format + '-label');

window.api.ipc.send('download-file', lines, fileType, format, formatLabel);
};

this.downloadRoutesResource = () => {
const generator = new IngressResourceGenerator();
const lines = generator.generate();
const fileType = i18n.t('ingress-code-ingress-yaml-title');
const formatLabel = this.shellLabelMapper('resource-file-format');

window.api.ipc.send('download-file', lines, fileType, 'yaml', formatLabel);
};
}

/*
Expand Down
13 changes: 13 additions & 0 deletions webui/src/js/viewModels/operator-code-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ function(i18n, accUtils, ko, project, OperatorScriptGenerator, ArrayDataProvider
this.shellScriptType(event.detail.value);
this.updateCodeText(event.detail.value);
};

this.download = () => {
const format = this.shellScriptType();
const generator = new OperatorScriptGenerator(format);
const lines = generator.generate();
const fileType = i18n.t('script-file-type-label', {
type: i18n.t('nav-operator'),
subType: i18n.t('domain-code-script-title')
});
const formatLabel = this.shellLabelMapper(format + '-label');

window.api.ipc.send('download-file', lines, fileType, format, formatLabel);
};
}

/*
Expand Down
31 changes: 31 additions & 0 deletions webui/src/js/viewModels/vz-application-code-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ function (accUtils, ko, project, VerrazzanoApplicationScriptGenerator, Verrazzan
};

this.renderScript(this.selectedSubview());

this.downloadDeployer = () => {
const format = this.shellScriptType();
const generator = new VerrazzanoApplicationScriptGenerator(format);
const lines = generator.generate();
const fileType = i18n.t('script-file-type-label', {
type: i18n.t('nav-vz-component'),
subType: i18n.t('vz-install-code-script-title')
});
const formatLabel = this.shellLabelMapper(format + '-label');

window.api.ipc.send('download-file', lines, fileType, format, formatLabel);
};

this.downloadApplicationResource = () => {
const generator = this.vzApplicationResourceGenerator;
const lines = generator.generate();
const fileType = i18n.t('vz-application-code-application-resource-title');
const formatLabel = this.shellLabelMapper('resource-file-format');

window.api.ipc.send('download-file', lines, fileType, 'yaml', formatLabel);
};

this.downloadProjectResource = () => {
const generator = this.vzProjectResourceGenerator;
const lines = generator.generate();
const fileType = i18n.t('vz-application-code-project-resource-title');
const formatLabel = this.shellLabelMapper('resource-file-format');

window.api.ipc.send('download-file', lines, fileType, 'yaml', formatLabel);
};
}

return VerrazzanoApplicationCodeViewModel;
Expand Down
31 changes: 31 additions & 0 deletions webui/src/js/viewModels/vz-component-code-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ function (accUtils, ko, project, VerrazzanoComponentScriptGenerator, VerrazzanoC
};

this.renderScript(this.selectedSubview());

this.downloadInstaller = () => {
const format = this.shellScriptType();
const generator = new VerrazzanoComponentScriptGenerator(format);
const lines = generator.generate();
const fileType = i18n.t('script-file-type-label', {
type: i18n.t('nav-vz-component'),
subType: i18n.t('vz-install-code-script-title')
});
const formatLabel = this.shellLabelMapper(format + '-label');

window.api.ipc.send('download-file', lines, fileType, format, formatLabel);
};

this.downloadComponentResource = () => {
const generator = this.vzComponentResourceGenerator;
const lines = generator.generate();
const fileType = i18n.t('vz-component-code-component-resource-title');
const formatLabel = this.shellLabelMapper('resource-file-format');

window.api.ipc.send('download-file', lines, fileType, 'yaml', formatLabel);
};

this.downloadConfigMap = () => {
const generator = this.vzComponentConfigMapGenerator;
const lines = generator.generate();
const fileType = i18n.t('vz-component-code-configmap-resource-title');
const formatLabel = this.shellLabelMapper('resource-file-format');

window.api.ipc.send('download-file', lines, fileType, 'yaml', formatLabel);
};
}

return VerrazzanoComponentCodeViewModel;
Expand Down
21 changes: 21 additions & 0 deletions webui/src/js/viewModels/vz-install-code-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ function (accUtils, ko, project, VerrazzanoInstallScriptGenerator, VerrazzanoIns

this.renderScript(this.selectedSubview());

this.downloadInstaller = () => {
const format = this.shellScriptType();
const generator = new VerrazzanoInstallScriptGenerator(format);
const lines = generator.generate();
const fileType = i18n.t('script-file-type-label', {
type: i18n.t('nav-verrazzano'),
subType: i18n.t('vz-install-code-script-title')
});
const formatLabel = this.shellLabelMapper(format + '-label');

window.api.ipc.send('download-file', lines, fileType, format, formatLabel);
};

this.downloadResource = () => {
const generator = this.vzInstallResourceGenerator;
const lines = generator.generate();
const fileType = i18n.t('vz-install-code-verrazzano-resource-title');
const formatLabel = this.shellLabelMapper('resource-file-format');

window.api.ipc.send('download-file', lines, fileType, 'yaml', formatLabel);
};
}

return VerrazzanoInstallCodeViewModel;
Expand Down
17 changes: 15 additions & 2 deletions webui/src/js/views/domain-code-view.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2021, Oracle and/or its affiliates.
Copyright (c) 2021, 2022, Oracle and/or its affiliates.
Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
-->
<div class="wkt-nested-tab-frame">
Expand All @@ -19,24 +19,37 @@
on-value-changed="[[selectedSubviewValueChangedHandler]]"
value="{{selectedSubview}}">
<div slot="script" class="oj-panel wkt-code-view-platform-frame">
<oj-form-layout max-columns="1" direction="row">
<oj-form-layout max-columns="2" direction="row">
<oj-select-single label-hint="[[shellLabelMapper('selector-label')]]"
on-value-changed="[[shellScriptTypeSelectValueChangedHandler]]"
value="{{shellScriptType}}"
data="{{shellScriptTypesDP}}"
help.instruction="[[shellLabelMapper('selector-help')]]">
</oj-select-single>
<oj-button chroming="callToAction" on-oj-action="[[downloadInstaller]]">
<span><oj-bind-text value="[[shellLabelMapper('button-download')]]"></oj-bind-text></span>
</oj-button>
</oj-form-layout>
<oj-text-area class="wkt-code-view" max-rows="100000" value="{{scriptText}}" readonly="true">
</oj-text-area>
</div>

<div slot="domain" class="oj-panel wkt-code-view-platform-frame">
<oj-form-layout max-columns="2" direction="row">
<oj-button chroming="callToAction" on-oj-action="[[downloadComponentResource]]">
<span><oj-bind-text value="[[shellLabelMapper('button-download')]]"></oj-bind-text></span>
</oj-button>
</oj-form-layout>
<oj-text-area class="wkt-code-view" max-rows="100000" value="{{domainText}}" readonly="true">
</oj-text-area>
</div>

<div slot="configMap" class="oj-panel wkt-code-view-platform-frame">
<oj-form-layout max-columns="2" direction="row">
<oj-button chroming="callToAction" on-oj-action="[[downloadConfigMap]]">
<span><oj-bind-text value="[[shellLabelMapper('button-download')]]"></oj-bind-text></span>
</oj-button>
</oj-form-layout>
<oj-text-area class="wkt-code-view" max-rows="100000" value="{{configMapText}}" readonly="true">
</oj-text-area>
</div>
Expand Down
5 changes: 4 additions & 1 deletion webui/src/js/views/image-code-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
class="wkt-code-view-switcher"
value="{{tabsStatus}}">
<div slot="enabled" class="oj-panel wkt-code-view-platform-frame">
<oj-form-layout max-columns="1" direction="row">
<oj-form-layout max-columns="2" direction="row">
<oj-select-single label-hint="Script Language"
on-value-changed="[[codeViewScriptLanguageSelectValueChangedHandler]]"
value="{{codeViewScriptLanguage}}"
data="[[codeViewScriptLanguagesDP]]"
help.instruction="The scripting language to show.">
</oj-select-single>
<oj-button chroming="callToAction" on-oj-action="[[downloadScript]]">
<span><oj-bind-text value="[[shellLabelMapper('button-download')]]"></oj-bind-text></span>
</oj-button>
</oj-form-layout>
<oj-text-area class="wkt-code-view"
max-rows="100000"
Expand Down
Loading