Skip to content

Commit

Permalink
fix code duplication by moving stuff into base class
Browse files Browse the repository at this point in the history
  • Loading branch information
dickschoeller committed May 28, 2018
1 parent 5b5c6d7 commit fc86254
Show file tree
Hide file tree
Showing 10 changed files with 1,191 additions and 1,265 deletions.
613 changes: 216 additions & 397 deletions gedbrowserng-frontend/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion gedbrowserng-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"private": true,
"dependencies": {
"@angular-devkit/core": "^0.6.5",
"@angular/animations": "^5.2.11",
"@angular/cdk": "^5.2.5",
"@angular/common": "^5.2.11",
Expand All @@ -35,7 +36,7 @@
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/cli": "1.5.5",
"@angular/cli": "^1.5.5",
"@angular/compiler-cli": "^5.2.11",
"@angular/language-service": "^5.2.11",
"@types/jasmine": "~2.5.53",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ export class NewAttributeDialogComponent
}

open() {
this._data = this.p.defaultData();
this.emitOpen.emit(this);
}

close() {
this.emitClose.emit();
this._data = this.p.defaultData();
}

ok() {
this.emitOK.emit(this._data);
this.emitClose.emit();
this._data = this.p.defaultData();
}

cancel() {
this.emitClose.emit();
this._data = this.p.defaultData();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {Component, OnInit, Input, EventEmitter, Output, OnDestroy} from '@angular/core';

@Component({
selector: 'app-base-dialog',
templateUrl: './base-dialog.component.html',
styleUrls: ['./base-dialog.component.css']
})
export class BaseDialogComponent<D, C> implements OnInit, OnDestroy {
export abstract class BaseDialogComponent<D, C> implements OnInit, OnDestroy {
@Input() p: any;
@Input() set display(value: boolean) {
this._display = value;
Expand All @@ -32,4 +27,18 @@ export class BaseDialogComponent<D, C> implements OnInit, OnDestroy {
this.emitOpen.unsubscribe();
}

abstract open(): void;

close() {
this.emitClose.emit();
}

ok() {
this.emitOK.emit(this._data);
this.emitClose.emit();
}

cancel() {
this.emitClose.emit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './base-dialog.component';
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import {
AttributeListItemDetailListComponent,
AttributeListItemDetailListItemComponent,
} from './attribute-list';
import {BaseDialogComponent} from './base-dialog/base-dialog.component';
import {NewPersonDialogComponent} from './new-person-dialog';
import {NewAttributeDialogComponent} from './attribute-dialog';
import {NewSourceDialogComponent} from './new-source-dialog/new-source-dialog.component';
import {NewSourceDialogComponent} from './new-source-dialog';

@NgModule({
imports: [
Expand Down Expand Up @@ -51,7 +50,6 @@ import {NewSourceDialogComponent} from './new-source-dialog/new-source-dialog.co
NewAttributeDialogComponent,
NewPersonDialogComponent,
NewSourceDialogComponent,
BaseDialogComponent,
],
exports: [
AttributeListComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,4 @@ export class NewPersonDialogComponent
open() {
this.emitOpen.emit(this);
}

close() {
this.emitClose.emit();
this.emitOpen.emit(this);
}

ok() {
this.emitOK.emit(this._data);
this.emitClose.emit();
this.emitOpen.emit(this);
}

cancel() {
this.emitClose.emit();
this.emitOpen.emit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class NewSourceDialogComponent
extends BaseDialogComponent<NewSourceDialogData, NewSourceDialogComponent>
implements OnInit, OnChanges {

_data: NewSourceDialogData = {title: '', abbreviation: '', text: ''};
_data: NewSourceDialogData;

constructor() {
super();
Expand All @@ -30,20 +30,4 @@ export class NewSourceDialogComponent
open() {
this.emitOpen.emit(this);
}

close() {
this.emitClose.emit();
this.emitOpen.emit(this);
}

ok() {
this.emitOK.emit(this._data);
this.emitClose.emit();
this.emitOpen.emit(this);
}

cancel() {
this.emitClose.emit();
this.emitOpen.emit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
<p-header>{{ source?.string }}: {{ source?.title }}</p-header>
</p-panel>

<p-panel header="Attributes" [toggleable]="true">
<app-attribute-list [dataset]="dataset" [attributes]="source?.attributes" [parent]="this"></app-attribute-list>
</p-panel>
<app-attribute-list [dataset]="dataset" [attributes]="source?.attributes" [parent]="this"></app-attribute-list>

<p-panel header="Images" [toggleable]="true">
<ngx-gallery [options]="galleryOptions" [images]="galleryImages()"></ngx-gallery>
Expand Down
Loading

0 comments on commit fc86254

Please sign in to comment.