/
qwc-kubernetes-manifest.js
108 lines (94 loc) · 2.98 KB
/
qwc-kubernetes-manifest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { LitElement, html, css} from 'lit';
import { JsonRpc } from 'jsonrpc';
import 'qui-code-block';
import '@vaadin/icon';
import '@vaadin/tabs';
import '@vaadin/tabsheet';
import '@vaadin/progress-bar';
export class QwcKubernetesManifest extends LitElement {
jsonRpc = new JsonRpc(this);
// Component style
static styles = css`
.codeBlock {
display:flex;
gap: 10px;
flex-direction: column;
padding-left: 10px;
padding-right: 10px;
}
`;
// Component properties
static properties = {
// Name -> Content
_manifests: {state: true, type: Map},
_message: {state: true}
}
// Components callbacks
/**
* Called when displayed
*/
connectedCallback() {
super.connectedCallback();
this._message = "Generating Kubernetes manifests...";
this.jsonRpc.generateManifests().then(jsonRpcResponse => {
const data = JSON.parse(jsonRpcResponse.result);
var m = new Map();
for (const key in data) {
m.set(key, data[key]);
}
this._manifests = m;
this._message = "No manifests generated.";
});
}
/**
* Called when it needs to render the components
* @returns {*}
*/
render() {
if (this._manifests) {
if (this._manifests.size == 0) {
return html`
<div style="color: var(--lumo-secondary-text-color);width: 95%;" >
<div>${this._message}</div>
</div>
`;
}
return html`
<vaadin-tabsheet>
<vaadin-tabs slot="tabs">
${this._renderFileName()}
</vaadin-tabs>
${this._renderContent()}
</vaadin-tabsheet>
`;
}
return html`
<div style="color: var(--lumo-secondary-text-color);width: 95%;" >
<div>${this._message}</div>
<vaadin-progress-bar indeterminate></vaadin-progress-bar>
</div>
`;
}
_renderFileName(){
let keys = Array.from( this._manifests.keys() );
return html`${keys.map((key) =>
html`<vaadin-tab id="${key}">${key}</vaadin-tab>`
)}`;
}
_renderContent(){
let keys = Array.from( this._manifests.keys() );
return html`${keys.map((key) =>
html`<div tab="${key}">${this._renderYaml(key)}</div>`
)}`;
}
_renderYaml(key){
let yaml = this._manifests.get(key);
return html`<div class="codeBlock">
<qui-code-block
mode='yaml'
content='${yaml}'>
</qui-code-block>
</div>`;
}
}
customElements.define('qwc-kubernetes-manifest', QwcKubernetesManifest);