ui/lib/shared/addon/components/form-ssl-termination/component.js

76 lines
1.9 KiB
JavaScript

import { get, set, observer, computed } from '@ember/object';
import { not } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import layout from './template';
export default Component.extend({
layout,
intl: service(),
editing: null,
ingress: null,
namespacedCertificates: null,
namespace: null,
certificates: null,
certs: null,
init() {
this._super(...arguments);
const certs = get(this, 'ingress.tls') || [];
set(this, 'certs', certs);
},
actions: {
removeCert(cert) {
get(this, 'certs').removeObject(cert);
},
addCert() {
get(this, 'certs').pushObject({
certificateId: '',
hosts: []
});
},
},
didReceiveAttrs() {
if (!this.get('expandFn')) {
this.set('expandFn', function (item) {
item.toggleProperty('expanded');
});
}
},
didInsertElement: function () {
if (get(this, 'editing') && get(this, 'certs.length') === 0) {
this.send('addCert');
}
},
inputDidChange: observer('certs.@each.{certificateId,hosts}', function () {
const certs = get(this, 'certs').filter(cert => cert.certificateId).map(cert => {
return {
certificateId: cert.certificateId,
hosts: cert.hosts,
};
});
set(this, 'ingress.tls', certs)
}),
allCertificates: computed('namespacedCertificates.[]', 'certificates.[]', 'namespace', function () {
const out = [];
const namespacedCertificates = (get(this, 'namespacedCertificates') || []).filter(c => {
const selectedNamespace = get(this, 'namespace.id');
return selectedNamespace === c.namespaceId;
});
out.pushObjects(namespacedCertificates.toArray());
out.pushObjects((get(this, 'certificates') || []).toArray());
return out;
}),
statusClass: null,
status: null,
});