-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(keymaps): add all the CRUD stuff for mappings
- Loading branch information
1 parent
3a2f8d9
commit 777b9ac
Showing
6 changed files
with
513 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package views | ||
|
||
import ( | ||
"strconv" | ||
"github.com/markbates/goth" | ||
"github.com/scottmckendry/mnemstart/data" | ||
) | ||
|
||
templ Mappings(user goth.User, mappings []data.Mapping) { | ||
<div id="modal" _="on closeModal add .closing then wait for animationend then remove me then go to location.reload()"> | ||
<div class="modal-underlay" _="on click trigger closeModal"></div> | ||
<div class="modal-content"> | ||
<h2>Mappings</h2> | ||
<table id="mappings-table"> | ||
<thead> | ||
<tr> | ||
<th>Keymap</th> | ||
<th>URL</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody hx-target="closest tr" hx-swap="outerHTML"> | ||
for _, mapping := range mappings { | ||
@MappingRow(&mapping) | ||
} | ||
<tr> | ||
<td colspan="3"> | ||
<button class="button" hx-get="/mappings/new" hx-swap="outerHTML">New Mapping</button> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<button class="button" _="on click trigger closeModal">Close</button> | ||
</div> | ||
</div> | ||
} | ||
|
||
templ MappingRow(mapping *data.Mapping) { | ||
<tr> | ||
<td>{ mapping.Keymap }</td> | ||
<td>{ mapping.MapsTo }</td> | ||
<td> | ||
<button | ||
class="button" | ||
hx-get={ "/mappings/edit/" + strconv.Itoa(mapping.ID) } | ||
hx-trigger="edit" | ||
onClick=" | ||
let editing = document.querySelector('.editing') | ||
if(editing) { | ||
htmx.trigger(editing, 'cancel') | ||
htmx.trigger(this, 'edit') | ||
} else { | ||
htmx.trigger(this, 'edit') | ||
}" | ||
>Edit</button> | ||
<button class="button" hx-delete={ "/mappings/delete/" + strconv.Itoa(mapping.ID) } hx-confirm="Are you sure?" hx-target="#mappings-table">Delete</button> | ||
</td> | ||
</tr> | ||
} | ||
|
||
templ NewMapping() { | ||
<tr> | ||
<td> | ||
<input type="text" id="keymap" name="keymap" data-include-add="" required/> | ||
</td> | ||
<td> | ||
<input type="text" id="mapsto" name="mapsto" data-include-add="" required/> | ||
</td> | ||
<td> | ||
<button class="button" hx-post="/mappings/add" hx-target="#mappings-table" hx-include="input[data-include-add]" hx-swap="outerHTML">Save</button> | ||
</td> | ||
</tr> | ||
} | ||
|
||
templ EditMapping(user goth.User, mapping *data.Mapping) { | ||
<tr hx-trigger="cancel" class="editing" hx-get={ "/mappings/" + strconv.Itoa(mapping.ID) }> | ||
<td> | ||
<input type="text" id="keymap" name="keymap" data-include-edit="" value={ mapping.Keymap } required/> | ||
</td> | ||
<td> | ||
<input type="text" id="mapsto" name="mapsto" data-include-edit="" value={ mapping.MapsTo } required/> | ||
</td> | ||
<td> | ||
<button class="button" hx-get={ "/mappings/" + strconv.Itoa(mapping.ID) }>Cancel</button> | ||
<button class="button" hx-put={ "/mappings/update/" + strconv.Itoa(mapping.ID) } hx-target="#mappings-table" hx-include="input[data-include-edit]">Save</button> | ||
</td> | ||
</tr> | ||
} |
Oops, something went wrong.