mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
refactoring parameters to simplify showing/hiding future posts, and adding "scheduled" view
This commit is contained in:
parent
305322bf25
commit
7879172c5d
8 changed files with 85 additions and 54 deletions
|
@ -3,6 +3,7 @@
|
|||
* Renaming Errors to Messages (thanks @yourcelf!).
|
||||
* Adding `fast-render` (thanks @arunoda!).
|
||||
* Extracted digest into its own package.
|
||||
* Adding "scheduled" view that shows upcoming scheduled posts.
|
||||
|
||||
## v0.9.11 “FormScope”
|
||||
|
||||
|
|
|
@ -9,25 +9,6 @@ STATUS_PENDING=1;
|
|||
STATUS_APPROVED=2;
|
||||
STATUS_REJECTED=3;
|
||||
|
||||
adminNav = adminNav.concat([
|
||||
{
|
||||
route: 'posts_pending',
|
||||
label: 'Pending'
|
||||
},
|
||||
{
|
||||
route: 'all-users',
|
||||
label: 'Users'
|
||||
},
|
||||
{
|
||||
route: 'settings',
|
||||
label: 'Settings'
|
||||
},
|
||||
{
|
||||
route: 'toolbox',
|
||||
label: 'Toolbox'
|
||||
}
|
||||
]);
|
||||
|
||||
// Sort postModules array position using modulePositions as index
|
||||
postModules = _.sortBy(postModules, function(module){return _.indexOf(modulePositions, module.position)});
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<div class="post-meta-item">
|
||||
<span class="points">{{baseScore}}</span>
|
||||
<span class="unit">{{pointsUnitDisplayText}}</span>
|
||||
<span class="post-time">{{timeAgo ago}}</span>
|
||||
{{#if postedAt}}<span class="post-time">{{timeAgo postedAt}}</span>{{/if}}
|
||||
{{#if can_edit}}
|
||||
| <a href="{{pathFor route='post_edit' _id=_id}}" class="edit-link goto-edit">{{_ "edit"}}</a>
|
||||
{{/if}}
|
||||
|
|
|
@ -5,11 +5,6 @@ Template[getTemplate('postInfo')].helpers({
|
|||
can_edit: function(){
|
||||
return canEdit(Meteor.user(), this);
|
||||
},
|
||||
ago: function(){
|
||||
// if post is approved show submission time, else show creation time.
|
||||
time = this.status == STATUS_APPROVED ? this.postedAt : this.createdAt;
|
||||
return time;
|
||||
},
|
||||
getTemplate: function() {
|
||||
return getTemplate("postAuthor");
|
||||
}
|
||||
|
|
|
@ -462,8 +462,13 @@ Meteor.methods({
|
|||
|
||||
approvePost: function(post){
|
||||
if(isAdmin(Meteor.user())){
|
||||
var now = new Date();
|
||||
var result = Posts.update(post._id, {$set: {status: 2, postedAt: now}}, {validate: false});
|
||||
var set = {status: 2};
|
||||
|
||||
// unless post is already scheduled and has a postedAt date, set its postedAt date to now
|
||||
if (!post.postedAt)
|
||||
set.postedAt = new Date();
|
||||
|
||||
var result = Posts.update(post._id, {$set: set}, {validate: false});
|
||||
}else{
|
||||
flashMessage('You need to be an admin to do that.', "error");
|
||||
}
|
||||
|
|
|
@ -7,32 +7,28 @@ getPostsParameters = function (terms) {
|
|||
// note: using jquery's extend() with "deep" parameter set to true instead of shallow _.extend()
|
||||
// see: http://api.jquery.com/jQuery.extend/
|
||||
|
||||
var baseParameters = {
|
||||
find: {
|
||||
status: STATUS_APPROVED,
|
||||
$or: [
|
||||
{postedAt: {$lte: new Date()}}, // only show posts if they're in the past
|
||||
{postedAt: {$exists: false}} // or if they don't have a "postedAt" date (i.e. pending posts)
|
||||
]
|
||||
},
|
||||
options: {
|
||||
limit: 10
|
||||
}
|
||||
};
|
||||
var parameters = baseParameters;
|
||||
var view = !!terms.view ? dashToCamel(terms.view) : 'top'; // if view is not defined, default to "top"
|
||||
// initialize parameters by extending baseParameters object, to avoid passing it by reference
|
||||
var parameters = deepExtend(true, {}, viewParameters.baseParameters);
|
||||
|
||||
// if view is not defined, default to "top"
|
||||
var view = !!terms.view ? dashToCamel(terms.view) : 'top';
|
||||
|
||||
// get query parameters according to current view
|
||||
if (typeof viewParameters[view] !== 'undefined')
|
||||
parameters = deepExtend(true, baseParameters, viewParameters[view](terms));
|
||||
parameters = deepExtend(true, parameters, viewParameters[view](terms));
|
||||
|
||||
// sort by _id to break ties
|
||||
// extend sort to sort posts by _id to break ties
|
||||
deepExtend(true, parameters, {options: {sort: {_id: -1}}});
|
||||
|
||||
if(typeof terms.limit != 'undefined' && !!terms.limit)
|
||||
// if there is a limit and it's not null, add it too
|
||||
if (typeof terms.limit !== 'undefined' && !!terms.limit)
|
||||
_.extend(parameters.options, {limit: parseInt(terms.limit)});
|
||||
|
||||
// console.log(parameters)
|
||||
// hide future scheduled posts unless "showFuture" is set to true
|
||||
if (!parameters.showFuture)
|
||||
parameters.find.postedAt = {$lte: new Date()};
|
||||
|
||||
// console.log(parameters);
|
||||
|
||||
return parameters;
|
||||
};
|
||||
|
|
|
@ -76,6 +76,10 @@ PostsPendingController = PostsListController.extend({
|
|||
view: 'pending'
|
||||
});
|
||||
|
||||
PostsScheduledController = PostsListController.extend({
|
||||
view: 'scheduled'
|
||||
});
|
||||
|
||||
// Controller for post pages
|
||||
|
||||
PostPageController = RouteController.extend({
|
||||
|
@ -148,6 +152,13 @@ Meteor.startup(function () {
|
|||
controller: PostsPendingController
|
||||
});
|
||||
|
||||
// Scheduled
|
||||
|
||||
Router.route('/scheduled/:limit?', {
|
||||
name: 'posts_scheduled',
|
||||
controller: PostsScheduledController
|
||||
});
|
||||
|
||||
// Post Page
|
||||
|
||||
Router.route('/posts/:_id', {
|
||||
|
|
|
@ -40,7 +40,28 @@ primaryNav = ['viewsMenu', 'adminMenu'];
|
|||
secondaryNav = ['userMenu', 'notificationsMenu', 'submitButton'];
|
||||
|
||||
// array containing items in the admin menu
|
||||
adminNav = [];
|
||||
adminNav = [
|
||||
{
|
||||
route: 'posts_pending',
|
||||
label: 'Pending'
|
||||
},
|
||||
{
|
||||
route: 'posts_scheduled',
|
||||
label: 'Scheduled'
|
||||
},
|
||||
{
|
||||
route: 'all-users',
|
||||
label: 'Users'
|
||||
},
|
||||
{
|
||||
route: 'settings',
|
||||
label: 'Settings'
|
||||
},
|
||||
{
|
||||
route: 'toolbox',
|
||||
label: 'Toolbox'
|
||||
}
|
||||
];
|
||||
|
||||
// array containing items in the views menu
|
||||
viewNav = [
|
||||
|
@ -62,7 +83,17 @@ viewNav = [
|
|||
|
||||
|
||||
// object containing post list view parameters
|
||||
viewParameters = {}
|
||||
viewParameters = {};
|
||||
|
||||
// will be common to all other view unless specific properties are overwritten
|
||||
viewParameters.baseParameters = {
|
||||
find: {
|
||||
status: STATUS_APPROVED
|
||||
},
|
||||
options: {
|
||||
limit: 10
|
||||
}
|
||||
};
|
||||
|
||||
viewParameters.top = function (terms) {
|
||||
return {
|
||||
|
@ -85,13 +116,24 @@ viewParameters.best = function (terms) {
|
|||
viewParameters.pending = function (terms) {
|
||||
return {
|
||||
find: {
|
||||
status: 1,
|
||||
$or: [
|
||||
{postedAt: {$lte: new Date("December 31, 2999")}},
|
||||
{postedAt: {$exists: false}}
|
||||
] // for pending view, show future posts too
|
||||
status: 1
|
||||
},
|
||||
options: {sort: {createdAt: -1}}
|
||||
options: {sort: {createdAt: -1}},
|
||||
showFuture: true
|
||||
};
|
||||
}
|
||||
|
||||
viewParameters.scheduled = function (terms) {
|
||||
return {
|
||||
find: {postedAt: {$gte: new Date()}},
|
||||
options: {sort: {postedAt: -1}},
|
||||
showFuture: true
|
||||
};
|
||||
}
|
||||
|
||||
viewParameters.upvoted = function (terms) {
|
||||
return {
|
||||
options: {sort: {sticky: -1, score: -1}}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue