Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Commit

Permalink
adds listByActivity method & hidden filters to list methods
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtreece committed May 6, 2014
1 parent 05929d2 commit 05284c8
Showing 1 changed file with 53 additions and 4 deletions.
57 changes: 53 additions & 4 deletions lib/phant-meta-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,35 @@ function PhantMeta(config) {

}

app.name = 'phant json metadata storage';
app.name = 'Metadata JSON';
app.directory = path.join(__dirname, '..');

app.newId = function() {
return uuid.v1().replace(/-/g, '');
};

function reverseSort(field) {

return function(a, b) {

if(a[field] === b[field]) {
return 0;
}

if(! a[field]) {
return -1;
}

if(! b[field]) {
return 1;
}

return b[field] - a[field];

};

}

app.getStreams = function(callback) {

var file = path.join(this.directory, 'streams.json');
Expand Down Expand Up @@ -108,7 +130,13 @@ app.list = function(callback, offset, limit) {

this.getStreams(function(streams) {

callback('', streams.slice(offset, limit + offset));
var result = _.filter(streams, function(stream) {

return !stream.hidden && !stream.flagged;

}).sort(reverseSort('date'));

callback('', result.slice(offset, limit + offset));

});

Expand All @@ -122,8 +150,29 @@ app.listByTag = function(tag, callback, offset, limit) {
this.getStreams(function(streams) {

var result = _.filter(streams, function(stream) {
return _.contains(stream.tags, tag);
});

return !stream.hidden && !stream.flagged && _.contains(stream.tags, tag);

}).sort(reverseSort('date'));

callback('', result.slice(offset, limit + offset));

});

};

app.listByActivity = function(callback, offset, limit) {

limit = limit || 20;
offset = offset || 0;

this.getStreams(function(streams) {

var result = _.filter(streams, function(stream) {

return !stream.hidden && !stream.flagged;

}).sort(reverseSort('last_push'));

callback('', result.slice(offset, limit + offset));

Expand Down

0 comments on commit 05284c8

Please sign in to comment.