Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guards #534

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0995f72
feat: add header
cobraii Jan 2, 2025
78d8f44
feat: завершена верстка карточек и обновлены общие стили
cobraii Jan 7, 2025
94e4f7e
fix: fix errors
cobraii Jan 9, 2025
7b921f4
feat: Реализован код базовых конструкций на TypeScript
cobraii Jan 9, 2025
999e2d4
feat: Добавлен роутинг, компонент, запросы на сервер и отрисовка в цикле
cobraii Jan 10, 2025
ac516fb
fix: delete coments
cobraii Jan 10, 2025
fee9d97
feat: Добавлен код для обработки списка пользователей: фильтрация, со…
cobraii Jan 11, 2025
ca51f11
feat: Added the UserList and TodosList components
cobraii Jan 12, 2025
e48629d
fix: fix errors
cobraii Jan 13, 2025
1a69375
feat: Added the UsersService and TodosService services
cobraii Jan 13, 2025
601c1b0
fix: added a type for buttons and a variable for data from the service
cobraii Jan 15, 2025
c771269
feat: Added create-user-form and create-todo-form
cobraii Jan 15, 2025
e042770
feat: Connected the angular material and stylized the form
cobraii Jan 16, 2025
ac748f3
feat: The form has been converted into a modal form, added confirm de…
cobraii Jan 23, 2025
e1cf553
fix: added changedetection to all components.
cobraii Jan 23, 2025
cc5d490
fix: added unsubscribe and type on buttons
cobraii Jan 26, 2025
b33a9d9
feat: Added pipes and directives
cobraii Feb 2, 2025
afeb6bd
fix: delete spec.ts
cobraii Feb 2, 2025
9c01c7d
feat: Added auth,admin components and guard
cobraii Feb 3, 2025
39f53ab
feat: Added auth,admin components and guard
cobraii Feb 3, 2025
69b218d
fix: deleted any from the interface
cobraii Feb 11, 2025
8d236e7
fix: deleted any from the interface
cobraii Feb 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"src/assets"
],
"styles": [
"@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
],
"scripts": []
Expand Down Expand Up @@ -90,12 +91,16 @@
"src/assets"
],
"styles": [
"@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
],
"scripts": []
}
}
}
}
},
"cli": {
"analytics": false
}
}
896 changes: 894 additions & 2 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
"private": true,
"dependencies": {
"@angular/animations": "^17.3.0",
"@angular/cdk": "^17.3.10",
"@angular/common": "^17.3.0",
"@angular/compiler": "^17.3.0",
"@angular/core": "^17.3.0",
"@angular/forms": "^17.3.0",
"@angular/material": "^17.3.10",
"@angular/platform-browser": "^17.3.0",
"@angular/platform-browser-dynamic": "^17.3.0",
"@angular/router": "^17.3.0",
Expand All @@ -35,4 +37,4 @@
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.4.2"
}
}
}
22 changes: 22 additions & 0 deletions src/app/Material.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatDialogModule } from "@angular/material/dialog";
import { MatTooltipModule} from '@angular/material/tooltip';


@NgModule({
exports: [
MatCardModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatButtonModule,
MatDialogModule,
MatTooltipModule
],
})
export class MaterialModule {}
1 change: 1 addition & 0 deletions src/app/admin/admin.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Только для админов!</h1>
Empty file.
11 changes: 11 additions & 0 deletions src/app/admin/admin.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-admin',
standalone: true,
imports: [],
templateUrl: './admin.component.html',
styleUrl: './admin.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AdminComponent {}
335 changes: 2 additions & 333 deletions src/app/app.component.html

Large diffs are not rendered by default.

29 changes: 0 additions & 29 deletions src/app/app.component.spec.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { HeaderComponent } from './header/header.component';

@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet],
imports: [RouterOutlet, HeaderComponent],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
})
Expand Down
7 changes: 6 additions & 1 deletion src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { HttpClientModule, provideHttpClient } from '@angular/common/http';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';

export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes)]
providers: [
provideRouter(routes),
provideHttpClient(), provideAnimationsAsync()
]
};
10 changes: 9 additions & 1 deletion src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { Routes } from '@angular/router';
import { UserListComponent } from './user-list/user-list.component';
import { TodosListComponent } from './todos-list/todos-list.component';
import { AdminComponent } from './admin/admin.component';
import { authAdminGuard } from './auth-admin.guard';

export const routes: Routes = [];
export const routes: Routes = [
{ path: 'users', component: UserListComponent },
{ path: 'todos', component: TodosListComponent },
{ path: 'admin', component: AdminComponent, canMatch: [authAdminGuard] },
];
14 changes: 14 additions & 0 deletions src/app/auth-admin.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { inject } from '@angular/core';
import { CanMatchFn, Router } from '@angular/router';
import { UserService } from './user.service';

export const authAdminGuard: CanMatchFn = () => {
const userService = inject(UserService);
const router = inject(Router);

if (userService.isAdmin) {
return true;
} else {
return false
}
};
9 changes: 9 additions & 0 deletions src/app/auth/auth.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<mat-card class="container">
<mat-card-header>
<h1>Войти как:</h1>
</mat-card-header>
<mat-card-content class="buttons-wrapper">
<button mat-button type="button" mat-dialog-close="admin">Админ</button>
<button mat-button type="button" mat-dialog-close="user">Юзер</button>
</mat-card-content>
</mat-card>
46 changes: 46 additions & 0 deletions src/app/auth/auth.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.container {
width: 400px;
padding: 20px;
text-align: center;
background: #ffffff;
border-radius: 12px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

mat-card-header h1 {
font-size: 1.5rem;
font-weight: bold;
color: #333;
}

.buttons-wrapper {
display: flex;
flex-direction: column;
gap: 15px;
margin-top: 20px;
}

button {
width: 100%;
padding: 10px;
font-size: 16px;
border-radius: 8px;
transition: all 0.3s ease-in-out;
}

button[mat-button] {
background: #3f51b5;
color: white;
}

button[mat-button]:hover {
background: #303f9f;
}

button[mat-button]:nth-child(2) {
background: #e91e63;
}

button[mat-button]:nth-child(2):hover {
background: #c2185b;
}
12 changes: 12 additions & 0 deletions src/app/auth/auth.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { MaterialModule } from '../Material.module';

@Component({
selector: 'app-auth',
standalone: true,
imports: [MaterialModule],
templateUrl: './auth.component.html',
styleUrl: './auth.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AuthComponent {}
5 changes: 5 additions & 0 deletions src/app/confirm-deletion/confirm-deletion.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h2 mat-dialog-title>Вы точно хотите удалить?</h2>
<mat-dialog-actions>
<button mat-button mat-dialog-close type="button">Нет</button>
<button mat-button [mat-dialog-close]="true" type="button">Да</button>
</mat-dialog-actions>
Empty file.
19 changes: 19 additions & 0 deletions src/app/confirm-deletion/confirm-deletion.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { MaterialModule } from '../Material.module';
import { MatDialog } from '@angular/material/dialog';

@Component({
selector: 'app-confirm-deletion',
standalone: true,
imports: [MaterialModule],
templateUrl: './confirm-deletion.component.html',
styleUrl: './confirm-deletion.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfirmDeletionComponent {
readonly dialog = inject(MatDialog);

openDialog() {
const dialogRef = this.dialog.open(ConfirmDeletionComponent);
}
}
37 changes: 37 additions & 0 deletions src/app/create-edit-todo-form/create-edit-todo-form.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<form class="form" [formGroup]="createEditTodoForm">
<mat-card>
<mat-card-header>
<h2>Добавить задачу</h2>
</mat-card-header>
<mat-card-content class="form-content-wrapper">
<mat-form-field>
<mat-label>Название задачи</mat-label>
<input formControlName="title" matInput />
</mat-form-field>
<mat-form-field>
<mat-label>Автор задачи</mat-label>
<input formControlName="userId" matInput />
</mat-form-field>
<mat-form-field>
<mat-label for="completed">Задача завершена?</mat-label>
<mat-select formControlName="completed">
<mat-option [value]="true">Да</mat-option>
<mat-option [value]="false">Нет</mat-option>
</mat-select>
</mat-form-field>
</mat-card-content>

<mat-card-actions>
<button
mat-raised-button
color="primary"
type="submit"
(click)="submitForm()"
[disabled]="createEditTodoForm.invalid"
>
Добавить
</button>
</mat-card-actions>
</mat-card>
</form>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.form {
width: 300px;
}

.form-content-wrapper{
padding: 20px;
display: grid;
gap: 20px;
}
51 changes: 51 additions & 0 deletions src/app/create-edit-todo-form/create-edit-todo-form.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
inject,
OnInit,
Output,
} from '@angular/core';
import {
FormControl,
FormGroup,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import { MaterialModule } from '../Material.module';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Todo } from '../interfaces/todos.interface';

@Component({
selector: 'app-create-edit-todo-form',
standalone: true,
imports: [ReactiveFormsModule, MaterialModule],
templateUrl: './create-edit-todo-form.component.html',
styleUrl: './create-edit-todo-form.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CreateEditTodoFormComponent implements OnInit {
readonly dialogRef = inject(MatDialogRef<CreateEditTodoFormComponent>);
readonly data = inject<Todo>(MAT_DIALOG_DATA);
@Output() createTodo = new EventEmitter();

ngOnInit(): void {
if (this.data) {
this.createEditTodoForm.patchValue(this.data);
}
}

createEditTodoForm = new FormGroup({
id: new FormControl(this.data?.id || null),
title: new FormControl('', [Validators.required, Validators.minLength(2)]),
userId: new FormControl('', [Validators.required, Validators.minLength(2)]),
completed: new FormControl(true, [Validators.required]),
});

submitForm() {
const userId = Date.now();
const userData = { ...this.createEditTodoForm.value, id: userId };
this.createTodo.emit(userData);
this.dialogRef.close(this.createEditTodoForm.value);
}
}
Loading