Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saves #21

Merged
merged 4 commits into from
Jul 30, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions converse.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ var Person = converse.define('Person', {
},
populate: '_author _document',
sort: '-score -created'
},
'Save': {
filter: function() {
var person = this;
return { _user: person._id };
},
populate: '_post',
sort: '-created'
}
},
icon: 'user'
Expand Down Expand Up @@ -362,6 +370,15 @@ Vote.pre('create', function(next, done) {
});
});

var Save = converse.define('Save', {
attributes: {
_user: { type: ObjectId , required: true , ref: 'Person', populate: ['query', 'get'] },
_post: { type: ObjectId , required: true , ref: 'Post', populate: ['query', 'get'] },
created: { type: Date , required: true , default: Date.now }
},
icon: 'bookmark'
});
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the above Resource, perhaps we add a field to denote the population criteria for the documents it is pointing at – for example, when a "Save" is retrieved, the _user path should have additional populate options passed to it. We already have populate being used to describe when population happens, but no additional parameters to specify any further population.


converse.define('Index', {
name: 'Index',
static: true,
Expand Down
18 changes: 18 additions & 0 deletions public/js/converse.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ $(document).on('click', '*[data-intent=comment]', function(e) {
$('textarea').focus();
});

$(document).on('click', '*[data-intent=save]', function(e) {
e.preventDefault();

var $self = $(this);
var post = $self.data('post');
var user = $self.data('user');

var data = {
_post: post,
_user: user
};

$.post('/saves', data, function(save, status, xhr) {
console.log('save:', save);
}, 'json');

});

$(document).on('click', '*[data-intent=upvote], *[data-intent=downvote]', function(e) {
e.preventDefault();

Expand Down
11 changes: 8 additions & 3 deletions views/mixins/post.jade
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ mixin PostView(post, maxWords, samePage)
a.ui.button(href="/posts/#{post._id}")
i.linkify.icon
| permalink
a.ui.button(href="#", data-intent="save")
i.bookmark.icon
| save
if (user)
a.ui.button(href="#", data-intent="save", data-post="#{post._id}", data-user="#{user._id}")
i.bookmark.icon
| save
else
a.ui.button.tooltipped(href="#", title="Sign in to save this to your bookmarks!")
i.bookmark.icon
| save
a.ui.button(href="#", data-intent="tip")
i.bitcoin.icon
| tip
Expand Down
8 changes: 8 additions & 0 deletions views/person.jade
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ block content

.ui.cards
include partials/post-list

h3 Saves
.ui.cards
code saves: #{saves}
code saves.length: #{saves.length}
.ui.cards
for save in saves
+PostView(save, 20)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This view will fail, as save._author does not get populated by default. We should look to implement this in martindale/maki#87.