Browse Source

Merge branch 'master' of github.com:RubaXa/Sortable

pull/404/merge
RubaXa 9 years ago
parent
commit
851129a45f
  1. 2
      CONTRIBUTING.md
  2. 2
      README.md
  3. 2
      index.html
  4. 12
      meteor/README.md
  5. 8
      meteor/example/.meteor/.finished-upgraders
  6. 7
      meteor/example/.meteor/.id
  7. 2
      meteor/example/.meteor/platforms
  8. 2
      meteor/example/.meteor/release
  9. 109
      meteor/example/.meteor/versions
  10. 2
      meteor/example/README.md
  11. 1
      meteor/example/package.json
  12. 1
      meteor/example/packages/Sortable
  13. 3
      meteor/example/server/sortable-collections.js
  14. 10
      meteor/methods-client.js
  15. 31
      meteor/methods-server.js
  16. 9
      meteor/package.js
  17. 2
      meteor/reactivize.js

2
CONTRIBUTING.md

@ -5,7 +5,7 @@
1. Try [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch, perhaps the problem has been solved; 1. Try [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch, perhaps the problem has been solved;
2. [Use the search](https://github.com/RubaXa/Sortable/search?q=problem), maybe already have an answer; 2. [Use the search](https://github.com/RubaXa/Sortable/search?q=problem), maybe already have an answer;
3. If not found, create example on [jsbin.com](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem. 3. If not found, create example on [jsbin.com (draft)](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem.
--- ---

2
README.md

@ -215,7 +215,7 @@ Sortable.create(el, {
Sortable.create(list, { Sortable.create(list, {
filter: ".js-remove, .js-edit", filter: ".js-remove, .js-edit",
onFilter: function (evt) { onFilter: function (evt) {
var item = el.item, var item = evt.item,
ctrl = evt.target; ctrl = evt.target;
if (Sortable.utils.is(ctrl, ".js-remove")) { // Click on remove button if (Sortable.utils.is(ctrl, ".js-remove")) { // Click on remove button

2
index.html

@ -173,7 +173,7 @@
<a name="ng"></a> <a name="ng"></a>
<div id="todos" ng-app="todoApp" class="container" style="margin-top: 100px"> <div id="todos" ng-app="todoApp" class="container" style="margin-top: 100px">
<div style="margin-left: 30px"> <div style="margin-left: 30px">
<div><div data-force="5" class="layer title title_xl">AngluarJS / ng-sortable</div></div> <div><div data-force="5" class="layer title title_xl">AngularJS / ng-sortable</div></div>
<div style="width: 30%; margin-top: -8px; margin-left: 10px; float: left;" class="block__list block__list_words"> <div style="width: 30%; margin-top: -8px; margin-left: 10px; float: left;" class="block__list block__list_words">
<div ng-controller="TodoController"> <div ng-controller="TodoController">

12
meteor/README.md

@ -25,10 +25,18 @@ Simplest invocation - order will be lost when the page is refreshed:
Persist the sort order in the 'order' field of each document in the collection: Persist the sort order in the 'order' field of each document in the collection:
*Client:*
```handlebars ```handlebars
{{#sortable items=<collection|cursor|array> sortField="order"}} {{#sortable items=<collection|cursor|array> sortField="order"}}
``` ```
*Server:*
```js
Sortable.collections = <collectionName>; // the name, not the variable
```
Along with `items`, `sortField` is the only Meteor-specific option. If it's missing, the package will Along with `items`, `sortField` is the only Meteor-specific option. If it's missing, the package will
assume there is a field called "order" in the collection, holding unique `Number`s such that every assume there is a field called "order" in the collection, holding unique `Number`s such that every
`order` differs from that before and after it by at least 1. Basically, keep to 0, 1, 2, ... . `order` differs from that before and after it by at least 1. Basically, keep to 0, 1, 2, ... .
@ -36,6 +44,10 @@ Try not to depend on a particular format for this field; it *is* though guarante
produce lexicographical order, and that the order will be maintained after an arbitrary number of produce lexicographical order, and that the order will be maintained after an arbitrary number of
reorderings, unlike with [naive solutions](http://programmers.stackexchange.com/questions/266451/maintain-ordered-collection-by-updating-as-few-order-fields-as-possible). reorderings, unlike with [naive solutions](http://programmers.stackexchange.com/questions/266451/maintain-ordered-collection-by-updating-as-few-order-fields-as-possible).
Remember to declare on the server which collections you want to be reorderable from the client.
Otherwise, the library will error because the client would be able to modify numerical fields in
any collection, which represents a security risk.
## Passing options to the Sortable library ## Passing options to the Sortable library

8
meteor/example/.meteor/.finished-upgraders

@ -0,0 +1,8 @@
# This file contains information which helps Meteor properly upgrade your
# app when you run 'meteor update'. You should check it into version control
# with your project.
notices-for-0.9.0
notices-for-0.9.1
0.9.4-platform-file
notices-for-facebook-graph-api-2

7
meteor/example/.meteor/.id

@ -0,0 +1,7 @@
# This file contains a token that is unique to your project.
# Check it into your repository along with the rest of this directory.
# It can be used for purposes such as:
# - ensuring you don't accidentally deploy one app on top of another
# - providing package authors with aggregated statistics
ir0jg2douy3yo5mehw

2
meteor/example/.meteor/platforms

@ -0,0 +1,2 @@
browser
server

2
meteor/example/.meteor/release

@ -1 +1 @@
METEOR@1.0.1 METEOR@1.1.0.2

109
meteor/example/.meteor/versions

@ -1,56 +1,53 @@
application-configuration@1.0.3 autopublish@1.0.3
autopublish@1.0.1 autoupdate@1.2.1
autoupdate@1.1.3 base64@1.0.3
base64@1.0.1 binary-heap@1.0.3
binary-heap@1.0.1 blaze@2.1.2
blaze-tools@1.0.1 blaze-tools@1.0.3
blaze@2.0.3 boilerplate-generator@1.0.3
boilerplate-generator@1.0.1 callback-hook@1.0.3
callback-hook@1.0.1 check@1.0.5
check@1.0.2 dburles:mongo-collection-instances@0.3.3
ctl-helper@1.0.4 ddp@1.1.0
ctl@1.0.2 deps@1.0.7
dburles:mongo-collection-instances@0.2.5 ejson@1.0.6
ddp@1.0.12 fastclick@1.0.3
deps@1.0.5 fezvrasta:bootstrap-material-design@0.3.0
ejson@1.0.4 geojson-utils@1.0.3
fastclick@1.0.1 html-tools@1.0.4
fezvrasta:bootstrap-material-design@0.2.1 htmljs@1.0.4
follower-livedata@1.0.2 http@1.1.0
geojson-utils@1.0.1 id-map@1.0.3
html-tools@1.0.2 insecure@1.0.3
htmljs@1.0.2 jquery@1.11.3_2
http@1.0.8 json@1.0.3
id-map@1.0.1 lai:collection-extensions@0.1.3
insecure@1.0.1 launch-screen@1.0.2
jquery@1.0.1 livedata@1.0.13
json@1.0.1 logging@1.0.7
launch-screen@1.0.0 meteor@1.1.6
livedata@1.0.11 meteor-platform@1.2.2
logging@1.0.5 minifiers@1.1.5
meteor-platform@1.2.0 minimongo@1.0.8
meteor@1.1.3 mobile-status-bar@1.0.3
minifiers@1.1.2 mongo@1.1.0
minimongo@1.0.5 observe-sequence@1.0.6
mobile-status-bar@1.0.1 ordered-dict@1.0.3
mongo@1.0.9 random@1.0.3
observe-sequence@1.0.3 reactive-dict@1.1.0
ordered-dict@1.0.1 reactive-var@1.0.5
random@1.0.1 reload@1.1.3
reactive-dict@1.0.4 retry@1.0.3
reactive-var@1.0.3 routepolicy@1.0.5
reload@1.1.1 rubaxa:sortable@1.2.0
retry@1.0.1 session@1.1.0
routepolicy@1.0.2 spacebars@1.0.6
rubaxa:sortable@1.0.0 spacebars-compiler@1.0.6
session@1.0.4 templating@1.1.1
spacebars-compiler@1.0.3 tracker@1.0.7
spacebars@1.0.3 twbs:bootstrap@3.3.4
templating@1.0.9 ui@1.0.6
tracker@1.0.3 underscore@1.0.3
twbs:bootstrap@3.3.1 url@1.0.4
ui@1.0.4 webapp@1.2.0
underscore@1.0.1 webapp-hashing@1.0.3
url@1.0.2
webapp-hashing@1.0.1
webapp@1.1.4

2
meteor/example/README.md

@ -35,7 +35,7 @@ run script:
### Differential ### Differential
Differential wrote [a blog post on reorderable lists with Differential wrote [a blog post on reorderable lists with
Meteor](differential.com/blog/sortable-lists-in-meteor-using-jquery-ui) and Meteor](http://differential.com/blog/sortable-lists-in-meteor-using-jquery-ui) and
[jQuery UI Sortable](http://jqueryui.com/sortable/). It served as inspiration [jQuery UI Sortable](http://jqueryui.com/sortable/). It served as inspiration
for integrating [rubaxa:sortable](rubaxa.github.io/Sortable/), for integrating [rubaxa:sortable](rubaxa.github.io/Sortable/),
which uses the HTML5 native drag&drop API (not without [its which uses the HTML5 native drag&drop API (not without [its

1
meteor/example/package.json

@ -1 +0,0 @@
../../package.json

1
meteor/example/packages/Sortable

@ -1 +0,0 @@
../../../

3
meteor/example/server/sortable-collections.js

@ -0,0 +1,3 @@
'use strict';
Sortable.collections = ['attributes'];

10
meteor/methods.js → meteor/methods-client.js

@ -2,19 +2,15 @@
Meteor.methods({ Meteor.methods({
/** /**
* Update the orderField of documents with given ids in a collection, incrementing it by incDec * Update the sortField of documents with given ids in a collection, incrementing it by incDec
* @param {String} collectionName - name of the collection to update * @param {String} collectionName - name of the collection to update
* @param {String[]} ids - array of document ids * @param {String[]} ids - array of document ids
* @param {String} orderField - the name of the order field, usually "order" * @param {String} orderField - the name of the order field, usually "order"
* @param {Number} incDec - pass 1 or -1 * @param {Number} incDec - pass 1 or -1
*/ */
'rubaxa:sortable/collection-update': function (collectionName, ids, orderField, incDec) { 'rubaxa:sortable/collection-update': function (collectionName, ids, sortField, incDec) {
check(collectionName, String);
check(ids, [String]);
check(orderField, String);
check(incDec, Number);
var selector = {_id: {$in: ids}}, modifier = {$inc: {}}; var selector = {_id: {$in: ids}}, modifier = {$inc: {}};
modifier.$inc[orderField] = incDec; modifier.$inc[sortField] = incDec;
Mongo.Collection.get(collectionName).update(selector, modifier, {multi: true}); Mongo.Collection.get(collectionName).update(selector, modifier, {multi: true});
} }
}); });

31
meteor/methods-server.js

@ -0,0 +1,31 @@
'use strict';
Sortable = {};
Sortable.collections = []; // array of collection names that the client is allowed to reorder
Meteor.methods({
/**
* Update the sortField of documents with given ids in a collection, incrementing it by incDec
* @param {String} collectionName - name of the collection to update
* @param {String[]} ids - array of document ids
* @param {String} orderField - the name of the order field, usually "order"
* @param {Number} incDec - pass 1 or -1
*/
'rubaxa:sortable/collection-update': function (collectionName, ids, sortField, incDec) {
check(collectionName, String);
// don't allow the client to modify just any collection
if (!Sortable || !Array.isArray(Sortable.collections)) {
throw new Meteor.Error(500, 'Please define Sortable.collections');
}
if (Sortable.collections.indexOf(collectionName) === -1) {
throw new Meteor.Error(403, 'Collection <' + collectionName + '> is not Sortable. Please add it to Sortable.collections in server code.');
}
check(ids, [String]);
check(sortField, String);
check(incDec, Number);
var selector = {_id: {$in: ids}}, modifier = {$inc: {}};
modifier.$inc[sortField] = incDec;
Mongo.Collection.get(collectionName).update(selector, modifier, {multi: true});
}
});

9
meteor/package.js

@ -10,20 +10,21 @@ Package.describe({
summary: 'Sortable: reactive minimalist reorderable drag-and-drop lists on modern browsers and touch devices', summary: 'Sortable: reactive minimalist reorderable drag-and-drop lists on modern browsers and touch devices',
version: packageJson.version, version: packageJson.version,
git: 'https://github.com/RubaXa/Sortable.git', git: 'https://github.com/RubaXa/Sortable.git',
readme: 'https://github.com/RubaXa/Sortable/blob/master/meteor/README.md' documentation: 'meteor/README.md'
}); });
Package.onUse(function (api) { Package.onUse(function (api) {
api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']); api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']);
api.use('templating', 'client'); api.use('templating', 'client');
api.use('dburles:mongo-collection-instances@0.2.6'); // to watch collections getting created api.use('dburles:mongo-collection-instances@0.3.3'); // to watch collections getting created
api.export('Sortable'); api.export('Sortable'); // exported on the server too, as a global to hold the array of sortable collections (for security)
api.addFiles([ api.addFiles([
'Sortable.js', 'Sortable.js',
'meteor/template.html', // the HTML comes first, so reactivize.js can refer to the template in it 'meteor/template.html', // the HTML comes first, so reactivize.js can refer to the template in it
'meteor/reactivize.js' 'meteor/reactivize.js'
], 'client'); ], 'client');
api.addFiles('meteor/methods.js'); // add to both client and server api.addFiles('meteor/methods-client.js', 'client');
api.addFiles('meteor/methods-server.js', 'server');
}); });
Package.onTest(function (api) { Package.onTest(function (api) {

2
meteor/reactivize.js

@ -1,6 +1,6 @@
/* /*
Make a Sortable reactive by binding it to a Mongo.Collection. Make a Sortable reactive by binding it to a Mongo.Collection.
Calls `rubaxa:sortable/collection-update` on the server to update the sortField or affected records. Calls `rubaxa:sortable/collection-update` on the server to update the sortField of affected records.
TODO: TODO:
* supply consecutive values if the `order` field doesn't have any * supply consecutive values if the `order` field doesn't have any

Loading…
Cancel
Save