Skip to content

Commit

Permalink
feat(InlineEditorEvent): Add instance prop when emit to client
Browse files Browse the repository at this point in the history
  • Loading branch information
tonivj5 committed Jun 29, 2017
1 parent 8a6a741 commit f93d368
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

Expand Down
33 changes: 24 additions & 9 deletions src/inline-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ import { InputDatetimeComponent } from "./inputs/input-datetime.component";
import { Subscription } from "rxjs/Subscription";
import { SelectOptions } from "./types/select-options.interface";
import { InlineEditorError } from "./types/inline-editor-error.interface";
import { InlineEditorEvent, InternalEvent, Events, InternalEvents, ExternalEvents } from "./types/inline-editor-events.class";
import {
InlineEditorEvent,
InternalEvent,
Events,
InternalEvents,
ExternalEvents,
ExternalEvent,
} from "./types/inline-editor-events.class";
import { InlineEditorState, InlineEditorStateOptions } from "./types/inline-editor-state.class";
import { EditOptions } from "./types/edit-options.interface";
import { InputType } from "./types/input-type.type";
Expand Down Expand Up @@ -342,7 +349,7 @@ export class InlineEditorComponent implements OnInit, AfterContentInit, OnDestro

this.subscriptions.onChangeSubcription = this.events.internal.onChange.subscribe(
({ event, state }: InternalEvent) => {
if (this.config.saveOnChange) {
if (this.config.saveOnChange) {
this.saveAndClose({
event,
state: state.getState(),
Expand Down Expand Up @@ -444,8 +451,8 @@ export class InlineEditorComponent implements OnInit, AfterContentInit, OnDestro
registerOnChange(refreshNGModel: (_: any) => void) {
this.refreshNGModel = refreshNGModel;
}
registerOnTouched() {
}

registerOnTouched() { }

// Method to display the inline editor form and hide the <a> element
public edit({ editing = true, focus = true, select = false, event }: EditOptions = {}) {
Expand Down Expand Up @@ -473,7 +480,7 @@ export class InlineEditorComponent implements OnInit, AfterContentInit, OnDestro

}

public save({ event, state: hotState }: InlineEditorEvent) {
public save({ event, state: hotState }: ExternalEvent) {
const prevState = this.state.getState();

const state = {
Expand All @@ -496,14 +503,14 @@ export class InlineEditorComponent implements OnInit, AfterContentInit, OnDestro
}
}

public saveAndClose(outsideEvent: InlineEditorEvent) {
public saveAndClose(outsideEvent: ExternalEvent) {
this.save(outsideEvent);

this.edit({ editing: false });
}

// Method to reset the editable value
public cancel(outsideEvent: InlineEditorEvent) {
public cancel(outsideEvent: ExternalEvent) {
this.edit({ editing: false });
this.emit(this.onCancel, outsideEvent);
}
Expand Down Expand Up @@ -607,7 +614,15 @@ export class InlineEditorComponent implements OnInit, AfterContentInit, OnDestro
}


private emit(event: EventEmitter<InlineEditorEvent | any>, data: InlineEditorEvent) {
event.emit(this.config.onlyValue ? data.state.value : data);
private emit(event: EventEmitter<InlineEditorEvent | any>, data: ExternalEvent) {
if (this.config.onlyValue) {
event.emit(data.state.value);
} else {
(event as EventEmitter<InlineEditorEvent>)
.emit({
...data,
instance: this,
});
}
}
}
46 changes: 23 additions & 23 deletions src/inline-editor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { FormsModule } from "@angular/forms";

import { InlineEditorComponent } from "./inline-editor.component";
import {
InputTimeComponent,
InputDateComponent,
InputDatetimeComponent,
InputNumberComponent,
InputRangeComponent,
InputPasswordComponent,
InputSelectComponent,
InputTextareaComponent,
InputTextComponent,
InputTimeComponent,
InputDateComponent,
InputDatetimeComponent,
InputNumberComponent,
InputRangeComponent,
InputPasswordComponent,
InputSelectComponent,
InputTextareaComponent,
InputTextComponent,
} from "./inputs/index";
import { InputBase } from "./inputs/input-base";

Expand All @@ -23,23 +23,23 @@ export { InputBase } from "./inputs/input-base";
export { InlineEditorEvent } from "./types/inline-editor-events.class";

const EXPORTS = [
InputBase,
InputTextComponent,
InputNumberComponent,
InputPasswordComponent,
InputRangeComponent,
InputTextareaComponent,
InputSelectComponent,
InputDateComponent,
InputTimeComponent,
InputDatetimeComponent,
InputBase,
InputTextComponent,
InputNumberComponent,
InputPasswordComponent,
InputRangeComponent,
InputTextareaComponent,
InputSelectComponent,
InputDateComponent,
InputTimeComponent,
InputDatetimeComponent,

InlineEditorComponent,
InlineEditorComponent,
];

@NgModule({
imports: [CommonModule, FormsModule],
declarations: EXPORTS,
exports: [InlineEditorComponent],
imports: [CommonModule, FormsModule],
declarations: EXPORTS,
exports: [InlineEditorComponent],
})
export class InlineEditorModule { }
5 changes: 4 additions & 1 deletion src/types/inline-editor-events.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EventEmitter } from "@angular/core";
import { InlineEditorError } from "./inline-editor-error.interface";
import { InlineConfig } from "../types/inline-configs";
import { InlineEditorState, InlineEditorStateOptions } from "./inline-editor-state.class";
import { InlineEditorComponent } from "../inline-editor.component";

export interface Events {
internal: InternalEvents;
Expand Down Expand Up @@ -48,4 +49,6 @@ export interface ExternalEvent {
state: InlineEditorStateOptions;
}

export type InlineEditorEvent = ExternalEvent;
export interface InlineEditorEvent extends ExternalEvent {
instance: InlineEditorComponent;
}

0 comments on commit f93d368

Please sign in to comment.