Commit cdc26eca authored by hasan khaddour's avatar hasan khaddour

comlete customer module

parent d87245d9
...@@ -24,7 +24,7 @@ import { JwtInterceptor } from './core/interceptors/jwt.interceptor'; ...@@ -24,7 +24,7 @@ import { JwtInterceptor } from './core/interceptors/jwt.interceptor';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ToastrModule } from 'ngx-toastr'; import { ToastrModule } from 'ngx-toastr';
import { NgxPaginationModule } from 'ngx-pagination'; import { NgxPaginationModule } from 'ngx-pagination';
import { CustomerRoutingModule } from './customers/customer-routing.module'; import { CustomerRoutingModule } from './customers/routing/customer-routing.module';
import { LoadingInterceptor } from './core/interceptors/loading.interceptor'; import { LoadingInterceptor } from './core/interceptors/loading.interceptor';
import { ProjectsModule } from './projects/projects.module'; import { ProjectsModule } from './projects/projects.module';
import { ProjectRoutingModule } from './projects/project-routing.module'; import { ProjectRoutingModule } from './projects/project-routing.module';
......
import { Component, Input, OnInit } from '@angular/core'; import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Customer } from '../../models/responses/customer'; import { Customer } from '../../models/responses/customer';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { CustomerService } from '../../services/customer.service'; import { CustomerService } from '../../services/customer.service';
...@@ -13,7 +13,7 @@ import { AddContactInfoRequest } from '../../models/requests/updateCustomerReque ...@@ -13,7 +13,7 @@ import { AddContactInfoRequest } from '../../models/requests/updateCustomerReque
export class AddContactinfoModalComponent implements OnInit{ export class AddContactinfoModalComponent implements OnInit{
@Input() customer :Customer @Input() customer :Customer
@Output() added = new EventEmitter<void>();
request =new AddContactInfoRequest(); request =new AddContactInfoRequest();
constructor( constructor(
...@@ -46,6 +46,7 @@ export class AddContactinfoModalComponent implements OnInit{ ...@@ -46,6 +46,7 @@ export class AddContactinfoModalComponent implements OnInit{
.subscribe({ .subscribe({
next : (data)=>{ next : (data)=>{
this.added.emit();
this.onClose() this.onClose()
}, },
error:(err)=>{ error:(err)=>{
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</div> </div>
<div class="row "> <div class="row ">
<button type="submit" [disabled]="projectForm.invalid " class="col m-4 btn btn-primary">إضافة</button> <button type="submit" [disabled]="projectForm.invalid " class="col m-4 btn btn-danger">إزالة</button>
<button class="col m-4 btn btn-seondary" (click)="onClose()" >إغلاق</button> <button class="col m-4 btn btn-seondary" (click)="onClose()" >إغلاق</button>
</div> </div>
......
import { Component, Input } from '@angular/core'; import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ContactInfo, Customer } from '../../models/responses/customer'; import { ContactInfo, Customer } from '../../models/responses/customer';
import { RemoveContactInfoRequest } from '../../models/requests/updateCustomerRequest'; import { RemoveContactInfoRequest } from '../../models/requests/updateCustomerRequest';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
...@@ -13,8 +13,8 @@ import { CustomerService } from '../../services/customer.service'; ...@@ -13,8 +13,8 @@ import { CustomerService } from '../../services/customer.service';
export class RemoveContactinfoModalComponent { export class RemoveContactinfoModalComponent {
@Input() contact :ContactInfo @Input() contact :ContactInfo
@Input() customer :Customer @Input() customer :Customer
@Output() removed = new EventEmitter<void>()
request =new RemoveContactInfoRequest(); request =new RemoveContactInfoRequest();
...@@ -48,6 +48,7 @@ export class RemoveContactinfoModalComponent { ...@@ -48,6 +48,7 @@ export class RemoveContactinfoModalComponent {
.removeContactInfo(this.request) .removeContactInfo(this.request)
.subscribe({ .subscribe({
next : (data)=>{ next : (data)=>{
this.removed.emit();
this.onClose(); this.onClose();
}, },
error:(err)=>{ error:(err)=>{
......
...@@ -5,7 +5,7 @@ import { CustomerService } from './services/customer.service'; ...@@ -5,7 +5,7 @@ import { CustomerService } from './services/customer.service';
import { FormsModule, NgModel } from '@angular/forms'; import { FormsModule, NgModel } from '@angular/forms';
import { CustomerDetailsComponent } from './pages/customer-details/customer-details.component'; import { CustomerDetailsComponent } from './pages/customer-details/customer-details.component';
import { UpdateCustomerComponent } from './pages/update-customer/update-customer.component'; import { UpdateCustomerComponent } from './pages/update-customer/update-customer.component';
import { CustomerRoutingModule } from './customer-routing.module'; import { CustomerRoutingModule } from './routing/customer-routing.module';
import { SharedModule } from "../shared/shared.module"; import { SharedModule } from "../shared/shared.module";
import { CustomerItemComponent } from './components/customer-item/customer-item.component'; import { CustomerItemComponent } from './components/customer-item/customer-item.component';
import { CustomerCreateComponent } from './pages/customer-create/customer-create.component'; import { CustomerCreateComponent } from './pages/customer-create/customer-create.component';
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
<form class="php-email-form"> <form class="php-email-form">
<div class="row gy-4"> <div class="row gy-4">
<div class="row text-center"> <div class="row text-center">
<p> <h3 class="text-center text-primary p-4">
إضافة جهة طارحة إضافة جهة طارحة
</p> </h3>
</div> </div>
<div class="col-12"> <div class="col-12">
<input type="text" [(ngModel)]="request.customerName" <input type="text" [(ngModel)]="request.customerName"
......
...@@ -17,12 +17,18 @@ import { RemoveContactinfoModalComponent } from '../../components/remove-contact ...@@ -17,12 +17,18 @@ import { RemoveContactinfoModalComponent } from '../../components/remove-contact
}) })
export class CustomerDetailsComponent implements OnInit { export class CustomerDetailsComponent implements OnInit {
//#region Properties
modalMode: 'edit' | 'delete' = 'edit'; modalMode: 'edit' | 'delete' = 'edit';
modalTitle: string = ''; modalTitle: string = '';
customerId : number customerId : number
customer: Customer ; customer: Customer ;
selectedCustomer :Customer ; selectedCustomer :Customer ;
//#endregion Properties
constructor( constructor(
private router : Router, private router : Router,
private route: ActivatedRoute, private route: ActivatedRoute,
...@@ -39,15 +45,16 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -39,15 +45,16 @@ export class CustomerDetailsComponent implements OnInit {
loadCustomer (){ loadCustomer (){
this.customerService.getCustomerById(this.customerId).subscribe({ this
.customerService
.getCustomerById(this.customerId)
.subscribe({
next :(data) => { next :(data) => {
this.customer = data; this.customer = data;
this.selectedCustomer=this.customer; this.selectedCustomer=this.customer;
}, },
error : (err)=>{ console.log(err)} error : (err)=>{ console.log(err)}
}); });
} }
...@@ -56,7 +63,8 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -56,7 +63,8 @@ export class CustomerDetailsComponent implements OnInit {
if (mode === 'edit') { if (mode === 'edit') {
this.modalTitle = 'تعديل جهة طارحة '; this.modalTitle = 'تعديل جهة طارحة ';
} else if (mode === 'delete') { }
else if (mode === 'delete') {
this.modalTitle = 'حذف جهة طارحة'; this.modalTitle = 'حذف جهة طارحة';
} }
...@@ -64,6 +72,7 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -64,6 +72,7 @@ export class CustomerDetailsComponent implements OnInit {
if (modalElement) { if (modalElement) {
new Modal(modalElement).show(); // Open the modal new Modal(modalElement).show(); // Open the modal
} }
} }
saveCustomer(): void { saveCustomer(): void {
...@@ -74,7 +83,10 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -74,7 +83,10 @@ export class CustomerDetailsComponent implements OnInit {
customerName:this.selectedCustomer.customerName customerName:this.selectedCustomer.customerName
} }
this.customerService.updateCustomer(this.selectedCustomer.id,request).subscribe({ this
.customerService
.updateCustomer(this.selectedCustomer.id,request)
.subscribe({
next :()=>{ next :()=>{
this.customer.address=this.selectedCustomer.address ; this.customer.address=this.selectedCustomer.address ;
...@@ -85,8 +97,8 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -85,8 +97,8 @@ export class CustomerDetailsComponent implements OnInit {
} }
, ,
error:(err)=>{ error:(err)=>{
this.toastr.error("لقد حدث خطاء ما ")
this.toastr.error("لقد حدث خطاء ما ")
this.closeModal(); this.closeModal();
} }
...@@ -96,7 +108,10 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -96,7 +108,10 @@ export class CustomerDetailsComponent implements OnInit {
delete(): void { delete(): void {
this.customerService.deleteCustomer(this.customer.id).subscribe({ this
.customerService
.deleteCustomer(this.customer.id)
.subscribe({
next :()=>{ next :()=>{
this.router.navigate(['/customers']) this.router.navigate(['/customers'])
...@@ -105,14 +120,13 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -105,14 +120,13 @@ export class CustomerDetailsComponent implements OnInit {
} }
, ,
error:(err)=>{ error:(err)=>{
this.toastr.error("لقد حدث خطاء ما ")
this.toastr.error("لقد حدث خطاء ما ")
this.closeModal(); this.closeModal();
} }
} });
);
} }
...@@ -121,8 +135,21 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -121,8 +135,21 @@ export class CustomerDetailsComponent implements OnInit {
const modalRef = this.modalService.open(AddContactinfoModalComponent); const modalRef = this.modalService.open(AddContactinfoModalComponent);
modalRef.componentInstance.customer = this.customer; modalRef.componentInstance.customer = this.customer;
modalRef
.componentInstance
.added
.subscribe({
next : ()=>{
modalRef.result.then((result) => { this.loadCustomer();
}
});
modalRef.result.then(
(result) => {
if (result) { if (result) {
...@@ -130,10 +157,13 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -130,10 +157,13 @@ export class CustomerDetailsComponent implements OnInit {
} }
}, (reason) => { }
, (reason) => {
this.loadCustomer(); this.loadCustomer();
}); }
);
} }
...@@ -143,6 +173,18 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -143,6 +173,18 @@ export class CustomerDetailsComponent implements OnInit {
modalRef.componentInstance.customer = this.customer; modalRef.componentInstance.customer = this.customer;
modalRef.componentInstance.contact= conta modalRef.componentInstance.contact= conta
modalRef
.componentInstance
.removed
.subscribe({
next : ()=>{
this.loadCustomer();
}
});
modalRef.result.then((result) => { modalRef.result.then((result) => {
if (result) { if (result) {
...@@ -166,5 +208,4 @@ export class CustomerDetailsComponent implements OnInit { ...@@ -166,5 +208,4 @@ export class CustomerDetailsComponent implements OnInit {
} }
} }
\ No newline at end of file
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { CustomerListComponent } from './pages/customer-list/customer-list.component'; import { CustomerCreateComponent } from '../pages/customer-create/customer-create.component';
import { UpdateCustomerComponent } from './pages/update-customer/update-customer.component'; import { UpdateCustomerComponent } from '../pages/update-customer/update-customer.component';
import { CustomerDetailsComponent } from './pages/customer-details/customer-details.component'; import { CustomerDetailsComponent } from '../pages/customer-details/customer-details.component';
import { CustomerCreateComponent } from './pages/customer-create/customer-create.component'; import { CustomerListComponent } from '../pages/customer-list/customer-list.component';
const routes: Routes = [ const routes: Routes = [
{ path: '', component: CustomerListComponent }, { path: '', component: CustomerListComponent },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment