Skip to content

Commit

Permalink
refactor/feat(codebase): Refactor API-compatible. Added many features. (
Browse files Browse the repository at this point in the history
#57)

* refactor/feat(codebase): Total refactor and API-compatible. Added many features.

In this refactor we have added new features too:
[x] Created a better organization of files and types.
[x] Created a way of communicate with our children components
[x] An API more robust and open
[x] Created external events to get changes from inputs (onChange, onBlur, onChange, onEnter, onEscape, onFocus, etc.).
    These events are shotcuts to angular-native events (ex. keypress.enter/keypress.escape), so you can bind those. However, this
    shorcuts provide you of state of input when this one changed.
[x] New options to configure when an event is triggered (ex. hidebuttons, cancelOnEscape, saveOnEnter, saveOnBlur, etc.)
[x] An internal service shared between root and child component. (this feature will be more use in the future, so it is WIP)
[x] Interfaces to provide a specifig config to inputs (specific intellisense to input text, input select, etc.)

How works The new API to communicate the root component with their children?
When a child component change its state, this one triggers an event and the root component get it.
Using this system of internal events we can provide external events (to the client) and trigger events such as onChange, onFocus, on Blur, etc.
A change of state can be: change of value, edit mode or disabled mode.

Closes #38 #47 #30 #21

* fix(InlineEditorComponent): When onSave emits the ngModel isn't refreshed yet. This fixs that, first is setted and then is emited

* refactor(InlineEditor): Use a subscriptions dictionary instead of property per subscription. Add destroy() in InlineService

* fix(InlineEditorComponent): Fix config overwritten order.

By order of preference
1. Config from attributes ([type], [pattern], etc.)
2. Config from [config] property
3. Default config (`defaultConfig`)

* feature(InlineEditorComponent): Add onlyValue option

This option is useful when you only want/need the value of input and not the complete event ( { event: Event, state: InlineState} ). It's `true` by default

Then, when onlyValue is enabled the external events emit an any value (it can be string, boolean, number, object, etc.)

* feature(InlineEditor): If an input is empty or not is handler by itself

This fix a problem with `InputSelectComponent`, it showed `empty` when the option was not found, but `empty` property of its state was `false`. It happened because the value was not empty (`"test"`, `1`), but there was not any option with that value.

Now the inputs handle when they are or are not empty implementing the `isEmpty` method of `InputBase`, by default an input is empty if its value is an empty string (`""`) , `undefined`  or `null`.

And I have simplified the way how the `InputSelectComponent` searched the option selected.

* fix(paths/names): Fixed paths and names. Better imports paths.

We have "normalized" some names like InlineError -> InlineError, InlineEvent -> InlineEditorEvent, etc.

Added `config.ts` that exports the input's config interfaces. Then, you can import them from 'ng2-inline-editor' or 'ng2-inline-editor/configs', interfaces like InputTextConfig, InputNumberConfig, etc.

* chore(yarn): Add yarn.lock to VCS and dependencies updated
  • Loading branch information
tonivj5 authored and Caballerog committed Jun 1, 2017
1 parent 8fbdc8e commit 71ff7cc
Show file tree
Hide file tree
Showing 33 changed files with 5,936 additions and 388 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ src/*.d.ts
typings
typings.json

# yarn
yarn.lock

# VS Code
.vscode/*

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@
},
"dependencies": {},
"peerDependencies": {
"@angular/common": "^4.0.2",
"@angular/core": "^4.0.2",
"@angular/forms": "^4.0.2"
"@angular/common": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0"
},
"devDependencies": {
"@angular/common": "^4.0.2",
"@angular/compiler": "^4.0.2",
"@angular/core": "^4.0.2",
"@angular/forms": "^4.0.2",
"@angular/common": "^4.1.3",
"@angular/compiler": "^4.1.3",
"@angular/core": "^4.1.3",
"@angular/forms": "^4.1.3",
"@types/del": "^2.2.32",
"@types/gulp": "^3.8.32",
"@types/gulp": "^4.0.3",
"@types/gulp-changed": "^0.0.31",
"@types/gulp-rename": "^0.0.32",
"@types/jasmine": "^2.5.47",
Expand Down Expand Up @@ -98,7 +98,7 @@
"ts-loader": "^2.0.3",
"ts-node": "~2.0.0",
"tslint": "^5.1.0",
"typescript": "~2.2.2",
"typescript": "~2.3.3",
"zone.js": "^0.8.5"
},
"engines": {
Expand Down
8 changes: 8 additions & 0 deletions src/configs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export {
InputConfig,
InputBaseConfig,
InputTextConfig,
InputNumberConfig,
InputSelectConfig,
InputTextareaConfig,
} from "./types/input-configs";
12 changes: 7 additions & 5 deletions src/inline-editor.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<div>
<div id="inlineEditWrapper">
<a [ngClass]="{'editable-empty': isEmpty, 'c-inline-editor' :true }" (click)="edit(value)" [hidden]="editing && !disabled">{{ showText() }}</a>
<div class="c-inline-editor inlineEditForm form-inline" [hidden]="!editing || disabled">
<a [ngClass]="{'editable-empty': state.isEmpty(), 'c-inline-editor': true }" (click)="!config.editOnClick || edit()" [hidden]="state.isEditing() && !disabled">{{ showText() }}</a>
<div class="c-inline-editor inlineEditForm form-inline" [hidden]="!state.isEditing() || disabled">
<div class="form-group">
<div #container></div>
<span class="c-inline-editor inline-editor-button-group">
<span *ngIf="!config.hideButtons" class="c-inline-editor inline-editor-button-group">
<button id="inline-editor-button-save" class="btn btn-xs btn-primary c-inline-editor"
(click)="onSubmit(value)"><span class="fa fa-check"></span></button>
<button class="btn btn-xs btn-danger c-inline-editor" (click)="cancel()"><span class="fa fa-remove"></span> </button>
(click)="saveAndClose({ event: $event, state: service.getState() })">
<span class="fa fa-check"></span>
</button>
<button class="btn btn-xs btn-danger c-inline-editor" (click)="cancel({ event: $event, state: service.getState() })"><span class="fa fa-remove"></span> </button>
</span>

</div>
Expand Down
Loading

0 comments on commit 71ff7cc

Please sign in to comment.