diff --git a/app/components/modal-edit-setting/component.js b/app/components/modal-edit-setting/component.js index 6aaa47761..ebd8f4393 100644 --- a/app/components/modal-edit-setting/component.js +++ b/app/components/modal-edit-setting/component.js @@ -6,20 +6,41 @@ import { normalizeName } from 'shared/settings/service'; import ModalBase from 'shared/mixins/modal-base'; import layout from './template'; +const cmOpts = { + autofocus: true, + gutters: ['CodeMirror-lint-markers'], + lineNumbers: true, + lineWrapping: true, + lint: true, + mode: { + name: 'javascript', + json: true, + }, + theme: 'monokai', + viewportMargin: Infinity, +}; + export default Component.extend(ModalBase, { - settings: service(), - growl: service(), + settings: service(), + growl: service(), layout, - classNames: ['span-8', 'offset-2'], + classNames: ['modal-edit-setting', 'span-8', 'offset-2'], - value: null, - removing: false, + codeMirrorOptions: cmOpts, + value: null, + formattedValue: null, + removing: false, - model: alias('modalService.modalOpts'), + model: alias('modalService.modalOpts'), init() { this._super(...arguments); - this.set('value', this.get('model.obj.value') || ''); + + if (this.get('model.kind') === 'json') { + this.set('formattedValue', JSON.stringify(JSON.parse(this.get('model.obj.value')), undefined, 2)); + } else { + this.set('value', this.get('model.obj.value') || ''); + } }, didInsertElement() { @@ -49,6 +70,11 @@ export default Component.extend(ModalBase, { done() { this.send('cancel'); + window.location.href = window.location.href; + }, + + updateJson(json) { + this.set('value', json); } }, }); diff --git a/app/components/modal-edit-setting/template.hbs b/app/components/modal-edit-setting/template.hbs index 0c84c0b55..1660e2359 100644 --- a/app/components/modal-edit-setting/template.hbs +++ b/app/components/modal-edit-setting/template.hbs @@ -15,6 +15,12 @@ {{textarea class="form-control" value=value rows=10}} {{else if (eq model.kind 'int')}} {{input-integer value=value class="form-control"}} + {{else if (eq model.kind 'json')}} + {{ivy-codemirror + value=formattedValue + valueUpdated=(action 'updateJson') + options=codeMirrorOptions + }} {{else if (eq model.kind 'boolean')}}
diff --git a/app/styles/components/_modals.scss b/app/styles/components/_modals.scss index da9a5c9c6..da8ebf893 100644 --- a/app/styles/components/_modals.scss +++ b/app/styles/components/_modals.scss @@ -56,6 +56,13 @@ $modal-overlay : rgba($light-grey, 0.75) !default; padding: 20px; margin-bottom: 20px; + &.modal-edit-setting { + .container-setting { + max-height: 70vh !important; + overflow-y: scroll; + } + } + &.large-modal { &.modal-container { width: calc(100% - 40px); @@ -120,4 +127,5 @@ $modal-overlay : rgba($light-grey, 0.75) !default; .modal-yaml { max-width: calc(100vw - 40px); } + } diff --git a/app/styles/pages/_settings.scss b/app/styles/pages/_settings.scss index 2c901c4a2..183c09d0c 100644 --- a/app/styles/pages/_settings.scss +++ b/app/styles/pages/_settings.scss @@ -32,7 +32,7 @@ &.gitlab { background-image: url('images/providers/gitlab.svg'); } - + &.github-for-pipeline { background-image: url('images/providers/github-for-pipeline.svg'); } @@ -95,3 +95,9 @@ } } } + +.container-json-setting { + max-height: 50vh; + overflow-y: scroll; + margin-bottom: 15px; +} diff --git a/ember-cli-build.js b/ember-cli-build.js index f38aba34c..da1fa35cd 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -83,6 +83,7 @@ module.exports = function(defaults) { app.import('node_modules/prismjs/prism.js'); app.import('node_modules/prismjs/components/prism-bash.js'); app.import('node_modules/prismjs/components/prism-yaml.js'); + app.import('node_modules/prismjs/components/prism-json.js'); app.import('node_modules/ember-source/dist/ember-template-compiler.js') // app.import('vendor/aws-sdk-ec2.js'); diff --git a/lib/global-admin/addon/components/azuread-endpoints/template.hbs b/lib/global-admin/addon/components/azuread-endpoints/template.hbs index 0a6fcf198..5502e8532 100644 --- a/lib/global-admin/addon/components/azuread-endpoints/template.hbs +++ b/lib/global-admin/addon/components/azuread-endpoints/template.hbs @@ -1,59 +1,51 @@
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-{{!-- {{#if (eq region 'custom')}} --}} -
-
-
- - {{input id="endpoint" type="url" value=authConfig.endpoint classNames="form-control"}} +
+
+
-
-
-
- - {{input id="graph-endpoint" type="url" value=authConfig.graphEndpoint classNames="form-control"}} +
+ +
+
+
+{{#if (eq region 'custom')}} +
+
+
+ + {{input id="endpoint" type="url" value=authConfig.endpoint classNames="form-control"}} +
+
+
+
+ + {{input id="graph-endpoint" type="url" value=authConfig.graphEndpoint classNames="form-control"}} +
+
+
-
-
-
- - {{input id="token-endpoint" type="url" value=authConfig.tokenEndpoint classNames="form-control"}} +
+
+
+ + {{input id="token-endpoint" type="url" value=authConfig.tokenEndpoint classNames="form-control"}} +
+
+
+
+ + {{input id="auth-endpoint" type="url" value=authConfig.authEndpoint classNames="form-control"}} +
-
-
- - {{input id="auth-endpoint" type="url" value=authConfig.authEndpoint classNames="form-control"}} -
-
-
-{{!-- {{/if}} --}} \ No newline at end of file +{{/if}} \ No newline at end of file diff --git a/lib/shared/addon/components/settings/danger-zone/component.js b/lib/shared/addon/components/settings/danger-zone/component.js index 8b03b74d2..d2c73f8f0 100644 --- a/lib/shared/addon/components/settings/danger-zone/component.js +++ b/lib/shared/addon/components/settings/danger-zone/component.js @@ -30,7 +30,7 @@ export default Component.extend({ }, }, - allowed: computed(() => { + allowed: computed('settings.all.@each.{name,customized}', () => { let out = {}; Object.keys(C.SETTING.ALLOWED).forEach((key) => { @@ -43,7 +43,7 @@ export default Component.extend({ return out; }), - current: computed('settings.all.@each.{name,source}', function() { + current: computed('allowed.@each.{name,customized}', function() { let all = get(this, 'settings.asMap'); let allowed = get(this, 'allowed'); let isLocalDev = window.location.host === 'localhost:8000'; @@ -65,6 +65,11 @@ export default Component.extend({ out.set('hide', true); } + if (get(details, 'kind') === 'json') { + out.set('hide', true); + out.set('parsedJSON', JSON.stringify(JSON.parse(out.get('obj.value')), undefined, 2)) + } + (Object.keys(details) || []).forEach((key2) => { out.set(key2, details[key2]); }); diff --git a/lib/shared/addon/components/settings/danger-zone/template.hbs b/lib/shared/addon/components/settings/danger-zone/template.hbs index 471a172e4..1fff644df 100644 --- a/lib/shared/addon/components/settings/danger-zone/template.hbs +++ b/lib/shared/addon/components/settings/danger-zone/template.hbs @@ -26,15 +26,25 @@
{{else}}
-
+              {{#if (eq row.kind "json" )}}
+                
+ {{code-block + class="setting-json" + code=row.parsedJSON + language="json" + }} +
+ {{else}} +
                 {{~#if row.obj.value~}}
                   {{~row.obj.value~}}
                 {{~else~}}
                   <none>
                 {{~/if~}}
-              
+
+ {{/if}}
- {{#if (eq row.kind 'multiline')}} + {{#if (or (eq row.kind 'multiline') (eq row.kind 'json'))}}
Hide {{row.key}}
{{/if}}
diff --git a/lib/shared/addon/helpers/to-json.js b/lib/shared/addon/helpers/to-json.js index e46e0eb80..833516a58 100644 --- a/lib/shared/addon/helpers/to-json.js +++ b/lib/shared/addon/helpers/to-json.js @@ -2,6 +2,6 @@ import Helper from '@ember/component/helper'; export default Helper.extend({ compute(params/* , options*/) { - return JSON.stringify(params[0]); + return JSON.stringify(params[0], undefined, 2); }, }); diff --git a/lib/shared/addon/settings/service.js b/lib/shared/addon/settings/service.js index 47da3750c..10a581397 100644 --- a/lib/shared/addon/settings/service.js +++ b/lib/shared/addon/settings/service.js @@ -5,7 +5,7 @@ import Evented from '@ember/object/evented'; import Service, { inject as service } from '@ember/service'; import C from 'shared/utils/constants'; import { minorVersion } from 'shared/utils/parse-version'; -import { get, set, computed } from '@ember/object'; +import { get, set, computed, observer } from '@ember/object'; import { isEmpty } from '@ember/utils'; export function normalizeName(str) { @@ -84,18 +84,18 @@ export default Service.extend(Evented, { return value; }, - promiseCountObserver: function() { + promiseCountObserver: observer('promiseCount', function() { if (get(this, 'promiseCount') <= 0) { this.trigger('settingsPromisesResolved'); } - }.observes('promiseCount'), + }), findByName(name) { return get(this, 'asMap')[normalizeName(name)]; }, loadAll() { - return get(this, 'globalStore').find('setting'); + return get(this, 'globalStore').findAll('setting'); }, load(names) { @@ -127,7 +127,15 @@ export default Service.extend(Evented, { return promise; }, - asMap: function() { + cliVersion: alias(`asMap.${ C.SETTING.VERSION_CLI }.value`), + dockerMachineVersion: alias(`asMap.${ C.SETTING.VERSION_MACHINE }.value`), + helmVersion: alias(`asMap.${ C.SETTING.VERSION_HELM }.value`), + minDockerVersion: alias(`asMap.${ C.SETTING.MIN_DOCKER }.value`), + rancherImage: alias(`asMap.${ C.SETTING.IMAGE_RANCHER }.value`), + rancherVersion: alias(`asMap.${ C.SETTING.VERSION_RANCHER }.value`), + serverUrl: alias(`asMap.${ C.SETTING.SERVER_URL }.value`), + + asMap: computed('all.@each.{name,value,customized}', function() { var out = {}; (get(this, 'all') || []).forEach((setting) => { @@ -137,15 +145,15 @@ export default Service.extend(Evented, { }); return out; - }.property('all.@each.{name,value}'), + }), - uiVersion: function() { + uiVersion: computed('app.version', function() { return `v${ get(this, 'app.version') }`; - }.property('app.version'), + }), - issueUrl: function() { + issueUrl: computed('app.currentRouteName', 'access.{provider,admin}', 'rancherVersion', 'uiVersion', function() { var str = '*Describe your issue here*\n\n\n---\n| Useful | Info |\n| :-- | :-- |\n' + - `|Versions|Rancher \`${ get(this, 'rancherVersion') || '-' }\` ` + + `|Versions|Rancher \`${ get(this, 'rancherVersion') || '-' }\` ` + `UI: \`${ get(this, 'uiVersion') || '--' }\` |\n`; if ( get(this, 'access.enabled') ) { @@ -161,39 +169,31 @@ export default Service.extend(Evented, { var url = `${ C.EXT_REFERENCES.GITHUB }/issues/new?body=${ encodeURIComponent(str) }`; return url; - }.property('app.currentRouteName', 'access.{provider,admin}', 'rancherVersion', 'uiVersion'), + }), - rancherImage: alias(`asMap.${ C.SETTING.IMAGE_RANCHER }.value`), - rancherVersion: alias(`asMap.${ C.SETTING.VERSION_RANCHER }.value`), - cliVersion: alias(`asMap.${ C.SETTING.VERSION_CLI }.value`), - dockerMachineVersion: alias(`asMap.${ C.SETTING.VERSION_MACHINE }.value`), - helmVersion: alias(`asMap.${ C.SETTING.VERSION_HELM }.value`), - serverUrl: alias(`asMap.${ C.SETTING.SERVER_URL }.value`), serverUrlIsEmpty: computed('serverUrl', function() { return isEmpty(get(this, 'serverUrl')); }), - isRancher: function() { + isRancher: computed(C.SETTING.PL, function() { const out = (get(this, C.SETTING.PL) || '').toUpperCase() === C.SETTING.PL_RANCHER_VALUE.toUpperCase(); return out; - }.property(C.SETTING.PL), + }), - isEnterprise: function() { + isEnterprise: computed('rancherImage', function() { return get(this, 'rancherImage') === 'rancher/enterprise'; - }.property('rancherImage'), + }), - appName: function() { + appName: computed('isRancher', C.SETTING.PL, function() { if ( get(this, 'isRancher') ) { return get(this, 'app.appName'); } return get(this, C.SETTING.PL) || ''; - }.property('isRancher', C.SETTING.PL), + }), - minDockerVersion: alias(`asMap.${ C.SETTING.MIN_DOCKER }.value`), - - minorVersion: function() { + minorVersion: computed('rancherVersion', function() { let version = get(this, 'rancherVersion'); if ( !version ) { @@ -201,9 +201,9 @@ export default Service.extend(Evented, { } return minorVersion(version); - }.property('rancherVersion'), + }), - docsBase: function() { + docsBase: computed('intl.locale', 'minorVersion', function() { let full = get(this, 'rancherVersion'); let version; @@ -222,5 +222,5 @@ export default Service.extend(Evented, { } return `${ C.EXT_REFERENCES.DOCS }/${ version }/${ lang }`; - }.property('intl.locale', 'minorVersion') + }) }); diff --git a/lib/shared/addon/utils/constants.js b/lib/shared/addon/utils/constants.js index f2ef0857e..81f095072 100644 --- a/lib/shared/addon/utils/constants.js +++ b/lib/shared/addon/utils/constants.js @@ -479,6 +479,7 @@ var C = { API_HOST: 'api-host', CA_CERTS: 'cacerts', + CLUSTER_DEFAULTS: 'cluster-defaults', ENGINE_URL: 'engine-install-url', ENGINE_ISO_URL: 'engine-iso-url', FIRST_LOGIN: 'first-login', @@ -512,6 +513,7 @@ var C = { C.SETTING.ALLOWED = { [C.SETTING.CA_CERTS]: { kind: 'multiline' }, + [C.SETTING.CLUSTER_DEFAULTS]: { kind: 'json' }, [C.SETTING.ENGINE_URL]: {}, [C.SETTING.ENGINE_ISO_URL]: {}, [C.SETTING.PL]: {}, @@ -519,8 +521,8 @@ C.SETTING.ALLOWED = { [C.SETTING.SERVER_URL]: {}, 'system-default-registry': {}, [C.SETTING.TELEMETRY]: { - kind: 'enum', - options: ['prompt', 'in', 'out'] + kind: 'enum', + options: ['prompt', 'in', 'out'] }, 'ui-index': {}, }; diff --git a/translations/en-us.yaml b/translations/en-us.yaml index 71847c03e..de80bae43 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -2896,6 +2896,7 @@ dangerZone: showLabel: I understand that I can break things by changing advanced settings. description: 'cacerts': "CA Certificates needed to verify the server's certificate" + 'cluster-defaults': 'Override RKE Defaults when creating new clusters.' 'engine-install-url': 'Default Docker engine installation URL (for most node drivers)' 'engine-iso-url': 'Default OS installation URL (for vSphere driver)' 'engine-newest-version': 'The newest supported version of Docker at the time of this release. A Docker version that does not satisfy supported docker range but is newer than this will be marked as untested'