Author SHA1 Message Date
ProstoDenya01 05fcf86e32 Поправил модалку с расписанием препода 2026-03-15 15:51:29 +03:00
alekan 8df736ae36 Кривая модалка занятий по teacherId добавлена, требует доработки, также код users.js требует унификации+оптимизации(новая модалка вкинута в конец) 2026-03-13 03:12:48 +03:00
alekan 24caa148e1 Модалка перенесена в шапку, частично настроены стили 2026-03-13 02:00:49 +03:00
ProstoDenya01 03eaf6ab13 Добавил для групп поле численности.
В модалку на UI добавил отображение численности групп и вместимости аудиторий, проверку на доступность и вместимость.
2026-03-12 14:45:25 +03:00
Denis 1b0a6c86ff Merge pull request 'Доделал модалку на создание занятий. Добавил поля выбора аудитории, типа и формата занятий.' (#6) from Create-Lesson into main
Build and Push Docker Images / build-and-push-backend (push) Successful in 12s
Build and Push Docker Images / build-and-push-frontend (push) Successful in 11s
Build and Push Docker Images / deploy-to-k8s (push) Successful in 1m13s
Reviewed-on: #6
2026-03-11 09:45:46 +00:00
ProstoDenya01 0216dfaa40 Доделал модалку на создание занятий. Добавил поля выбора аудитории, типа и формата занятий. 2026-03-11 12:43:42 +03:00
Zuev 7e0e2cdfc5 fix: increase rollout timeout for backend to 300s
Build and Push Docker Images / build-and-push-backend (push) Successful in 11s
Build and Push Docker Images / build-and-push-frontend (push) Successful in 11s
Build and Push Docker Images / deploy-to-k8s (push) Successful in 1m15s
2026-03-11 02:58:49 +03:00
Zuev a6ee024935 Merge pull request 'Create-Lesson' (#5) from Create-Lesson into main
Build and Push Docker Images / build-and-push-backend (push) Successful in 27s
Build and Push Docker Images / build-and-push-frontend (push) Successful in 10s
Build and Push Docker Images / deploy-to-k8s (push) Failing after 2m6s
Reviewed-on: #5
2026-03-10 23:51:53 +00:00
Zuev 6d003f5fa8 fix: install kubectl in deploy-to-k8s job
Build and Push Docker Images / build-and-push-backend (push) Successful in 10s
Build and Push Docker Images / build-and-push-frontend (push) Successful in 10s
Build and Push Docker Images / deploy-to-k8s (push) Successful in 1m12s
2026-03-11 02:49:33 +03:00
Zuev 8deba5cc3d Merge pull request 'feat: add CD step to docker-build workflow' (#4) from Zuev into main
Build and Push Docker Images / build-and-push-backend (push) Successful in 13s
Build and Push Docker Images / build-and-push-frontend (push) Successful in 16s
Build and Push Docker Images / deploy-to-k8s (push) Failing after 1s
Reviewed-on: #4
2026-03-10 23:30:16 +00:00
Zuev 11ef481269 feat: add CD step to docker-build workflow 2026-03-11 02:28:52 +03:00
Zuev 494a671c3d Merge pull request 'fix: resolve labels property issue in docker-build workflow' (#3) from Zuev into main
Build and Push Docker Images / build-and-push-backend (push) Successful in 15s
Build and Push Docker Images / build-and-push-frontend (push) Successful in 11s
Reviewed-on: #3
2026-03-10 22:12:01 +00:00
Zuev c8570d3cf8 fix: resolve labels property issue in docker-build workflow 2026-03-11 01:10:00 +03:00
Zuev 5104e36d7d Merge pull request 'Update GitHub Actions versions to latest' (#2) from Zuev into main
Build and Push Docker Images / build-and-push-backend (push) Successful in 2m29s
Build and Push Docker Images / build-and-push-frontend (push) Successful in 10s
Reviewed-on: #2
2026-03-09 23:23:50 +00:00
Zuev 8e540940f7 Update GitHub Actions versions to latest 2026-03-10 02:22:48 +03:00
Zuev e8b1d77117 Merge pull request 'Zuev' (#1) from Zuev into main
Build and Push Docker Images / build-and-push-backend (push) Successful in 7m10s
Build and Push Docker Images / build-and-push-frontend (push) Successful in 15s
Reviewed-on: #1
2026-03-09 22:56:57 +00:00
Zuev 41dec9c772 update docker-build.yaml 2026-03-10 01:51:33 +03:00
ProstoDenya01 01ea7a8dc1 Обновил init.sql, добавил одного преподавателя и несколько занятий при инициализации БД
Добавил методы на удаление и обновления занятий
2026-03-06 17:14:29 +03:00
ProstoDenya01 9bd21757d6 Доделал таблицу вывода занятий на FE 2026-03-04 23:31:42 +03:00
ProstoDenya01 7a729a782d тест 2026-03-04 22:57:56 +03:00
ProstoDenya01 be35733e4d Merge remote-tracking branch 'origin/Zuev' into Create-Lesson 2026-03-04 22:57:08 +03:00
ProstoDenya01 169f7435b1 Добавил новые поля в создание занятия и получение общего списка 2026-03-04 22:49:58 +03:00
Zuev 2563c769de Реализована фильтрация столбцов и улучшена сортировка в расписании 2026-03-04 22:46:36 +03:00
ProstoDenya01 47039ee878 Изменил метод на получение общего списка занятий. Внёс небольшие правки в FE для странички с расписанием 2026-03-03 17:28:20 +03:00
alekan 88f1abfe25 Создание вкладки "Расписание занятий" 2026-03-03 00:02:07 +03:00
alekan 2004766855 Создание кнопки "Добавить занятие" с модальным окном с выбором дня,недели и тд. 2026-03-02 23:27:20 +03:00
ProstoDenya01 0e03dcb2d6 Поправил комментарий в application.properties 2026-03-02 16:27:20 +03:00
ProstoDenya01 438a16c383 Исправил все известные баги в запросе на создание занятия для пользователя.
Написал запрос на получение списка занятий по конкретному ID пользователя.
Добавил логирование для LessonsController
2026-03-02 16:24:22 +03:00
82 changed files with 2604 additions and 174 deletions

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
name: Build and Push Docker Images
on:
push:
branches:
- main
tags:
- 'v*'
env:
REGISTRY: gitea.zuev.company # Замените на реальный домен вашего Gitea
BACKEND_IMAGE: zuev/magistr-backend
FRONTEND_IMAGE: zuev/magistr-frontend
jobs:
build-and-push-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.ZUEV_TOKEN }} # Нужно создать секрет ZUEV_TOKEN в настройках репозитория (Personal Access Token)
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./backend
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: |
${{ steps.meta.outputs.labels }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
build-and-push-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.ZUEV_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./frontend
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: |
${{ steps.meta.outputs.labels }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
deploy-to-k8s:
needs: [build-and-push-backend, build-and-push-frontend]
runs-on: ubuntu-latest
steps:
- name: Create kubeconfig
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG_DATA }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/
- name: Trigger Kubernetes Rollout
run: |
# Перезапускаем поды, чтобы они скачали свежий :main образ
kubectl rollout restart deployment backend frontend -n magistr
# Ждём успешного обновления (5 минут на backend из-за Spring Boot)
kubectl rollout status deployment/frontend -n magistr --timeout=120s
kubectl rollout status deployment/backend -n magistr --timeout=300s
+7 -3
View File
@@ -1,7 +1,4 @@
# Игнорируем данные БД (но не init-скрипты)
db/data/ db/data/
# Игнорируем секреты
.env .env
# Игнорируем временные файлы сборки (на будущее) # Игнорируем временные файлы сборки (на будущее)
@@ -9,3 +6,10 @@ backend/target/
backend/build/ backend/build/
frontend/node_modules/ frontend/node_modules/
frontend/dist/ frontend/dist/
.agents
.idea/
.vscode/
*.DS_Store
AGENTS.md
GEMINI.md
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
+1 -1
View File
@@ -1 +1 @@
КОММИТ12 тест
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
File mode changed.
File mode changed.
File mode changed.
+6
View File
@@ -32,6 +32,7 @@ public class GroupController {
.map(g -> new GroupResponse( .map(g -> new GroupResponse(
g.getId(), g.getId(),
g.getName(), g.getName(),
g.getGroupSize(),
g.getEducationForm().getId(), g.getEducationForm().getId(),
g.getEducationForm().getName())) g.getEducationForm().getName()))
.toList(); .toList();
@@ -45,6 +46,9 @@ public class GroupController {
if (groupRepository.findByName(request.getName().trim()).isPresent()) { if (groupRepository.findByName(request.getName().trim()).isPresent()) {
return ResponseEntity.badRequest().body(Map.of("message", "Группа с таким названием уже существует")); return ResponseEntity.badRequest().body(Map.of("message", "Группа с таким названием уже существует"));
} }
if (request.getGroupSize() == null) {
return ResponseEntity.badRequest().body(Map.of("message", "Численность группы обязательна"));
}
if (request.getEducationFormId() == null) { if (request.getEducationFormId() == null) {
return ResponseEntity.badRequest().body(Map.of("message", "Форма обучения обязательна")); return ResponseEntity.badRequest().body(Map.of("message", "Форма обучения обязательна"));
} }
@@ -56,12 +60,14 @@ public class GroupController {
StudentGroup group = new StudentGroup(); StudentGroup group = new StudentGroup();
group.setName(request.getName().trim()); group.setName(request.getName().trim());
group.setGroupSize(request.getGroupSize());
group.setEducationForm(efOpt.get()); group.setEducationForm(efOpt.get());
groupRepository.save(group); groupRepository.save(group);
return ResponseEntity.ok(new GroupResponse( return ResponseEntity.ok(new GroupResponse(
group.getId(), group.getId(),
group.getName(), group.getName(),
group.getGroupSize(),
group.getEducationForm().getId(), group.getEducationForm().getId(),
group.getEducationForm().getName())); group.getEducationForm().getName()));
} }
@@ -0,0 +1,507 @@
package com.magistr.app.controller;
import com.magistr.app.dto.CreateLessonRequest;
import com.magistr.app.dto.LessonResponse;
import com.magistr.app.model.*;
import com.magistr.app.repository.*;
import com.magistr.app.utils.DayAndWeekValidator;
import com.magistr.app.utils.TypeAndFormatLessonValidator;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import org.slf4j.Logger;
import org.springframework.http.HttpStatus;
@RestController
@RequestMapping("/api/users/lessons")
public class LessonsController {
private static final Logger logger = LoggerFactory.getLogger(LessonsController.class);
private final LessonRepository lessonRepository;
private final UserRepository teacherRepository;
private final GroupRepository groupRepository;
private final SubjectRepository subjectRepository;
private final EducationFormRepository educationFormRepository;
private final ClassroomRepository classroomRepository;
public LessonsController(LessonRepository lessonRepository, UserRepository teacherRepository, GroupRepository groupRepository, SubjectRepository subjectRepository, EducationFormRepository educationForm, ClassroomRepository classroomRepository) {
this.lessonRepository = lessonRepository;
this.teacherRepository = teacherRepository;
this.groupRepository = groupRepository;
this.subjectRepository = subjectRepository;
this.educationFormRepository = educationForm;
this.classroomRepository = classroomRepository;
}
//Создание нового занятия
@PostMapping("/create")
public ResponseEntity<?> createLesson(@RequestBody CreateLessonRequest request) {
//Полное логирование входящего запроса
logger.info("Получен запрос на создание занятия: teacherId={}, groupId={}, subjectId={}, day={}, week={}, time={}",
request.getTeacherId(), request.getGroupId(), request.getSubjectId(), request.getDay(), request.getWeek(), request.getTime());
//Проверка teacherId
if (request.getTeacherId() == null || request.getTeacherId() == 0) {
String errorMessage = "ID преподавателя обязателен";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
//Проверка groupId
if (request.getGroupId() == null || request.getGroupId() == 0) {
String errorMessage = "ID группы обязателен";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
//Проверка subjectId
if (request.getSubjectId() == null || request.getSubjectId() == 0) {
String errorMessage = "ID предмета обязателен";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
//Проверка lessonFormat
if (request.getLessonFormat() == null || request.getLessonFormat().isBlank()) {
String errorMessage = "Выбор формата занятия обязателен";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
} else if(!TypeAndFormatLessonValidator.isValidFormat(request.getLessonFormat())){
String errorMessage = "Некорректный формат занятий. " + TypeAndFormatLessonValidator.getValidFormatsMessage();
logger.info("Ошибка валидации формата: '{}' - {}", request.getLessonFormat(), errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
//Проверка typeLesson
if (request.getTypeLesson() == null || request.getTypeLesson().isBlank()) {
String errorMessage = "Выбор типа занятия обязателен";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
} else if(!TypeAndFormatLessonValidator.isValidType(request.getTypeLesson())){
String errorMessage = "Некорректный тип занятия. " + TypeAndFormatLessonValidator.getValidTypesMessage();
logger.info("Ошибка валидации типа: '{}' - {}", request.getTypeLesson(), errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
//Проверка classroomId
if (request.getClassroomId() == null || request.getClassroomId() == 0) {
String errorMessage = "ID аудитории обязателен";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
//Проверка day
if (request.getDay() == null || request.getDay().isBlank()) {
String errorMessage = "Выбор дня обязателен";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
} else if(!DayAndWeekValidator.isValidDay(request.getDay())){
String errorMessage = "Некорректный день недели. " + DayAndWeekValidator.getValidDaysMessage();
logger.info("Ошибка валидации дня: '{}' - {}", request.getDay(), errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
//Проверка week
if (request.getWeek() == null || request.getWeek().isBlank()) {
String errorMessage = "Выбор недели обязателен";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
} else if(!DayAndWeekValidator.isValidWeek(request.getWeek())){
String errorMessage = "Некорректная неделя. " + DayAndWeekValidator.getValidWeekMessage();
logger.info("Ошибка валидации недели: '{}' - {}", request.getWeek(), errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
//Проверка time
if (request.getTime() == null || request.getTime().isBlank()) {
String errorMessage = "Время обязательно";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
//Сохранение полученных данных и формирование ответа клиенту
try {
Lesson lesson = new Lesson();
lesson.setTeacherId(request.getTeacherId());
lesson.setSubjectId(request.getSubjectId());
lesson.setGroupId(request.getGroupId());
lesson.setLessonFormat(request.getLessonFormat());
lesson.setTypeLesson(request.getTypeLesson());
lesson.setClassroomId(request.getClassroomId());
lesson.setDay(request.getDay());
lesson.setWeek(request.getWeek());
lesson.setTime(request.getTime());
Lesson savedLesson = lessonRepository.save(lesson);
Map<String, Object> response = new LinkedHashMap<>();
response.put("id", savedLesson.getId());
response.put("teacherId", savedLesson.getTeacherId());
response.put("groupId", savedLesson.getGroupId());
response.put("subjectId", savedLesson.getSubjectId());
response.put("formatLesson", savedLesson.getLessonFormat());
response.put("typeLesson", savedLesson.getTypeLesson());
response.put("classroomId", savedLesson.getClassroomId());
response.put("day", savedLesson.getDay());
response.put("week", savedLesson.getWeek());
response.put("time", savedLesson.getTime());
logger.info("Занятие успешно создано с ID: {}", savedLesson.getId());
return ResponseEntity.ok(response);
} catch (Exception e) {
logger.error("Ошибка при сохранении занятия: {}", e.getMessage(),e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Map.of("message", "Произошла ошибка при создании занятия: " + e.getMessage()));
}
}
//Запрос для получения всего списка занятий
@GetMapping
public List<LessonResponse> getAllLessons() {
logger.info("Запрос на получение всех занятий");
try {
List<Lesson> lessons = lessonRepository.findAll();
List<LessonResponse> response = lessons.stream()
.map(lesson -> {
String teacherName = teacherRepository.findById(lesson.getTeacherId())
.map(User::getUsername)
.orElse("Неизвестно");
StudentGroup group = groupRepository.findById(lesson.getGroupId()).orElse(null);
String groupName = groupRepository.findById(lesson.getGroupId())
.map(StudentGroup::getName)
.orElse("Неизвестно");
String educationFormName = "Неизвестно";
if(group != null && group.getEducationForm() != null) {
Long educationFormId = group.getEducationForm().getId();
educationFormName = educationFormRepository.findById(educationFormId)
.map(EducationForm::getName)
.orElse("Неизвестно");
}
String subjectName = subjectRepository.findById(lesson.getSubjectId())
.map(Subject::getName)
.orElse("Неизвестно");
String classroomName = classroomRepository.findById(lesson.getClassroomId())
.map(Classroom::getName)
.orElse("Неизвестно");
return new LessonResponse(
lesson.getId(),
teacherName,
groupName,
classroomName,
educationFormName,
subjectName,
lesson.getTypeLesson(),
lesson.getLessonFormat(),
lesson.getDay(),
lesson.getWeek(),
lesson.getTime()
);
})
.toList();
logger.info("Получено {} занятий", lessons.size());
return response;
} catch (Exception e) {
logger.error("Ошибка при получении списка всех занятий: {}", e.getMessage(), e);
throw e;
}
}
//Запрос на получение всех занятий для конкретного преподавателя
@GetMapping("/{teacherId}")
public ResponseEntity<?> getLessonsById(@PathVariable Long teacherId) {
logger.info("Запрос на получение занятий для преподавателя с ID: {}", teacherId);
try {
List<Lesson> lessons = lessonRepository.findByTeacherId(teacherId);
if(lessons.isEmpty()) {
logger.info("У преподавателя с ID {} нет занятий", teacherId);
return ResponseEntity.ok(Map.of(
"message", "У преподавателя с ID " + teacherId +" нет занятий.",
"lessons", Collections.emptyList()
));
}
List<LessonResponse> lessonResponses = lessons.stream()
.map(lesson -> {
String teacherName = teacherRepository.findById(lesson.getTeacherId())
.map(User::getUsername)
.orElse("Неизвестно");
StudentGroup group = groupRepository.findById(lesson.getGroupId()).orElse(null);
String groupName = groupRepository.findById(lesson.getGroupId())
.map(StudentGroup::getName)
.orElse("Неизвестно");
String educationFormName = "Неизвестно";
if(group != null && group.getEducationForm() != null) {
Long educationFormId = group.getEducationForm().getId();
educationFormName = educationFormRepository.findById(educationFormId)
.map(EducationForm::getName)
.orElse("Неизвестно");
}
String subjectName = subjectRepository.findById(lesson.getSubjectId())
.map(Subject::getName)
.orElse("Неизвестно");
String classroomName = classroomRepository.findById(lesson.getClassroomId())
.map(Classroom::getName)
.orElse("Неизвестно");
return new LessonResponse(
lesson.getId(),
teacherName,
groupName,
classroomName,
educationFormName,
subjectName,
lesson.getTypeLesson(),
lesson.getLessonFormat(),
lesson.getDay(),
lesson.getWeek(),
lesson.getTime()
);
})
.toList();
logger.info("Найдено {} занятий для преподавателя с ID: {}", lessonResponses.size(), teacherId);
return ResponseEntity.ok(lessonResponses);
} catch (Exception e ){
logger.error("Ошибка при получении занятий для преподавателя с ID {}: {}", teacherId, e.getMessage(), e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Map.of("message", "Ошибка при поиске занятий: " + e.getMessage()));
}
}
//Тестовый запрос на проверку доступности контроллера
@GetMapping("/ping")
public String ping() {
logger.debug("Получен ping запрос");
String response = "pong";
logger.debug("Ответ на ping: {}", response);
return response;
}
//Удаление занятия по его ID
@DeleteMapping("/delete/{lessonId}")
public ResponseEntity<?> deleteLessonById(@PathVariable Long lessonId){
logger.info("Запрос на удаление занятия по ID: {}", lessonId);
if(!lessonRepository.existsById(lessonId)) {
return ResponseEntity.badRequest().body(Map.of("message", "Занятие не найдено"));
}
lessonRepository.deleteById(lessonId);
logger.info("Занятие с ID - {} успешно удалено", lessonId);
return ResponseEntity.ok(Map.of("message", "Занятие успешно удалено"));
}
//Обновление занятия по его ID
@PutMapping("/update/{lessonId}")
public ResponseEntity<?> updateLessonById(@PathVariable Long lessonId, @RequestBody CreateLessonRequest request) {
logger.info("Получен запрос на обновление занятия с ID - {}", lessonId);
logger.info("Данные для обновления: teacherId={}, groupId={}, subjectId={}, lessonFormat={}, typeLesson={}, classroomId={}, day={}, week={}, time={}",
request.getTeacherId(), request.getGroupId(), request.getSubjectId(), request.getLessonFormat(), request.getTypeLesson(), request.getClassroomId(),
request.getDay(), request.getWeek(), request.getTime());
try {
//Проверка на наличие записи
Lesson existingLesson = lessonRepository.findById(lessonId).orElse(null);
if(existingLesson == null) {
String errorMessage = "Занятие с ID " + lessonId + " не найдено";
logger.info("Ошибка: {}", errorMessage);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Map.of("message", errorMessage));
}
boolean hasChanges = false;
Map<String, Object> changes = new LinkedHashMap<>();
//Проверка и обновление teacherId, если он передан и отличается
if(request.getTeacherId() != null) {
if(!request.getTeacherId().equals(existingLesson.getTeacherId())) {
if(request.getTeacherId() == 0) {
return ResponseEntity.badRequest()
.body(Map.of("message", "ID преподавателя не может быть равен 0"));
}
existingLesson.setTeacherId(request.getTeacherId());
changes.put("teacherId", request.getTeacherId());
hasChanges = true;
}
}
//Проверка и обновление groupId, если он передан и отличается
if(request.getGroupId() != null) {
if(!request.getGroupId().equals(existingLesson.getGroupId())) {
if(request.getGroupId() == 0) {
return ResponseEntity.badRequest()
.body(Map.of("message", "ID группы не может быть равен 0"));
}
existingLesson.setGroupId(request.getGroupId());
changes.put("groupId", request.getGroupId());
hasChanges = true;
}
}
//Проверка и обновление subjectId, если он передан и отличается
if(request.getSubjectId() != null) {
if(!request.getSubjectId().equals(existingLesson.getSubjectId())) {
if(request.getSubjectId() == 0) {
return ResponseEntity.badRequest()
.body(Map.of("message", "ID дисциплины не может быть равен 0"));
}
existingLesson.setSubjectId(request.getSubjectId());
changes.put("subjectId", request.getSubjectId());
hasChanges = true;
}
}
//Проверка и обновление lessonFormat, если он передан и отличается
if(request.getLessonFormat() != null) {
if(!request.getLessonFormat().equals(existingLesson.getLessonFormat())) {
if(request.getLessonFormat().isBlank()) {
return ResponseEntity.badRequest()
.body(Map.of("message", "Формат занятия не может быть пустым"));
}
if(!TypeAndFormatLessonValidator.isValidFormat(request.getLessonFormat())) {
String errorMessage = "Некорректный формат занятий. " + TypeAndFormatLessonValidator.getValidFormatsMessage();
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
existingLesson.setLessonFormat(request.getLessonFormat());
changes.put("lessonFormat", request.getLessonFormat());
hasChanges = true;
}
}
//Проверка и обновление typeLesson, если он передан и отличается
if(request.getTypeLesson() != null) {
if(!request.getTypeLesson().equals(existingLesson.getTypeLesson())) {
if(request.getTypeLesson().isBlank()) {
return ResponseEntity.badRequest()
.body(Map.of("message", "Тип занятия не может быть пустым"));
}
if(!TypeAndFormatLessonValidator.isValidType(request.getTypeLesson())) {
String errorMessage = "Некорректный тип занятий. " + TypeAndFormatLessonValidator.getValidTypesMessage();
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
existingLesson.setLessonFormat(request.getTypeLesson());
changes.put("typeLesson", request.getTypeLesson());
hasChanges = true;
}
}
//Проверка и обновление classroomId, если он передан и отличается
if(request.getClassroomId() != null) {
if(!request.getClassroomId().equals(existingLesson.getClassroomId())) {
if(request.getClassroomId() == 0) {
return ResponseEntity.badRequest()
.body(Map.of("message", "ID аудитории не можеть быть равен 0"));
}
existingLesson.setClassroomId(request.getClassroomId());
changes.put("classroomId", request.getClassroomId());
hasChanges = true;
}
}
//Проверка и обновление day, если он передан и отличается
if(request.getDay() != null){
if(!request.getDay().equals(existingLesson.getDay())) {
if(request.getDay().isBlank()) {
return ResponseEntity.badRequest()
.body(Map.of("message", "Поле \"День\" не может быть пустым"));
}
if(!DayAndWeekValidator.isValidDay(request.getDay())) {
String errorMessage = "Некорректный день. " + DayAndWeekValidator.getValidDaysMessage();
return ResponseEntity.badRequest()
.body(Map.of("message", errorMessage));
}
existingLesson.setDay(request.getDay());
changes.put("day", request.getDay());
hasChanges = true;
}
}
//Проверка и обновление week, если он передан и отличается
if(request.getWeek() != null) {
if(!request.getWeek().equals(existingLesson.getWeek())) {
if (request.getWeek().isBlank()) {
return ResponseEntity.badRequest()
.body(Map.of("message", "Поле \"Неделя\" не может быть пустым"));
}
if (!DayAndWeekValidator.isValidWeek(request.getWeek())) {
String errorMessage = "Некорректная неделя. " + DayAndWeekValidator.getValidWeekMessage();
return ResponseEntity.badRequest()
.body((Map.of("message", errorMessage)));
}
existingLesson.setWeek(request.getWeek());
changes.put("week", request.getWeek());
hasChanges = true;
}
}
//Проверка и обновление time, если он передан и отличается
if(request.getTime() != null) {
if(!request.getTime().equals(existingLesson.getTime())) {
if(request.getTime().isBlank()){
return ResponseEntity.badRequest()
.body(Map.of("message", "Поле \"Время\" не может быть пустым"));
}
existingLesson.setTime(request.getTime());
changes.put("time", request.getTime());
hasChanges = true;
}
}
if(!hasChanges) {
logger.info("Обновление не требуется - все полня идентичны существующим для занятия с ID: {}", lessonId);
Map<String, Object> response = buildResponse(existingLesson);
response.put("message", "Изменений не обнаружено");
return ResponseEntity.ok(response);
}
Lesson updatedLesson = lessonRepository.save(existingLesson);
Map<String, Object> response = buildResponse(updatedLesson);
response.put("updatedFields", changes);
response.put("message", "Занятие успешно обновлено");
logger.info("Занятие с ID - {} успешно обновлено. Изменения: {}", lessonId, changes);
return ResponseEntity.ok(response);
} catch (Exception e) {
logger.error("Ошибка при обновлении занятия с ID {}: {}", lessonId, e.getMessage(),e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Map.of("message", "Произошла ошибка при обновлении занятия: " + e.getMessage()));
}
}
private Map<String, Object> buildResponse(Lesson lesson) {
Map<String, Object> response = new LinkedHashMap<>();
response.put("id", lesson.getId());
response.put("teacherId", lesson.getTeacherId());
response.put("groupId", lesson.getGroupId());
response.put("subjectId", lesson.getSubjectId());
response.put("LessonFormat", lesson.getLessonFormat());
response.put("typeLesson", lesson.getTypeLesson());
response.put("classroomId", lesson.getClassroomId());
response.put("day", lesson.getDay());
response.put("week", lesson.getWeek());
response.put("time", lesson.getTime());
return response;
}
}
File mode changed.
File mode changed.
@@ -1,67 +0,0 @@
package com.magistr.app.controller;
import com.magistr.app.dto.CreateLessonRequest;
import com.magistr.app.dto.LessonResponse;
import com.magistr.app.model.Lesson;
import com.magistr.app.repository.LessonRepository;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/users/test")
public class TestController {
private final LessonRepository lessonRepository;
public TestController(LessonRepository lessonRepository) {
this.lessonRepository = lessonRepository;
}
@PostMapping("/create")
public ResponseEntity<?> createLesson(@RequestBody CreateLessonRequest request) {
if (request.getTeacherId() == null || request.getTeacherId() == 0) {
return ResponseEntity.badRequest().body(Map.of("message", "ID преподавателя обязателен"));
}
if (request.getGroupId() == null || request.getGroupId() == 0) {
return ResponseEntity.badRequest().body(Map.of("message", "ID группы обязателен"));
}
if (request.getLessonTypeId() == null || request.getLessonTypeId() == 0) {
return ResponseEntity.badRequest().body(Map.of("message", "ID предмета обязателен"));
}
if (request.getDay() == null || request.getDay().isBlank()) {
return ResponseEntity.badRequest().body(Map.of("message", "Выбор дня обязателен"));
}
if (request.getWeek() == null || request.getWeek().isBlank()) {
return ResponseEntity.badRequest().body(Map.of("message", "Выбор недели обязателен"));
}
if (request.getTime() == null || request.getTime().isBlank()) {
return ResponseEntity.badRequest().body(Map.of("message", "Время обязательно"));
}
Lesson lesson = new Lesson();
lesson.setTeacherId(request.getTeacherId());
lesson.setLessonTypeId(request.getLessonTypeId());
lesson.setGroupId(request.getGroupId());
lesson.setDay(request.getDay());
lesson.setWeek(request.getWeek());
lesson.setTime(request.getTime());
lessonRepository.save(lesson);
return ResponseEntity.ok(new LessonResponse(lesson.getId(), lesson.getDay(), lesson.getWeek(), lesson.getTime()));
}
@GetMapping
public List<LessonResponse> getAllLessons() {
return lessonRepository.findAll().stream()
.map(l -> new LessonResponse(l.getId(), l.getTeacherId(), l.getLessonTypeId(), l.getDay(), l.getWeek(), l.getTime()))
.toList();
}
@GetMapping("/ping")
public String ping() {
return "pong";
}
}
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
+9
View File
@@ -3,6 +3,7 @@ package com.magistr.app.dto;
public class CreateGroupRequest { public class CreateGroupRequest {
private String name; private String name;
private Long groupSize;
private Long educationFormId; private Long educationFormId;
public String getName() { public String getName() {
@@ -13,6 +14,14 @@ public class CreateGroupRequest {
this.name = name; this.name = name;
} }
public Long getGroupSize() {
return groupSize;
}
public void setGroupSize(Long groupSize) {
this.groupSize = groupSize;
}
public Long getEducationFormId() { public Long getEducationFormId() {
return educationFormId; return educationFormId;
} }
+32 -5
View File
@@ -4,7 +4,10 @@ public class CreateLessonRequest {
private Long teacherId; private Long teacherId;
private Long groupId; private Long groupId;
private Long lessonTypeId; private Long subjectId;
private String lessonFormat;
private String typeLesson;
private Long classroomId;
private String day; private String day;
private String week; private String week;
private String time; private String time;
@@ -28,12 +31,36 @@ public class CreateLessonRequest {
this.groupId = groupId; this.groupId = groupId;
} }
public Long getLessonTypeId() { public Long getSubjectId() {
return lessonTypeId; return subjectId;
} }
public void setLessonTypeId(Long lessonTypeId) { public void setSubjectId(Long subjectId) {
this.lessonTypeId= lessonTypeId; this.subjectId = subjectId;
}
public String getLessonFormat() {
return lessonFormat;
}
public void setLessonFormat(String lessonFormat) {
this.lessonFormat = lessonFormat;
}
public String getTypeLesson() {
return typeLesson;
}
public void setTypeLesson(String typeLesson) {
this.typeLesson = typeLesson;
}
public Long getClassroomId() {
return classroomId;
}
public void setClassroomId(Long classroomId) {
this.classroomId = classroomId;
} }
public String getDay() { public String getDay() {
View File
File mode changed.
+7 -1
View File
@@ -4,12 +4,14 @@ public class GroupResponse {
private Long id; private Long id;
private String name; private String name;
private Long groupSize;
private Long educationFormId; private Long educationFormId;
private String educationFormName; private String educationFormName;
public GroupResponse(Long id, String name, Long educationFormId, String educationFormName) { public GroupResponse(Long id, String name, Long groupSize, Long educationFormId, String educationFormName) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.groupSize = groupSize;
this.educationFormId = educationFormId; this.educationFormId = educationFormId;
this.educationFormName = educationFormName; this.educationFormName = educationFormName;
} }
@@ -22,6 +24,10 @@ public class GroupResponse {
return name; return name;
} }
public Long getGroupSize() {
return groupSize;
}
public Long getEducationFormId() { public Long getEducationFormId() {
return educationFormId; return educationFormId;
} }
+94 -10
View File
@@ -1,11 +1,23 @@
package com.magistr.app.dto; package com.magistr.app.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class LessonResponse { public class LessonResponse {
private Long id; private Long id;
private Long teacherId; private Long teacherId;
private String teacherName;
private Long groupId; private Long groupId;
private Long lessonTypeId; private String groupName;
private String educationFormName;
private Long subjectId;
private String subjectName;
private String lessonFormat;
private String typeLesson;
private Long classroomId;
private String classroomName;
private String day; private String day;
private String week; private String week;
private String time; private String time;
@@ -13,17 +25,25 @@ public class LessonResponse {
public LessonResponse() { public LessonResponse() {
} }
public LessonResponse(Long lessonTypeId, String day, String week, String time) { public LessonResponse(Long id, Long teacherId, Long groupId, Long subjectId, String day, String week, String time) {
this.lessonTypeId = lessonTypeId; this.id = id;
this.teacherId = teacherId;
this.groupId = groupId;
this.subjectId = subjectId;
this.day = day; this.day = day;
this.week = week; this.week = week;
this.time = time; this.time = time;
} }
public LessonResponse(Long id, Long teacherId, Long lessonTypeId, String day, String week, String time) { public LessonResponse(Long id, String teacherName, String groupName, String classroomName, String educationFormName, String subjectName, String typeLesson, String lessonFormat, String day, String week, String time) {
this.id = id; this.id = id;
this.teacherId = teacherId; this.teacherName = teacherName;
this.lessonTypeId = lessonTypeId; this.groupName = groupName;
this.classroomName = classroomName;
this.educationFormName = educationFormName;
this.subjectName = subjectName;
this.typeLesson = typeLesson;
this.lessonFormat = lessonFormat;
this.day = day; this.day = day;
this.week = week; this.week = week;
this.time = time; this.time = time;
@@ -45,6 +65,14 @@ public class LessonResponse {
this.teacherId = teacherId; this.teacherId = teacherId;
} }
public String getTeacherName() {
return teacherName;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
public Long getGroupId() { public Long getGroupId() {
return groupId; return groupId;
} }
@@ -53,12 +81,68 @@ public class LessonResponse {
this.groupId = groupId; this.groupId = groupId;
} }
public Long getLessonTypeId() { public String getGroupName() {
return lessonTypeId; return groupName;
} }
public void setLessonTypeId(Long lessonTypeId) { public void setGroupName(String groupName) {
this.lessonTypeId = lessonTypeId; this.groupName = groupName;
}
public String getTypeLesson() {
return typeLesson;
}
public void setTypeLesson(String typeLesson) {
this.typeLesson = typeLesson;
}
public String getLessonFormat() {
return lessonFormat;
}
public void setLessonFormat(String lessonFormat) {
this.lessonFormat = lessonFormat;
}
public Long getClassroomId() {
return classroomId;
}
public void setClassroomId(Long classroomId) {
this.classroomId = classroomId;
}
public String getClassroomName() {
return classroomName;
}
public void setClassroomName(String classroomName) {
this.classroomName = classroomName;
}
public String getEducationFormName() {
return educationFormName;
}
public void setEducationFormName(String educationFormName) {
this.educationFormName = educationFormName;
}
public Long getSubjectId() {
return subjectId;
}
public void setSubjectId(Long subjectId) {
this.subjectId = subjectId;
}
public String getSubjectName() {
return subjectName;
}
public void setSubjectName(String subjectName) {
this.subjectName = subjectName;
} }
public String getDay() { public String getDay() {
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
+39 -6
View File
@@ -16,8 +16,17 @@ public class Lesson {
@Column(name = "group_id", nullable = false) @Column(name = "group_id", nullable = false)
private Long groupId; private Long groupId;
@Column(name = "lesson_type_id", nullable = false) @Column(name = "subject_id", nullable = false)
private Long lessonTypeId; private Long subjectId;
@Column(name = "lesson_format", nullable = false, length = 255)
private String lessonFormat;
@Column(name = "type_lesson", nullable = false, length = 255)
private String typeLesson;
@Column(name = "classroom_id", nullable = false)
private Long classroomId;
@Column(name = "day", nullable = false, length = 255) @Column(name = "day", nullable = false, length = 255)
private String day; private String day;
@@ -55,12 +64,36 @@ public class Lesson {
this.groupId = groupId; this.groupId = groupId;
} }
public Long getLessonTypeId() { public Long getSubjectId() {
return lessonTypeId; return subjectId;
} }
public void setLessonTypeId(Long lessonTypeId) { public void setSubjectId(Long subjectId) {
this.lessonTypeId = lessonTypeId; this.subjectId = subjectId;
}
public String getLessonFormat() {
return lessonFormat;
}
public void setLessonFormat(String lessonFormat) {
this.lessonFormat = lessonFormat;
}
public String getTypeLesson() {
return typeLesson;
}
public void setTypeLesson(String typeLesson) {
this.typeLesson = typeLesson;
}
public Long getClassroomId() {
return classroomId;
}
public void setClassroomId(Long classroomId) {
this.classroomId = classroomId;
} }
public String getDay() { public String getDay() {
View File
File mode changed.
+11
View File
@@ -13,6 +13,9 @@ public class StudentGroup {
@Column(unique = true, nullable = false, length = 100) @Column(unique = true, nullable = false, length = 100)
private String name; private String name;
@Column(name = "group_size", nullable = false)
private Long groupSize;
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "education_form_id", nullable = false) @JoinColumn(name = "education_form_id", nullable = false)
private EducationForm educationForm; private EducationForm educationForm;
@@ -36,6 +39,14 @@ public class StudentGroup {
this.name = name; this.name = name;
} }
public Long getGroupSize() {
return groupSize;
}
public void setGroupSize(Long groupSize) {
this.groupSize = groupSize;
}
public EducationForm getEducationForm() { public EducationForm getEducationForm() {
return educationForm; return educationForm;
} }
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
File mode changed.
File mode changed.
File mode changed.
View File
File mode changed.
+4 -1
View File
@@ -3,9 +3,12 @@ package com.magistr.app.repository;
import com.magistr.app.model.Lesson; import com.magistr.app.model.Lesson;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface LessonRepository extends JpaRepository<Lesson, Long> { public interface LessonRepository extends JpaRepository<Lesson, Long> {
Optional<Lesson> findByLessonTypeId(Long lessonTypeId); Optional<Lesson> findBySubjectId(Long subjectId);
List<Lesson> findByTeacherId(Long teacherId);
} }
File mode changed.
File mode changed.
View File
File mode changed.
@@ -0,0 +1,30 @@
package com.magistr.app.utils;
import java.util.Set;
public class DayAndWeekValidator {
private static final Set<String> VALID_DAYS = Set.of(
"Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"
);
private static final Set<String> VALID_WEEKS = Set.of(
"Верхняя", "Нижняя", "Обе"
);
public static boolean isValidDay(String day) {
return day != null && VALID_DAYS.contains(day);
}
public static boolean isValidWeek(String week) {
return week != null && VALID_WEEKS.contains(week);
}
public static String getValidDaysMessage() {
return "Допустимые дни: " + String.join(", ", VALID_DAYS);
}
public static String getValidWeekMessage() {
return "Допустимы для выбора: " + String.join(", ", VALID_WEEKS);
}
}
@@ -0,0 +1,30 @@
package com.magistr.app.utils;
import java.util.Set;
public class TypeAndFormatLessonValidator {
private static final Set<String> VALID_TYPES = Set.of(
"Лекция", "Лабораторная работа", "Практическая работа"
);
private static final Set<String> VALID_FORMATS = Set.of(
"Онлайн", "Очно"
);
public static boolean isValidType(String type) {
return type != null && VALID_TYPES.contains(type);
}
public static boolean isValidFormat(String format) {
return format != null && VALID_FORMATS.contains(format);
}
public static String getValidTypesMessage() {
return "Допустимые типы: " + String.join(", ", VALID_TYPES);
}
public static String getValidFormatsMessage() {
return "Допустимые форматы: " + String.join(", ", VALID_FORMATS);
}
}
+3
View File
@@ -10,3 +10,6 @@ spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=validate spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=false spring.jpa.show-sql=false
spring.jpa.open-in-view=false spring.jpa.open-in-view=false
#Eta nastroyka otvechayet za vklyucheniye vidimosti logov urovnya DEBUG v logakh BE, poka vyklyuchil chtoby ne zasoryat'. Zapisi INFO otobrazhat'sya budut
#logging.level.root=DEBUG
Regular → Executable
View File
File mode changed.
Regular → Executable
+18 -4
View File
@@ -17,7 +17,8 @@ CREATE TABLE IF NOT EXISTS users (
-- Админ по умолчанию: admin / admin (bcrypt через pgcrypto) -- Админ по умолчанию: admin / admin (bcrypt через pgcrypto)
INSERT INTO users (username, password, role) INSERT INTO users (username, password, role)
VALUES ('admin', crypt('admin', gen_salt('bf', 10)), 'ADMIN') VALUES ('admin', crypt('admin', gen_salt('bf', 10)), 'ADMIN'),
('Тестовый преподаватель', '1234567890', 'TEACHER')
ON CONFLICT (username) DO NOTHING; ON CONFLICT (username) DO NOTHING;
-- ========================================== -- ==========================================
@@ -42,14 +43,16 @@ ON CONFLICT (name) DO NOTHING;
CREATE TABLE IF NOT EXISTS student_groups ( CREATE TABLE IF NOT EXISTS student_groups (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
name VARCHAR(100) UNIQUE NOT NULL, name VARCHAR(100) UNIQUE NOT NULL,
group_size BIGINT NOT NULL,
education_form_id BIGINT NOT NULL REFERENCES education_forms(id), education_form_id BIGINT NOT NULL REFERENCES education_forms(id),
course INT CHECK (course BETWEEN 1 AND 6), course INT CHECK (course BETWEEN 1 AND 6),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
-- Тестовая базовая группа для работы -- Тестовая базовая группа для работы
INSERT INTO student_groups (name, education_form_id, course) INSERT INTO student_groups (name, group_size, education_form_id, course)
VALUES ('ИВТ-21-1', 1, 3) VALUES ('ИВТ-21-1', 25, 1, 3),
('ИБ-41м', 15, 2, 2)
ON CONFLICT (name) DO NOTHING; ON CONFLICT (name) DO NOTHING;
-- ========================================== -- ==========================================
@@ -185,12 +188,23 @@ CREATE TABLE IF NOT EXISTS lessons (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
teacher_id BIGINT NOT NULL REFERENCES users(id), teacher_id BIGINT NOT NULL REFERENCES users(id),
group_id BIGINT NOT NULL REFERENCES student_groups(id), group_id BIGINT NOT NULL REFERENCES student_groups(id),
lesson_type_id BIGINT NOT NULL REFERENCES lesson_types(id), subject_id BIGINT NOT NULL REFERENCES subjects(id),
lesson_format VARCHAR(255) NOT NULL,
type_lesson VARCHAR(255) NOT NULL,
classroom_id BIGINT NOT NULL REFERENCES classrooms(id),
day VARCHAR(255) NOT NULL, day VARCHAR(255) NOT NULL,
week VARCHAR(255) NOT NULL, week VARCHAR(255) NOT NULL,
time VARCHAR(255) NOT NULL time VARCHAR(255) NOT NULL
); );
INSERT INTO lessons (teacher_id, group_id, subject_id, lesson_format, type_lesson, classroom_id, day, week, time) VALUES
(2, 1, 1, 'Очно', 'Лекция', 1, 'Понедельник', 'Верхняя', '11:40 - 13:10'),
(1, 1, 2, 'Онлайн', 'Практическая работа', 2, 'Вторник', 'Нижняя', '15:00 - 16:30'),
(2, 1, 3, 'Очно', 'Лабораторная работа', 3, 'Среда', 'Верхняя', '8:00 - 9:30'),
(1, 1, 4, 'Онлайн', 'Лекция', 1, 'Четверг', 'Нижняя', '11:40 - 13:10'),
(2, 1, 5, 'Очно', 'Практическая работа', 2, 'Пятница', 'Верхняя', '15:00 - 16:30'),
(1, 1, 3, 'Онлайн', 'Лабораторная работа', 3, 'Суббота', 'Нижняя', '8:00 - 9:30');
-- ========================================== -- ==========================================
-- Функция обновления timestamp -- Функция обновления timestamp
-- ========================================== -- ==========================================
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
+224 -55
View File
@@ -432,6 +432,230 @@ thead th {
border-bottom: 1px solid var(--bg-card-border); border-bottom: 1px solid var(--bg-card-border);
} }
/* Sortable columns */
thead th.sortable {
cursor: pointer;
user-select: none;
white-space: nowrap;
transition: color 0.2s ease;
}
thead th.sortable:hover {
color: var(--accent);
}
thead th.sortable.sort-active {
color: var(--accent);
}
.sort-arrow {
display: inline-block;
width: 0;
height: 0;
margin-left: 5px;
vertical-align: middle;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 5px solid currentColor;
opacity: 0.3;
transition: transform 0.25s ease, opacity 0.25s ease;
}
thead th.sortable:hover .sort-arrow {
opacity: 0.6;
}
thead th.sortable.sort-asc .sort-arrow {
opacity: 1;
border-bottom: 5px solid var(--accent);
transform: rotate(0deg);
}
thead th.sortable.sort-desc .sort-arrow {
opacity: 1;
border-bottom: 5px solid var(--accent);
transform: rotate(180deg);
}
/* ===== Filter Icon & Popup ===== */
thead th.filterable {
cursor: pointer;
user-select: none;
white-space: nowrap;
transition: color 0.2s ease;
}
thead th.filterable:hover {
color: var(--accent);
}
.filter-icon {
display: inline-block;
margin-left: 4px;
font-size: 0.65rem;
opacity: 0.4;
cursor: pointer;
transition: opacity 0.2s ease, color 0.2s ease;
vertical-align: middle;
}
thead th.filterable:hover .filter-icon {
opacity: 0.8;
}
thead th.filter-active .filter-icon {
opacity: 1;
color: var(--accent);
}
thead th.filter-active {
color: var(--accent);
}
.filter-popup {
position: absolute;
top: 100%;
left: 0;
min-width: 220px;
max-width: 280px;
background: rgba(15, 23, 42, 0.97);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid var(--bg-card-border);
border-radius: var(--radius-sm);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
padding: 0.75rem;
z-index: 200;
animation: filterPopupIn 0.2s ease-out both;
text-transform: none;
}
[data-theme="light"] .filter-popup {
background: rgba(255, 255, 255, 0.98);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
}
@keyframes filterPopupIn {
from {
opacity: 0;
transform: translateY(-6px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.filter-search {
width: 100%;
padding: 0.5rem 0.7rem;
background: var(--bg-input);
border: 1px solid var(--bg-card-border);
border-radius: 6px;
color: var(--text-primary);
font-family: inherit;
font-size: 0.85rem;
outline: none;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
margin-bottom: 0.5rem;
}
.filter-search::placeholder {
color: var(--text-placeholder);
}
.filter-search:focus {
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-glow);
}
.filter-btn-row {
display: flex;
gap: 0.4rem;
margin-bottom: 0.5rem;
}
.filter-btn-action {
flex: 1;
padding: 0.3rem 0.5rem;
background: var(--bg-input);
border: 1px solid var(--bg-card-border);
border-radius: 6px;
color: var(--text-secondary);
font-family: inherit;
font-size: 0.75rem;
cursor: pointer;
transition: all 0.2s ease;
}
.filter-btn-action:hover {
background: var(--bg-hover);
color: var(--text-primary);
border-color: var(--accent);
}
.filter-list {
max-height: 180px;
overflow-y: auto;
margin-bottom: 0.5rem;
scrollbar-width: thin;
scrollbar-color: var(--bg-card-border) transparent;
}
.filter-list::-webkit-scrollbar {
width: 4px;
}
.filter-list::-webkit-scrollbar-thumb {
background: var(--bg-card-border);
border-radius: 2px;
}
.filter-item {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.35rem 0.3rem;
border-radius: 4px;
cursor: pointer;
font-size: 0.85rem;
color: var(--text-primary);
transition: background 0.15s ease;
}
.filter-item:hover {
background: var(--bg-hover);
}
.filter-item input[type="checkbox"] {
cursor: pointer;
width: 1rem;
height: 1rem;
accent-color: var(--accent);
flex-shrink: 0;
}
.filter-btn-apply {
width: 100%;
padding: 0.5rem;
background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
border: none;
border-radius: 6px;
color: #fff;
font-family: inherit;
font-size: 0.82rem;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease;
box-shadow: 0 3px 10px var(--accent-glow);
}
.filter-btn-apply:hover {
transform: translateY(-1px);
box-shadow: 0 5px 15px var(--accent-glow);
}
tbody td { tbody td {
padding: 0.85rem 1rem; padding: 0.85rem 1rem;
font-size: 0.95rem; font-size: 0.95rem;
@@ -530,58 +754,3 @@ tbody tr:hover {
align-items: center; align-items: center;
gap: 8px; gap: 8px;
} }
/* ===== Modal ===== */
.modal-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(4px);
z-index: 1000;
align-items: center;
justify-content: center;
opacity: 0;
transition: opacity var(--transition);
}
.modal-overlay.open {
display: flex;
opacity: 1;
}
.modal-content {
background: var(--bg-primary);
border: 1px solid var(--bg-card-border);
border-radius: var(--radius-md);
padding: 2rem;
width: 90%;
max-width: 500px;
position: relative;
transform: scale(0.95);
transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.modal-overlay.open .modal-content {
transform: scale(1);
}
.modal-close {
position: absolute;
top: 1rem;
right: 1rem;
background: none;
border: none;
font-size: 1.5rem;
color: var(--text-secondary);
cursor: pointer;
transition: color var(--transition);
}
.modal-close:hover {
color: var(--error);
}
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
+418
View File
@@ -0,0 +1,418 @@
/* ===== Modal (общие стили) ===== */
.modal-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
/* bottom: 0; */
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(4px);
z-index: 1000;
align-items: center;
justify-content: center;
opacity: 0;
transition: opacity var(--transition);
}
.modal-overlay.open {
display: flex;
opacity: 1;
}
.modal-content {
background: var(--bg-primary);
border: 1px solid var(--bg-card-border);
border-radius: var(--radius-md);
padding: 2rem;
width: 100%;
top: 0;
max-width: 100%;
margin: 0 auto;
position: relative;
transform: scale(0.95);
transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.modal-overlay.open .modal-content {
transform: scale(1);
}
.modal-close {
position: absolute;
top: 1rem;
right: 1rem;
background: none;
border: none;
font-size: 1.5rem;
color: var(--text-secondary);
cursor: pointer;
transition: color var(--transition);
}
.modal-close:hover {
color: var(--error);
}
/* ===== Кнопки ===== */
.btn-add-lesson {
padding: 0.35rem 0.7rem;
background: rgba(16, 185, 129, 0.1);
border: 1px solid rgba(16, 185, 129, 0.2);
border-radius: var(--radius-sm);
color: var(--success);
font-family: inherit;
font-size: 0.8rem;
cursor: pointer;
transition: background var(--transition), transform var(--transition);
position: relative;
overflow: hidden;
}
.btn-add-lesson:hover {
background: rgba(16, 185, 129, 0.2);
transform: scale(1.05);
}
.btn-view-lessons {
padding: 0.35rem 0.7rem;
background: rgba(99, 102, 241, 0.1);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: var(--radius-sm);
color: var(--accent);
font-family: inherit;
font-size: 0.8rem;
cursor: pointer;
transition: all var(--transition);
white-space: nowrap;
}
.btn-view-lessons:hover {
background: rgba(99, 102, 241, 0.2);
transform: translateY(-1px);
}
/* ===== Кнопки-переключатели (неделя) ===== */
.btn-checkbox {
display: inline-block;
cursor: pointer;
}
.btn-checkbox input {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
.checkbox-btn {
display: inline-block;
padding: 0.5rem 1rem;
background: var(--bg-secondary);
border: 1px solid var(--bg-card-border);
border-radius: var(--radius-sm);
color: var(--text-primary);
transition: all var(--transition);
user-select: none;
}
.btn-checkbox input:checked + .checkbox-btn {
background: var(--success, #10b981);
border-color: var(--success, #10b981);
color: #fff;
}
/* ===========================================================
===== 2-е модальное окно (View Lessons) — ОСНОВНЫЕ ПРАВКИ =====
Требования:
- слева
- ~30% ширины
- сверху начинается СРАЗУ под 1-й модалкой
- высота = весь остаток до низа экрана
- визуально "ниже" 1-й модалки (и по z-index тоже ниже)
=========================================================== */
#modal-view-lessons.modal-overlay {
background: transparent !important;
backdrop-filter: none !important;
pointer-events: none;
z-index: 999; /* ниже чем 1-е (1000) */
}
/* В открытом состоянии: прижать влево и опустить вниз на высоту "шапки" */
#modal-view-lessons.modal-overlay.open {
justify-content: flex-start;
align-items: flex-start;
padding-left: 1rem;
padding-right: 1rem;
/* ключевое: высота 1-й модалки приходит из JS через --add-lesson-height */
padding-top: var(--add-lesson-height, 0px);
}
/* Панель 2-й модалки */
#modal-view-lessons .view-lessons-modal {
width: 30vw !important;
max-width: 30vw !important;
min-width: 320px;
pointer-events: auto;
background: var(--bg-primary);
border: 1px solid var(--bg-card-border);
border-radius: var(--radius-md);
padding: 2rem;
position: relative;
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
margin: 0;
/* отключаем "пружинку" от .modal-content */
transform: none;
/* ключевое: занимает остаток по высоте */
height: calc(100vh - var(--add-lesson-height, 0px));
max-height: calc(100vh - var(--add-lesson-height, 0px));
/* чтобы скролл был внутри, а не у всей модалки */
display: flex;
flex-direction: column;
overflow: hidden;
}
/* Header во 2-й модалке */
#modal-veiw-lessons .modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
padding-right: 2rem;
flex: 0 0 auto;
}
#modal-view-lessons .modal-header h2 {
margin: 0;
font-size: 1.3rem;
color: var(--text-primary);
}
/* Контейнер занятий: растягивается и скроллится */
#modal-view-lessons .lessons-container {
flex: 1 1 auto;
overflow-y: auto;
/* перебиваем старое ограничение */
max-height: none;
padding-right: 0.5rem;
}
/* ===== Карточки занятий ===== */
.lesson-card {
background: var(--bg-card);
border: 1px solid var(--bg-card-border);
border-radius: var(--radius-sm);
padding: 1.2rem;
margin-bottom: 1rem;
transition: all 0.2s ease;
}
.lesson-card:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
border-color: var(--accent);
}
.lesson-card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.8rem;
padding-bottom: 0.5rem;
border-bottom: 1px dashed var(--bg-card-border);
}
.lesson-group {
font-weight: 700;
color: var(--accent);
font-size: 1rem;
background: rgba(99, 102, 241, 0.1);
padding: 0.3rem 0.8rem;
border-radius: 20px;
}
.lesson-time {
color: var(--text-secondary);
font-size: 0.9rem;
display: flex;
align-items: center;
gap: 0.3rem;
}
.lesson-time::before {
content: "🕒";
font-size: 0.9rem;
opacity: 0.7;
}
.lesson-card-body {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.lesson-subject {
font-weight: 600;
color: var(--text-primary);
font-size: 1.1rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.lesson-subject::before {
content: "📚";
font-size: 1rem;
opacity: 0.7;
}
.lesson-details {
display: flex;
flex-wrap: wrap;
gap: 0.8rem;
margin-top: 0.5rem;
}
.lesson-detail-item {
background: var(--bg-input);
padding: 0.3rem 0.8rem;
border-radius: 15px;
font-size: 0.85rem;
color: var(--text-secondary);
border: 1px solid var(--bg-card-border);
}
/* День недели как разделитель */
.lesson-day-divider {
margin: 1.5rem 0 1rem 0;
font-weight: 700;
color: var(--accent);
font-size: 1.1rem;
text-transform: uppercase;
letter-spacing: 0.05em;
border-bottom: 2px solid var(--accent-glow);
padding-bottom: 0.3rem;
}
.lesson-day-divider:first-of-type {
margin-top: 0;
}
/* Загрузка/пусто */
.loading-lessons,
.no-lessons {
text-align: center;
color: var(--text-secondary);
padding: 3rem;
font-size: 1rem;
background: var(--bg-card);
border-radius: var(--radius-sm);
}
/* Светлая тема */
[data-theme="light"] .lesson-card {
background: #fff;
border-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .lesson-group {
background: rgba(99, 102, 241, 0.05);
}
/* ===== Адаптивность ===== */
@media (max-width: 1200px) {
#modal-view-lessons .view-lessons-modal {
width: 40vw !important;
max-width: 40vw !important;
}
}
@media (max-width: 768px) {
/* На мобилке делаем поведение более "обычным" */
#modal-view-lessons.modal-overlay.open {
padding-top: 1rem;
justify-content: center;
align-items: flex-start;
}
#modal-view-lessons .view-lessons-modal {
width: 90vw !important;
max-width: 90vw !important;
min-width: 0;
/* чтобы занимало почти весь экран */
height: calc(100vh - 2rem);
max-height: calc(100vh - 2rem);
}
.lesson-card-header {
flex-direction: column;
align-items: flex-start;
gap: 0.5rem;
}
}
/* ===== Скролл во 2-й модалке ===== */
#modal-view-lessons .lessons-container {
scrollbar-width: thin; /* Firefox */
scrollbar-color: rgba(99, 102, 241, 0.55) rgba(255, 255, 255, 0.06); /* thumb track */
}
/* WebKit (Chrome/Edge/Safari) */
#modal-view-lessons .lessons-container::-webkit-scrollbar {
width: 10px;
}
#modal-view-lessons .lessons-container::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.06);
border-radius: 10px;
}
#modal-view-lessons .lessons-container::-webkit-scrollbar-thumb {
background: rgba(99, 102, 241, 0.55); /* под accent */
border-radius: 10px;
border: 2px solid rgba(0, 0, 0, 0); /* чтобы выглядел “тоньше” */
background-clip: padding-box;
}
#modal-view-lessons .lessons-container::-webkit-scrollbar-thumb:hover {
background: rgba(99, 102, 241, 0.75);
}
/* Общий блюр/затемнение за модалками */
#modal-backdrop{
position: fixed;
inset: 0;
background: rgba(0,0,0,0.55);
backdrop-filter: blur(6px);
-webkit-backdrop-filter: blur(6px);
opacity: 0;
pointer-events: none;
transition: opacity var(--transition);
z-index: 998; /* ниже модалок: 999 и 1000 */
}
#modal-backdrop.open{
opacity: 1;
pointer-events: auto;
}
Regular → Executable
+10
View File
@@ -13,6 +13,7 @@
<link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/layout.css"> <link rel="stylesheet" href="css/layout.css">
<link rel="stylesheet" href="css/components.css"> <link rel="stylesheet" href="css/components.css">
<link rel="stylesheet" href="css/modals.css">
</head> </head>
<body> <body>
@@ -86,6 +87,15 @@
</svg> </svg>
Дисциплины Дисциплины
</a> </a>
<a href="#" class="nav-item" data-tab="schedule">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
<line x1="16" y1="2" x2="16" y2="6"></line>
<line x1="8" y1="2" x2="8" y2="6"></line>
<line x1="3" y1="10" x2="21" y2="10"></line>
</svg>
Расписание занятий
</a>
</nav> </nav>
<div class="sidebar-footer"> <div class="sidebar-footer">
<button class="btn-logout" id="btn-logout"> <button class="btn-logout" id="btn-logout">
Regular → Executable
View File
File mode changed.
Regular → Executable
+3
View File
@@ -7,6 +7,7 @@ import { initEduForms } from './views/edu-forms.js';
import { initEquipments } from './views/equipments.js'; import { initEquipments } from './views/equipments.js';
import { initClassrooms } from './views/classrooms.js'; import { initClassrooms } from './views/classrooms.js';
import { initSubjects } from './views/subjects.js'; import { initSubjects } from './views/subjects.js';
import {initSchedule} from "./views/schedule.js";
// Configuration // Configuration
const ROUTES = { const ROUTES = {
@@ -16,6 +17,8 @@ const ROUTES = {
equipments: { title: 'Оборудование', file: 'views/equipments.html', init: initEquipments }, equipments: { title: 'Оборудование', file: 'views/equipments.html', init: initEquipments },
classrooms: { title: 'Аудитории', file: 'views/classrooms.html', init: initClassrooms }, classrooms: { title: 'Аудитории', file: 'views/classrooms.html', init: initClassrooms },
subjects: { title: 'Дисциплины и преподаватели', file: 'views/subjects.html', init: initSubjects }, subjects: { title: 'Дисциплины и преподаватели', file: 'views/subjects.html', init: initSubjects },
// Новая вкладка
schedule: { title: 'Расписание занятий', file: 'views/schedule.html', init: initSchedule },
}; };
let currentTab = null; let currentTab = null;
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
+4 -1
View File
@@ -68,6 +68,7 @@ export async function initGroups() {
<tr> <tr>
<td>${g.id}</td> <td>${g.id}</td>
<td>${escapeHtml(g.name)}</td> <td>${escapeHtml(g.name)}</td>
<td>${escapeHtml(g.groupSize)}</td>
<td><span class="badge badge-ef">${escapeHtml(g.educationFormName)}</span></td> <td><span class="badge badge-ef">${escapeHtml(g.educationFormName)}</span></td>
<td><button class="btn-delete" data-id="${g.id}">Удалить</button></td> <td><button class="btn-delete" data-id="${g.id}">Удалить</button></td>
</tr>`).join(''); </tr>`).join('');
@@ -77,13 +78,15 @@ export async function initGroups() {
e.preventDefault(); e.preventDefault();
hideAlert('create-group-alert'); hideAlert('create-group-alert');
const name = document.getElementById('new-group-name').value.trim(); const name = document.getElementById('new-group-name').value.trim();
const groupSize = document.getElementById('new-group-size').value;
const educationFormId = newGroupEfSelect.value; const educationFormId = newGroupEfSelect.value;
if (!name) { showAlert('create-group-alert', 'Введите название группы', 'error'); return; } if (!name) { showAlert('create-group-alert', 'Введите название группы', 'error'); return; }
if (!groupSize) { showAlert('create-group-alert', 'Введите размер группы', 'error'); return; }
if (!educationFormId) { showAlert('create-group-alert', 'Выберите форму обучения', 'error'); return; } if (!educationFormId) { showAlert('create-group-alert', 'Выберите форму обучения', 'error'); return; }
try { try {
const data = await api.post('/api/groups', { name, educationFormId: Number(educationFormId) }); const data = await api.post('/api/groups', { name, groupSize, educationFormId: Number(educationFormId) });
showAlert('create-group-alert', `Группа "${escapeHtml(data.name)}" создана`, 'success'); showAlert('create-group-alert', `Группа "${escapeHtml(data.name)}" создана`, 'success');
createGroupForm.reset(); createGroupForm.reset();
loadGroups(); loadGroups();
+370
View File
@@ -0,0 +1,370 @@
import { api } from '../api.js';
import { escapeHtml } from '../utils.js';
export async function initSchedule() {
const tbody = document.getElementById('schedule-tbody');
const table = document.getElementById('schedule-table');
let lessonsData = [];
let sortKey = null;
let sortDir = 'asc';
// Активные фильтры: { teacher: Set, group: Set, subject: Set, day: Set }
const activeFilters = {};
// Маппинг дней недели для корректной сортировки
const dayOrder = {
'понедельник': 1, 'вторник': 2, 'среда': 3,
'четверг': 4, 'пятница': 5, 'суббота': 6, 'воскресенье': 7
};
// ===================== Фильтрация =====================
// Извлечение отображаемого значения поля для фильтрации
function getDisplayValue(lesson, key) {
switch (key) {
case 'teacher':
return lesson.teacher?.username || lesson.teacherName || '—';
case 'group':
return lesson.group?.name || lesson.groupName || '—';
case 'subject':
return lesson.subject?.name || lesson.subjectName || '—';
case 'day':
return lesson.day || '—';
case 'educationForm':
return lesson.educationForm?.name || lesson.educationFormName || '—';
default:
return '';
}
}
// Собрать уникальные значения из данных
function getUniqueValues(key) {
const vals = new Set();
lessonsData.forEach(lesson => {
vals.add(getDisplayValue(lesson, key));
});
// Для дней — сортируем по порядку
if (key === 'day') {
return [...vals].sort((a, b) => (dayOrder[a.toLowerCase()] ?? 99) - (dayOrder[b.toLowerCase()] ?? 99));
}
return [...vals].sort((a, b) => a.localeCompare(b, 'ru'));
}
// Применить все фильтры
function applyFilters(lessons) {
return lessons.filter(lesson => {
for (const key of Object.keys(activeFilters)) {
const filterSet = activeFilters[key];
if (filterSet && filterSet.size > 0) {
const val = getDisplayValue(lesson, key);
if (!filterSet.has(val)) return false;
}
}
return true;
});
}
// ===================== Попап фильтра =====================
let currentPopup = null;
function closePopup() {
if (currentPopup) {
currentPopup.remove();
currentPopup = null;
}
document.removeEventListener('click', onDocumentClick, true);
}
function onDocumentClick(e) {
if (currentPopup && !currentPopup.contains(e.target)) {
// Проверяем, не кликнули ли по иконке фильтра
if (!e.target.closest('.filter-icon')) {
closePopup();
}
}
}
function openFilterPopup(th, filterKey) {
// Если уже открыт этот же — закрыть
if (currentPopup && currentPopup.dataset.filterKey === filterKey) {
closePopup();
return;
}
closePopup();
const uniqueValues = getUniqueValues(filterKey);
const currentFilter = activeFilters[filterKey];
// Создаём попап
const popup = document.createElement('div');
popup.className = 'filter-popup';
popup.dataset.filterKey = filterKey;
// Поисковое поле
const searchInput = document.createElement('input');
searchInput.type = 'text';
searchInput.className = 'filter-search';
searchInput.placeholder = 'Поиск...';
popup.appendChild(searchInput);
// Кнопки «Выбрать все» / «Сбросить»
const btnRow = document.createElement('div');
btnRow.className = 'filter-btn-row';
const btnAll = document.createElement('button');
btnAll.className = 'filter-btn-action';
btnAll.textContent = 'Все';
btnAll.addEventListener('click', (e) => {
e.stopPropagation();
checkboxes.forEach(cb => { cb.checked = true; });
});
const btnNone = document.createElement('button');
btnNone.className = 'filter-btn-action';
btnNone.textContent = 'Сбросить';
btnNone.addEventListener('click', (e) => {
e.stopPropagation();
checkboxes.forEach(cb => { cb.checked = false; });
});
btnRow.appendChild(btnAll);
btnRow.appendChild(btnNone);
popup.appendChild(btnRow);
// Список чекбоксов
const listWrap = document.createElement('div');
listWrap.className = 'filter-list';
const checkboxes = [];
uniqueValues.forEach(val => {
const label = document.createElement('label');
label.className = 'filter-item';
const cb = document.createElement('input');
cb.type = 'checkbox';
cb.value = val;
// Если фильтр активен — отмечаем только выбранные; если нет — все отмечены
cb.checked = currentFilter ? currentFilter.has(val) : true;
const span = document.createElement('span');
span.textContent = val;
label.appendChild(cb);
label.appendChild(span);
listWrap.appendChild(label);
checkboxes.push(cb);
});
popup.appendChild(listWrap);
// Кнопка «Применить»
const btnApply = document.createElement('button');
btnApply.className = 'filter-btn-apply';
btnApply.textContent = 'Применить';
btnApply.addEventListener('click', (e) => {
e.stopPropagation();
const selected = new Set();
checkboxes.forEach(cb => {
if (cb.checked) selected.add(cb.value);
});
// Если все выбраны — снимаем фильтр
if (selected.size === uniqueValues.length) {
delete activeFilters[filterKey];
th.classList.remove('filter-active');
} else {
activeFilters[filterKey] = selected;
th.classList.add('filter-active');
}
closePopup();
renderSchedule(lessonsData);
});
popup.appendChild(btnApply);
// Поиск по чекбоксам
searchInput.addEventListener('input', () => {
const query = searchInput.value.toLowerCase();
listWrap.querySelectorAll('.filter-item').forEach(item => {
const text = item.querySelector('span').textContent.toLowerCase();
item.style.display = text.includes(query) ? '' : 'none';
});
});
// Предотвращаем всплытие кликов внутри попапа (чтобы не срабатывала сортировка th)
popup.addEventListener('click', (e) => e.stopPropagation());
searchInput.addEventListener('click', (e) => e.stopPropagation());
// Позиционируем попап под th
th.style.position = 'relative';
th.appendChild(popup);
currentPopup = popup;
// Фокус на поиск
setTimeout(() => searchInput.focus(), 50);
// Закрытие по клику вне
setTimeout(() => {
document.addEventListener('click', onDocumentClick, true);
}, 10);
}
// Обработчики кликов по заголовкам с фильтрами (клик по всей ячейке)
table.querySelectorAll('thead th.filterable').forEach(th => {
th.addEventListener('click', (e) => {
// Не открываем попап при клике внутри самого попапа
if (e.target.closest('.filter-popup')) return;
const filterKey = th.dataset.filterKey;
openFilterPopup(th, filterKey);
});
});
// ===================== Сортировка =====================
function getSortValue(lesson, key) {
switch (key) {
case 'id':
return lesson.id ?? 0;
case 'teacher':
return (lesson.teacher?.username || lesson.teacherName || '').toLowerCase();
case 'group':
return (lesson.group?.name || lesson.groupName || '').toLowerCase();
case 'classroomName':
return (lesson.classroomName?.name || lesson.classroomName || '').toLowerCase();
case 'educationForm':
return (lesson.educationForm?.name || lesson.educationFormName || '').toLowerCase();
case 'subject':
return (lesson.subject?.name || lesson.subjectName || '').toLowerCase();
case 'lessonFormat':
return (lesson.lessonFormat?.name || lesson.lessonFormat || '').toLowerCase();
case 'typeLesson':
return (lesson.typeLesson?.name || lesson.typeLesson || '').toLowerCase();
case 'day': {
const d = (lesson.day || '').toLowerCase();
return dayOrder[d] ?? 99;
}
case 'week':
return (lesson.week || '').toLowerCase();
case 'time': {
// Составной ключ: день + время для правильной сортировки
const d = (lesson.day || '').toLowerCase();
const dayNum = dayOrder[d] ?? 99;
const t = lesson.time || '99:99';
return String(dayNum).padStart(2, '0') + '_' + t;
}
default:
return '';
}
}
function sortLessons(lessons) {
if (!sortKey) return lessons;
return [...lessons].sort((a, b) => {
let va = getSortValue(a, sortKey);
let vb = getSortValue(b, sortKey);
if (typeof va === 'number' && typeof vb === 'number') {
return sortDir === 'asc' ? va - vb : vb - va;
}
va = String(va);
vb = String(vb);
const cmp = va.localeCompare(vb, 'ru');
return sortDir === 'asc' ? cmp : -cmp;
});
}
function updateSortHeaders() {
table.querySelectorAll('thead th.sortable').forEach(th => {
th.classList.remove('sort-asc', 'sort-desc', 'sort-active');
if (th.dataset.sortKey === sortKey) {
th.classList.add('sort-active', sortDir === 'asc' ? 'sort-asc' : 'sort-desc');
}
});
}
// Навешиваем обработчики клика на заголовки (сортировка)
table.querySelectorAll('thead th.sortable').forEach(th => {
th.addEventListener('click', (e) => {
// Не сортируем, если кликнули по иконке фильтра или внутри попапа
if (e.target.closest('.filter-icon') || e.target.closest('.filter-popup')) return;
const key = th.dataset.sortKey;
if (sortKey === key) {
if (sortDir === 'asc') {
sortDir = 'desc';
} else {
sortKey = null;
sortDir = 'asc';
}
} else {
sortKey = key;
sortDir = 'asc';
}
updateSortHeaders();
renderSchedule(lessonsData);
});
});
// ===================== Загрузка и рендер =====================
async function loadSchedule() {
try {
const lessons = await api.get('/api/users/lessons');
lessonsData = lessons;
renderSchedule(lessons);
} catch (e) {
tbody.innerHTML = `<tr><td colspan="8" class="loading-row">Ошибка загрузки: ${escapeHtml(e.message)}</td></tr>`;
}
}
function renderSchedule(lessons) {
if (!lessons || !lessons.length) {
tbody.innerHTML = '<tr><td colspan="8" class="loading-row">Нет занятий</td></tr>';
return;
}
// Сначала фильтруем, потом сортируем
const filtered = applyFilters(lessons);
if (!filtered.length) {
tbody.innerHTML = '<tr><td colspan="8" class="loading-row">Нет занятий по выбранным фильтрам</td></tr>';
return;
}
const sorted = sortLessons(filtered);
tbody.innerHTML = sorted.map(lesson => {
const teacherName = lesson.teacher?.username || lesson.teacherName || '—';
const groupName = lesson.group?.name || lesson.groupName || '—';
const classroomName = lesson.classroom?.name || lesson.classroomName || '—';
const educationForm = lesson.educationForm?.name || lesson.educationFormName || '-';
const subjectName = lesson.subject?.name || lesson.subjectName || '—';
const lessonFormat = lesson.lessonFormat?.name || lesson.lessonFormat || '—';
const typeLesson = lesson.typeLesson?.name || lesson.typeLesson || '—';
const day = lesson.day || '—';
const week = lesson.week || '—';
const time = lesson.time || '—';
return `<tr>
<td>${escapeHtml(lesson.id)}</td>
<td>${escapeHtml(teacherName)}</td>
<td>${escapeHtml(groupName)}</td>
<td>${escapeHtml(classroomName)}</td>
<td>${escapeHtml(educationForm)}</td>
<td>${escapeHtml(subjectName)}</td>
<td>${escapeHtml(lessonFormat)}</td>
<td>${escapeHtml(typeLesson)}</td>
<td>${escapeHtml(day)}</td>
<td>${escapeHtml(week)}</td>
<td>${escapeHtml(time)}</td>
</tr>`;
}).join('');
}
await loadSchedule();
}
View File
File mode changed.
Regular → Executable
+507 -20
View File
@@ -7,14 +7,197 @@ const ROLE_BADGE = { ADMIN: 'badge-admin', TEACHER: 'badge-teacher', STUDENT: 'b
export async function initUsers() { export async function initUsers() {
const usersTbody = document.getElementById('users-tbody'); const usersTbody = document.getElementById('users-tbody');
const createForm = document.getElementById('create-form'); const createForm = document.getElementById('create-form');
const createAlert = document.getElementById('create-alert'); const modalBackdrop = document.getElementById('modal-backdrop');
// ===== 1-е модальное окно: Добавить занятие =====
const modalAddLesson = document.getElementById('modal-add-lesson');
const modalAddLessonClose = document.getElementById('modal-add-lesson-close');
const addLessonForm = document.getElementById('add-lesson-form');
const lessonGroupSelect = document.getElementById('lesson-group');
const lessonDisciplineSelect = document.getElementById('lesson-discipline');
const lessonClassroomSelect = document.getElementById('lesson-classroom');
const lessonTypeSelect = document.getElementById('lesson-type');
const lessonOnlineFormat = document.getElementById('format-online');
const lessonOfflineFormat = document.getElementById('format-offline');
const lessonUserId = document.getElementById('lesson-user-id');
const lessonDaySelect = document.getElementById('lesson-day');
const weekUpper = document.getElementById('week-upper');
const weekLower = document.getElementById('week-lower');
const lessonTimeSelect = document.getElementById('lesson-time');
// ===== 2-е модальное окно: Просмотр занятий =====
const modalViewLessons = document.getElementById('modal-view-lessons');
const modalViewLessonsClose = document.getElementById('modal-view-lessons-close');
const lessonsContainer = document.getElementById('lessons-container');
const modalTeacherName = document.getElementById('modal-teacher-name');
let currentLessonsTeacherId = null;
let currentLessonsTeacherName = '';
// ===== Данные =====
let groups = [];
let subjects = [];
let classrooms = [];
const weekdaysTimes = [
"8:00-9:30",
"9:40-11:10",
"11:40-13:10",
"13:20-14:50",
"15:00-16:30",
"16:50-18:20",
"18:30-19:00"
];
const saturdayTimes = [
"8:20-9:50",
"10:00-11:30",
"11:40-13:10",
"13:20-14:50"
];
// =========================================================
// СИНХРОНИЗАЦИЯ ВЫСОТЫ 1-й МОДАЛКИ -> CSS переменная
// =========================================================
const addLessonContent = document.querySelector('#modal-add-lesson .modal-content');
function setAddLessonHeightVar(px) {
const h = Math.max(0, Math.ceil(px || 0));
document.documentElement.style.setProperty('--add-lesson-height', `${h}px`);
}
function syncAddLessonHeight() {
if (!addLessonContent) return;
if (!modalAddLesson?.classList.contains('open')) {
// если первая модалка закрыта — "шапки" нет
setAddLessonHeightVar(0);
return;
}
setAddLessonHeightVar(addLessonContent.getBoundingClientRect().height);
}
// Авто-обновление при любом изменении размеров первой модалки
if (addLessonContent && 'ResizeObserver' in window) {
const ro = new ResizeObserver(() => syncAddLessonHeight());
ro.observe(addLessonContent);
}
window.addEventListener('resize', () => syncAddLessonHeight());
// =========================================================
// Загрузка справочников
// =========================================================
async function loadGroups() {
try {
groups = await api.get('/api/groups');
renderGroupOptions();
} catch (e) {
console.error('Ошибка загрузки групп:', e);
}
}
async function loadSubjects() {
try {
subjects = await api.get('/api/subjects');
renderSubjectOptions();
} catch (e) {
console.error('Ошибка загрузки дисциплин:', e);
}
}
async function loadClassrooms() {
try {
classrooms = await api.get('/api/classrooms');
renderClassroomsOptions();
} catch (e) {
console.error('Ошибка загрузки аудиторий:', e);
}
}
function renderGroupOptions() {
if (!groups || groups.length === 0) {
lessonGroupSelect.innerHTML = '<option value="">Нет доступных групп</option>';
return;
}
lessonGroupSelect.innerHTML =
'<option value="">Выберите группу</option>' +
groups.map(g => {
let optionText = escapeHtml(g.name);
if (g.groupSize) optionText += ` (численность: ${g.groupSize} чел.)`;
return `<option value="${g.id}">${optionText}</option>`;
}).join('');
}
function renderSubjectOptions() {
lessonDisciplineSelect.innerHTML =
'<option value="">Выберите дисциплину</option>' +
subjects.map(s => `<option value="${s.id}">${escapeHtml(s.name)}</option>`).join('');
}
function renderClassroomsOptions() {
if (!classrooms || classrooms.length === 0) {
lessonClassroomSelect.innerHTML = '<option value="">Нет доступных аудиторий</option>';
return;
}
const selectedGroupId = lessonGroupSelect.value;
const selectedGroup = groups?.find(g => g.id == selectedGroupId);
const groupSize = selectedGroup?.groupSize || 0;
lessonClassroomSelect.innerHTML =
'<option value="">Выберите аудиторию</option>' +
classrooms.map(c => {
let optionText = escapeHtml(c.name);
if (c.capacity) optionText += ` (вместимость: ${c.capacity} чел.)`;
if (c.isAvailable === false) {
optionText += ` ❌ Занята`;
} else if (selectedGroupId && groupSize > 0 && c.capacity && groupSize > c.capacity) {
optionText += ` ⚠️ Недостаточно места`;
}
return `<option value="${c.id}">${optionText}</option>`;
}).join('');
}
lessonGroupSelect.addEventListener('change', function () {
renderClassroomsOptions();
requestAnimationFrame(() => syncAddLessonHeight());
});
function updateTimeOptions(dayValue) {
let times = [];
if (dayValue === "Суббота") {
times = saturdayTimes;
} else if (dayValue && dayValue !== '') {
times = weekdaysTimes;
} else {
lessonTimeSelect.innerHTML = '<option value="">Сначала выберите день</option>';
lessonTimeSelect.disabled = true;
return;
}
lessonTimeSelect.innerHTML =
'<option value="">Выберите время</option>' +
times.map(t => `<option value="${t}">${t}</option>`).join('');
lessonTimeSelect.disabled = false;
}
// =========================================================
// Пользователи
// =========================================================
async function loadUsers() { async function loadUsers() {
try { try {
const users = await api.get('/api/users'); const users = await api.get('/api/users');
renderUsers(users); renderUsers(users);
} catch (e) { } catch (e) {
usersTbody.innerHTML = '<tr><td colspan="4" class="loading-row">Ошибка загрузки: ' + escapeHtml(e.message) + '</td></tr>'; usersTbody.innerHTML =
'<tr><td colspan="4" class="loading-row">Ошибка загрузки: ' +
escapeHtml(e.message) + '</td></tr>';
} }
} }
@@ -23,45 +206,349 @@ export async function initUsers() {
usersTbody.innerHTML = '<tr><td colspan="4" class="loading-row">Нет пользователей</td></tr>'; usersTbody.innerHTML = '<tr><td colspan="4" class="loading-row">Нет пользователей</td></tr>';
return; return;
} }
usersTbody.innerHTML = users.map(u => ` usersTbody.innerHTML = users.map(u => `
<tr> <tr>
<td>${u.id}</td> <td>${u.id}</td>
<td>${escapeHtml(u.username)}</td> <td>${escapeHtml(u.username)}</td>
<td><span class="badge ${ROLE_BADGE[u.role] || ''}">${ROLE_LABELS[u.role] || escapeHtml(u.role)}</span></td> <td><span class="badge ${ROLE_BADGE[u.role] || ''}">${ROLE_LABELS[u.role] || escapeHtml(u.role)}</span></td>
<td><button class="btn-delete" data-id="${u.id}">Удалить</button></td> <td>
</tr>`).join(''); <button class="btn-delete" data-id="${u.id}">Удалить</button>
</td>
<td>
<button class="btn-add-lesson" data-id="${u.id}" data-name="${escapeHtml(u.username)}">Добавить занятие</button>
</td>
</tr>
`).join('');
} }
function updateBackdrop() {
if(!modalBackdrop) return;
const anyOpen =
modalAddLesson?.classList.contains('open') ||
modalViewLessons?.classList.contains('open');
modalBackdrop.classList.toggle('open', anyOpen);
}
// Клик мимо модалок закроет их, если не надо, то закомментить этот код
modalBackdrop?.addEventListener('click', () => {
if (modalAddLesson?.classList.contains('open')) {
modalAddLesson.classList.remove('open');
resetLessonForm();
syncAddLessonHeight();
}
if (modalViewLessons?.classList.contains('open')) {
closeViewLessonsModal();
}
});
// =========================================================
// 1-я модалка: добавление занятия
// =========================================================
function resetLessonForm() {
addLessonForm.reset();
lessonUserId.value = '';
if (weekUpper) weekUpper.checked = false;
if (weekLower) weekLower.checked = false;
if (lessonOfflineFormat) lessonOfflineFormat.checked = true;
if (lessonOnlineFormat) lessonOnlineFormat.checked = false;
lessonTimeSelect.innerHTML = '<option value="">Сначала выберите день</option>';
lessonTimeSelect.disabled = true;
hideAlert('add-lesson-alert');
}
function openAddLessonModal(userId) {
lessonUserId.value = userId;
lessonDaySelect.value = '';
updateTimeOptions('');
modalAddLesson.classList.add('open');
updateBackdrop();
requestAnimationFrame(() => syncAddLessonHeight());
}
addLessonForm.addEventListener('submit', async (e) => {
e.preventDefault();
hideAlert('add-lesson-alert');
const userId = lessonUserId.value;
const groupId = lessonGroupSelect.value;
const subjectId = lessonDisciplineSelect.value;
const classroomId = lessonClassroomSelect.value;
const lessonType = lessonTypeSelect.value;
const dayOfWeek = lessonDaySelect.value;
const timeSlot = lessonTimeSelect.value;
const lessonFormat = document.querySelector('input[name="lessonFormat"]:checked')?.value;
if (!groupId) { showAlert('add-lesson-alert', 'Выберите группу', 'error'); requestAnimationFrame(() => syncAddLessonHeight()); return; }
if (!subjectId) { showAlert('add-lesson-alert', 'Выберите дисциплину', 'error'); requestAnimationFrame(() => syncAddLessonHeight()); return; }
if (!classroomId) { showAlert('add-lesson-alert', 'Выберите аудиторию', 'error'); requestAnimationFrame(() => syncAddLessonHeight()); return; }
if (!dayOfWeek) { showAlert('add-lesson-alert', 'Выберите день недели', 'error'); requestAnimationFrame(() => syncAddLessonHeight()); return; }
if (!timeSlot) { showAlert('add-lesson-alert', 'Выберите время', 'error'); requestAnimationFrame(() => syncAddLessonHeight()); return; }
const weekUpperChecked = weekUpper?.checked || false;
const weekLowerChecked = weekLower?.checked || false;
let weekType = null;
if (weekUpperChecked && weekLowerChecked) weekType = 'Обе';
else if (weekUpperChecked) weekType = 'Верхняя';
else if (weekLowerChecked) weekType = 'Нижняя';
try {
await api.post('/api/users/lessons/create', {
teacherId: parseInt(userId),
groupId: parseInt(groupId),
subjectId: parseInt(subjectId),
classroomId: parseInt(classroomId),
typeLesson: lessonType,
lessonFormat: lessonFormat,
day: dayOfWeek,
week: weekType,
time: timeSlot
});
if (modalViewLessons?.classList.contains('open') && currentLessonsTeacherId == userId) {
await loadTeacherLessons(currentLessonsTeacherId, currentLessonsTeacherName);
}
showAlert('add-lesson-alert', 'Занятие добавлено', 'success');
lessonGroupSelect.value = '';
lessonDisciplineSelect.value = '';
lessonClassroomSelect.value = '';
lessonTypeSelect.value = '';
lessonDaySelect.value = '';
lessonTimeSelect.value = '';
lessonTimeSelect.disabled = true;
weekUpper.checked = false;
weekLower.checked = false;
document.querySelector('input[name="lessonFormat"][value="Очно"]').checked = true;
requestAnimationFrame(() => syncAddLessonHeight());
setTimeout(() => {
hideAlert('add-lesson-alert');
syncAddLessonHeight();
}, 3000);
} catch (err) {
showAlert('add-lesson-alert', err.message || 'Ошибка добавления занятия', 'error');
requestAnimationFrame(() => syncAddLessonHeight());
}
});
lessonDaySelect.addEventListener('change', function () {
updateTimeOptions(this.value);
requestAnimationFrame(() => syncAddLessonHeight());
});
if (modalAddLessonClose) {
modalAddLessonClose.addEventListener('click', () => {
modalAddLesson.classList.remove('open');
resetLessonForm();
syncAddLessonHeight();
updateBackdrop();
});
}
if (modalAddLesson) {
modalAddLesson.addEventListener('click', (e) => {
if (e.target === modalAddLesson) {
modalAddLesson.classList.remove('open');
resetLessonForm();
syncAddLessonHeight();
updateBackdrop();
}
});
}
// =========================================================
// Создание пользователя
// =========================================================
createForm.addEventListener('submit', async (e) => { createForm.addEventListener('submit', async (e) => {
e.preventDefault(); e.preventDefault();
hideAlert('create-alert'); hideAlert('create-alert');
const username = document.getElementById('new-username').value.trim(); const username = document.getElementById('new-username').value.trim();
const password = document.getElementById('new-password').value; const password = document.getElementById('new-password').value;
const role = document.getElementById('new-role').value; const role = document.getElementById('new-role').value;
if (!username || !password) { showAlert('create-alert', 'Заполните все поля', 'error'); return; }
if (!username || !password) {
showAlert('create-alert', 'Заполните все поля', 'error');
return;
}
try { try {
const data = await api.post('/api/users', { username, password, role }); const data = await api.post('/api/users', { username, password, role });
showAlert('create-alert', `Пользователь "${escapeHtml(data.username)}" создан`, 'success'); showAlert('create-alert', `Пользователь "${escapeHtml(data.username)}" создан`, 'success');
createForm.reset(); createForm.reset();
loadUsers(); loadUsers();
} catch (e) { } catch (err) {
showAlert('create-alert', e.message || 'Ошибка соединения', 'error'); showAlert('create-alert', err.message || 'Ошибка соединения', 'error');
} }
}); });
usersTbody.addEventListener('click', async (e) => { // =========================================================
const btn = e.target.closest('.btn-delete'); // Инициализация
if (!btn) return; // =========================================================
if (!confirm('Удалить пользователя?')) return; await Promise.all([loadUsers(), loadGroups(), loadSubjects(), loadClassrooms()]);
// =========================================================
// 2-я модалка: просмотр занятий
// =========================================================
async function loadTeacherLessons(teacherId, teacherName) {
try { try {
await api.delete('/api/users/' + btn.dataset.id); lessonsContainer.innerHTML = '<div class="loading-lessons">Загрузка занятий...</div>';
loadUsers();
modalTeacherName.textContent = teacherName
? `Занятия преподавателя: ${teacherName}`
: 'Занятия преподавателя';
const lessons = await api.get(`/api/users/lessons/${teacherId}`);
if (!lessons || lessons.length === 0) {
lessonsContainer.innerHTML = '<div class="no-lessons">У преподавателя пока нет занятий</div>';
return;
}
const daysOrder = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'];
const lessonsByDay = {};
lessons.forEach(lesson => {
if (!lessonsByDay[lesson.day]) lessonsByDay[lesson.day] = [];
lessonsByDay[lesson.day].push(lesson);
});
Object.keys(lessonsByDay).forEach(day => {
lessonsByDay[day].sort((a, b) => a.time.localeCompare(b.time));
});
let html = '';
daysOrder.forEach(day => {
if (!lessonsByDay[day]) return;
html += `<div class="lesson-day-divider">${day}</div>`;
lessonsByDay[day].forEach(lesson => {
html += `
<div class="lesson-card">
<div class="lesson-card-header">
<span class="lesson-group">${escapeHtml(lesson.groupName)}</span>
<span class="lesson-time">${escapeHtml(lesson.time)}</span>
</div>
<div class="lesson-card-body">
<div class="lesson-subject">${escapeHtml(lesson.subjectName)}</div>
<div class="lesson-details">
<span class="lesson-detail-item">${escapeHtml(lesson.typeLesson)}</span>
<span class="lesson-detail-item">${escapeHtml(lesson.lessonFormat)}</span>
<span class="lesson-detail-item">${escapeHtml(lesson.week)}</span>
<span class="lesson-detail-item">${escapeHtml(lesson.classroomName)}</span>
</div>
</div>
</div>
`;
});
});
lessonsContainer.innerHTML = html;
} catch (e) { } catch (e) {
alert(e.message || 'Ошибка удаления'); lessonsContainer.innerHTML = `<div class="no-lessons">Ошибка загрузки: ${escapeHtml(e.message)}</div>`;
console.error('Ошибка загрузки занятий:', e);
}
}
function openViewLessonsModal(teacherId, teacherName) {
currentLessonsTeacherId = teacherId;
currentLessonsTeacherName = teacherName || '';
loadTeacherLessons(teacherId, teacherName);
requestAnimationFrame(() => syncAddLessonHeight());
modalViewLessons.classList.add('open');
updateBackdrop();
// document.body.style.overflow = 'hidden';
}
function closeViewLessonsModal() {
modalViewLessons.classList.remove('open');
updateBackdrop();
// document.body.style.overflow = '';
currentLessonsTeacherId = null;
currentLessonsTeacherName = '';
}
if (modalViewLessonsClose) {
modalViewLessonsClose.addEventListener('click', closeViewLessonsModal);
}
if (modalViewLessons) {
modalViewLessons.addEventListener('click', (e) => {
if (e.target === modalViewLessons) closeViewLessonsModal();
});
}
document.addEventListener('keydown', (e) => {
if (e.key !== 'Escape') return;
if (modalAddLesson?.classList.contains('open')) {
modalAddLesson.classList.remove('open');
resetLessonForm();
syncAddLessonHeight();
updateBackdrop();
return;
}
if (modalViewLessons?.classList.contains('open')) {
closeViewLessonsModal();
return;
} }
}); });
// Initial load // =========================================================
loadUsers(); // ЕДИНЫЙ обработчик кликов по таблице (ВАЖНО: без дубля)
// =========================================================
usersTbody.addEventListener('click', async (e) => {
const deleteBtn = e.target.closest('.btn-delete');
if (deleteBtn) {
if (!confirm('Удалить пользователя?')) return;
try {
await api.delete('/api/users/' + deleteBtn.dataset.id);
loadUsers();
} catch (err) {
alert(err.message || 'Ошибка удаления');
}
return;
}
const addLessonBtn = e.target.closest('.btn-add-lesson');
if (addLessonBtn) {
e.preventDefault();
const teacherId = addLessonBtn.dataset.id;
const teacherName = addLessonBtn.dataset.name;
openAddLessonModal(teacherId);
openViewLessonsModal(teacherId, teacherName);
return;
}
const viewLessonsBtn = e.target.closest('.btn-view-lessons');
if (viewLessonsBtn) {
e.preventDefault();
const teacherId = viewLessonsBtn.dataset.id;
const teacherName = viewLessonsBtn.dataset.name;
openViewLessonsModal(teacherId, teacherName);
return;
}
});
} }
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
Regular → Executable
+5
View File
@@ -7,6 +7,10 @@
<label for="new-group-name">Название группы</label> <label for="new-group-name">Название группы</label>
<input type="text" id="new-group-name" placeholder="ИВТ-21-1" required> <input type="text" id="new-group-name" placeholder="ИВТ-21-1" required>
</div> </div>
<div class="form-group">
<label for="new-group-size">Численность группы</label>
<input type="text" id="new-group-size" placeholder="20" required>
</div>
<div class="form-group"> <div class="form-group">
<label for="new-group-ef">Форма обучения</label> <label for="new-group-ef">Форма обучения</label>
<select id="new-group-ef"> <select id="new-group-ef">
@@ -35,6 +39,7 @@
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>Название</th> <th>Название</th>
<th>Численность (чел.)</th>
<th>Форма обучения</th> <th>Форма обучения</th>
<th>Действия</th> <th>Действия</th>
</tr> </tr>
+43
View File
@@ -0,0 +1,43 @@
<div class="card">
<h2>Расписание занятий</h2>
<div class="table-wrap">
<table id="schedule-table">
<thead>
<tr>
<th class="sortable" data-sort-key="id">ID <span class="sort-arrow"></span></th>
<th class="filterable" data-filter-key="teacher">
Преподаватель <span class="filter-icon">&#9662;</span>
</th>
<th class="filterable" data-filter-key="group">
Группа <span class="filter-icon">&#9662;</span>
</th>
<th class="filterable" data-filter-key="classroomName">
Аудитория <span class="filter-icon">&#9662;</span>
</th>
<th class="filterable" data-filter-key="educationForm">
Форма обучения <span class="filter-icon">&#9662;</span>
</th>
<th class="filterable" data-filter-key="subject">
Дисциплина <span class="filter-icon">&#9662;</span>
</th>
<th class="filterable" data-filter-key="lessonFormat">
Формат занятия <span class="filter-icon">&#9662;</span>
</th>
<th class="filterable" data-filter-key="typeLesson">
Тип занятия <span class="filter-icon">&#9662;</span>
</th>
<th class="filterable" data-filter-key="day">
День недели <span class="filter-icon">&#9662;</span>
</th>
<th>Неделя</th>
<th>Время</th>
</tr>
</thead>
<tbody id="schedule-tbody">
<tr>
<td colspan="8" class="loading-row">Загрузка...</td>
</tr>
</tbody>
</table>
</div>
</div>
View File
File mode changed.
Regular → Executable
+125
View File
@@ -45,3 +45,128 @@
</table> </table>
</div> </div>
</div> </div>
<!-- Add Lesson Modal -->
<div class="modal-overlay" id="modal-add-lesson">
<div class="modal-content card">
<h2>Добавить занятие</h2>
<button class="modal-close" id="modal-add-lesson-close">&times;</button>
<form id="add-lesson-form">
<input type="hidden" id="lesson-user-id">
<!-- Один общий ряд для всех элементов -->
<div class="form-row" style="align-items: flex-end; gap: 1rem; flex-wrap: wrap; width: 100%; justify-content: space-between;">
<!-- Группа -->
<div class="form-group" style="flex: 0 1 auto; max-width: 190px">
<label for="lesson-group">Группа</label>
<select id="lesson-group" required>
<option value="">Выберите группу</option>
</select>
</div>
<!-- Дисциплина -->
<div class="form-group" style="flex: 0 1 auto; max-width: 220px">
<label for="lesson-discipline">Дисциплина</label>
<select id="lesson-discipline" required>
<option value="">Выберите дисциплину</option>
</select>
</div>
<!-- Аудитория -->
<div class="form-group" style="flex: 0 1 auto; max-width: 215px">
<label for="lesson-classroom">Аудитория</label>
<select id="lesson-classroom" required>
<option value="">Выберите аудиторию</option>
</select>
</div>
<!-- День недели -->
<div class="form-group" style="flex: 0 1 auto; max-width: 170px">
<label for="lesson-day">День недели</label>
<select id="lesson-day" required>
<option value="">Выберите день</option>
<option value="Понедельник">Понедельник</option>
<option value="Вторник">Вторник</option>
<option value="Среда">Среда</option>
<option value="Четверг">Четверг</option>
<option value="Пятница">Пятница</option>
<option value="Суббота">Суббота</option>
</select>
</div>
<!-- Тип недели (ВЕРТИКАЛЬНО) -->
<div class="form-group" style="flex: 0 1 auto; max-width: 192px">
<label>Неделя</label>
<div style="display: flex; gap: 0.2rem;">
<label class="btn-checkbox">
<input type="checkbox" name="weekType" value="Верхняя" id="week-upper">
<span class="checkbox-btn">Верхняя</span>
</label>
<label class="btn-checkbox">
<input type="checkbox" name="weekType" value="Нижняя" id="week-lower">
<span class="checkbox-btn">Нижняя</span>
</label>
</div>
</div>
<!-- Тип занятия -->
<div class="form-group" style="flex: 0 1 auto; max-width: 160px">
<label for="lesson-type">Тип занятия</label>
<select id="lesson-type" required>
<option value="">Выберите тип</option>
<option value="Практическая работа">Практическая</option>
<option value="Лекция">Лекция</option>
<option value="Лабораторная работа">Лабораторная</option>
</select>
</div>
<!-- Формат занятия (ВЕРТИКАЛЬНО) -->
<div class="form-group" style="flex: 0 1 auto; max-width: 170px">
<label>Формат занятия</label>
<div style="display: flex; gap: 0.2rem;">
<label class="btn-checkbox">
<input type="radio" name="lessonFormat" value="Очно" id="format-offline" checked>
<span class="checkbox-btn">Очно</span>
</label>
<label class="btn-checkbox">
<input type="radio" name="lessonFormat" value="Онлайн" id="format-online">
<span class="checkbox-btn">Онлайн</span>
</label>
</div>
</div>
<!-- Время занятия -->
<div class="form-group" style="flex: 0 0 auto; max-width: 235px">
<label for="lesson-time">Время занятия</label>
<select id="lesson-time" required disabled>
<option value="">Сначала выберите день</option>
</select>
</div>
<!-- Кнопка Сохранить (в том же ряду) -->
<div class="form-group" style="flex: 0 0 auto;">
<button type="submit" class="btn-primary" style="white-space: nowrap;">Сохранить</button>
</div>
</div> <!-- Закрытие form-row -->
<div class="form-alert" id="add-lesson-alert" role="alert" style="margin-top: 1rem;"></div>
</form>
</div>
<!-- View Teacher Lessons Modal -->
<div class="modal-overlay" id="modal-view-lessons">
<div class="modal-content view-lessons-modal">
<div class="modal-header">
<h2 id="modal-teacher-name">Занятия преподавателя</h2>
<button class="modal-close" id="modal-view-lessons-close">&times;</button>
</div>
<div class="lessons-container" id="lessons-container">
<!-- Фильтры по дням (добавим позже) -->
<div class="loading-lessons">Загрузка занятий...</div>
</div>
</div>
</div>
</div>
<div id="modal-backdrop"></div>
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.