Chore: Upgrade to Angular v18
Chore: Upgrade to Python 3.12 Chore: Upgrade to psycopg3
This commit is contained in:
@ -30,18 +30,19 @@
|
||||
formArrayName="discounts"
|
||||
class="flex flex-row flex-wrap justify-around content-start items-start discounts gap-x-5"
|
||||
>
|
||||
<div
|
||||
*ngFor="let r of item.discounts; index as i"
|
||||
[formGroupName]="i"
|
||||
class="flex flex-row justify-around content-start items-start basis-[calc((100%_/_3)_-_(20px_*_2_/_3))]"
|
||||
>
|
||||
<mat-form-field class="flex-auto">
|
||||
<mat-label>Discount on {{ r.name }}</mat-label>
|
||||
<input matInput formControlName="discount" />
|
||||
<span matSuffix>%</span>
|
||||
<mat-hint>Max {{ r.limit | percent: '1.2-2' }}</mat-hint>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
@for (r of item.discounts; track r; let i = $index) {
|
||||
<div
|
||||
[formGroupName]="i"
|
||||
class="flex flex-row justify-around content-start items-start basis-[calc((100%_/_3)_-_(20px_*_2_/_3))]"
|
||||
>
|
||||
<mat-form-field class="flex-auto">
|
||||
<mat-label>Discount on {{ r.name }}</mat-label>
|
||||
<input matInput formControlName="discount" />
|
||||
<span matSuffix>%</span>
|
||||
<mat-hint>Max {{ r.limit | percent: '1.2-2' }}</mat-hint>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
|
||||
@ -8,7 +8,7 @@ describe('CustomerDetailComponent', () => {
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [CustomerDetailComponent],
|
||||
imports: [CustomerDetailComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
|
||||
@ -1,6 +1,13 @@
|
||||
import { PercentPipe } from '@angular/common';
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormArray, FormControl, FormGroup } from '@angular/forms';
|
||||
import { FormArray, FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButton } from '@angular/material/button';
|
||||
import { MatCard, MatCardHeader, MatCardTitle, MatCardContent, MatCardActions } from '@angular/material/card';
|
||||
import { MatCheckbox } from '@angular/material/checkbox';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatDivider } from '@angular/material/divider';
|
||||
import { MatFormField, MatLabel, MatSuffix, MatHint } from '@angular/material/form-field';
|
||||
import { MatInput } from '@angular/material/input';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { round } from 'mathjs';
|
||||
|
||||
@ -13,6 +20,24 @@ import { CustomerService } from '../customer.service';
|
||||
selector: 'app-customer-detail',
|
||||
templateUrl: './customer-detail.component.html',
|
||||
styleUrls: ['./customer-detail.component.css'],
|
||||
standalone: true,
|
||||
imports: [
|
||||
MatCard,
|
||||
MatCardHeader,
|
||||
MatCardTitle,
|
||||
MatCardContent,
|
||||
ReactiveFormsModule,
|
||||
MatFormField,
|
||||
MatLabel,
|
||||
MatInput,
|
||||
MatCheckbox,
|
||||
MatDivider,
|
||||
MatSuffix,
|
||||
MatHint,
|
||||
MatCardActions,
|
||||
MatButton,
|
||||
PercentPipe,
|
||||
],
|
||||
})
|
||||
export class CustomerDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
@ -81,27 +106,27 @@ export class CustomerDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
() => {
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe({
|
||||
next: () => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/customers');
|
||||
},
|
||||
(error) => {
|
||||
error: (error) => {
|
||||
this.toaster.show('Error', error);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id as string).subscribe(
|
||||
() => {
|
||||
this.ser.delete(this.item.id as string).subscribe({
|
||||
next: () => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/customers');
|
||||
},
|
||||
(error) => {
|
||||
error: (error) => {
|
||||
this.toaster.show('Error', error);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { Customer } from '../core/customer';
|
||||
|
||||
import { CustomerService } from './customer.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CustomerListResolver {
|
||||
constructor(private ser: CustomerService) {}
|
||||
|
||||
resolve(): Observable<Customer[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
10
bookie/src/app/customers/customer-list.resolver.ts
Normal file
10
bookie/src/app/customers/customer-list.resolver.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
|
||||
import { Customer } from '../core/customer';
|
||||
|
||||
import { CustomerService } from './customer.service';
|
||||
|
||||
export const customerListResolver: ResolveFn<Customer[]> = () => {
|
||||
return inject(CustomerService).list();
|
||||
};
|
||||
@ -41,9 +41,9 @@
|
||||
<mat-header-cell *matHeaderCellDef>Discounts</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">
|
||||
<ul>
|
||||
<li *ngFor="let discount of row.discounts">
|
||||
{{ discount.name }} - {{ discount.discount | percent: '1.2-2' }}
|
||||
</li>
|
||||
@for (discount of row.discounts; track discount) {
|
||||
<li>{{ discount.name }} - {{ discount.discount | percent: '1.2-2' }}</li>
|
||||
}
|
||||
</ul>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
@ -1,5 +1,21 @@
|
||||
import { PercentPipe } from '@angular/common';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { MatAnchor } from '@angular/material/button';
|
||||
import { MatCard, MatCardHeader, MatCardTitleGroup, MatCardTitle, MatCardContent } from '@angular/material/card';
|
||||
import { MatIcon } from '@angular/material/icon';
|
||||
import {
|
||||
MatTable,
|
||||
MatColumnDef,
|
||||
MatHeaderCellDef,
|
||||
MatHeaderCell,
|
||||
MatCellDef,
|
||||
MatCell,
|
||||
MatHeaderRowDef,
|
||||
MatHeaderRow,
|
||||
MatRowDef,
|
||||
MatRow,
|
||||
} from '@angular/material/table';
|
||||
import { ActivatedRoute, RouterLink } from '@angular/router';
|
||||
|
||||
import { Customer } from '../../core/customer';
|
||||
|
||||
@ -9,6 +25,28 @@ import { CustomerListDatasource } from './customer-list-datasource';
|
||||
selector: 'app-customer-list',
|
||||
templateUrl: './customer-list.component.html',
|
||||
styleUrls: ['./customer-list.component.css'],
|
||||
standalone: true,
|
||||
imports: [
|
||||
MatCard,
|
||||
MatCardHeader,
|
||||
MatCardTitleGroup,
|
||||
MatCardTitle,
|
||||
MatAnchor,
|
||||
RouterLink,
|
||||
MatIcon,
|
||||
MatCardContent,
|
||||
MatTable,
|
||||
MatColumnDef,
|
||||
MatHeaderCellDef,
|
||||
MatHeaderCell,
|
||||
MatCellDef,
|
||||
MatCell,
|
||||
MatHeaderRowDef,
|
||||
MatHeaderRow,
|
||||
MatRowDef,
|
||||
MatRow,
|
||||
PercentPipe,
|
||||
],
|
||||
})
|
||||
export class CustomerListComponent implements OnInit {
|
||||
dataSource: CustomerListDatasource = new CustomerListDatasource([]);
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { Customer } from '../core/customer';
|
||||
|
||||
import { CustomerService } from './customer.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CustomerResolver {
|
||||
constructor(private ser: CustomerService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<Customer> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
import { CustomerRoutingModule } from './customer-routing.module';
|
||||
|
||||
describe('CustomersRoutingModule', () => {
|
||||
let customerRoutingModule: CustomerRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
customerRoutingModule = new CustomerRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(customerRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1,50 +0,0 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
import { CustomerDetailComponent } from './customer-detail/customer-detail.component';
|
||||
import { CustomerListComponent } from './customer-list/customer-list.component';
|
||||
import { CustomerListResolver } from './customer-list-resolver.service';
|
||||
import { CustomerResolver } from './customer-resolver.service';
|
||||
|
||||
const customersRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: CustomerListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Customers',
|
||||
},
|
||||
resolve: {
|
||||
list: CustomerListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: CustomerDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Customers',
|
||||
},
|
||||
resolve: {
|
||||
item: CustomerResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: CustomerDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
resolve: {
|
||||
item: CustomerResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild(customersRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [CustomerListResolver, CustomerResolver],
|
||||
})
|
||||
export class CustomerRoutingModule {}
|
||||
@ -1,13 +0,0 @@
|
||||
import { CustomerModule } from './customer.module';
|
||||
|
||||
describe('CustomerModule', () => {
|
||||
let customerModuleModule: CustomerModule;
|
||||
|
||||
beforeEach(() => {
|
||||
customerModuleModule = new CustomerModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(customerModuleModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1,38 +0,0 @@
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
|
||||
import { CustomerDetailComponent } from './customer-detail/customer-detail.component';
|
||||
import { CustomerListComponent } from './customer-list/customer-list.component';
|
||||
import { CustomerRoutingModule } from './customer-routing.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatCheckboxModule,
|
||||
MatDividerModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
CustomerRoutingModule,
|
||||
],
|
||||
declarations: [CustomerListComponent, CustomerDetailComponent],
|
||||
})
|
||||
export class CustomerModule {}
|
||||
11
bookie/src/app/customers/customer.resolver.ts
Normal file
11
bookie/src/app/customers/customer.resolver.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
|
||||
import { Customer } from '../core/customer';
|
||||
|
||||
import { CustomerService } from './customer.service';
|
||||
|
||||
export const customerResolver: ResolveFn<Customer> = (route) => {
|
||||
const id = route.paramMap.get('id');
|
||||
return inject(CustomerService).get(id);
|
||||
};
|
||||
41
bookie/src/app/customers/customer.routes.ts
Normal file
41
bookie/src/app/customers/customer.routes.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
import { authGuard } from '../auth/auth-guard.service';
|
||||
|
||||
import { CustomerDetailComponent } from './customer-detail/customer-detail.component';
|
||||
import { CustomerListComponent } from './customer-list/customer-list.component';
|
||||
import { customerListResolver } from './customer-list.resolver';
|
||||
import { customerResolver } from './customer.resolver';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: CustomerListComponent,
|
||||
canActivate: [authGuard],
|
||||
data: {
|
||||
permission: 'Customers',
|
||||
},
|
||||
resolve: {
|
||||
list: customerListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: CustomerDetailComponent,
|
||||
canActivate: [authGuard],
|
||||
data: {
|
||||
permission: 'Customers',
|
||||
},
|
||||
resolve: {
|
||||
item: customerResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: CustomerDetailComponent,
|
||||
canActivate: [authGuard],
|
||||
resolve: {
|
||||
item: customerResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user