Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public record ActivityDTO(
int maxParticipants,
List<String> participants,
int currentParticipantCount,
ActivityTypeDTO type) {
ActivityTypeDTO type,
DifficultyLevelDTO difficultyLevel) {
public record ScheduleDetailsDTO(
List<String> days,
String startTime,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mergingtonhigh.schoolmanagement.application.dtos;

/**
* DTO for difficulty level data transfer.
*/
public record DifficultyLevelDTO(
String name,
String label) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.mongodb.core.mapping.Document;

import com.mergingtonhigh.schoolmanagement.domain.valueobjects.ActivityType;
import com.mergingtonhigh.schoolmanagement.domain.valueobjects.DifficultyLevel;
import com.mergingtonhigh.schoolmanagement.domain.valueobjects.Email;
import com.mergingtonhigh.schoolmanagement.domain.valueobjects.ScheduleDetails;

Expand All @@ -24,20 +25,27 @@ public class Activity {
private int maxParticipants;
private List<String> participants;
private ActivityType type;
private DifficultyLevel difficultyLevel;

public Activity() {
this.participants = new ArrayList<>();
}

public Activity(String name, String description, String schedule,
ScheduleDetails scheduleDetails, int maxParticipants, ActivityType type) {
this(name, description, schedule, scheduleDetails, maxParticipants, type, null);
}

public Activity(String name, String description, String schedule,
ScheduleDetails scheduleDetails, int maxParticipants, ActivityType type, DifficultyLevel difficultyLevel) {
this.name = validateName(name);
this.description = validateDescription(description);
this.schedule = schedule;
this.scheduleDetails = scheduleDetails;
this.maxParticipants = validateMaxParticipants(maxParticipants);
this.participants = new ArrayList<>();
this.type = type != null ? type : ActivityType.determineFromContent(name, description);
this.difficultyLevel = difficultyLevel;
}

public boolean canAddParticipant() {
Expand Down Expand Up @@ -146,4 +154,12 @@ public ActivityType getType() {
public void setType(ActivityType type) {
this.type = type != null ? type : ActivityType.determineFromContent(this.name, this.description);
}

public DifficultyLevel getDifficultyLevel() {
return difficultyLevel;
}

public void setDifficultyLevel(DifficultyLevel difficultyLevel) {
this.difficultyLevel = difficultyLevel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mergingtonhigh.schoolmanagement.domain.valueobjects;

/**
* Enum representing the different difficulty levels of activities.
* Each level has a label for display purposes.
*/
public enum DifficultyLevel {
BEGINNER("Iniciante"),
INTERMEDIATE("Intermediário"),
ADVANCED("Avançado");

private final String label;

DifficultyLevel(String label) {
this.label = label;
}

public String getLabel() {
return label;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.mergingtonhigh.schoolmanagement.domain.entities.Activity;
import com.mergingtonhigh.schoolmanagement.domain.entities.Teacher;
import com.mergingtonhigh.schoolmanagement.domain.valueobjects.ActivityType;
import com.mergingtonhigh.schoolmanagement.domain.valueobjects.DifficultyLevel;
import com.mergingtonhigh.schoolmanagement.domain.valueobjects.ScheduleDetails;

import io.mongock.api.annotations.ChangeUnit;
Expand Down Expand Up @@ -70,15 +71,16 @@ private void seedActivities() {
chessClub.setParticipants(List.of("michael@mergington.edu", "daniel@mergington.edu"));
mongoTemplate.save(chessClub);

// Aula de Programação
// Aula de Programação - Intermediário
Activity programmingClass = new Activity(
"Aula de Programação",
"Aprenda fundamentos de programação e desenvolva projetos de software",
"Terças e quintas-feiras, 07:00 - 08:00",
new ScheduleDetails(List.of("Tuesday", "Thursday"), LocalTime.of(7, 0),
LocalTime.of(8, 0)),
20,
ActivityType.TECHNOLOGY);
ActivityType.TECHNOLOGY,
DifficultyLevel.INTERMEDIATE);
programmingClass.setParticipants(List.of("emma@mergington.edu", "sophia@mergington.edu"));
mongoTemplate.save(programmingClass);

Expand Down Expand Up @@ -118,14 +120,15 @@ private void seedActivities() {
basketballTeam.setParticipants(List.of("ava@mergington.edu", "mia@mergington.edu"));
mongoTemplate.save(basketballTeam);

// Clube de Arte
// Clube de Arte - Iniciante
Activity artClub = new Activity(
"Clube de Arte",
"Explore diversas técnicas artísticas e crie obras-primas",
"Quintas-feiras, 15:15 - 17:00",
new ScheduleDetails(List.of("Thursday"), LocalTime.of(15, 15), LocalTime.of(17, 0)),
15,
ActivityType.ARTS);
ActivityType.ARTS,
DifficultyLevel.BEGINNER);
artClub.setParticipants(List.of("amelia@mergington.edu", "harper@mergington.edu"));
mongoTemplate.save(artClub);

Expand Down Expand Up @@ -163,25 +166,27 @@ private void seedActivities() {
debateTeam.setParticipants(List.of("charlotte@mergington.edu", "amelia@mergington.edu"));
mongoTemplate.save(debateTeam);

// Oficina de Robótica
// Oficina de Robótica - Avançado
Activity roboticsWorkshop = new Activity(
"Oficina de Robótica",
"Construa e programe robôs em nossa oficina de última geração",
"Sábados, 10:00 - 14:00",
new ScheduleDetails(List.of("Saturday"), LocalTime.of(10, 0), LocalTime.of(14, 0)),
15,
ActivityType.TECHNOLOGY);
ActivityType.TECHNOLOGY,
DifficultyLevel.ADVANCED);
roboticsWorkshop.setParticipants(List.of("ethan@mergington.edu", "oliver@mergington.edu"));
mongoTemplate.save(roboticsWorkshop);

// Olimpíada de Ciências
// Olimpíada de Ciências - Avançado
Activity scienceOlympiad = new Activity(
"Olimpíada de Ciências",
"Preparação para competições científicas regionais e estaduais aos fins de semana",
"Sábados, 13:00 - 16:00",
new ScheduleDetails(List.of("Saturday"), LocalTime.of(13, 0), LocalTime.of(16, 0)),
18,
ActivityType.ACADEMIC);
ActivityType.ACADEMIC,
DifficultyLevel.ADVANCED);
scienceOlympiad.setParticipants(List.of("isabella@mergington.edu", "lucas@mergington.edu"));
mongoTemplate.save(scienceOlympiad);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.mergingtonhigh.schoolmanagement.application.dtos.ActivityDTO;
import com.mergingtonhigh.schoolmanagement.application.dtos.ActivityTypeDTO;
import com.mergingtonhigh.schoolmanagement.application.dtos.DifficultyLevelDTO;
import com.mergingtonhigh.schoolmanagement.domain.entities.Activity;

/**
Expand Down Expand Up @@ -34,6 +35,13 @@ public ActivityDTO toDTO(Activity activity) {
activity.getType().getTextColor());
}

DifficultyLevelDTO difficultyLevelDTO = null;
if (activity.getDifficultyLevel() != null) {
difficultyLevelDTO = new DifficultyLevelDTO(
activity.getDifficultyLevel().name().toLowerCase(),
activity.getDifficultyLevel().getLabel());
}

return new ActivityDTO(
activity.getName(),
activity.getDescription(),
Expand All @@ -42,6 +50,7 @@ public ActivityDTO toDTO(Activity activity) {
activity.getMaxParticipants(),
activity.getParticipants(),
activity.getCurrentParticipantCount(),
typeDTO);
typeDTO,
difficultyLevelDTO);
}
}
55 changes: 55 additions & 0 deletions src/main/resources/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ document.addEventListener("DOMContentLoaded", () => {
const categoryFilters = document.querySelectorAll(".category-filter");
const dayFilters = document.querySelectorAll(".day-filter");
const timeFilters = document.querySelectorAll(".time-filter");
const difficultyFilters = document.querySelectorAll(".difficulty-filter");

// Authentication elements
const loginButton = document.getElementById("login-button");
Expand All @@ -33,6 +34,7 @@ document.addEventListener("DOMContentLoaded", () => {
let searchQuery = "";
let currentDay = "";
let currentTimeRange = "";
let currentDifficulty = "";

// Authentication state
let currentUser = null;
Expand All @@ -57,6 +59,12 @@ document.addEventListener("DOMContentLoaded", () => {
if (activeTimeFilter) {
currentTimeRange = activeTimeFilter.dataset.time;
}

// Initialize difficulty filter
const activeDifficultyFilter = document.querySelector(".difficulty-filter.active");
if (activeDifficultyFilter) {
currentDifficulty = activeDifficultyFilter.dataset.difficulty;
}
}

// Function to set day filter
Expand Down Expand Up @@ -91,6 +99,22 @@ document.addEventListener("DOMContentLoaded", () => {
fetchActivities();
}

// Function to set difficulty filter
function setDifficultyFilter(difficulty) {
currentDifficulty = difficulty;

// Update active class
difficultyFilters.forEach((btn) => {
if (btn.dataset.difficulty === difficulty) {
btn.classList.add("active");
} else {
btn.classList.remove("active");
}
});

fetchActivities();
}

// Check if user is already logged in (from localStorage)
function checkAuthentication() {
const savedUser = localStorage.getItem("currentUser");
Expand Down Expand Up @@ -386,6 +410,23 @@ document.addEventListener("DOMContentLoaded", () => {
return;
}

// Aplicar filtro de dificuldade
if (currentDifficulty !== "") {
const activityDifficulty = details.difficultyLevel ? details.difficultyLevel.name : null;

if (currentDifficulty === "none") {
// "Todos os Níveis" significa apenas atividades sem dificuldade especificada
if (activityDifficulty !== null) {
return;
}
} else {
// Filtrar por nível específico (beginner, intermediate, advanced)
if (activityDifficulty !== currentDifficulty) {
return;
}
}
}

// Atividade passou por todos os filtros, adicionar à lista filtrada
filteredActivities[name] = details;
});
Expand Down Expand Up @@ -579,6 +620,19 @@ document.addEventListener("DOMContentLoaded", () => {
});
});

// Add event listeners for difficulty filter buttons
difficultyFilters.forEach((button) => {
button.addEventListener("click", () => {
// Update active class
difficultyFilters.forEach((btn) => btn.classList.remove("active"));
button.classList.add("active");

// Update current difficulty filter and display filtered activities
currentDifficulty = button.dataset.difficulty;
displayFilteredActivities();
});
});

// Open registration modal
function openRegistrationModal(activityName) {
modalActivityName.textContent = activityName;
Expand Down Expand Up @@ -797,6 +851,7 @@ document.addEventListener("DOMContentLoaded", () => {
window.activityFilters = {
setDayFilter,
setTimeRangeFilter,
setDifficultyFilter,
};

// Initialize app
Expand Down
22 changes: 22 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ <h3>Filtrar Atividades</h3>
<button class="time-filter" data-time="weekend">Fim de Semana</button>
</div>
</div>

<!-- Difficulty Filter -->
<div class="filter-container difficulty-filter-container">
<div class="filter-label">Filtrar por dificuldade:</div>
<div class="difficulty-filters" id="difficulty-filters">
<button class="difficulty-filter active" data-difficulty="">
Todas as Dificuldades
</button>
<button class="difficulty-filter" data-difficulty="none">
Todos os Níveis
</button>
<button class="difficulty-filter" data-difficulty="beginner">
Iniciante
</button>
<button class="difficulty-filter" data-difficulty="intermediate">
Intermediário
</button>
<button class="difficulty-filter" data-difficulty="advanced">
Avançado
</button>
</div>
</div>
</aside>

<!-- Activities Content -->
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -539,15 +539,17 @@ footer {

.category-filters,
.day-filters,
.time-filters {
.time-filters,
.difficulty-filters {
display: flex;
flex-wrap: wrap;
gap: 6px;
}

.category-filter,
.day-filter,
.time-filter {
.time-filter,
.difficulty-filter {
background-color: var(--background);
border: 1px solid var(--border);
color: var(--text-primary);
Expand All @@ -560,15 +562,17 @@ footer {

.category-filter.active,
.day-filter.active,
.time-filter.active {
.time-filter.active,
.difficulty-filter.active {
background-color: var(--primary);
color: white;
border-color: var(--primary-dark);
}

.category-filter:hover,
.day-filter:hover,
.time-filter:hover {
.time-filter:hover,
.difficulty-filter:hover {
background-color: var(--primary-light);
color: white;
}
Expand Down
Loading