This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkube-new-service.html
112 lines (101 loc) · 3.18 KB
/
kube-new-service.html
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
109
110
111
112
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-fab/paper-fab.html">
<link rel="import" href="kube-card.html">
<link rel="import" href="kube-new-container.html">
<polymer-element name="kube-new-service" attributes="core label">
<template>
<style>
:host {
display: block;
}
kube-card {
width: 20%;
}
kube-card paper-input {
width: 100%;
}
paper-fab {
color: #ffffff;
}
.actions > paper-button {
color: #4285f4;
fill: #4285f4;
}
</style>
<kube-card icon="settings-ethernet" top="{{label}}">
<main>
<paper-input floatingLabel required
label="Service ID: myService" value="{{data.id}}">
</paper-input>
<paper-input floatingLabel multiline
label="Labels: stage=dev, kind=frontend" value="{{data.labels}}">
</paper-input>
<paper-input floatingLabel multiline required
label="Selector: name=myPods" value="{{data.selector}}">
</paper-input>
<paper-input floatingLabel required type="number"
label="Host Port: 8080" value="{{data.port}}">
</paper-input>
<paper-input floatingLabel required type="number"
label="Container Port: 80" value="{{data.containerPort}}">
</paper-input>
</main>
</kube-card>
<section class="actions">
<paper-button label="Create" on-click="{{create}}"></paper-button>
</section>
</template>
<script>
Polymer({
label: 'New Service',
data: {
id: 'my-service',
labels: '',
selector: 'name=myPods',
port: 8080,
containerPort: 80
},
create: function() {
if (!this.core) {
return;
};
var srv = {
id: this.data.id.toLowerCase(),
labels: {},
selector: {},
port: parseInt(this.data.port),
containerPort: parseInt(this.data.containerPort)
};
var labels = this.data.labels.
replace(/, +/g, ',').
split(/[, ]/).
filter(function(e) { return e.indexOf('=') > 0 }) || [];
for (var i=0, l; l = labels[i]; i++) {
var parts = l.split('=');
srv.labels[parts[0]] = parts[1];
}
if (!srv.labels['name']) {
srv.labels['name'] = this.data.id;
}
var selector = this.data.selector.
replace(/, +/g, ',').
split(/[, ]/).
filter(function(e) { return e.indexOf('=') > 0 }) || [];
for (var i=0, l; l = selector[i]; i++) {
var parts = l.split('=');
srv.selector[parts[0]] = parts[1];
}
this.core.createService({
callback: this.handleCreateResponse.bind(this)
}, srv);
},
handleCreateResponse: function(resp, isError) {
var evtName = isError ? 'kube-service-create-error' : 'kube-service-created';
this.fire(evtName, resp);
}
});
</script>
</polymer-element>