Skip to content

Commit

Permalink
#1197 updated comment service references
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhyder committed Mar 14, 2017
1 parent db87b0f commit 64f519e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 43 deletions.
7 changes: 4 additions & 3 deletions controllers/base_controller.js
Expand Up @@ -349,11 +349,12 @@ var uuid = require('uuid');
/**
* Retrieves a context object that contains the necessary information for
* service prototypes
* @method getServiceContext
* @param {object} [base] The custom set of attributes that should be provided. Any items from the derived context
* will override the base attributes
* @return {Object}
*/
BaseController.prototype.getServiceContext = function(){
return Object.assign({}, this.context);
BaseController.prototype.getServiceContext = function(base){
return Object.assign(base || {}, this.context);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion include/service/entities/content/content_view_loader.js
Expand Up @@ -64,7 +64,7 @@ class ContentViewLoader {
* @property commentService
* @type {CommentService}
*/
this.commentService = context.commentService || new CommentService(context);
this.commentService = context.commentService;
}

/**
Expand Down
29 changes: 15 additions & 14 deletions plugins/pencilblue/controllers/api/content/get_articles.js
Expand Up @@ -22,10 +22,10 @@ var async = require('async');
module.exports = function(pb) {

//pb dependencies
var util = pb.util;
var BaseController = pb.BaseController;
var Comments = pb.CommentService;
var ArticleServiceV2 = pb.ArticleServiceV2;
const ArticleServiceV2 = pb.ArticleServiceV2;
const BaseController = pb.BaseController;
const CommentService = pb.CommentService;
const util = pb.util;

/**
* Get articles within indices, for real time pagination
Expand All @@ -45,19 +45,20 @@ module.exports = function(pb) {
var contentService = new pb.ContentService();
contentService.getSettings(function(err, contentSettings) {

//set the content settings
self.contentSettings = contentSettings;

//create the service
var asContext = self.getServiceContext();
asContext.contentSettings = contentSettings;
self.service = new pb.ArticleServiceV2(asContext);
self.contentSettings = contentSettings;
self.service = new pb.ArticleServiceV2(self.getServiceContext({
contentSettings: contentSettings
}));

//create the loader context
var cvlContext = self.getServiceContext();
cvlContext.service = self.service;
cvlContext.contentSettings = contentSettings;
self.contentViewLoader = new pb.ContentViewLoader(cvlContext);
self.contentViewLoader = new pb.ContentViewLoader(self.getServiceContext({
contentSettings: contentSettings,
service: self.service,
commentService: new CommentService(self.getServiceContext({
articleService: self.service
}))
}));

//call back
cb(err, !util.isError(err));
Expand Down
17 changes: 11 additions & 6 deletions plugins/pencilblue/controllers/article.js
Expand Up @@ -18,7 +18,9 @@
module.exports = function(pb) {

//pb dependencies
var util = pb.util;
const util = pb.util;
const BaseController = pb.BaseController;
const CommentService = pb.CommentService;

/**
* Loads a single article
Expand All @@ -27,11 +29,11 @@ module.exports = function(pb) {
* @extends BaseController
*/
function ArticleViewController(){}
util.inherits(ArticleViewController, pb.BaseController);
util.inherits(ArticleViewController, BaseController);

/**
* @method init
* @param {Object} content
* @param {Object} context
* @param {Function} cb
*/
ArticleViewController.prototype.init = function(context, cb) {
Expand All @@ -45,9 +47,12 @@ module.exports = function(pb) {
self.service = new pb.ArticleServiceV2(self.getServiceContext());

//create the loader context
var context = self.getServiceContext();
context.service = self.service;
self.contentViewLoader = new pb.ContentViewLoader(context);
self.contentViewLoader = new pb.ContentViewLoader(self.getServiceContext({
service: service,
commentService: new CommentService(self.getServiceContext({
articleService: self.service
}))
}));

cb(null, true);
};
Expand Down
20 changes: 12 additions & 8 deletions plugins/pencilblue/controllers/blog.js
Expand Up @@ -18,7 +18,8 @@
module.exports = function(pb) {

//pb dependencies
var util = pb.util;
const CommentService = pb.CommentService;
const util = pb.util;

/**
* Loads a section
Expand All @@ -40,15 +41,18 @@ module.exports = function(pb) {

//create the service
self.contentSettings = contentSettings;
var asContext = self.getServiceContext();
asContext.contentSettings = contentSettings;
self.service = new pb.ArticleServiceV2(asContext);
self.service = new pb.ArticleServiceV2(self.getServiceContext({
contentSettings: contentSettings
}));

//create the loader context
var cvlContext = self.getServiceContext();
cvlContext.contentSettings = contentSettings;
cvlContext.service = self.service;
self.contentViewLoader = new pb.ContentViewLoader(cvlContext);
self.contentViewLoader = new pb.ContentViewLoader(self.getServiceContext({
contentSettings: contentSettings,
service: self.service,
commentService: new CommentService(self.getServiceContext({
articleService: self.service
}))
}));

cb(null, true);
});
Expand Down
8 changes: 6 additions & 2 deletions plugins/pencilblue/controllers/page.js
Expand Up @@ -19,7 +19,8 @@
module.exports = function(pb) {

//pb dependencies
var util = pb.util;
const CommentService = pb.CommentService;
const util = pb.util;

/**
* Loads a single article
Expand Down Expand Up @@ -48,7 +49,10 @@ module.exports = function(pb) {
//create the loader context
var context = self.getServiceContext();
context.service = self.service;
self.contentViewLoader = new pb.ContentViewLoader(context);
self.contentViewLoader = new pb.ContentViewLoader(self.getServiceContext({
service: self.service,
commentService: new CommentService(self.getServiceContext())
}));

cb(null, true);
};
Expand Down
23 changes: 14 additions & 9 deletions plugins/pencilblue/controllers/section.js
Expand Up @@ -19,7 +19,8 @@
module.exports = function(pb) {

//pb dependencies
var util = pb.util;
const CommentService = pb.CommentService;
const util = pb.util;

/**
* Loads a section
Expand All @@ -45,20 +46,24 @@ module.exports = function(pb) {
if (util.isError(err)) {
return cb(err);
}

//create the service
self.contentSettings = contentSettings;
var asContext = self.getServiceContext();
asContext.contentSettings = contentSettings;
self.service = new pb.ArticleServiceV2(asContext);
self.service = new pb.ArticleServiceV2(self.getServiceContext({
contentSettings: contentSettings
}));

//create the loader context
var cvlContext = self.getServiceContext();
cvlContext.contentSettings = contentSettings;
cvlContext.service = self.service;
self.contentViewLoader = new pb.ContentViewLoader(cvlContext);
self.contentViewLoader = new pb.ContentViewLoader(self.getServiceContext({
contentSettings: contentSettings,
service: self.service,
commentService: new CommentService(self.getServiceContext({
articleService: self.service
}))
}));

//provide a dao
self.dao = new pb.DAO();
self.dao = new pb.DAO();

cb(null, true);
});
Expand Down

0 comments on commit 64f519e

Please sign in to comment.