Skip to content

Instantly share code, notes, and snippets.

@mupkoo
Last active March 31, 2017 21:35
Show Gist options
  • Save mupkoo/5df4bdb0f652df90c258315c5d06e10e to your computer and use it in GitHub Desktop.
Save mupkoo/5df4bdb0f652df90c258315c5d06e10e to your computer and use it in GitHub Desktop.
Swap nodes
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
filter: 'all',
_parts: [
{ name: "Green", isArchived: false },
{ name: "Blue", isArchived: false },
{ name: "Yellow", isArchived: true }
],
parts: Ember.computed('_parts.@each.isArchived', 'filter', function () {
if (this.get('filter') === 'all') {
return this.get('_parts');
} else {
return this.get('_parts').filter((part) => !part.isArchived);
}
}),
actions: {
swapPlaces() {
let [greenPart, bluePart, archived] = document.querySelectorAll('.part');
archived.parentNode.insertBefore(archived, bluePart);
}
}
});
<p> Here what you need to do:</p>
<ol>
<li>Drag the archived part</li>
<li>Click "Active" button</li>
<li>Click "All" button</li>
</ol>
<br><br>
<ul>
{{#each parts as |part|}}
<li class="part">
{{ part.name }}
{{#if part.isArchived}}
<strong>ARCHIVED</strong>
{{/if}}
</li>
{{/each}}
</ul>
<br><br>
<button type="button" onclick={{ action "swapPlaces" }}>Swap places</button>
<br><br>
<button type="button" onclick={{ action (mut filter) 'all' }}>All</button>
<button type="button" onclick={{ action (mut filter) 'active' }}>Active</button>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment