Updated Admin Panel
This commit is contained in:
1 parent
60b489ab7c
commit
d83992d3ce
3 files changed
+94
-31
No files matched your search
@@ -45,7 +45,9 @@
|
|||||||
|
|
||||||
.admin-dashboard-tile,
|
.admin-dashboard-tile,
|
||||||
.create-article-tile,
|
.create-article-tile,
|
||||||
.articles-list-tile {
|
.articles-list-tile,
|
||||||
|
.delete-article-tile,
|
||||||
|
.edit-article-tile {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border-radius: 25px;
|
border-radius: 25px;
|
||||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
@@ -63,7 +65,38 @@
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.edit-article-tile {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
max-width: 400px;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#editId, #editTitle {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
#editId {
|
||||||
|
max-width: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#editTitle {
|
||||||
|
margin-left: 30px;
|
||||||
|
max-width: 230px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-article-tile {
|
||||||
|
margin-bottom: 30px;
|
||||||
|
max-width: 300px;
|
||||||
|
}
|
||||||
|
.delete-article-tile input {
|
||||||
|
max-width: 80px;
|
||||||
|
margin-right: 20px;
|
||||||
|
margin-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.articles-list-tile {
|
.articles-list-tile {
|
||||||
|
margin-top: 30px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
max-width: 300px;
|
max-width: 300px;
|
||||||
}
|
}
|
||||||
@@ -77,7 +110,7 @@ textarea {
|
|||||||
border-radius: 25px;
|
border-radius: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.admin-actions button, .create-article-tile button {
|
.admin-actions button, .create-article-tile button, .delete-article-tile button, .edit-article-tile button {
|
||||||
background-color: #bd3948;
|
background-color: #bd3948;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 12px 20px;
|
padding: 12px 20px;
|
||||||
@@ -87,10 +120,15 @@ textarea {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.admin-actions button:hover, .create-article-tile button:hover {
|
.admin-actions button:hover:enabled, .create-article-tile button:hover:enabled, .delete-article-tile button:hover:enabled, .edit-article-tile button:hover:enabled {
|
||||||
background-color: #e3485a;
|
background-color: #e3485a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.create-article-tile button:disabled, .delete-article-tile button:disabled, .edit-article-tile button:disabled {
|
||||||
|
background-color: #ccc;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
.admin-actions button.logout {
|
.admin-actions button.logout {
|
||||||
background-color: #713252;
|
background-color: #713252;
|
||||||
color: white;
|
color: white;
|
||||||
|
|||||||
@@ -3,7 +3,22 @@
|
|||||||
<!-- Left Section: Placeholder -->
|
<!-- Left Section: Placeholder -->
|
||||||
<ng-container *ngIf="!isMobile">
|
<ng-container *ngIf="!isMobile">
|
||||||
<div class="left-section">
|
<div class="left-section">
|
||||||
<!-- Placeholder for future content -->
|
<div class="delete-article-tile">
|
||||||
|
<h2>Delete Article</h2>
|
||||||
|
<form #deleteForm="ngForm" id="deleteForm" (ngSubmit)="deleteArticle(deleteForm)">
|
||||||
|
<input id="deleteId" type="number" min="1" required name="deleteId" ngModel placeholder="Article ID">
|
||||||
|
<button type="submit" [disabled]="deleteForm.invalid">Delete Article</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="edit-article-tile">
|
||||||
|
<h2>Edit Article</h2>
|
||||||
|
<form #editForm="ngForm" id="editForm" (ngSubmit)="editArticle(editForm)">
|
||||||
|
<input id="editId" type="number" min="1" required name="editId" ngModel placeholder="Article ID">
|
||||||
|
<input id="editTitle" type="text" name="editTitle" ngModel placeholder="Edit Title (Optional)"><br>
|
||||||
|
<textarea id="editContent" type="text" name="editContent" placeholder="Edit Content (Optional)"></textarea>
|
||||||
|
<button type="submit" [disabled]="editForm.invalid">Edit Article</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<!-- Center Section: Admin Dashboard and Create Article Tiles -->
|
<!-- Center Section: Admin Dashboard and Create Article Tiles -->
|
||||||
@@ -11,8 +26,6 @@
|
|||||||
<div class="admin-dashboard-tile">
|
<div class="admin-dashboard-tile">
|
||||||
<h2>Admin Dashboard</h2>
|
<h2>Admin Dashboard</h2>
|
||||||
<div class="admin-actions">
|
<div class="admin-actions">
|
||||||
<button (click)="editArticle()">Edit Article</button>
|
|
||||||
<button (click)="deleteArticle()">Delete Article</button>
|
|
||||||
<button class="logout" (click)="logout()">Logout</button>
|
<button class="logout" (click)="logout()">Logout</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -20,19 +33,29 @@
|
|||||||
|
|
||||||
<div class="create-article-tile">
|
<div class="create-article-tile">
|
||||||
<h2>Create New Article</h2>
|
<h2>Create New Article</h2>
|
||||||
<form (ngSubmit)="createArticle()">
|
<form #createForm="ngForm" (ngSubmit)="createArticle(createForm)">
|
||||||
<div>
|
<input type="text" id="title" name="title" required ngModel placeholder="Article Title"/><br>
|
||||||
<label for="title">Title:</label>
|
<textarea id="content" name="content" required ngModel placeholder="Article Content"></textarea>
|
||||||
<input type="text" id="title" [(ngModel)]="title" name="title" required />
|
<button type="submit" [disabled]="createForm.invalid">Create Article</button>
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="content">Content:</label>
|
|
||||||
<textarea id="content" [(ngModel)]="content" name="content" required></textarea>
|
|
||||||
</div>
|
|
||||||
<button type="submit" [disabled]="!title || !content">Create Article</button>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<ng-container *ngIf="isMobile">
|
<ng-container *ngIf="isMobile">
|
||||||
|
<div class="delete-article-tile">
|
||||||
|
<h2>Delete Article</h2>
|
||||||
|
<form #deleteFormMobile="ngForm" id="deleteFormMobile" (ngSubmit)="deleteArticle(deleteFormMobile)">
|
||||||
|
<input id="deleteIdMobile" type="number" min="1" required name="deleteId" ngModel placeholder="Article ID">
|
||||||
|
<button type="submit" [disabled]="deleteFormMobile.invalid">Delete Article</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="edit-article-tile">
|
||||||
|
<h2>Edit Article</h2>
|
||||||
|
<form #editFormMobile="ngForm" id="editFormMobile" (ngSubmit)="editArticle(editFormMobile)">
|
||||||
|
<input id="editIdMobile" type="number" min="1" required name="editId" ngModel placeholder="Article ID">
|
||||||
|
<input id="editTitleMobile" type="text" name="editTitle" ngModel placeholder="Edit Title (Optional)"><br>
|
||||||
|
<textarea id="editContentMobile" type="text" name="editContent" placeholder="Edit Content (Optional)"></textarea>
|
||||||
|
<button type="submit" [disabled]="editFormMobile.invalid">Edit Article</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<div class="articles-list-tile">
|
<div class="articles-list-tile">
|
||||||
<h2>Articles</h2>
|
<h2>Articles</h2>
|
||||||
<div *ngIf="noArticles">
|
<div *ngIf="noArticles">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {Component, OnInit} from '@angular/core';
|
|||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import {ArticleService} from '../services/article.service';
|
import {ArticleService} from '../services/article.service';
|
||||||
import {NgFor, NgIf, NgStyle} from '@angular/common';
|
import {NgFor, NgIf, NgStyle} from '@angular/common';
|
||||||
import {Observer} from 'rxjs';
|
import { Observer} from 'rxjs';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||||
import {Title} from '@angular/platform-browser';
|
import {Title} from '@angular/platform-browser';
|
||||||
@@ -59,18 +59,21 @@ export class AdminComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
createArticle() {
|
createArticle(form: any) {
|
||||||
if (!this.token) {
|
if (!this.token) {
|
||||||
this.navigateToLogin();
|
this.navigateToLogin();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.title || !this.content) {
|
const title = form.value.title;
|
||||||
|
const content = form.value.content;
|
||||||
|
|
||||||
|
if (!title || !content) {
|
||||||
alert('Both title and content are required!');
|
alert('Both title and content are required!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.articleService.postArticle(this.token, this.title, this.content).subscribe(
|
this.articleService.postArticle(this.token, title, content).subscribe(
|
||||||
(response) => {
|
(response) => {
|
||||||
alert('Article created successfully!');
|
alert('Article created successfully!');
|
||||||
this.loadArticles();
|
this.loadArticles();
|
||||||
@@ -83,13 +86,13 @@ export class AdminComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
editArticle(): void {
|
editArticle(form: any): void {
|
||||||
if (!this.token) {
|
if (!this.token) {
|
||||||
this.navigateToLogin();
|
this.navigateToLogin();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const articleId = prompt('Enter the article ID to edit:');
|
const articleId = form.value.editId;
|
||||||
|
|
||||||
if (articleId && !isNaN(Number(articleId))) {
|
if (articleId && !isNaN(Number(articleId))) {
|
||||||
const id = Number(articleId);
|
const id = Number(articleId);
|
||||||
@@ -103,8 +106,8 @@ export class AdminComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prompt for title and content with placeholders
|
// Prompt for title and content with placeholders
|
||||||
const newTitle = prompt('Enter the new title (Leave blank to leave as is):');
|
const newTitle = form.value.editTitle || form.value.editTitleMobile;
|
||||||
const newContent = prompt('Enter the new content (Leave blank to leave as is):');
|
const newContent = form.value.editContent || form.value.editContentMobile;
|
||||||
|
|
||||||
// Use current values if left blank
|
// Use current values if left blank
|
||||||
const updatedTitle = newTitle?.trim() || article.title;
|
const updatedTitle = newTitle?.trim() || article.title;
|
||||||
@@ -130,23 +133,22 @@ export class AdminComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteArticle(): void {
|
deleteArticle(form: any): void {
|
||||||
if (!this.token) {
|
if (!this.token) {
|
||||||
this.navigateToLogin();
|
this.navigateToLogin();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const articleId = prompt('Enter the article ID to delete:');
|
|
||||||
|
const articleId = form.value.deleteId || form.value.deleteIdMobile;
|
||||||
|
|
||||||
if (articleId && !isNaN(Number(articleId))) {
|
if (articleId && !isNaN(Number(articleId))) {
|
||||||
const id = Number(articleId);
|
this.articleService.deleteArticle(articleId, this.token).subscribe(
|
||||||
|
|
||||||
this.articleService.deleteArticle(id, this.token).subscribe(
|
|
||||||
() => {
|
() => {
|
||||||
alert(`Article ${id} deleted successfully`);
|
alert(`Article ${articleId} deleted successfully`);
|
||||||
this.loadArticles();
|
this.loadArticles();
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
alert(`Error deleting article ${id}: ${error.message}`);
|
alert(`Error deleting article ${articleId}: ${error.message}`);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user