-
-
Save lolmaus/f1c737d3bc106cb9cca071fd01fe334f to your computer and use it in GitHub Desktop.
ember-drag-sort updating attribute on parent, approach 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember' | |
export default Ember.Component.extend({ | |
classNames: ['the-item'], | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember' | |
export default Ember.Controller.extend({ | |
actions : { | |
dragEnd ({sourceList, sourceIndex, targetList, targetIndex}) { | |
if (sourceList === targetList && sourceIndex === targetIndex) return | |
const draggedItem = sourceList.objectAt(sourceIndex) | |
sourceList.removeAt(sourceIndex) | |
targetList.insertAt(targetIndex, draggedItem) | |
}, | |
}, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model" | |
import attr from "ember-data/attr" | |
import { belongsTo, hasMany } from "ember-data/relationships" | |
export default Model.extend({ | |
parent: belongsTo('item', {inverse: 'children', async: false}), | |
children: hasMany('item', {inverse: 'parent', async: false}), | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember' | |
const payload = { | |
data: [ | |
{ | |
type: 'item', | |
id: '0', | |
attributes: { isParent: true }, | |
relationships: { | |
parent: { data: { type: 'item', id: '0' } }, | |
children: { | |
data: [ | |
{type: 'item', id: '1'}, | |
{type: 'item', id: '4'}, | |
] | |
} | |
} | |
}, | |
{ | |
type: 'item', | |
id: '1', | |
attributes: { isParent: true }, | |
relationships: { | |
parent: { data: { type: 'item', id: '0' } }, | |
children: { | |
data: [ | |
{type: 'item', id: '2'}, | |
{type: 'item', id: '3'}, | |
] | |
} | |
} | |
}, | |
{ | |
type: 'item', | |
id: '2', | |
attributes: { isParent: false }, | |
relationships: { | |
parent: { data: { type: 'item', id: '1' } }, | |
children: { | |
data: [] | |
} | |
} | |
}, | |
{ | |
type: 'item', | |
id: '3', | |
attributes: { isParent: false }, | |
relationships: { | |
parent: { data: { type: 'item', id: '1' } }, | |
children: { | |
data: [] | |
} | |
} | |
}, | |
{ | |
type: 'item', | |
id: '4', | |
attributes: { isParent: true }, | |
relationships: { parent: { data: { type: 'item', id: '0' } }, | |
children: { | |
data: [ | |
{type: 'item', id: '5'}, | |
{type: 'item', id: '6'}, | |
] | |
} | |
} | |
}, | |
{ | |
type: 'item', | |
id: '5', | |
attributes: { isParent: false }, | |
relationships: { | |
parent: { data: { type: 'item', id: '4' } }, | |
children: { | |
data: [] | |
} | |
} | |
}, | |
{ | |
type: 'item', | |
id: '6', | |
attributes: { isParent: false }, | |
relationships: { | |
parent: { data: { type: 'item', id: '4' } }, | |
children: { | |
data: [] | |
} | |
} | |
}, | |
], | |
} | |
export default Ember.Route.extend({ | |
model () { | |
const store = this.get('store') | |
store.push(payload) | |
return store.peekRecord('item', '0') | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.the-item { | |
margin: 4px; | |
padding: 1em; | |
border: 1px solid black; | |
display: flex; | |
} | |
.the-item-title { | |
flex-shrink: 0; | |
flex-grow: 0; | |
width: 100px; | |
} | |
.the-item .dragSortList { | |
flex-shrink: 0; | |
flex-grow: 1; | |
} | |
.the-item .dragSortList.-isExpanded { | |
padding-top: 55px; | |
} | |
.the-item .dragSortList.-isDragging { | |
outline: 2px dashed black; | |
background-color: deepskyblue; | |
} | |
.the-item .dragSortList.-isExpanded.-isDraggingOver:before { | |
top: 15px; | |
} | |
.the-item { | |
background-color : #FFD0E9; | |
} | |
.the-item .the-item { | |
background-color: #FFAAD7; | |
} | |
.the-item .the-item .the-item { | |
background-color: #FF8CC9; | |
} | |
.the-item .the-item .the-item .the-item { | |
background-color: #FF74BD; | |
} | |
.the-item .the-item .the-item .the-item .the-item { | |
background-color: #FF60B4; | |
} | |
.the-item .the-item .the-item .the-item .the-item .the-item { | |
background-color: #FF50AD; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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", | |
"ember-drag-sort": "1.0.2", | |
"ember-truth-helpers": "2.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment