diff --git a/.gitignore b/.gitignore index e4194d8..2713e6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /isc_rest.log +/isc_data.db diff --git a/controllers/player_controller.go b/controllers/player_controller.go index eb0f95e..8940b1f 100644 --- a/controllers/player_controller.go +++ b/controllers/player_controller.go @@ -46,7 +46,7 @@ func GetPlayersByClanHTML(c *gin.Context) { var htmlOptions string for _, player := range players { - htmlOptions += fmt.Sprintf(playerItem, player.Name, player.ID) + htmlOptions += fmt.Sprintf(playerItem, player.Name, player.ID, player.ID) } c.Header("Content-Type", "text/html") @@ -124,13 +124,13 @@ func UpdatePlayerByID(c *gin.Context) { } } - msg := "Updating player '" + player.Name + "'#" + strconv.FormatUint(uint64(player.ID), 10) + msg := "Updating player '" + player.Name + "' #" + strconv.FormatUint(uint64(player.ID), 10) if player.Name != input.Name { msg += " (new: '" + input.Name + "')" } msg += " with clan #" + utils.UintToString(player.ClanID) if player.ClanID != input.ClanID { - msg += " (new: รค" + utils.UintToString(input.ClanID) + ")" + msg += " (new: #" + utils.UintToString(input.ClanID) + ")" } _, err := fmt.Fprintf(utils.GinWriter, msg+"\n") if err != nil { diff --git a/isc_data.db b/isc_data.db deleted file mode 100644 index ce19e86..0000000 Binary files a/isc_data.db and /dev/null differ diff --git a/main.go b/main.go index fc7b885..2538605 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,7 @@ func main() { "./templates/modals/edit_clan.html", "./templates/modals/add_player.html", "./templates/modals/delete_player.html", + "./templates/modals/edit_player.html", "./templates/components/header.html", } tmpl, err := template.ParseFiles(files...) diff --git a/models/player.go b/models/player.go index 4f65b5c..e042481 100644 --- a/models/player.go +++ b/models/player.go @@ -4,4 +4,5 @@ type Player struct { ID uint `json:"id" gorm:"primary_key"` Name string `json:"name"` ClanID uint `json:"clan_id"` + Clan Clan `gorm:"references:ID"` } diff --git a/static/index.js b/static/index.js index 075d833..d4bdf3f 100644 --- a/static/index.js +++ b/static/index.js @@ -44,7 +44,9 @@ function getClanLists(event) { function getPlayerLists(event) { const button = event.relatedTarget; - const playerListId = button.getAttribute('data-bs-list'); + let playerListId = button.getAttribute('data-bs-list'); + if (playerListId === null) + playerListId = '#' + button.closest('ul').parentElement.parentElement.id; const playerList = document.querySelector(playerListId); let otherPlayerListId; @@ -59,7 +61,9 @@ function getPlayerLists(event) { function getSelectedClan(event) { const button = event.relatedTarget; - const playerListId = button.getAttribute('data-bs-list'); + let playerListId = button.getAttribute('data-bs-list'); + if (playerListId === null) + playerListId = '#' + button.closest('ul').parentElement.parentElement.id; let clanListId; if (playerListId === '#home-player-list') diff --git a/templates/index.html b/templates/index.html index 7be7381..564cd1a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -42,6 +42,8 @@ {{ template "add_player" . }} {{ template "delete_player" . }} + +{{ template "edit_player" . }} + +{{ end }} \ No newline at end of file diff --git a/templates/player_list_item.html b/templates/player_list_item.html index b06d9b3..d4db368 100644 --- a/templates/player_list_item.html +++ b/templates/player_list_item.html @@ -5,7 +5,7 @@ %s