mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
admin now able to change user and date
This commit is contained in:
parent
5628b1e298
commit
7afaee4e80
7 changed files with 101 additions and 26 deletions
|
@ -11,10 +11,6 @@
|
||||||
<label class="control-label">URL</label>
|
<label class="control-label">URL</label>
|
||||||
<div class="controls"><input id="url" type="text" value="{{url}}" /></div>
|
<div class="controls"><input id="url" type="text" value="{{url}}" /></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
|
||||||
<label class="control-label">Submitted</label>
|
|
||||||
<div class="controls"><input id="submitted" type="text" value="{{submittedDate}}" /><input id="submitted_hidden" type="hidden" value="{{submitted}}" /></div>
|
|
||||||
</div>
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">Body</label>
|
<label class="control-label">Body</label>
|
||||||
<div class="controls" id="editor"><textarea id="body" value="" class="input-xlarge">{{body}}</textarea></div>
|
<div class="controls" id="editor"><textarea id="body" value="" class="input-xlarge">{{body}}</textarea></div>
|
||||||
|
@ -30,12 +26,26 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{#if isAdmin}}
|
{{#if isAdmin}}
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">Sticky?</label>
|
<label class="control-label">Sticky?</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input type="checkbox" name="sticky" id="sticky" {{#if sticky}}checked{{/if}} />
|
<input type="checkbox" name="sticky" id="sticky" {{#if sticky}}checked{{/if}} />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">Date</label>
|
||||||
|
<div class="controls"><input id="submitted" type="text" value="{{submittedDate}}" /><input id="submitted_hidden" type="hidden" value="{{submitted}}" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">User</label>
|
||||||
|
<div class="controls">
|
||||||
|
<select id="postUser">
|
||||||
|
{{#each users}}
|
||||||
|
<option {{#if isSelected}}selected{{/if}} value="{{_id}}">{{userName}}</option>
|
||||||
|
{{/each}}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<a class="delete-link" href="/posts/deleted">Delete Post</a>
|
<a class="delete-link" href="/posts/deleted">Delete Post</a>
|
||||||
|
|
|
@ -18,6 +18,16 @@ Template.post_edit.helpers({
|
||||||
},
|
},
|
||||||
submittedDate: function(){
|
submittedDate: function(){
|
||||||
return moment(this.submitted).format("MMMM Do, h:mm:ss a");
|
return moment(this.submitted).format("MMMM Do, h:mm:ss a");
|
||||||
|
},
|
||||||
|
users: function(){
|
||||||
|
return Meteor.users.find();
|
||||||
|
},
|
||||||
|
userName: function(){
|
||||||
|
return getDisplayName(this);
|
||||||
|
},
|
||||||
|
isSelected: function(){
|
||||||
|
var post=Posts.findOne(Session.get('selectedPostId'));
|
||||||
|
return post && this._id == post.userId;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -43,26 +53,29 @@ Template.post_edit.events = {
|
||||||
var selectedPostId=Session.get('selectedPostId');
|
var selectedPostId=Session.get('selectedPostId');
|
||||||
var title= $('#title').val();
|
var title= $('#title').val();
|
||||||
var url = $('#url').val();
|
var url = $('#url').val();
|
||||||
var submitted = $('#submitted_hidden').val();
|
|
||||||
var body = instance.editor.exportFile();
|
var body = instance.editor.exportFile();
|
||||||
var sticky=!!$('#sticky').attr('checked');
|
|
||||||
var categories=[];
|
var categories=[];
|
||||||
|
var sticky=!!$('#sticky').attr('checked');
|
||||||
|
var submitted = $('#submitted_hidden').val();
|
||||||
|
var userId = $('#postUser').val();
|
||||||
|
|
||||||
$('input[name=category]:checked').each(function() {
|
$('input[name=category]:checked').each(function() {
|
||||||
categories.push($(this).val());
|
categories.push($(this).val());
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('categories:', categories);
|
console.log('categories:', categories);
|
||||||
|
console.log('submitted', submitted);
|
||||||
|
console.log('userId', userId, getDisplayNameById(userId));
|
||||||
Posts.update(selectedPostId,
|
Posts.update(selectedPostId,
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
headline: title
|
headline: title
|
||||||
, url: url
|
, url: url
|
||||||
, submitted: parseInt(submitted)
|
|
||||||
, body: body
|
, body: body
|
||||||
, sticky: sticky
|
|
||||||
, categories: categories
|
, categories: categories
|
||||||
|
, submitted: parseInt(submitted)
|
||||||
|
, sticky: sticky
|
||||||
|
, userId: userId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
,function(error){
|
,function(error){
|
||||||
|
|
|
@ -25,6 +25,28 @@
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{#if isAdmin}}
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">Sticky?</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="checkbox" name="sticky" id="sticky" {{#if sticky}}checked{{/if}} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">Date</label>
|
||||||
|
<div class="controls"><input id="submitted" type="text" value="{{submittedDate}}" /><input id="submitted_hidden" type="hidden" value="{{submitted}}" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">User</label>
|
||||||
|
<div class="controls">
|
||||||
|
<select id="postUser">
|
||||||
|
{{#each users}}
|
||||||
|
<option {{#if isSelected}}selected{{/if}} value="{{_id}}">{{userName}}</option>
|
||||||
|
{{/each}}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
{{/constant}}
|
{{/constant}}
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<input type="submit" value="Submit" />
|
<input type="submit" value="Submit" />
|
||||||
|
|
|
@ -1,9 +1,31 @@
|
||||||
Template.post_submit.helpers({
|
Template.post_submit.helpers({
|
||||||
categories: function(){
|
categories: function(){
|
||||||
return Categories.find();
|
return Categories.find();
|
||||||
|
},
|
||||||
|
users: function(){
|
||||||
|
return Meteor.users.find();
|
||||||
|
},
|
||||||
|
userName: function(){
|
||||||
|
return getDisplayName(this);
|
||||||
|
},
|
||||||
|
isSelected: function(){
|
||||||
|
var post=Posts.findOne(Session.get('selectedPostId'));
|
||||||
|
return post && this._id == post.userId;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Template.post_submit.rendered = function(){
|
||||||
|
Session.set('selectedPostId', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Template.post_submit.rendered = function(){
|
||||||
|
this.editor= new EpicEditor(EpicEditorOptions).load();
|
||||||
|
$('#submitted').datepicker().on('changeDate', function(ev){
|
||||||
|
$('#submitted_hidden').val(moment(ev.date).valueOf());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Template.post_submit.events = {
|
Template.post_submit.events = {
|
||||||
'click input[type=submit]': function(e, instance){
|
'click input[type=submit]': function(e, instance){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -19,6 +41,9 @@ Template.post_submit.events = {
|
||||||
var url = $('#url').val();
|
var url = $('#url').val();
|
||||||
var body = instance.editor.exportFile();
|
var body = instance.editor.exportFile();
|
||||||
var categories=[];
|
var categories=[];
|
||||||
|
var sticky=!!$('#sticky').attr('checked');
|
||||||
|
var submitted = $('#submitted_hidden').val();
|
||||||
|
var userId = $('#postUser').val();
|
||||||
|
|
||||||
$('input[name=category]:checked').each(function() {
|
$('input[name=category]:checked').each(function() {
|
||||||
categories.push($(this).val());
|
categories.push($(this).val());
|
||||||
|
@ -29,6 +54,9 @@ Template.post_submit.events = {
|
||||||
body: body,
|
body: body,
|
||||||
url: url,
|
url: url,
|
||||||
categories: categories,
|
categories: categories,
|
||||||
|
sticky: sticky,
|
||||||
|
submitted: submitted,
|
||||||
|
userId: userId
|
||||||
}, function(error, postId) {
|
}, function(error, postId) {
|
||||||
if(error){
|
if(error){
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
@ -59,8 +87,4 @@ Template.post_submit.events = {
|
||||||
alert("Please fill in an URL first!");
|
alert("Please fill in an URL first!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Template.post_submit.rendered = function(){
|
|
||||||
this.editor= new EpicEditor(EpicEditorOptions).load();
|
|
||||||
}
|
|
|
@ -1,6 +1,8 @@
|
||||||
Meteor.methods({
|
Meteor.methods({
|
||||||
post: function(post){
|
post: function(post){
|
||||||
var user = Meteor.user();
|
var user = Meteor.user();
|
||||||
|
var userId = post.userId || user._id;
|
||||||
|
var submitted = parseInt(post.submitted) || new Date().getTime();
|
||||||
|
|
||||||
if (!user || !canPost(user))
|
if (!user || !canPost(user))
|
||||||
throw new Meteor.Error(123, 'You need to login or be invited to post new stories.');
|
throw new Meteor.Error(123, 'You need to login or be invited to post new stories.');
|
||||||
|
@ -11,10 +13,14 @@ Meteor.methods({
|
||||||
if(!this.isSimulation)
|
if(!this.isSimulation)
|
||||||
limitRate(user, Posts, 30);
|
limitRate(user, Posts, 30);
|
||||||
|
|
||||||
|
console.log(userId);
|
||||||
|
console.log(submitted);
|
||||||
|
console.log(post);
|
||||||
|
|
||||||
post = _.extend(post, {
|
post = _.extend(post, {
|
||||||
userId: user._id,
|
userId: userId,
|
||||||
author: getDisplayName(user),
|
author: getDisplayNameById(userId),
|
||||||
submitted: new Date().getTime(),
|
submitted: submitted,
|
||||||
votes: 0,
|
votes: 0,
|
||||||
comments: 0,
|
comments: 0,
|
||||||
baseScore: 0,
|
baseScore: 0,
|
||||||
|
|
|
@ -7,12 +7,12 @@ isAdmin=function(user){
|
||||||
return false;
|
return false;
|
||||||
return !!user.isAdmin;
|
return !!user.isAdmin;
|
||||||
}
|
}
|
||||||
getDisplayNameById = function(userId){
|
|
||||||
getDisplayName(Meteor.users.findOne(userId));
|
|
||||||
}
|
|
||||||
getDisplayName = function(user){
|
getDisplayName = function(user){
|
||||||
return (user.profile && user.profile.name) ? user.profile.name : user.username;
|
return (user.profile && user.profile.name) ? user.profile.name : user.username;
|
||||||
}
|
}
|
||||||
|
getDisplayNameById = function(userId){
|
||||||
|
return getDisplayName(Meteor.users.findOne(userId));
|
||||||
|
}
|
||||||
getSignupMethod = function(user){
|
getSignupMethod = function(user){
|
||||||
if(user.services && user.services.twitter){
|
if(user.services && user.services.twitter){
|
||||||
return 'twitter';
|
return 'twitter';
|
||||||
|
|
|
@ -24,7 +24,7 @@ Meteor.startup(function () {
|
||||||
// recalculate scores every N seconds
|
// recalculate scores every N seconds
|
||||||
if(scoreInterval>0){
|
if(scoreInterval>0){
|
||||||
intervalId=Meteor.setInterval(function () {
|
intervalId=Meteor.setInterval(function () {
|
||||||
console.log('tick ('+scoreInterval+')');
|
// console.log('tick ('+scoreInterval+')');
|
||||||
Posts.find().forEach(function (post) { updateScore(Posts, post._id); });
|
Posts.find().forEach(function (post) { updateScore(Posts, post._id); });
|
||||||
Comments.find().forEach(function (comment) { updateScore(Comments, comment._id); });
|
Comments.find().forEach(function (comment) { updateScore(Comments, comment._id); });
|
||||||
}, scoreInterval * 1000);
|
}, scoreInterval * 1000);
|
||||||
|
|
Loading…
Add table
Reference in a new issue