Skip to content

Commit

Permalink
fix broken child-unlink and further reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
dickschoeller committed Jun 11, 2018
1 parent 4da7567 commit d6c38a3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
</span>
<span class="example-fill-remaining-space"></span>
<span class="hidden">
<p-button icon="fa fa-fw fa-unlink" (onClick)="delete()" pTooltip="Unlink child" [styleClass]="'ui-button-danger'"></p-button>
<p-button icon="fa fa-fw fa-unlink" (onClick)="unlink()" pTooltip="Unlink child" [styleClass]="'ui-button-danger'"></p-button>
</span>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Component, OnInit, Input, OnChanges} from '@angular/core';

import {ApiAttribute, ApiPerson} from '../../models';
import {PersonService, NewPersonLinkService} from '../../services';
import {LifespanUtil, UrlBuilder} from '../../utils';
import {PersonFamilyComponent} from './person-family.component';
import {PersonGetter} from './person-getter';

Expand All @@ -27,9 +26,10 @@ export class PersonFamilyChildComponent extends PersonGetter implements OnInit,
@Input() index: number;
person: ApiPerson;

constructor(public newPersonLinkService: NewPersonLinkService,
constructor(newPersonLinkService: NewPersonLinkService,
personService: PersonService) {
super(personService);
super(newPersonLinkService, personService);
this.famMemberType = 'children';
}

ngOnInit() {
Expand All @@ -40,10 +40,6 @@ export class PersonFamilyChildComponent extends PersonGetter implements OnInit,
this.init(this.dataset, this.child.string);
}

lifespanYearString(): string {
return new LifespanUtil(this.person.lifespan).lifespanYearString();
}

first(): boolean {
return this.index === 0;
}
Expand All @@ -52,9 +48,11 @@ export class PersonFamilyChildComponent extends PersonGetter implements OnInit,
return this.index + 1 >= this.parent.family.children.length;
}

delete(): void {
const ub: UrlBuilder = new UrlBuilder(this.dataset, 'families', 'children');
this.newPersonLinkService.delete(ub, this.parent.familyString(), this.person)
.subscribe((data: ApiPerson) => { this.parent.refreshPerson(); });
familyString(): string {
return this.parent.familyString();
}

refreshPerson(): void {
this.parent.refreshPerson();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<span *ngIf="person"><a
<span *ngIf="person" class="parent"><a
[routerLink]="['/' + dataset + '/persons', person.string]"
class="name parent">{{ person.indexName }} {{ lifespanYearString() }} [{{ person.string }}]</a>
<span class="example-fill-remaining-space"></span>
<span class="hidden">
<p-button icon="fa fa-fw fa-unlink" (onClick)="unlink()"
pTooltip="Unlink spouse" [styleClass]="'ui-button-danger'"></p-button>
</span>
</span>
</span>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Component, OnInit, Input, OnChanges} from '@angular/core';

import {ApiAttribute, ApiPerson} from '../../models';
import {PersonService, NewPersonLinkService} from '../../services';
import {LifespanUtil, StringUtil, UrlBuilder} from '../../utils';
import {PersonFamilyComponent} from './person-family.component';
import {PersonGetter} from './person-getter';

Expand All @@ -25,9 +24,10 @@ export class PersonFamilySpouseComponent extends PersonGetter implements OnInit,
@Input() parent: PersonFamilyComponent;
@Input() attribute: ApiAttribute;

constructor(public newPersonLinkService: NewPersonLinkService,
constructor(newPersonLinkService: NewPersonLinkService,
personService: PersonService) {
super(personService);
super(newPersonLinkService, personService);
this.famMemberType = 'spouses';
}

ngOnInit() {
Expand All @@ -38,17 +38,11 @@ export class PersonFamilySpouseComponent extends PersonGetter implements OnInit,
this.init(this.dataset, this.attribute.string);
}

lifespanYearString(): string {
return new LifespanUtil(this.person.lifespan).lifespanYearString();
familyString(): string {
return this.parent.familyString();
}

unlink(): void {
const ub: UrlBuilder = new UrlBuilder(this.dataset, 'families', 'spouses');
this.newPersonLinkService.delete(ub, this.parent.familyString(), this.person)
.subscribe((data: ApiPerson) => { this.refreshPerson(); });
}

refreshPerson() {
refreshPerson(): void {
this.parent.refreshPerson();
}
}
26 changes: 22 additions & 4 deletions gedbrowserng-frontend/src/app/modules/person/person-getter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { ApiPerson } from '../../models';
import {PersonService} from '../../services';
import {ApiPerson} from '../../models';
import {PersonService, NewPersonLinkService} from '../../services';
import {UrlBuilder, LifespanUtil} from '../../utils';

export class PersonGetter {
export abstract class PersonGetter {
dataset: string;
person: ApiPerson;
famMemberType: string;

constructor(private personService: PersonService) {}
constructor(public newPersonLinkService: NewPersonLinkService,
private personService: PersonService) {}

abstract refreshPerson(): void;
abstract familyString(): string;

init(dataset: string, attrString: string): void {
this.dataset = dataset;
this.get(dataset, attrString, (person: ApiPerson) => {
this.person = person;
});
Expand All @@ -16,4 +24,14 @@ export class PersonGetter {
this.personService.getOne(dataset, id)
.subscribe(callback);
}

unlink(): void {
const ub: UrlBuilder = new UrlBuilder(this.dataset, 'families', this.famMemberType);
this.newPersonLinkService.delete(ub, this.familyString(), this.person)
.subscribe((data: ApiPerson) => { this.refreshPerson(); });
}

lifespanYearString(): string {
return new LifespanUtil(this.person.lifespan).lifespanYearString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Component, OnInit, Input, OnChanges} from '@angular/core';

import {ApiAttribute, ApiPerson} from '../../models';
import {PersonService, NewPersonLinkService} from '../../services';
import {LifespanUtil, UrlBuilder} from '../../utils';
import {PersonParentFamilyComponent} from './person-parent-family.component';
import {PersonGetter} from './person-getter';

Expand All @@ -16,9 +15,10 @@ export class PersonParentComponent extends PersonGetter implements OnInit, OnCha
@Input() parent: PersonParentFamilyComponent;
@Input() attribute: ApiAttribute;

constructor(public newPersonLinkService: NewPersonLinkService,
constructor(newPersonLinkService: NewPersonLinkService,
personService: PersonService) {
super(personService);
super(newPersonLinkService, personService);
this.famMemberType = 'spouses';
}

ngOnInit() {
Expand All @@ -39,14 +39,8 @@ export class PersonParentComponent extends PersonGetter implements OnInit, OnCha
return 'Parent';
}

lifespanYearString(): string {
return new LifespanUtil(this.person.lifespan).lifespanYearString();
}

unlink(): void {
const ub: UrlBuilder = new UrlBuilder(this.dataset, 'families', 'spouses');
this.newPersonLinkService.delete(ub, this.parent.familyString(), this.person)
.subscribe((data: ApiPerson) => { this.refreshPerson(); });
familyString(): string {
return this.parent.familyString();
}

refreshPerson() {
Expand Down

0 comments on commit d6c38a3

Please sign in to comment.