Compare commits
14 Commits
personal-s
...
9f124c52a5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f124c52a5 | ||
|
|
10c06e726a | ||
|
|
9d2de1faaf | ||
|
|
59caa9d6cc | ||
|
|
bad1215341 | ||
|
|
ccdc371c3a | ||
|
|
4c2293b620 | ||
|
|
6ea420e529 | ||
|
|
75b1ad166e | ||
|
|
abad3776db | ||
|
|
13b3a5c481 | ||
|
|
3579ef9f1c | ||
|
|
14cc006f06 | ||
| 9e55472de7 |
0
.gitea/workflows/docker-build.yaml
Normal file → Executable file
0
.gitea/workflows/docker-build.yaml
Normal file → Executable file
77
backend/README.md
Normal file
77
backend/README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# Руководство Backend-разработчика Magistr
|
||||
|
||||
Добро пожаловать в проект Magistr! Этот бэкенд построен на **Spring Boot** и имеет сложную **мультитенантную архитектуру**, где одно приложение обслуживает множество независимых университетов, каждый со своей базой данных. В проекте также есть интеграция с Kubernetes для "горячего" управления этими тенантами.
|
||||
|
||||
Здесь описано, как тут всё устроено, чтобы вы ничего не сломали.
|
||||
|
||||
---
|
||||
|
||||
## 1. Архитектура мультитенантности
|
||||
|
||||
Мы используем подход **Separate Database per Tenant** (Отдельная БД для каждого клиента).
|
||||
|
||||
- **Как приложение понимает, к какой базе обращаться?**
|
||||
Все запросы с фронтенда приходят с заголовком `Host` (например, `swsu.zuev.company`).
|
||||
В классе `TenantInterceptor` (находится в `config/tenant/TenantInterceptor.java`) мы перехватываем этот запрос ДО того, как он дойдёт до контроллеров, вытаскиваем поддомен (`swsu`) и сохраняем его в `ThreadLocal` переменную через класс `TenantContext`.
|
||||
|
||||
- **Как переключаются базы данных?**
|
||||
Класс `TenantRoutingDataSource` наследуется от спринговского `AbstractRoutingDataSource`. Перед каждым запросом в базу (любой `findById` или `save` из репозитория) Spring спрашивает этот класс: *"Какой сейчас ключ тенанта?"*. Класс берёт имя из `TenantContext` и переключает коннект на нужную БД на лету.
|
||||
|
||||
> **Важно:** Вся логика переключения абсолютно прозрачна для бизнес-кода. В контроллерах и сервисах вы пишете обычный код (`userRepository.findAll()`), и он сам выполнится в нужной базе.
|
||||
|
||||
---
|
||||
|
||||
## 2. Динамическое управление тенантами (Kubernetes / ConfigMap)
|
||||
|
||||
Бэкенд спроектирован для работы в **Kubernetes с несколькими репликами (replicas: 2+)**.
|
||||
|
||||
Список тенантов не зашит в код:
|
||||
- В K8s он лежит в специальном `ConfigMap`, который монтируется внутрь пода как файл `tenants.json`.
|
||||
- В классе `DatabaseController` находится API для добавления нового тенанта из админки.
|
||||
- Чтобы изменения применились ко **всем подам** без перезагрузки, `DatabaseController` вызывает `ConfigMapUpdater`. Этот класс обращается напрямую к **Kubernetes API** (используя ServiceAccount токен пода) и патчит `ConfigMap`.
|
||||
- В фоне работает планировщик `TenantConfigWatcher` (каждые 30 секунд). Он следит за изменениями `tenants.json` и, если видит нового тенанта, на лету поднимает для него новый `HikariCP` пул соединений и добавляет в маршрутизатор баз данных.
|
||||
|
||||
---
|
||||
|
||||
## 3. Базы данных и Миграции (Flyway)
|
||||
|
||||
Мы **НЕ используем** автоматическую генерацию таблиц через Hibernate (`spring.jpa.hibernate.ddl-auto=none`).
|
||||
Структурой баз данных правит **Flyway**.
|
||||
|
||||
Поскольку баз данных много (они создаются динамически), стандартный Spring Boot Flyway отключён. Вместо этого `TenantConfigWatcher` вызывает Flyway **программно** в момент первого подключения нового тенанта.
|
||||
|
||||
### 🛑 ПРАВИЛА ИЗМЕНЕНИЯ СТРУКТУРЫ БД:
|
||||
|
||||
Если вам нужно добавить новую таблицу, колонку или изменить тип поля:
|
||||
|
||||
1. **Запрещено трогать старые файлы миграций!**
|
||||
Запомните: файл `V1__init.sql` (и любые другие V-файлы, которые уже попали в коммит) — **СВЯЩЕНЕН**. Если вы его измените, бэкенд не запустится на сервере с ошибкой `Migration checksum mismatch`.
|
||||
|
||||
2. **Как правильно добавить таблицу?**
|
||||
- Зайдите в папку `src/main/resources/db/migration/`.
|
||||
- Создайте новый файл. Название **строго** по формату: `V<Номер>__<Описание>.sql`. Например: `V2__add_student_rating_table.sql`.
|
||||
- Напишите в нём ваш SQL (`CREATE TABLE ...`, `ALTER TABLE ...`).
|
||||
- Сохраните и запустите проект. Flyway **сам** пройдёт по всем базам данных тенантов и накатит этот скрипт.
|
||||
|
||||
3. **Что если локально я накосячил в V2?**
|
||||
Пока файл `V2_...` не залит в Git и крутится только у вас на локалке, вы можете его переписывать. Но для этого вам нужно зайти в вашу локальную БД (через DBeaver/pgAdmin), вручную откатить свои кривые изменения (удалить таблицу) и **удалить запись из истории Flyway**:
|
||||
`DELETE FROM flyway_schema_history WHERE version = '2';`
|
||||
Либо, что проще: удалите контейнер с локальной БД (`docker compose down -v`) и поднимите заново пустую.
|
||||
|
||||
---
|
||||
|
||||
## 4. Как запускать проект локально
|
||||
|
||||
В корневой папке репозитория (где лежит `docker-compose.yaml`) поднимите инфраструктуру:
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
Соберется и запустится:
|
||||
- Фронтенд
|
||||
- Бэкенд
|
||||
- Ваша локальная тестовая PostgreSQL-база данных (на порту 5432, имя базы `app_db`, юзер `myuser`, логин/пароль см. в compose файле).
|
||||
|
||||
Файл `backend/tenants.json` нужен для локальной разработки. Если вы запускаете бэкенд в Docker Compose, вы можете указать URL `jdbc:postgresql://db:5432/app_db` (где `db` — имя контейнера в compose сети).
|
||||
Либо, если вы тестируете взаимодействие бэкенда с вашим текущим IP-адресом (например, `192.168.1.87`), вы можете использовать этот IP. Оба варианта рабочие! Проект сразу подхватит настройки и накатит таблицы через Flyway.
|
||||
|
||||
Контроллеры и бизнес-логику пишите как в обычном Spring Boot проекте. Главное, помните: у каждого тенанта — своё изолированное хранилище!
|
||||
@@ -32,6 +32,12 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Flyway Database Migrations -->
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
@@ -43,6 +49,13 @@
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-crypto</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- H2 in-memory DB (fallback когда нет настроенных тенантов) -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -2,8 +2,12 @@ package com.magistr.app;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, FlywayAutoConfiguration.class})
|
||||
@EnableScheduling
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -1,50 +1,39 @@
|
||||
package com.magistr.app.config;
|
||||
|
||||
import com.magistr.app.model.Role;
|
||||
import com.magistr.app.model.User;
|
||||
import com.magistr.app.repository.UserRepository;
|
||||
import com.magistr.app.config.tenant.TenantConfig;
|
||||
import com.magistr.app.config.tenant.TenantConfigWatcher;
|
||||
import com.magistr.app.config.tenant.TenantRoutingDataSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* При запуске приложения инициализирует БД для каждого тенанта.
|
||||
* Делегирует инициализацию в TenantConfigWatcher.initDatabaseForTenant().
|
||||
*/
|
||||
@Component
|
||||
public class DataInitializer implements CommandLineRunner {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DataInitializer.class);
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final BCryptPasswordEncoder passwordEncoder;
|
||||
private final TenantRoutingDataSource routingDataSource;
|
||||
private final TenantConfigWatcher configWatcher;
|
||||
|
||||
public DataInitializer(UserRepository userRepository, BCryptPasswordEncoder passwordEncoder) {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
public DataInitializer(TenantRoutingDataSource routingDataSource,
|
||||
TenantConfigWatcher configWatcher) {
|
||||
this.routingDataSource = routingDataSource;
|
||||
this.configWatcher = configWatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
Optional<User> existing = userRepository.findByUsername("admin");
|
||||
log.info("Initializing databases for {} tenant(s)...", routingDataSource.getTenantConfigs().size());
|
||||
|
||||
if (existing.isEmpty()) {
|
||||
User admin = new User();
|
||||
admin.setUsername("admin");
|
||||
admin.setPassword(passwordEncoder.encode("admin"));
|
||||
admin.setRole(Role.ADMIN);
|
||||
userRepository.save(admin);
|
||||
log.info("Created default admin user");
|
||||
} else {
|
||||
User admin = existing.get();
|
||||
if (!passwordEncoder.matches("admin", admin.getPassword())) {
|
||||
admin.setPassword(passwordEncoder.encode("admin"));
|
||||
admin.setRole(Role.ADMIN);
|
||||
userRepository.save(admin);
|
||||
log.info("Reset admin password (hash was invalid)");
|
||||
} else {
|
||||
log.info("Admin user already exists with correct password");
|
||||
}
|
||||
for (TenantConfig tenant : routingDataSource.getTenantConfigs().values()) {
|
||||
configWatcher.initDatabaseForTenant(tenant);
|
||||
}
|
||||
|
||||
log.info("Database initialization complete");
|
||||
}
|
||||
}
|
||||
|
||||
127
backend/src/main/java/com/magistr/app/config/tenant/ConfigMapUpdater.java
Executable file
127
backend/src/main/java/com/magistr/app/config/tenant/ConfigMapUpdater.java
Executable file
@@ -0,0 +1,127 @@
|
||||
package com.magistr.app.config.tenant;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
/**
|
||||
* Обновляет K8s ConfigMap tenants-config через Kubernetes REST API.
|
||||
*
|
||||
* Работает ТОЛЬКО внутри K8s пода (использует ServiceAccount token).
|
||||
* При запуске вне K8s (локальная разработка) — просто логирует предупреждение.
|
||||
*/
|
||||
@Service
|
||||
public class ConfigMapUpdater {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ConfigMapUpdater.class);
|
||||
|
||||
private static final String TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
|
||||
private static final String NAMESPACE_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/namespace";
|
||||
private static final String K8S_API_BASE = "https://kubernetes.default.svc";
|
||||
private static final String CONFIGMAP_NAME = "tenants-config";
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private final boolean runningInK8s;
|
||||
|
||||
public ConfigMapUpdater() {
|
||||
this.runningInK8s = Files.exists(Path.of(TOKEN_PATH));
|
||||
if (!runningInK8s) {
|
||||
log.info("Not running in K8s — ConfigMap updates will be skipped");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновляет ConfigMap tenants-config с новым списком тенантов.
|
||||
* @return true если обновление успешно (или мы не в K8s)
|
||||
*/
|
||||
public boolean updateTenantsConfig(List<TenantConfig> tenants) {
|
||||
if (!runningInK8s) {
|
||||
log.warn("Not in K8s, skipping ConfigMap update");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
String token = Files.readString(Path.of(TOKEN_PATH)).trim();
|
||||
String namespace = Files.readString(Path.of(NAMESPACE_PATH)).trim();
|
||||
|
||||
// Формируем JSON для тенантов
|
||||
String tenantsJson = objectMapper.writerWithDefaultPrettyPrinter()
|
||||
.writeValueAsString(tenants);
|
||||
|
||||
// Strategic merge patch для ConfigMap
|
||||
String patchBody = objectMapper.writeValueAsString(Map.of(
|
||||
"data", Map.of("tenants.json", tenantsJson)
|
||||
));
|
||||
|
||||
String url = String.format("%s/api/v1/namespaces/%s/configmaps/%s",
|
||||
K8S_API_BASE, namespace, CONFIGMAP_NAME);
|
||||
|
||||
// Создаём HttpClient с отключённой проверкой сертификатов
|
||||
// (внутри кластера используется self-signed CA)
|
||||
HttpClient client = createInsecureClient();
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url))
|
||||
.header("Authorization", "Bearer " + token)
|
||||
.header("Content-Type", "application/strategic-merge-patch+json")
|
||||
.method("PATCH", HttpRequest.BodyPublishers.ofString(patchBody))
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
log.info("ConfigMap '{}' updated successfully ({} tenants)", CONFIGMAP_NAME, tenants.size());
|
||||
return true;
|
||||
} else {
|
||||
log.error("Failed to update ConfigMap: HTTP {} — {}", response.statusCode(), response.body());
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error updating ConfigMap: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Создаёт HttpClient, который доверяет self-signed сертификатам K8s API.
|
||||
*/
|
||||
private HttpClient createInsecureClient() {
|
||||
try {
|
||||
TrustManager[] trustAll = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
|
||||
}
|
||||
};
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, trustAll, new SecureRandom());
|
||||
|
||||
return HttpClient.newBuilder()
|
||||
.sslContext(sslContext)
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to create insecure client, using default: {}", e.getMessage());
|
||||
return HttpClient.newHttpClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
41
backend/src/main/java/com/magistr/app/config/tenant/TenantConfig.java
Executable file
41
backend/src/main/java/com/magistr/app/config/tenant/TenantConfig.java
Executable file
@@ -0,0 +1,41 @@
|
||||
package com.magistr.app.config.tenant;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
/**
|
||||
* Модель конфигурации тенанта (университета).
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class TenantConfig {
|
||||
|
||||
private String name; // "ЮЗГУ", "МГУ"
|
||||
private String domain; // "swsu", "mgu" (поддомен)
|
||||
private String url; // "jdbc:postgresql://192.168.1.50:5432/magistr_db"
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public TenantConfig() {}
|
||||
|
||||
public TenantConfig(String name, String domain, String url, String username, String password) {
|
||||
this.name = name;
|
||||
this.domain = domain;
|
||||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDomain() { return domain; }
|
||||
public void setDomain(String domain) { this.domain = domain; }
|
||||
|
||||
public String getUrl() { return url; }
|
||||
public void setUrl(String url) { this.url = url; }
|
||||
|
||||
public String getUsername() { return username; }
|
||||
public void setUsername(String username) { this.username = username; }
|
||||
|
||||
public String getPassword() { return password; }
|
||||
public void setPassword(String password) { this.password = password; }
|
||||
}
|
||||
156
backend/src/main/java/com/magistr/app/config/tenant/TenantConfigWatcher.java
Executable file
156
backend/src/main/java/com/magistr/app/config/tenant/TenantConfigWatcher.java
Executable file
@@ -0,0 +1,156 @@
|
||||
package com.magistr.app.config.tenant;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Периодически перечитывает tenants.json (mounted ConfigMap).
|
||||
* Если ConfigMap был обновлён через K8s API, этот компонент
|
||||
* подхватит изменения и синхронизирует in-memory datasource'ы.
|
||||
*
|
||||
* Также отвечает за инициализацию БД (init.sql) для новых тенантов.
|
||||
*/
|
||||
@Component
|
||||
public class TenantConfigWatcher {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TenantConfigWatcher.class);
|
||||
|
||||
private final TenantRoutingDataSource routingDataSource;
|
||||
private final DataSource dataSource;
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Value("${app.tenants.config-path:tenants.json}")
|
||||
private String tenantsConfigPath;
|
||||
|
||||
// Хеш последнего прочитанного конфига — чтобы не перезагружать зря
|
||||
private String lastConfigHash = "";
|
||||
|
||||
public TenantConfigWatcher(TenantRoutingDataSource routingDataSource, DataSource dataSource) {
|
||||
this.routingDataSource = routingDataSource;
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Каждые 30 секунд проверяет, изменился ли tenants.json.
|
||||
*/
|
||||
@Scheduled(fixedDelay = 30_000, initialDelay = 30_000)
|
||||
public void watchForChanges() {
|
||||
try {
|
||||
File file = new File(tenantsConfigPath);
|
||||
if (!file.exists()) return;
|
||||
|
||||
String content = new String(java.nio.file.Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
|
||||
String hash = Integer.toHexString(content.hashCode());
|
||||
|
||||
if (hash.equals(lastConfigHash)) {
|
||||
return; // Ничего не изменилось
|
||||
}
|
||||
|
||||
log.info("Detected tenants.json change (hash: {} -> {}), reloading...", lastConfigHash, hash);
|
||||
lastConfigHash = hash;
|
||||
|
||||
List<TenantConfig> newTenants = objectMapper.readValue(content, new TypeReference<>() {});
|
||||
syncTenants(newTenants);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error watching tenants config: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновляет хеш конфига (вызывается после ручного обновления ConfigMap с этого же пода).
|
||||
*/
|
||||
public void refreshHash() {
|
||||
try {
|
||||
File file = new File(tenantsConfigPath);
|
||||
if (file.exists()) {
|
||||
String content = new String(java.nio.file.Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
|
||||
lastConfigHash = Integer.toHexString(content.hashCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to refresh config hash: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Синхронизирует in-memory тенантов с конфигом из файла.
|
||||
*/
|
||||
private void syncTenants(List<TenantConfig> newTenants) {
|
||||
Map<String, TenantConfig> current = routingDataSource.getTenantConfigs();
|
||||
Set<String> newDomains = newTenants.stream()
|
||||
.map(t -> t.getDomain().toLowerCase())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// Добавить новые тенанты
|
||||
for (TenantConfig tenant : newTenants) {
|
||||
String domain = tenant.getDomain().toLowerCase();
|
||||
if (!current.containsKey(domain)) {
|
||||
log.info("Adding new tenant '{}' from ConfigMap update", domain);
|
||||
routingDataSource.addTenant(tenant);
|
||||
// Инициализируем БД для нового тенанта
|
||||
initDatabaseForTenant(tenant);
|
||||
}
|
||||
}
|
||||
|
||||
// Удалить тенанты, которых больше нет в конфиге
|
||||
for (String existingDomain : new ArrayList<>(current.keySet())) {
|
||||
if (!newDomains.contains(existingDomain)) {
|
||||
log.info("Removing tenant '{}' (no longer in ConfigMap)", existingDomain);
|
||||
routingDataSource.removeTenant(existingDomain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Выполняет миграции Flyway для конкретного тенанта пи подключении.
|
||||
* Если БД уже существует, но история Flyway пуста —
|
||||
* делает baseline (считает V1_init.sql уже выполненным).
|
||||
*/
|
||||
public void initDatabaseForTenant(TenantConfig tenant) {
|
||||
String domain = tenant.getDomain();
|
||||
try {
|
||||
TenantContext.setCurrentTenant(domain);
|
||||
|
||||
log.info("[{}] Starting Flyway migrations...", domain);
|
||||
|
||||
// Получаем DataSource конкретно для этого тенанта
|
||||
javax.sql.DataSource tenantDs = routingDataSource.getResolvedDataSources().get(domain);
|
||||
if (tenantDs == null) {
|
||||
// Если ещё не resolve'нулся (первый запуск), берём обёртку
|
||||
tenantDs = dataSource;
|
||||
}
|
||||
|
||||
org.flywaydb.core.Flyway flyway = org.flywaydb.core.Flyway.configure()
|
||||
.dataSource(tenantDs)
|
||||
.baselineOnMigrate(true)
|
||||
.baselineVersion("1")
|
||||
.load();
|
||||
|
||||
flyway.migrate();
|
||||
log.info("[{}] Flyway migrations completed successfully", domain);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("[{}] Flyway migration failed: {}", domain, e.getMessage());
|
||||
} finally {
|
||||
TenantContext.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
22
backend/src/main/java/com/magistr/app/config/tenant/TenantContext.java
Executable file
22
backend/src/main/java/com/magistr/app/config/tenant/TenantContext.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package com.magistr.app.config.tenant;
|
||||
|
||||
/**
|
||||
* ThreadLocal хранилище текущего тенанта (домена).
|
||||
* Устанавливается в TenantInterceptor на каждый HTTP-запрос.
|
||||
*/
|
||||
public class TenantContext {
|
||||
|
||||
private static final ThreadLocal<String> CURRENT_TENANT = new ThreadLocal<>();
|
||||
|
||||
public static String getCurrentTenant() {
|
||||
return CURRENT_TENANT.get();
|
||||
}
|
||||
|
||||
public static void setCurrentTenant(String tenant) {
|
||||
CURRENT_TENANT.set(tenant);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
CURRENT_TENANT.remove();
|
||||
}
|
||||
}
|
||||
156
backend/src/main/java/com/magistr/app/config/tenant/TenantDataSourceConfig.java
Executable file
156
backend/src/main/java/com/magistr/app/config/tenant/TenantDataSourceConfig.java
Executable file
@@ -0,0 +1,156 @@
|
||||
package com.magistr.app.config.tenant;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Конфигурация мультитенантного DataSource.
|
||||
* Загружает тенанты из JSON-файла (mounted ConfigMap).
|
||||
*
|
||||
* Если нет ни одного настроенного тенанта — создаёт H2 in-memory БД
|
||||
* как заглушку, чтобы Spring JPA мог инициализироваться.
|
||||
*/
|
||||
@Configuration
|
||||
public class TenantDataSourceConfig implements WebMvcConfigurer {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TenantDataSourceConfig.class);
|
||||
|
||||
@Value("${app.tenants.config-path:tenants.json}")
|
||||
private String tenantsConfigPath;
|
||||
|
||||
@Value("${spring.datasource.url:}")
|
||||
private String defaultDbUrl;
|
||||
|
||||
@Value("${spring.datasource.username:}")
|
||||
private String defaultDbUsername;
|
||||
|
||||
@Value("${spring.datasource.password:}")
|
||||
private String defaultDbPassword;
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public DataSource dataSource() {
|
||||
TenantRoutingDataSource routingDataSource = new TenantRoutingDataSource();
|
||||
|
||||
// Загружаем тенантов из JSON (read-only ConfigMap mount)
|
||||
List<TenantConfig> tenants = loadTenantsFromFile();
|
||||
|
||||
// Если нет тенантов и есть дефолтный datasource — создаём "default" тенант
|
||||
if (tenants.isEmpty() && defaultDbUrl != null && !defaultDbUrl.isBlank()) {
|
||||
TenantConfig defaultTenant = new TenantConfig(
|
||||
"Default", "default", defaultDbUrl, defaultDbUsername, defaultDbPassword
|
||||
);
|
||||
tenants.add(defaultTenant);
|
||||
log.info("No tenants config found, using default datasource: {}", defaultDbUrl);
|
||||
}
|
||||
|
||||
// Регистрируем тенантов
|
||||
for (TenantConfig tenant : tenants) {
|
||||
try {
|
||||
routingDataSource.addTenant(tenant);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to add tenant '{}': {}", tenant.getDomain(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Если всё ещё нет ни одного тенанта — H2 in-memory заглушка
|
||||
if (routingDataSource.getTenantConfigs().isEmpty()) {
|
||||
log.warn("=== НЕТ НАСТРОЕННЫХ ТЕНАНТОВ ===");
|
||||
log.warn("Создаём H2 in-memory заглушку для запуска приложения.");
|
||||
log.warn("Добавьте тенант через POST /api/database/tenants");
|
||||
|
||||
TenantConfig h2Fallback = new TenantConfig(
|
||||
"H2 Placeholder", "default",
|
||||
"jdbc:h2:mem:placeholder;DB_CLOSE_DELAY=-1",
|
||||
"sa", ""
|
||||
);
|
||||
routingDataSource.addTenant(h2Fallback);
|
||||
}
|
||||
|
||||
return routingDataSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TenantRoutingDataSource tenantRoutingDataSource(DataSource dataSource) {
|
||||
return (TenantRoutingDataSource) dataSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
|
||||
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||
em.setDataSource(dataSource);
|
||||
em.setPackagesToScan("com.magistr.app.model");
|
||||
|
||||
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||
vendorAdapter.setGenerateDdl(false);
|
||||
vendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQLDialect");
|
||||
em.setJpaVendorAdapter(vendorAdapter);
|
||||
|
||||
Map<String, Object> props = new HashMap<>();
|
||||
props.put("hibernate.hbm2ddl.auto", "none");
|
||||
props.put("hibernate.show_sql", "false");
|
||||
em.setJpaPropertyMap(props);
|
||||
|
||||
return em;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
|
||||
return new JpaTransactionManager(emf);
|
||||
}
|
||||
|
||||
@org.springframework.context.annotation.Lazy
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
private TenantRoutingDataSource tenantRoutingDataSource;
|
||||
|
||||
@Bean
|
||||
public TenantInterceptor tenantInterceptor(TenantRoutingDataSource routingDataSource) {
|
||||
TenantInterceptor interceptor = new TenantInterceptor();
|
||||
interceptor.setRoutingDataSource(routingDataSource);
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// Вызываем метод-бин с переданным параметром (будет перехвачен CGLIB)
|
||||
registry.addInterceptor(tenantInterceptor(tenantRoutingDataSource)).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
private List<TenantConfig> loadTenantsFromFile() {
|
||||
File file = new File(tenantsConfigPath);
|
||||
if (!file.exists()) {
|
||||
log.info("Tenants config file not found: {}", tenantsConfigPath);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
List<TenantConfig> list = mapper.readValue(file, new TypeReference<>() {});
|
||||
log.info("Loaded {} tenant(s) from {}", list.size(), tenantsConfigPath);
|
||||
return list;
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to read tenants config: {}", e.getMessage());
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
99
backend/src/main/java/com/magistr/app/config/tenant/TenantInterceptor.java
Executable file
99
backend/src/main/java/com/magistr/app/config/tenant/TenantInterceptor.java
Executable file
@@ -0,0 +1,99 @@
|
||||
package com.magistr.app.config.tenant;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Interceptor: извлекает поддомен из Host header и кладёт в TenantContext.
|
||||
*
|
||||
* Если тенант не настроен в TenantRoutingDataSource —
|
||||
* сразу возвращает HTTP 404 (не допускает fallback на чужой тенант).
|
||||
*
|
||||
* Примеры:
|
||||
* "swsu.zuev.company" → tenant = "swsu"
|
||||
* "mgu.zuev.company" → tenant = "mgu"
|
||||
* "localhost" → tenant = "default"
|
||||
* "localhost:8080" → tenant = "default"
|
||||
*
|
||||
* API управления тенантами (/api/database/**) пропускается без проверки,
|
||||
* чтобы администратор мог добавлять тенантов с любого домена.
|
||||
*/
|
||||
public class TenantInterceptor implements HandlerInterceptor {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TenantInterceptor.class);
|
||||
|
||||
private TenantRoutingDataSource routingDataSource;
|
||||
|
||||
/**
|
||||
* Устанавливается после создания бина (из TenantDataSourceConfig).
|
||||
*/
|
||||
public void setRoutingDataSource(TenantRoutingDataSource routingDataSource) {
|
||||
this.routingDataSource = routingDataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
|
||||
String host = request.getHeader("Host");
|
||||
String tenant = resolveTenant(host);
|
||||
String path = request.getRequestURI();
|
||||
|
||||
// API управления тенантами — всегда пропускаем
|
||||
// (нужно чтобы админ мог добавить тенант даже если его домен не настроен)
|
||||
if (path.startsWith("/api/database")) {
|
||||
TenantContext.setCurrentTenant(tenant);
|
||||
log.debug("Database API request, tenant '{}' (no strict check)", tenant);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Проверяем, существует ли тенант
|
||||
if (routingDataSource != null && !routingDataSource.hasTenant(tenant)) {
|
||||
log.warn("Unknown tenant '{}' from Host '{}' — returning 404", tenant, host);
|
||||
response.setStatus(404);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
new ObjectMapper().writeValue(response.getOutputStream(), Map.of(
|
||||
"error", "Тенант не найден",
|
||||
"tenant", tenant,
|
||||
"message", "Домен " + host + " не настроен. Обратитесь к администратору."
|
||||
));
|
||||
return false; // Останавливаем обработку запроса
|
||||
}
|
||||
|
||||
TenantContext.setCurrentTenant(tenant);
|
||||
log.debug("Resolved tenant '{}' from Host '{}'", tenant, host);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
TenantContext.clear();
|
||||
}
|
||||
|
||||
private String resolveTenant(String host) {
|
||||
if (host == null || host.isBlank()) {
|
||||
return "default";
|
||||
}
|
||||
|
||||
// Убираем порт (localhost:8080 → localhost)
|
||||
String hostname = host.contains(":") ? host.substring(0, host.indexOf(':')) : host;
|
||||
|
||||
// localhost или IP → default
|
||||
if ("localhost".equalsIgnoreCase(hostname) || hostname.matches("\\d+\\.\\d+\\.\\d+\\.\\d+")) {
|
||||
return "default";
|
||||
}
|
||||
|
||||
// Извлекаем первый поддомен: swsu.zuev.company → swsu
|
||||
int firstDot = hostname.indexOf('.');
|
||||
if (firstDot > 0) {
|
||||
return hostname.substring(0, firstDot).toLowerCase();
|
||||
}
|
||||
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
150
backend/src/main/java/com/magistr/app/config/tenant/TenantRoutingDataSource.java
Executable file
150
backend/src/main/java/com/magistr/app/config/tenant/TenantRoutingDataSource.java
Executable file
@@ -0,0 +1,150 @@
|
||||
package com.magistr.app.config.tenant;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* DataSource, который переключается между БД разных тенантов.
|
||||
* На каждый запрос determineCurrentLookupKey() возвращает текущий тенант из TenantContext.
|
||||
*/
|
||||
public class TenantRoutingDataSource extends AbstractRoutingDataSource {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TenantRoutingDataSource.class);
|
||||
|
||||
private final Map<String, TenantConfig> tenantConfigs = new ConcurrentHashMap<>();
|
||||
private final Map<Object, Object> dataSources = new ConcurrentHashMap<>();
|
||||
private boolean initialized = false;
|
||||
|
||||
public TenantRoutingDataSource() {
|
||||
// Устанавливаем пустой map чтобы afterPropertiesSet не падал
|
||||
setTargetDataSources(new HashMap<>());
|
||||
setLenientFallback(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
String tenant = TenantContext.getCurrentTenant();
|
||||
|
||||
if (tenant == null) {
|
||||
// Нет HTTP контекста (JPA init, background tasks) — берём первый доступный
|
||||
if (!dataSources.isEmpty()) {
|
||||
return dataSources.keySet().iterator().next().toString();
|
||||
}
|
||||
return "default";
|
||||
}
|
||||
|
||||
// HTTP запрос — возвращаем точный ключ тенанта
|
||||
// Если тенанта нет — TenantInterceptor уже вернул 404
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет тенант и создаёт для него HikariCP пул.
|
||||
*/
|
||||
public void addTenant(TenantConfig config) {
|
||||
String domain = config.getDomain().toLowerCase();
|
||||
HikariDataSource ds = createDataSource(config);
|
||||
|
||||
dataSources.put(domain, ds);
|
||||
tenantConfigs.put(domain, config);
|
||||
|
||||
// Обновляем target data sources
|
||||
setTargetDataSources(dataSources);
|
||||
afterPropertiesSet();
|
||||
initialized = true;
|
||||
|
||||
log.info("Added tenant '{}' -> {}", domain, config.getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет тенант и закрывает его пул соединений.
|
||||
*/
|
||||
public void removeTenant(String domain) {
|
||||
domain = domain.toLowerCase();
|
||||
Object removed = dataSources.remove(domain);
|
||||
tenantConfigs.remove(domain);
|
||||
|
||||
if (removed instanceof HikariDataSource ds) {
|
||||
ds.close();
|
||||
log.info("Removed and closed tenant '{}'", domain);
|
||||
}
|
||||
|
||||
setTargetDataSources(dataSources);
|
||||
afterPropertiesSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет подключение к БД для указанного тенанта.
|
||||
*/
|
||||
public boolean testConnection(String domain) {
|
||||
DataSource ds = (DataSource) dataSources.get(domain.toLowerCase());
|
||||
if (ds == null) return false;
|
||||
|
||||
try (Connection conn = ds.getConnection()) {
|
||||
return conn.isValid(5);
|
||||
} catch (SQLException e) {
|
||||
log.warn("Connection test failed for tenant '{}': {}", domain, e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует подключение по произвольным параметрам (без регистрации тенанта).
|
||||
*/
|
||||
public String testExternalConnection(String url, String username, String password) {
|
||||
HikariDataSource ds = new HikariDataSource();
|
||||
ds.setJdbcUrl(url);
|
||||
ds.setUsername(username);
|
||||
ds.setPassword(password);
|
||||
ds.setMaximumPoolSize(1);
|
||||
ds.setConnectionTimeout(5000);
|
||||
|
||||
try (Connection conn = ds.getConnection()) {
|
||||
if (conn.isValid(5)) {
|
||||
return "OK";
|
||||
}
|
||||
return "Подключение не валидно";
|
||||
} catch (Exception e) {
|
||||
return e.getMessage();
|
||||
} finally {
|
||||
ds.close();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, TenantConfig> getTenantConfigs() {
|
||||
return tenantConfigs;
|
||||
}
|
||||
|
||||
public boolean hasTenant(String domain) {
|
||||
return tenantConfigs.containsKey(domain.toLowerCase());
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return initialized && !dataSources.isEmpty();
|
||||
}
|
||||
|
||||
private HikariDataSource createDataSource(TenantConfig config) {
|
||||
HikariDataSource ds = new HikariDataSource();
|
||||
ds.setJdbcUrl(config.getUrl());
|
||||
ds.setUsername(config.getUsername());
|
||||
ds.setPassword(config.getPassword());
|
||||
ds.setPoolName("tenant-" + config.getDomain());
|
||||
ds.setMaximumPoolSize(10);
|
||||
ds.setMinimumIdle(2);
|
||||
ds.setConnectionTimeout(10000);
|
||||
ds.setIdleTimeout(300000);
|
||||
ds.setMaxLifetime(600000);
|
||||
// Не падать при инициализации если БД недоступна
|
||||
ds.setInitializationFailTimeout(-1);
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
181
backend/src/main/java/com/magistr/app/controller/DatabaseController.java
Executable file
181
backend/src/main/java/com/magistr/app/controller/DatabaseController.java
Executable file
@@ -0,0 +1,181 @@
|
||||
package com.magistr.app.controller;
|
||||
|
||||
import com.magistr.app.config.tenant.ConfigMapUpdater;
|
||||
import com.magistr.app.config.tenant.TenantConfig;
|
||||
import com.magistr.app.config.tenant.TenantConfigWatcher;
|
||||
import com.magistr.app.config.tenant.TenantContext;
|
||||
import com.magistr.app.config.tenant.TenantRoutingDataSource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* API управления подключениями к базам данных (тенантами).
|
||||
* Доступно только для ADMIN.
|
||||
*
|
||||
* При добавлении/удалении тенанта:
|
||||
* 1. Обновляется in-memory DataSource (мгновенно на этом поде)
|
||||
* 2. Обновляется K8s ConfigMap (через ConfigMapUpdater)
|
||||
* 3. Другие поды подхватят изменения через TenantConfigWatcher (~30 сек)
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/database")
|
||||
public class DatabaseController {
|
||||
|
||||
private final TenantRoutingDataSource routingDataSource;
|
||||
private final ConfigMapUpdater configMapUpdater;
|
||||
private final TenantConfigWatcher configWatcher;
|
||||
|
||||
public DatabaseController(TenantRoutingDataSource routingDataSource,
|
||||
ConfigMapUpdater configMapUpdater,
|
||||
TenantConfigWatcher configWatcher) {
|
||||
this.routingDataSource = routingDataSource;
|
||||
this.configMapUpdater = configMapUpdater;
|
||||
this.configWatcher = configWatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Статус текущего подключения (по домену запроса).
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
public ResponseEntity<Map<String, Object>> getStatus() {
|
||||
String currentTenant = TenantContext.getCurrentTenant();
|
||||
boolean connected = routingDataSource.testConnection(currentTenant);
|
||||
|
||||
TenantConfig config = routingDataSource.getTenantConfigs().get(currentTenant);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("tenant", currentTenant);
|
||||
result.put("connected", connected);
|
||||
result.put("configured", config != null);
|
||||
if (config != null) {
|
||||
result.put("name", config.getName());
|
||||
result.put("url", config.getUrl());
|
||||
}
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Список всех тенантов.
|
||||
*/
|
||||
@GetMapping("/tenants")
|
||||
public ResponseEntity<List<Map<String, Object>>> getTenants() {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
|
||||
for (TenantConfig config : routingDataSource.getTenantConfigs().values()) {
|
||||
Map<String, Object> tenant = new HashMap<>();
|
||||
tenant.put("name", config.getName());
|
||||
tenant.put("domain", config.getDomain());
|
||||
tenant.put("url", config.getUrl());
|
||||
tenant.put("username", config.getUsername());
|
||||
tenant.put("connected", routingDataSource.testConnection(config.getDomain()));
|
||||
result.add(tenant);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавить новый тенант.
|
||||
*/
|
||||
@PostMapping("/tenants")
|
||||
public ResponseEntity<Map<String, Object>> addTenant(@RequestBody TenantConfig config) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
if (config.getDomain() == null || config.getDomain().isBlank()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "Домен не может быть пустым");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
if (config.getUrl() == null || config.getUrl().isBlank()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "URL базы данных не может быть пустым");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
if (routingDataSource.hasTenant(config.getDomain())) {
|
||||
routingDataSource.removeTenant(config.getDomain());
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. Добавить в in-memory (мгновенно на этом поде)
|
||||
routingDataSource.addTenant(config);
|
||||
|
||||
// 2. Инициализировать БД (init.sql) если нужно
|
||||
configWatcher.initDatabaseForTenant(config);
|
||||
|
||||
// 3. Обновить K8s ConfigMap (другие поды подхватят через ~30 сек)
|
||||
persistToConfigMap();
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "Тенант '" + config.getDomain() + "' добавлен");
|
||||
return ResponseEntity.ok(result);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "Ошибка: " + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Удалить тенант.
|
||||
*/
|
||||
@DeleteMapping("/tenants/{domain}")
|
||||
public ResponseEntity<Map<String, Object>> removeTenant(@PathVariable String domain) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
if (!routingDataSource.hasTenant(domain)) {
|
||||
result.put("success", false);
|
||||
result.put("message", "Тенант '" + domain + "' не найден");
|
||||
return ResponseEntity.status(404).body(result);
|
||||
}
|
||||
|
||||
routingDataSource.removeTenant(domain);
|
||||
persistToConfigMap();
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "Тенант '" + domain + "' удалён");
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тест подключения к произвольной БД.
|
||||
*/
|
||||
@PostMapping("/test")
|
||||
public ResponseEntity<Map<String, Object>> testConnection(@RequestBody Map<String, String> params) {
|
||||
String url = params.get("url");
|
||||
String username = params.get("username");
|
||||
String password = params.get("password");
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
if (url == null || url.isBlank()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "URL не указан");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
String testResult = routingDataSource.testExternalConnection(url, username, password);
|
||||
boolean success = "OK".equals(testResult);
|
||||
|
||||
result.put("success", success);
|
||||
result.put("message", success ? "Подключение успешно!" : testResult);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Сохраняет текущий список тенантов в K8s ConfigMap.
|
||||
*/
|
||||
private void persistToConfigMap() {
|
||||
List<TenantConfig> tenants = new ArrayList<>(routingDataSource.getTenantConfigs().values());
|
||||
boolean ok = configMapUpdater.updateTenantsConfig(tenants);
|
||||
if (ok) {
|
||||
configWatcher.refreshHash(); // Чтобы watcher не перезагрузил те же данные
|
||||
}
|
||||
}
|
||||
}
|
||||
0
backend/src/main/java/com/magistr/app/utils/TypeAndFormatLessonValidator.java
Normal file → Executable file
0
backend/src/main/java/com/magistr/app/utils/TypeAndFormatLessonValidator.java
Normal file → Executable file
@@ -1,15 +1,18 @@
|
||||
server.port=8080
|
||||
|
||||
# PostgreSQL
|
||||
# PostgreSQL (дефолтный — для локальной разработки через Docker Compose)
|
||||
spring.datasource.url=jdbc:postgresql://db:5432/app_db
|
||||
spring.datasource.username=${POSTGRES_USER}
|
||||
spring.datasource.password=${POSTGRES_PASSWORD}
|
||||
spring.datasource.username=${POSTGRES_USER:myuser}
|
||||
spring.datasource.password=${POSTGRES_PASSWORD:supersecretpassword}
|
||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
|
||||
# JPA
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=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
|
||||
# Мультитенантность
|
||||
app.tenants.config-path=${TENANTS_CONFIG_PATH:tenants.json}
|
||||
|
||||
#logging.level.root=DEBUG
|
||||
|
||||
|
||||
9
backend/tenants.json
Executable file
9
backend/tenants.json
Executable file
@@ -0,0 +1,9 @@
|
||||
[
|
||||
{
|
||||
"name": "Default (dev)",
|
||||
"domain": "default",
|
||||
"url": "jdbc:postgresql://db:5432/app_db",
|
||||
"username": "myuser",
|
||||
"password": "supersecretpassword"
|
||||
}
|
||||
]
|
||||
20
compose.yaml
20
compose.yaml
@@ -10,9 +10,7 @@ services:
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
networks:
|
||||
- proxy
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
frontend:
|
||||
container_name: frontend
|
||||
restart: always
|
||||
@@ -23,6 +21,7 @@ services:
|
||||
- proxy
|
||||
depends_on:
|
||||
- backend
|
||||
|
||||
db:
|
||||
image: postgres:alpine3.23
|
||||
container_name: db
|
||||
@@ -30,21 +29,12 @@ services:
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_USER: myuser
|
||||
POSTGRES_PASSWORD: supersecretpassword
|
||||
POSTGRES_DB: app_db
|
||||
volumes:
|
||||
- ./db/data:/var/lib/postgresql
|
||||
- ./db/init:/docker-entrypoint-initdb.d:ro
|
||||
networks:
|
||||
- proxy
|
||||
healthcheck:
|
||||
test:
|
||||
- CMD-SHELL
|
||||
- pg_isready -U ${POSTGRES_USER} -d app_db
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
networks:
|
||||
proxy:
|
||||
external: true
|
||||
|
||||
@@ -754,3 +754,108 @@ tbody tr:hover {
|
||||
align-items: center;
|
||||
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);
|
||||
}
|
||||
|
||||
.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-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);
|
||||
/* используем success или зелёный */
|
||||
border-color: var(--success, #10b981);
|
||||
color: white;
|
||||
}
|
||||
@@ -1,418 +0,0 @@
|
||||
/* ===== 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;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<link rel="stylesheet" href="css/main.css">
|
||||
<link rel="stylesheet" href="css/layout.css">
|
||||
<link rel="stylesheet" href="css/components.css">
|
||||
<link rel="stylesheet" href="css/modals.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -96,6 +95,14 @@
|
||||
</svg>
|
||||
Расписание занятий
|
||||
</a>
|
||||
<a href="#" class="nav-item" data-tab="database">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<ellipse cx="12" cy="5" rx="9" ry="3"></ellipse>
|
||||
<path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"></path>
|
||||
<path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"></path>
|
||||
</svg>
|
||||
База данных
|
||||
</a>
|
||||
</nav>
|
||||
<div class="sidebar-footer">
|
||||
<button class="btn-logout" id="btn-logout">
|
||||
|
||||
@@ -8,6 +8,7 @@ import { initEquipments } from './views/equipments.js';
|
||||
import { initClassrooms } from './views/classrooms.js';
|
||||
import { initSubjects } from './views/subjects.js';
|
||||
import {initSchedule} from "./views/schedule.js";
|
||||
import {initDatabase} from "./views/database.js";
|
||||
|
||||
// Configuration
|
||||
const ROUTES = {
|
||||
@@ -17,8 +18,8 @@ const ROUTES = {
|
||||
equipments: { title: 'Оборудование', file: 'views/equipments.html', init: initEquipments },
|
||||
classrooms: { title: 'Аудитории', file: 'views/classrooms.html', init: initClassrooms },
|
||||
subjects: { title: 'Дисциплины и преподаватели', file: 'views/subjects.html', init: initSubjects },
|
||||
// Новая вкладка
|
||||
schedule: { title: 'Расписание занятий', file: 'views/schedule.html', init: initSchedule },
|
||||
database: { title: 'База данных', file: 'views/database.html', init: initDatabase },
|
||||
};
|
||||
|
||||
let currentTab = null;
|
||||
|
||||
157
frontend/admin/js/views/database.js
Executable file
157
frontend/admin/js/views/database.js
Executable file
@@ -0,0 +1,157 @@
|
||||
import { api } from '../api.js';
|
||||
import { escapeHtml, showAlert, hideAlert } from '../utils.js';
|
||||
|
||||
export async function initDatabase() {
|
||||
const tenantsTbody = document.getElementById('tenants-tbody');
|
||||
const addTenantForm = document.getElementById('add-tenant-form');
|
||||
const statusInfo = document.getElementById('db-status-info');
|
||||
const btnTest = document.getElementById('btn-test-connection');
|
||||
|
||||
// === Загрузка статуса текущего подключения ===
|
||||
async function loadStatus() {
|
||||
try {
|
||||
const data = await api.get('/api/database/status');
|
||||
const statusBadge = data.connected
|
||||
? '<span class="badge badge-available">Online</span>'
|
||||
: '<span class="badge badge-unavailable">Offline</span>';
|
||||
|
||||
statusInfo.innerHTML = `
|
||||
<div style="display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;">
|
||||
<div>
|
||||
<span style="color: var(--text-secondary); font-size: 0.85rem;">Тенант:</span>
|
||||
<strong>${escapeHtml(data.tenant || '—')}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span style="color: var(--text-secondary); font-size: 0.85rem;">Название:</span>
|
||||
<strong>${escapeHtml(data.name || '—')}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span style="color: var(--text-secondary); font-size: 0.85rem;">Статус:</span>
|
||||
${statusBadge}
|
||||
</div>
|
||||
${data.url ? `<div>
|
||||
<span style="color: var(--text-secondary); font-size: 0.85rem;">URL:</span>
|
||||
<code style="font-size: 0.85rem;">${escapeHtml(data.url)}</code>
|
||||
</div>` : ''}
|
||||
</div>
|
||||
`;
|
||||
} catch (e) {
|
||||
statusInfo.innerHTML = `<div class="form-alert error" style="display:block">Ошибка загрузки статуса: ${e.message}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
// === Загрузка списка тенантов ===
|
||||
async function loadTenants() {
|
||||
try {
|
||||
const tenants = await api.get('/api/database/tenants');
|
||||
renderTenantsTable(tenants);
|
||||
} catch (e) {
|
||||
tenantsTbody.innerHTML = `<tr><td colspan="6" class="loading-row">Ошибка загрузки: ${e.message}</td></tr>`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderTenantsTable(tenants) {
|
||||
if (!tenants || !tenants.length) {
|
||||
tenantsTbody.innerHTML = '<tr><td colspan="6" class="loading-row">Нет подключённых тенантов</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
tenantsTbody.innerHTML = tenants.map(t => {
|
||||
const statusBadge = t.connected
|
||||
? '<span class="badge badge-available">Online</span>'
|
||||
: '<span class="badge badge-unavailable">Offline</span>';
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td>${escapeHtml(t.name || '—')}</td>
|
||||
<td><code>${escapeHtml(t.domain)}</code></td>
|
||||
<td><code style="font-size: 0.82rem;">${escapeHtml(t.url)}</code></td>
|
||||
<td>${escapeHtml(t.username || '—')}</td>
|
||||
<td>${statusBadge}</td>
|
||||
<td><button class="btn-delete" data-domain="${escapeHtml(t.domain)}">Удалить</button></td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// === Тест подключения ===
|
||||
btnTest.addEventListener('click', async () => {
|
||||
hideAlert('add-tenant-alert');
|
||||
const url = document.getElementById('tenant-url').value.trim();
|
||||
const username = document.getElementById('tenant-username').value.trim();
|
||||
const password = document.getElementById('tenant-password').value;
|
||||
|
||||
if (!url) {
|
||||
showAlert('add-tenant-alert', 'Введите JDBC URL', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
btnTest.textContent = '...';
|
||||
btnTest.disabled = true;
|
||||
|
||||
try {
|
||||
const result = await api.post('/api/database/test', { url, username, password });
|
||||
if (result.success) {
|
||||
showAlert('add-tenant-alert', '✓ Подключение успешно!', 'success');
|
||||
} else {
|
||||
showAlert('add-tenant-alert', `✗ ${result.message}`, 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
showAlert('add-tenant-alert', `Ошибка: ${e.message}`, 'error');
|
||||
} finally {
|
||||
btnTest.textContent = 'Тест';
|
||||
btnTest.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// === Добавление тенанта ===
|
||||
addTenantForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
hideAlert('add-tenant-alert');
|
||||
|
||||
const name = document.getElementById('tenant-name').value.trim();
|
||||
const domain = document.getElementById('tenant-domain').value.trim().toLowerCase();
|
||||
const url = document.getElementById('tenant-url').value.trim();
|
||||
const username = document.getElementById('tenant-username').value.trim();
|
||||
const password = document.getElementById('tenant-password').value;
|
||||
|
||||
if (!name || !domain || !url) {
|
||||
showAlert('add-tenant-alert', 'Заполните все обязательные поля', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await api.post('/api/database/tenants', { name, domain, url, username, password });
|
||||
if (result.success) {
|
||||
showAlert('add-tenant-alert', `Тенант "${escapeHtml(domain)}" добавлен!`, 'success');
|
||||
addTenantForm.reset();
|
||||
loadTenants();
|
||||
loadStatus();
|
||||
} else {
|
||||
showAlert('add-tenant-alert', result.message, 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
showAlert('add-tenant-alert', `Ошибка: ${e.message}`, 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// === Удаление тенанта ===
|
||||
tenantsTbody.addEventListener('click', async (e) => {
|
||||
const btn = e.target.closest('.btn-delete');
|
||||
if (!btn) return;
|
||||
|
||||
const domain = btn.dataset.domain;
|
||||
if (!confirm(`Удалить тенант "${domain}"? Пул соединений будет закрыт.`)) return;
|
||||
|
||||
try {
|
||||
await api.delete(`/api/database/tenants/${domain}`);
|
||||
loadTenants();
|
||||
loadStatus();
|
||||
} catch (e) {
|
||||
alert(`Ошибка: ${e.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
// === Init ===
|
||||
loadStatus();
|
||||
loadTenants();
|
||||
}
|
||||
@@ -7,13 +7,11 @@ const ROLE_BADGE = { ADMIN: 'badge-admin', TEACHER: 'badge-teacher', STUDENT: 'b
|
||||
export async function initUsers() {
|
||||
const usersTbody = document.getElementById('users-tbody');
|
||||
const createForm = document.getElementById('create-form');
|
||||
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');
|
||||
@@ -24,21 +22,15 @@ export async function initUsers() {
|
||||
const lessonDaySelect = document.getElementById('lesson-day');
|
||||
const weekUpper = document.getElementById('week-upper');
|
||||
const weekLower = document.getElementById('week-lower');
|
||||
// NEW: получаем элемент выбора времени
|
||||
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 = [];
|
||||
|
||||
// NEW: массивы с временными слотами
|
||||
const weekdaysTimes = [
|
||||
"8:00-9:30",
|
||||
"9:40-11:10",
|
||||
@@ -56,39 +48,7 @@ export async function initUsers() {
|
||||
"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');
|
||||
@@ -98,6 +58,7 @@ export async function initUsers() {
|
||||
}
|
||||
}
|
||||
|
||||
// Загрузка дисциплин
|
||||
async function loadSubjects() {
|
||||
try {
|
||||
subjects = await api.get('/api/subjects');
|
||||
@@ -116,29 +77,31 @@ export async function initUsers() {
|
||||
}
|
||||
}
|
||||
|
||||
// Заполнение select группами
|
||||
function renderGroupOptions() {
|
||||
if (!groups || groups.length === 0) {
|
||||
lessonGroupSelect.innerHTML = '<option value="">Нет доступных групп</option>';
|
||||
lessonClassroomSelect.innerHTML = '<option value="">Нет доступных групп</option>';
|
||||
return;
|
||||
}
|
||||
|
||||
lessonGroupSelect.innerHTML =
|
||||
'<option value="">Выберите группу</option>' +
|
||||
lessonGroupSelect.innerHTML = '<option value="">Выберите группу</option>' +
|
||||
groups.map(g => {
|
||||
let optionText = escapeHtml(g.name);
|
||||
if (g.groupSize) optionText += ` (численность: ${g.groupSize} чел.)`;
|
||||
if(g.groupSize) {
|
||||
optionText += ` (численность: ${g.groupSize} чел.)`;
|
||||
}
|
||||
return `<option value="${g.id}">${optionText}</option>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// Заполнение select дисциплинами
|
||||
function renderSubjectOptions() {
|
||||
lessonDisciplineSelect.innerHTML =
|
||||
'<option value="">Выберите дисциплину</option>' +
|
||||
lessonDisciplineSelect.innerHTML = '<option value="">Выберите дисциплину</option>' +
|
||||
subjects.map(s => `<option value="${s.id}">${escapeHtml(s.name)}</option>`).join('');
|
||||
}
|
||||
|
||||
function renderClassroomsOptions() {
|
||||
if (!classrooms || classrooms.length === 0) {
|
||||
if (!classrooms || classrooms.length ===0) {
|
||||
lessonClassroomSelect.innerHTML = '<option value="">Нет доступных аудиторий</option>';
|
||||
return;
|
||||
}
|
||||
@@ -147,28 +110,32 @@ export async function initUsers() {
|
||||
const selectedGroup = groups?.find(g => g.id == selectedGroupId);
|
||||
const groupSize = selectedGroup?.groupSize || 0;
|
||||
|
||||
lessonClassroomSelect.innerHTML =
|
||||
'<option value="">Выберите аудиторию</option>' +
|
||||
lessonClassroomSelect.innerHTML = '<option value="">Выберите аудиторию</option>' +
|
||||
classrooms.map(c => {
|
||||
let optionText = escapeHtml(c.name);
|
||||
// Добавление текста с инфой о вместимости чел.
|
||||
if(c.capacity) {
|
||||
optionText += ` (вместимость: ${c.capacity} чел.)`;
|
||||
}
|
||||
|
||||
if (c.capacity) optionText += ` (вместимость: ${c.capacity} чел.)`;
|
||||
|
||||
// Если аудитория занята, то рисуем крестик допом
|
||||
if (c.isAvailable === false) {
|
||||
optionText += ` ❌ Занята`;
|
||||
optionText += ` ❌ Занята`
|
||||
// Если свободна, но меньше численности группы, отображаем воскл. знак
|
||||
} else if (selectedGroupId && groupSize > 0 && c.capacity && groupSize > c.capacity) {
|
||||
optionText += ` ⚠️ Недостаточно места`;
|
||||
}
|
||||
|
||||
|
||||
return `<option value="${c.id}">${optionText}</option>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
lessonGroupSelect.addEventListener('change', function () {
|
||||
lessonGroupSelect.addEventListener('change', function() {
|
||||
renderClassroomsOptions();
|
||||
requestAnimationFrame(() => syncAddLessonHeight());
|
||||
});
|
||||
|
||||
// NEW: функция обновления списка времени в зависимости от дня
|
||||
function updateTimeOptions(dayValue) {
|
||||
let times = [];
|
||||
if (dayValue === "Суббота") {
|
||||
@@ -181,23 +148,17 @@ export async function initUsers() {
|
||||
return;
|
||||
}
|
||||
|
||||
lessonTimeSelect.innerHTML =
|
||||
'<option value="">Выберите время</option>' +
|
||||
lessonTimeSelect.innerHTML = '<option value="">Выберите время</option>' +
|
||||
times.map(t => `<option value="${t}">${t}</option>`).join('');
|
||||
lessonTimeSelect.disabled = false;
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// Пользователи
|
||||
// =========================================================
|
||||
async function loadUsers() {
|
||||
try {
|
||||
const users = await api.get('/api/users');
|
||||
renderUsers(users);
|
||||
} 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>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,72 +167,40 @@ export async function initUsers() {
|
||||
usersTbody.innerHTML = '<tr><td colspan="4" class="loading-row">Нет пользователей</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
usersTbody.innerHTML = users.map(u => `
|
||||
<tr>
|
||||
<td>${u.id}</td>
|
||||
<td>${escapeHtml(u.username)}</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>
|
||||
<button class="btn-add-lesson" data-id="${u.id}" data-name="${escapeHtml(u.username)}">Добавить занятие</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
<td><button class="btn-delete" data-id="${u.id}">Удалить</button></td>
|
||||
<td><button class="btn-add-lesson" data-id="${u.id}">Добавить занятие</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;
|
||||
|
||||
// NEW: сбрасываем селект времени
|
||||
if (lessonOfflineFormat) lessonOfflineFormat.checked = true;
|
||||
if (lessonOnlineFormat) lessonOnlineFormat.checked = false;
|
||||
|
||||
lessonTimeSelect.innerHTML = '<option value="">Сначала выберите день</option>';
|
||||
lessonTimeSelect.disabled = true;
|
||||
|
||||
hideAlert('add-lesson-alert');
|
||||
}
|
||||
|
||||
// Открытие модалки с установкой userId
|
||||
function openAddLessonModal(userId) {
|
||||
lessonUserId.value = userId;
|
||||
|
||||
// NEW: сбрасываем выбранный день и время
|
||||
lessonDaySelect.value = '';
|
||||
updateTimeOptions('');
|
||||
|
||||
modalAddLesson.classList.add('open');
|
||||
updateBackdrop();
|
||||
requestAnimationFrame(() => syncAddLessonHeight());
|
||||
}
|
||||
|
||||
// Обработчик отправки формы добавления занятия
|
||||
addLessonForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
hideAlert('add-lesson-alert');
|
||||
@@ -282,26 +211,48 @@ export async function initUsers() {
|
||||
const classroomId = lessonClassroomSelect.value;
|
||||
const lessonType = lessonTypeSelect.value;
|
||||
const dayOfWeek = lessonDaySelect.value;
|
||||
const timeSlot = lessonTimeSelect.value;
|
||||
const timeSlot = lessonTimeSelect.value; // NEW: получаем выбранное время
|
||||
|
||||
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; }
|
||||
// Проверка обязательных полей
|
||||
if (!groupId) {
|
||||
showAlert('add-lesson-alert', 'Выберите группу', 'error');
|
||||
return;
|
||||
}
|
||||
if (!subjectId) {
|
||||
showAlert('add-lesson-alert', 'Выберите дисциплину', 'error');
|
||||
return;
|
||||
}
|
||||
if (!classroomId) {
|
||||
showAlert('add-lesson-alert', 'Выберите аудиторию', 'error')
|
||||
return;
|
||||
}
|
||||
if (!dayOfWeek) {
|
||||
showAlert('add-lesson-alert', 'Выберите день недели', 'error');
|
||||
return;
|
||||
}
|
||||
// NEW: проверка времени
|
||||
if (!timeSlot) {
|
||||
showAlert('add-lesson-alert', 'Выберите время', 'error');
|
||||
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 = 'Нижняя';
|
||||
if (weekUpperChecked && weekLowerChecked) {
|
||||
weekType = 'Обе';
|
||||
} else if (weekUpperChecked) {
|
||||
weekType = 'Верхняя';
|
||||
} else if (weekLowerChecked) {
|
||||
weekType = 'Нижняя';
|
||||
}
|
||||
|
||||
try {
|
||||
await api.post('/api/users/lessons/create', {
|
||||
// Отправляем данные на сервер
|
||||
const response = await api.post('/api/users/lessons/create', {
|
||||
teacherId: parseInt(userId),
|
||||
groupId: parseInt(groupId),
|
||||
subjectId: parseInt(subjectId),
|
||||
@@ -310,212 +261,37 @@ export async function initUsers() {
|
||||
lessonFormat: lessonFormat,
|
||||
day: dayOfWeek,
|
||||
week: weekType,
|
||||
time: timeSlot
|
||||
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();
|
||||
}, 1500);
|
||||
} catch (e) {
|
||||
showAlert('add-lesson-alert', e.message || 'Ошибка добавления занятия', 'error');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// Создание пользователя
|
||||
// =========================================================
|
||||
createForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
hideAlert('create-alert');
|
||||
|
||||
const username = document.getElementById('new-username').value.trim();
|
||||
const password = document.getElementById('new-password').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 {
|
||||
const data = await api.post('/api/users', { username, password, role });
|
||||
showAlert('create-alert', `Пользователь "${escapeHtml(data.username)}" создан`, 'success');
|
||||
createForm.reset();
|
||||
loadUsers();
|
||||
} catch (err) {
|
||||
showAlert('create-alert', err.message || 'Ошибка соединения', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// =========================================================
|
||||
// Инициализация
|
||||
// =========================================================
|
||||
await Promise.all([loadUsers(), loadGroups(), loadSubjects(), loadClassrooms()]);
|
||||
|
||||
// =========================================================
|
||||
// 2-я модалка: просмотр занятий
|
||||
// =========================================================
|
||||
async function loadTeacherLessons(teacherId, teacherName) {
|
||||
try {
|
||||
lessonsContainer.innerHTML = '<div class="loading-lessons">Загрузка занятий...</div>';
|
||||
|
||||
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) {
|
||||
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;
|
||||
showAlert('create-alert', e.message || 'Ошибка соединения', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// =========================================================
|
||||
// ЕДИНЫЙ обработчик кликов по таблице (ВАЖНО: без дубля)
|
||||
// =========================================================
|
||||
// Обработчик кликов по таблице
|
||||
usersTbody.addEventListener('click', async (e) => {
|
||||
const deleteBtn = e.target.closest('.btn-delete');
|
||||
if (deleteBtn) {
|
||||
@@ -523,8 +299,8 @@ export async function initUsers() {
|
||||
try {
|
||||
await api.delete('/api/users/' + deleteBtn.dataset.id);
|
||||
loadUsers();
|
||||
} catch (err) {
|
||||
alert(err.message || 'Ошибка удаления');
|
||||
} catch (e) {
|
||||
alert(e.message || 'Ошибка удаления');
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -532,23 +308,35 @@ export async function initUsers() {
|
||||
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;
|
||||
if (modalAddLesson) {
|
||||
openAddLessonModal(addLessonBtn.dataset.id);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
// NEW: обработчик изменения дня недели для обновления списка времени
|
||||
lessonDaySelect.addEventListener('change', function() {
|
||||
updateTimeOptions(this.value);
|
||||
});
|
||||
|
||||
// Закрытие модалки по крестику
|
||||
if (modalAddLessonClose) {
|
||||
modalAddLessonClose.addEventListener('click', () => {
|
||||
modalAddLesson.classList.remove('open');
|
||||
resetLessonForm();
|
||||
});
|
||||
}
|
||||
|
||||
// Закрытие по клику на overlay
|
||||
if (modalAddLesson) {
|
||||
modalAddLesson.addEventListener('click', (e) => {
|
||||
if (e.target === modalAddLesson) {
|
||||
modalAddLesson.classList.remove('open');
|
||||
resetLessonForm();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Загружаем все данные при инициализации
|
||||
await Promise.all([loadUsers(), loadGroups(), loadSubjects(), loadClassrooms()]);
|
||||
}
|
||||
73
frontend/admin/views/database.html
Executable file
73
frontend/admin/views/database.html
Executable file
@@ -0,0 +1,73 @@
|
||||
<!-- ===== Database / Tenants Tab ===== -->
|
||||
|
||||
<!-- Текущее подключение -->
|
||||
<div class="card">
|
||||
<h2>Текущее подключение</h2>
|
||||
<div id="db-status-info" class="db-status-card">
|
||||
<div class="loading-row">Загрузка...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Таблица тенантов -->
|
||||
<div class="card">
|
||||
<h2>Подключённые университеты</h2>
|
||||
<div class="table-wrap">
|
||||
<table id="tenants-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
<th>Домен</th>
|
||||
<th>JDBC URL</th>
|
||||
<th>Пользователь</th>
|
||||
<th>Статус</th>
|
||||
<th>Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tenants-tbody">
|
||||
<tr>
|
||||
<td colspan="6" class="loading-row">Загрузка...</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Добавить тенант -->
|
||||
<div class="card create-card">
|
||||
<h2>Добавить подключение</h2>
|
||||
<form id="add-tenant-form">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="tenant-name">Название университета</label>
|
||||
<input type="text" id="tenant-name" placeholder="ЮЗГУ" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="tenant-domain">Поддомен</label>
|
||||
<input type="text" id="tenant-domain" placeholder="swsu" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row" style="margin-top: 0.75rem;">
|
||||
<div class="form-group" style="flex: 3;">
|
||||
<label for="tenant-url">JDBC URL</label>
|
||||
<input type="text" id="tenant-url" placeholder="jdbc:postgresql://192.168.1.50:5432/magistr_db" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row" style="margin-top: 0.75rem;">
|
||||
<div class="form-group">
|
||||
<label for="tenant-username">Пользователь</label>
|
||||
<input type="text" id="tenant-username" placeholder="postgres" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="tenant-password">Пароль</label>
|
||||
<input type="password" id="tenant-password" placeholder="••••••••" required>
|
||||
</div>
|
||||
<button type="button" class="btn-primary" id="btn-test-connection" style="height: fit-content;">
|
||||
Тест
|
||||
</button>
|
||||
<button type="submit" class="btn-primary" style="height: fit-content;">
|
||||
Добавить
|
||||
</button>
|
||||
</div>
|
||||
<div class="form-alert" id="add-tenant-alert" role="alert"></div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -54,35 +54,29 @@
|
||||
<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">
|
||||
<div class="form-group" style="margin-top: 1rem;">
|
||||
<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">
|
||||
<div class="form-group" style="margin-top: 1rem;">
|
||||
<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">
|
||||
<div class="form-group" style="margin-top: 1rem;">
|
||||
<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">
|
||||
<div class="form-row" style="margin-top: 1rem;">
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label for="lesson-day">День недели</label>
|
||||
<select id="lesson-day" required>
|
||||
<option value="">Выберите день</option>
|
||||
@@ -94,11 +88,9 @@
|
||||
<option value="Суббота">Суббота</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Тип недели (ВЕРТИКАЛЬНО) -->
|
||||
<div class="form-group" style="flex: 0 1 auto; max-width: 192px">
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label>Неделя</label>
|
||||
<div style="display: flex; gap: 0.2rem;">
|
||||
<div style="display: flex; gap: 0.5rem;">
|
||||
<label class="btn-checkbox">
|
||||
<input type="checkbox" name="weekType" value="Верхняя" id="week-upper">
|
||||
<span class="checkbox-btn">Верхняя</span>
|
||||
@@ -109,22 +101,21 @@
|
||||
</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">
|
||||
<div class="form-row" style="margin-top: 1rem;">
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<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: 1;">
|
||||
<label>Формат занятия</label>
|
||||
<div style="display: flex; gap: 0.2rem;">
|
||||
<div style="display: flex; gap: 0.5rem;">
|
||||
<label class="btn-checkbox">
|
||||
<input type="radio" name="lessonFormat" value="Очно" id="format-offline" checked>
|
||||
<span class="checkbox-btn">Очно</span>
|
||||
@@ -135,38 +126,17 @@
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Время занятия -->
|
||||
<div class="form-group" style="flex: 0 0 auto; max-width: 235px">
|
||||
<div class="form-group" style="margin-top: 1rem;">
|
||||
<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>
|
||||
<button type="submit" class="btn-primary" style="width: 100%; margin-top: 1rem;">Сохранить</button>
|
||||
<div class="form-alert" id="add-lesson-alert" role="alert"></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">×</button>
|
||||
</div>
|
||||
|
||||
<div class="lessons-container" id="lessons-container">
|
||||
<!-- Фильтры по дням (добавим позже) -->
|
||||
<div class="loading-lessons">Загрузка занятий...</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="modal-backdrop"></div>
|
||||
Reference in New Issue
Block a user