Compare commits
22 Commits
trafic-log
...
2fc9e3ee53
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2fc9e3ee53 | ||
| e2fd4fb29a | |||
| 0cce8b2982 | |||
| 1ca2f872f7 | |||
| 03dd52de71 | |||
|
|
859273a9c1 | ||
| 653536b0da | |||
|
|
5fca5bde55 | ||
|
|
d36fd17690 | ||
|
|
295f977a21 | ||
|
|
1a00d0cd19 | ||
|
|
2da6a58b20 | ||
|
|
0d2883fe2a | ||
|
|
7f99d11209 | ||
|
|
053ac89e3c | ||
|
|
cfca22bf66 | ||
|
|
7c5cc38cff | ||
|
|
dae0a4b78d | ||
|
|
882ffe7094 | ||
|
|
136771ab60 | ||
| 3865c26397 | |||
|
|
26a217cd50 |
76
.gitea/workflows/build-and-deploy.yml
Normal file
76
.gitea/workflows/build-and-deploy.yml
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
name: Build and Deploy Java Gradle Application
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- fix-left-side-menu
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 📄 Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: 📄 Checkout configuration
|
||||||
|
env:
|
||||||
|
SSH_PRIVATE_KEY: ${{ secrets.PROD_PROPERTIES_SSH_KEY }}
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
git clone -b hexagonal-reforged ssh://gitea@gitea.takiguchi.ovh:12960/Codiki/codiki-properties.git --config core.sshCommand='ssh -o StrictHostKeyChecking=no'
|
||||||
|
|
||||||
|
- name: 📄 Edit configuration
|
||||||
|
run: |
|
||||||
|
sed -i "s/<POSTGRES_PASSWORD>/$(cat ./codiki-properties/passwords/postgresql/codiki_user)/g" ./codiki-properties/application-prod.yml
|
||||||
|
cp ./codiki-properties/application-prod.yml ./backend/codiki-launcher/src/main/resources/application.yml
|
||||||
|
sed -i "s/<POSTGRES_ADMIN_PASSWORD>/$(cat ./codiki-properties/passwords/postgresql/codiki_admin)/g" ./docker-compose.yml
|
||||||
|
|
||||||
|
- name: 🔨 Build backend docker image
|
||||||
|
run: |
|
||||||
|
sudo /usr/bin/docker build -t codiki-backend -f ./Dockerfile-backend . --no-cache
|
||||||
|
|
||||||
|
- name: 📦 Extract backend docker image into archive
|
||||||
|
run: |
|
||||||
|
sudo /usr/bin/docker save codiki-backend:latest -o ./codiki-backend.tar
|
||||||
|
|
||||||
|
- name: 🔨 Build frontend docker image
|
||||||
|
run: |
|
||||||
|
sudo /usr/bin/docker build -t codiki-frontend -f ./Dockerfile-frontend . --no-cache
|
||||||
|
|
||||||
|
- name: 📦 Extract frontend docker image into archive
|
||||||
|
run: |
|
||||||
|
sudo /usr/bin/docker save codiki-frontend:latest -o ./codiki-frontend.tar
|
||||||
|
|
||||||
|
- name: 📤 Transfer artifacts to remote server
|
||||||
|
env:
|
||||||
|
SSH_PRIVATE_KEY: ${{ secrets.PROD_SSH_PRIVATE_KEY }}
|
||||||
|
REMOTE_USER: ${{ secrets.PROD_REMOTE_USER }}
|
||||||
|
REMOTE_HOST: ${{ secrets.PROD_REMOTE_HOST }}
|
||||||
|
REMOTE_PORT: ${{ secrets.PROD_REMOTE_PORT }}
|
||||||
|
REMOTE_PATH: ${{ secrets.PROD_REMOTE_PATH }}
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
scp -o StrictHostKeyChecking=no -P $REMOTE_PORT ./codiki-backend.tar $REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH
|
||||||
|
scp -o StrictHostKeyChecking=no -P $REMOTE_PORT ./codiki-frontend.tar $REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH
|
||||||
|
scp -o StrictHostKeyChecking=no -P $REMOTE_PORT ./docker-compose.yml $REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH
|
||||||
|
|
||||||
|
- name: 🚀 Launch application onto remote server
|
||||||
|
env:
|
||||||
|
SSH_PRIVATE_KEY: ${{ secrets.PROD_SSH_PRIVATE_KEY }}
|
||||||
|
REMOTE_USER: ${{ secrets.PROD_REMOTE_USER }}
|
||||||
|
REMOTE_HOST: ${{ secrets.PROD_REMOTE_HOST }}
|
||||||
|
REMOTE_PORT: ${{ secrets.PROD_REMOTE_PORT }}
|
||||||
|
REMOTE_PATH: ${{ secrets.PROD_REMOTE_PATH }}
|
||||||
|
run: |
|
||||||
|
ssh -o StrictHostKeyChecking=no $REMOTE_HOST -l $REMOTE_USER -p $REMOTE_PORT << EOC
|
||||||
|
cd $REMOTE_PATH
|
||||||
|
sudo /usr/bin/docker load < $REMOTE_PATH/codiki-backend.tar
|
||||||
|
sudo /usr/bin/docker load < $REMOTE_PATH/codiki-frontend.tar
|
||||||
|
sudo /usr/bin/docker compose down
|
||||||
|
sudo /usr/bin/docker compose up --detach
|
||||||
|
EOC
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM maven:3.9.9-eclipse-temurin-21 AS builder
|
FROM maven:3.9.11-eclipse-temurin-21 AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY backend/pom.xml /app/
|
COPY backend/pom.xml /app/
|
||||||
COPY backend/codiki-application /app/codiki-application
|
COPY backend/codiki-application /app/codiki-application
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
FROM node:22-alpine AS builder
|
FROM node:25-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY frontend /app
|
COPY frontend /app
|
||||||
RUN npm install
|
RUN npm install
|
||||||
RUN npm run build-prod-en
|
RUN npm run build-prod-en
|
||||||
RUN npm run build-prod-fr
|
RUN npm run build-prod-fr
|
||||||
|
|
||||||
FROM nginx:1.27-alpine AS final
|
FROM nginx:1.29-alpine AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/dist/codiki/en/browser /usr/share/nginx/html/en/
|
COPY --from=builder /app/dist/codiki/en/browser /usr/share/nginx/html/en/
|
||||||
COPY --from=builder /app/dist/codiki/fr/browser/fr /usr/share/nginx/html/fr/
|
COPY --from=builder /app/dist/codiki/fr/browser/fr /usr/share/nginx/html/fr/
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ public class CustomUserDetails implements UserDetails {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return user.id().toString();
|
return user.id().toString();
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
package org.codiki.application.traffic;
|
|
||||||
|
|
||||||
import jakarta.annotation.Nullable;
|
|
||||||
import org.codiki.domain.traffic.exception.TrafficTraceCreationException;
|
|
||||||
import org.codiki.domain.traffic.model.TrafficEndpoint;
|
|
||||||
import org.codiki.domain.traffic.model.TrafficTrace;
|
|
||||||
import org.codiki.domain.traffic.port.TrafficTracePort;
|
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.Clock;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
import static org.codiki.domain.traffic.model.TrafficTrace.aTrafficTrace;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class TrafficTraceUseCases {
|
|
||||||
private final TrafficTracePort trafficTracePort;
|
|
||||||
private final Clock clock;
|
|
||||||
|
|
||||||
public TrafficTraceUseCases(TrafficTracePort trafficTracePort, Clock clock) {
|
|
||||||
this.trafficTracePort = trafficTracePort;
|
|
||||||
this.clock = clock;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Async
|
|
||||||
public void saveNewTrace(
|
|
||||||
TrafficEndpoint trafficEndpoint,
|
|
||||||
@Nullable UUID userId,
|
|
||||||
@Nullable String correlationId
|
|
||||||
) {
|
|
||||||
if (isNull(trafficEndpoint)) {
|
|
||||||
throw new TrafficTraceCreationException("Traffic endpoint should not be null.");
|
|
||||||
}
|
|
||||||
|
|
||||||
TrafficTrace newTrace = aTrafficTrace()
|
|
||||||
.withId(UUID.randomUUID())
|
|
||||||
.withDateTime(ZonedDateTime.now(clock))
|
|
||||||
.withEndpoint(trafficEndpoint)
|
|
||||||
.withUserId(userId)
|
|
||||||
.withCorrelationId(correlationId)
|
|
||||||
.build();
|
|
||||||
trafficTracePort.save(newTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -87,7 +87,9 @@ public class UserUseCases {
|
|||||||
.map(Authentication::getPrincipal)
|
.map(Authentication::getPrincipal)
|
||||||
.filter(CustomUserDetails.class::isInstance)
|
.filter(CustomUserDetails.class::isInstance)
|
||||||
.map(CustomUserDetails.class::cast)
|
.map(CustomUserDetails.class::cast)
|
||||||
.map(CustomUserDetails::getUser);
|
.map(CustomUserDetails::getUsername)
|
||||||
|
.map(UUID::fromString)
|
||||||
|
.flatMap(userPort::findById);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserAuthenticationData generateAuthenticationData(User user) {
|
private UserAuthenticationData generateAuthenticationData(User user) {
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package org.codiki.domain.traffic.exception;
|
|
||||||
|
|
||||||
import org.codiki.domain.exception.FunctionnalException;
|
|
||||||
|
|
||||||
public class TrafficTraceCreationException extends FunctionnalException {
|
|
||||||
public TrafficTraceCreationException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package org.codiki.domain.traffic.model;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public enum HttpMethod {
|
|
||||||
GET, POST, PUT, DELETE;
|
|
||||||
|
|
||||||
public static Optional<HttpMethod> fromString(String methodAsString) {
|
|
||||||
return Arrays.stream(values())
|
|
||||||
.filter(method -> method.name().equals(methodAsString))
|
|
||||||
.findFirst();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package org.codiki.domain.traffic.model;
|
|
||||||
|
|
||||||
public record TrafficEndpoint(
|
|
||||||
HttpMethod method,
|
|
||||||
String path
|
|
||||||
) {}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package org.codiki.domain.traffic.model;
|
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public record TrafficTrace(
|
|
||||||
UUID id,
|
|
||||||
ZonedDateTime dateTime,
|
|
||||||
TrafficEndpoint endpoint,
|
|
||||||
UUID userId,
|
|
||||||
String correlationId
|
|
||||||
) {
|
|
||||||
public static Builder aTrafficTrace() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private UUID id;
|
|
||||||
private ZonedDateTime dateTime;
|
|
||||||
private TrafficEndpoint endpoint;
|
|
||||||
private UUID userId;
|
|
||||||
private String correlationId;
|
|
||||||
|
|
||||||
private Builder() {}
|
|
||||||
|
|
||||||
public Builder withId(UUID id) {
|
|
||||||
this.id = id;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder withDateTime(ZonedDateTime dateTime) {
|
|
||||||
this.dateTime = dateTime;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder withEndpoint(TrafficEndpoint endpoint) {
|
|
||||||
this.endpoint = endpoint;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder withUserId(UUID userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder withCorrelationId(String correlationId) {
|
|
||||||
this.correlationId = correlationId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TrafficTrace build() {
|
|
||||||
return new TrafficTrace(id, dateTime, endpoint, userId, correlationId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package org.codiki.domain.traffic.port;
|
|
||||||
|
|
||||||
import org.codiki.domain.traffic.model.TrafficTrace;
|
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface TrafficTracePort {
|
|
||||||
void save(TrafficTrace trace);
|
|
||||||
List<TrafficTrace> getAllInPeriod(ZonedDateTime startDate, ZonedDateTime endDate);
|
|
||||||
List<TrafficTrace> getAllByCorrelationId(String correlationId);
|
|
||||||
Integer countAllInPeriod(ZonedDateTime startDate, ZonedDateTime endDate);
|
|
||||||
Integer countByCorrelationId(String correlationId);
|
|
||||||
}
|
|
||||||
@@ -25,10 +25,6 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-aop</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package org.codiki.exposition.configuration;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableAspectJAutoProxy
|
|
||||||
@EnableAsync
|
|
||||||
public class TrafficTraceConfiguration {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -38,6 +38,10 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
.filter(authorizationHeader -> !isEmpty(authorizationHeader))
|
.filter(authorizationHeader -> !isEmpty(authorizationHeader))
|
||||||
.filter(authorizationHeader -> authorizationHeader.startsWith(BEARER_PREFIX))
|
.filter(authorizationHeader -> authorizationHeader.startsWith(BEARER_PREFIX))
|
||||||
.map(authorizationHeader -> authorizationHeader.substring(BEARER_PREFIX.length()))
|
.map(authorizationHeader -> authorizationHeader.substring(BEARER_PREFIX.length()))
|
||||||
|
.filter(token -> {
|
||||||
|
String authorizationHeader = request.getHeader(AUTHORIZATION);
|
||||||
|
return !isEmpty(authorizationHeader) && authorizationHeader.startsWith(BEARER_PREFIX);
|
||||||
|
})
|
||||||
.filter(jwtService::isValid)
|
.filter(jwtService::isValid)
|
||||||
.flatMap(jwtService::extractUser)
|
.flatMap(jwtService::extractUser)
|
||||||
.map(CustomUserDetails::new)
|
.map(CustomUserDetails::new)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class SecurityConfiguration {
|
|||||||
public SecurityFilterChain securityFilterChain(
|
public SecurityFilterChain securityFilterChain(
|
||||||
HttpSecurity httpSecurity,
|
HttpSecurity httpSecurity,
|
||||||
JwtAuthenticationFilter jwtAuthenticationFilter
|
JwtAuthenticationFilter jwtAuthenticationFilter
|
||||||
) throws Exception {
|
) {
|
||||||
httpSecurity
|
httpSecurity
|
||||||
.csrf(AbstractHttpConfigurer::disable)
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
.httpBasic(Customizer.withDefaults())
|
.httpBasic(Customizer.withDefaults())
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
package org.codiki.exposition.traffic;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
import org.aspectj.lang.annotation.Before;
|
|
||||||
import org.codiki.application.traffic.TrafficTraceUseCases;
|
|
||||||
import org.codiki.application.user.UserUseCases;
|
|
||||||
import org.codiki.domain.traffic.model.HttpMethod;
|
|
||||||
import org.codiki.domain.traffic.model.TrafficEndpoint;
|
|
||||||
import org.codiki.domain.user.model.User;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Aspect
|
|
||||||
public class ApiCallsLoggerAspect {
|
|
||||||
private static final String HTTP_HEADER_CORRELATION_ID = "x-correlation-id";
|
|
||||||
|
|
||||||
private final TrafficTraceUseCases trafficTraceUseCases;
|
|
||||||
private final UserUseCases userUseCases;
|
|
||||||
|
|
||||||
public ApiCallsLoggerAspect(
|
|
||||||
TrafficTraceUseCases trafficTraceUseCases,
|
|
||||||
UserUseCases userUseCases
|
|
||||||
) {
|
|
||||||
this.trafficTraceUseCases = trafficTraceUseCases;
|
|
||||||
this.userUseCases = userUseCases;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before("@annotation(org.springframework.web.bind.annotation.GetMapping)")
|
|
||||||
public void logGetApiCall(JoinPoint joinPoint) {
|
|
||||||
logApiCall();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before("@annotation(org.springframework.web.bind.annotation.PostMapping)")
|
|
||||||
public void logPostApiCall(JoinPoint joinPoint) {
|
|
||||||
logApiCall();
|
|
||||||
}
|
|
||||||
@Before("@annotation(org.springframework.web.bind.annotation.PutMapping)")
|
|
||||||
public void logPutApiCall(JoinPoint joinPoint) {
|
|
||||||
logApiCall();
|
|
||||||
}
|
|
||||||
@Before("@annotation(org.springframework.web.bind.annotation.DeleteMapping)")
|
|
||||||
public void logDeleteApiCall(JoinPoint joinPoint) {
|
|
||||||
logApiCall();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void logApiCall() {
|
|
||||||
getHttpServletRequest().ifPresent(request ->
|
|
||||||
Optional.of(request.getMethod())
|
|
||||||
.flatMap(HttpMethod::fromString)
|
|
||||||
.ifPresent(queryHttpMethod -> {
|
|
||||||
String queryUriPath = request.getRequestURI();
|
|
||||||
TrafficEndpoint endpoint = new TrafficEndpoint(queryHttpMethod, queryUriPath);
|
|
||||||
UUID userId = userUseCases.getAuthenticatedUser()
|
|
||||||
.map(User::id)
|
|
||||||
.orElse(null);
|
|
||||||
String correlationId = request.getHeader(HTTP_HEADER_CORRELATION_ID);
|
|
||||||
trafficTraceUseCases.saveNewTrace(endpoint, userId, correlationId);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Optional<HttpServletRequest> getHttpServletRequest() {
|
|
||||||
return Optional.ofNullable(RequestContextHolder.getRequestAttributes())
|
|
||||||
.filter(ServletRequestAttributes.class::isInstance)
|
|
||||||
.map(ServletRequestAttributes.class::cast)
|
|
||||||
.map(ServletRequestAttributes::getRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.codiki.infrastructure.configuration;
|
package org.codiki.infrastructure.configuration;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
import org.springframework.boot.persistence.autoconfigure.EntityScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
package org.codiki.infrastructure.traffic;
|
|
||||||
|
|
||||||
import org.codiki.domain.traffic.model.TrafficTrace;
|
|
||||||
import org.codiki.domain.traffic.port.TrafficTracePort;
|
|
||||||
import org.codiki.infrastructure.traffic.model.TrafficTraceEntity;
|
|
||||||
import org.codiki.infrastructure.traffic.repository.TrafficTraceEntityJpaRepository;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class TrafficTraceJpaAdapter implements TrafficTracePort {
|
|
||||||
private final TrafficTraceEntityJpaRepository repository;
|
|
||||||
|
|
||||||
public TrafficTraceJpaAdapter(TrafficTraceEntityJpaRepository repository) {
|
|
||||||
this.repository = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(TrafficTrace trace) {
|
|
||||||
TrafficTraceEntity entity = new TrafficTraceEntity(trace);
|
|
||||||
repository.save(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TrafficTrace> getAllInPeriod(ZonedDateTime startDate, ZonedDateTime endDate) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TrafficTrace> getAllByCorrelationId(String correlationId) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer countAllInPeriod(ZonedDateTime startDate, ZonedDateTime endDate) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer countByCorrelationId(String correlationId) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package org.codiki.infrastructure.traffic.model;
|
|
||||||
|
|
||||||
import org.codiki.domain.traffic.model.HttpMethod;
|
|
||||||
|
|
||||||
public enum HttpMethodEntity {
|
|
||||||
GET, POST, PUT, DELETE;
|
|
||||||
|
|
||||||
public HttpMethod toDomain() {
|
|
||||||
return switch (this) {
|
|
||||||
case GET -> HttpMethod.GET;
|
|
||||||
case POST -> HttpMethod.POST;
|
|
||||||
case PUT -> HttpMethod.PUT;
|
|
||||||
case DELETE -> HttpMethod.DELETE;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HttpMethodEntity fromDomain(HttpMethod method) {
|
|
||||||
return switch (method) {
|
|
||||||
case HttpMethod.GET -> GET;
|
|
||||||
case HttpMethod.POST -> POST;
|
|
||||||
case HttpMethod.PUT -> PUT;
|
|
||||||
case HttpMethod.DELETE -> DELETE;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package org.codiki.infrastructure.traffic.model;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.codiki.domain.traffic.model.TrafficEndpoint;
|
|
||||||
import org.codiki.domain.traffic.model.TrafficTrace;
|
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static org.codiki.domain.traffic.model.TrafficTrace.aTrafficTrace;
|
|
||||||
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@Entity
|
|
||||||
@Table(name = "traffic")
|
|
||||||
public class TrafficTraceEntity {
|
|
||||||
@Id
|
|
||||||
private UUID id;
|
|
||||||
@Column(nullable = false)
|
|
||||||
private ZonedDateTime dateTime;
|
|
||||||
@Column(nullable = false)
|
|
||||||
@Enumerated
|
|
||||||
private HttpMethodEntity endpointMethod;
|
|
||||||
@Column(nullable = false)
|
|
||||||
private String endpointPath;
|
|
||||||
private UUID userId;
|
|
||||||
private String correlationId;
|
|
||||||
|
|
||||||
public TrafficTraceEntity(TrafficTrace trace) {
|
|
||||||
id = trace.id();
|
|
||||||
dateTime = trace.dateTime();
|
|
||||||
endpointMethod = HttpMethodEntity.fromDomain(trace.endpoint().method());
|
|
||||||
endpointPath = trace.endpoint().path();
|
|
||||||
userId = trace.userId();
|
|
||||||
correlationId = trace.correlationId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TrafficTrace toDomain() {
|
|
||||||
return aTrafficTrace()
|
|
||||||
.withId(id)
|
|
||||||
.withDateTime(dateTime)
|
|
||||||
.withEndpoint(new TrafficEndpoint(
|
|
||||||
endpointMethod.toDomain(),
|
|
||||||
endpointPath
|
|
||||||
))
|
|
||||||
.withUserId(userId)
|
|
||||||
.withCorrelationId(correlationId)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package org.codiki.infrastructure.traffic.repository;
|
|
||||||
|
|
||||||
import org.codiki.infrastructure.traffic.model.TrafficTraceEntity;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface TrafficTraceEntityJpaRepository extends JpaRepository<TrafficTraceEntity, UUID> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS traffic (
|
|
||||||
id UUID NOT NULL,
|
|
||||||
date_time TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
||||||
endpoint_method SMALLINT NOT NULL,
|
|
||||||
endpoint_path VARCHAR NOT NULL,
|
|
||||||
user_id UUID,
|
|
||||||
correlation_id VARCHAR,
|
|
||||||
CONSTRAINT traffic_pk PRIMARY KEY (id),
|
|
||||||
CONSTRAINT traffic_user_id_fk FOREIGN KEY (user_id) REFERENCES "user" (id)
|
|
||||||
);
|
|
||||||
CREATE INDEX traffic_user_id_idx ON traffic (user_id);
|
|
||||||
@@ -16,10 +16,10 @@
|
|||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<jakarta.servlet-api.version>6.1.0</jakarta.servlet-api.version>
|
<jakarta.servlet-api.version>6.1.0</jakarta.servlet-api.version>
|
||||||
<java-jwt.version>4.4.0</java-jwt.version>
|
<java-jwt.version>4.5.0</java-jwt.version>
|
||||||
<tika-core.version>2.9.0</tika-core.version>
|
<postgresql.version>42.7.8</postgresql.version>
|
||||||
<postgresql.version>42.7.4</postgresql.version>
|
<tika-core.version>3.2.3</tika-core.version>
|
||||||
<commons-lang3.version>3.17.0</commons-lang3.version>
|
<commons-lang3.version>3.20.0</commons-lang3.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
<version>3.3.4</version>
|
<version>4.0.1</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
@@ -24,13 +24,13 @@
|
|||||||
},
|
},
|
||||||
"architect": {
|
"architect": {
|
||||||
"build": {
|
"build": {
|
||||||
"builder": "@angular-devkit/build-angular:application",
|
"builder": "@angular/build:application",
|
||||||
"options": {
|
"options": {
|
||||||
"outputPath": "dist/codiki",
|
"outputPath": "dist/codiki",
|
||||||
"index": "src/index.html",
|
"index": "src/index.html",
|
||||||
"browser": "src/main.ts",
|
"browser": "src/main.ts",
|
||||||
"polyfills": [
|
"polyfills": [
|
||||||
"zone.js"
|
"@angular/localize/init"
|
||||||
],
|
],
|
||||||
"tsConfig": "tsconfig.app.json",
|
"tsConfig": "tsconfig.app.json",
|
||||||
"inlineStyleLanguage": "scss",
|
"inlineStyleLanguage": "scss",
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
"defaultConfiguration": ""
|
"defaultConfiguration": ""
|
||||||
},
|
},
|
||||||
"serve": {
|
"serve": {
|
||||||
"builder": "@angular-devkit/build-angular:dev-server",
|
"builder": "@angular/build:dev-server",
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production-en": {
|
"production-en": {
|
||||||
"buildTarget": "codiki:build:production-en"
|
"buildTarget": "codiki:build:production-en"
|
||||||
@@ -123,17 +123,15 @@
|
|||||||
"defaultConfiguration": "development"
|
"defaultConfiguration": "development"
|
||||||
},
|
},
|
||||||
"extract-i18n": {
|
"extract-i18n": {
|
||||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
"builder": "@angular/build:extract-i18n",
|
||||||
"options": {
|
"options": {
|
||||||
"buildTarget": "codiki:build"
|
"buildTarget": "codiki:build"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test": {
|
"test": {
|
||||||
"builder": "@angular-devkit/build-angular:karma",
|
"builder": "@angular/build:karma",
|
||||||
"options": {
|
"options": {
|
||||||
"polyfills": [
|
"polyfills": [
|
||||||
"zone.js",
|
|
||||||
"zone.js/testing"
|
|
||||||
],
|
],
|
||||||
"tsConfig": "tsconfig.spec.json",
|
"tsConfig": "tsconfig.spec.json",
|
||||||
"inlineStyleLanguage": "scss",
|
"inlineStyleLanguage": "scss",
|
||||||
@@ -153,5 +151,31 @@
|
|||||||
},
|
},
|
||||||
"cli": {
|
"cli": {
|
||||||
"analytics": false
|
"analytics": false
|
||||||
|
},
|
||||||
|
"schematics": {
|
||||||
|
"@schematics/angular:component": {
|
||||||
|
"type": "component"
|
||||||
|
},
|
||||||
|
"@schematics/angular:directive": {
|
||||||
|
"type": "directive"
|
||||||
|
},
|
||||||
|
"@schematics/angular:service": {
|
||||||
|
"type": "service"
|
||||||
|
},
|
||||||
|
"@schematics/angular:guard": {
|
||||||
|
"typeSeparator": "."
|
||||||
|
},
|
||||||
|
"@schematics/angular:interceptor": {
|
||||||
|
"typeSeparator": "."
|
||||||
|
},
|
||||||
|
"@schematics/angular:module": {
|
||||||
|
"typeSeparator": "."
|
||||||
|
},
|
||||||
|
"@schematics/angular:pipe": {
|
||||||
|
"typeSeparator": "."
|
||||||
|
},
|
||||||
|
"@schematics/angular:resolver": {
|
||||||
|
"typeSeparator": "."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ http {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location ~ ^/api {
|
location ~ ^/api {
|
||||||
proxy_pass http://192.168.0.153:50011;
|
proxy_pass http://192.168.1.153:50011;
|
||||||
proxy_set_header Host $host:$server_port;
|
proxy_set_header Host $host:$server_port;
|
||||||
proxy_set_header X-Forwarded-Host $server_name;
|
proxy_set_header X-Forwarded-Host $server_name;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|||||||
12983
frontend/package-lock.json
generated
12983
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -17,34 +17,26 @@
|
|||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "^18.2.5",
|
"@angular/animations": "^21.1.2",
|
||||||
"@angular/cdk": "^18.2.5",
|
"@angular/cdk": "^21.1.2",
|
||||||
"@angular/common": "^18.2.5",
|
"@angular/common": "^21.1.2",
|
||||||
"@angular/compiler": "^18.2.5",
|
"@angular/compiler": "^21.1.2",
|
||||||
"@angular/core": "^18.2.5",
|
"@angular/core": "^21.1.2",
|
||||||
"@angular/forms": "^18.2.5",
|
"@angular/forms": "^21.1.2",
|
||||||
"@angular/material": "^18.2.5",
|
"@angular/material": "^21.1.2",
|
||||||
"@angular/platform-browser": "^18.2.5",
|
"@angular/platform-browser": "^21.1.2",
|
||||||
"@angular/platform-browser-dynamic": "^18.2.5",
|
"@angular/platform-browser-dynamic": "^21.1.2",
|
||||||
"@angular/router": "^18.2.5",
|
"@angular/router": "^21.1.2",
|
||||||
"rxjs": "~7.8.0",
|
"rxjs": "~7.8.2",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.8.1"
|
||||||
"uuid": "^10.0.0",
|
|
||||||
"zone.js": "~0.14.10"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "^18.2.5",
|
"@angular/build": "^21.1.2",
|
||||||
"@angular/cli": "^18.2.5",
|
"@angular/cli": "^21.1.2",
|
||||||
"@angular/compiler-cli": "^18.2.5",
|
"@angular/compiler-cli": "^21.1.2",
|
||||||
"@angular/localize": "^18.2.5",
|
"@angular/localize": "^21.1.2",
|
||||||
"@types/jasmine": "~5.1.0",
|
"@types/jasmine": "~5.1.15",
|
||||||
"@types/uuid": "^10.0.0",
|
"jasmine-core": "~5.13.0",
|
||||||
"jasmine-core": "~5.1.0",
|
"typescript": "~5.9.3"
|
||||||
"karma": "~6.4.0",
|
|
||||||
"karma-chrome-launcher": "~3.2.0",
|
|
||||||
"karma-coverage": "~2.2.0",
|
|
||||||
"karma-jasmine": "~5.1.0",
|
|
||||||
"karma-jasmine-html-reporter": "~2.1.0",
|
|
||||||
"typescript": "~5.5.4"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
|
||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {RouterOutlet} from '@angular/router';
|
import {RouterOutlet} from '@angular/router';
|
||||||
import {HeaderComponent} from './components/header/header.component';
|
import {HeaderComponent} from './components/header/header.component';
|
||||||
@@ -6,9 +5,7 @@ import { FooterComponent } from './components/footer/footer.component';
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
standalone: true,
|
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
|
||||||
RouterOutlet,
|
RouterOutlet,
|
||||||
HeaderComponent,
|
HeaderComponent,
|
||||||
FooterComponent
|
FooterComponent
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { ApplicationConfig } from '@angular/core';
|
import {ApplicationConfig, inject, provideAppInitializer} from '@angular/core';
|
||||||
import {provideRouter, withRouterConfig} from '@angular/router';
|
import {provideRouter, withRouterConfig} from '@angular/router';
|
||||||
|
|
||||||
import {HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
import {HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
||||||
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
|
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
|
||||||
import {routes} from './app.routes';
|
import {routes} from './app.routes';
|
||||||
import {JwtInterceptor} from './core/interceptor/jwt.interceptor';
|
import {JwtInterceptor} from './core/interceptor/jwt.interceptor';
|
||||||
import { CorrelationIdInterceptor } from './core/interceptor/correlation-id.interceptor';
|
import {AuthenticationService} from './core/service/authentication.service';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
@@ -19,6 +19,9 @@ export const appConfig: ApplicationConfig = {
|
|||||||
provideAnimationsAsync(),
|
provideAnimationsAsync(),
|
||||||
provideHttpClient(withInterceptorsFromDi()),
|
provideHttpClient(withInterceptorsFromDi()),
|
||||||
{provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},
|
{provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},
|
||||||
{ provide: HTTP_INTERCEPTORS, useClass: CorrelationIdInterceptor, multi: true },
|
provideAppInitializer(() => {
|
||||||
|
const initializerFn = ((authenticationService: AuthenticationService) => () => authenticationService.startAuthenticationCheckingProcess())(inject(AuthenticationService));
|
||||||
|
return initializerFn();
|
||||||
|
})
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import {Routes} from '@angular/router';
|
import {Routes} from '@angular/router';
|
||||||
|
import {alreadyAuthenticatedGuard} from './core/guard/already-authenticated.guard';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: 'login',
|
path: 'login',
|
||||||
loadComponent: () => import('./pages/login/login.component').then(module => module.LoginComponent)
|
loadComponent: () => import('./pages/login/login.component').then(module => module.LoginComponent),
|
||||||
|
canActivate: [alreadyAuthenticatedGuard]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'signin',
|
path: 'signin',
|
||||||
loadComponent: () => import('./pages/signin/signin.component').then(module => module.SigninComponent)
|
loadComponent: () => import('./pages/signin/signin.component').then(module => module.SigninComponent),
|
||||||
|
canActivate: [alreadyAuthenticatedGuard]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'disconnect',
|
path: 'disconnect',
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
<h2>{{ description }}</h2>
|
<h2>{{ description }}</h2>
|
||||||
<footer>
|
<footer>
|
||||||
<button type="button" class="secondary" (click)="closeDialog()" i18n>
|
<button type="button" class="cod-button secondary" (click)="closeDialog()" matRipple i18n>
|
||||||
No
|
No
|
||||||
</button>
|
</button>
|
||||||
<button type="button" (click)="closeAndValidate()" i18n>
|
<button type="button" class="cod-button" (click)="closeAndValidate()" matRipple i18n>
|
||||||
Yes
|
Yes
|
||||||
</button>
|
</button>
|
||||||
</footer>
|
</footer>
|
||||||
@@ -8,32 +8,5 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
button {
|
|
||||||
padding: .8em 1.2em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5b6ed8;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.secondary {
|
|
||||||
color: #3f51b5;
|
|
||||||
background-color: white;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #f2f4ff;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Component, inject, Input } from "@angular/core";
|
import {Component, inject} from "@angular/core";
|
||||||
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||||
|
|
||||||
export interface ConfirmationDialogData {
|
export interface ConfirmationDialogData {
|
||||||
@@ -8,10 +9,9 @@ export interface ConfirmationDialogData {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-confirmation-dialog',
|
selector: 'app-confirmation-dialog',
|
||||||
standalone: true,
|
|
||||||
templateUrl: './confirmation-dialog.component.html',
|
templateUrl: './confirmation-dialog.component.html',
|
||||||
styleUrl: './confirmation-dialog.component.scss',
|
styleUrl: './confirmation-dialog.component.scss',
|
||||||
imports: []
|
imports: [MatRippleModule]
|
||||||
})
|
})
|
||||||
export class ConfirmationDialog {
|
export class ConfirmationDialog {
|
||||||
private readonly dialogRef = inject(MatDialogRef<ConfirmationDialog>);
|
private readonly dialogRef = inject(MatDialogRef<ConfirmationDialog>);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<div i18n>
|
<div i18n>
|
||||||
<span class="copy-left">©</span>
|
<span class="copy-left">©</span>
|
||||||
2016 - 2024 All rights reserved
|
2016 - 2026 All rights reserved
|
||||||
-
|
-
|
||||||
2.0-alpha
|
2.2
|
||||||
<a [routerLink]="['./']" matTooltip="Health checking will be available in future..." i18n-matTooltip>
|
<a [routerLink]="['./']" matTooltip="Health checking will be available in future..." i18n-matTooltip>
|
||||||
<mat-icon>favorite</mat-icon>
|
<mat-icon>favorite</mat-icon>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -12,10 +12,12 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
gap: .2em;
|
||||||
|
|
||||||
.copy-left {
|
.copy-left {
|
||||||
transform: rotate(180deg);
|
transform: rotate(180deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: rgba(255, 255, 255, .6);
|
color: rgba(255, 255, 255, .6);
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ import { RouterModule } from '@angular/router';
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-footer',
|
selector: 'app-footer',
|
||||||
standalone: true,
|
|
||||||
imports: [MatIconModule, MatTooltipModule, RouterModule],
|
imports: [MatIconModule, MatTooltipModule, RouterModule],
|
||||||
templateUrl: './footer.component.html',
|
templateUrl: './footer.component.html',
|
||||||
styleUrl: './footer.component.scss'
|
styleUrl: './footer.component.scss'
|
||||||
})
|
})
|
||||||
export class FooterComponent {
|
export class FooterComponent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
<div class="left">
|
<div class="left">
|
||||||
<button type="button" (click)="sideMenu.open()" matTooltip="Click to show side menu" i18n-matTooltip>
|
<button type="button"
|
||||||
|
(click)="sideMenu.open()"
|
||||||
|
class="cod-button icon"
|
||||||
|
matTooltip="Click to show side menu"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
<mat-icon>menu</mat-icon>
|
<mat-icon>menu</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<a [routerLink]="['/home']">
|
<a [routerLink]="['/home']">
|
||||||
@@ -14,7 +19,10 @@
|
|||||||
|
|
||||||
<div class="right">
|
<div class="right">
|
||||||
@if (isAuthenticated) {
|
@if (isAuthenticated) {
|
||||||
<button mat-button class="button" [matMenuTriggerFor]="authenticatedUserMenu">
|
<button type="button"
|
||||||
|
class="cod-button icon"
|
||||||
|
[matMenuTriggerFor]="authenticatedUserMenu"
|
||||||
|
matRipple>
|
||||||
<mat-icon>more_vert</mat-icon>
|
<mat-icon>more_vert</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<mat-menu #authenticatedUserMenu="matMenu">
|
<mat-menu #authenticatedUserMenu="matMenu">
|
||||||
@@ -30,7 +38,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</mat-menu>
|
</mat-menu>
|
||||||
} @else {
|
} @else {
|
||||||
<a [routerLink]="['/login']" class="button" matRipple i18n>Login</a>
|
<a [routerLink]="['/login']" class="cod-button" matRipple i18n>Login</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<app-side-menu #sideMenu></app-side-menu>
|
<app-side-menu #sideMenu></app-side-menu>
|
||||||
@@ -26,25 +26,6 @@ $headerHeight: 3.5em;
|
|||||||
padding: 0 1em;
|
padding: 0 1em;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
|
|
||||||
button {
|
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
border-radius: 10em;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
$buttonSize: 2.5em;
|
|
||||||
width: $buttonSize;
|
|
||||||
height: $buttonSize;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: #5c6bc0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
a {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@@ -120,45 +101,10 @@ $headerHeight: 3.5em;
|
|||||||
top: 0;
|
top: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
|
margin-right: .5em;
|
||||||
|
|
||||||
a {
|
a, button {
|
||||||
display: flex;
|
margin: .5em;
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-width: 5em;
|
|
||||||
color: white;
|
|
||||||
margin: 0.5em 0.5em;
|
|
||||||
border-radius: 10em;
|
|
||||||
text-decoration: none;
|
|
||||||
padding: 0 .8em;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5c6bc0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-width: 2.5em;
|
|
||||||
color: white;
|
|
||||||
margin: 0.5em 0.5em;
|
|
||||||
border-radius: 10em;
|
|
||||||
text-decoration: none;
|
|
||||||
padding: 0;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5c6bc0;
|
|
||||||
}
|
|
||||||
|
|
||||||
mat-icon {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
|
||||||
import {Component, inject} from '@angular/core';
|
import {Component, inject} from '@angular/core';
|
||||||
import {FormControl, ReactiveFormsModule} from '@angular/forms';
|
import {FormControl, ReactiveFormsModule} from '@angular/forms';
|
||||||
import {MatButtonModule} from '@angular/material/button';
|
import {MatButtonModule} from '@angular/material/button';
|
||||||
@@ -13,9 +12,7 @@ import { SideMenuComponent } from '../side-menu/side-menu.component';
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-header',
|
selector: 'app-header',
|
||||||
standalone: true,
|
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatMenuModule,
|
MatMenuModule,
|
||||||
@@ -24,10 +21,10 @@ import { SideMenuComponent } from '../side-menu/side-menu.component';
|
|||||||
PublicationsSearchBarComponent,
|
PublicationsSearchBarComponent,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
RouterModule,
|
RouterModule,
|
||||||
SideMenuComponent,
|
SideMenuComponent
|
||||||
],
|
],
|
||||||
templateUrl: './header.component.html',
|
templateUrl: './header.component.html',
|
||||||
styleUrl: './header.component.scss',
|
styleUrl: './header.component.scss'
|
||||||
})
|
})
|
||||||
export class HeaderComponent {
|
export class HeaderComponent {
|
||||||
private authenticationService = inject(AuthenticationService);
|
private authenticationService = inject(AuthenticationService);
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
<button type="button" class="close" (click)="closeDialog()">
|
<button type="button"
|
||||||
|
(click)="closeDialog()"
|
||||||
|
class="cod-button icon secondary close"
|
||||||
|
matTooltip="Close"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
<mat-icon>close</mat-icon>
|
<mat-icon>close</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<header>
|
<header>
|
||||||
<h1 i18n>Add a code block</h1>
|
<h1 i18n>Add a code block</h1>
|
||||||
</header>
|
</header>
|
||||||
<form [formGroup]="formGroup" (submit)="closeAndValidate()" ngNativeValidate>
|
<form [formGroup]="formGroup" (submit)="closeAndValidate()" class="cod-form" ngNativeValidate>
|
||||||
<div class="form-content">
|
<div class="form-content">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label i18n>Programming language</mat-label>
|
<mat-label i18n>Programming language</mat-label>
|
||||||
@@ -21,11 +26,11 @@
|
|||||||
<textarea matInput formControlName="codeBlock"></textarea>
|
<textarea matInput formControlName="codeBlock"></textarea>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions reversed">
|
||||||
<button type="submit" i18n>
|
<button type="submit" class="cod-button" matRipple i18n>
|
||||||
Validate
|
Validate
|
||||||
</button>
|
</button>
|
||||||
<button type="button" (click)="closeDialog()" class="secondary" i18n>
|
<button type="button" (click)="closeDialog()" class="cod-button secondary" matRipple i18n>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,20 +6,6 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
max-height: 90vh;
|
max-height: 90vh;
|
||||||
|
|
||||||
.close {
|
|
||||||
position: absolute;
|
|
||||||
top: 1em;
|
|
||||||
right: 1em;
|
|
||||||
width: 2.5em;
|
|
||||||
height: 2.5em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
header {
|
header {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -39,40 +25,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.actions {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row-reverse;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
button {
|
|
||||||
padding: .8em 1.2em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5b6ed8;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.secondary {
|
|
||||||
color: #3f51b5;
|
|
||||||
background-color: white;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #f2f4ff;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import {Component, inject} from "@angular/core";
|
import {Component, inject} from "@angular/core";
|
||||||
import {FormBuilder, FormControl, ReactiveFormsModule, Validators} from "@angular/forms";
|
import {FormBuilder, FormControl, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||||
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import {MatDialogRef} from "@angular/material/dialog";
|
import {MatDialogRef} from "@angular/material/dialog";
|
||||||
import {MatFormFieldModule} from "@angular/material/form-field";
|
import {MatFormFieldModule} from "@angular/material/form-field";
|
||||||
import {MatIcon} from "@angular/material/icon";
|
import {MatIcon} from "@angular/material/icon";
|
||||||
import {MatInputModule} from "@angular/material/input";
|
import {MatInputModule} from "@angular/material/input";
|
||||||
import {MatSelectModule} from '@angular/material/select';
|
import {MatSelectModule} from '@angular/material/select';
|
||||||
|
import {MatTooltip} from "@angular/material/tooltip";
|
||||||
|
|
||||||
export interface ProgramingLanguage {
|
export interface ProgramingLanguage {
|
||||||
code: string;
|
code: string;
|
||||||
@@ -84,14 +86,15 @@ export const PROGRAMMING_LANGUAGES: ProgramingLanguage[] = [
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-code-block-dialog',
|
selector: 'app-code-block-dialog',
|
||||||
standalone: true,
|
|
||||||
templateUrl: './code-block-dialog.component.html',
|
templateUrl: './code-block-dialog.component.html',
|
||||||
styleUrl: './code-block-dialog.component.scss',
|
styleUrl: './code-block-dialog.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
MatFormFieldModule,
|
MatFormFieldModule,
|
||||||
MatIcon,
|
MatIcon,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
|
MatRippleModule,
|
||||||
MatSelectModule,
|
MatSelectModule,
|
||||||
|
MatTooltip,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,17 +1,23 @@
|
|||||||
<button type="button" class="close" (click)="closeDialog()">
|
<button type="button"
|
||||||
|
(click)="closeDialog()"
|
||||||
|
class="cod-button icon secondary close"
|
||||||
|
matTooltip="Close"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
<mat-icon>close</mat-icon>
|
<mat-icon>close</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<header>
|
<header>
|
||||||
<h1 i18n>Select an illustration</h1>
|
<h1 i18n>Select an illustration</h1>
|
||||||
</header>
|
</header>
|
||||||
<div class="picture-container">
|
<div class="picture-container">
|
||||||
@if (isLoading) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Pictures loading...</h2>
|
<h2 i18n>Pictures loading...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner></mat-spinner>
|
||||||
} @else {
|
} @else {
|
||||||
@if (pictures.length) {
|
@if (pictures.length) {
|
||||||
@for (picture of pictures; track picture) {
|
@for (picture of pictures; track picture) {
|
||||||
<img src="/api/pictures/{{picture.id}}" (click)="selectPicture(picture)" matTooltip="Choose this illustration" i18n-matTooltip/>
|
<img src="/api/pictures/{{picture.id}}" (click)="selectPicture(picture)" matTooltip="Choose this illustration"
|
||||||
|
i18n-matTooltip/>
|
||||||
}
|
}
|
||||||
} @else {
|
} @else {
|
||||||
<h2 i18n>There is no any picture.</h2>
|
<h2 i18n>There is no any picture.</h2>
|
||||||
@@ -19,10 +25,18 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<button type="button" class="secondary" matRipple (click)="closeDialog()" i18n>
|
<button type="button"
|
||||||
|
(click)="closeDialog()"
|
||||||
|
class="cod-button secondary"
|
||||||
|
matRipple
|
||||||
|
i18n>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button type="button" (click)="fileUpload.click()" matRipple i18n>
|
<button type="button"
|
||||||
|
(click)="fileUpload.click()"
|
||||||
|
class="cod-button"
|
||||||
|
matRipple
|
||||||
|
i18n>
|
||||||
<mat-icon>upload_file</mat-icon>
|
<mat-icon>upload_file</mat-icon>
|
||||||
Add new picture
|
Add new picture
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -6,20 +6,6 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
max-height: 90vh;
|
max-height: 90vh;
|
||||||
|
|
||||||
.close {
|
|
||||||
position: absolute;
|
|
||||||
top: 1em;
|
|
||||||
right: 1em;
|
|
||||||
width: 2.5em;
|
|
||||||
height: 2.5em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
header {
|
header {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, inject, OnInit } from "@angular/core";
|
import {Component, inject, OnInit, signal} from "@angular/core";
|
||||||
import {Picture} from "../../../core/rest-services/picture/model/picture";
|
import {Picture} from "../../../core/rest-services/picture/model/picture";
|
||||||
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
@@ -10,22 +10,26 @@ import { MatTooltip } from "@angular/material/tooltip";
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-picture-selection',
|
selector: 'app-picture-selection',
|
||||||
standalone: true,
|
|
||||||
imports: [MatProgressSpinnerModule, MatIcon, MatRippleModule, MatTooltip],
|
|
||||||
templateUrl: './picture-selection-dialog.component.html',
|
templateUrl: './picture-selection-dialog.component.html',
|
||||||
styleUrl: './picture-selection-dialog.component.scss',
|
styleUrl: './picture-selection-dialog.component.scss',
|
||||||
|
imports: [
|
||||||
|
MatIcon,
|
||||||
|
MatRippleModule,
|
||||||
|
MatProgressSpinnerModule,
|
||||||
|
MatTooltip
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class PictureSelectionDialog implements OnInit {
|
export class PictureSelectionDialog implements OnInit {
|
||||||
private readonly pictureRestService = inject(PictureRestService);
|
private readonly pictureRestService = inject(PictureRestService);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
private readonly snackBar = inject(MatSnackBar);
|
||||||
private readonly dialogRef = inject(MatDialogRef<PictureSelectionDialog>);
|
private readonly dialogRef = inject(MatDialogRef<PictureSelectionDialog>);
|
||||||
|
|
||||||
isLoading: boolean = false;
|
isLoading = signal(false);
|
||||||
isLoaded: boolean = false;
|
isLoaded = signal(false);
|
||||||
pictures: Picture[] = [];
|
pictures: Picture[] = [];
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.isLoading = true;
|
this.isLoading.set(true);
|
||||||
this.pictureRestService.getAllOfCurrentUser()
|
this.pictureRestService.getAllOfCurrentUser()
|
||||||
.then(pictures => {
|
.then(pictures => {
|
||||||
this.pictures = pictures;
|
this.pictures = pictures;
|
||||||
@@ -34,14 +38,14 @@ export class PictureSelectionDialog implements OnInit {
|
|||||||
if (error.status === 401) {
|
if (error.status === 401) {
|
||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
} else {
|
} else {
|
||||||
const errorMessage = $localize`An error occured while loading pictures.`;
|
const errorMessage = $localize`An error occurred while loading pictures.`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isLoading = false;
|
this.isLoading.set(false);
|
||||||
this.isLoaded = true;
|
this.isLoaded.set(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +65,7 @@ export class PictureSelectionDialog implements OnInit {
|
|||||||
this.dialogRef.close(pictureId);
|
this.dialogRef.close(pictureId);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`A technical error occured while uploading your picture.`;
|
const errorMessage = $localize`A technical error occurred while uploading your picture.`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<form [formGroup]="publicationEditionForm" (submit)="save()" ngNativeValidate>
|
<form [formGroup]="publicationEditionForm" (submit)="save()" ngNativeValidate>
|
||||||
<header>
|
<header>
|
||||||
<h1>{{title}}</h1>
|
<h1>{{ title() }}</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<mat-tab-group dynamicHeight (selectedIndexChange)="onTabChange($event)">
|
<mat-tab-group dynamicHeight (selectedIndexChange)="onTabChange($event)">
|
||||||
@@ -29,7 +29,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="picture-container">
|
<div class="picture-container">
|
||||||
<img [src]="publication.illustrationId.length ? '/api/pictures/' + publication.illustrationId : '/assets/images/default-picture.png'"
|
<img
|
||||||
|
[src]="publication().illustrationId.length ? '/api/pictures/' + publication().illustrationId : '/assets/images/default-picture.png'"
|
||||||
(click)="displayPictureSectionDialog()"
|
(click)="displayPictureSectionDialog()"
|
||||||
matTooltip="Click to change illustration"
|
matTooltip="Click to change illustration"
|
||||||
i18n-matTooltip/>
|
i18n-matTooltip/>
|
||||||
@@ -37,25 +38,53 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<button type="button" matTooltip="Click to insert a title 1 section" (click)="insertTitle(1)" i18n-matTooltip>
|
<button type="button"
|
||||||
|
(click)="insertTitle(1)"
|
||||||
|
matTooltip="Click to insert a title 1 section"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
H1
|
H1
|
||||||
</button>
|
</button>
|
||||||
<button type="button" matTooltip="Click to insert a title 2 section" (click)="insertTitle(2)" i18n-matTooltip>
|
<button type="button"
|
||||||
|
(click)="insertTitle(2)"
|
||||||
|
matTooltip="Click to insert a title 2 section"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
H2
|
H2
|
||||||
</button>
|
</button>
|
||||||
<button type="button" matTooltip="Click to insert a title 3 section" (click)="insertTitle(3)" i18n-matTooltip>
|
<button type="button"
|
||||||
|
(click)="insertTitle(3)"
|
||||||
|
matTooltip="Click to insert a title 3 section"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
H3
|
H3
|
||||||
</button>
|
</button>
|
||||||
<button type="button" matTooltip="Click to insert a picture" (click)="selectAPicture()" i18n-matTooltip>
|
<button type="button"
|
||||||
<mat-icon>image</mat-icon>
|
(click)="insertLink()"
|
||||||
</button>
|
matTooltip="Click to insert a link"
|
||||||
<button type="button" matTooltip="Click to insert a link" (click)="insertLink()" i18n-matTooltip>
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
<mat-icon>link</mat-icon>
|
<mat-icon>link</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<button type="button" matTooltip="Click to insert a code block" (click)="displayCodeBlockDialog()" i18n-matTooltip>
|
<button type="button"
|
||||||
|
(click)="selectAPicture()"
|
||||||
|
matTooltip="Click to insert a picture"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
|
<mat-icon>image</mat-icon>
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
(click)="displayCodeBlockDialog()"
|
||||||
|
matTooltip="Click to insert a code block"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
<mat-icon>code</mat-icon>
|
<mat-icon>code</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<button type="button" disabled matTooltip="Click to display editor help" i18n-matTooltip>
|
<button type="button"
|
||||||
|
matTooltip="Click to display editor help"
|
||||||
|
disabled
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
<mat-icon>help</mat-icon>
|
<mat-icon>help</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -75,25 +104,29 @@
|
|||||||
|
|
||||||
<mat-tab label="Previewing" i18n-label>
|
<mat-tab label="Previewing" i18n-label>
|
||||||
<div class="preview">
|
<div class="preview">
|
||||||
@if ((isPreviewing$ | async) === true) {
|
@if (isPreviewing()) {
|
||||||
<div class="preview-loading">
|
<div class="preview-loading">
|
||||||
<h2 i18n>Preview is loading...</h2>
|
<h2 i18n>Preview is loading...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner></mat-spinner>
|
||||||
</div>
|
</div>
|
||||||
} @else {
|
} @else {
|
||||||
<img class="illustration" src="/api/pictures/{{ publication.illustrationId }}" />
|
<img class="illustration" src="/api/pictures/{{ publication().illustrationId }}"/>
|
||||||
<header>
|
<header>
|
||||||
<h1>{{ publication.title }}</h1>
|
<h1>{{ publication().title }}</h1>
|
||||||
<h2>{{ publication.description }}</h2>
|
<h2>{{ publication().description }}</h2>
|
||||||
</header>
|
</header>
|
||||||
<main [innerHTML]="publicationInEdition.parsedText"></main>
|
<main [innerHTML]="publicationInEdition().parsedText"></main>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</mat-tab>
|
</mat-tab>
|
||||||
</mat-tab-group>
|
</mat-tab-group>
|
||||||
<footer>
|
<footer>
|
||||||
<app-submit-button label="Save" [requestPending]="!!(isSaving$ | async)" i18n-label></app-submit-button>
|
<app-submit-button [requestPending]="isSaving()" i18n>Save</app-submit-button>
|
||||||
<button type="button" class="secondary" (click)="goPreviousLocation()" i18n>
|
<button type="button"
|
||||||
|
class="cod-button secondary"
|
||||||
|
(click)="goPreviousLocation()"
|
||||||
|
matRipple
|
||||||
|
i18n>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
@@ -102,6 +102,11 @@
|
|||||||
|
|
||||||
button {
|
button {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
border-radius: 10em;
|
||||||
|
border: none;
|
||||||
|
background-color: #3f51b5;
|
||||||
|
color: white;
|
||||||
|
transition: background-color .2s ease-in-out;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -109,17 +114,6 @@
|
|||||||
height: 3em;
|
height: 3em;
|
||||||
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button, a.button {
|
|
||||||
padding: .8em 1.2em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #5b6ed8;
|
background-color: #5b6ed8;
|
||||||
@@ -130,14 +124,6 @@ button, a.button {
|
|||||||
background-color: #5f6aa6;
|
background-color: #5f6aa6;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.secondary {
|
|
||||||
color: #3f51b5;
|
|
||||||
background-color: white;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #f2f4ff;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {CommonModule, Location} from "@angular/common";
|
import {CommonModule, Location} from "@angular/common";
|
||||||
import { Component, EventEmitter, inject, Input, OnChanges, OnDestroy, Output } from "@angular/core";
|
import {Component, effect, inject, input, output, signal} from "@angular/core";
|
||||||
import { FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators } from "@angular/forms";
|
import {FormGroup, ReactiveFormsModule} from "@angular/forms";
|
||||||
import {MatDialogModule} from "@angular/material/dialog";
|
import {MatDialogModule} from "@angular/material/dialog";
|
||||||
import {MatIconModule} from "@angular/material/icon";
|
import {MatIconModule} from "@angular/material/icon";
|
||||||
import {MatInputModule} from "@angular/material/input";
|
import {MatInputModule} from "@angular/material/input";
|
||||||
@@ -8,17 +8,16 @@ import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
|
|||||||
import {MatSelectModule} from "@angular/material/select";
|
import {MatSelectModule} from "@angular/material/select";
|
||||||
import {MatTabsModule} from "@angular/material/tabs";
|
import {MatTabsModule} from "@angular/material/tabs";
|
||||||
import {MatTooltipModule} from "@angular/material/tooltip";
|
import {MatTooltipModule} from "@angular/material/tooltip";
|
||||||
import { map, Observable, of, Subscription } from "rxjs";
|
import {map, Observable} from "rxjs";
|
||||||
import {Category} from "../../core/rest-services/category/model/category";
|
import {Category} from "../../core/rest-services/category/model/category";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {DEFAULT_PUBLICATION, Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import {CategoryService} from "../../core/service/category.service";
|
import {CategoryService} from "../../core/service/category.service";
|
||||||
import {SubmitButtonComponent} from "../submit-button/submit-button.component";
|
import {SubmitButtonComponent} from "../submit-button/submit-button.component";
|
||||||
import { PictureSelectionDialog } from "./picture-selection-dialog/picture-selection-dialog.component";
|
|
||||||
import {PublicationEditionService} from "./publication-edition.service";
|
import {PublicationEditionService} from "./publication-edition.service";
|
||||||
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication-edition',
|
selector: 'app-publication-edition',
|
||||||
standalone: true,
|
|
||||||
templateUrl: './publication-edition.component.html',
|
templateUrl: './publication-edition.component.html',
|
||||||
styleUrl: './publication-edition.component.scss',
|
styleUrl: './publication-edition.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
@@ -26,51 +25,47 @@ import { PublicationEditionService } from "./publication-edition.service";
|
|||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
|
MatRippleModule,
|
||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
MatSelectModule,
|
MatSelectModule,
|
||||||
MatTabsModule,
|
MatTabsModule,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
PictureSelectionDialog,
|
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
SubmitButtonComponent
|
SubmitButtonComponent
|
||||||
],
|
],
|
||||||
providers: [PublicationEditionService]
|
providers: [PublicationEditionService]
|
||||||
})
|
})
|
||||||
export class PublicationEditionComponent implements OnChanges, OnDestroy {
|
export class PublicationEditionComponent {
|
||||||
@Input()
|
readonly #categoryService = inject(CategoryService);
|
||||||
publication!: Publication;
|
readonly #location = inject(Location);
|
||||||
@Input()
|
readonly #publicationEditionService = inject(PublicationEditionService);
|
||||||
title!: string;
|
|
||||||
@Input()
|
|
||||||
isSaving$: Observable<boolean> = of(false);
|
|
||||||
@Output()
|
|
||||||
publicationSave = new EventEmitter<Publication>();
|
|
||||||
|
|
||||||
publicationInEdition!: Publication;
|
publication = input.required<Publication>();
|
||||||
private readonly categoryService = inject(CategoryService);
|
title = input.required<string>();
|
||||||
private readonly formBuilder = inject(FormBuilder);
|
isSaving = input.required<boolean>();
|
||||||
private readonly location = inject(Location);
|
publicationSave = output<Publication>();
|
||||||
private readonly publicationEditionService = inject(PublicationEditionService);
|
|
||||||
private subscriptions: Subscription[] = [];
|
|
||||||
|
|
||||||
publicationEditionForm: FormGroup = this.formBuilder.group({
|
isLoading = this.#publicationEditionService.isLoading;
|
||||||
title: new FormControl<string | undefined>('', [Validators.required]),
|
isPreviewing = this.#publicationEditionService.isPreviewing;
|
||||||
description: new FormControl<string | undefined>('', [Validators.required]),
|
publicationInEdition = signal<Publication>(DEFAULT_PUBLICATION);
|
||||||
text: new FormControl<string | undefined>('', [Validators.required]),
|
|
||||||
illustrationId: new FormControl<string | undefined>('', [Validators.required]),
|
constructor() {
|
||||||
categoryId: new FormControl<string | undefined>('', [Validators.required])
|
effect(() => {
|
||||||
|
let publication = this.publication();
|
||||||
|
const publicationInEdition = this.publicationInEdition();
|
||||||
|
if (!publicationInEdition || publicationInEdition !== publication) {
|
||||||
|
this.publicationInEdition.set(publication);
|
||||||
|
this.#publicationEditionService.init(publication);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
|
||||||
return this.publicationEditionService.isLoading$;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get isPreviewing$(): Observable<boolean> {
|
get publicationEditionForm(): FormGroup {
|
||||||
return this.publicationEditionService.isPreviewing$;
|
return this.#publicationEditionService.publicationEditionForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
get categories$(): Observable<Category[]> {
|
get categories$(): Observable<Category[]> {
|
||||||
return this.categoryService.categories$
|
return this.#categoryService.categories$
|
||||||
.pipe(
|
.pipe(
|
||||||
map(categories =>
|
map(categories =>
|
||||||
categories.filter(category => category.subCategories.length == 0)
|
categories.filter(category => category.subCategories.length == 0)
|
||||||
@@ -93,83 +88,28 @@ export class PublicationEditionComponent implements OnChanges, OnDestroy {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(): void {
|
|
||||||
this.ngOnDestroy();
|
|
||||||
|
|
||||||
this.publicationInEdition = this.publication;
|
|
||||||
this.publicationEditionService.init(this.publicationInEdition);
|
|
||||||
|
|
||||||
['title', 'description', 'text'].forEach(fieldName => {
|
|
||||||
const fieldSubscription = this.publicationEditionForm.controls[fieldName].valueChanges
|
|
||||||
.pipe(
|
|
||||||
map(value => value?.length ? value as string : '')
|
|
||||||
)
|
|
||||||
.subscribe(fieldValue => {
|
|
||||||
switch (fieldName) {
|
|
||||||
case 'title':
|
|
||||||
this.publicationEditionService.editTitle(fieldValue);
|
|
||||||
break;
|
|
||||||
case 'description':
|
|
||||||
this.publicationEditionService.editDescription(fieldValue);
|
|
||||||
break;
|
|
||||||
case 'text':
|
|
||||||
this.publicationEditionService.editText(fieldValue);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.subscriptions.push(fieldSubscription);
|
|
||||||
});
|
|
||||||
|
|
||||||
const categoryIdChangeSubscription = this.publicationEditionForm.controls['categoryId'].valueChanges
|
|
||||||
.subscribe(newCategoryId => {
|
|
||||||
this.publicationEditionService.editCategoryId(newCategoryId);
|
|
||||||
});
|
|
||||||
this.subscriptions.push(categoryIdChangeSubscription);
|
|
||||||
|
|
||||||
const publicationSubscription = this.publicationEditionService.state$.subscribe(state => {
|
|
||||||
console.log(state.publication.parsedText.substring(0, 15));
|
|
||||||
this.publicationInEdition = state.publication;
|
|
||||||
this.publicationEditionForm.controls['title'].setValue(this.publicationInEdition.title, { emitEvent: false });
|
|
||||||
this.publicationEditionForm.controls['description'].setValue(this.publicationInEdition.description, { emitEvent: false });
|
|
||||||
this.publicationEditionForm.controls['text'].setValue(this.publicationInEdition.text, { emitEvent: false });
|
|
||||||
this.publicationEditionForm.controls['illustrationId'].setValue(this.publicationInEdition.illustrationId, { emitEvent: false });
|
|
||||||
this.publicationEditionForm.controls['categoryId'].setValue(this.publicationInEdition.categoryId, { emitEvent: false });
|
|
||||||
});
|
|
||||||
this.subscriptions.push(publicationSubscription);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
this.subscriptions.forEach(subscription => subscription?.unsubscribe());
|
|
||||||
}
|
|
||||||
|
|
||||||
goPreviousLocation(): void {
|
goPreviousLocation(): void {
|
||||||
this.location.back();
|
this.#location.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
insertTitle(titleNumber: number): void {
|
insertTitle(titleNumber: number): void {
|
||||||
this.publicationEditionService.insertTitle(titleNumber);
|
this.#publicationEditionService.insertTitle(titleNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectAPicture(): void {
|
selectAPicture(): void {
|
||||||
this.publicationEditionService.selectAPicture();
|
this.#publicationEditionService.selectAPicture();
|
||||||
}
|
}
|
||||||
|
|
||||||
insertLink(): void {
|
insertLink(): void {
|
||||||
this.publicationEditionService.insertLink();
|
this.#publicationEditionService.insertLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
displayCodeBlockDialog(): void {
|
displayCodeBlockDialog(): void {
|
||||||
this.publicationEditionService.displayCodeBlockDialog();
|
this.#publicationEditionService.displayCodeBlockDialog();
|
||||||
}
|
|
||||||
|
|
||||||
save(): void {
|
|
||||||
this.publicationSave.emit(this.publicationInEdition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
displayPictureSectionDialog(): void {
|
displayPictureSectionDialog(): void {
|
||||||
this.publicationEditionService.displayPictureSectionDialog();
|
this.#publicationEditionService.displayPictureSectionDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCursorPosition(event: KeyboardEvent | MouseEvent): void {
|
updateCursorPosition(event: KeyboardEvent | MouseEvent): void {
|
||||||
@@ -179,13 +119,17 @@ export class PublicationEditionComponent implements OnChanges, OnDestroy {
|
|||||||
const positionStart = textarea.selectionStart;
|
const positionStart = textarea.selectionStart;
|
||||||
const positionEnd = textarea.selectionEnd;
|
const positionEnd = textarea.selectionEnd;
|
||||||
|
|
||||||
this.publicationEditionService.editCursorPosition(positionStart, positionEnd);
|
this.#publicationEditionService.editCursorPosition(positionStart, positionEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
save(): void {
|
||||||
|
this.publicationSave.emit(this.#publicationEditionService.editedPublication);
|
||||||
|
}
|
||||||
|
|
||||||
onTabChange(tabSelectedIndex: number): void {
|
onTabChange(tabSelectedIndex: number): void {
|
||||||
if (tabSelectedIndex === 1) {
|
if (tabSelectedIndex === 1) {
|
||||||
this.publicationEditionService.loadPreview();
|
this.#publicationEditionService.loadPreview();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
import {Location} from "@angular/common";
|
import {Location} from "@angular/common";
|
||||||
import { inject, Injectable, OnDestroy } from "@angular/core";
|
import {inject, Injectable, OnDestroy, Signal, signal} from "@angular/core";
|
||||||
import {MatDialog} from "@angular/material/dialog";
|
import {MatDialog} from "@angular/material/dialog";
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import {ActivatedRoute} from "@angular/router";
|
import {ActivatedRoute} from "@angular/router";
|
||||||
import { BehaviorSubject, Observable, Subscription } from "rxjs";
|
import {debounceTime, distinctUntilChanged, Subscription} from "rxjs";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {DEFAULT_PUBLICATION, Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import {copy} from "../../core/utils/ObjectUtils";
|
import {copy} from "../../core/utils/ObjectUtils";
|
||||||
import {CodeBlockDialog} from "./code-block-dialog/code-block-dialog.component";
|
import {CodeBlockDialog} from "./code-block-dialog/code-block-dialog.component";
|
||||||
import {PictureSelectionDialog} from "./picture-selection-dialog/picture-selection-dialog.component";
|
import {PictureSelectionDialog} from "./picture-selection-dialog/picture-selection-dialog.component";
|
||||||
import {PreviewContentRequest} from "../../core/rest-services/publications/model/preview";
|
import {PreviewContentRequest} from "../../core/rest-services/publications/model/preview";
|
||||||
|
import {FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
|
||||||
|
|
||||||
declare let Prism: any;
|
declare let Prism: any;
|
||||||
|
|
||||||
@@ -30,23 +31,6 @@ export interface PublicationEditionState {
|
|||||||
cursorPosition: CursorPosition;
|
cursorPosition: CursorPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_PUBLICATION: Publication = {
|
|
||||||
id: '',
|
|
||||||
key: '',
|
|
||||||
title: '',
|
|
||||||
text: '',
|
|
||||||
parsedText: '',
|
|
||||||
description: '',
|
|
||||||
creationDate: new Date(),
|
|
||||||
illustrationId: '',
|
|
||||||
categoryId: '',
|
|
||||||
author: {
|
|
||||||
id: '',
|
|
||||||
name: '',
|
|
||||||
image: ''
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const DEFAULT_CURSOR_POSITION = new CursorPosition(0, 0);
|
const DEFAULT_CURSOR_POSITION = new CursorPosition(0, 0);
|
||||||
|
|
||||||
const DEFAULT_STATE: PublicationEditionState = {
|
const DEFAULT_STATE: PublicationEditionState = {
|
||||||
@@ -56,109 +40,120 @@ const DEFAULT_STATE: PublicationEditionState = {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PublicationEditionService implements OnDestroy {
|
export class PublicationEditionService implements OnDestroy {
|
||||||
private readonly activatedRoute = inject(ActivatedRoute);
|
readonly #activatedRoute = inject(ActivatedRoute);
|
||||||
private readonly publicationRestService = inject(PublicationRestService);
|
readonly #dialog = inject(MatDialog);
|
||||||
private readonly location = inject(Location);
|
readonly #formBuilder = inject(FormBuilder);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
readonly #location = inject(Location);
|
||||||
private readonly dialog = inject(MatDialog);
|
readonly #publicationRestService = inject(PublicationRestService);
|
||||||
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
|
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private stateSubject = new BehaviorSubject<PublicationEditionState>(copy(DEFAULT_STATE));
|
#state = signal<PublicationEditionState>(copy(DEFAULT_STATE));
|
||||||
private subscriptions: Subscription[] = [];
|
#isSaving = signal<boolean>(false);
|
||||||
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
#isPreviewing = signal<boolean>(false);
|
||||||
private isPreviewingSubject = new BehaviorSubject<boolean>(false);
|
#subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
|
publicationEditionForm: FormGroup = this.#formBuilder.group({
|
||||||
|
title: new FormControl<string | undefined>('', [Validators.required]),
|
||||||
|
description: new FormControl<string | undefined>('', [Validators.required]),
|
||||||
|
text: new FormControl<string | undefined>('', [Validators.required]),
|
||||||
|
illustrationId: new FormControl<string | undefined>('', [Validators.required]),
|
||||||
|
categoryId: new FormControl<string | undefined>('', [Validators.required])
|
||||||
|
});
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.subscriptions.forEach(subscription => subscription.unsubscribe());
|
this.#subscriptions.forEach(subscription => subscription.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _state(): PublicationEditionState {
|
#updateForm(): void {
|
||||||
return this.stateSubject.value;
|
const state = this.#state();
|
||||||
|
const publication = state.publication;
|
||||||
|
|
||||||
|
this.publicationEditionForm.controls['title'].setValue(publication.title);
|
||||||
|
this.publicationEditionForm.controls['description'].setValue(publication.description);
|
||||||
|
this.publicationEditionForm.controls['text'].setValue(publication.text);
|
||||||
|
this.publicationEditionForm.controls['illustrationId'].setValue(publication.illustrationId);
|
||||||
|
this.publicationEditionForm.controls['categoryId'].setValue(publication.categoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _save(state: PublicationEditionState): void {
|
get isLoading(): Signal<boolean> {
|
||||||
this.stateSubject.next(state);
|
return this.#isLoading.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
get isSaving(): Signal<boolean> {
|
||||||
return this.isLoadingSubject.asObservable();
|
return this.#isSaving.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isSaving$(): Observable<boolean> {
|
get isPreviewing(): Signal<boolean> {
|
||||||
return this.isSavingSubject.asObservable();
|
return this.#isPreviewing.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isPreviewing$(): Observable<boolean> {
|
get state(): Signal<PublicationEditionState> {
|
||||||
return this.isPreviewingSubject.asObservable();
|
return this.#state.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get state$(): Observable<PublicationEditionState> {
|
get editedPublication(): Publication {
|
||||||
return this.stateSubject.asObservable();
|
return this.#state().publication;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPublication(): void {
|
loadPublication(): void {
|
||||||
this.isLoadingSubject.next(true);
|
this.#isLoading.set(true);
|
||||||
|
|
||||||
this.activatedRoute.paramMap.subscribe(params => {
|
this.#activatedRoute.paramMap.subscribe(params => {
|
||||||
const publicationId = params.get('publicationId');
|
const publicationId = params.get('publicationId');
|
||||||
if (publicationId == undefined) {
|
if (publicationId == undefined) {
|
||||||
this.snackBar.open($localize`A technical error occurred while loading publication data.`, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open($localize`A technical error occurred while loading publication data.`, $localize`Close`, {duration: 5000});
|
||||||
this.location.back();
|
this.#location.back();
|
||||||
} else {
|
} else {
|
||||||
this.publicationRestService.getById(publicationId)
|
this.#publicationRestService.getById(publicationId)
|
||||||
.then(publication => {
|
.then(publication => {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
state.publication = publication;
|
state.publication = publication;
|
||||||
this.stateSubject.next(state);
|
this.#state.set(state);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`A technical error occurred while loading publication data.`;
|
const errorMessage = $localize`A technical error occurred while loading publication data.`;
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
console.error(errorMessage, error)
|
console.error(errorMessage, error)
|
||||||
})
|
})
|
||||||
.finally(() => this.isLoadingSubject.next(false));
|
.finally(() => this.#isLoading.set(false));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
init(publication: Publication): void {
|
init(publication: Publication): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
state.publication = publication;
|
state.publication = publication;
|
||||||
this.stateSubject.next(state);
|
this.#state.set(state);
|
||||||
|
this.#updateForm();
|
||||||
|
|
||||||
|
const formValueChangesSubscription = this.publicationEditionForm.valueChanges
|
||||||
|
.pipe(
|
||||||
|
debounceTime(200),
|
||||||
|
distinctUntilChanged()
|
||||||
|
)
|
||||||
|
.subscribe(formValue => {
|
||||||
|
const state = this.#state();
|
||||||
|
const publication = state.publication;
|
||||||
|
|
||||||
|
publication.title = formValue.title;
|
||||||
|
publication.description = formValue.description;
|
||||||
|
publication.categoryId = formValue.categoryId;
|
||||||
|
publication.text = formValue.text;
|
||||||
|
|
||||||
|
this.#state.set(state);
|
||||||
|
});
|
||||||
|
this.#subscriptions.push(formValueChangesSubscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
editTitle(title: string): void {
|
private editIllustrationId(pictureId: string): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
state.publication.title = title;
|
|
||||||
this._save(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
editDescription(description: string): void {
|
|
||||||
const state = this._state;
|
|
||||||
state.publication.description = description;
|
|
||||||
this._save(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
editCategoryId(categoryId: string): void {
|
|
||||||
const state = this._state;
|
|
||||||
state.publication.categoryId = categoryId;
|
|
||||||
this._save(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
editText(text: string): void {
|
|
||||||
const state = this._state;
|
|
||||||
state.publication.text = text;
|
|
||||||
this._save(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
editIllustrationId(pictureId: string): void {
|
|
||||||
const state = this._state;
|
|
||||||
state.publication.illustrationId = pictureId
|
state.publication.illustrationId = pictureId
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
displayPictureSectionDialog(): void {
|
displayPictureSectionDialog(): void {
|
||||||
const dialogRef = this.dialog.open(PictureSelectionDialog);
|
const dialogRef = this.#dialog.open(PictureSelectionDialog);
|
||||||
|
|
||||||
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
||||||
.subscribe(newPictureId => {
|
.subscribe(newPictureId => {
|
||||||
@@ -166,11 +161,11 @@ export class PublicationEditionService implements OnDestroy {
|
|||||||
this.editIllustrationId(newPictureId);
|
this.editIllustrationId(newPictureId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.subscriptions.push(afterDialogCloseSubscription);
|
this.#subscriptions.push(afterDialogCloseSubscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
displayCodeBlockDialog(): void {
|
displayCodeBlockDialog(): void {
|
||||||
const dialogRef = this.dialog.open(CodeBlockDialog, { width: '60em' });
|
const dialogRef = this.#dialog.open(CodeBlockDialog, {width: '60em'});
|
||||||
|
|
||||||
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
||||||
.subscribe(codeBlockWithLanguage => {
|
.subscribe(codeBlockWithLanguage => {
|
||||||
@@ -178,21 +173,21 @@ export class PublicationEditionService implements OnDestroy {
|
|||||||
this.insertCodeBlock(codeBlockWithLanguage.programmingLanguage, codeBlockWithLanguage.codeBlock);
|
this.insertCodeBlock(codeBlockWithLanguage.programmingLanguage, codeBlockWithLanguage.codeBlock);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.subscriptions.push(afterDialogCloseSubscription);
|
this.#subscriptions.push(afterDialogCloseSubscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
editCursorPosition(positionStart: number, positionEnd: number): void {
|
editCursorPosition(positionStart: number, positionEnd: number): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
state.cursorPosition.start = positionStart;
|
state.cursorPosition.start = positionStart;
|
||||||
state.cursorPosition.end = positionEnd;
|
state.cursorPosition.end = positionEnd;
|
||||||
|
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
insertTitle(titleNumber: number): void {
|
insertTitle(titleNumber: number): void {
|
||||||
if (titleNumber >= 1 && titleNumber <= 3) {
|
if (titleNumber >= 1 && titleNumber <= 3) {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
const publication = state.publication;
|
const publication = state.publication;
|
||||||
|
|
||||||
@@ -203,14 +198,15 @@ export class PublicationEditionService implements OnDestroy {
|
|||||||
|
|
||||||
publication.text = textWithTags;
|
publication.text = textWithTags;
|
||||||
|
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
|
this.#updateForm();
|
||||||
} else {
|
} else {
|
||||||
console.error(`Bad value for parameter of function 'insertTitle': '${titleNumber}'.`);
|
console.error(`Bad value for parameter of function 'insertTitle': '${titleNumber}'.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectAPicture(): void {
|
selectAPicture(): void {
|
||||||
const dialogRef = this.dialog.open(PictureSelectionDialog);
|
const dialogRef = this.#dialog.open(PictureSelectionDialog);
|
||||||
|
|
||||||
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
||||||
.subscribe(newPictureId => {
|
.subscribe(newPictureId => {
|
||||||
@@ -218,11 +214,11 @@ export class PublicationEditionService implements OnDestroy {
|
|||||||
this.insertPicture(newPictureId);
|
this.insertPicture(newPictureId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.subscriptions.push(afterDialogCloseSubscription);
|
this.#subscriptions.push(afterDialogCloseSubscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
insertPicture(pictureId: string): void {
|
insertPicture(pictureId: string): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
const publication = state.publication;
|
const publication = state.publication;
|
||||||
|
|
||||||
@@ -232,11 +228,12 @@ export class PublicationEditionService implements OnDestroy {
|
|||||||
|
|
||||||
publication.text = textWithTags;
|
publication.text = textWithTags;
|
||||||
|
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
|
this.#updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
insertLink(): void {
|
insertLink(): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
const publication = state.publication;
|
const publication = state.publication;
|
||||||
|
|
||||||
@@ -247,11 +244,12 @@ export class PublicationEditionService implements OnDestroy {
|
|||||||
|
|
||||||
publication.text = textWithTags;
|
publication.text = textWithTags;
|
||||||
|
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
|
this.#updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
insertCodeBlock(programmingLanguage: string, codeBlock: string): void {
|
private insertCodeBlock(programmingLanguage: string, codeBlock: string): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
const publication = state.publication;
|
const publication = state.publication;
|
||||||
|
|
||||||
@@ -262,27 +260,28 @@ export class PublicationEditionService implements OnDestroy {
|
|||||||
|
|
||||||
publication.text = textWithTags;
|
publication.text = textWithTags;
|
||||||
|
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
|
this.#updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPreview(): void {
|
loadPreview(): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
this.isPreviewingSubject.next(true);
|
this.#isPreviewing.set(true);
|
||||||
const request: PreviewContentRequest = {
|
const request: PreviewContentRequest = {
|
||||||
text: state.publication.text
|
text: state.publication.text
|
||||||
};
|
};
|
||||||
this.publicationRestService.preview(request)
|
this.#publicationRestService.preview(request)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
state.publication.parsedText = response.text;
|
state.publication.parsedText = response.text;
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
setTimeout(() => Prism.highlightAll(), 1000);
|
setTimeout(() => Prism.highlightAll(), 1000);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isPreviewingSubject.next(false);
|
this.#isPreviewing.set(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
@for(publication of publications$ | async; track publication) {
|
@for (publication of publications(); track publication.id) {
|
||||||
<a [routerLink]="['/publications/' + publication.id]" class="publication">
|
<a [routerLink]="['/publications/' + publication.id]" class="publication">
|
||||||
<img src="/api/pictures/{{ publication.illustrationId }}"/>
|
<img src="/api/pictures/{{ publication.illustrationId }}"/>
|
||||||
<div class="body">
|
<div class="body">
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
import { Component, Input } from "@angular/core";
|
import {Component, input} from "@angular/core";
|
||||||
import {Publication} from "../../core/rest-services/publications/model/publication";
|
import {Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import { Observable } from "rxjs";
|
|
||||||
import {CommonModule} from "@angular/common";
|
import {CommonModule} from "@angular/common";
|
||||||
import {RouterModule} from "@angular/router";
|
import {RouterModule} from "@angular/router";
|
||||||
import {MatTooltipModule} from "@angular/material/tooltip";
|
import {MatTooltipModule} from "@angular/material/tooltip";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication-list',
|
selector: 'app-publication-list',
|
||||||
standalone: true,
|
|
||||||
templateUrl: './publication-list.component.html',
|
templateUrl: './publication-list.component.html',
|
||||||
styleUrl: './publication-list.component.scss',
|
styleUrl: './publication-list.component.scss',
|
||||||
imports: [CommonModule, RouterModule, MatTooltipModule]
|
imports: [CommonModule, RouterModule, MatTooltipModule]
|
||||||
})
|
})
|
||||||
export class PublicationListComponent {
|
export class PublicationListComponent {
|
||||||
@Input()
|
publications = input.required<Publication[]>();
|
||||||
publications$!: Observable<Publication[]>;
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<form [formGroup]="formGroup">
|
<form [formGroup]="formGroup">
|
||||||
<input name="search-query" placeholder="Search something..." formControlName="criteria" i18n-placeholder/>
|
<input name="search-query" placeholder="Search something..." formControlName="criteria" i18n-placeholder/>
|
||||||
<button type="submit" (click)="searchPublications()">
|
<button type="submit" (click)="searchPublications()" matRipple>
|
||||||
<mat-icon>search</mat-icon>
|
<mat-icon>search</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -24,9 +24,10 @@
|
|||||||
border-radius: $borderRadiusValue;
|
border-radius: $borderRadiusValue;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border: none;
|
border: none;
|
||||||
top: .4em;
|
top: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
color: #aaaaaa;
|
color: #aaaaaa;
|
||||||
|
padding: .3em;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { HttpParams } from "@angular/common/http";
|
|
||||||
import {Component, inject} from "@angular/core";
|
import {Component, inject} from "@angular/core";
|
||||||
import {FormBuilder, FormControl, ReactiveFormsModule, Validators} from "@angular/forms";
|
import {FormBuilder, FormControl, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||||
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import {MatIconModule} from "@angular/material/icon";
|
import {MatIconModule} from "@angular/material/icon";
|
||||||
import {Router} from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
|
|
||||||
@@ -9,10 +9,10 @@ import { Router } from "@angular/router";
|
|||||||
selector: 'app-publications-search-bar',
|
selector: 'app-publications-search-bar',
|
||||||
templateUrl: './publications-search-bar.component.html',
|
templateUrl: './publications-search-bar.component.html',
|
||||||
styleUrl: './publications-search-bar.component.scss',
|
styleUrl: './publications-search-bar.component.scss',
|
||||||
standalone: true,
|
|
||||||
imports: [
|
imports: [
|
||||||
ReactiveFormsModule,
|
MatIconModule,
|
||||||
MatIconModule
|
MatRippleModule,
|
||||||
|
ReactiveFormsModule
|
||||||
],
|
],
|
||||||
providers: []
|
providers: []
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
@for(category of categories$ | async; track category) {
|
@for (category of categories(); track category.id) {
|
||||||
<div class="category {{category.isOpenned ? 'openned' : ''}}">
|
<div class="category {{category.isOpenned ? 'openned' : ''}}">
|
||||||
<div id="category-{{category.id}}" class="category-header" (click)="setOpenned(category)">
|
<div id="category-{{category.id}}" class="category-header" (click)="setOpened(category)">
|
||||||
{{ category.name }}
|
{{ category.name }}
|
||||||
<mat-icon>chevron_right</mat-icon>
|
<mat-icon>chevron_right</mat-icon>
|
||||||
</div>
|
</div>
|
||||||
<div class="sub-category-container {{category.isOpenned ? 'displayed' : ''}}">
|
<div class="sub-category-container {{category.isOpenned ? 'displayed' : ''}}">
|
||||||
@for (subCategory of category.subCategories; track subCategory) {
|
@for (subCategory of category.subCategories; track subCategory) {
|
||||||
<a [routerLink]="['/publications']" [queryParams]="{'category-id': subCategory.id}" (click)="categoryClicked.emit()" class="sub-category">
|
<a [routerLink]="['/publications']"
|
||||||
|
[queryParams]="{'category-id': subCategory.id}"
|
||||||
|
(click)="categoryClicked.emit()"
|
||||||
|
class="sub-category">
|
||||||
{{ subCategory.name }}
|
{{ subCategory.name }}
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +1,58 @@
|
|||||||
import {CommonModule} from "@angular/common";
|
import {CommonModule} from "@angular/common";
|
||||||
import { Component, EventEmitter, inject, OnInit, Output } from "@angular/core";
|
import {Component, inject, OnInit, output, Signal} from "@angular/core";
|
||||||
import {MatIconModule} from "@angular/material/icon";
|
import {MatIconModule} from "@angular/material/icon";
|
||||||
import {DisplayableCategory, SideMenuService} from "../side-menu.service";
|
import {DisplayableCategory, SideMenuService} from "../side-menu.service";
|
||||||
import { Observable } from "rxjs";
|
|
||||||
import {RouterModule} from "@angular/router";
|
import {RouterModule} from "@angular/router";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-categories-menu',
|
selector: 'app-categories-menu',
|
||||||
standalone: true,
|
|
||||||
imports: [CommonModule, RouterModule, MatIconModule],
|
|
||||||
templateUrl: './categories-menu.component.html',
|
templateUrl: './categories-menu.component.html',
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
RouterModule,
|
||||||
|
MatIconModule
|
||||||
|
],
|
||||||
styleUrl: './categories-menu.component.scss'
|
styleUrl: './categories-menu.component.scss'
|
||||||
})
|
})
|
||||||
export class CategoriesMenuComponent implements OnInit {
|
export class CategoriesMenuComponent implements OnInit {
|
||||||
private sideMenuService = inject(SideMenuService);
|
readonly #sideMenuService = inject(SideMenuService);
|
||||||
@Output()
|
categoryClicked = output<void>();
|
||||||
categoryClicked = new EventEmitter<void>();
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.sideMenuService.loadCategories();
|
this.#sideMenuService.loadCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
get categories$(): Observable<DisplayableCategory[]> {
|
get categories(): Signal<DisplayableCategory[]> {
|
||||||
return this.sideMenuService.categories$;
|
return this.#sideMenuService.categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenned(category: DisplayableCategory): void {
|
setOpened(category: DisplayableCategory): void {
|
||||||
if (category.isOpenned) {
|
if (category.isOpenned) {
|
||||||
const categoryDiv = document.getElementById(`category-${category.id}`);
|
const categoryDiv = document.getElementById(`category-${category.id}`);
|
||||||
if (categoryDiv) {
|
if (categoryDiv) {
|
||||||
this.closeAccordion(categoryDiv);
|
this.#closeAccordion(categoryDiv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const categoriesDivs = document.getElementsByClassName('category-header');
|
const categoriesDivs = document.getElementsByClassName('category-header');
|
||||||
Array.from(categoriesDivs)
|
Array.from(categoriesDivs)
|
||||||
.map(category => category as HTMLElement)
|
.map(category => category as HTMLElement)
|
||||||
.forEach(categoryDiv => this.closeAccordion(categoryDiv));
|
.forEach(categoryDiv => this.#closeAccordion(categoryDiv));
|
||||||
|
|
||||||
const categoryDiv = document.getElementById(`category-${category.id}`);
|
const categoryDiv = document.getElementById(`category-${category.id}`);
|
||||||
if (categoryDiv) {
|
if (categoryDiv) {
|
||||||
this.openAccordion(categoryDiv);
|
this.#openAccordion(categoryDiv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sideMenuService.setOpenned(category);
|
this.#sideMenuService.setOpened(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
private closeAccordion(categoryDiv: HTMLElement): void {
|
#closeAccordion(categoryDiv: HTMLElement): void {
|
||||||
const divContent = categoryDiv?.nextElementSibling as HTMLElement;
|
const divContent = categoryDiv?.nextElementSibling as HTMLElement;
|
||||||
divContent.style.maxHeight = '0';
|
divContent.style.maxHeight = '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
private openAccordion(categoryDiv: HTMLElement): void {
|
#openAccordion(categoryDiv: HTMLElement): void {
|
||||||
const divContent = categoryDiv?.nextElementSibling as HTMLElement;
|
const divContent = categoryDiv?.nextElementSibling as HTMLElement;
|
||||||
divContent.style.maxHeight = `${divContent.scrollHeight}px`;
|
divContent.style.maxHeight = `${divContent.scrollHeight}px`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
<div class="menu {{ isOpenned ? 'displayed' : '' }}">
|
<div class="menu {{ isOpened() ? 'displayed' : '' }}">
|
||||||
<h1>
|
<h1>
|
||||||
<a [routerLink]="['/home']">
|
<a [routerLink]="['/home']">
|
||||||
<img src="assets/images/codiki.png" alt="logo"/>
|
<img src="assets/images/codiki.png" alt="logo"/>
|
||||||
Codiki
|
Codiki
|
||||||
</a>
|
</a>
|
||||||
<button type="button" (click)="close()" matTooltip="Close the menu" i18n-matTooltip>
|
<button type="button"
|
||||||
|
(click)="close()"
|
||||||
|
class="cod-button icon"
|
||||||
|
matTooltip="Close the menu"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
<mat-icon>close</mat-icon>
|
<mat-icon>close</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</h1>
|
</h1>
|
||||||
<h2 i18n>Categories</h2>
|
<h2 i18n>Categories</h2>
|
||||||
<app-categories-menu (categoryClicked)="close()"></app-categories-menu>
|
<app-categories-menu (categoryClicked)="close()"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="overlay {{ isOpenned ? 'displayed' : ''}}" (click)="close()"></div>
|
<div class="overlay {{ isOpened() ? 'displayed' : ''}}" (click)="close()"></div>
|
||||||
|
|||||||
@@ -41,24 +41,6 @@
|
|||||||
height: $imageSize;
|
height: $imageSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
width: 2.5em;
|
|
||||||
height: 2.5em;
|
|
||||||
color: white;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: #5c6bc0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
|
|||||||
@@ -1,24 +1,30 @@
|
|||||||
import { Component } from '@angular/core';
|
import {Component, signal} from '@angular/core';
|
||||||
import {MatIconModule} from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import {MatTooltipModule} from '@angular/material/tooltip';
|
import {MatTooltipModule} from '@angular/material/tooltip';
|
||||||
import {RouterModule} from '@angular/router';
|
import {RouterModule} from '@angular/router';
|
||||||
import {CategoriesMenuComponent} from './categories-menu/categories-menu.component';
|
import {CategoriesMenuComponent} from './categories-menu/categories-menu.component';
|
||||||
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-side-menu',
|
selector: 'app-side-menu',
|
||||||
standalone: true,
|
|
||||||
imports: [CategoriesMenuComponent, MatIconModule, MatTooltipModule, RouterModule],
|
|
||||||
templateUrl: './side-menu.component.html',
|
templateUrl: './side-menu.component.html',
|
||||||
styleUrl: './side-menu.component.scss'
|
styleUrl: './side-menu.component.scss',
|
||||||
|
imports: [
|
||||||
|
CategoriesMenuComponent,
|
||||||
|
MatIconModule,
|
||||||
|
MatRippleModule,
|
||||||
|
MatTooltipModule,
|
||||||
|
RouterModule
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class SideMenuComponent {
|
export class SideMenuComponent {
|
||||||
isOpenned: boolean = false;
|
isOpened = signal(false);
|
||||||
|
|
||||||
open(): void {
|
open(): void {
|
||||||
this.isOpenned = true;
|
this.isOpened.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(): void {
|
close(): void {
|
||||||
this.isOpenned = false;
|
this.isOpened.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable, Signal, signal} from '@angular/core';
|
||||||
import {MatSnackBar} from '@angular/material/snack-bar';
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
|
||||||
import {CategoryRestService} from '../../core/rest-services/category/category.rest-service';
|
import {CategoryRestService} from '../../core/rest-services/category/category.rest-service';
|
||||||
import {Category} from '../../core/rest-services/category/model/category';
|
import {Category} from '../../core/rest-services/category/model/category';
|
||||||
|
|
||||||
@@ -20,68 +19,60 @@ export interface DisplayableSubCategory {
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class SideMenuService {
|
export class SideMenuService {
|
||||||
private categoryRestService = inject(CategoryRestService);
|
readonly #categoryRestService = inject(CategoryRestService);
|
||||||
private snackBar = inject(MatSnackBar);
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
private categoriesSubject = new BehaviorSubject<DisplayableCategory[]>([]);
|
#categories = signal<DisplayableCategory[]>([]);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private isLoadedSubject = new BehaviorSubject<boolean>(false);
|
isLoaded = signal(false);
|
||||||
|
|
||||||
private mapToDisplayableCategory(category: Category): DisplayableCategory {
|
#mapToDisplayableCategory(category: Category): DisplayableCategory {
|
||||||
return {
|
return {
|
||||||
id: category.id,
|
id: category.id,
|
||||||
name: category.name,
|
name: category.name,
|
||||||
subCategories: category.subCategories.map(subCategory => this.mapToDisplayableSubCategory(subCategory)),
|
subCategories: category.subCategories.map(subCategory => this.#mapToDisplayableSubCategory(subCategory)),
|
||||||
isOpenned: false
|
isOpenned: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private mapToDisplayableSubCategory(subCategory: Category): DisplayableSubCategory {
|
#mapToDisplayableSubCategory(subCategory: Category): DisplayableSubCategory {
|
||||||
return {
|
return {
|
||||||
id: subCategory.id,
|
id: subCategory.id,
|
||||||
name: subCategory.name
|
name: subCategory.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private get categories(): DisplayableCategory[] {
|
get categories(): Signal<DisplayableCategory[]> {
|
||||||
return this.categoriesSubject.value;
|
return this.#categories.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
private save(categories: DisplayableCategory[]): void {
|
get isLoading(): Signal<boolean> {
|
||||||
this.categoriesSubject.next(categories);
|
return this.#isLoading.asReadonly();
|
||||||
}
|
|
||||||
|
|
||||||
get categories$(): Observable<DisplayableCategory[]> {
|
|
||||||
return this.categoriesSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
|
||||||
return this.isLoadingSubject.asObservable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadCategories(): void {
|
loadCategories(): void {
|
||||||
this.isLoadingSubject.next(true);
|
this.#isLoading.set(true);
|
||||||
this.isLoadedSubject.next(false);
|
this.isLoaded.set(false);
|
||||||
|
|
||||||
this.categoryRestService.getCategories()
|
this.#categoryRestService.getCategories()
|
||||||
.then(categories => {
|
.then(categories => {
|
||||||
const displayableCategories = categories
|
const displayableCategories = categories
|
||||||
.filter(category => category.subCategories?.length)
|
.filter(category => category.subCategories?.length)
|
||||||
.map(category => this.mapToDisplayableCategory(category));
|
.map(category => this.#mapToDisplayableCategory(category));
|
||||||
this.categoriesSubject.next(displayableCategories);
|
this.#categories.set(displayableCategories);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occured while loading categories.`;
|
const errorMessage = $localize`An error occured while loading categories.`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isLoadingSubject.next(false);
|
this.#isLoading.set(false);
|
||||||
this.isLoadedSubject.next(true);
|
this.isLoaded.set(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenned(category: DisplayableCategory): void {
|
setOpened(category: DisplayableCategory): void {
|
||||||
const categories = this.categories;
|
const categories = this.#categories();
|
||||||
const matchingCategory = categories.find(categoryTemp => categoryTemp.id === category.id);
|
const matchingCategory = categories.find(categoryTemp => categoryTemp.id === category.id);
|
||||||
if (matchingCategory) {
|
if (matchingCategory) {
|
||||||
const actualOpennedCategory = categories.find(category => category.isOpenned);
|
const actualOpennedCategory = categories.find(category => category.isOpenned);
|
||||||
@@ -91,7 +82,7 @@ export class SideMenuService {
|
|||||||
categories.forEach(categoryTemp => categoryTemp.isOpenned = false);
|
categories.forEach(categoryTemp => categoryTemp.isOpenned = false);
|
||||||
matchingCategory.isOpenned = true;
|
matchingCategory.isOpenned = true;
|
||||||
}
|
}
|
||||||
this.save(categories);
|
this.#categories.set(categories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
<button type="submit" [class]="color" [disabled]="disabled || requestPending" (click)="click.emit()">
|
<button type="submit"
|
||||||
@if (requestPending) {
|
class="cod-button {{color()}}"
|
||||||
<mat-spinner class="spinner {{color}}" [diameter]="25"></mat-spinner>
|
[disabled]="disabled() || requestPending()"
|
||||||
|
(click)="click.emit()"
|
||||||
|
matRipple>
|
||||||
|
@if (requestPending()) {
|
||||||
|
<mat-spinner class="spinner {{color()}}" [diameter]="25"></mat-spinner>
|
||||||
}
|
}
|
||||||
<span>
|
<span>
|
||||||
{{ label }}
|
<ng-content/>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import {Component, input, output} from "@angular/core";
|
||||||
import { Component, EventEmitter, Input, Output } from "@angular/core";
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
|
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-submit-button',
|
selector: 'app-submit-button',
|
||||||
standalone: true,
|
|
||||||
imports: [MatProgressSpinnerModule, CommonModule],
|
|
||||||
templateUrl: 'submit-button.component.html',
|
templateUrl: 'submit-button.component.html',
|
||||||
styleUrl: 'submit-button.component.scss'
|
styleUrl: 'submit-button.component.scss',
|
||||||
|
imports: [
|
||||||
|
MatRippleModule,
|
||||||
|
MatProgressSpinnerModule
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class SubmitButtonComponent {
|
export class SubmitButtonComponent {
|
||||||
@Input() requestPending: boolean = false;
|
requestPending = input.required<boolean>();
|
||||||
@Input() label: string = '';
|
label = input<string>();
|
||||||
@Input() disabled: boolean = false;
|
disabled = input<boolean>(false);
|
||||||
@Input() color?: 'secondary';
|
color = input<'secondary' | undefined>('secondary');
|
||||||
@Output() click = new EventEmitter<void>();
|
click = output<void>();
|
||||||
}
|
}
|
||||||
|
|
||||||
18
frontend/src/app/core/guard/already-authenticated.guard.ts
Normal file
18
frontend/src/app/core/guard/already-authenticated.guard.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import {inject} from "@angular/core";
|
||||||
|
import {CanActivateFn, Router} from "@angular/router";
|
||||||
|
import {AuthenticationService} from "../service/authentication.service";
|
||||||
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
|
|
||||||
|
export const alreadyAuthenticatedGuard: CanActivateFn = () => {
|
||||||
|
const authenticationService = inject(AuthenticationService);
|
||||||
|
const router = inject(Router);
|
||||||
|
const snackBar = inject(MatSnackBar);
|
||||||
|
|
||||||
|
if (authenticationService.isAuthenticated()) {
|
||||||
|
router.navigate(['/home']);
|
||||||
|
snackBar.open($localize`You can't access to this page because you are already authenticated.`, $localize`Close`, {duration: 5000});
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,13 @@ import { CanActivateFn, Router } from "@angular/router";
|
|||||||
import {AuthenticationService} from "../service/authentication.service";
|
import {AuthenticationService} from "../service/authentication.service";
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
|
|
||||||
export const authenticationGuard: CanActivateFn = () => {
|
export const authenticationGuard: CanActivateFn = async () => {
|
||||||
const authenticationService = inject(AuthenticationService);
|
const authenticationService = inject(AuthenticationService);
|
||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
const snackBar = inject(MatSnackBar);
|
const snackBar = inject(MatSnackBar);
|
||||||
|
|
||||||
|
await authenticationService.checkIsAuthenticated();
|
||||||
|
|
||||||
if (authenticationService.isAuthenticated()) {
|
if (authenticationService.isAuthenticated()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http";
|
|
||||||
import { inject, Injectable } from "@angular/core";
|
|
||||||
import { Observable } from "rxjs";
|
|
||||||
import { CorrelationIdService } from "../service/correlation-id.service";
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class CorrelationIdInterceptor implements HttpInterceptor {
|
|
||||||
private readonly correlationIdService = inject(CorrelationIdService);
|
|
||||||
|
|
||||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
|
||||||
const correlationId = this.correlationIdService.getCorrelationId();
|
|
||||||
|
|
||||||
const requestWithCorrelationId = request.clone({
|
|
||||||
headers: request.headers.set('x-correlation-id', correlationId)
|
|
||||||
});
|
|
||||||
|
|
||||||
return next.handle(requestWithCorrelationId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
|
import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
|
||||||
import {inject, Injectable} from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {catchError, filter, Observable, Subject, switchMap, take, throwError} from 'rxjs';
|
import {catchError, filter, Observable, Subject, switchMap, take, throwError} from 'rxjs';
|
||||||
import { RefreshTokenRequest } from '../rest-services/user/model/refresh-token.model';
|
|
||||||
import {UserRestService} from '../rest-services/user/user.rest-service';
|
import {UserRestService} from '../rest-services/user/user.rest-service';
|
||||||
import {AuthenticationService} from '../service/authentication.service';
|
import {AuthenticationService} from '../service/authentication.service';
|
||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
@@ -41,23 +40,12 @@ export class JwtInterceptor implements HttpInterceptor {
|
|||||||
this.isRefreshingToken = true;
|
this.isRefreshingToken = true;
|
||||||
this.refreshTokenSubject.next(undefined);
|
this.refreshTokenSubject.next(undefined);
|
||||||
|
|
||||||
const refreshToken = this.authenticationService.getRefreshToken();
|
this.authenticationService.refreshToken()
|
||||||
if (refreshToken) {
|
|
||||||
const refreshTokenRequest: RefreshTokenRequest = {
|
|
||||||
refreshTokenValue: refreshToken
|
|
||||||
};
|
|
||||||
this.userRestService.refreshToken(refreshTokenRequest)
|
|
||||||
.then(refreshTokenResponse => {
|
.then(refreshTokenResponse => {
|
||||||
this.authenticationService.authenticate(refreshTokenResponse.accessToken, refreshTokenResponse.refreshToken);
|
|
||||||
this.refreshTokenSubject.next(refreshTokenResponse.accessToken);
|
this.refreshTokenSubject.next(refreshTokenResponse.accessToken);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => this.handleNoRefreshToken(initialError))
|
||||||
return this.handleNoRefreshToken(initialError);
|
|
||||||
})
|
|
||||||
.finally(() => this.isRefreshingToken = false);
|
.finally(() => this.isRefreshingToken = false);
|
||||||
} else {
|
|
||||||
return this.handleNoRefreshToken(initialError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.refreshTokenSubject.pipe(
|
return this.refreshTokenSubject.pipe(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {lastValueFrom} from 'rxjs';
|
import {lastValueFrom} from 'rxjs';
|
||||||
import {Category} from './model/category';
|
import {Category} from './model/category';
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { HttpClient, HttpParams } from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
import {inject, Injectable} from "@angular/core";
|
import {inject, Injectable} from "@angular/core";
|
||||||
import {Picture} from "./model/picture";
|
import {Picture} from "./model/picture";
|
||||||
import {lastValueFrom} from "rxjs";
|
import {lastValueFrom} from "rxjs";
|
||||||
|
|||||||
@@ -12,3 +12,20 @@ export interface Publication {
|
|||||||
categoryId: string;
|
categoryId: string;
|
||||||
author: Author;
|
author: Author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_PUBLICATION: Publication = {
|
||||||
|
id: '',
|
||||||
|
key: '',
|
||||||
|
title: '',
|
||||||
|
text: '',
|
||||||
|
parsedText: '',
|
||||||
|
description: '',
|
||||||
|
creationDate: new Date(),
|
||||||
|
illustrationId: '',
|
||||||
|
categoryId: '',
|
||||||
|
author: {
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
image: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import { last, lastValueFrom } from 'rxjs';
|
import {lastValueFrom} from 'rxjs';
|
||||||
import {Publication} from './model/publication';
|
import {Publication} from './model/publication';
|
||||||
import {PreviewContentRequest, PreviewContentResponse} from './model/preview';
|
import {PreviewContentRequest, PreviewContentResponse} from './model/preview';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {HttpClient} from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
import { Injectable, inject } from "@angular/core";
|
import {inject, Injectable} from "@angular/core";
|
||||||
import {LoginRequest, LoginResponse} from "./model/login.model";
|
import {LoginRequest, LoginResponse} from "./model/login.model";
|
||||||
import {lastValueFrom} from "rxjs";
|
import {lastValueFrom} from "rxjs";
|
||||||
import {SigninRequest} from "./model/signin.model";
|
import {SigninRequest} from "./model/signin.model";
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import {inject, Injectable} from "@angular/core";
|
import {inject, Injectable} from "@angular/core";
|
||||||
|
import {BehaviorSubject, interval} from "rxjs";
|
||||||
import {User} from "../model/User";
|
import {User} from "../model/User";
|
||||||
import {UserRestService} from "../rest-services/user/user.rest-service";
|
import {UserRestService} from "../rest-services/user/user.rest-service";
|
||||||
import {RefreshTokenRequest} from "../rest-services/user/model/refresh-token.model";
|
import {RefreshTokenRequest} from "../rest-services/user/model/refresh-token.model";
|
||||||
|
import {LoginResponse} from "../rest-services/user/model/login.model";
|
||||||
|
|
||||||
const JWT_PARAM = 'jwt';
|
const JWT_PARAM = 'jwt';
|
||||||
const REFRESH_TOKEN_PARAM = 'refresh-token';
|
const REFRESH_TOKEN_PARAM = 'refresh-token';
|
||||||
@@ -18,18 +20,30 @@ interface UserDetails {
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthenticationService {
|
export class AuthenticationService {
|
||||||
|
private readonly AUTHENTICATION_CHECKING_PERIOD = 5 * 60 * 1000;
|
||||||
|
private isAuthenticatedSubject = new BehaviorSubject<boolean>(false);
|
||||||
|
private readonly userRestService = inject(UserRestService);
|
||||||
|
|
||||||
|
startAuthenticationCheckingProcess(): void {
|
||||||
|
this.checkIsAuthenticated();
|
||||||
|
interval(this.AUTHENTICATION_CHECKING_PERIOD)
|
||||||
|
.subscribe(() => this.checkIsAuthenticated());
|
||||||
|
}
|
||||||
|
|
||||||
authenticate(token: string, refreshToken: string): void {
|
authenticate(token: string, refreshToken: string): void {
|
||||||
localStorage.setItem(JWT_PARAM, token);
|
localStorage.setItem(JWT_PARAM, token);
|
||||||
localStorage.setItem(REFRESH_TOKEN_PARAM, refreshToken);
|
localStorage.setItem(REFRESH_TOKEN_PARAM, refreshToken);
|
||||||
|
this.isAuthenticatedSubject.next(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
unauthenticate(): void {
|
unauthenticate(): void {
|
||||||
localStorage.removeItem(JWT_PARAM);
|
localStorage.removeItem(JWT_PARAM);
|
||||||
|
localStorage.removeItem(REFRESH_TOKEN_PARAM);
|
||||||
|
this.isAuthenticatedSubject.next(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
isAuthenticated(): boolean {
|
isAuthenticated(): boolean {
|
||||||
return !!localStorage.getItem(JWT_PARAM);
|
return this.isAuthenticatedSubject.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuthenticatedUser(): User | undefined {
|
getAuthenticatedUser(): User | undefined {
|
||||||
@@ -45,7 +59,7 @@ export class AuthenticationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isTokenExpired(): boolean {
|
isTokenExpired(): boolean {
|
||||||
let result = false;
|
let result = true;
|
||||||
|
|
||||||
const userDetails = this.extractUserDetails();
|
const userDetails = this.extractUserDetails();
|
||||||
|
|
||||||
@@ -59,8 +73,43 @@ export class AuthenticationService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshToken(): Promise<LoginResponse> {
|
||||||
|
const refreshToken = this.getRefreshToken();
|
||||||
|
if (refreshToken) {
|
||||||
|
const refreshTokenRequest: RefreshTokenRequest = {
|
||||||
|
refreshTokenValue: refreshToken
|
||||||
|
};
|
||||||
|
return this.userRestService.refreshToken(refreshTokenRequest)
|
||||||
|
.then(refreshTokenResponse => {
|
||||||
|
this.authenticate(refreshTokenResponse.accessToken, refreshTokenResponse.refreshToken);
|
||||||
|
return refreshTokenResponse;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject('No any refresh token found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
checkIsAuthenticated(): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const isTokenExpired = this.isTokenExpired();
|
||||||
|
if (isTokenExpired) {
|
||||||
|
if (this.getRefreshToken()) {
|
||||||
|
this.refreshToken()
|
||||||
|
.then(() => resolve())
|
||||||
|
.catch(() => reject());
|
||||||
|
} else {
|
||||||
|
this.isAuthenticatedSubject.next(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.isAuthenticatedSubject.next(true);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private extractUserFromLocalStorage(): User | undefined {
|
private extractUserFromLocalStorage(): User | undefined {
|
||||||
let result: User | undefined = undefined;
|
let result: User | undefined;
|
||||||
|
|
||||||
const userDetails = this.extractUserDetails();
|
const userDetails = this.extractUserDetails();
|
||||||
if (userDetails) {
|
if (userDetails) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {CategoryRestService} from '../rest-services/category/category.rest-service';
|
import {CategoryRestService} from '../rest-services/category/category.rest-service';
|
||||||
import {BehaviorSubject, Observable} from 'rxjs';
|
import {BehaviorSubject, Observable} from 'rxjs';
|
||||||
import {Category} from '../rest-services/category/model/category';
|
import {Category} from '../rest-services/category/model/category';
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import { Injectable } from "@angular/core";
|
|
||||||
import * as uuid from 'uuid';
|
|
||||||
|
|
||||||
const CORRELATION_ID_KEY = 'correlationId';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class CorrelationIdService {
|
|
||||||
getCorrelationId(): string {
|
|
||||||
let correlationId = this.getCorrelationFromLocalStorage();
|
|
||||||
if (correlationId === undefined) {
|
|
||||||
correlationId = this.createNewCorrelationId();
|
|
||||||
}
|
|
||||||
return correlationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getCorrelationFromLocalStorage(): string | undefined {
|
|
||||||
return localStorage.getItem(CORRELATION_ID_KEY) ?? undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
private createNewCorrelationId(): string {
|
|
||||||
const newCorrelationId = uuid.v4();
|
|
||||||
localStorage.setItem(CORRELATION_ID_KEY, newCorrelationId);
|
|
||||||
return newCorrelationId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
import { Component, OnInit, inject } from '@angular/core';
|
import {Component, inject, OnInit} from '@angular/core';
|
||||||
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
||||||
import {AuthenticationService} from '../../core/service/authentication.service';
|
import {AuthenticationService} from '../../core/service/authentication.service';
|
||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-disconnection',
|
selector: 'app-disconnection',
|
||||||
standalone: true,
|
|
||||||
imports: [MatProgressSpinnerModule],
|
imports: [MatProgressSpinnerModule],
|
||||||
templateUrl: './disconnection.component.html',
|
templateUrl: './disconnection.component.html',
|
||||||
styleUrl: './disconnection.component.scss'
|
styleUrl: './disconnection.component.scss'
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<h1 i18n>Last publications</h1>
|
<h1 i18n>Last publications</h1>
|
||||||
@if ((isLoading$ | async) === true) {
|
@if ((isLoading())) {
|
||||||
<h2 i18n>Publications loading...</h2>
|
<h2 i18n>Publications loading...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner/>
|
||||||
} @else {
|
} @else {
|
||||||
@if ((publications$ | async) != []) {
|
@if (publications(); as publications) {
|
||||||
<app-publication-list [publications$]="publications$"></app-publication-list>
|
<app-publication-list [publications]="publications"/>
|
||||||
} @else {
|
} @else {
|
||||||
<h2 i18n>No any publication.</h2>
|
<h2 i18n>No any publication.</h2>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
import { Component, OnInit, inject } from '@angular/core';
|
import {Component, inject, OnInit} from '@angular/core';
|
||||||
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import {PublicationListComponent} from '../../components/publication-list/publication-list.component';
|
import {PublicationListComponent} from '../../components/publication-list/publication-list.component';
|
||||||
import { Publication } from '../../core/rest-services/publications/model/publication';
|
|
||||||
import {HomeService} from './home.service';
|
import {HomeService} from './home.service';
|
||||||
import {CommonModule} from '@angular/common';
|
import {CommonModule} from '@angular/common';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-home',
|
selector: 'app-home',
|
||||||
standalone: true,
|
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
@@ -19,17 +16,11 @@ import { CommonModule } from '@angular/common';
|
|||||||
providers: [HomeService]
|
providers: [HomeService]
|
||||||
})
|
})
|
||||||
export class HomeComponent implements OnInit {
|
export class HomeComponent implements OnInit {
|
||||||
private homeService = inject(HomeService);
|
readonly #homeService = inject(HomeService);
|
||||||
|
isLoading = this.#homeService.isLoading;
|
||||||
get isLoading$(): Observable<boolean> {
|
publications = this.#homeService.publications;
|
||||||
return this.homeService.isLoading$;
|
|
||||||
}
|
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
|
||||||
return this.homeService.publications$;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.homeService.startLatestPublicationsRetrieving();
|
this.#homeService.startLatestPublicationsRetrieving();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Injectable, inject } from "@angular/core";
|
import {inject, Injectable, Signal, signal} from "@angular/core";
|
||||||
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import { BehaviorSubject, Observable } from "rxjs";
|
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar"
|
import {MatSnackBar} from "@angular/material/snack-bar"
|
||||||
import {Publication} from "../../core/rest-services/publications/model/publication";
|
import {Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
|
|
||||||
@@ -9,27 +8,27 @@ export class HomeService {
|
|||||||
private publicationRestService = inject(PublicationRestService);
|
private publicationRestService = inject(PublicationRestService);
|
||||||
private snackBar = inject(MatSnackBar);
|
private snackBar = inject(MatSnackBar);
|
||||||
|
|
||||||
private publicationsSubject = new BehaviorSubject<Publication[]>([]);
|
#publications = signal<Publication[]>([]);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoadingSubject = signal<boolean>(false);
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
get isLoading(): Signal<boolean> {
|
||||||
return this.isLoadingSubject.asObservable();
|
return this.#isLoadingSubject.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
get publications(): Signal<Publication[]> {
|
||||||
return this.publicationsSubject.asObservable();
|
return this.#publications.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
startLatestPublicationsRetrieving(): void {
|
startLatestPublicationsRetrieving(): void {
|
||||||
this.isLoadingSubject.next(true);
|
this.#isLoadingSubject.set(true);
|
||||||
|
|
||||||
this.publicationRestService.getLatest()
|
this.publicationRestService.getLatest()
|
||||||
.then(publications => this.publicationsSubject.next(publications))
|
.then(publications => this.#publications.set(publications))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occurred while retrieving latest publications...`;
|
const errorMessage = $localize`An error occurred while retrieving latest publications...`;
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
})
|
})
|
||||||
.finally(() => this.isLoadingSubject.next(false));
|
.finally(() => this.#isLoadingSubject.set(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<form [formGroup]="loginForm" (submit)="performLogin()" ngNativeValidate>
|
<form [formGroup]="loginForm" (submit)="performLogin()" class="cod-form card" ngNativeValidate>
|
||||||
<h1 i18n>Login</h1>
|
<h1 i18n>Login</h1>
|
||||||
<div>
|
<div class="form-field">
|
||||||
<mat-icon>mail</mat-icon>
|
<mat-icon>mail</mat-icon>
|
||||||
<label for="email" i18n>
|
<label for="email" i18n>
|
||||||
Email address
|
Email address
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<input type="email" id="email" formControlName="email" autocomplete="email" required/>
|
<input type="email" id="email" formControlName="email" autocomplete="email" required/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="form-field">
|
||||||
<mat-icon>lock</mat-icon>
|
<mat-icon>lock</mat-icon>
|
||||||
<label for="password" i18n>
|
<label for="password" i18n>
|
||||||
Password
|
Password
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
</label>
|
</label>
|
||||||
<input type="password" id="password" formControlName="password" required/>
|
<input type="password" id="password" formControlName="password" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions reversed">
|
||||||
<button type="submit" i18n>Send</button>
|
<app-submit-button [requestPending]="false" [disabled]="false" i18n>Send</app-submit-button>
|
||||||
<a [routerLink]="['/signin']" i18n>Create an account</a>
|
<a [routerLink]="['/signin']" class="cod-button secondary" matRipple i18n>Create an account</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -4,79 +4,4 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
|
|
||||||
form {
|
|
||||||
width: 80%;
|
|
||||||
max-width: 20em;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 1em;
|
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
|
||||||
border-radius: .5em;
|
|
||||||
padding: 1em 1.5em;
|
|
||||||
background-color: #ffffff;
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
div {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
position: relative;
|
|
||||||
gap: .1em;
|
|
||||||
|
|
||||||
mat-icon {
|
|
||||||
position: absolute;
|
|
||||||
top: 1.3em;
|
|
||||||
left: .5em;
|
|
||||||
color: #777;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.actions {
|
|
||||||
flex-direction: row-reverse;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: #3f51b5;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
button, a.button {
|
|
||||||
padding: .8em 1.2em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5b6ed8;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
label {
|
|
||||||
flex: 1;
|
|
||||||
font-style: italic;
|
|
||||||
padding-left: 1em;
|
|
||||||
color: #777;
|
|
||||||
|
|
||||||
.required {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
|
||||||
flex: 1;
|
|
||||||
background-color: #eeeeee;
|
|
||||||
border: none;
|
|
||||||
border-radius: 10em;
|
|
||||||
padding: 1em 1em 1em 3em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,24 @@
|
|||||||
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||||
import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
import {MatSnackBarModule} from '@angular/material/snack-bar';
|
import {MatSnackBarModule} from '@angular/material/snack-bar';
|
||||||
import { Subscription, debounceTime, map } from 'rxjs';
|
import {debounceTime, map, Subscription} from 'rxjs';
|
||||||
import {LoginService} from './login.service';
|
import {LoginService} from './login.service';
|
||||||
import {MatIconModule} from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import {RouterModule} from '@angular/router';
|
import {RouterModule} from '@angular/router';
|
||||||
|
import {SubmitButtonComponent} from "../../components/submit-button/submit-button.component";
|
||||||
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
standalone: true,
|
|
||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
styleUrl: './login.component.scss',
|
styleUrl: './login.component.scss',
|
||||||
imports: [ReactiveFormsModule, MatIconModule, RouterModule],
|
imports: [
|
||||||
|
MatIconModule,
|
||||||
|
MatRippleModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
RouterModule,
|
||||||
|
SubmitButtonComponent
|
||||||
|
],
|
||||||
providers: [LoginService, MatSnackBarModule]
|
providers: [LoginService, MatSnackBarModule]
|
||||||
})
|
})
|
||||||
export class LoginComponent implements OnInit, OnDestroy {
|
export class LoginComponent implements OnInit, OnDestroy {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {BehaviorSubject, Observable} from 'rxjs';
|
import {BehaviorSubject, Observable} from 'rxjs';
|
||||||
import {copy} from '../../core/utils/ObjectUtils';
|
import {copy} from '../../core/utils/ObjectUtils';
|
||||||
import {FormError} from '../../core/model/FormError';
|
import {FormError} from '../../core/model/FormError';
|
||||||
@@ -60,8 +60,7 @@ export class LoginService {
|
|||||||
performLogin(): void {
|
performLogin(): void {
|
||||||
const state = this.state;
|
const state = this.state;
|
||||||
|
|
||||||
// Check state is valid
|
if (this.isStateValid(state)) {
|
||||||
|
|
||||||
this.userRestService
|
this.userRestService
|
||||||
.login(state.request)
|
.login(state.request)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
@@ -73,5 +72,12 @@ export class LoginService {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
this.snackBar.open($localize`Authentication failed.`, $localize`Close`, {duration: 5000});
|
this.snackBar.open($localize`Authentication failed.`, $localize`Close`, {duration: 5000});
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.snackBar.open($localize`Please, fill the inputs before send.`, $localize`Close`, {duration: 5000});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isStateValid(state: LoginState): boolean {
|
||||||
|
return !!state.request.email?.trim().length && !!state.request.password?.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,17 @@
|
|||||||
class="new-publication"
|
class="new-publication"
|
||||||
matTooltip="Add a new publication"
|
matTooltip="Add a new publication"
|
||||||
matTooltipPosition="left"
|
matTooltipPosition="left"
|
||||||
|
matRipple
|
||||||
i18n-matTooltip>
|
i18n-matTooltip>
|
||||||
+
|
+
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
@if ((isLoading$ | async) === true) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Publication loading...</h2>
|
<h2 i18n>Publication loading...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner></mat-spinner>
|
||||||
} @else {
|
} @else {
|
||||||
@if ((isLoaded$ | async) === true) {
|
@if (isLoaded()) {
|
||||||
<app-publication-list [publications$]="publications$"></app-publication-list>
|
<app-publication-list [publications]="publications()"></app-publication-list>
|
||||||
} @else {
|
} @else {
|
||||||
<h2 i18n>There is no any publication...</h2>
|
<h2 i18n>There is no any publication...</h2>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
import {Component, inject, OnInit} from "@angular/core";
|
import {Component, inject, OnInit} from "@angular/core";
|
||||||
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
|
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
|
||||||
import {MyPublicationsService} from "./my-publications.service";
|
import {MyPublicationsService} from "./my-publications.service";
|
||||||
import { Observable } from "rxjs";
|
|
||||||
import {PublicationListComponent} from "../../components/publication-list/publication-list.component";
|
import {PublicationListComponent} from "../../components/publication-list/publication-list.component";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
|
||||||
import {CommonModule} from "@angular/common";
|
import {CommonModule} from "@angular/common";
|
||||||
import {RouterModule} from "@angular/router";
|
import {RouterModule} from "@angular/router";
|
||||||
import {MatTooltipModule} from "@angular/material/tooltip";
|
import {MatTooltipModule} from "@angular/material/tooltip";
|
||||||
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-my-component',
|
selector: 'app-my-component',
|
||||||
standalone: true,
|
|
||||||
templateUrl: './my-publications.component.html',
|
templateUrl: './my-publications.component.html',
|
||||||
styleUrl: './my-publications.component.scss',
|
styleUrl: './my-publications.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
PublicationListComponent,
|
MatRippleModule,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
|
PublicationListComponent,
|
||||||
RouterModule
|
RouterModule
|
||||||
],
|
],
|
||||||
providers: [MyPublicationsService]
|
providers: [MyPublicationsService]
|
||||||
@@ -26,17 +25,9 @@ import { MatTooltipModule } from "@angular/material/tooltip";
|
|||||||
export class MyPublicationsComponent implements OnInit {
|
export class MyPublicationsComponent implements OnInit {
|
||||||
private readonly myPublicationsService = inject(MyPublicationsService);
|
private readonly myPublicationsService = inject(MyPublicationsService);
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
publications = this.myPublicationsService.publications;
|
||||||
return this.myPublicationsService.publications$;
|
isLoading = this.myPublicationsService.isLoading;
|
||||||
}
|
isLoaded = this.myPublicationsService.isLoaded;
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
|
||||||
return this.myPublicationsService.isLoading$;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoaded$(): Observable<boolean> {
|
|
||||||
return this.myPublicationsService.isLoaded$;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.myPublicationsService.loadAuthenticatedUserPublications();
|
this.myPublicationsService.loadAuthenticatedUserPublications();
|
||||||
|
|||||||
@@ -1,57 +1,56 @@
|
|||||||
import { inject, Injectable } from "@angular/core";
|
import {inject, Injectable, Signal, signal} from "@angular/core";
|
||||||
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import {AuthenticationService} from "../../core/service/authentication.service";
|
import {AuthenticationService} from "../../core/service/authentication.service";
|
||||||
import { BehaviorSubject, Observable } from "rxjs";
|
|
||||||
import {Publication} from "../../core/rest-services/publications/model/publication";
|
import {Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import {Router} from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MyPublicationsService {
|
export class MyPublicationsService {
|
||||||
private readonly authenticationService = inject(AuthenticationService);
|
readonly #authenticationService = inject(AuthenticationService);
|
||||||
private readonly publicationRestService = inject(PublicationRestService);
|
readonly #publicationRestService = inject(PublicationRestService);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
private readonly router = inject(Router);
|
readonly #router = inject(Router);
|
||||||
private publicationsSubject = new BehaviorSubject<Publication[]>([]);
|
#publications = signal<Publication[]>([]);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private isLoadedSubject = new BehaviorSubject<boolean>(false);
|
#isLoaded = signal(false);
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
get publications(): Signal<Publication[]> {
|
||||||
return this.publicationsSubject.asObservable();
|
return this.#publications.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
get isLoading(): Signal<boolean> {
|
||||||
return this.isLoadingSubject.asObservable();
|
return this.#isLoading.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isLoaded$(): Observable<boolean> {
|
get isLoaded(): Signal<boolean> {
|
||||||
return this.isLoadedSubject.asObservable();
|
return this.#isLoaded.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAuthenticatedUserPublications(): void {
|
loadAuthenticatedUserPublications(): void {
|
||||||
const authenticatedUser = this.authenticationService.getAuthenticatedUser();
|
const authenticatedUser = this.#authenticationService.getAuthenticatedUser();
|
||||||
if (authenticatedUser) {
|
if (authenticatedUser) {
|
||||||
this.isLoadingSubject.next(true);
|
this.#isLoading.set(true);
|
||||||
this.isLoadedSubject.next(false);
|
this.#isLoaded.set(false);
|
||||||
|
|
||||||
const query = `author_id=${authenticatedUser.id}`;
|
const query = `author_id=${authenticatedUser.id}`;
|
||||||
this.publicationRestService.search(query)
|
this.#publicationRestService.search(query)
|
||||||
.then(publications => {
|
.then(publications => {
|
||||||
this.publicationsSubject.next(publications);
|
this.#publications.set(publications);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occurred while retrieving your publications...`;
|
const errorMessage = $localize`An error occurred while retrieving your publications...`;
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isLoadingSubject.next(false);
|
this.#isLoading.set(false);
|
||||||
this.isLoadedSubject.next(true);
|
this.#isLoaded.set(true);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.authenticationService.unauthenticate();
|
this.#authenticationService.unauthenticate();
|
||||||
this.snackBar.open($localize`You are unauthenticated. Please, log-in first.`, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open($localize`You are unauthenticated. Please, log-in first.`, $localize`Close`, {duration: 5000});
|
||||||
this.router.navigate(['/login']);
|
this.#router.navigate(['/login']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<app-publication-edition
|
<app-publication-edition
|
||||||
title="Creation of a new publication"
|
title="Creation of a new publication"
|
||||||
[publication]="publication"
|
[publication]="publication()"
|
||||||
[isSaving$]="isSaving$"
|
[isSaving]="isSaving()"
|
||||||
(publicationSave)="onPublicationSave($event)"
|
(publicationSave)="onPublicationSave($event)"
|
||||||
i18n-title>
|
i18n-title
|
||||||
</app-publication-edition>
|
/>
|
||||||
|
|||||||
@@ -1,76 +1,53 @@
|
|||||||
import { Component, inject, OnInit } from "@angular/core";
|
import {Component, inject, OnInit, signal} from "@angular/core";
|
||||||
import {PublicationEditionComponent} from "../../components/publication-edition/publication-edition.component";
|
import {PublicationEditionComponent} from "../../components/publication-edition/publication-edition.component";
|
||||||
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import { BehaviorSubject, Observable, Subscription } from "rxjs";
|
import {DEFAULT_PUBLICATION, Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
|
||||||
import {AuthenticationService} from "../../core/service/authentication.service";
|
import {AuthenticationService} from "../../core/service/authentication.service";
|
||||||
import {Author} from "../../core/rest-services/publications/model/author";
|
import {Author} from "../../core/rest-services/publications/model/author";
|
||||||
import { CommonModule } from "@angular/common";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication-creation',
|
selector: 'app-publication-creation',
|
||||||
standalone: true,
|
|
||||||
templateUrl: './publication-creation.component.html',
|
templateUrl: './publication-creation.component.html',
|
||||||
styleUrl: './publication-creation.component.scss',
|
styleUrl: './publication-creation.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
|
||||||
PublicationEditionComponent
|
PublicationEditionComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class PublicationCreationComponent implements OnInit {
|
export class PublicationCreationComponent implements OnInit {
|
||||||
private readonly authenticationService = inject(AuthenticationService);
|
readonly #authenticationService = inject(AuthenticationService);
|
||||||
private readonly publicationRestService = inject(PublicationRestService);
|
readonly #publicationRestService = inject(PublicationRestService);
|
||||||
private readonly router = inject(Router);
|
readonly #router = inject(Router);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
isSaving = signal(false);
|
||||||
private subscriptions: Subscription[] = [];
|
publication = signal<Publication>(DEFAULT_PUBLICATION);
|
||||||
publication!: Publication;
|
|
||||||
|
|
||||||
get isSaving$(): Observable<boolean> {
|
|
||||||
return this.isSavingSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const authenticatedUser = this.authenticationService.getAuthenticatedUser();
|
const authenticatedUser = this.#authenticationService.getAuthenticatedUser();
|
||||||
if (authenticatedUser) {
|
if (authenticatedUser) {
|
||||||
const author: Author = {
|
const author: Author = {
|
||||||
id: authenticatedUser.id,
|
id: authenticatedUser.id,
|
||||||
name: authenticatedUser.pseudo,
|
name: authenticatedUser.pseudo,
|
||||||
image: authenticatedUser.photoId ?? ''
|
image: authenticatedUser.photoId ?? ''
|
||||||
};
|
};
|
||||||
this.publication = {
|
const newPublication: Publication = {...DEFAULT_PUBLICATION, author};
|
||||||
id: '',
|
this.publication.set(newPublication);
|
||||||
key: '',
|
|
||||||
title: '',
|
|
||||||
text: '',
|
|
||||||
parsedText: '',
|
|
||||||
description: '',
|
|
||||||
creationDate: new Date(),
|
|
||||||
illustrationId: '',
|
|
||||||
categoryId: '',
|
|
||||||
author
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
this.subscriptions.forEach(subscription => subscription?.unsubscribe());
|
|
||||||
}
|
|
||||||
|
|
||||||
onPublicationSave(publication: Publication): void {
|
onPublicationSave(publication: Publication): void {
|
||||||
this.isSavingSubject.next(true);
|
this.isSaving.set(true);
|
||||||
this.publicationRestService.create(publication)
|
this.#publicationRestService.create(publication)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.snackBar.open($localize`Publication created succesfully!`, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open($localize`Publication created succesfully!`, $localize`Close`, {duration: 5000});
|
||||||
this.router.navigate(['/my-publications']);
|
this.#router.navigate(['/my-publications']);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occured while saving new publication.`;
|
const errorMessage = $localize`An error occured while saving new publication.`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
})
|
})
|
||||||
.finally(() => this.isSavingSubject.next(false));
|
.finally(() => this.isSaving.set(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,16 @@
|
|||||||
@if ((isLoading$ | async) == true) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Loading publication to edit...</h2>
|
<h2 i18n>Loading publication to edit...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner/>
|
||||||
}
|
} @else {
|
||||||
@else {
|
@if (publication(); as publication) {
|
||||||
@if (publication) {
|
|
||||||
<app-publication-edition
|
<app-publication-edition
|
||||||
title="Update publication {{ publication.title }}"
|
title="Update publication {{ publication.title }}"
|
||||||
[publication]="publication"
|
[publication]="publication"
|
||||||
[isSaving$]="isSaving$"
|
[isSaving]="isSaving()"
|
||||||
(publicationSave)="onPublicationSave($event)"
|
(publicationSave)="onPublicationSave($event)"
|
||||||
i18n-title>
|
i18n-title
|
||||||
</app-publication-edition>
|
/>
|
||||||
}
|
} @else {
|
||||||
@else {
|
|
||||||
<div class="loading-failed">
|
<div class="loading-failed">
|
||||||
<h1 i18n>Publication failed to load...</h1>
|
<h1 i18n>Publication failed to load...</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {CommonModule, Location} from '@angular/common';
|
import {CommonModule, Location} from '@angular/common';
|
||||||
import { Component, inject, OnDestroy, OnInit } from '@angular/core';
|
import {Component, effect, inject, Signal, signal} from '@angular/core';
|
||||||
import {ReactiveFormsModule} from '@angular/forms';
|
import {ReactiveFormsModule} from '@angular/forms';
|
||||||
import {MatDialogModule} from '@angular/material/dialog';
|
import {MatDialogModule} from '@angular/material/dialog';
|
||||||
import {MatIconModule} from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
@@ -9,16 +9,14 @@ import { MatSnackBar } from '@angular/material/snack-bar';
|
|||||||
import {MatTabsModule} from '@angular/material/tabs';
|
import {MatTabsModule} from '@angular/material/tabs';
|
||||||
import {MatTooltipModule} from '@angular/material/tooltip';
|
import {MatTooltipModule} from '@angular/material/tooltip';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
|
|
||||||
import {PublicationEditionComponent} from '../../components/publication-edition/publication-edition.component';
|
import {PublicationEditionComponent} from '../../components/publication-edition/publication-edition.component';
|
||||||
import { SubmitButtonComponent } from '../../components/submit-button/submit-button.component';
|
|
||||||
import {Publication} from '../../core/rest-services/publications/model/publication';
|
import {Publication} from '../../core/rest-services/publications/model/publication';
|
||||||
import {PublicationRestService} from '../../core/rest-services/publications/publication.rest-service';
|
import {PublicationRestService} from '../../core/rest-services/publications/publication.rest-service';
|
||||||
import { PictureSelectionDialog } from '../../components/publication-edition/picture-selection-dialog/picture-selection-dialog.component';
|
import {toSignal} from "@angular/core/rxjs-interop";
|
||||||
|
import {map} from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication-update',
|
selector: 'app-publication-update',
|
||||||
standalone: true,
|
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
@@ -27,71 +25,69 @@ import { PictureSelectionDialog } from '../../components/publication-edition/pic
|
|||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
MatTabsModule,
|
MatTabsModule,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
PictureSelectionDialog,
|
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
SubmitButtonComponent,
|
|
||||||
PublicationEditionComponent
|
PublicationEditionComponent
|
||||||
],
|
],
|
||||||
templateUrl: './publication-update.component.html',
|
templateUrl: './publication-update.component.html',
|
||||||
styleUrl: './publication-update.component.scss',
|
styleUrl: './publication-update.component.scss'
|
||||||
})
|
})
|
||||||
export class PublicationUpdateComponent implements OnInit, OnDestroy {
|
export class PublicationUpdateComponent {
|
||||||
private readonly publicationRestService = inject(PublicationRestService);
|
readonly #activatedRoute = inject(ActivatedRoute);
|
||||||
private readonly activatedRoute = inject(ActivatedRoute);
|
readonly #location = inject(Location);
|
||||||
private readonly location = inject(Location);
|
readonly #publicationRestService = inject(PublicationRestService);
|
||||||
private readonly router = inject(Router);
|
readonly #router = inject(Router);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
#isSavingSubject = signal(false);
|
||||||
private subscriptions: Subscription[] = [];
|
publication = signal<Publication | undefined>(undefined);
|
||||||
publication: Publication | undefined;
|
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
#publicationId$ = this.#activatedRoute.params
|
||||||
return this.isLoadingSubject.asObservable();
|
.pipe(map(queryParams => queryParams['publicationId']));
|
||||||
|
#publicationId = toSignal(this.#publicationId$, {initialValue: undefined});
|
||||||
|
|
||||||
|
get isLoading(): Signal<boolean> {
|
||||||
|
return this.#isLoading.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isSaving$(): Observable<boolean> {
|
get isSaving(): Signal<boolean> {
|
||||||
return this.isSavingSubject.asObservable();
|
return this.#isSavingSubject.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
constructor() {
|
||||||
this.isLoadingSubject.next(true);
|
effect(() => {
|
||||||
this.activatedRoute.paramMap.subscribe(params => {
|
this.#isLoading.set(true);
|
||||||
const publicationId = params.get('publicationId');
|
|
||||||
if (publicationId == undefined) {
|
const publicationId = this.#publicationId();
|
||||||
this.snackBar.open($localize`A technical error occurred while loading publication data.`, $localize`Close`, { duration: 5000 });
|
if (publicationId) {
|
||||||
this.location.back();
|
this.#publicationRestService.getById(publicationId)
|
||||||
} else {
|
|
||||||
this.publicationRestService.getById(publicationId)
|
|
||||||
.then(publication => {
|
.then(publication => {
|
||||||
this.publication = publication;
|
this.publication.set(publication);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`A technical error occurred while loading publication data.`;
|
const errorMessage = $localize`A technical error occurred while loading publication data.`;
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
console.error(errorMessage, error)
|
console.error(errorMessage, error)
|
||||||
})
|
})
|
||||||
.finally(() => this.isLoadingSubject.next(false));
|
.finally(() => this.#isLoading.set(false));
|
||||||
|
} else {
|
||||||
|
this.#snackBar.open($localize`A technical error occurred while loading publication data.`, $localize`Close`, {duration: 5000});
|
||||||
|
this.#location.back();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
this.subscriptions.forEach(subscription => subscription?.unsubscribe());
|
|
||||||
}
|
|
||||||
|
|
||||||
onPublicationSave(publication: Publication): void {
|
onPublicationSave(publication: Publication): void {
|
||||||
this.isSavingSubject.next(true);
|
this.#isSavingSubject.set(true);
|
||||||
this.publicationRestService.update(publication)
|
this.#publicationRestService.update(publication)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.snackBar.open($localize`Publication updated succesfully!`, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open($localize`Publication updated succesfully!`, $localize`Close`, {duration: 5000});
|
||||||
this.router.navigate(['/home']);
|
this.#router.navigate(['/home']);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occured while saving publication modifications.`;
|
const errorMessage = $localize`An error occured while saving publication modifications.`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
})
|
})
|
||||||
.finally(() => this.isSavingSubject.next(false));
|
.finally(() => this.#isSavingSubject.set(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
@if (isLoading) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Publication content loading...</h2>
|
<h2 i18n>Publication content loading...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner></mat-spinner>
|
||||||
} @else {
|
} @else {
|
||||||
@if (publication) {
|
@if (publication(); as publication) {
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<img src="/api/pictures/{{ publication.illustrationId }}"/>
|
<img src="/api/pictures/{{ publication.illustrationId }}"/>
|
||||||
<header>
|
<header>
|
||||||
<h1>{{ publication.title }}</h1>
|
<h1>{{ publication.title }}</h1>
|
||||||
<h2>{{ publication.description }}</h2>
|
<h2>{{ publication.description }}</h2>
|
||||||
@if (isAuthorAndUserEquals) {
|
@if (isAuthorAndUserEquals()) {
|
||||||
<a [routerLink]="['edit']"
|
<a [routerLink]="['edit']"
|
||||||
class="button action"
|
class="button action"
|
||||||
matTooltip="Click to edit the publication"
|
matTooltip="Click to edit the publication"
|
||||||
|
matRipple
|
||||||
i18n-matTooltip>
|
i18n-matTooltip>
|
||||||
<mat-icon>edit</mat-icon>
|
<mat-icon>edit</mat-icon>
|
||||||
</a>
|
</a>
|
||||||
@@ -28,11 +29,12 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@if (isAuthorAndUserEquals) {
|
@if (isAuthorAndUserEquals()) {
|
||||||
<button type="button"
|
<button type="button"
|
||||||
(click)="deletePublication()"
|
(click)="deletePublication()"
|
||||||
matTooltip="Click to delete the publication"
|
matTooltip="Click to delete the publication"
|
||||||
matTooltipPosition="left"
|
matTooltipPosition="left"
|
||||||
|
matRipple
|
||||||
i18n-matTooltip>
|
i18n-matTooltip>
|
||||||
<mat-icon>delete</mat-icon>
|
<mat-icon>delete</mat-icon>
|
||||||
Delete
|
Delete
|
||||||
|
|||||||
@@ -1,25 +1,32 @@
|
|||||||
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
|
||||||
import { PublicationRestService } from '../../core/rest-services/publications/publication.rest-service';
|
|
||||||
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
|
||||||
import { Subscription } from 'rxjs';
|
|
||||||
import { Publication } from '../../core/rest-services/publications/model/publication';
|
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
||||||
import {CommonModule, Location} from '@angular/common';
|
import {CommonModule, Location} from '@angular/common';
|
||||||
import { MatProgressSpinner } from '@angular/material/progress-spinner';
|
import {Component, inject, OnDestroy, OnInit, signal} from '@angular/core';
|
||||||
import { MatTooltip, MatTooltipModule } from '@angular/material/tooltip';
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
import { MatIcon } from '@angular/material/icon';
|
|
||||||
import { AuthenticationService } from '../../core/service/authentication.service';
|
|
||||||
import {MatDialog} from '@angular/material/dialog';
|
import {MatDialog} from '@angular/material/dialog';
|
||||||
|
import {MatIcon} from '@angular/material/icon';
|
||||||
|
import {MatProgressSpinner} from '@angular/material/progress-spinner';
|
||||||
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||||
|
import {MatTooltipModule} from '@angular/material/tooltip';
|
||||||
|
import {ActivatedRoute, RouterModule} from '@angular/router';
|
||||||
|
import {Subscription} from 'rxjs';
|
||||||
import {ConfirmationDialog} from '../../components/confirmation-dialog/confirmation-dialog.component';
|
import {ConfirmationDialog} from '../../components/confirmation-dialog/confirmation-dialog.component';
|
||||||
|
import {Publication} from '../../core/rest-services/publications/model/publication';
|
||||||
|
import {PublicationRestService} from '../../core/rest-services/publications/publication.rest-service';
|
||||||
|
import {AuthenticationService} from '../../core/service/authentication.service';
|
||||||
|
|
||||||
declare let Prism: any;
|
declare let Prism: any;
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication',
|
selector: 'app-publication',
|
||||||
standalone: true,
|
|
||||||
imports: [CommonModule, MatProgressSpinner, MatTooltip, RouterModule, MatIcon, MatTooltipModule],
|
|
||||||
templateUrl: './publication.component.html',
|
templateUrl: './publication.component.html',
|
||||||
styleUrl: './publication.component.scss'
|
styleUrl: './publication.component.scss',
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
MatIcon,
|
||||||
|
MatRippleModule,
|
||||||
|
MatProgressSpinner,
|
||||||
|
MatTooltipModule,
|
||||||
|
RouterModule
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class PublicationComponent implements OnInit, OnDestroy {
|
export class PublicationComponent implements OnInit, OnDestroy {
|
||||||
private readonly activatedRoute = inject(ActivatedRoute);
|
private readonly activatedRoute = inject(ActivatedRoute);
|
||||||
@@ -30,9 +37,9 @@ export class PublicationComponent implements OnInit, OnDestroy {
|
|||||||
private readonly snackBar = inject(MatSnackBar);
|
private readonly snackBar = inject(MatSnackBar);
|
||||||
private paramMapSubscription?: Subscription;
|
private paramMapSubscription?: Subscription;
|
||||||
private afterDialogCloseSubscription?: Subscription;
|
private afterDialogCloseSubscription?: Subscription;
|
||||||
isLoading: boolean = false;
|
isLoading = signal(false);
|
||||||
isAuthorAndUserEquals: boolean = false;
|
isAuthorAndUserEquals = signal(false);
|
||||||
publication?: Publication;
|
publication = signal<Publication | null>(null);
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.paramMapSubscription = this.activatedRoute
|
this.paramMapSubscription = this.activatedRoute
|
||||||
@@ -41,12 +48,12 @@ export class PublicationComponent implements OnInit, OnDestroy {
|
|||||||
const publicationId = params.get('publicationId');
|
const publicationId = params.get('publicationId');
|
||||||
|
|
||||||
if (publicationId) {
|
if (publicationId) {
|
||||||
this.isLoading = true;
|
this.isLoading.set(true);
|
||||||
|
|
||||||
this.publicationRestService.getById(publicationId)
|
this.publicationRestService.getById(publicationId)
|
||||||
.then(publication => {
|
.then(publication => {
|
||||||
this.publication = publication;
|
this.publication.set(publication);
|
||||||
this.isAuthorAndUserEquals = this.authenticationService.getAuthenticatedUser()?.id === this.publication.author.id;
|
this.isAuthorAndUserEquals.set(this.authenticationService.getAuthenticatedUser()?.id === this.publication()?.author.id);
|
||||||
setTimeout(() => Prism.highlightAll(), 100);
|
setTimeout(() => Prism.highlightAll(), 100);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@@ -55,7 +62,7 @@ export class PublicationComponent implements OnInit, OnDestroy {
|
|||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isLoading = false;
|
this.isLoading.set(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -79,8 +86,9 @@ export class PublicationComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.afterDialogCloseSubscription = dialogRef.afterClosed()
|
this.afterDialogCloseSubscription = dialogRef.afterClosed()
|
||||||
.subscribe(response => {
|
.subscribe(response => {
|
||||||
if (response && this.publication?.id) {
|
const publication = this.publication();
|
||||||
this.publicationRestService.delete(this.publication.id);
|
if (response && publication?.id) {
|
||||||
|
this.publicationRestService.delete(publication.id);
|
||||||
this.snackBar.open($localize`Publication deleted`, $localize`Close`, {duration: 5000});
|
this.snackBar.open($localize`Publication deleted`, $localize`Close`, {duration: 5000});
|
||||||
this.location.back();
|
this.location.back();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<h1 i18n>Search results</h1>
|
<h1 i18n>Search results</h1>
|
||||||
@if((isLoading$ | async) === true) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Search in progress...</h2>
|
<h2 i18n>Search in progress...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner/>
|
||||||
} @else if((isLoaded$ | async) === true) {
|
} @else if (isLoaded()) {
|
||||||
@if((publications$ | async)?.length) {
|
@if (publications().length) {
|
||||||
<app-publication-list [publications$]="publications$"></app-publication-list>
|
<app-publication-list [publications]="publications()"/>
|
||||||
} @else {
|
} @else {
|
||||||
<span i18n>No any result.</span>
|
<span i18n>No any result.</span>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,30 @@
|
|||||||
import {CommonModule} from "@angular/common";
|
import {CommonModule} from "@angular/common";
|
||||||
import { Component, inject, OnDestroy, OnInit } from "@angular/core";
|
import {Component, effect, inject} from "@angular/core";
|
||||||
import {MatProgressSpinner} from "@angular/material/progress-spinner";
|
import {MatProgressSpinner} from "@angular/material/progress-spinner";
|
||||||
import {ActivatedRoute} from "@angular/router";
|
import {ActivatedRoute} from "@angular/router";
|
||||||
import { Observable, Subscription } from "rxjs";
|
|
||||||
import {PublicationListComponent} from "../../components/publication-list/publication-list.component";
|
import {PublicationListComponent} from "../../components/publication-list/publication-list.component";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
|
||||||
import {SearchPublicationsService} from "./search-publications.service";
|
import {SearchPublicationsService} from "./search-publications.service";
|
||||||
|
import {toSignal} from "@angular/core/rxjs-interop";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-search-publications',
|
selector: 'app-search-publications',
|
||||||
templateUrl: './search-publications.component.html',
|
templateUrl: './search-publications.component.html',
|
||||||
styleUrl: './search-publications.component.scss',
|
styleUrl: './search-publications.component.scss',
|
||||||
standalone: true,
|
|
||||||
imports: [CommonModule, MatProgressSpinner, PublicationListComponent],
|
imports: [CommonModule, MatProgressSpinner, PublicationListComponent],
|
||||||
providers: [SearchPublicationsService]
|
providers: [SearchPublicationsService]
|
||||||
})
|
})
|
||||||
export class SearchPublicationsComponent implements OnInit, OnDestroy {
|
export class SearchPublicationsComponent {
|
||||||
private searchPublicationsService = inject(SearchPublicationsService);
|
private searchPublicationsService = inject(SearchPublicationsService);
|
||||||
private activatedRoute = inject(ActivatedRoute);
|
private activatedRoute = inject(ActivatedRoute);
|
||||||
private queryParamsSubscription?: Subscription;
|
publications = this.searchPublicationsService.publications;
|
||||||
|
isLoading = this.searchPublicationsService.isLoading;
|
||||||
|
isLoaded = this.searchPublicationsService.isLoaded;
|
||||||
|
|
||||||
ngOnInit(): void {
|
constructor() {
|
||||||
this.queryParamsSubscription = this.activatedRoute.queryParamMap
|
const queryParams = toSignal(this.activatedRoute.queryParamMap);
|
||||||
.subscribe(params => {
|
effect(() => {
|
||||||
|
let params = queryParams();
|
||||||
|
if (params) {
|
||||||
const categoryId = params.get('category-id');
|
const categoryId = params.get('category-id');
|
||||||
if (categoryId) {
|
if (categoryId) {
|
||||||
this.searchPublicationsService.loadPublications(`category_id=${categoryId}`);
|
this.searchPublicationsService.loadPublications(`category_id=${categoryId}`);
|
||||||
@@ -31,22 +33,7 @@ export class SearchPublicationsComponent implements OnInit, OnDestroy {
|
|||||||
if (query) {
|
if (query) {
|
||||||
this.searchPublicationsService.loadPublications(query);
|
this.searchPublicationsService.loadPublications(query);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
this.queryParamsSubscription?.unsubscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
|
||||||
return this.searchPublicationsService.publications$;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
|
||||||
return this.searchPublicationsService.isLoading$;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoaded$(): Observable<boolean> {
|
|
||||||
return this.searchPublicationsService.isLoaded$;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,49 +1,47 @@
|
|||||||
import { inject, Injectable } from "@angular/core";
|
import {inject, Injectable, Signal, signal} from "@angular/core";
|
||||||
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import { BehaviorSubject, Observable } from "rxjs";
|
|
||||||
import {Publication} from "../../core/rest-services/publications/model/publication";
|
import {Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SearchPublicationsService {
|
export class SearchPublicationsService {
|
||||||
private publicationRestService = inject(PublicationRestService);
|
#snackBar = inject(MatSnackBar);
|
||||||
private publicationsSubject = new BehaviorSubject<Publication[]>([]);
|
#publicationRestService = inject(PublicationRestService);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#publications = signal<Publication[]>([]);
|
||||||
private isLoadedSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private snackBar = inject(MatSnackBar);
|
#isLoaded = signal(false);
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
get publications(): Signal<Publication[]> {
|
||||||
return this.publicationsSubject.asObservable();
|
return this.#publications.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
get isLoading(): Signal<boolean> {
|
||||||
return this.isLoadingSubject.asObservable();
|
return this.#isLoading.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isLoaded$(): Observable<boolean> {
|
get isLoaded(): Signal<boolean> {
|
||||||
return this.isLoadedSubject.asObservable();
|
return this.#isLoaded.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPublications(searchCriteria: string): void {
|
loadPublications(searchCriteria: string): void {
|
||||||
this.isLoadingSubject.next(true);
|
this.#isLoading.set(true);
|
||||||
this.isLoadedSubject.next(false);
|
this.#isLoaded.set(false);
|
||||||
this.publicationsSubject.next([]);
|
this.#publications.set([]);
|
||||||
|
|
||||||
this.publicationRestService.search(searchCriteria)
|
this.#publicationRestService.search(searchCriteria)
|
||||||
.then(publications => {
|
.then(publications => {
|
||||||
this.publicationsSubject.next(publications);
|
this.#publications.set(publications);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error.status !== 404) {
|
if (error.status !== 404) {
|
||||||
const errorMessage = $localize`An error occured while retrieving publications.`;
|
const errorMessage = $localize`An error occured while retrieving publications.`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isLoadingSubject.next(false);
|
this.#isLoading.set(false);
|
||||||
this.isLoadedSubject.next(true);
|
this.#isLoaded.set(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<form [formGroup]="signinForm" (submit)="performSignin()" ngNativeValidate>
|
<form [formGroup]="signinForm" (submit)="performSignin()" class="cod-form card" ngNativeValidate>
|
||||||
<h1 i18n>Signin</h1>
|
<h1 i18n>Signin</h1>
|
||||||
<div>
|
<div class="form-field">
|
||||||
<mat-icon>person</mat-icon>
|
<mat-icon>person</mat-icon>
|
||||||
<label for="pseudo" i18n>
|
<label for="pseudo" i18n>
|
||||||
Pseudo
|
Pseudo
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<input type="text" id="pseudo" formControlName="pseudo" autocomplete="pseudo" required/>
|
<input type="text" id="pseudo" formControlName="pseudo" autocomplete="pseudo" required/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="form-field">
|
||||||
<mat-icon>mail</mat-icon>
|
<mat-icon>mail</mat-icon>
|
||||||
<label for="email" i18n>
|
<label for="email" i18n>
|
||||||
Email address
|
Email address
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<input type="email" id="email" formControlName="email" autocomplete="email" required/>
|
<input type="email" id="email" formControlName="email" autocomplete="email" required/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="form-field">
|
||||||
<mat-icon>lock</mat-icon>
|
<mat-icon>lock</mat-icon>
|
||||||
<label for="password" i18n>
|
<label for="password" i18n>
|
||||||
Password
|
Password
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<input type="password" id="password" formControlName="password" required/>
|
<input type="password" id="password" formControlName="password" required/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="form-field">
|
||||||
<mat-icon>lock</mat-icon>
|
<mat-icon>lock</mat-icon>
|
||||||
<label for="confirm-password" i18n>
|
<label for="confirm-password" i18n>
|
||||||
Confirm password
|
Confirm password
|
||||||
@@ -32,8 +32,8 @@
|
|||||||
</label>
|
</label>
|
||||||
<input type="password" id="confirm-password" formControlName="confirmPassword" required/>
|
<input type="password" id="confirm-password" formControlName="confirmPassword" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions reversed">
|
||||||
<button type="submit" i18n>Send</button>
|
<app-submit-button [requestPending]="false" [disabled]="false" i18n>Send</app-submit-button>
|
||||||
<a [routerLink]="['/login']" i18n>I already have an account</a>
|
<a [routerLink]="['/login']" class="cod-button secondary" matRipple i18n>I already have an account</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -4,79 +4,4 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
|
|
||||||
form {
|
|
||||||
width: 80%;
|
|
||||||
max-width: 20em;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 1em;
|
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
|
||||||
border-radius: .5em;
|
|
||||||
padding: 1em 1.5em;
|
|
||||||
background-color: #ffffff;
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
div {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
position: relative;
|
|
||||||
gap: .1em;
|
|
||||||
|
|
||||||
mat-icon {
|
|
||||||
position: absolute;
|
|
||||||
top: 1.3em;
|
|
||||||
left: .5em;
|
|
||||||
color: #777;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.actions {
|
|
||||||
flex-direction: row-reverse;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
button {
|
|
||||||
padding: .8em 1.2em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5b6ed8;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: #3f51b5;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
label {
|
|
||||||
flex: 1;
|
|
||||||
font-style: italic;
|
|
||||||
padding-left: 1em;
|
|
||||||
color: #777;
|
|
||||||
|
|
||||||
.required {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
|
||||||
flex: 1;
|
|
||||||
background-color: #eeeeee;
|
|
||||||
border: none;
|
|
||||||
border-radius: 10em;
|
|
||||||
padding: 1em 1em 1em 3em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,25 @@
|
|||||||
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||||
import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
import {MatIconModule} from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import {RouterModule} from '@angular/router';
|
import {RouterModule} from '@angular/router';
|
||||||
import { Subscription, debounceTime, distinctUntilChanged, map } from 'rxjs';
|
import {debounceTime, distinctUntilChanged, map, Subscription} from 'rxjs';
|
||||||
import {SigninService} from './signin.service';
|
import {SigninService} from './signin.service';
|
||||||
import {LoginService} from '../login/login.service';
|
import {LoginService} from '../login/login.service';
|
||||||
import {FormError} from '../../core/model/FormError';
|
import {FormError} from '../../core/model/FormError';
|
||||||
|
import {SubmitButtonComponent} from "../../components/submit-button/submit-button.component";
|
||||||
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-signin',
|
selector: 'app-signin',
|
||||||
standalone: true,
|
|
||||||
imports: [ReactiveFormsModule, MatIconModule, RouterModule],
|
|
||||||
templateUrl: './signin.component.html',
|
templateUrl: './signin.component.html',
|
||||||
styleUrl: './signin.component.scss',
|
styleUrl: './signin.component.scss',
|
||||||
|
imports: [
|
||||||
|
MatIconModule,
|
||||||
|
MatRippleModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
RouterModule,
|
||||||
|
SubmitButtonComponent
|
||||||
|
],
|
||||||
providers: [SigninService, LoginService]
|
providers: [SigninService, LoginService]
|
||||||
})
|
})
|
||||||
export class SigninComponent implements OnInit, OnDestroy {
|
export class SigninComponent implements OnInit, OnDestroy {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {SigninRequest} from '../../core/rest-services/user/model/signin.model';
|
import {SigninRequest} from '../../core/rest-services/user/model/signin.model';
|
||||||
import {FormError} from '../../core/model/FormError';
|
import {FormError} from '../../core/model/FormError';
|
||||||
import {BehaviorSubject, Observable} from 'rxjs';
|
import {BehaviorSubject, Observable} from 'rxjs';
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user