admin page rework
This commit is contained in:
1 parent
a9794bc5ba
commit
8ea703d780
9 files changed
+1041
-439
No files matched your search
+275
-131
@@ -1,153 +1,322 @@
|
||||
@keyframes fadeIn {
|
||||
0% {
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
|
||||
#admin-bg {
|
||||
animation: fadeIn 1s ease-out;
|
||||
#main-container {
|
||||
background: #39354a;
|
||||
position: fixed;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
z-index: -100;
|
||||
overflow-y: auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.height-container {
|
||||
.dashboard-titlebar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
width: 100vw;
|
||||
overflow-y: auto;
|
||||
height: 63px;
|
||||
}
|
||||
|
||||
.center-section,
|
||||
.left-section,
|
||||
.title h2 {
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
img {
|
||||
height: 50px;
|
||||
margin-bottom: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.main-separator {
|
||||
margin-top: 5px;
|
||||
height: 6px;
|
||||
width: 100%;
|
||||
background: #26262c;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.right-separator {
|
||||
margin-top: 5px;
|
||||
height: 6px;
|
||||
width: 100%;
|
||||
background: #202025;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.main-section,
|
||||
.right-section {
|
||||
position: fixed;
|
||||
height: 100vh !important;
|
||||
padding: 15px;
|
||||
color: white;
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
box-sizing: border-box
|
||||
}
|
||||
|
||||
.main-section {
|
||||
top: 0;
|
||||
left: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
background: #202025;
|
||||
}
|
||||
|
||||
.article-input-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 33.33%;
|
||||
padding: 30px;
|
||||
height: calc(100% - 74px);
|
||||
}
|
||||
|
||||
form {
|
||||
box-sizing: border-box;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
margin-top: 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.action-bar.mobile {
|
||||
flex-direction: column;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.action-bar.mobile #editTitle {
|
||||
width: 100%;
|
||||
margin: 0 0 15px 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.admin-dashboard-tile,
|
||||
.create-article-tile,
|
||||
.articles-list-tile,
|
||||
.delete-article-tile,
|
||||
.edit-article-tile {
|
||||
background: #fff;
|
||||
border-radius: 25px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
.action-bar.mobile #modeSel,
|
||||
.action-bar.mobile #articleId,
|
||||
.action-bar.mobile #submitBtn {
|
||||
margin: 15px 0 0 0;
|
||||
}
|
||||
|
||||
#articleId {
|
||||
margin-left: 15px;
|
||||
width: 60px;
|
||||
text-align: center;
|
||||
max-width: 400px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.admin-dashboard-tile,
|
||||
.create-article-tile {
|
||||
margin-bottom: 30px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
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;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.delete-article-tile {
|
||||
margin-bottom: 30px;
|
||||
max-width: 300px;
|
||||
}
|
||||
.delete-article-tile input, #editUserId, #deleteUserId {
|
||||
max-width: 80px;
|
||||
margin-right: 20px;
|
||||
margin-left: 20px;
|
||||
#submitBtn,
|
||||
#modeSel {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
margin: 0 0 0 15px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.articles-list-tile {
|
||||
margin-top: 30px;
|
||||
#submitBtn {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
#modeSel,
|
||||
#userSel{
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 150px;
|
||||
min-height: 50px;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
border-radius: 25px;
|
||||
background-image: url('/assets/arrow-down.svg');
|
||||
background-repeat: no-repeat;
|
||||
background-size: 24px 24px;
|
||||
background-position: calc(100% - 15px);
|
||||
padding-right: 24px;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.mode-select-button {
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.mode-dropdown {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 15px;
|
||||
width: 166px;
|
||||
background: #202025;
|
||||
border: 4px solid #202025;
|
||||
border-radius: 0 0 25px 25px;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 30px 0 10px 0;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.mode-dropdown li {
|
||||
padding: 10px;
|
||||
cursor: pointer;
|
||||
transition: all ease-in-out 0.2s;
|
||||
}
|
||||
|
||||
.mode-dropdown li:hover {
|
||||
color: #bc8fc5;
|
||||
}
|
||||
|
||||
#userForm input {
|
||||
margin: 6px;
|
||||
}
|
||||
|
||||
#userForm .mode-select-button {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
#userForm .mode-dropdown {
|
||||
left: 63px;
|
||||
width: 166px;
|
||||
}
|
||||
|
||||
#editContent {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
box-sizing: border-box
|
||||
}
|
||||
|
||||
.right-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 340px;
|
||||
background: #26262c;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.list-container {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.right-section ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
margin: 15px 0;
|
||||
overflow-y: auto;
|
||||
max-width: 300px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.right-section li {
|
||||
background: #202025;
|
||||
padding: 16px;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: all ease-in-out 0.2s;
|
||||
}
|
||||
|
||||
.right-section li:hover {
|
||||
color: #bc8fc5;
|
||||
background: #1c1c22;
|
||||
}
|
||||
|
||||
.right-section li:active {
|
||||
background: #22222e;
|
||||
}
|
||||
|
||||
.right-section li:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.sel-titlebar {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
height: 63px;
|
||||
}
|
||||
.sel-titlebar h2 {
|
||||
text-align: left;
|
||||
font-size: 1.4rem;
|
||||
margin: 10px;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.sel-titlebar div {
|
||||
}
|
||||
|
||||
input,
|
||||
textarea {
|
||||
width: 90%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 25px;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #bd3948;
|
||||
textarea,
|
||||
select {
|
||||
padding: 15px 20px;
|
||||
font-size: 0.9rem;
|
||||
font-family: "Roboto", sans-serif;
|
||||
color: white;
|
||||
padding: 12px 20px;
|
||||
margin: 10px;
|
||||
background: #26262c;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: all ease-in-out 0.2s;
|
||||
}
|
||||
|
||||
button:hover:enabled {
|
||||
background-color: #e3485a;
|
||||
textarea {
|
||||
resize: none;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
background-color: #ccc;
|
||||
input[type="number"]::-webkit-inner-spin-button,
|
||||
input[type="number"]::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
input[type="number"] {
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
|
||||
input:disabled,
|
||||
textarea:disabled {
|
||||
background-color: rgba(28, 21, 21, 0.25);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.admin-actions button.logout {
|
||||
background-color: #713252;
|
||||
input:focus,
|
||||
textarea:focus {
|
||||
outline: none;
|
||||
background: #2b2b32;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #8a6bbf;
|
||||
color: white;
|
||||
padding: 12px 20px;
|
||||
padding: 12px 22px;
|
||||
margin: 10px;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: all ease-in-out 0.2s;
|
||||
}
|
||||
|
||||
.admin-actions button.logout:hover {
|
||||
background-color: #592840;
|
||||
button:hover:enabled {
|
||||
background-color: #a36cff;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
background-color: #402929;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
button.toggle-button {
|
||||
background-color: transparent;
|
||||
padding: 0;
|
||||
color: #007bff;
|
||||
margin: 10px;
|
||||
color: #ab7cbd;
|
||||
margin: 0;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
@@ -156,44 +325,19 @@ button.toggle-button {
|
||||
}
|
||||
|
||||
button.toggle-button i {
|
||||
font-size: 27px;
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
button.toggle-button:hover:active, button.toggle-button:hover {
|
||||
background-color: transparent;
|
||||
color: #0056b3;
|
||||
color: #a24cba;
|
||||
}
|
||||
|
||||
.articles-list-tile ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
overflow-y: auto;
|
||||
max-height: 100%;
|
||||
button.logout {
|
||||
background-color: #713252;
|
||||
margin: 0 0 0 5px;
|
||||
}
|
||||
|
||||
.articles-list-tile li {
|
||||
border: 1px solid #ccc;
|
||||
padding: 10px;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.articles-list-tile li:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.articles-list-tile h2 {
|
||||
margin-bottom: 30px;
|
||||
transform: translateX( +15px);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.articles-list-tile {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: none;
|
||||
min-height: 100px;
|
||||
button.logout:hover {
|
||||
background-color: #592840;
|
||||
}
|
||||
+170
-181
@@ -1,200 +1,189 @@
|
||||
<div id="admin-bg">
|
||||
<div class="height-container">
|
||||
<!-- Left Section: Edit/Delete Article -->
|
||||
@if (!isNarrow) {
|
||||
<div class="left-section">
|
||||
<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" ngModel placeholder="Edit Content (Optional)"></textarea>
|
||||
<button type="submit" [disabled]="editForm.invalid">Edit Article</button>
|
||||
</form>
|
||||
<div id="main-container">
|
||||
<!-- Main Section -->
|
||||
<div class="main-section" [ngStyle]="{'width': isNarrow ? '100%' : 'calc(100% - 340px)'}">
|
||||
<div class="dashboard-titlebar" [ngStyle]="{'justify-content': isNarrow ? 'center' : 'space-between'}">
|
||||
<img alt="Logo" src="/assets/logo_m.svg" [routerLink]="'/'">
|
||||
@if (!isNarrow) {
|
||||
<div class="title">
|
||||
<h2>Admin Dashboard</h2>
|
||||
</div>
|
||||
}
|
||||
<div class="admin-actions">
|
||||
<button (click)="openUserModal()">Manage Users</button>
|
||||
<button class="logout" (click)="this.authService.logout()">Logout</button>
|
||||
</div>
|
||||
}
|
||||
<!-- Center Section: Admin Dashboard and Create Article Tiles -->
|
||||
<div class="center-section" [ngStyle]="{'width': isNarrow ? '100%' : '33.33%'}">
|
||||
<div class="admin-dashboard-tile">
|
||||
<h2>Admin Dashboard</h2>
|
||||
<div class="admin-actions">
|
||||
<button (click)="openModal('create')">Create User</button>
|
||||
<button (click)="openModal('edit')">Edit User</button>
|
||||
<button (click)="openModal('delete')">Delete User</button>
|
||||
<button class="logout" (click)="this.authService.logout()">Logout</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- User Actions Modal -->
|
||||
<app-modal
|
||||
[isOpen]="isModalOpen"
|
||||
[title]="modalTitle"
|
||||
(onClose)="closeModal()"
|
||||
<div class="main-separator"></div>
|
||||
|
||||
<div class="article-input-box">
|
||||
<form #articleForm="ngForm" (ngSubmit)="submitArticle(articleForm)" [ngStyle]="{'height': isNarrow ? 'calc(100% - 272px)' : 'calc(100% - 69px)'}">
|
||||
<div class="action-bar" [class.mobile]="isNarrow">
|
||||
<input
|
||||
id="editTitle"
|
||||
type="text"
|
||||
name="title"
|
||||
ngModel
|
||||
placeholder="Article Title"
|
||||
[required]="articleMode === 'create'"
|
||||
[disabled]="articleMode === 'delete'"
|
||||
/>
|
||||
<div class="mode-select-button" [ngStyle]="{'justify-content': isNarrow ? 'left' : 'center'}">
|
||||
<div id=modeSel (click)="toggleDropdown()" [ngStyle]="{'background-color': articleMode === 'create' ? '#78cd8b' : articleMode === 'edit' ? '#8e95e3' : '#ba243a'}">
|
||||
{{ articleMode | titlecase }} Article
|
||||
</div>
|
||||
@if (isDropdownOpen) {
|
||||
<ul class="mode-dropdown" [ngStyle]="{'left': isNarrow ? '0' : '15px'}">
|
||||
<li (click)="setMode('create')">Create Article</li>
|
||||
<li (click)="setMode('edit')">Edit Article</li>
|
||||
<li (click)="setMode('delete')">Delete Article</li>
|
||||
</ul>
|
||||
}
|
||||
</div>
|
||||
<input
|
||||
id="articleId"
|
||||
type="number"
|
||||
name="articleId"
|
||||
ngModel
|
||||
placeholder="Article ID"
|
||||
min="1"
|
||||
[required]="articleMode !== 'create'"
|
||||
[disabled]="articleMode === 'create'"
|
||||
/>
|
||||
<button
|
||||
id="submitBtn"
|
||||
type="submit"
|
||||
name="submit"
|
||||
[disabled]="articleForm.invalid"
|
||||
>
|
||||
@if (modalAction === 'create') {
|
||||
<form (submit)="createUser(createUserForm)" #createUserForm="ngForm" id="createUserForm">
|
||||
<input id="createUsername" ngModel required name="createUsername" placeholder="Username"/>
|
||||
<input id="createPassword" type="password" ngModel required name="createPassword" placeholder="Password"/>
|
||||
<button type="submit" [disabled]="createUserForm.invalid">Create User</button>
|
||||
</form>
|
||||
}
|
||||
{{ articleMode === 'create' ? 'Create' : articleMode === 'edit' ? 'Edit' : 'Delete' }}
|
||||
</button>
|
||||
</div>
|
||||
<textarea
|
||||
id="editContent"
|
||||
name="content"
|
||||
ngModel
|
||||
placeholder="Article Content"
|
||||
[required]="articleMode === 'create'"
|
||||
[disabled]="articleMode === 'delete'"
|
||||
>
|
||||
</textarea>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (modalAction === 'edit') {
|
||||
<form (submit)="editUser(editUserForm)" #editUserForm="ngForm" id="editUserForm">
|
||||
<input id="editUserId" type="number" min="1" ngModel required name="editUserId" placeholder="User ID"/>
|
||||
<input id="editUsername" ngModel name="editUsername" placeholder="New Username (Optional)"/>
|
||||
<input id="editPassword" ngModel type="password" name="editPassword" placeholder="New Password (Optional)"/>
|
||||
<button type="submit" [disabled]="editUserForm.invalid">Edit User</button>
|
||||
</form>
|
||||
}
|
||||
|
||||
@if (modalAction === 'delete') {
|
||||
<form (submit)="deleteUser(deleteUserForm)" #deleteUserForm="ngForm" id="deleteUserForm">
|
||||
<input id="deleteUserId" type="number" min="1" required name="deleteUserId" ngModel placeholder="User ID"/>
|
||||
<button type="submit" [disabled]="deleteUserForm.invalid">Delete User</button>
|
||||
</form>
|
||||
}
|
||||
</app-modal>
|
||||
<!-- Right Section -->
|
||||
@if (!isNarrow) {
|
||||
<div class="right-section">
|
||||
<div class="sel-titlebar">
|
||||
<h2>
|
||||
{{ isViewingArticles ? 'Articles' : 'Users' }}
|
||||
</h2>
|
||||
<button (click)="toggleView()" class="toggle-button">
|
||||
<i class="material-icons">{{ isViewingArticles ? 'person' : 'article' }}</i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="right-separator"></div>
|
||||
|
||||
<div class="create-article-tile">
|
||||
<h2>Create New Article</h2>
|
||||
<form #createForm="ngForm" (ngSubmit)="createArticle(createForm)">
|
||||
<input type="text" id="title" name="title" required ngModel placeholder="Article Title"/><br>
|
||||
<textarea id="content" name="content" required ngModel placeholder="Article Content"></textarea>
|
||||
<button type="submit" [disabled]="createForm.invalid">Create Article</button>
|
||||
</form>
|
||||
</div>
|
||||
@if (isNarrow) {
|
||||
<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>
|
||||
@if (isViewingArticles) {
|
||||
<div class="list-container">
|
||||
@if (noArticles) {
|
||||
<p>No articles available.</p>
|
||||
}
|
||||
@if (!noArticles) {
|
||||
<ul>
|
||||
@for (article of articles; track article) {
|
||||
<li (click)="navigateToArticle(article.slug)">
|
||||
<strong>ID {{ article.id }}</strong> - {{ article.title }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</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">
|
||||
<h2>
|
||||
{{ isViewingArticles ? 'Articles' : 'Users' }}
|
||||
<button (click)="toggleView()" class="toggle-button">
|
||||
<i class="material-icons">{{ isViewingArticles ? 'person' : 'article' }}</i>
|
||||
</button>
|
||||
</h2>
|
||||
@if (isViewingArticles) {
|
||||
}
|
||||
<!-- Display users list -->
|
||||
@if (!isViewingArticles) {
|
||||
<div class="list-container">
|
||||
@if (users.length === 0) {
|
||||
<div>
|
||||
@if (noArticles) {
|
||||
<div>
|
||||
<p>No articles available.</p>
|
||||
</div>
|
||||
}
|
||||
@if (!noArticles) {
|
||||
<div>
|
||||
<ul>
|
||||
@for (article of articles; track article) {
|
||||
<li (click)="navigateToArticle(article.slug)">
|
||||
<strong>ID {{ article.id }}</strong> - {{ article.title }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
<p>No users available.</p>
|
||||
</div>
|
||||
}
|
||||
<!-- Display users list -->
|
||||
@if (!isViewingArticles) {
|
||||
@if (users.length > 0) {
|
||||
<div>
|
||||
@if (users.length === 0) {
|
||||
<div>
|
||||
<p>No users available.</p>
|
||||
</div>
|
||||
}
|
||||
@if (users.length > 0) {
|
||||
<div>
|
||||
<ul>
|
||||
@for (user of users; track user) {
|
||||
<li>
|
||||
<strong>ID {{ user.id }}</strong> - {{ user.username }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
<ul>
|
||||
@for (user of users; track user) {
|
||||
<li>
|
||||
<strong>ID {{ user.id }}</strong> - {{ user.username }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Right Section: Articles List Tile -->
|
||||
@if (!isNarrow) {
|
||||
<div class="right-section">
|
||||
<div class="articles-list-tile">
|
||||
<h2>
|
||||
{{ isViewingArticles ? 'Articles' : 'Users' }}
|
||||
<button (click)="toggleView()" class="toggle-button">
|
||||
<i class="material-icons">{{ isViewingArticles ? 'person' : 'article' }}</i>
|
||||
</button>
|
||||
</h2>
|
||||
@if (isViewingArticles) {
|
||||
<div>
|
||||
@if (noArticles) {
|
||||
<div>
|
||||
<p>No articles available.</p>
|
||||
</div>
|
||||
}
|
||||
@if (!noArticles) {
|
||||
<div>
|
||||
<ul>
|
||||
@for (article of articles; track article) {
|
||||
<li (click)="navigateToArticle(article.slug)">
|
||||
<strong>ID {{ article.id }}</strong> - {{ article.title }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<!-- Display users list -->
|
||||
@if (!isViewingArticles) {
|
||||
<div>
|
||||
@if (users.length === 0) {
|
||||
<div>
|
||||
<p>No users available.</p>
|
||||
</div>
|
||||
}
|
||||
@if (users.length > 0) {
|
||||
<div>
|
||||
<ul>
|
||||
@for (user of users; track user) {
|
||||
<li>
|
||||
<strong>ID {{ user.id }}</strong> - {{ user.username }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- User Actions Modal -->
|
||||
<app-modal
|
||||
[isOpen]="isModalOpen"
|
||||
[title]="modalTitle"
|
||||
(onClose)="closeModal()"
|
||||
>
|
||||
<form #userForm="ngForm" (ngSubmit)="submitUser(userForm)" id="userForm">
|
||||
<div class="mode-select-button">
|
||||
<div
|
||||
id="userSel"
|
||||
(click)="toggleUserDropdown()"
|
||||
[ngStyle]="{'background-color' : userMode === 'create' ? '#78cd8b' : userMode === 'edit' ? '#8e95e3' : '#ba243a'}"
|
||||
>
|
||||
{{ userMode | titlecase }} User
|
||||
</div>
|
||||
|
||||
@if (isUserDropdownOpen) {
|
||||
<ul class="mode-dropdown">
|
||||
<li (click)="setUserMode('create')">Create User</li>
|
||||
<li (click)="setUserMode('edit')">Edit User</li>
|
||||
<li (click)="setUserMode('delete')">Delete User</li>
|
||||
</ul>
|
||||
}
|
||||
</div>
|
||||
|
||||
<input
|
||||
id="userId"
|
||||
type="number"
|
||||
name="userId"
|
||||
ngModel
|
||||
placeholder="User ID"
|
||||
min="1"
|
||||
[required]="userMode !== 'create'"
|
||||
[disabled]="userMode === 'create'"
|
||||
/>
|
||||
|
||||
<input
|
||||
id="username"
|
||||
name="username"
|
||||
ngModel
|
||||
placeholder="Username"
|
||||
[required]="userMode === 'create'"
|
||||
[disabled]="userMode === 'delete'"
|
||||
/>
|
||||
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
name="password"
|
||||
ngModel
|
||||
placeholder="Password"
|
||||
[required]="userMode === 'create'"
|
||||
[disabled]="userMode === 'delete'"
|
||||
/>
|
||||
|
||||
<button type="submit" [disabled]="isUserSubmitDisabled(userForm)">
|
||||
{{ userMode === 'create' ? 'Create' : userMode === 'edit' ? 'Edit' : 'Delete' }}
|
||||
</button>
|
||||
</form>
|
||||
</app-modal>
|
||||
+158
-116
@@ -1,8 +1,8 @@
|
||||
import {Component, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Router} from '@angular/router';
|
||||
import {Router, RouterLink} from '@angular/router';
|
||||
import {ArticleService} from '../shared/services/article.service';
|
||||
import {UserService} from '../shared/services/user.service';
|
||||
import { NgStyle } from '@angular/common';
|
||||
import {NgStyle, TitleCasePipe} from '@angular/common';
|
||||
import {Observer, Subscription, interval} from 'rxjs';
|
||||
import {FormsModule, NgForm} from '@angular/forms';
|
||||
import {ViewportService} from '../shared/services/viewport.service';
|
||||
@@ -17,8 +17,10 @@ import {AuthService} from '../shared/services/auth.service';
|
||||
imports: [
|
||||
FormsModule,
|
||||
NgStyle,
|
||||
ModalComponent
|
||||
]
|
||||
ModalComponent,
|
||||
TitleCasePipe,
|
||||
RouterLink
|
||||
]
|
||||
})
|
||||
export class AdminComponent implements OnInit, OnDestroy {
|
||||
tokenValidationInterval: Subscription = new Subscription();
|
||||
@@ -33,9 +35,9 @@ export class AdminComponent implements OnInit, OnDestroy {
|
||||
content: string = '';
|
||||
|
||||
modalTitle: string = '';
|
||||
modalAction: string = '';
|
||||
isModalOpen: boolean = false;
|
||||
isViewingArticles: boolean = true;
|
||||
userMode: 'create' | 'edit' | 'delete' = 'create';
|
||||
isUserDropdownOpen = false;
|
||||
|
||||
userData = {
|
||||
username: '',
|
||||
@@ -43,6 +45,11 @@ export class AdminComponent implements OnInit, OnDestroy {
|
||||
id: '',
|
||||
};
|
||||
|
||||
isViewingArticles: boolean = true;
|
||||
|
||||
articleMode: 'create' | 'edit' | 'delete' = 'create';
|
||||
isDropdownOpen = false;
|
||||
|
||||
constructor(
|
||||
private articleService: ArticleService,
|
||||
private userService: UserService,
|
||||
@@ -70,11 +77,8 @@ export class AdminComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
createArticle(form: any) {
|
||||
const title = form.value.title;
|
||||
const content = form.value.content;
|
||||
|
||||
if (!title || !content) {
|
||||
createArticle(title:string, content: string) {
|
||||
if (!title?.trim() || !content?.trim()) {
|
||||
alert('Both title and content are required!');
|
||||
return;
|
||||
}
|
||||
@@ -83,22 +87,21 @@ export class AdminComponent implements OnInit, OnDestroy {
|
||||
if (!valid) return;
|
||||
|
||||
const token = this.authService.token!;
|
||||
this.articleService.postArticle(token, title, content).subscribe(
|
||||
() => {
|
||||
alert('Article created successfully!');
|
||||
|
||||
this.articleService.postArticle(token, title.trim(), content.trim()).subscribe({
|
||||
next: () => {
|
||||
alert('Article created successfully.');
|
||||
this.loadArticles();
|
||||
},
|
||||
error => {
|
||||
error: err => {
|
||||
alert('Error creating article');
|
||||
console.error(error);
|
||||
console.log(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
editArticle(form: NgForm): void {
|
||||
const articleId = form.value.editId;
|
||||
|
||||
editArticle(articleId: number, title?: string, content?: string): void {
|
||||
if (!articleId || isNaN(Number(articleId))) {
|
||||
alert('Invalid input. Please enter a valid article ID.');
|
||||
return;
|
||||
@@ -118,11 +121,8 @@ export class AdminComponent implements OnInit, OnDestroy {
|
||||
return;
|
||||
}
|
||||
|
||||
const newTitle = form.value.editTitle || form.value.editTitleMobile;
|
||||
const newContent = form.value.editContent || form.value.editContentMobile;
|
||||
|
||||
const updatedTitle = newTitle?.trim() || article.title;
|
||||
const updatedContent = newContent?.trim() || article.content;
|
||||
const updatedTitle = title?.trim() || article.title;
|
||||
const updatedContent = content?.trim() || article.content;
|
||||
|
||||
this.articleService.editArticle(id, token, updatedTitle, updatedContent).subscribe(
|
||||
(response) => {
|
||||
@@ -144,9 +144,7 @@ export class AdminComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
deleteArticle(form: any): void {
|
||||
const articleId = form.value.deleteId || form.value.deleteIdMobile;
|
||||
|
||||
deleteArticle(articleId: number): void {
|
||||
if (!articleId || isNaN(Number(articleId))) {
|
||||
alert('Invalid input. Please enter a valid article ID.');
|
||||
return;
|
||||
@@ -210,20 +208,49 @@ export class AdminComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
openModal(action: string) {
|
||||
openUserModal() {
|
||||
this.isModalOpen = true;
|
||||
this.modalAction = action;
|
||||
this.modalTitle = 'Manage Users';
|
||||
this.userMode = 'create';
|
||||
this.isUserDropdownOpen = false;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case 'create':
|
||||
this.modalTitle = 'Create User';
|
||||
break;
|
||||
case 'edit':
|
||||
this.modalTitle = 'Edit User';
|
||||
break;
|
||||
case 'delete':
|
||||
this.modalTitle = 'Delete User';
|
||||
break;
|
||||
toggleUserDropdown(): void {
|
||||
this.isUserDropdownOpen = !this.isUserDropdownOpen;
|
||||
}
|
||||
|
||||
setUserMode(mode: 'create' | 'edit' | 'delete'): void {
|
||||
this.userMode = mode;
|
||||
this.isUserDropdownOpen = false;
|
||||
}
|
||||
|
||||
isUserSubmitDisabled(form: NgForm): boolean {
|
||||
const { userId, username, password } = form.value;
|
||||
|
||||
if (this.userMode === 'create') {
|
||||
return !username?.trim() || !password?.trim();
|
||||
}
|
||||
|
||||
if (this.userMode === 'edit') {
|
||||
return !userId;
|
||||
}
|
||||
|
||||
if (this.userMode === 'delete') {
|
||||
return !userId;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
submitUser(form: NgForm): void {
|
||||
const { userId, username, password } = form.value;
|
||||
|
||||
if (this.userMode === 'create') {
|
||||
this.createUserFromValues(username, password);
|
||||
} else if (this.userMode === 'edit') {
|
||||
this.editUserFromValues(Number(userId), username, password);
|
||||
} else if (this.userMode === 'delete') {
|
||||
this.deleteUserById(Number(userId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,113 +263,128 @@ export class AdminComponent implements OnInit, OnDestroy {
|
||||
};
|
||||
}
|
||||
|
||||
createUser(form: any): void {
|
||||
const username = form.value.createUsername;
|
||||
const password = form.value.createPassword;
|
||||
|
||||
if (!username || !password) {
|
||||
createUserFromValues(username: string, password: string): void {
|
||||
if (!username?.trim() || !password?.trim()) {
|
||||
alert('Both username and password are required!');
|
||||
return;
|
||||
}
|
||||
|
||||
this.authService.validateToken().subscribe(valid => {
|
||||
if (!valid) return;
|
||||
this.authService.validateToken().subscribe({
|
||||
next: valid => {
|
||||
if (!valid) return;
|
||||
|
||||
const token = this.authService.token!;
|
||||
const token = this.authService.token!;
|
||||
|
||||
this.userService.createUser(token, username, password).subscribe(
|
||||
(response) => {
|
||||
alert('User created successfully!');
|
||||
this.loadUsers();
|
||||
console.log(response);
|
||||
},
|
||||
|
||||
(error) => {
|
||||
alert('Error creating user');
|
||||
console.error(error);
|
||||
this.userService.createUser(token, username.trim(), password.trim()).subscribe({
|
||||
next: response => {
|
||||
alert('User created successfully!');
|
||||
this.loadUsers();
|
||||
console.log(response);
|
||||
this.closeModal();
|
||||
},
|
||||
error: error => {
|
||||
alert('Error creating user');
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
this.closeModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
editUser(form: any): void {
|
||||
const userId = form.value.editUserId;
|
||||
|
||||
editUserFromValues(userId: number, username?: string, password?: string): void {
|
||||
if (!userId || isNaN(Number(userId))) {
|
||||
alert('Invalid input. Please enter a valid user ID.');
|
||||
this.closeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
const id = Number(userId);
|
||||
|
||||
this.authService.validateToken().subscribe(valid => {
|
||||
if (!valid) return;
|
||||
this.authService.validateToken().subscribe({
|
||||
next: valid => {
|
||||
if (!valid) return;
|
||||
|
||||
const token = this.authService.token!;
|
||||
const token = this.authService.token!;
|
||||
|
||||
this.userService.getUserById(id, token).subscribe(
|
||||
(user) => {
|
||||
if (!user) {
|
||||
alert(`User with ID ${id} not found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const newUsername = form.value.editUsername;
|
||||
const newPassword = form.value.editPassword;
|
||||
|
||||
const updatedUsername = newUsername?.trim();
|
||||
const updatedPassword = newPassword?.trim();
|
||||
|
||||
this.userService.editUser(id, token, updatedUsername, updatedPassword).subscribe(
|
||||
(response) => {
|
||||
alert(`User ${id} updated successfully!`);
|
||||
console.log('Updated User:', response);
|
||||
this.loadUsers();
|
||||
},
|
||||
(error) => {
|
||||
alert(`Error updating user ${id}: ${error.message}`);
|
||||
console.error('Error:', error);
|
||||
this.userService.getUserById(id, token).subscribe({
|
||||
next: user => {
|
||||
if (!user) {
|
||||
alert(`User with ID ${id} not found.`);
|
||||
return;
|
||||
}
|
||||
);
|
||||
},
|
||||
(error: { message: any }) => {
|
||||
alert(`Failed to fetch user with ID ${id}: ${error.message}`);
|
||||
console.error('Error:', error);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this.closeModal();
|
||||
const updatedUsername = username?.trim() || undefined;
|
||||
const updatedPassword = password?.trim() || undefined;
|
||||
|
||||
this.userService.editUser(id, token, updatedUsername, updatedPassword).subscribe({
|
||||
next: response => {
|
||||
alert(`User ${id} updated successfully!`);
|
||||
console.log('Updated User:', response);
|
||||
this.loadUsers();
|
||||
this.closeModal();
|
||||
},
|
||||
error: error => {
|
||||
alert(`Error updating user ${id}: ${error.message}`);
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
error: error => {
|
||||
alert(`Failed to fetch user with ID ${id}: ${error.message}`);
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteUser(form: any): void {
|
||||
const userId = form.value.deleteUserId;
|
||||
|
||||
deleteUserById(userId: number): void {
|
||||
if (!userId || isNaN(Number(userId))) {
|
||||
alert('Invalid input. Please enter a valid user ID.');
|
||||
console.error('Invalid input:', userId);
|
||||
this.closeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
this.authService.validateToken().subscribe(valid => {
|
||||
if (!valid) return;
|
||||
this.authService.validateToken().subscribe({
|
||||
next: valid => {
|
||||
if (!valid) return;
|
||||
|
||||
const token = this.authService.token!;
|
||||
const token = this.authService.token!;
|
||||
|
||||
this.userService.deleteUser(Number(userId), token).subscribe(
|
||||
() => {
|
||||
alert(`User ${userId} deleted successfully`);
|
||||
this.loadUsers();
|
||||
},
|
||||
(error) => {
|
||||
alert(`Error deleting user ${userId}: ${error.message}`);
|
||||
console.error('Error deleting user:', error);
|
||||
}
|
||||
);
|
||||
this.userService.deleteUser(userId, token).subscribe({
|
||||
next: () => {
|
||||
alert(`User ${userId} deleted successfully`);
|
||||
this.loadUsers();
|
||||
this.closeModal();
|
||||
},
|
||||
error: error => {
|
||||
alert(`Error deleting user ${userId}: ${error.message}`);
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.closeModal();
|
||||
toggleDropdown() {
|
||||
this.isDropdownOpen = !this.isDropdownOpen;
|
||||
}
|
||||
|
||||
setMode(mode: 'create' | 'edit' | 'delete') {
|
||||
this.articleMode = mode;
|
||||
this.isDropdownOpen = false;
|
||||
}
|
||||
|
||||
submitArticle(form: NgForm) {
|
||||
if (form.invalid) return;
|
||||
|
||||
const { title, articleId, content } = form.value;
|
||||
const mode = this.articleMode;
|
||||
|
||||
if (mode === 'create') {
|
||||
this.createArticle(title, content);
|
||||
} else if (mode === 'edit') {
|
||||
this.editArticle(articleId, title, content);
|
||||
} else if (mode === 'delete') {
|
||||
this.deleteArticle(articleId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
.login-container {
|
||||
color: white;
|
||||
flex-direction: column;
|
||||
background: #26262c;
|
||||
background: #202025;
|
||||
border-radius: 25px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
padding: 40px;
|
||||
@@ -42,9 +42,15 @@ input {
|
||||
padding: 12px;
|
||||
margin: 10px 0;
|
||||
color: white;
|
||||
background: #1c1c23;
|
||||
background: #26262c;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
transition: all ease-in-out 0.2s;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
outline: none;
|
||||
background: #2b2b32;
|
||||
}
|
||||
|
||||
button {
|
||||
@@ -56,15 +62,16 @@ button {
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: all ease-in-out 0.2s;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
background-color: #221a1a;
|
||||
background-color: rgba(64, 41, 41, 0.25);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
button:hover:enabled {
|
||||
background-color: #ff277a;
|
||||
background-color: #a36cff;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
|
||||
@@ -8,25 +8,38 @@
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal {
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
background-color: #202025;
|
||||
color: #fff;
|
||||
border-radius: 25px;
|
||||
padding: 15px;
|
||||
min-width: 300px;
|
||||
max-width: 300px;
|
||||
position: relative;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
z-index: 1001;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
top: 4px;
|
||||
right: 8px;
|
||||
background: none;
|
||||
color: white;
|
||||
border: none;
|
||||
font-size: 20px;
|
||||
font-size: 28px;
|
||||
cursor: pointer;
|
||||
transition: all ease-in-out 0.2s;
|
||||
}
|
||||
|
||||
.close-btn:hover {
|
||||
color: #ebe1fa;
|
||||
}
|
||||
|
||||
.close-btn:active {
|
||||
color: #a172e8;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
@if (isOpen) {
|
||||
<div class="modal-backdrop">
|
||||
<div class="modal">
|
||||
<button class="close-btn" (click)="closeModal()">✖</button>
|
||||
<button class="close-btn" (click)="closeModal()"><i class="fa-solid fa-xmark"></i></button>
|
||||
<h2>{{ title }}</h2>
|
||||
<ng-content></ng-content>
|
||||
</div>
|
||||
|
||||
@@ -31,7 +31,7 @@ export class UserService {
|
||||
}, { headers });
|
||||
}
|
||||
|
||||
editUser(id: number, token: string | null, username: string, password: string): Observable<any> {
|
||||
editUser(id: number, token: string | null, username?: string, password?: string): Observable<any> {
|
||||
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`);
|
||||
|
||||
const body: any = {};
|
||||
|
||||
Reference in new issue
Block a user