From e9b59b42f523fc6b27dac752a1bda94aeb9c5801 Mon Sep 17 00:00:00 2001 From: loganhz Date: Mon, 19 Nov 2018 14:13:52 +0800 Subject: [PATCH 1/4] Fix the issue that download filename is always download.txt --- lib/shared/addon/components/modal-yaml/template.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shared/addon/components/modal-yaml/template.hbs b/lib/shared/addon/components/modal-yaml/template.hbs index 728b01c10..65f9b782c 100644 --- a/lib/shared/addon/components/modal-yaml/template.hbs +++ b/lib/shared/addon/components/modal-yaml/template.hbs @@ -1,7 +1,7 @@
- {{form-key-value initialMap=primaryResource.data allowEmptyValue=true + header=(t 'newConfigMap.values.label') + allowUpload=true addActionLabel="newConfigMap.addActionLabel" addInitialEmptyRow=true editing=notView diff --git a/lib/shared/addon/components/form-key-value/component.js b/lib/shared/addon/components/form-key-value/component.js index 57e96bb92..290d68192 100644 --- a/lib/shared/addon/components/form-key-value/component.js +++ b/lib/shared/addon/components/form-key-value/component.js @@ -1,7 +1,8 @@ import { on } from '@ember/object/evented'; import { next, debounce } from '@ember/runloop'; import Component from '@ember/component'; -import { get, set, observer } from '@ember/object'; +import { get, set, observer } from '@ember/object' +import Upload from 'shared/mixins/upload'; import layout from './template'; function applyLinesIntoArray(lines, ary) { @@ -55,7 +56,7 @@ function removeEmptyEntries(ary, allowEmptyValue = false) { ary.removeObjects(toRemove); } -export default Component.extend({ +export default Component.extend(Upload, { layout, // Inputs initialStr: null, @@ -65,6 +66,7 @@ export default Component.extend({ ary: null, allowEmptyValue: false, allowAdd: true, + allowUpload: false, allowRemove: true, allowEditKey: true, addInitialEmptyRow: false, @@ -79,6 +81,8 @@ export default Component.extend({ valueLabel: 'formKeyValue.value.label', keyPlaceholder: 'formKeyValue.key.placeholder', valuePlaceholder: 'formKeyValue.value.placeholder', + uploadAction: 'pastedValues', + init() { this._super(...arguments); diff --git a/lib/shared/addon/components/form-key-value/template.hbs b/lib/shared/addon/components/form-key-value/template.hbs index a2143ecd2..50f08acf9 100644 --- a/lib/shared/addon/components/form-key-value/template.hbs +++ b/lib/shared/addon/components/form-key-value/template.hbs @@ -1,6 +1,14 @@
{{#if header}} - +
+ +
+ {{/if}} + + {{#if (and allowUpload editing)}} +
+ +
{{/if}}
@@ -75,3 +83,4 @@
{{/if}} + \ No newline at end of file diff --git a/lib/shared/addon/mixins/upload.js b/lib/shared/addon/mixins/upload.js new file mode 100644 index 000000000..92bea9e68 --- /dev/null +++ b/lib/shared/addon/mixins/upload.js @@ -0,0 +1,35 @@ +import Mixin from '@ember/object/mixin'; +import { inject as service } from '@ember/service'; +import { get } from '@ember/object'; + +export default Mixin.create({ + growl: service(), + + actions: { + upload() { + this.$('INPUT[type=file]')[0].click(); + }, + }, + + change(event) { + const input = event.target; + + if ( input.files && input.files[0] ) { + let file = input.files[0]; + + const reader = new FileReader(); + + reader.onerror = (err) => { + get(this, 'growl').fromError(get(err, 'srcElement.error.message')); + }; + + reader.onload = (event2) => { + const out = event2.target.result; + + this.send(get(this, 'uploadAction'), out); + input.value = ''; + }; + reader.readAsText(file); + } + } +}); diff --git a/lib/shared/app/mixins/upload.js b/lib/shared/app/mixins/upload.js new file mode 100644 index 000000000..2c678ae9f --- /dev/null +++ b/lib/shared/app/mixins/upload.js @@ -0,0 +1 @@ +export { default } from 'shared/mixins/upload'; From 71b826df75100a4aabc9be1aa8051d67995a1e58 Mon Sep 17 00:00:00 2001 From: loganhz Date: Mon, 19 Nov 2018 15:06:24 +0800 Subject: [PATCH 3/4] Show import YAML button in config map list --- app/authenticated/project/config-maps/index/template.hbs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/authenticated/project/config-maps/index/template.hbs b/app/authenticated/project/config-maps/index/template.hbs index 95f0073b4..c0d0e58d5 100644 --- a/app/authenticated/project/config-maps/index/template.hbs +++ b/app/authenticated/project/config-maps/index/template.hbs @@ -9,6 +9,9 @@ {{#link-to (query-params group="namespace") classNames="btn btn-sm bg-default"}}{{/link-to}} {{/tooltip-element}} + + + {{#link-to "authenticated.project.config-maps.new" classNames="btn btn-sm bg-primary" disabled=(rbac-prevents resource=resource scope="project" permission="create")}}{{t 'configMapsPage.index.linkTo'}}{{/link-to}} From 098628204bb1110c32891e9edee2190fc855e6bb Mon Sep 17 00:00:00 2001 From: loganhz Date: Mon, 19 Nov 2018 22:13:53 +0800 Subject: [PATCH 4/4] Restrict file type to text --- lib/shared/addon/components/form-key-value/template.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shared/addon/components/form-key-value/template.hbs b/lib/shared/addon/components/form-key-value/template.hbs index 50f08acf9..5dd1d2dcc 100644 --- a/lib/shared/addon/components/form-key-value/template.hbs +++ b/lib/shared/addon/components/form-key-value/template.hbs @@ -83,4 +83,4 @@ {{/if}} - \ No newline at end of file + \ No newline at end of file