Skip to content

Commit

Permalink
Feature/#181 child info box (#182)
Browse files Browse the repository at this point in the history
* info-child-box works

* style fix

* refactoring

* fix

* directive

* style
  • Loading branch information
litvinets authored Apr 30, 2021
1 parent 0b6f9cf commit 879ec3f
Show file tree
Hide file tree
Showing 38 changed files with 640 additions and 209 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<mat-card class="card" #childInfoBox [style]="{top:top, left:left}">
<mat-card-header fxLayout='column' fxLayoutAlign='center start'>
<div mat-card-avatar fxLayout='column' fxLayoutAlign='center start'></div>
<mat-card-title>ДАНІ ДИТИНИ</mat-card-title>
<h3>{{child.firstName}} {{child.lastName}} {{child.patronymic}}</h3>
<h4>{{child.birthDay}}</h4><br>
</mat-card-header>
<mat-card-content fxLayout='column' fxLayoutAlign='center start'>
<h4>Соціальна група</h4>
<p>Відсутня</p>
<h4>Батьки</h4>
<p>{{child.parent?.firstName}} {{child.parent.lastName}} {{child.parent.secondName}}</p>
<h4>Телефон</h4>
<p>{{child.parent?.phone}}</p>
<h4>Емейл</h4>
<p>{{child.parent?.email}}</p>
</mat-card-content>
</mat-card>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.card{
display: block;
position: absolute;
z-index: 2;
background:white;
box-shadow: 0px 6px 16px rgba(0, 0, 0, 0.08);
min-width:400px;
border-radius: 5px;
padding: 1rem;
margin: 1rem 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ChildInfoBoxComponent } from './child-info-box.component';

describe('ChildInfoBoxComponent', () => {
let component: ChildInfoBoxComponent;
let fixture: ComponentFixture<ChildInfoBoxComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ChildInfoBoxComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ChildInfoBoxComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
import { Child } from '../../models/child.model';

@Component({
selector: 'app-child-info-box',
templateUrl: './child-info-box.component.html',
styleUrls: ['./child-info-box.component.scss']
})
export class ChildInfoBoxComponent implements OnInit {

constructor() { }

@Input() child: Child;
@ViewChild('childInfoBox') childInfoBox: ElementRef<HTMLInputElement>;
@Input() top: string;
@Input() left: string;

ngOnInit(): void {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="card_header" fxLayout="row" fxLayoutAlign="end start">
<div *ngIf="!(isMainPage$ | async) then ProviderActions; else UserActions"></div>
<a href="#" class="card_category">
<img src="assets/icons/{{card.category}}.png" alt="{{card.category}}" class="card_category-img">
<img src="assets/icons/{{workshop.category}}.png" alt="{{workshop.category}}" class="card_category-img">
</a>
</div>
<div *ngIf="( isMainPage$ | async) then MainView; else ProviderActivities"></div>
Expand All @@ -16,38 +16,38 @@
<ng-template #MainView>
<div class="card_body">
<h3 class="card_title">
{{card.title}}
{{workshop.title}}
</h3>
<ul class="card_data">
<li class="card_data-item">
<img src="assets/icons/rate.png" alt="rate" class="card_data-icon">
{{card.rate}} <span class="card_rate-span">({{card.votes}})</span>
{{workshop.rate}} <span class="card_rate-span">({{workshop.votes}})</span>
</li>
<li class="card_data-item">
<img src="assets/icons/name.png" alt="name" class="card_data-icon">
<a href="#" class="card_owner">
{{card.head}}
{{workshop.head}}
</a>
</li>
<li class="card_data-item">
<img src="assets/icons/age.png" alt="age" class="card_data-icon">
{{card.minAge}}-{{card.maxAge}}
{{workshop.minAge}}-{{workshop.maxAge}}
</li>
<li class="card_data-item">
<img src="assets/icons/price.png" alt="price" class="card_data-icon">
{{card.price}}
{{workshop.price}}
</li>
<li class="card_data-item">
<img src="assets/icons/address.png" alt="address" class="card_data-icon">
{{card.address.city}}, {{card.address.street}}, {{card.address.buildingNumber}}
{{workshop.address.city}}, {{workshop.address.street}}, {{workshop.address.buildingNumber}}
</li>
</ul>
</div>
</ng-template>
<ng-template #ProviderActivities>
<div class="card_body">
<h3 class="card_title">
{{card.title}}
{{workshop.title}}
</h3>
<ul class="card_data">
<li class="card_data-item">
Expand All @@ -69,7 +69,7 @@ <h3 class="card_title">
<ng-template #ProviderActions>
<div fxLayout="row" fxLayoutAlign="end start">
<div class="actions_btn"><img src="assets/icons/edit.png" alt="edit"></div>
<div class="actions_btn"><img src="assets/icons/delete.png" alt="delete"></div>
<div class="actions_btn"><img src="assets/icons/delete.png" alt="delete" (click)="onDelete()"></div>
</div>
</ng-template>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, Input, OnInit } from '@angular/core';
import { Select } from '@ngxs/store';
import { Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { Workshop } from '../../models/workshop.model';
import { AppState } from '../../store/app.state';
import { DeleteWorkshop } from '../../store/provider.actions';

@Component({
selector: 'app-workshop-card',
Expand All @@ -13,11 +14,14 @@ export class WorkshopCardComponent implements OnInit {

@Select(AppState.isMainPage)
isMainPage$: Observable<boolean>;
@Input() card: Workshop;
@Input() workshop: Workshop;

constructor() { }
constructor(private store: Store) { }

ngOnInit(): void {
}

onDelete(): void {
this.store.dispatch(new DeleteWorkshop(this.workshop))
}
}
8 changes: 8 additions & 0 deletions src/app/shared/directives/info-box-host.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { InfoBoxHostDirective } from './info-box-host.directive';

describe('InfoBoxHostDirective', () => {
it('should create an instance', () => {
const directive = new InfoBoxHostDirective();
expect(directive).toBeTruthy();
});
});
10 changes: 10 additions & 0 deletions src/app/shared/directives/info-box-host.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Directive, ViewContainerRef } from '@angular/core';

@Directive({
selector: '[appInfoBoxHost]'
})
export class InfoBoxHostDirective {

constructor(public viewContainerRef: ViewContainerRef) { }

}
2 changes: 2 additions & 0 deletions src/app/shared/models/application.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Child } from "./child.model";
import { Provider } from "./provider.model";
import { Workshop } from "./workshop.model";

export class Application {
Expand All @@ -8,6 +9,7 @@ export class Application {
date: Date;
workshop: Workshop;
child: Child;
provider: Provider;

constructor(info) {
this.id = null;
Expand Down
21 changes: 11 additions & 10 deletions src/app/shared/models/child.model.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@

import { Parent } from "./parent.model";
export class Child {
firstName: string;
lastName: string;
secondName: string;
birthDay: Date;
patronymic: string;
birthDay: string;
type: Boolean;
gender: string;
gender: number;
parent: Parent;
socialGroupId: number;


constructor(info) {
this.firstName = info.firstName;
this.lastName= info.lastName;
this.secondName= info.secondName;
this.birthDay= info.birthDay;
this.type = info.type;
this.gender = info.gender;
this.lastName = info.lastName;
this.patronymic = info.second;
this.birthDay = "2021-04-27";
this.gender = 0;
this.socialGroupId = 0;
}
}

17 changes: 17 additions & 0 deletions src/app/shared/models/parent.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export class Parent {
firstName: string;
lastName: string;
secondName: string;
birthDay: Date;
gender: string;
phone: string;
email: string;

constructor(info) {
this.firstName = info.firstName;
this.lastName = info.lastName;
this.secondName = info.secondName;
this.birthDay = info.birthDay;
this.gender = info.gender;
}
}
12 changes: 12 additions & 0 deletions src/app/shared/models/provider.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Workshop } from "./workshop.model";

export class Provider {
title: string;
phone: string;
email: string;
workshop: Workshop

constructor(info) {
this.title = info.title;
}
}
1 change: 1 addition & 0 deletions src/app/shared/models/workshop.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Workshop {
ownership: string;
rate: string;
votes: string;
placeAmount: number;

constructor(about, description, addr, tchrs) {
this.title = about.title;
Expand Down
9 changes: 4 additions & 5 deletions src/app/shared/services/child-cards/child-cards.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import { Child } from '../../models/child.model';
})
export class ChildCardService {

dataUrl = '/Child/Get'

constructor(private http: HttpClient) { }

getCards(): Observable<Child[]> {
getChildren(): Observable<Child[]> {
return this.http.get<Child[]>('/Child/Get')
}
createChildren( child: Child): void {
this.http.post('/Child/Create', child).subscribe(child => console.log(child));

createChildren(child: Child): void {
this.http.post('/Child/Create', child);
}
}
16 changes: 16 additions & 0 deletions src/app/shared/services/info-box/info-box.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { InfoBoxService } from './info-box.service';

describe('InfoBoxService', () => {
let service: InfoBoxService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(InfoBoxService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
56 changes: 56 additions & 0 deletions src/app/shared/services/info-box/info-box.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Component, ComponentFactoryResolver, Injectable, Type, ViewContainerRef } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { ChildInfoBoxComponent } from '../../components/child-info-box/child-info-box.component';
import { Child } from '../../models/child.model';

@Injectable({
providedIn: 'root'
})
export class InfoBoxService {

private isMouseOver = new BehaviorSubject(false);
isMouseOver$ = this.isMouseOver.asObservable();
child: Child;
top: string;
left: string;

constructor(private cfr: ComponentFactoryResolver) { }

onMouseOver({ element, child }: { element: Element, child: Child }) {
this.isMouseOver.next(true);
this.child = child;
this.getPosition(element);
}

onMouseLeave() {
this.isMouseOver.next(false);
}

async loadComponent(vcr: ViewContainerRef, isMouseOver: boolean) {
const { ChildInfoBoxComponent } = await import('../../components/child-info-box/child-info-box.component');

vcr.clear();
const component: Type<ChildInfoBoxComponent> = ChildInfoBoxComponent;
if (isMouseOver) {
const componentRef = vcr.createComponent(this.cfr.resolveComponentFactory(component));

(<ChildInfoBoxComponent>componentRef.instance).child = this.child ? this.child : null;
(<ChildInfoBoxComponent>componentRef.instance).top = this.top ? this.top : null;
(<ChildInfoBoxComponent>componentRef.instance).left = this.left ? this.left : null;

return componentRef;
}
}

/**
* This method get position pf emitted element
* @param Element element
*/
getPosition(element: Element): void {
const bodyRect = document.body.getBoundingClientRect();
const elementRect = element.getBoundingClientRect();
const offset = elementRect.top - bodyRect.top + 20;
this.top = offset + 'px';
this.left = elementRect.left + 'px';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ProviderWorkshopsService {
return this.http.get<Workshop[]>('/Workshop/Get')
}

createWorkshop( workshop ): void {
this.http.post('/Workshop/Create', workshop).subscribe(workshop => console.log(workshop));
createWorkshop(workshop): void {
this.http.post('/Workshop/Create', workshop);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ export class ProviderWorkshopsService {
return this.http.get<Workshop[]>('/Workshop/Get')
}

createWorkshop(workshop): any {
createWorkshop(workshop: Workshop): any {
return this.http.post('/Workshop/Create', workshop);
}

deleteWorkshop(workshop: Workshop): any {
const id = workshop.id;
return this.http.delete(`/Workshop/Delete/${id}`);
}
}
Loading

0 comments on commit 879ec3f

Please sign in to comment.