Make standard labels and annotations readonly

This commit is contained in:
loganhz 2019-08-26 14:31:15 +08:00
parent 774b998c2f
commit d3f73b74bd
5 changed files with 49 additions and 13 deletions

View File

@ -63,6 +63,7 @@ export default Component.extend(Upload, {
initialMap: null, initialMap: null,
initialArray: null, initialArray: null,
requiredIfAny: null, requiredIfAny: null,
readonlyArray: null,
ary: null, ary: null,
allowEmptyValue: false, allowEmptyValue: false,
allowAdd: true, allowAdd: true,
@ -89,12 +90,14 @@ export default Component.extend(Upload, {
var ary = []; var ary = [];
var map = get(this, 'initialMap'); var map = get(this, 'initialMap');
const readonlyArray = get(this, 'readonlyArray') || [];
if ( map ) { if ( map ) {
Object.keys(map).forEach((key) => { Object.keys(map).forEach((key) => {
ary.push({ ary.push({
key, key,
value: map[key] value: map[key],
editable: readonlyArray.indexOf(key) === -1
}); });
}); });
} else if ( get(this, 'initialStr') ) { } else if ( get(this, 'initialStr') ) {

View File

@ -27,7 +27,7 @@
{{#each ary as |row|}} {{#each ary as |row|}}
<tr> <tr>
<td data-title="{{t keyLabel}}:"> <td data-title="{{t keyLabel}}:">
{{#if (and editing allowEditKey (not-eq row.editable false))}} {{#if editing}}
{{input-paste {{input-paste
separators=separators separators=separators
pasted=(action "pastedValues") pasted=(action "pastedValues")
@ -35,6 +35,7 @@
type="text" type="text"
value=row.key value=row.key
placeholder=keyPlaceholder placeholder=keyPlaceholder
disabled=(not (and allowEditKey (not-eq row.editable false)))
}} }}
{{else}} {{else}}
{{row.key}} {{row.key}}
@ -61,7 +62,7 @@
<td>&nbsp;</td> <td>&nbsp;</td>
<td class="valign-top text-right"> <td class="valign-top text-right">
{{#if (and editing allowRemove)}} {{#if (and editing allowRemove)}}
<button class="btn bg-primary btn-sm" {{action "remove" row}}><i class="icon icon-minus"/><span class="sr-only">{{t "generic.remove"}}</span></button> <button class="btn bg-primary btn-sm" {{action "remove" row}} disabled={{eq row.editable false}}><i class="icon icon-minus"/><span class="sr-only">{{t "generic.remove"}}</span></button>
{{/if}} {{/if}}
</td> </td>
</tr> </tr>

View File

@ -1,5 +1,5 @@
import { next } from '@ember/runloop'; import { next } from '@ember/runloop';
import { set } from '@ember/object'; import { get, set } from '@ember/object';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import Component from '@ember/component'; import Component from '@ember/component';
import ManageLabels from 'shared/mixins/manage-labels'; import ManageLabels from 'shared/mixins/manage-labels';
@ -9,6 +9,7 @@ import {
classForStatus classForStatus
} from 'shared/components/accordion-list-item/component'; } from 'shared/components/accordion-list-item/component';
import layout from './template'; import layout from './template';
import C from 'ui/utils/constants';
export default Component.extend(ManageLabels, { export default Component.extend(ManageLabels, {
intl: service(), intl: service(),
@ -22,6 +23,7 @@ export default Component.extend(ManageLabels, {
expandAll: null, expandAll: null,
editing: true, editing: true,
readonlyLabels: null, readonlyLabels: null,
readonlyAnnotations: null,
// Inputs // Inputs
initialLabels: null, initialLabels: null,
@ -32,10 +34,9 @@ export default Component.extend(ManageLabels, {
init() { init() {
this._super(...arguments); this._super(...arguments);
this.initLabels(this.get('initialLabels'), 'user', null, this.get('readonlyLabels')); this.initLablesAndAnnotations();
this.labelsChanged();
this.initCounts();
}, },
didReceiveAttrs() { didReceiveAttrs() {
if (!this.get('expandFn')) { if (!this.get('expandFn')) {
this.set('expandFn', (item) => { this.set('expandFn', (item) => {
@ -82,6 +83,29 @@ export default Component.extend(ManageLabels, {
return this.get('intl').t(`${ STATUS_INTL_KEY }.${ k }`, { count }); return this.get('intl').t(`${ STATUS_INTL_KEY }.${ k }`, { count });
}.property('labelsCount', 'annotationsCount'), }.property('labelsCount', 'annotationsCount'),
initLablesAndAnnotations() {
const readonlyLabels = get(this, 'readonlyLabels') || [];
let readonlyAnnotations = get(this, 'readonlyAnnotations') || [];
Object.keys((get(this, 'initialLabels') || {})).forEach((key) => {
if ( C.LABEL_PREFIX_TO_IGNORE.find((L) => key.startsWith(L))) {
readonlyLabels.push(key);
}
})
Object.keys((get(this, 'model.annotations') || {})).forEach((key) => {
if ( C.ANNOTATIONS_TO_IGNORE.find((L) => key.indexOf(L) > -1)) {
readonlyAnnotations.push(key);
}
})
set(this, 'readonlyAnnotations', readonlyAnnotations);
this.initLabels(this.get('initialLabels'), 'user', null, readonlyLabels);
this.labelsChanged();
this.initCounts();
},
initCounts(){ initCounts(){
let labels = this.get('model.labels'); let labels = this.get('model.labels');
let annotations = this.get('model.annotations'); let annotations = this.get('model.annotations');

View File

@ -80,6 +80,7 @@
{{form-key-value {{form-key-value
header=(t "formAnnotations.title") header=(t "formAnnotations.title")
editing=editing editing=editing
readonlyArray=readonlyAnnotations
initialMap=model.annotations initialMap=model.annotations
changed=(action "annotationsChange") changed=(action "annotationsChange")
addActionLabel="formAnnotations.addActionLabel" addActionLabel="formAnnotations.addActionLabel"

View File

@ -566,10 +566,17 @@ C.LABEL_PREFIX_TO_IGNORE = [
'node-role.kubernetes.io/', 'node-role.kubernetes.io/',
'kubernetes.io/', 'kubernetes.io/',
'cattle.io/', 'cattle.io/',
'authz.management.cattle.io',
'rke.cattle.io', 'rke.cattle.io',
'field.cattle.io', 'field.cattle.io',
]; ];
C.ANNOTATIONS_TO_IGNORE = [
'coreos.com/',
'kubernetes.io/',
'cattle.io/',
]
C.SYSTEM_LABELS_WITH_CONTROL = [ C.SYSTEM_LABELS_WITH_CONTROL = [
C.LABEL.SCHED_GLOBAL, C.LABEL.SCHED_GLOBAL,
C.LABEL.HOSTNAME_OVERRIDE, C.LABEL.HOSTNAME_OVERRIDE,