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

View File

@ -27,7 +27,7 @@
{{#each ary as |row|}}
<tr>
<td data-title="{{t keyLabel}}:">
{{#if (and editing allowEditKey (not-eq row.editable false))}}
{{#if editing}}
{{input-paste
separators=separators
pasted=(action "pastedValues")
@ -35,6 +35,7 @@
type="text"
value=row.key
placeholder=keyPlaceholder
disabled=(not (and allowEditKey (not-eq row.editable false)))
}}
{{else}}
{{row.key}}
@ -61,7 +62,7 @@
<td>&nbsp;</td>
<td class="valign-top text-right">
{{#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}}
</td>
</tr>

View File

@ -1,5 +1,5 @@
import { next } from '@ember/runloop';
import { set } from '@ember/object';
import { get, set } from '@ember/object';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import ManageLabels from 'shared/mixins/manage-labels';
@ -9,6 +9,7 @@ import {
classForStatus
} from 'shared/components/accordion-list-item/component';
import layout from './template';
import C from 'ui/utils/constants';
export default Component.extend(ManageLabels, {
intl: service(),
@ -16,12 +17,13 @@ export default Component.extend(ManageLabels, {
layout,
classNames: ['accordion-wrapper'],
detailKey: 'formLabelsAnnotations.detail',
annotationsCount: 0,
labelsCount: 0,
expandAll: null,
editing: true,
readonlyLabels: null,
detailKey: 'formLabelsAnnotations.detail',
annotationsCount: 0,
labelsCount: 0,
expandAll: null,
editing: true,
readonlyLabels: null,
readonlyAnnotations: null,
// Inputs
initialLabels: null,
@ -32,10 +34,9 @@ export default Component.extend(ManageLabels, {
init() {
this._super(...arguments);
this.initLabels(this.get('initialLabels'), 'user', null, this.get('readonlyLabels'));
this.labelsChanged();
this.initCounts();
this.initLablesAndAnnotations();
},
didReceiveAttrs() {
if (!this.get('expandFn')) {
this.set('expandFn', (item) => {
@ -82,6 +83,29 @@ export default Component.extend(ManageLabels, {
return this.get('intl').t(`${ STATUS_INTL_KEY }.${ k }`, { count });
}.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(){
let labels = this.get('model.labels');
let annotations = this.get('model.annotations');

View File

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

View File

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