Skip to content

Commit

Permalink
usunięto ActivatedRoute na rzecz @input
Browse files Browse the repository at this point in the history
ogarnięte CascadeType i działa edycja wydatków i ich zapisywanie. reszta chyba też
  • Loading branch information
JanisBe committed Jun 12, 2024
1 parent d6cf6ad commit 08aa7e6
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Component, OnInit} from '@angular/core';
import {Component, Input, OnInit} from '@angular/core';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
import {CategoryService} from "../../../service/category.service";
import {Category} from "../../../model/category";
import {ActivatedRoute, Router} from "@angular/router";
import {Router} from "@angular/router";
import {SnackbarService} from "../../../service/snackbar.service";
import {Observer} from "rxjs";
import {MatDialog} from "@angular/material/dialog";
Expand All @@ -22,14 +22,13 @@ import {MatFormField, MatLabel, MatPrefix} from '@angular/material/form-field';
export class AddCategoryComponent implements OnInit {
form: FormGroup;
currentCategory: Category;
currentCategoryId: number;
@Input("currentCategoryId") currentCategoryId: number;
categoryIconName: string;
private editMode: boolean;

constructor(private categoryService: CategoryService,
private router: Router,
private snackbarService: SnackbarService,
private route: ActivatedRoute,
private dialog: MatDialog) {
}

Expand All @@ -49,9 +48,8 @@ export class AddCategoryComponent implements OnInit {

ngOnInit() {
this.categoryIconName = "euro";
if (!!this.route.snapshot.params['categoryId']) {
if (!!this.currentCategoryId) {
this.editMode = true;
this.currentCategoryId = this.route.snapshot.params['categoryId'];
this.categoryService.findById(this.currentCategoryId).subscribe(
category => {
this.currentCategory = category;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Component, OnInit} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {Component, Input, OnInit} from '@angular/core';
import {SnackbarService} from "../../../service/snackbar.service";
import {UserService} from "../../../service/user.service";
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
import {ActivatedRoute, Router} from "@angular/router";
import {Router} from "@angular/router";
import {User} from "../../../model/user";
import {MatButton} from '@angular/material/button';
import {NgIf} from '@angular/common';
Expand All @@ -20,12 +19,11 @@ import {MatFormField, MatLabel} from '@angular/material/form-field';
export class ForgotPasswordComponent implements OnInit {
userForm: FormGroup;
changePassword: false;
@Input() login: string

constructor(private http: HttpClient,
private snackbarService: SnackbarService,
constructor(private snackbarService: SnackbarService,
private userService: UserService,
private router: Router,
private route: ActivatedRoute) {
private router: Router) {
}

onSubmit() {
Expand All @@ -49,8 +47,8 @@ export class ForgotPasswordComponent implements OnInit {

ngOnInit(): void {
this.initializeForm();
if (this.route.snapshot.queryParams['login']) {
this.userForm.patchValue({userName: this.route.snapshot.queryParams['login']})
if (!!this.login) {
this.userForm.patchValue({userName: this.login})
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {Component, Input, OnInit} from '@angular/core';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
import {AuthService} from "../../../auth/auth.service";
import {ActivatedRoute, Router, RouterLink} from "@angular/router";
import {Router, RouterLink} from "@angular/router";
import {MatButton} from '@angular/material/button';
import {MatInput} from '@angular/material/input';
import {MatFormField, MatLabel} from '@angular/material/form-field';
Expand All @@ -14,21 +14,22 @@ import {MatFormField, MatLabel} from '@angular/material/form-field';
imports: [FormsModule, ReactiveFormsModule, MatFormField, MatLabel, MatInput, MatButton, RouterLink]
})
export class LoginComponent implements OnInit {
constructor(private authService: AuthService,
private router: Router,
private route: ActivatedRoute) {
}
@Input() email: string;

loginForm: FormGroup;

constructor(private authService: AuthService,
private router: Router) {
}

ngOnInit(): void {
this.authService.isHttpsEnabled().subscribe();
if (!!this.authService.user.value) {
// this.router.navigate(['/group/list']);
}
this.initForm();
if (this.route.snapshot.queryParams['email']) {
this.loginForm.patchValue({login: this.route.snapshot.queryParams['email']})
if (!!this.email) {
this.loginForm.patchValue({login: this.email})
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component} from '@angular/core';
import {Component, Input} from '@angular/core';
import {AuthService} from "../../../auth/auth.service";
import {ActivatedRoute, Router} from "@angular/router";
import {Router} from "@angular/router";
import {UserService} from "../../../service/user.service";
import {SnackbarService} from "../../../service/snackbar.service";
import {HttpErrorResponse} from "@angular/common/http";
Expand All @@ -13,22 +13,22 @@ import {HttpErrorResponse} from "@angular/common/http";
})
export class VerifyEmailComponent {

constructor(private route: ActivatedRoute,
private userService: UserService,
@Input() token: string;
@Input() userId: string;

constructor(private userService: UserService,
private snackbarService: SnackbarService,
private router: Router,
private authService: AuthService
) {
}

ngOnInit(): void {
const token = this.route.snapshot.queryParams['token'];
const userId = this.route.snapshot.queryParams['userId'];
if (!token || !userId) {
if (!this.token || !this.userId) {
this.snackbarService.displayError('Niepoprawny link aktywacji');
this.router.navigate(['/login']);
}
this.userService.verifyUser(token, userId).subscribe({
this.userService.verifyUser(this.token, this.userId).subscribe({
next: (response) => {
const user = response.body!;
this.snackbarService.displayMessage('Konto zostało aktywowane, witamy!.', 5000)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, OnInit} from '@angular/core';
import {Component, Input, OnInit} from '@angular/core';
import {ExpenseService} from "../../../service/expense.service";
import {ActivatedRoute, Router} from "@angular/router";
import {Router} from "@angular/router";
import {SnackbarService} from "../../../service/snackbar.service";
import {Expense} from "../../../model/expense";
import {ConfirmationComponent} from "../../common/confirmation/confirmation.component";
Expand Down Expand Up @@ -55,44 +55,44 @@ export class AllExpensesComponent implements OnInit {
displayedColumns: string[] = ['description', 'amount', 'with', 'currency', 'date', 'actions'];
columnsToDisplayWithExpand = [...this.displayedColumns, 'szczegóły'];
expenses: Expense[];
private groupId: number = 1;
expandedElement: Expense | null;

constructor(private expenseService: ExpenseService,
private router: Router,
private snackbarService: SnackbarService,
private route: ActivatedRoute,
private dialog: MatDialog) {
}

@Input() groupId: number;

ngOnInit(): void {
if (!!this.route.snapshot.params['groupId']) {
this.groupId = this.route.snapshot.params['groupId'];
this.fetchExpensesForGroup(this.groupId);
} else {
this.fetchAllExpenses();
}
if (!!this.groupId) {
this.fetchExpensesForGroup(this.groupId);
} else {
this.fetchAllExpenses();
}
}

editExpense(expense: Expense) {
this.router.navigate(['expense/details', expense.id]);
}
editExpense(expense: Expense) {
this.router.navigate(['expense/details', expense.id]);
}

deleteExpense(expense: Expense) {
let dialogRef = this.dialog.open(ConfirmationComponent, {
data: {content: expense.description, category: 'expense'}
});
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.expenseService.deleteExpense(expense.id!).subscribe(
() => {
this.snackbarService.displayMessage(`Wydatek ${expense.description} został skasowany`, 3000);
this.fetchExpensesForGroup(expense.groupId);
}
);
}
});
deleteExpense(expense: Expense) {
let dialogRef = this.dialog.open(ConfirmationComponent, {
data: {content: expense.description, category: 'expense'}
});
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.expenseService.deleteExpense(expense.id!).subscribe(
() => {
this.snackbarService.displayMessage(`Wydatek ${expense.description} został skasowany`, 3000);
this.fetchExpensesForGroup(expense.groupId);
}
);
}
});

}
}

printUsers(expense: Expense) {
let output = '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
import {User} from "../../../model/user";
import {Category} from "../../../model/category";
import {Group} from "../../../model/group";
import {Expense} from "../../../model/expense";
import {COMMA, ENTER} from "@angular/cdk/keycodes";
import {ExpenseService} from "../../../service/expense.service";
import {ActivatedRoute, Router, RouterLink} from "@angular/router";
import {Router, RouterLink} from "@angular/router";
import {SnackbarService} from "../../../service/snackbar.service";
import {UserService} from "../../../service/user.service";
import {CurrencyService} from "../../../service/currency.service";
Expand Down Expand Up @@ -39,7 +39,8 @@ export class EditExpenseComponent implements OnInit {
usersOriginalList: User[];
categories: Category[];
currentUser: User;
currentGroupId: number;
@Input("groupId") currentGroupId: number;
@Input() expenseId: number;
currentGroup: Group;
currentExpense: Expense;
userGroups: Group[];
Expand All @@ -61,15 +62,13 @@ export class EditExpenseComponent implements OnInit {
private userService: UserService,
private currencyService: CurrencyService,
private categoryService: CategoryService,
private route: ActivatedRoute,
private groupService: GroupService,
private authService: AuthService) {
}


ngOnInit(): void {
this.currentUser = this.authService.user.value!;
this.currentGroupId = this.route.snapshot.params['groupId'];
this.initForm();
this.groupService.findById(this.currentGroupId).subscribe(group => {
this.currentGroup = group;
Expand All @@ -88,9 +87,9 @@ export class EditExpenseComponent implements OnInit {
this.categoryService.findAllCategories().subscribe(category => this.categories = category);
this.currencies = this.currencyService.getAllCurrencies();

if (!!this.route.snapshot.params['expenseId']) {
if (!!this.expenseId) {
this.editMode = true;
this.expenseService.findById(this.route.snapshot.params['expenseId']).subscribe({
this.expenseService.findById(this.expenseId).subscribe({
next: (expense) => {
this.currentExpense = expense;
let debtors = expense.debt.flatMap(d => d.from);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {GroupService} from "../../../service/group.service";
import {Group} from "../../../model/group";
import {User} from "../../../model/user";
import {SnackbarService} from "../../../service/snackbar.service";
import {ActivatedRoute, Router, RouterLink} from "@angular/router";
import {Router, RouterLink} from "@angular/router";
import {UserService} from "../../../service/user.service";
import {MatAutocomplete, MatAutocompleteSelectedEvent, MatAutocompleteTrigger} from "@angular/material/autocomplete";
import {CurrencyService} from "../../../service/currency.service";
Expand Down Expand Up @@ -48,7 +48,6 @@ export class AddGroupComponent implements OnInit {
constructor(private groupService: GroupService,
private snackbarService: SnackbarService,
private router: Router,
private route: ActivatedRoute,
private userService: UserService,
private currencyService: CurrencyService,
private categoryService: CategoryService,
Expand Down Expand Up @@ -109,11 +108,11 @@ export class AddGroupComponent implements OnInit {
id = this.currentUser.id;
}
(<FormArray>this.groupForm.get('users')).push(
new FormGroup({
id: new FormControl(id),
name: new FormControl(user, Validators.required),
mail: new FormControl(email, Validators.email)
})
new FormGroup({
id: new FormControl(id),
name: new FormControl(user, Validators.required),
mail: new FormControl(email, Validators.email)
})
);
this.userGroupAdded++;
}
Expand Down Expand Up @@ -167,11 +166,11 @@ export class AddGroupComponent implements OnInit {
if (group.users) {
for (let user of group.users) {
groupUsers.push(
new FormGroup({
id: new FormControl(user.id),
name: new FormControl(user.name, Validators.required),
mail: new FormControl(user.mail, Validators.email)
})
new FormGroup({
id: new FormControl(user.id),
name: new FormControl(user.name, Validators.required),
mail: new FormControl(user.mail, Validators.email)
})
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Component, Input, OnInit} from '@angular/core';
import {ActivatedRoute} from "@angular/router";
import {ExpenseService} from "../../../service/expense.service";
import {Expense} from "../../../model/expense";
import {DatePipe, KeyValue, KeyValuePipe, NgFor} from "@angular/common";
Expand All @@ -18,8 +17,8 @@ import {SpinnerComponent} from "../../common/spinner/spinner.component";
})
export class GroupSummaryComponent implements OnInit {
expenses: Map<string, Expense[]> = new Map<string, Expense[]>();

constructor(private expenseService: ExpenseService,
private route: ActivatedRoute,
private dialog: MatDialog
) {
}
Expand All @@ -28,9 +27,10 @@ export class GroupSummaryComponent implements OnInit {
@Input() groupName?: number;

ngOnInit(): void {
console.log("refreshed")
this.expenseService.findAllByGroupId(this.groupId!).subscribe(expenses => {
this.expenses = this.groupByDate(expenses);
});
this.expenses = this.groupByDate(expenses);
});
}

groupByDate(objects: Expense[]): Map<string, Expense[]> {
Expand Down
Loading

0 comments on commit 08aa7e6

Please sign in to comment.