Skip to content

Commit c893bc0

Browse files
committed
noworking commit
1 parent 8abf25b commit c893bc0

File tree

7 files changed

+103
-18
lines changed

7 files changed

+103
-18
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@
1414
<th class="col-2 text-center">Visibility</th>
1515
</tr>
1616
</thead>
17-
<app-loading-bar *ngIf="(isLoading$ | async)"></app-loading-bar>
18-
<tbody *ngIf="((isLoading$ | async) === false)">
17+
<app-loading-bar *ngIf="isLoading$ | async"></app-loading-bar>
18+
<tbody *ngIf="(isLoading$ | async) === false">
1919
<tr class="d-flex" *ngFor="let customer of customers">
2020
<td class="col-4 text-break">{{ customer.id }}</td>
2121
<td class="col-4 text-break">{{ customer.name }}</td>
2222
<td class="col-2 text-center">
2323
<button
2424
data-toggle="modal"
25-
(click)="editCustomer(customer.id)"
26-
type="button" data-target="#editModal"
27-
class="btn btn-sm btn-primary">
25+
(click)="editCustomer(customer.id); scrollToCustomerForm()"
26+
type="button"
27+
data-target="#editModal"
28+
class="btn btn-sm btn-primary"
29+
>
2830
<i class="fa fa-pen fa-xs"></i>
2931
</button>
3032
</td>
3133
<td class="col-2 text-center">
32-
<app-dropdown
33-
[info] = "customer"
34-
(updateInfo) = "switchStatus($event)"
35-
> </app-dropdown>
34+
<app-dropdown [info]="customer" (updateInfo)="switchStatus($event)"> </app-dropdown>
3635
</td>
3736
</tr>
3837
</tbody>
@@ -62,5 +61,5 @@
6261
[title]="'Edit Customer'"
6362
[body]="message"
6463
(closeModalEvent)="closeModal()"
65-
>
64+
>
6665
</app-dialog>

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ describe('CustomerTableListComponent', () => {
8484

8585
it('Onclick Edit, if there are changes, the modal must be presented ', () => {
8686
component.hasChange = true;
87-
const expectMessage = 'Do you have changes in a client, do you want to discard them?';
87+
const expectMessage = 'You have changes in a client, do you want to discard them?';
8888

8989
component.editCustomer('1');
9090

9191
expect(component.message).toEqual(expectMessage);
9292
expect(component.showModal).toBeTrue();
9393
});
9494

95-
it('onClick edit, if there are not have changes dispatch SetCustomerToEdit, enable customer form and hidden modal', () => {
95+
it('onClick edit, if there are no unsaved changes dispatch SetCustomerToEdit, enable customer form and hidden modal', () => {
9696
component.hasChange = false;
9797

9898
spyOn(store, 'dispatch');
@@ -104,6 +104,17 @@ describe('CustomerTableListComponent', () => {
104104
expect(component.showModal).toBeFalse();
105105
});
106106

107+
it('onClick edit, if there are no unsaved changes customer edit form should be visible', () => {
108+
component.hasChange = false;
109+
110+
spyOn(store, 'dispatch');
111+
112+
component.editCustomer('1');
113+
const bottomElement = document.getElementById("bottom");
114+
expect(bottomElement).toBeTrue();
115+
116+
});
117+
107118
it('onClick edit, dispatch clean Forms in project and project type', () => {
108119
spyOn(store, 'dispatch');
109120

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,15 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
117117
editCustomer(customerId: string) {
118118
this.idToEdit = customerId;
119119
if (this.hasChange) {
120-
this.message = 'Do you have changes in a client, do you want to discard them?';
120+
this.message = 'You have changes in a client, do you want to discard them?';
121121
this.showModal = true;
122122
} else {
123123
this.showCustomerForm = true;
124124
this.showModal = false;
125125
this.changeValueShowCustomerForm.emit(this.showCustomerForm);
126126
this.resetProjectFieldsToEdit();
127127
this.store.dispatch(new SetCustomerToEdit(customerId));
128+
128129
}
129130
}
130131

@@ -199,4 +200,43 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
199200
this.store.dispatch(new UnarchiveCustomer(this.idToDelete, this.changeOppositeStatus(this.statusToEdit)));
200201
}
201202

203+
scrollToCustomerForm(): void {
204+
/* Makes the editCustomer form visible */
205+
const element = document.getElementById("bottom");
206+
element.scrollIntoView();
207+
}
208+
209+
210+
isVisible( elm ) {
211+
/* Check if an element is visible on the screen */
212+
const vpH = $(window).height(); // Viewport Height
213+
const st = $(window).scrollTop(); // Scroll Top
214+
const y = $(elm).offset().top;
215+
const elementHeight = $(elm).height();
216+
console.log(vpH, st, y, elementHeight);
217+
218+
return ((y < (vpH + st)) && (y > (st - elementHeight)));
219+
}
220+
221+
waitForForm() {
222+
const selector = "customerFormDiv";
223+
return new Promise(resolve => {
224+
if (document.querySelector(selector)) {
225+
return resolve(document.querySelector(selector));
226+
}
227+
228+
const observer = new MutationObserver(mutations => {
229+
if (document.querySelector(selector)) {
230+
resolve(document.querySelector(selector));
231+
observer.disconnect();
232+
}
233+
});
234+
235+
observer.observe(document.body, {
236+
childList: true,
237+
subtree: true
238+
});
239+
});
240+
}
241+
202242
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<div class="container-fluid px-0 full-height">
22
<div class="row">
33
<div style="padding: 15px;">
4-
<button (click)="activateCustomerForm()" class="btn btn-primary">Add new customer</button>
4+
<button (click)="activateCustomerForm(); scrollToCustomerForm()" class="btn btn-primary">Add new customer</button>
55
</div>
66
</div>
77
<app-customer-list
88
[showCustomerForm]="showCustomerForm"
99
[hasChange]="hasChangeComponent"
1010
(changeValueShowCustomerForm)="showCustomerForm = $event"
1111
></app-customer-list>
12-
<div class="row" *ngIf="showCustomerForm">
13-
<div class="col">
14-
<app-management-customer-projects (sendChanges)="getChangesInputs($event)" (closeCustemerForm)="closeCustomerForm($event)"></app-management-customer-projects>
12+
<div id="bottom">
13+
<div class="row" *ngIf="showCustomerForm">
14+
<div class="col" id="customerFormDiv">
15+
<app-management-customer-projects
16+
(sendChanges)="getChangesInputs($event)"
17+
(closeCustemerForm)="closeCustomerForm($event)"
18+
></app-management-customer-projects>
19+
</div>
1520
</div>
1621
</div>
1722
</div>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,16 @@ describe('CustomerComponent', () => {
5454

5555
expect(component.hasChangeComponent).toBe(true);
5656
});
57+
58+
59+
60+
function isVisible( elm ) {
61+
/* Check if an element is visible on the screen */
62+
const vpH = $(window).height(); // Viewport Height
63+
const st = $(window).scrollTop(); // Scroll Top
64+
const y = $(elm).offset().top;
65+
const elementHeight = $(elm).height();
66+
67+
return ((y < (vpH + st)) && (y > (st - elementHeight)));
68+
}
5769
});

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,22 @@ export class CustomerComponent {
2828
getChangesInputs(event) {
2929
this.hasChangeComponent = event;
3030
}
31+
32+
33+
scrollToCustomerForm(): void {
34+
const element = document.getElementById("bottom");
35+
element.scrollIntoView();
36+
this.isVisible(element);
37+
}
38+
39+
40+
isVisible( elm ) {
41+
/* Check if an element is visible on the screen */
42+
const vpH = $(window).height(); // Viewport Height
43+
const st = $(window).scrollTop(); // Scroll Top
44+
const y = $(elm).offset().top;
45+
const elementHeight = $(elm).height();
46+
47+
return ((y < (vpH + st)) && (y > (st - elementHeight)));
48+
}
3149
}

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const webpack = require('webpack')
22
const { addTailwindPlugin } = require("@ngneat/tailwind");
33
const tailwindConfig = require("./tailwind.config.js");
4-
require('dotenv').config();
4+
require('dotenv').config({ path: './.dev.env' });
55

66
module.exports = (config) => {
77
const config_ = {

0 commit comments

Comments
 (0)