DEVELOPMENT ENVIRONMENT

~liljamo/felu

ref: 0.1.6 felu/internal/components/managepartials_templ.go -rw-r--r-- 8.5 KiB
8c173e8fJonni Liljamo feat: manual updating of A records 1 year, 14 days ago
                                                                                
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Code generated by templ@(devel) DO NOT EDIT.

package components

//lint:file-ignore SA4006 This context is only used if a nested component is present.

import "github.com/a-h/templ"
import "context"
import "io"
import "bytes"

import "git.src.quest/~skye/felu-ddns/internal/db"
import "fmt"

func toggleApiKeyVisibility(id string) templ.ComponentScript {
	return templ.ComponentScript{
		Name: `__templ_toggleApiKeyVisibility_542b`,
		Function: `function __templ_toggleApiKeyVisibility_542b(id){var input = document.getElementById("domain_apikey_" + id);
	var eye_vis = document.getElementById("domain_eye_vis_" + id);
	var eye_hid = document.getElementById("domain_eye_hid_" + id);
	if (input.type === "password") {
		input.type = "text";
	} else {
		input.type = "password";
	};
	eye_vis.classList.toggle("hidden");
	eye_hid.classList.toggle("hidden");}`,
		Call: templ.SafeScript(`__templ_toggleApiKeyVisibility_542b`, id),
	}
}

func ManagePartialDomains(domains []db.Domain) templ.Component {
	return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
		templBuffer, templIsBuffer := w.(*bytes.Buffer)
		if !templIsBuffer {
			templBuffer = templ.GetBuffer()
			defer templ.ReleaseBuffer(templBuffer)
		}
		ctx = templ.InitializeContext(ctx)
		var_1 := templ.GetChildren(ctx)
		if var_1 == nil {
			var_1 = templ.NopComponent
		}
		ctx = templ.ClearChildren(ctx)
		if len(domains) > 0 {
			_, err = templBuffer.WriteString("<table class=\"table-auto\"><thead><tr><th class=\"text-start p-2\">")
			if err != nil {
				return err
			}
			var_2 := `Domain`
			_, err = templBuffer.WriteString(var_2)
			if err != nil {
				return err
			}
			_, err = templBuffer.WriteString("</th><th class=\"text-start p-2\">")
			if err != nil {
				return err
			}
			var_3 := `A Record`
			_, err = templBuffer.WriteString(var_3)
			if err != nil {
				return err
			}
			_, err = templBuffer.WriteString("</th><th class=\"text-start p-2\">")
			if err != nil {
				return err
			}
			var_4 := `Api Key`
			_, err = templBuffer.WriteString(var_4)
			if err != nil {
				return err
			}
			_, err = templBuffer.WriteString("</th></tr></thead><tbody>")
			if err != nil {
				return err
			}
			for _, domain := range domains {
				_, err = templBuffer.WriteString("<tr class=\"border\"><td><div class=\"p-2\"><span class=\"font-bold\">")
				if err != nil {
					return err
				}
				var var_5 string = domain.Domain
				_, err = templBuffer.WriteString(templ.EscapeString(var_5))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("</span><span class=\"\">")
				if err != nil {
					return err
				}
				var var_6 string = getDomainPattern()
				_, err = templBuffer.WriteString(templ.EscapeString(var_6))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("</span></div></td><td><div class=\"p-2 flex flex-col\"><form class=\"flex items-center gap-1\" hx-patch=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(fmt.Sprintf("/manage/domains/%s", domain.Id)))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\" hx-target=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(fmt.Sprintf("#domain_patch_error_%s", domain.Id)))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\" hx-confirm=\"Apply?\"><input class=\"border\" type=\"text\" name=\"a_record\" value=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(domain.A))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\"><button class=\"border p-1\" type=\"submit\"><svg class=\"w-5 h-5\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M4 12.6111L8.92308 17.5L20 6.5\" stroke=\"black\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path></svg></button></form><div class=\"text-rose-600 text-center\" id=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(fmt.Sprintf("domain_patch_error_%s", domain.Id)))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\"></div></div></td><td><div class=\"p-2 flex items-center gap-1\"><input class=\"border\" disabled type=\"password\" value=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(domain.ApiKey))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\" id=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(fmt.Sprintf("domain_apikey_%s", domain.Id)))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\"><div class=\"border p-1 flex items-center justify-center\">")
				if err != nil {
					return err
				}
				err = templ.RenderScriptItems(ctx, templBuffer, toggleApiKeyVisibility(domain.Id))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("<input class=\"absolute w-6 h-6 appearance-none cursor-pointer\" type=\"checkbox\" onClick=\"")
				if err != nil {
					return err
				}
				var var_7 templ.ComponentScript = toggleApiKeyVisibility(domain.Id)
				_, err = templBuffer.WriteString(var_7.Call)
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\"><div><svg id=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(fmt.Sprintf("domain_eye_vis_%s", domain.Id)))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\" class=\"hidden w-5 h-5\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M15.0007 12C15.0007 13.6569 13.6576 15 12.0007 15C10.3439 15 9.00073 13.6569 9.00073 12C9.00073 10.3431 10.3439 9 12.0007 9C13.6576 9 15.0007 10.3431 15.0007 12Z\" stroke=\"black\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path><path d=\"M12.0012 5C7.52354 5 3.73326 7.94288 2.45898 12C3.73324 16.0571 7.52354 19 12.0012 19C16.4788 19 20.2691 16.0571 21.5434 12C20.2691 7.94291 16.4788 5 12.0012 5Z\" stroke=\"black\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path></svg><svg id=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(fmt.Sprintf("domain_eye_hid_%s", domain.Id)))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\" class=\"w-5 h-5\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M2.99902 3L20.999 21M9.8433 9.91364C9.32066 10.4536 8.99902 11.1892 8.99902 12C8.99902 13.6569 10.3422 15 11.999 15C12.8215 15 13.5667 14.669 14.1086 14.133M6.49902 6.64715C4.59972 7.90034 3.15305 9.78394 2.45703 12C3.73128 16.0571 7.52159 19 11.9992 19C13.9881 19 15.8414 18.4194 17.3988 17.4184M10.999 5.04939C11.328 5.01673 11.6617 5 11.9992 5C16.4769 5 20.2672 7.94291 21.5414 12C21.2607 12.894 20.8577 13.7338 20.3522 14.5\" stroke=\"black\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path></svg></div></div><button class=\"border p-1\" hx-confirm=\"Refresh?\" hx-post=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(fmt.Sprintf("/manage/domains/%s/api_key", domain.Id)))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\"><svg class=\"w-5 h-5\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M11.5 20.5C6.80558 20.5 3 16.6944 3 12C3 7.30558 6.80558 3.5 11.5 3.5C16.1944 3.5 20 7.30558 20 12C20 13.5433 19.5887 14.9905 18.8698 16.238M22.5 15L18.8698 16.238M17.1747 12.3832L18.5289 16.3542L18.8698 16.238\" stroke=\"black\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path></svg></button></div></td><td><div class=\"p-2\"><button class=\"border p-1\" hx-confirm=\"Sure?\" hx-delete=\"")
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString(templ.EscapeString(fmt.Sprintf("/manage/domains/%s", domain.Id)))
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("\">")
				if err != nil {
					return err
				}
				var_8 := `Delete`
				_, err = templBuffer.WriteString(var_8)
				if err != nil {
					return err
				}
				_, err = templBuffer.WriteString("</button></div></td></tr>")
				if err != nil {
					return err
				}
			}
			_, err = templBuffer.WriteString("</tbody></table>")
			if err != nil {
				return err
			}
		}
		if !templIsBuffer {
			_, err = templBuffer.WriteTo(w)
		}
		return err
	})
}