From 565520c47afb42fe2c27c9bd0cddabb4bc73fc4c Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Fri, 4 Sep 2020 03:46:01 -0700 Subject: [PATCH] Fleet clustergroup creaet --- assets/translations/en-us.yaml | 5 ++ components/ResourceYaml.vue | 13 ++-- components/form/MatchExpressions.vue | 82 +++++++++----------------- edit/fleet.cattle.io.clustergroup.vue | 57 ++++++++++++++++++ models/fleet.cattle.io.clustergroup.js | 12 ++++ plugins/steve/resource-instance.js | 8 ++- 6 files changed, 118 insertions(+), 59 deletions(-) create mode 100644 edit/fleet.cattle.io.clustergroup.vue create mode 100644 models/fleet.cattle.io.clustergroup.js diff --git a/assets/translations/en-us.yaml b/assets/translations/en-us.yaml index b7fdce84c4..4428c6ca66 100644 --- a/assets/translations/en-us.yaml +++ b/assets/translations/en-us.yaml @@ -1444,3 +1444,8 @@ typeLabel: one { Endpoint } other { Endpoints } } + fleet.cattle.io.clustergroup: |- + {count, plural, + one { Cluster Group } + other {Cluster Groups } + } diff --git a/components/ResourceYaml.vue b/components/ResourceYaml.vue index 460e3ef079..9b785a922f 100644 --- a/components/ResourceYaml.vue +++ b/components/ResourceYaml.vue @@ -123,10 +123,6 @@ export default { cm.foldLinesMatching(/^status:\s*$/); } - // regardless of edit or create we should probably fold all the comments so they dont get out of hand. - cm.getMode().fold = 'yamlcomments'; - cm.execCommand('foldAll'); - try { const parsed = jsyaml.safeLoad(this.currentYaml); const annotations = Object.keys(parsed?.metadata?.annotations || {}); @@ -152,7 +148,14 @@ export default { } } catch (e) {} - cm.foldLinesMatching(/^\s+managedFields:\s*$/); + cm.foldLinesMatching(/managedFields/); + + // regardless of edit or create we should probably fold all the comments so they dont get out of hand. + const saved = cm.getMode().fold; + + cm.getMode().fold = 'yamlcomments'; + cm.execCommand('foldAll'); + cm.getMode().fold = saved; }, onChanges(cm, changes) { diff --git a/components/form/MatchExpressions.vue b/components/form/MatchExpressions.vue index 32cd0a9217..66dccbe557 100644 --- a/components/form/MatchExpressions.vue +++ b/components/form/MatchExpressions.vue @@ -5,6 +5,7 @@ import LabeledSelect from '@/components/form/LabeledSelect'; import { sortBy } from '@/utils/sort'; import ArrayList from '@/components/form/ArrayList'; import { mapGetters } from 'vuex'; +import { removeObject } from '@/utils/array'; export default { components: { @@ -63,34 +64,6 @@ export default { data() { const t = this.$store.getters['i18n/t']; - const tableHeaders = [ - { - name: 'key', - label: t('workload.scheduling.affinity.matchExpressions.key'), - value: 'key' - }, - { - name: 'operator', - label: t('workload.scheduling.affinity.matchExpressions.operator'), - value: 'operator', - width: '20%' - }, - { - name: 'value', - label: t('workload.scheduling.affinity.matchExpressions.value'), - value: 'values' - }, - ]; - - if (this.showRemove) { - tableHeaders.push({ - name: 'remove', - label: '', - value: '', - width: 50 - }); - } - const podOptions = [ { label: t('workload.scheduling.affinity.matchExpressions.exists'), value: 'Exists' }, { label: t('workload.scheduling.affinity.matchExpressions.doesNotExist'), value: 'DoesNotExist' }, @@ -111,18 +84,22 @@ export default { rules = rules.map((rule) => { if (rule.values && typeof rule.values !== 'string') { - rule.values = rule.values.join(','); + rule.values = rule.values.join(', '); } return rule; }); if (!rules.length && this.initialEmptyRow) { - rules.push({ values: '' }); + rules.push({ + key: '', operator: 'In', values: '' + }); } return { - ops, rules, custom: [], tableHeaders + ops, + rules, + custom: [] }; }, @@ -160,35 +137,32 @@ export default { methods: { removeRule(row) { - const idx = this.rules.indexOf(row); - - this.rules.splice(idx, 1); + removeObject(this.rules, row); this.update(); }, addRule() { - this.rules.push({ values: '' }); + this.rules.push({ + key: '', + operator: 'In', + values: '' + }); }, update() { this.$nextTick(() => { - const out = [ - ...this.rules.map((rule) => { - const matchExpression = { key: rule.key }; + const out = this.rules.map((rule) => { + const matchExpression = { key: rule.key, operator: rule.operator }; + const val = (rule.values || '').trim(); - if (rule.operator) { - matchExpression.operator = rule.operator; - } - if (rule.values) { - if ((rule.operator === 'In' || rule.operator === 'NotIn')) { - matchExpression.values = (rule.values || []).split(','); - } else { - matchExpression.values = [rule.values]; - } - } + if ( !val ) { + return; + } - return matchExpression; - })]; + matchExpression.values = val.split(/\s*,\s*/).filter(x => !!x); + + return matchExpression; + }).filter(x => !!x); this.$emit('input', out); }); @@ -265,13 +239,15 @@ export default { v-model="row.operator" class="inline" :options="ops" + label="label" + :reduce="opt=>opt.value" :mode="mode" @input="update" />
- +
@@ -279,7 +255,7 @@ export default {
-
+