diff --git a/public/assets/arrow-down.svg b/public/assets/arrow-down.svg new file mode 100644 index 0000000..cccc9fc --- /dev/null +++ b/public/assets/arrow-down.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/public/assets/logo_m.svg b/public/assets/logo_m.svg new file mode 100755 index 0000000..afadf47 --- /dev/null +++ b/public/assets/logo_m.svg @@ -0,0 +1,400 @@ + + + MineCrew Logo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + MineCrew Logo + 14.05.2020 + + + Michael Reisinger + + + + + https://creativecommons.org/licenses/by-nc-nd/4.0/ + + + Logo + + + Michael Reisinger + + + minecrew_logo + + + + + + + + + diff --git a/src/app/admin/admin.component.css b/src/app/admin/admin.component.css index b362c27..abe8982 100644 --- a/src/app/admin/admin.component.css +++ b/src/app/admin/admin.component.css @@ -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; } diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 67b55db..81421f6 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -1,200 +1,189 @@ -
-
- - @if (!isNarrow) { -
-
-

Delete Article

-
- - -
-
-
-

Edit Article

-
- -
- - -
+
+ +
+
+ Logo + @if (!isNarrow) { +
+

Admin Dashboard

+ } +
+ +
- } - -
-
-

Admin Dashboard

-
- - - - -
+
- -
+ +
+
+
+ +
+
+ {{ articleMode | titlecase }} Article +
+ @if (isDropdownOpen) { +
    +
  • Create Article
  • +
  • Edit Article
  • +
  • Delete Article
  • +
+ } +
+ + - - } + {{ articleMode === 'create' ? 'Create' : articleMode === 'edit' ? 'Edit' : 'Delete' }} + +
+ + +
+
- @if (modalAction === 'edit') { -
- - - - -
- } - - @if (modalAction === 'delete') { -
- - -
- } - + + @if (!isNarrow) { +
+
+

+ {{ isViewingArticles ? 'Articles' : 'Users' }} +

+
+
-
-

Create New Article

-
-
- - -
-
- @if (isNarrow) { -
-

Delete Article

-
- - -
+ @if (isViewingArticles) { +
+ @if (noArticles) { +

No articles available.

+ } + @if (!noArticles) { +
    + @for (article of articles; track article) { +
  • + ID {{ article.id }} - {{ article.title }} +
  • + } +
+ }
-
-

Edit Article

-
- -
- - -
-
-
-

- {{ isViewingArticles ? 'Articles' : 'Users' }} - -

- @if (isViewingArticles) { + } + + @if (!isViewingArticles) { +
+ @if (users.length === 0) {
- @if (noArticles) { -
-

No articles available.

-
- } - @if (!noArticles) { -
-
    - @for (article of articles; track article) { -
  • - ID {{ article.id }} - {{ article.title }} -
  • - } -
-
- } +

No users available.

} - - @if (!isViewingArticles) { + @if (users.length > 0) {
- @if (users.length === 0) { -
-

No users available.

-
- } - @if (users.length > 0) { -
-
    - @for (user of users; track user) { -
  • - ID {{ user.id }} - {{ user.username }} -
  • - } -
-
- } +
    + @for (user of users; track user) { +
  • + ID {{ user.id }} - {{ user.username }} +
  • + } +
}
}
- - - @if (!isNarrow) { -
-
-

- {{ isViewingArticles ? 'Articles' : 'Users' }} - -

- @if (isViewingArticles) { -
- @if (noArticles) { -
-

No articles available.

-
- } - @if (!noArticles) { -
-
    - @for (article of articles; track article) { -
  • - ID {{ article.id }} - {{ article.title }} -
  • - } -
-
- } -
- } - - @if (!isViewingArticles) { -
- @if (users.length === 0) { -
-

No users available.

-
- } - @if (users.length > 0) { -
-
    - @for (user of users; track user) { -
  • - ID {{ user.id }} - {{ user.username }} -
  • - } -
-
- } -
- } -
-
- } -
+ }
+ + + +
+
+
+ {{ userMode | titlecase }} User +
+ + @if (isUserDropdownOpen) { +
    +
  • Create User
  • +
  • Edit User
  • +
  • Delete User
  • +
+ } +
+ + + + + + + + +
+
diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index f6a8513..3a2cf68 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -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); + } } } diff --git a/src/app/login/login.component.css b/src/app/login/login.component.css index 45f6f38..99e508c 100644 --- a/src/app/login/login.component.css +++ b/src/app/login/login.component.css @@ -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 { diff --git a/src/app/shared/modal/modal.component.css b/src/app/shared/modal/modal.component.css index de2fb80..c62995f 100644 --- a/src/app/shared/modal/modal.component.css +++ b/src/app/shared/modal/modal.component.css @@ -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; } diff --git a/src/app/shared/modal/modal.component.html b/src/app/shared/modal/modal.component.html index 3b6ff87..aca3bd2 100644 --- a/src/app/shared/modal/modal.component.html +++ b/src/app/shared/modal/modal.component.html @@ -1,7 +1,7 @@ @if (isOpen) {