Created: {{post.createdOn | date:"MM/dd/yyyy 'at' h:mma"}}
diff --git a/admin/lib/controllers/posts-ctrl.ts b/admin/lib/controllers/posts-ctrl.ts
index f386c45c..9f83f736 100644
--- a/admin/lib/controllers/posts-ctrl.ts
+++ b/admin/lib/controllers/posts-ctrl.ts
@@ -3,7 +3,7 @@
/**
* Controller for the dashboard posts section
*/
- export class PostsCtrl extends PagedContentCtrl
+ export class PostsCtrl
{
public postToken: Modepress.IPost;
public posts: Array
;
@@ -26,13 +26,18 @@
public showMediaBrowser: boolean;
public defaultSlug: string;
public targetImgReciever: string;
+
private _q: ng.IQService;
+ private http: ng.IHttpService;
+ private error: boolean;
+ private loading: boolean;
+ private errorMsg: string;
+ private pager: IPagerRemote;
// $inject annotation.
public static $inject = ["$scope", "$http", "apiURL", "mediaURL", "categories", "$q"];
constructor(scope, http: ng.IHttpService, apiURL: string, mediaURL: string, categories: Array, $q: ng.IQService)
{
- super(http);
this.newCategoryMode = false;
this.scope = scope;
this.apiURL = apiURL;
@@ -51,10 +56,15 @@
this.defaultSlug = "";
this.showMediaBrowser = false;
this.targetImgReciever = "";
+
+ this.http = http;
+ this.loading = false;
+ this.error = false;
+ this.errorMsg = "";
this._q = $q;
+ this.pager = this.createPagerRemote();
this.postToken = { title: "", content: "", slug: "", tags: [], categories: [], public: true, brief: "" };
- //this.updatePageContent();
var that = this;
tinymce.init({
@@ -139,13 +149,13 @@
swapOrder()
{
this.sortOrder = (this.sortOrder == 'asc' ? 'desc' : 'asc');
- this.updatePageContent();
+ this.pager.invalidate();
}
swapSortType()
{
this.sortType = (this.sortType == 'created' ? 'updated' : 'created');
- this.updatePageContent();
+ this.pager.invalidate();
}
/**
@@ -193,42 +203,42 @@
});
}
- /**
- * Fetches the posts from the database
- */
- updatePageContent(index?: number, limit? : number)
+ createPagerRemote(): IPagerRemote
{
var that = this;
- this.error = false;
- this.errorMsg = "";
- this.loading = true;
- //var index = this.index;
- //var limit = this.limit;
- var keyword = this.searchKeyword;
- var searchCategory = this.searchCategory;
- var order = this.sortOrder;
- var sortType = this.sortType;
-
- return new this._q(function(resolve, reject)
- {
- that.http.get(`${that.apiURL}/posts/get-posts?visibility=all&verbose=true&sort=${sortType}&sortOrder=${order}&categories=${searchCategory}&index=${index}&limit=${limit}&keyword=${keyword}`).then(function (token)
+ var remote: IPagerRemote = {
+ update: function(index?: number, limit? : number)
{
- if (token.data.error) {
- that.error = true;
- that.errorMsg = token.data.message;
- that.posts = [];
- that.last = 1;
- resolve(1);
- }
- else {
- that.posts = token.data.data;
- that.last = token.data.count;
- resolve(token.data.count);
- }
+ that.error = false;
+ that.errorMsg = "";
+ that.loading = true;
+ var keyword = that.searchKeyword;
+ var searchCategory = that.searchCategory;
+ var order = that.sortOrder;
+ var sortType = that.sortType;
+
+ return new that._q(function(resolve, reject)
+ {
+ that.http.get(`${that.apiURL}/posts/get-posts?visibility=all&verbose=true&sort=${sortType}&sortOrder=${order}&categories=${searchCategory}&index=${index}&limit=${limit}&keyword=${keyword}`).then(function (token)
+ {
+ if (token.data.error) {
+ that.error = true;
+ that.errorMsg = token.data.message;
+ that.posts = [];
+ resolve(1);
+ }
+ else {
+ that.posts = token.data.data;
+ resolve(token.data.count);
+ }
- that.loading = false;
- });
- });
+ that.loading = false;
+ });
+ });
+ }
+ };
+
+ return remote;
}
/**
diff --git a/admin/lib/directives/pager.ts b/admin/lib/directives/pager.ts
index 723b7f4c..ed1449e1 100644
--- a/admin/lib/directives/pager.ts
+++ b/admin/lib/directives/pager.ts
@@ -3,9 +3,10 @@ module clientAdmin
/**
* Interface for the object you pass as the directive's 'interface' attribute
*/
- export interface IPager
+ export interface IPagerRemote
{
- updatePageContent : (index?: number, limit? : number) => ng.IPromise;
+ update : (index?: number, limit? : number) => ng.IPromise;
+ invalidate?: () => void;
}
@@ -18,7 +19,7 @@ module clientAdmin
transclude = true;
templateUrl = 'templates/directives/pager.html';
scope = {
- interface: '=', // must be IPager
+ interface: '=', // must be IPagerRemote
index: '=?',
limit: '=?',
last: '=?'
@@ -33,7 +34,15 @@ module clientAdmin
scope.index = scope.index || 0;
scope.limit = scope.limit || 10;
scope.last = scope.last || 1;
- var iPager : IPager = scope.interface;
+ var iPager : IPagerRemote = scope.interface;
+
+ /**
+ * Creates the invalidate function which can be used externally to control
+ * when the pager updates its content
+ */
+ iPager.invalidate = function() {
+ handlePromise(iPager.update( scope.index, scope.limit ));
+ }
/**
* Handles the promise returned by the update function
@@ -71,7 +80,7 @@ module clientAdmin
scope.goFirst = function()
{
scope.index = 0;
- handlePromise( iPager.updatePageContent( scope.index, scope.limit) );
+ handlePromise( iPager.update( scope.index, scope.limit) );
}
/**
@@ -80,7 +89,7 @@ module clientAdmin
scope.goLast = function()
{
scope.index = scope.last - (scope.last % scope.limit);
- handlePromise( iPager.updatePageContent( scope.index, scope.limit) );
+ handlePromise( iPager.update( scope.index, scope.limit) );
}
/**
@@ -89,7 +98,7 @@ module clientAdmin
scope.goNext = function()
{
scope.index += scope.limit;
- handlePromise( iPager.updatePageContent( scope.index, scope.limit) );
+ handlePromise( iPager.update( scope.index, scope.limit) );
}
/**
@@ -101,11 +110,11 @@ module clientAdmin
if (scope.index < 0)
scope.index = 0;
- handlePromise( iPager.updatePageContent( scope.index, scope.limit) );
+ handlePromise( iPager.update( scope.index, scope.limit) );
}
// Call the initial update
- handlePromise( iPager.updatePageContent( scope.index, scope.limit) );
+ handlePromise( iPager.update( scope.index, scope.limit) );
}
/**
diff --git a/server/dist/definitions/definitions.d.ts b/server/dist/definitions/definitions.d.ts
index cb1f8ff1..b25546ff 100644
--- a/server/dist/definitions/definitions.d.ts
+++ b/server/dist/definitions/definitions.d.ts
@@ -228,7 +228,7 @@ declare module clientAdmin {
/**
* Controller for the dashboard posts section
*/
- class PostsCtrl extends PagedContentCtrl {
+ class PostsCtrl {
postToken: Modepress.IPost;
posts: Array;
showNewPostForm: boolean;
@@ -251,6 +251,11 @@ declare module clientAdmin {
defaultSlug: string;
targetImgReciever: string;
private _q;
+ private http;
+ private error;
+ private loading;
+ private errorMsg;
+ private pager;
static $inject: string[];
constructor(scope: any, http: ng.IHttpService, apiURL: string, mediaURL: string, categories: Array, $q: ng.IQService);
/**
@@ -287,10 +292,7 @@ declare module clientAdmin {
* Sets the page into edit mode
*/
editPostMode(post: Modepress.IPost): void;
- /**
- * Fetches the posts from the database
- */
- updatePageContent(index?: number, limit?: number): ng.IPromise;
+ createPagerRemote(): IPagerRemote;
/**
* Processes the tags in a post array of keywords
*/
@@ -327,8 +329,9 @@ declare module clientAdmin {
/**
* Interface for the object you pass as the directive's 'interface' attribute
*/
- interface IPager {
- updatePageContent: (index?: number, limit?: number) => ng.IPromise;
+ interface IPagerRemote {
+ update: (index?: number, limit?: number) => ng.IPromise;
+ invalidate?: () => void;
}
/**
* Controller for the dashboard media section