Skip to content

Commit

Permalink
#EHA-33 Form and controller Get function for filtering veterinarian n…
Browse files Browse the repository at this point in the history
…ame is added.
  • Loading branch information
beyzaaydeniz committed Jan 3, 2024
1 parent cb0f7f8 commit b38d096
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;


@Controller
@RequestMapping("/api/veterinarians")
Expand Down Expand Up @@ -90,6 +92,25 @@ public ResponseEntity<List<VeterinarianDTO>> getAllVeterinarians() {
public String desktop(Model model) {
List<VeterinarianDTO> veterinarians = veterinarianService.getAllVeterinarians();
model.addAttribute("veterinarians", veterinarians);
model.addAttribute("viewType", "default");
return "desktop";
}

@PostMapping("/desktop")
public String desktopFormSubmit(@RequestParam String clinicName, RedirectAttributes redirectAttributes) {
// Redirect to the URL with the user-provided clinicName
redirectAttributes.addAttribute("name", clinicName);
return "redirect:/api/veterinarians/desktop/{name}";
}

@GetMapping("/desktop/{name}")
public String desktop(@PathVariable String name, Model model) {
List<VeterinarianDTO> filteredVeterinarians = veterinarianService.getVeterinariansByClinic(name);
if(filteredVeterinarians==null){
return null;
}
model.addAttribute("filteredVeterinarians", filteredVeterinarians);
model.addAttribute("viewType", "filtered");
return "desktop";
}

Expand Down
53 changes: 22 additions & 31 deletions src/main/resources/templates/desktop.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@
Veterinary List
</div>
</div>

<form th:action="@{/api/veterinarians/desktop}" method="post">
<label for="clinicName">Name:</label>
<input type="text" id="clinicName" name="clinicName" required>
<button type="submit" style="background-color: #2A3240; border: none; color: white;">Filter</button>
</form>
<div class="Content" style="width: 80%; height: 849px; padding-top: 24px; padding-bottom: 85px; padding-left: 24px; padding-right: 24px; flex-direction: column; justify-content: flex-start; align-items: center; gap: 24px; display: flex">
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#filter-vet-modal" style="position: fixed; bottom: 2.5em; right: 2.5em; background-color: #1B85F3; border: none; color: white;">
Filter Veterinarian
</button>
<table class="table table-hover table-sm" style="width: 100%; text-align: center;">

<table th:if="${viewType == 'default'}" class="table table-hover table-sm" style="width: 100%; text-align: center;">
<thead>
<tr class="table-active">
<th>Name</th>
Expand All @@ -84,33 +86,22 @@
</tr>
</tbody>
</table>
<table th:if="${viewType == 'filtered'}" class="table table-hover table-sm" style="width: 100%; text-align: center;">
<thead>
<tr class="table-active">
<th>Name</th>
<th>Clinic Name</th>
<th colspan="2">Delete</th>
</tr>
</thead>
<tbody style="text-align: center;">
<tr th:each="filteredvet : ${filteredVeterinarians}">
<td th:text="${filteredvet.user.name}"></td>
<td th:text="${filteredvet.clinic}"></td>
</tr>
</tbody>
</table>

<!-- FILTER -->
<div class="modal fade" id="filter-vet-modal" tabindex="-1" aria-labelledby="filter-vet-modal-label" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="filter-vet-modal-label">Search</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body"><form action="/filter_vet" method="POST">
<label class="form-label">Name:</label>
<input type="text" class="form-control" name="fname">

<label class="form-label">Clinic:</label>
<input type="text" class="form-control" name="fclinic">

<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-warning" style="background-color: #1B85F3; border: none; color: white;">
Filter
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit b38d096

Please sign in to comment.