Add button to edit publications on publication view page.
This commit is contained in:
@@ -40,7 +40,6 @@
|
|||||||
|
|
||||||
</mat-tab>
|
</mat-tab>
|
||||||
</mat-tab-group>
|
</mat-tab-group>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<app-submit-button label="Save" [requestPending]="(isSaving$ | async) == true"></app-submit-button>
|
<app-submit-button label="Save" [requestPending]="(isSaving$ | async) == true"></app-submit-button>
|
||||||
<button type="button" class="secondary" (click)="goPreviousLocation()">
|
<button type="button" class="secondary" (click)="goPreviousLocation()">
|
||||||
|
|||||||
@@ -128,17 +128,16 @@ export class PublicationEditionService implements OnDestroy {
|
|||||||
const publication = this._publication;
|
const publication = this._publication;
|
||||||
|
|
||||||
this.isSavingSubject.next(true);
|
this.isSavingSubject.next(true);
|
||||||
setTimeout(() => this.isSavingSubject.next(false), 1500);
|
this.publicationRestService.update(publication)
|
||||||
// this.publicationRestService.update(publication)
|
.then(() => {
|
||||||
// .then(() => {
|
this.snackBar.open('Publication updated succesfully!', 'Close', { duration: 5000 });
|
||||||
// this.snackBar.open('Publication updated succesfully!', 'Close', { duration: 5000 });
|
this.router.navigate(['/home']);
|
||||||
// this.router.navigate(['/home']);
|
})
|
||||||
// })
|
.catch(error => {
|
||||||
// .catch(error => {
|
const errorMessage = 'An error occured while saving publication modifications.';
|
||||||
// const errorMessage = 'An error occured while saving publication modifications.';
|
console.error(errorMessage, error);
|
||||||
// console.error(errorMessage, error);
|
this.snackBar.open(errorMessage, 'Close', { duration: 5000 });
|
||||||
// this.snackBar.open(errorMessage, 'Close', { duration: 5000 });
|
})
|
||||||
// })
|
.finally(() => this.isSavingSubject.next(false));
|
||||||
// .finally(() => this.isSavingSubject.next(false));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
<ng-container *ngIf="isLoading; else afterLoadingPart">
|
@if (isLoading) {
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner></mat-spinner>
|
||||||
</ng-container>
|
} @else {
|
||||||
|
@if (publication) {
|
||||||
<ng-template #afterLoadingPart>
|
|
||||||
<ng-container *ngIf="publication; else loadingFailedMessage">
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<img src="/pictures/{{ publication.illustrationId }}" />
|
<img src="/pictures/{{ publication.illustrationId }}" />
|
||||||
<header>
|
<header>
|
||||||
<h1>{{ publication.title }}</h1>
|
<h1>{{ publication.title }}</h1>
|
||||||
<h2>{{ publication.description }}</h2>
|
<h2>{{ publication.description }}</h2>
|
||||||
|
@if (isAuthorAndUserEquals) {
|
||||||
|
<a [routerLink]="['edit']" class="button action" matTooltip="Click to edit the publication">
|
||||||
|
<mat-icon>edit</mat-icon>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
</header>
|
</header>
|
||||||
<main [innerHTML]="publication.parsedText"></main>
|
<main [innerHTML]="publication.parsedText"></main>
|
||||||
<footer>
|
<footer>
|
||||||
@@ -19,11 +22,9 @@
|
|||||||
</span>
|
</span>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
} @else {
|
||||||
|
|
||||||
<ng-template #loadingFailedMessage>
|
|
||||||
<div class="loading-failed">
|
<div class="loading-failed">
|
||||||
<h1>Publication failed to load...</h1>
|
<h1>Publication failed to load...</h1>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
}
|
||||||
</ng-template>
|
}
|
||||||
@@ -34,6 +34,7 @@ $cardBorderRadius: .5em;
|
|||||||
|
|
||||||
header {
|
header {
|
||||||
padding: 2em;
|
padding: 2em;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
@@ -46,6 +47,26 @@ $cardBorderRadius: .5em;
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
padding: .8em .8em;
|
||||||
|
border-radius: 10em;
|
||||||
|
border: none;
|
||||||
|
background-color: #3f51b5;
|
||||||
|
color: white;
|
||||||
|
transition: background-color .2s ease-in-out;
|
||||||
|
position: absolute;
|
||||||
|
top: -1.5em;
|
||||||
|
right: 3em;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #5b6ed8;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|||||||
@@ -1,26 +1,30 @@
|
|||||||
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
||||||
import { PublicationRestService } from '../../core/rest-services/publications/publication.rest-service';
|
import { PublicationRestService } from '../../core/rest-services/publications/publication.rest-service';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute, RouterModule } from '@angular/router';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } 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';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { MatProgressSpinner } from '@angular/material/progress-spinner';
|
import { MatProgressSpinner } from '@angular/material/progress-spinner';
|
||||||
import { MatTooltip } from '@angular/material/tooltip';
|
import { MatTooltip, MatTooltipModule } from '@angular/material/tooltip';
|
||||||
|
import { MatIcon } from '@angular/material/icon';
|
||||||
|
import { AuthenticationService } from '../../core/service/authentication.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication',
|
selector: 'app-publication',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, MatProgressSpinner, MatTooltip],
|
imports: [CommonModule, MatProgressSpinner, MatTooltip, RouterModule, MatIcon, MatTooltipModule],
|
||||||
templateUrl: './publication.component.html',
|
templateUrl: './publication.component.html',
|
||||||
styleUrl: './publication.component.scss'
|
styleUrl: './publication.component.scss'
|
||||||
})
|
})
|
||||||
export class PublicationComponent implements OnInit, OnDestroy {
|
export class PublicationComponent implements OnInit, OnDestroy {
|
||||||
private activatedRoute = inject(ActivatedRoute);
|
private activatedRoute = inject(ActivatedRoute);
|
||||||
|
private authenticationService = inject(AuthenticationService);
|
||||||
private publicationRestService = inject(PublicationRestService);
|
private publicationRestService = inject(PublicationRestService);
|
||||||
private paramMapSubscription?: Subscription;
|
private paramMapSubscription?: Subscription;
|
||||||
private snackBar = inject(MatSnackBar);
|
private snackBar = inject(MatSnackBar);
|
||||||
isLoading: boolean = false;
|
isLoading: boolean = false;
|
||||||
|
isAuthorAndUserEquals: boolean = false;
|
||||||
publication?: Publication;
|
publication?: Publication;
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@@ -35,6 +39,7 @@ export class PublicationComponent implements OnInit, OnDestroy {
|
|||||||
this.publicationRestService.getById(publicationId)
|
this.publicationRestService.getById(publicationId)
|
||||||
.then(publication => {
|
.then(publication => {
|
||||||
this.publication = publication;
|
this.publication = publication;
|
||||||
|
this.isAuthorAndUserEquals = this.authenticationService.getAuthenticatedUser()?.id === this.publication.author.id;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.snackBar.open('An error occurred while loading publication...', 'Close', { duration: 5000 });
|
this.snackBar.open('An error occurred while loading publication...', 'Close', { duration: 5000 });
|
||||||
@@ -45,8 +50,6 @@ export class PublicationComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// this.publicationRestService.getById()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user