From 06cc9d76305b2331210c3d52aba7a9a3ad0a9f80 Mon Sep 17 00:00:00 2001 From: loganhz Date: Sun, 26 Aug 2018 15:09:37 +0800 Subject: [PATCH] Should only be allow to enter 1 of each item https://github.com/rancher/rancher/issues/14859 --- app/authenticated/cluster/route.js | 2 +- .../form-resource-quota/component.js | 2 +- .../form-resource-quota/template.hbs | 1 + .../resource-quota-row/component.js | 24 ++++++++++++++++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/authenticated/cluster/route.js b/app/authenticated/cluster/route.js index 8d09f8968..024ab355d 100644 --- a/app/authenticated/cluster/route.js +++ b/app/authenticated/cluster/route.js @@ -9,7 +9,7 @@ const VALID_ROUTES = ['authenticated.cluster.nodes', 'authenticated.cluster.stor 'authenticated.cluster.storage.persistent-volumes', 'authenticated.cluster.notifier', 'authenticated.cluster.alert', 'authenticated.cluster.logging', 'authenticated.cluster.security.members.index', 'authenticated.cluster.projects', - 'authenticated.cluster.quotas', 'authenticated.cluster.pipeline']; + 'authenticated.cluster.quotas']; export default Route.extend(Preload, { scope: service(), diff --git a/app/components/form-resource-quota/component.js b/app/components/form-resource-quota/component.js index 36c058eba..011fe7f61 100644 --- a/app/components/form-resource-quota/component.js +++ b/app/components/form-resource-quota/component.js @@ -28,7 +28,7 @@ export default Component.extend({ actions: { addQuota() { get(this, 'quotaArray').pushObject({ - key: 'pods', + key: '', value: '', }); }, diff --git a/app/components/form-resource-quota/template.hbs b/app/components/form-resource-quota/template.hbs index f44d7533a..8e6f2de43 100644 --- a/app/components/form-resource-quota/template.hbs +++ b/app/components/form-resource-quota/template.hbs @@ -12,6 +12,7 @@ {{#each quotaArray as |quota|}} {{resource-quota-row quota=quota + currentQuota=quotaArray editing=editing remove=(action "removeQuota") }} diff --git a/app/components/resource-quota-row/component.js b/app/components/resource-quota-row/component.js index cebe19d0b..14b007af7 100644 --- a/app/components/resource-quota-row/component.js +++ b/app/components/resource-quota-row/component.js @@ -1,6 +1,7 @@ -import { get, set } from '@ember/object'; +import { get, set, observer } from '@ember/object'; import { inject as service } from '@ember/service'; import Component from '@ember/component'; +import { next } from '@ember/runloop'; import layout from './template'; const IGNORED = ['requestsStorage', 'persistentVolumeClaims']; @@ -13,13 +14,22 @@ export default Component.extend({ tagName: 'TR', classNames: 'main-row', - resourceChoices: null, + resourceChoices: null, + allResourceChoices: null, init() { this._super(...arguments); this.initResourceChoices(); }, + currentQuotaDidChange: observer('currentQuota.@each.key', function() { + set(this, 'resourceChoices', get(this, 'allResourceChoices').filter((choice) => this.doesExist(choice))); + }), + + doesExist(choice) { + return get(choice, 'value') === get(this, 'quota.key') || !get(this, 'currentQuota').findBy('key', get(choice, 'value')); + }, + initResourceChoices() { const choices = []; const schema = get(this, 'globalStore').getById('schema', 'resourcequotalimit'); @@ -33,6 +43,14 @@ export default Component.extend({ }); } - set(this, 'resourceChoices', choices); + set(this, 'allResourceChoices', choices); + + set(this, 'resourceChoices', choices.filter((choice) => this.doesExist(choice))); + + if ( get(this, 'resourceChoices.length') && !get(this, 'quota.key') ) { + next(() => { + set(this, 'quota.key', get(this, 'resourceChoices.firstObject.value')); + }); + } } });