blob: b97a18784aa925eacb455c2276af08727ff85111 [file] [log] [blame]
gio778577f2024-04-29 09:44:38 +04001{{ define "task" }}
2{{ range . }}
3<li aria-busy="{{ eq .Status 1 }}">
4 {{ if eq .Status 3 }}<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><g fill="none"><circle cx="12" cy="12" r="8" fill="green" fill-opacity="0.25"/><path stroke="green" stroke-width="1.2" d="m8.5 11l2.894 2.894a.15.15 0 0 0 .212 0L19.5 6"/><path stroke="green" stroke-linecap="round" d="M19.358 10.547a7.5 7.5 0 1 1-3.608-5.042"/></g></svg>{{ end }}{{ .Title }}{{ if .Err }} - {{ .Err.Error }} {{ end }}
5 {{ if .Subtasks }}
6 <ul>
7 {{ template "task" .Subtasks }}
8 </ul>
9 {{ end }}
10</li>
11{{ end }}
12{{ end }}
13
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +040014{{ define "schema-form" }}
15 {{ $readonly := .ReadOnly }}
16 {{ $networks := .AvailableNetworks }}
17 {{ $data := .Data }}
gio44f621b2024-04-29 09:44:38 +040018 {{ range $f := .Schema.Fields }}
19 {{ $name := $f.Name }}
20 {{ $schema := $f.Schema }}
Giorgi Lekveishvilie009a5d2024-01-05 14:10:11 +040021 {{ if eq $schema.Kind 0 }}
gio44f621b2024-04-29 09:44:38 +040022 <label {{ if $schema.Advanced }}hidden{{ end }}>
23 <input type="checkbox" role="swtich" name="{{ $name }}" oninput="valueChanged({{ $name }}, this.checked)" {{ if $readonly }}disabled{{ end }} {{ if index $data $name }}checked{{ end }} />
24 {{ $schema.Name }}
Giorgi Lekveishvilie009a5d2024-01-05 14:10:11 +040025 </label>
Giorgi Lekveishvilib59b7c22024-04-03 22:17:50 +040026 {{ else if eq $schema.Kind 7 }}
gio44f621b2024-04-29 09:44:38 +040027 <label {{ if $schema.Advanced }}hidden{{ end }}>
28 {{ $schema.Name }}
29 <input type="text" name="{{ $name }}" oninput="valueChanged({{ $name }}, parseInt(this.value))" {{ if $readonly }}disabled{{ end }} value="{{ index $data $name }}" />
Giorgi Lekveishvilib59b7c22024-04-03 22:17:50 +040030 </label>
Giorgi Lekveishvilie009a5d2024-01-05 14:10:11 +040031 {{ else if eq $schema.Kind 1 }}
gio44f621b2024-04-29 09:44:38 +040032 <label {{ if $schema.Advanced }}hidden{{ end }}>
33 {{ $schema.Name }}
Giorgi Lekveishvilia09fad72024-03-21 15:24:35 +040034 <input type="text" name="{{ $name }}" oninput="valueChanged({{ $name }}, this.value)" {{ if $readonly }}disabled{{ end }} value="{{ index $data $name }}" />
Giorgi Lekveishvilie009a5d2024-01-05 14:10:11 +040035 {{ else if eq $schema.Kind 4 }}
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +040036 </label>
gio44f621b2024-04-29 09:44:38 +040037 <label {{ if $schema.Advanced }}hidden{{ end }}>
38 {{ $schema.Name }}
39 <input type="text" name="{{ $name }}" oninput="valueChanged({{ $name }}, this.value)" {{ if $readonly }}disabled{{ end }} value="{{ index $data $name }}" />
40 </label>
Giorgi Lekveishvili7c427602024-01-04 00:13:55 +040041 {{ else if eq $schema.Kind 3 }}
gio44f621b2024-04-29 09:44:38 +040042 <label {{ if $schema.Advanced }}hidden{{ end }}>
43 {{ $schema.Name }}
44 <select name="{{ $name }}" oninput="valueChanged({{ $name }}, this.value)" {{ if $readonly }}disabled{{ end }} >
45 {{ if not $readonly }}<option disabled selected value>Available networks</option>{{ end }}
46 {{ range $networks }}
47 <option {{if eq .Name (index $data $name) }}selected{{ end }}>{{ .Name }}</option>
48 {{ end }}
49 </select>
Giorgi Lekveishvilia09fad72024-03-21 15:24:35 +040050 </label>
Giorgi Lekveishvilia09fad72024-03-21 15:24:35 +040051 {{ else if eq $schema.Kind 5 }}
Giorgi Lekveishvilia09fad72024-03-21 15:24:35 +040052 {{ $auth := index $data $name }}
53 {{ $authEnabled := false }}
54 {{ $authGroups := "" }}
55 {{ if and $auth (index $auth "enabled") }}{{ $authEnabled = true }}{{ end }}
56 {{ if and $auth (index $auth "groups") }}{{ $authGroups = index $auth "groups" }}{{ end }}
gio44f621b2024-04-29 09:44:38 +040057 <label {{ if $schema.Advanced }}hidden{{ end }}>
58 <input type="checkbox" role="swtich" name="authEnabled" oninput="valueChanged('{{- $name -}}.enabled', this.checked)" {{ if $readonly }}disabled{{ end }} {{ if $authEnabled }}checked{{ end }} />
59 <span>Require authentication</span>
Giorgi Lekveishvilia09fad72024-03-21 15:24:35 +040060 </label>
gio44f621b2024-04-29 09:44:38 +040061 <label for="authGroups">
62 <span>Authentication groups</span>
63 <input type="text" name="authGroups" oninput="valueChanged('{{- $name -}}.groups', this.value)" {{ if $readonly }}disabled{{ end }} value="{{ $authGroups }}" />
64 </label>
Giorgi Lekveishvilib6a58062024-04-02 16:49:19 +040065 {{ else if eq $schema.Kind 6 }}
66 {{ $sshKey := index $data $name }}
67 {{ $public := "" }}
68 {{ $private := "" }}
69 {{ if $sshKey }}{{ $public = index $sshKey "public" }}{{ end }}
70 {{ if $sshKey }}{{ $private = index $sshKey "private" }}{{ end }}
gio44f621b2024-04-29 09:44:38 +040071 <label {{ if $schema.Advanced }}hidden{{ end }}>
72 <span>Public Key</span>
73 <textarea name="{{ $name }}-public" disabled>{{ $public }}</textarea>
Giorgi Lekveishvilib6a58062024-04-02 16:49:19 +040074 </label>
gio44f621b2024-04-29 09:44:38 +040075 <label {{ if $schema.Advanced }}hidden{{ end }}>
76 <span>Private Key</span>
77 <textarea name="{{ $name }}-private" disabled>{{ $private }}</textarea>
Giorgi Lekveishvilib6a58062024-04-02 16:49:19 +040078 </label>
Giorgi Lekveishvilia09fad72024-03-21 15:24:35 +040079 {{ end }}
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +040080 {{ end }}
81{{ end }}
82
Davit Tabidze3ec24cf2024-05-22 14:06:02 +040083{{ define "header" }}
84 <h1>{{ .App.Icon }}{{ .App.Name }}</h1>
85{{ end }}
gio18d5c682024-05-02 10:30:57 +040086
Davit Tabidze3ec24cf2024-05-22 14:06:02 +040087{{ define "extra_menu" }}
88 <li><a href="/app/{{ .App.Slug }}" class="{{ if eq $.CurrentPage .App.Name }}outline{{ else }}secondary{{ end }}">{{ .App.Name }}</a></li>
89 {{ range .Instances }}
90 <li><a href="/instance/{{ .Id }}" class="{{ if eq $.CurrentPage .Id }}outline{{ else }}secondary{{ end }}">{{ .Id }}</a></li>
gio778577f2024-04-29 09:44:38 +040091 {{ end }}
92{{ end }}
93
Davit Tabidze3ec24cf2024-05-22 14:06:02 +040094{{ define "content"}}
95 {{ $schema := .App.Schema }}
96 {{ $networks := .AvailableNetworks }}
97 {{ $instance := .Instance }}
98 {{ $renderForm := true }}
99
100 {{ if .Task }}
101 {{if or (eq .Task.Status 0) (eq .Task.Status 1) }}
102 {{ $renderForm = false }}
103 Waiting for resources:
104 <ul class="progress">
105 {{ template "task" .Task.Subtasks }}
106 </ul>
107 <script>setTimeout(() => location.reload(), 3000);</script>
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400108 {{ end }}
Davit Tabidze3ec24cf2024-05-22 14:06:02 +0400109 {{ end }}
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400110
Davit Tabidze3ec24cf2024-05-22 14:06:02 +0400111 {{ if $renderForm }}
112 <form id="config-form">
113 {{ if $instance }}
114 {{ template "schema-form" (dict "Schema" $schema "AvailableNetworks" $networks "ReadOnly" false "Data" ($instance.InputToValues $schema)) }}
115 {{ else }}
116 {{ template "schema-form" (dict "Schema" $schema "AvailableNetworks" $networks "ReadOnly" false "Data" (dict)) }}
117 {{ end }}
118 {{ if $instance }}
119 <div class="grid">
120 <button type="submit" id="submit" name="update">Update</button>
121 <button type="submit" id="uninstall" name="remove">Uninstall</button>
122 </div>
123 {{ else }}
124 <button type="submit" id="submit">{{ if $instance }}Update{{ else }}Install{{ end }}</button>
125 {{ end }}
126 </form>
gio778577f2024-04-29 09:44:38 +0400127 {{ end }}
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400128
129<div id="toast-failure" class="toast hidden">
130 <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2S2 6.477 2 12s4.477 10 10 10Zm3-6L9 8m0 8l6-8"/></svg> {{ if $instance }}Update failed{{ else}}Install failed{{ end }}
131</div>
132
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400133<div id="toast-uninstall-failure" class="toast hidden">
134 <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2S2 6.477 2 12s4.477 10 10 10Zm3-6L9 8m0 8l6-8"/></svg> Failed to uninstall application
135</div>
136
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400137<script>
gio3cdee592024-04-17 10:15:56 +0400138 let config = {{ if $instance }}JSON.parse({{ toJson ($instance.InputToValues $schema) }}){{ else }}{}{{ end }};
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400139
Giorgi Lekveishvilia09fad72024-03-21 15:24:35 +0400140 function setValue(name, value, config) {
141 let items = name.split(".")
142 for (let i = 0; i < items.length - 1; i++) {
143 if (!(items[i] in config)) {
144 config[items[i]] = {}
145 }
146 config = config[items[i]];
147 }
148 config[items[items.length - 1]] = value;
149}
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400150 function valueChanged(name, value) {
Giorgi Lekveishvilia09fad72024-03-21 15:24:35 +0400151 setValue(name, value, config);
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400152 }
153
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400154 function disableForm() {
155 document.querySelectorAll("#config-form input").forEach((i) => i.setAttribute("disabled", ""));
156 document.querySelectorAll("#config-form select").forEach((i) => i.setAttribute("disabled", ""));
157 document.querySelectorAll("#config-form button").forEach((i) => i.setAttribute("disabled", ""));
158 }
159
160 function enableForm() {
161 document.querySelectorAll("[aria-busy]").forEach((i) => i.removeAttribute("aria-busy"));
162 document.querySelectorAll("#config-form input").forEach((i) => i.removeAttribute("disabled"));
163 document.querySelectorAll("#config-form select").forEach((i) => i.removeAttribute("disabled"));
164 document.querySelectorAll("#config-form button").forEach((i) => i.removeAttribute("disabled"));
165 }
166
167 function installStarted() {
168 const submit = document.getElementById("submit");
169 submit.setAttribute("aria-busy", true);
170 submit.innerHTML = {{ if $instance }}"Updating ..."{{ else }}"Installing ..."{{ end }};
171 disableForm();
172 }
173
174 function uninstallStarted() {
175 const submit = document.getElementById("uninstall");
176 submit.setAttribute("aria-busy", true);
177 submit.innerHTML = "Uninstalling ...";
178 disableForm();
179 }
180
181 function actionFinished(toast) {
182 enableForm();
183 toast.classList.remove("hidden");
184 setTimeout(
185 () => toast.classList.add("hidden"),
186 2000,
187 );
188 }
189
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400190 function installFailed() {
191 actionFinished(document.getElementById("toast-failure"));
192 }
193
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400194 function uninstallFailed() {
195 actionFinished(document.getElementById("toast-uninstall-failure"));
196 }
197
gio44f621b2024-04-29 09:44:38 +0400198 const submitAddr = {{ if $instance }}"/api/instance/{{ $instance.Id }}/update"{{ else }}"/api/app/{{ .App.Slug }}/install"{{ end }};
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400199
200 async function install() {
201 installStarted();
202 const resp = await fetch(submitAddr, {
gio778577f2024-04-29 09:44:38 +0400203 method: "POST",
204 headers: {
205 "Content-Type": "application/json",
206 "Accept": "application/json",
207 },
208 body: JSON.stringify(config),
209 });
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400210 if (resp.status === 200) {
gio778577f2024-04-29 09:44:38 +0400211 window.location = await resp.text();
212 } else {
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400213 installFailed();
214 }
215 }
216
217 async function uninstall() {
218 {{ if $instance }}
219 uninstallStarted();
220 const resp = await fetch("/api/instance/{{ $instance.Id }}/remove", {
221 method: "POST",
222 });
223 if (resp.status === 200) {
gio778577f2024-04-29 09:44:38 +0400224 window.location = await resp.text();
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400225 } else {
226 uninstallFailed();
227 }
228 {{ end }}
229 }
230
231 document.getElementById("config-form").addEventListener("submit", (event) => {
232 event.preventDefault();
233 if (event.submitter.id === "submit") {
234 install();
235 } if (event.submitter.id === "uninstall") {
236 uninstall();
237 }
238 });
239</script>
Davit Tabidze3ec24cf2024-05-22 14:06:02 +0400240
241{{end}}