Skip to content

Commit

Permalink
Select Category fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomog committed Jan 18, 2024
1 parent 3f906a9 commit be40c37
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
8 changes: 7 additions & 1 deletion internal/handler/moderPanelHanlder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"net/http"
"strconv"

Expand Down Expand Up @@ -38,9 +39,13 @@ func handlePostRequestModerPage(w http.ResponseWriter, r *http.Request, m *Repos
return
}

selectedCategory := r.FormValue("btnradio")
topicID := r.FormValue("topicID")
selectedCategory := r.FormValue("btnradio" + topicID)

if r.FormValue("postID") != "" {
postIDF := r.FormValue("postID")
selectedCategory := r.FormValue("btnradio" + postIDF)

postID, err := strconv.Atoi(r.FormValue("postID"))
if err != nil {
setErrorAndRedirect(w, r, "Could not convert string into int "+err.Error(), "/error-page")
Expand Down Expand Up @@ -72,6 +77,7 @@ func handlePostRequestModerPage(w http.ResponseWriter, r *http.Request, m *Repos
return
}
cat := models.TextClassification(selectedCategory)
fmt.Println("selectedCategory", cat)

err = m.DB.EditTopicClassification(topic, cat)
if err != nil {
Expand Down
73 changes: 36 additions & 37 deletions template/moderMain.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,41 @@ <h2>Select Posts Category:</h2>

{{if $posts}}
<div>
<tbody class="containerBody">
{{ range $posts }}
{{$postsCategory := .Classification}}
{{$postID := .ID}}
<tr>
<td>
<br>Created by user with ID: {{ .UserID}}
<br>Topic created: {{convertTime . }}
<br>Category: {{ .Classification}}
<br><em>{{ .Subject }} </em>
<br><strong>{{ .Content }} </strong>
</td>
<tbody class="containerBody">
<tr>
<td>
<form method="post" action="">
{{range $index, $category := $categories}}
<div class="btn-group" role="group" aria-label="Basic radio toggle button group">
<input type="radio" class="btn-check" name="btnradio" id="btnradio{{$index}}"
autocomplete="off" value="{{$category}}" {{ if eq $category $postsCategory }}
checked {{end}}>
<label class="btn btn-outline-primary" for="btnradio{{$index}}"> {{$category}} </label>
<input type="hidden" name="postID" value="{{ $postID }}">
</div>
{{end}}
<input type="submit" value="Submit">
</form>

</td>
</tr>
<tbody class="containerBody">
{{ range $posts }}
{{$postsCategory := .Classification}}
{{$postID := .ID}}
<tr>
<td>
<br>Created by user with ID: {{ .UserID}}
<br>Topic created: {{convertTime . }}
<br>Category: {{ .Classification}}
<br><em>{{ .Subject }} </em>
<br><strong>{{ .Content }} </strong>
</td>
</tr>
<tr>
<td>
<form method="post" action="">
{{range $index, $category := $categories}}
<div class="btn-group" role="group" aria-label="Basic radio toggle button group">
<input type="radio" class="btn-check" name="btnradio{{$postID}}" id="btnradio{{$postID}}{{$index}}"
autocomplete="off" value="{{$category}}" {{ if eq $category $postsCategory }}
checked {{end}}>
<label class="btn btn-outline-primary" for="btnradio{{$postID}}{{$index}}"> {{$category}} </label>
</div>
{{end}}
<input type="hidden" name="postID" value="{{ $postID }}">
<input type="submit" value="Submit">
</form>
</td>
</tr>
<tr>
<td><hr></td>
</tr>
{{ end }}
</tbody>

</tbody>
<hr>
</tr>
{{ end }}
</tbody>

{{ end }}

Expand All @@ -104,10 +103,10 @@ <h2>Select Posts Category:</h2>
<form method="post" action="">
{{range $index, $category := $categories}}
<div class="btn-group" role="group" aria-label="Basic radio toggle button group">
<input type="radio" class="btn-check" name="btnradio" id="btnradio{{$index}}"
<input type="radio" class="btn-check" name="btnradio{{$topicID}}" id="btnradio{{$topicID}}{{$index}}"
autocomplete="off" value="{{$category}}" {{ if eq $category $topicCategory }}
checked {{end}}>
<label class="btn btn-outline-primary" for="btnradio{{$index}}"> {{$category}} </label>
<label class="btn btn-outline-primary" for="btnradio{{$topicID}}{{$index}}"> {{$category}} </label>
<input type="hidden" name="topicID" value="{{ $topicID }}">
</div>
{{end}}
Expand Down

0 comments on commit be40c37

Please sign in to comment.