Skip to content

Commit

Permalink
Merged devlop back into master for release of 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dgavey committed Jan 10, 2016
2 parents 5fb1a4f + 49081e4 commit 827bb32
Show file tree
Hide file tree
Showing 31 changed files with 364 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .watchmanconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ignore_dirs": ["tmp"]
"ignore_dirs": ["tmp", "dist"]
}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ When using this addon, you get to work with objects in your domain layer, just l
## Requirements

- ember-cli 0.2.7 or higher (may work with lower version, but this is what is tested)
- ember-drag-drop 0.1.0 or higher (to match current docs)
- If you use the sorting object, you will need Ember 1.13.2 or higher.

## Installation

Expand Down Expand Up @@ -162,6 +162,11 @@ You can check out an example of this is action [here](http://mharris717.github.i

We now have a basic sorting capabilities in this library. If you wrap the `{{#sortable-objects}}` component around your `{{#draggable-object}}` components you can get an array of sorted elements returned.

**Important Note on Ember Versions:
If you use Ember version 1.13.2 and above you must user at least addon version 0.3 if you use sorting
If you use Ember version 1.12.1 and below you must use 0.2.3 is you use sorting
This only applies if you use the sort capabilities, regular dragging is not version specific.

An Example:

```handlebars
Expand Down
15 changes: 12 additions & 3 deletions addon/components/sortable-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ export default Ember.Component.extend( {
classNameBindings: ['overrideClass'],
enableSort: true,
sortableObjectList: Ember.A(),
dragStart: function() {
this.set('dragCoordinator.arrayList', this.get('sortableObjectList'));

didInsertElement() {
this.set('dragCoordinator.sortComponentController', this);
},
willDestroyElement() {
this.set('dragCoordinator.sortComponentController', null);
},
dragStart: function(event) {
if (!this.get('enableSort')) {
event.preventDefault();
return;
}
},
dragOver: function() {
//needed so drop event will fire
return false;
},
drop: function() {
if (this.get('enableSort')) {
this.set('sortableObjectList', this.get('dragCoordinator').getChangedArray());
this.sendAction('sortEndAction');
}
}
Expand Down
44 changes: 17 additions & 27 deletions addon/services/drag-coordinator.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import Ember from 'ember';

export default Ember.Service.extend({
arrayList: null,
newSortedList: Ember.computed('arrayList', function(){
//copy the passed in array so things aren't triggered while swapping items
var simpleArray = [];
this.get('arrayList').forEach(function(item){
simpleArray.push(item);
});
return simpleArray;
}),
sortComponentController: null,
currentDragObject: null,
currentDragEvent: null,
currentDragItem: null,
currentOffsetItem: null,
isMoving: false,
lastEvent: null,

arrayList: Ember.computed.alias('sortComponentController.sortableObjectList'),
enableSort: Ember.computed.alias('sortComponentController.enableSort'),

dragStarted: function(object, event, emberObject) {
if (!this.get('enableSort') && this.get('sortComponentController')) {
//disable drag if sorting is disabled this is not used for regular
event.preventDefault();
return;
}
Ember.run.later(function(){
Ember.$(event.target).css('opacity', '0.5');
});
Expand Down Expand Up @@ -61,24 +62,22 @@ export default Ember.Service.extend({
}
}
},
swapNodes: function(a, b) {
var aparent = a.parentNode;
var asibling = a.nextSibling === b ? a : a.nextSibling;
b.parentNode.insertBefore(a, b);
aparent.insertBefore(b, asibling);
},
swapObjectPositions: function(a, b) {
var newList = this.get('newSortedList');
var newList = this.get('arrayList').toArray();
var newArray = Ember.A();
var aPos = newList.indexOf(a);
var bPos = newList.indexOf(b);
newList[aPos] = b;
newList[bPos] = a;
this.set('newSortedList', newList);
newList.forEach(function(item){
newArray.push(item);
});
this.set('sortComponentController.sortableObjectList', newArray);
},
swapElements: function(overElement) {
var draggingItem = this.get('currentDragItem');
this.swapNodes(draggingItem.$()[0], overElement.$()[0]);
this.swapObjectPositions(draggingItem.get('content'), overElement.get('content'));
this.get('sortComponentController').rerender();
},
relativeClientPosition: function (el, event) {
var rect = el.getBoundingClientRect();
Expand All @@ -90,14 +89,5 @@ export default Ember.Service.extend({
px: x / rect.width,
py: y / rect.height
};
},
getChangedArray: function() {
//rebuild the passed in array
var arrayList = this.get('arrayList');
arrayList.clear();
this.get('newSortedList').forEach(function(item){
arrayList.addObject(item);
});
return arrayList;
}
});
23 changes: 11 additions & 12 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{
"name": "ember-drag-drop",
"dependencies": {
"ember": "1.12.0",

"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-data": "1.0.0-beta.18",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.4",
"ember-qunit": "0.3.3",
"ember-qunit-notifications": "0.0.7",
"ember-resolver": "~0.1.15",
"jquery": "^1.11.1",
"loader.js": "ember-cli/loader.js#3.2.0",
"qunit": "~1.17.1"
"ember": "1.13.11",
"ember-cli-shims": "0.0.6",
"ember-cli-test-loader": "0.2.1",
"ember-data": "1.13.15",
"ember-load-initializers": "0.1.7",
"ember-qunit": "0.4.16",
"ember-qunit-notifications": "0.1.0",
"ember-resolver": "~0.1.20",
"jquery": "^1.11.3",
"loader.js": "ember-cli/loader.js#3.4.0",
"qunit": "~1.20.0"
}
}
7 changes: 4 additions & 3 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*jshint node:true*/
module.exports = {
scenarios: [
{
Expand All @@ -12,8 +13,8 @@ module.exports = {
resolutions: {
'ember': 'release'
}
},
{
}
/*{
name: 'ember-beta',
dependencies: {
'ember': 'components/ember#beta'
Expand All @@ -30,6 +31,6 @@ module.exports = {
resolutions: {
'ember': 'canary'
}
}
}*/
]
};
1 change: 1 addition & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*jshint node:true*/
'use strict';

module.exports = function(/* environment, appConfig */) {
Expand Down
18 changes: 18 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*jshint node:true*/
/* global require, module */
var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
var app = new EmberAddon(defaults, {
// Add options here
});

/*
This build file specifes the options for the dummy test app of this
addon, located in `/tests/dummy`
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
};
46 changes: 24 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
{
"name": "ember-drag-drop",
"version": "0.2.3",
"version": "0.3.0",
"description": "Addon for Ember CLI to do drag and drop",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"start": "ember server",
"build": "ember build",
"test": "ember test"
"start": "ember server",
"test": "ember try:testall"
},
"repository": "https://github.com/mharris717/ember-drag-drop",
"repository": "",
"engines": {
"node": ">= 0.10.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.2",
"ember-cli": "1.13.8",
"ember-cli-app-version": "0.3.3",
"broccoli-asset-rev": "^2.2.0",
"ember-cli": "1.13.13",
"ember-cli-app-version": "^1.0.0",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "^1.0.0",
"ember-cli-github-pages": "0.0.6",
"ember-cli-htmlbars": "0.7.6",
"ember-cli-htmlbars-inline-precompile": "0.3.1",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.13",
"ember-cli-uglify": "^1.0.1",
"ember-data": "1.0.0-beta.18",
"ember-cli-dependency-checker": "^1.1.0",
"ember-cli-htmlbars": "^1.0.1",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-ic-ajax": "0.2.4",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-qunit": "^1.0.4",
"ember-cli-release": "0.2.8",
"ember-cli-sri": "^1.2.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "2.2",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.4",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-disable-proxy-controllers": "^1.0.0",
"ember-export-application-global": "^1.0.2",
"ember-try": "0.0.6"
"ember-try": "~0.0.8"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.0.0"
"ember-cli-babel": "^5.1.5"
},
"ember-addon": {
"configPath": "tests/dummy/config"
"configPath": "tests/dummy/config",
"demoURL": "http://mharris717.github.io/ember-drag-drop/"
}
}
}
5 changes: 3 additions & 2 deletions tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"node": false,
"browser": false,
"boss": true,
"curly": false,
"curly": true,
"debug": false,
"devel": false,
"eqeqeq": true,
Expand All @@ -47,5 +47,6 @@
"strict": false,
"white": false,
"eqnull": true,
"esnext": true
"esnext": true,
"unused": true
}
15 changes: 15 additions & 0 deletions tests/dummy/app/controllers/sortdata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Ember from 'ember';

export default Ember.Controller.extend({

sortFinishText: null,

actions: {
dragStart: function(object) {
console.log('Drag Start', object);
},
sortEndAction: function() {
console.log('Sort Ended', this.get('model.pages'));
}
}
});
8 changes: 8 additions & 0 deletions tests/dummy/app/models/book.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import DS from 'ember-data';

var Book = DS.Model.extend({
title: DS.attr('string'),
pages: DS.hasMany('page', {async: true})
});

export default Book;
7 changes: 7 additions & 0 deletions tests/dummy/app/models/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import DS from 'ember-data';

var Page = DS.Model.extend({
title: DS.attr('string')
});

export default Page;
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Router.map(function() {
this.resource("posts");
this.resource("simple");
this.resource("sort");
this.resource("sortdata");
this.resource("handle");
});

Expand Down
15 changes: 15 additions & 0 deletions tests/dummy/app/routes/sortdata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Ember from 'ember';

export default Ember.Route.extend({
createdStore: false,
model: function() {
if (!this.get('createdStore')) {
let page1 = this.store.createRecord('page',{id:1, title:'Page Title 1'});
let page2 = this.store.createRecord('page',{id:2, title:'Page Title 2'});
let page3 = this.store.createRecord('page',{id:3, title:'Page Title 3'});
let page4 = this.store.createRecord('page',{id:4, title:'Page Title 4'});
this.set('createdStore', true);
return this.store.createRecord('book',{id:1, title:'Book Title',pages: [page1, page2, page3, page4]});
}
}
});
4 changes: 3 additions & 1 deletion tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<h2 id="title">Ember-Drag-Drop Add-on Examples</h2>
<h4> for the Ember addon <a href="https://github.com/mharris717/ember-drag-drop">https://github.com/mharris717/ember-drag-drop</a></h4>

<h3>Example Links</h3>
<ul>
<li>{{#link-to 'simple'}}A simple Drag and Drop Example{{/link-to}}</li>
<li>{{#link-to 'sort'}}A Simple Sorting Example{{/link-to}}</li>
<li>{{#link-to 'sort'}}A Simple Sorting Example with POJO{{/link-to}}</li>
<li>{{#link-to 'sortdata'}}A Simple Sorting with Ember Data{{/link-to}}</li>
<li>{{#link-to 'handle'}}Drag with a handle{{/link-to}}</li>
</ul>
<br><br>
Expand Down
Loading

0 comments on commit 827bb32

Please sign in to comment.