Skip to content

Commit 21a964c

Browse files
committed
feat: TT-26 detect changes in projects and project types
1 parent 155acea commit 21a964c

File tree

10 files changed

+48
-24
lines changed

10 files changed

+48
-24
lines changed

src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
formControlName="name"
99
placeholder="Customer name"
1010
[class.is-invalid]="customerForm.invalid && customerForm.touched"
11-
(input)="onSearchChange($event.target.value)"
11+
(input)="onSearchChanges($event.target.value)"
1212
required
1313
/>
1414
<span
@@ -24,7 +24,7 @@
2424
rows="3"
2525
formControlName="description"
2626
placeholder="Customer description"
27-
(input)="onSearchChange($event.target.value)"
27+
(input)="onSearchChanges($event.target.value)"
2828
></textarea>
2929
</div>
3030
<button type="submit" class="btn btn-primary" [disabled]="!customerForm.valid">Save</button>

src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
2424
customerForm: FormGroup;
2525
@Input() areTabsActive: boolean;
2626
@Input() haveChanges: boolean;
27-
@Output() ishaveChanges = new EventEmitter<boolean>();
27+
@Output() isHaveChanges = new EventEmitter<boolean>();
2828
@Output() changeValueAreTabsActives = new EventEmitter<boolean>();
2929
@Output() closeCustomerComponent = new EventEmitter<boolean>();
3030
customerToEdit: Customer;
@@ -70,7 +70,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
7070
this.store.dispatch(new LoadProjectTypes(customerData.id));
7171
this.store.dispatch(new LoadCustomerProjects(customerData.id));
7272
this.changeValueAreTabsActives.emit(true);
73-
this.ishaveChanges.emit(this.haveChanges = false);
73+
this.isHaveChanges.emit(this.haveChanges = false);
7474
this.customerForm.setValue({
7575
name: customerData.name,
7676
description: customerData.description,
@@ -98,13 +98,8 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
9898
this.closeCustomerComponent.emit(false);
9999
}
100100

101-
onSearchChange(searchValue: string): void {
102-
if (searchValue) {
103-
this.haveChanges = true;
104-
this.ishaveChanges.emit(this.haveChanges);
105-
} else {
106-
this.haveChanges = false;
107-
this.ishaveChanges.emit(this.haveChanges);
108-
}
101+
onSearchChanges(searchValue: string): void {
102+
return searchValue ? this.isHaveChanges.emit(this.haveChanges = true) :
103+
this.isHaveChanges.emit(this.haveChanges = false);
109104
}
110105
}

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
3232
changeCustomerSubscription: Subscription;
3333
showModal = false;
3434
idToDelete: string;
35-
idToEdit: string;
3635
message: string;
3736
isLoading$: Observable<boolean>;
3837

src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h4 class="navbar-brand nav-title">{{customerName}}</h4>
5555
<app-create-customer
5656
[areTabsActive]="areTabsActive"
5757
(changeValueAreTabsActives)="activeTabs($event)"
58-
(ishaveChanges)="getChangesInputs($event)"
58+
(isHaveChanges)="getChanges($event)"
5959
(closeCustomerComponent)="closeCustomer($event)"
6060
></app-create-customer>
6161
</div>
@@ -67,7 +67,7 @@ <h4 class="navbar-brand nav-title">{{customerName}}</h4>
6767
aria-labelledby="projects-type-tab"
6868
>
6969
<div class="container">
70-
<app-create-project-type></app-create-project-type>
70+
<app-create-project-type (isHaveChanges)="getChanges($event)"></app-create-project-type>
7171
<app-project-type-list></app-project-type-list>
7272
</div>
7373
</div>
@@ -79,7 +79,7 @@ <h4 class="navbar-brand nav-title">{{customerName}}</h4>
7979
aria-labelledby="projects-tab"
8080
>
8181
<div class="container mb-1">
82-
<app-create-project></app-create-project>
82+
<app-create-project (isHaveChanges)="getChanges($event)"></app-create-project>
8383
<app-project-list></app-project-list>
8484
</div>
8585
</div>

src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export class ManagementCustomerProjectsComponent implements OnInit {
4444
this.activeTab = activeTab;
4545
}
4646

47-
getChangesInputs($haveChanges: boolean) {
47+
getChanges($haveChanges: boolean) {
48+
console.log('llegando cambios', $haveChanges);
4849
setTimeout(() => {
4950
this.haveChanges = $haveChanges;
5051
this.sendChanges.emit($haveChanges);

src/app/modules/customer-management/components/projects-type/components/create-project-type/create-project-type.component.html

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
<form style="width: 600px;" [formGroup]="projectTypeForm" (ngSubmit)="onSubmit(projectTypeForm.value)">
22
<div class="form-group">
3-
<input type="text" class="form-control form-control-sm" id="name" formControlName="name" aria-describedby=""
4-
[class.is-invalid]="name.invalid && name.touched" required placeholder="Name" />
3+
<input type="text"class="form-control form-control-sm"
4+
id="name"
5+
formControlName="name"
6+
aria-describedby=""
7+
[class.is-invalid]="name.invalid && name.touched"
8+
required placeholder="Name"
9+
(input)="onSearchChanges($event.target.value)"
10+
/>
511
<div class="text-danger" *ngIf="(name.dirty || name.touched) && name.invalid && name.errors.required">
612
Name is required.
713
</div>
814
</div>
915
<div class="form-group">
10-
<textarea class="form-control form-control-sm mt-2" id="descriptionTextArea" rows="3" placeholder="Description"
11-
formControlName="description"></textarea>
16+
<textarea class="form-control
17+
form-control-sm mt-2"
18+
id="descriptionTextArea"
19+
rows="3"
20+
placeholder="Description"
21+
formControlName="description"
22+
(input)="onSearchChanges($event.target.value)"
23+
></textarea>
1224
</div>
1325
<button type="submit" class="btn btn-primary" [disabled]="!projectTypeForm.valid">
1426
Save

src/app/modules/customer-management/components/projects-type/components/create-project-type/create-project-type.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, OnDestroy } from '@angular/core';
1+
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
22
import { FormBuilder, Validators, FormGroup } from '@angular/forms';
33
import { Store, select } from '@ngrx/store';
44

@@ -14,6 +14,8 @@ import { Subscription } from 'rxjs';
1414
styleUrls: ['./create-project-type.component.scss'],
1515
})
1616
export class CreateProjectTypeComponent implements OnInit, OnDestroy {
17+
@Input() haveChanges: boolean;
18+
@Output() isHaveChanges = new EventEmitter<boolean>();
1719
projectTypeForm: FormGroup;
1820
projectTypeToEdit: ProjectType;
1921
customerId: string;
@@ -63,9 +65,11 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
6365
id: this.projectTypeToEdit.id,
6466
};
6567
this.store.dispatch(new UpdateProjectType(projectType));
68+
this.isHaveChanges.emit(this.haveChanges = false);
6669
} else {
6770
this.store.dispatch(new CreateProjectType({ ...projectTypeData, customer_id: this.customerId }));
6871
this.projectTypeForm.get('description').setValue('');
72+
this.isHaveChanges.emit(this.haveChanges = false);
6973
}
7074
}
7175

@@ -76,4 +80,9 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
7680
ngOnDestroy(): void {
7781
this.getCustomerIdSubscription.unsubscribe();
7882
}
83+
84+
onSearchChanges(searchValue: string): void {
85+
return searchValue ? this.isHaveChanges.emit(this.haveChanges = true) :
86+
this.isHaveChanges.emit(this.haveChanges = false);
87+
}
7988
}

src/app/modules/customer-management/components/projects/components/create-project/create-project.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
placeholder="Project name"
77
formControlName="name"
88
[class.is-invalid]="name.invalid && name.touched"
9+
(input)="onSearchChanges($event.target.value)"
910
/>
1011
<div class="text-danger" *ngIf="(name.dirty || name.touched) && name.invalid && name.errors.required">
1112
Project name is required.
@@ -16,6 +17,7 @@
1617
rows="3"
1718
formControlName="description"
1819
placeholder="Description"
20+
(input)="onSearchChanges($event.target.value)"
1921
></textarea>
2022
<div class="form-group">
2123
<select class="custom-select custom-select-sm mt-2" formControlName="project_type_id">

src/app/modules/customer-management/components/projects/components/create-project/create-project.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, OnDestroy } from '@angular/core';
1+
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
22
import { FormBuilder, Validators } from '@angular/forms';
33
import { Store, select } from '@ngrx/store';
44

@@ -16,6 +16,8 @@ import { getCustomerId } from 'src/app/modules/customer-management/store/custome
1616
styleUrls: ['./create-project.component.scss'],
1717
})
1818
export class CreateProjectComponent implements OnInit, OnDestroy {
19+
@Input() haveChanges: boolean;
20+
@Output() isHaveChanges = new EventEmitter<boolean>();
1921
projectForm;
2022
projectToEdit: Project;
2123
projectsTypes: ProjectType[] = [];
@@ -107,4 +109,9 @@ export class CreateProjectComponent implements OnInit, OnDestroy {
107109
project_type_id: null,
108110
});
109111
}
112+
113+
onSearchChanges(searchValue: string): void {
114+
return searchValue ? this.isHaveChanges.emit(this.haveChanges = true) :
115+
this.isHaveChanges.emit(this.haveChanges = false);
116+
}
110117
}

src/app/modules/customer-management/pages/customer.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ export class CustomerComponent {
2727
getChangesInputs(event) {
2828
this.haveChanges = event;
2929
}
30-
3130
}

0 commit comments

Comments
 (0)