Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*

# ember-try
/.node_modules.ember-try/
Expand Down
35 changes: 34 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,38 @@ module.exports = {
browser: true
},
rules: {
}
},
overrides: [
// node files
{
files: [
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'index.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
},
env: {
browser: false,
node: true
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}
]
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/node_modules/

# misc
/.env*
/.sass-cache
/connect.lock
/coverage/
Expand Down
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
/.bowerrc
/.editorconfig
/.ember-cli
/.env*
/.eslintignore
/.eslintrc.js
/.gitignore
/.watchmanconfig
/.template-lintrc.js
/.travis.yml
/.watchmanconfig
/bower.json
/config/ember-try.js
/CONTRIBUTING.md
/ember-cli-build.js
/testem.js
/tests/
Expand Down
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ env:
# See https://git.io/vdao3 for details.
- JOBS=1

branches:
only:
- master
# npm version tags
- /^v\d+\.\d+\.\d+/

jobs:
fail_fast: true
allow_failures:
Expand All @@ -44,7 +50,8 @@ jobs:
# as well as latest stable release (bonus points to beta/canary)
- stage: "Additional Tests"
env: EMBER_TRY_SCENARIO=ember-lts-2.16
- env: EMBER_TRY_SCENARIO=ember-lts-2.18
env: EMBER_TRY_SCENARIO=ember-lts-2.18
- env: EMBER_TRY_SCENARIO=ember-lts-3.4
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
Expand Down
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# How To Contribute

## Installation

* `git clone https://github.com/btecu/ember-simple-tree`
* `cd my-addon`
* `npm install`

## Linting

* `npm run lint:hbs`
* `npm run lint:js`
* `npm run lint:js -- --fix`

## Running tests

* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions

## Running the dummy application

* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018
Copyright (c) 2019

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
66 changes: 60 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# ember-simple-tree

Simple tree component for Ember without any dependency.
Lightweight, composable tree component for Ember without any dependency.

## Compatibility

* Ember.js v2.16 or above
* Ember CLI v2.13 or above

If you are using 0.5.x and would like to upgrade to 0.6.0, please note there
are BREAKING CHANGES. For details, see (Upgrading)[UPGRADING.md].


## Installation

Expand All @@ -17,6 +26,19 @@ Basic example:
{{x-tree model=tree}}
```

Standard example:

```handlebars
{{#x-tree
model=tree
checkable=true
as |node|
}}
{{node.toggle}}
{{node.checkbox}}
{{node.model.name}}
{{/x-tree}}
```

### Available actions

Expand Down Expand Up @@ -115,21 +137,53 @@ Accepts: `boolean`
When enabled, checking a box will also check children's boxes as well. Also enables indeterminate state for checkboxes.
Has no effect if `checkable` is not enabled.

#### expandedIcon

Default: `x-tree-expanded-icon`,

Accepts: `string` or `Component`

```handlebars
{{x-tree model=tree expandedIcon=(component "my-expanded-icon-component")}}
```
or
```handlebars
{{x-tree model=tree expandedIcon="my-expanded-icon-component"}}
```

Component to use for expanded icon

#### collapsedIcon

Default: `x-tree-collapsed-icon`,

Accepts: `string`

```handlebars
{{x-tree model=tree collapsedIcon=(component "my-collapsed-icon-component")}}
```
or
```handlebars
{{x-tree model=tree collapsedIcon="my-collapsed-icon-component"}}
```

Component to use for collapsed icon

### Blocks

You may optionally pass a block to the `x-tree` component to render each node area with custom HTML.
The node area is the area directly to the right of each arrow (and possibly checkbox) in the tree.
The Node yields back the model for each area so that you can use attributes dynamically.

```handlebars
{{#x-tree
chosenId=selectedNode
checkable=isCheckable
expandDepth=2
onSelect=(action 'selectNode')
model=model as |node|}}
<i class="fa text-muted {{if node.isExpanded 'fa-folder-open' 'fa-folder'}}">&zwnj;</i>
{{node.name}}
model=model
as |node|
}}
<i class="fa text-muted {{if node.isExpanded 'fa-folder-open' 'fa-folder'}}">&zwnj;</i>
{{node.model.name}}
{{/x-tree}}
```

Expand Down
35 changes: 35 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Upgrading

## from 0.5.x to 0.6.0

If you are using the block form of the {{x-tree}} component,
the expand/collapse toggle and the checkbox are no longer
included in the custom HTML. Furthermore, the value yielded
is no longer the model for the node, but an object containing
the model and the components that are included.

To upgrade, convert:

```
{{#x-tree
model=tree
checkable=true
as |node|
}}
{{node.name}}
{{/x-tree}}
```

to

```
{{#x-tree
model=tree
checkable=true
as |node|
}}
{{node.toggle}}
{{node.checkbox}}
{{node.model.name}}
{{/x-tree}}
```
8 changes: 8 additions & 0 deletions addon/components/x-tree-checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Component from '@ember/component';
import layout from '../templates/components/x-tree-checkbox';

export default Component.extend({
layout,
tagName: 'span',
classNames: ['tree-checkbox']
});
5 changes: 3 additions & 2 deletions addon/components/x-tree-children.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Component from '@ember/component';
import layout from '../templates/components/x-tree-children';
import { get, setProperties } from '@ember/object';

export default Component.extend({
layout,
Expand All @@ -10,7 +11,7 @@ export default Component.extend({
updateCheckbox() {
if (this.get('recursiveCheck')) {
let model = this.get('model');
let children = model.get('children');
let children = get(model, 'children');

if (children.length) {
let isChecked = false;
Expand All @@ -22,7 +23,7 @@ export default Component.extend({
isIndeterminate = true;
}

model.setProperties({ isChecked, isIndeterminate });
setProperties(model, { isChecked, isIndeterminate });
}

if (this.updateCheckbox) {
Expand Down
6 changes: 6 additions & 0 deletions addon/components/x-tree-collapsed-icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Component from '@ember/component';
import layout from '../templates/components/x-tree-collapsed-icon';

export default Component.extend({
layout
});
6 changes: 6 additions & 0 deletions addon/components/x-tree-expanded-icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Component from '@ember/component';
import layout from '../templates/components/x-tree-expanded-icon';

export default Component.extend({
layout
});
12 changes: 8 additions & 4 deletions addon/components/x-tree-node.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import { computed, get, setProperties } from '@ember/object';
import layout from '../templates/components/x-tree-node';

export default Component.extend({
layout,
classNameBindings: ['model.isSelected:tree-highlight', 'isChosen:tree-chosen'],
classNameBindings: [
'model.isSelected:x-tree-highlight',
'isChosen:x-tree-chosen',
'model.children.length:tree-children'
],

recursiveCheck: false,

Expand Down Expand Up @@ -47,10 +51,10 @@ export default Component.extend({
},

setChildCheckboxesRecursively(node, isChecked) {
let children = node.get('children');
let children = get(node, 'children');
if (children.length) {
children.forEach(child => {
child.setProperties({
setProperties(child, {
isChecked,
isIndeterminate: false
});
Expand Down
8 changes: 8 additions & 0 deletions addon/components/x-tree-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Component from '@ember/component';
import layout from '../templates/components/x-tree-toggle';

export default Component.extend({
layout,
tagName: 'span',
classNames: ['tree-toggle']
});
4 changes: 4 additions & 0 deletions addon/components/x-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export default Component.extend({
layout,
expandDepth: 0,
recursiveCheck: false,
classNames: ['tree'],

expandedIcon: 'x-tree-expanded-icon',
collapsedIcon: 'x-tree-collapsed-icon',

init() {
this._super(...arguments);
Expand Down
Loading