From 1ea256e58b77e6039e02cbac5c5cfb35c27e72de Mon Sep 17 00:00:00 2001 From: shprink Date: Fri, 2 Oct 2015 00:25:36 -0500 Subject: [PATCH] shit storm... #86 #30 #76 --- .gitignore | 1 + CHANGELOG.md | 5 +- CONFIGURATION.md | 244 ++++-------------- config.json.dist => config.default.json | 93 +++++-- config.dev.dist | 8 + config.prod.dist | 8 + install.sh | 4 +- lib/abstract/AbstractItem.js | 50 ++++ lib/abstract/AbstractItemService.js | 32 +++ lib/abstract/AbstractList.js | 5 +- ...tTypeService.js => AbstractListService.js} | 13 +- lib/authors/author.controller.js | 33 +++ lib/authors/author.html | 17 ++ lib/authors/author.service.js | 11 + .../{controller.js => authors.controller.js} | 0 lib/authors/{index.html => authors.html} | 4 +- .../{service.js => authors.service.js} | 2 +- lib/authors/config.js | 25 +- lib/authors/index.js | 12 +- lib/config.coffee | 5 - lib/config.js | 18 ++ lib/directives/author/author.coffee | 7 +- lib/directives/author/author.html | 3 +- lib/directives/authors/index.html | 8 + lib/directives/authors/index.js | 18 ++ lib/directives/directives.module.coffee | 21 -- lib/directives/directives.scss | 2 + lib/directives/index.js | 31 +++ lib/directives/page/index.html | 21 ++ lib/directives/page/index.js | 19 ++ lib/directives/page/index.scss | 14 + lib/directives/pages/index.html | 19 ++ lib/directives/pages/index.js | 38 +++ lib/directives/pages/index.scss | 5 + lib/directives/post/post.html | 2 +- lib/directives/post/style.scss | 2 +- lib/directives/posts/posts.coffee | 4 +- lib/directives/posts/posts.html | 8 +- lib/directives/posts/style.scss | 3 - lib/directives/taxonomies/taxonomies.html | 2 +- lib/filters/index.js | 7 + lib/filters/truncate.js | 14 + lib/index.coffee | 24 +- lib/pages/config.js | 25 +- lib/pages/index.js | 12 +- lib/pages/page.controller.js | 13 + lib/pages/page.html | 8 + lib/pages/page.service.js | 11 + .../{controller.js => pages.controller.js} | 5 +- lib/pages/{index.html => pages.html} | 2 +- lib/pages/{service.js => pages.service.js} | 6 +- lib/posts/controller.js | 5 +- lib/posts/index.html | 2 +- lib/posts/service.js | 6 +- lib/search/controller.js | 4 +- lib/search/service.js | 6 +- lib/taxonomies/category.service.js | 16 ++ lib/taxonomies/config.js | 23 ++ lib/taxonomies/controller.js | 21 ++ lib/taxonomies/index.html | 10 + lib/taxonomies/index.js | 17 ++ .../{taxonomies.modal.html => modal.html} | 0 lib/taxonomies/posts.controller.js | 41 +++ lib/taxonomies/posts.html | 10 + lib/taxonomies/service.js | 32 +++ lib/taxonomies/tag.service.js | 15 ++ lib/taxonomies/taxonomies.config.coffee | 17 -- lib/taxonomies/taxonomies.controller.coffee | 15 -- lib/taxonomies/taxonomies.html | 8 - lib/taxonomies/taxonomies.module.coffee | 6 - .../taxonomies.posts.controller.coffee | 12 - lib/taxonomies/taxonomies.service.coffee | 61 ----- lib/translations/de.json | 8 +- lib/translations/en.json | 4 + lib/translations/es.json | 8 +- lib/translations/fr.json | 10 +- lib/translations/pl.json | 8 +- lib/translations/zh.json | 8 +- package.json | 2 +- webpack.config.js | 3 +- webpack.config.prod.js | 3 +- 81 files changed, 865 insertions(+), 460 deletions(-) rename config.json.dist => config.default.json (73%) create mode 100644 config.dev.dist create mode 100644 config.prod.dist create mode 100644 lib/abstract/AbstractItem.js create mode 100644 lib/abstract/AbstractItemService.js rename lib/abstract/{AbstractTypeService.js => AbstractListService.js} (82%) create mode 100644 lib/authors/author.controller.js create mode 100644 lib/authors/author.html create mode 100644 lib/authors/author.service.js rename lib/authors/{controller.js => authors.controller.js} (100%) rename lib/authors/{index.html => authors.html} (78%) rename lib/authors/{service.js => authors.service.js} (80%) delete mode 100644 lib/config.coffee create mode 100644 lib/config.js create mode 100644 lib/directives/authors/index.html create mode 100644 lib/directives/authors/index.js delete mode 100644 lib/directives/directives.module.coffee create mode 100644 lib/directives/index.js create mode 100644 lib/directives/page/index.html create mode 100644 lib/directives/page/index.js create mode 100644 lib/directives/page/index.scss create mode 100644 lib/directives/pages/index.html create mode 100644 lib/directives/pages/index.js create mode 100644 lib/directives/pages/index.scss create mode 100644 lib/filters/index.js create mode 100644 lib/filters/truncate.js create mode 100644 lib/pages/page.controller.js create mode 100644 lib/pages/page.html create mode 100644 lib/pages/page.service.js rename lib/pages/{controller.js => pages.controller.js} (65%) rename lib/pages/{index.html => pages.html} (86%) rename lib/pages/{service.js => pages.service.js} (58%) create mode 100644 lib/taxonomies/category.service.js create mode 100644 lib/taxonomies/config.js create mode 100644 lib/taxonomies/controller.js create mode 100644 lib/taxonomies/index.html create mode 100644 lib/taxonomies/index.js rename lib/taxonomies/{taxonomies.modal.html => modal.html} (100%) create mode 100644 lib/taxonomies/posts.controller.js create mode 100644 lib/taxonomies/posts.html create mode 100644 lib/taxonomies/service.js create mode 100644 lib/taxonomies/tag.service.js delete mode 100644 lib/taxonomies/taxonomies.config.coffee delete mode 100644 lib/taxonomies/taxonomies.controller.coffee delete mode 100644 lib/taxonomies/taxonomies.html delete mode 100644 lib/taxonomies/taxonomies.module.coffee delete mode 100644 lib/taxonomies/taxonomies.posts.controller.coffee delete mode 100644 lib/taxonomies/taxonomies.service.coffee diff --git a/.gitignore b/.gitignore index ae2c139fc..d7fd6175b 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ platforms_backup/ plugins/ bower_components/ config.json +config.dev.json config.prod.json *.keystore release.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 2152bf27b..f688b38a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,12 @@ * WP-API v2 support * Adding German translation +* Authors list +* Pages list #### Breaking changes: -* [CONFIG] the new `posts.query` objects replaces `posts.per_page`, `posts.order` etc. -* [CONFIG] `posts.posts_per_page` becomes `posts.query.per_page` +* [CONFIG] `config.json` does not exist anymore. The installation creates two files `config.dev.json` and `config.prod.json`. Those two files overwrite `config.default.json` (this on is read only). ### 1.6.0 (2015-09-24) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 54761bab5..934725f26 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -47,6 +47,9 @@ Here is a simple view of what you can configure: * comments * syntaxHighlighter * taxonomies +* search +* pages +* authors * posts * translation * available @@ -70,7 +73,7 @@ Here is a simple view of what you can configure: ### debugEnabled [Boolean] -Make sure this option is TRUE for ```config.json``` and FALSE for ```config.prod.json``` +Make sure this option is TRUE for ```config.dev.json``` and FALSE for ```config.prod.json``` ### title [String] @@ -82,40 +85,6 @@ allow overwriting ionic configuration tags instead of new-line characters in the output, useful when code is marked up using a non-
 container.
 * ***classPrefix***: a string prefix added before class names in the generated markup, used for backwards compatibility with stylesheets.
 * ***languages***: an array of language names and aliases restricting auto detection to only these languages.
-
-```
-"syntaxHighlighter": {
-    "classPrefix": "hljs-",
-    "tabReplace": "    ",
-    "useBR": false,
-    "languages": ["javascript", "html", "coffeescript", "html", "css", "scss", "json", "apache", "bash", "markdown", "less", "php", "apache", "typescript"]
-}
-```
diff --git a/config.json.dist b/config.default.json
similarity index 73%
rename from config.json.dist
rename to config.default.json
index 71baeead3..dcf5dd508 100644
--- a/config.json.dist
+++ b/config.default.json
@@ -4,7 +4,7 @@
         "timeout": 10000,
         "maxAttempt": 3
     },
-    "debugEnabled" : false,
+    "debugEnabled": false,
     "title": "Your Blog title",
     "ionicConfig": {
         "views": {
@@ -40,17 +40,21 @@
         }
     },
     "menu": {
+        "defaultState": {
+            "state": "public.posts",
+            "params": {}
+        },
         "exposeAsideWhen": "(min-width:900px)",
         "list": [{
             "type": "internal",
-            "trans": "menu.home",
+            "trans": "menu.posts",
             "route": "public.posts",
-            "icon": "icon ion-home"
-        },{
+            "icon": "icon ion-ios-paper"
+        }, {
             "type": "internal",
             "trans": "menu.pages",
             "route": "public.pages",
-            "icon": "icon ion-ios-paper"
+            "icon": "icon ion-android-document"
         }, {
             "type": "internal",
             "trans": "menu.authors",
@@ -62,8 +66,8 @@
             "icon": "icon ion-folder",
             "list": [{
                 "type": "internal",
-                "trans": "Mobile",
-                "route": "public.taxonomies.slug({ term: 'category', slug: 'mobile' })",
+                "trans": "Uncategorized",
+                "route": "public.taxonomies.slug({ term: 'category', slug: 'uncategorized' })",
                 "icon": "icon ion-iphone"
             }, {
                 "type": "internal",
@@ -72,11 +76,21 @@
                 "icon": "icon ion-folder"
             }]
         }, {
-            "type": "internal",
+            "type": "folder",
             "trans": "menu.tags",
-            "route": "public.taxonomies({ term: 'post_tag' })",
-            "icon": "icon ion-pricetags"
-        }, {
+            "icon": "icon ion-folder",
+            "list": [{
+                "type": "internal",
+                "trans": "Dumb tag",
+                "route": "public.taxonomies.slug({ term: 'post_tag', slug: 'dumb' })",
+                "icon": "icon ion-iphone"
+            }, {
+                "type": "internal",
+                "trans": "All",
+                "route": "public.taxonomies({ term: 'post_tag' })",
+                "icon": "icon ion-pricetags"
+            }]
+        },{
             "type": "internal",
             "trans": "menu.bookmarks",
             "route": "public.bookmarks",
@@ -125,8 +139,7 @@
             "deleteOnExpire": "aggressive",
             "recycleFreq": 1000,
             "cacheFlushInterval": null,
-            "storageMode": "localStorage",
-            "verifyIntegrity": true
+            "storageMode": "localStorage"
         }
     },
     "bookmark": {
@@ -152,18 +165,54 @@
         "languages": ["javascript", "html", "coffeescript", "html", "css", "scss", "json", "apache", "bash", "markdown", "less", "php", "apache", "typescript"]
     },
     "taxonomies": {
+        "query": {
+            "per_page": 5,
+            "orderby": "count",
+            "order": "desc"
+        },
         "cache": {
             "maxAge": 172800000
         }
     },
+    "authors": {
+        "query": {
+            "per_page": 5
+        },
+        "cache": {
+            "capacity": 10,
+            "maxAge": 86400000
+        }
+    },
     "pages": {
-        "per_page": 6
+        "query": {
+            "per_page": 5,
+            "filter[orderby]": "date",
+            "filter[order]": "desc"
+        },
+        "cache": {
+            "capacity": 10,
+            "maxAge": 86400000
+        }
+    },
+    "search": {
+        "query": {
+            "per_page": 5,
+            "filter[orderby]": "date",
+            "filter[order]": "desc",
+            "filter[post_status]": "publish"
+        },
+        "cache": {
+            "capacity": 25,
+            "maxAge": 86400000
+        }
     },
     "posts": {
-        "per_page": 6,
-        "orderby": "date",
-        "order": "desc",
-        "post_status": "publish",
+        "query": {
+            "per_page": 5,
+            "filter[orderby]": "date",
+            "filter[order]": "desc",
+            "filter[post_status]": "publish"
+        },
         "cache": {
             "capacity": 25,
             "maxAge": 86400000
@@ -200,11 +249,11 @@
     },
     "cordova": {
         "statubar": {
-            "show": true,
+            "show": false,
             "color": "#455a64"
         },
         "appRate": {
-            "enabled": true,
+            "enabled": false,
             "language": "en",
             "appName": "Your Blog title",
             "openStoreInApp": true,
@@ -216,8 +265,8 @@
             "windowsURL": ""
         },
         "pushNotifications": {
-            "enabled": true,
-            "baseUrl" : "http://yourDomain.com/pnfw",
+            "enabled": false,
+            "baseUrl": "http://yourDomain.com/pnfw",
             "android": {
                 "senderID": ""
             },
diff --git a/config.dev.dist b/config.dev.dist
new file mode 100644
index 000000000..9d647c38a
--- /dev/null
+++ b/config.dev.dist
@@ -0,0 +1,8 @@
+{
+    "api": {
+        "baseUrl": "http://yourDomain.com/wp-json",
+        "timeout": 10000
+    },
+    "debugEnabled": true,
+    "title": "[DEV] Your Blog title"
+}
diff --git a/config.prod.dist b/config.prod.dist
new file mode 100644
index 000000000..b8d7ea747
--- /dev/null
+++ b/config.prod.dist
@@ -0,0 +1,8 @@
+{
+    "api": {
+        "baseUrl": "http://yourDomain.com/wp-json",
+        "timeout": 20000
+    },
+    "debugEnabled": false,
+    "title": "[PROD] Your Blog title"
+}
diff --git a/install.sh b/install.sh
index eda3d0780..b401f7b37 100755
--- a/install.sh
+++ b/install.sh
@@ -5,9 +5,9 @@ set -e
 npm install
 
 # Dev App config
-cp config.json.dist config.json
+cp config.dev.dist config.dev.json
 # Prod App config
-cp config.json.dist config.prod.json
+cp config.prod.dist config.prod.json
 # Hybrid config
 cp config.xml.dist config.xml
 # Sass config
diff --git a/lib/abstract/AbstractItem.js b/lib/abstract/AbstractItem.js
new file mode 100644
index 000000000..f640bc880
--- /dev/null
+++ b/lib/abstract/AbstractItem.js
@@ -0,0 +1,50 @@
+export default class {
+    constructor($WPHCConfig, $q, $scope, $stateParams) {
+        'ngInject';
+
+        this.type = null;
+        this.title = null;
+        this.item = null;
+        this.service = null;
+        this.config = $WPHCConfig;
+        this.$stateParams = $stateParams;
+        this.$q = $q;
+        this.$scope = $scope;
+    }
+
+    init() {
+        this.page = 1;
+        return this.doLoadMore();
+    }
+
+    refresh() {
+        this.init();
+        this.item = null;
+        this.doLoadMore().finally(() => this.$scope.$broadcast('scroll.refreshComplete'));
+    }
+
+    doLoadMore() {
+        var self = this;
+        return this.service.get(this.$stateParams.id, angular.merge(this.getQuery(), _.get(this.config, `[${this.type}].query`) || {})).then((response) => {
+            self.item = response.data;
+        });
+    }
+
+    getQuery() {
+        return {
+            "_embed": true
+        }
+    }
+
+    setType(type = null) {
+        this.type = type;
+    }
+
+    setService(service = null) {
+        this.service = service;
+    }
+
+    setTitle(title = null) {
+        this.title = title;
+    }
+}
diff --git a/lib/abstract/AbstractItemService.js b/lib/abstract/AbstractItemService.js
new file mode 100644
index 000000000..8235da2f0
--- /dev/null
+++ b/lib/abstract/AbstractItemService.js
@@ -0,0 +1,32 @@
+import md5 from 'MD5';
+import AbstractList from '../abstract/AbstractListService.js';
+
+export default class extends AbstractList {
+    constructor($WPHCConfig, $q, CacheFactory, $log, $stateParams) {
+        'ngInject';
+
+        super($WPHCConfig, $q, CacheFactory, $log, $stateParams);
+    }
+
+    getHttpPromise(id) {
+        return this.service.get(id);
+    }
+
+    get(id) {
+        let deferred = this.$q.defer();
+        let hash = md5(this.$WPHCConfig.api.baseUrl + id);
+        let itemCache = this.getCache().get('item-' + hash);
+        if (itemCache) {
+            deferred.resolve(itemCache);
+        } else {
+            this.getHttpPromise(id).then((response) => {
+                    this.getCache().put('item-' + hash, response);
+                    deferred.resolve(response);
+                })
+                .catch((response) => {
+                    deferred.reject(error);
+                });
+        }
+        return deferred.promise;
+    }
+}
diff --git a/lib/abstract/AbstractList.js b/lib/abstract/AbstractList.js
index f5a2a3a27..1204aa89c 100644
--- a/lib/abstract/AbstractList.js
+++ b/lib/abstract/AbstractList.js
@@ -1,5 +1,5 @@
 export default class {
-    constructor($WPHCConfig, $q, $scope) {
+    constructor($WPHCConfig, $q, $scope, $stateParams) {
         'ngInject';
 
         this.type = null;
@@ -9,6 +9,7 @@ export default class {
         this.isLoadingMore = false;
         this.isPaginationOver = false;
         this.config = $WPHCConfig;
+        this.$stateParams = $stateParams;
         this.$q = $q;
         this.page = 1;
         this.$scope = $scope;
@@ -34,7 +35,7 @@ export default class {
             return this.$q.when(null);
         }
         this.isLoadingMore = true;
-        return this.service.getList(angular.merge(this.getQuery(), _.get(this.config, `[${this.type}].query`) || {})).then((response) => {
+        return this.service.get(angular.merge(this.getQuery(), _.get(this.config, `[${this.type}].query`) || {})).then((response) => {
             self.page++;
             self.list = (self.list) ? self.list.concat(response.data) : response.data;
             self.isPaginationOver = (response.data.length === 0 || response.data.length < _.get(this.config, `${this.type}.query.per_page`));
diff --git a/lib/abstract/AbstractTypeService.js b/lib/abstract/AbstractListService.js
similarity index 82%
rename from lib/abstract/AbstractTypeService.js
rename to lib/abstract/AbstractListService.js
index 0a3009cde..998755dd6 100644
--- a/lib/abstract/AbstractTypeService.js
+++ b/lib/abstract/AbstractListService.js
@@ -1,13 +1,14 @@
 import md5 from 'MD5';
 
 export default class {
-    constructor($WPHCConfig, $q, CacheFactory, $log) {
+    constructor($WPHCConfig, $q, CacheFactory, $log, $stateParams) {
         'ngInject';
 
         this.$WPHCConfig = $WPHCConfig;
         this.CacheFactory = CacheFactory;
         this.$log = $log;
         this.$q = $q;
+        this.$stateParams = $stateParams;
         this.type = null;
         this.service = null;
     }
@@ -32,17 +33,19 @@ export default class {
         this.CacheFactory.destroy(this.type);
     }
 
-    getList(query) {
+    getHttpPromise(query) {
+        return this.service.getList(query);
+    }
+
+    get(query) {
         let queryString = JSON.stringify(query);
         let deferred = this.$q.defer();
         let hash = md5(this.$WPHCConfig.api.baseUrl + queryString);
         let listCache = this.getCache().get('list-' + hash);
-        this.$log.debug(`${this.type} cache`, listCache);
         if (listCache) {
             deferred.resolve(listCache);
         } else {
-            this.service.getList(query)
-                .then((response) => {
+            this.getHttpPromise(query).then((response) => {
                     this.getCache().put('list-' + hash, response);
                     deferred.resolve(response);
                 })
diff --git a/lib/authors/author.controller.js b/lib/authors/author.controller.js
new file mode 100644
index 000000000..316998503
--- /dev/null
+++ b/lib/authors/author.controller.js
@@ -0,0 +1,33 @@
+import AbstractList from '../abstract/AbstractList.js';
+
+export default class extends AbstractList {
+
+    constructor($WPHCPosts, $WPHCConfig, $q, $scope, $filter, $stateParams, $WPHCAuthor) {
+        'ngInject';
+
+        super($WPHCConfig, $q, $scope, $stateParams);
+        this.setType('authorPosts');
+        this.setService($WPHCPosts);
+        this.$filter = $filter;
+        this.author = undefined;
+        this.$WPHCAuthor = $WPHCAuthor;
+        this.getAuthor();
+        // this.setTitle(this.getTitle($stateParams.term, $stateParams.slug));
+    }
+
+    getAuthor() {
+        var self = this;
+        this.$WPHCAuthor.get(this.$stateParams.id).then((response) => {
+            self.author = response.data;
+            self.setTitle(this.$filter('translate')('author.title', {
+                name: response.data.name
+            }));
+        });
+    }
+
+    getQuery() {
+        var query = super.getQuery();
+        query["filter[author]"] = this.$stateParams.id
+        return query;
+    }
+}
diff --git a/lib/authors/author.html b/lib/authors/author.html
new file mode 100644
index 000000000..56cbdf114
--- /dev/null
+++ b/lib/authors/author.html
@@ -0,0 +1,17 @@
+
+    {{ postsCtrl.title | translate}}
+    
+        
+        
+        
+        
+
+ +

+ +
+
+ + test +
+
diff --git a/lib/authors/author.service.js b/lib/authors/author.service.js new file mode 100644 index 000000000..47e77aca0 --- /dev/null +++ b/lib/authors/author.service.js @@ -0,0 +1,11 @@ +import AbstractItemService from '../abstract/AbstractItemService.js'; + +export default class extends AbstractItemService { + constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiUsers) { + 'ngInject'; + + super($WPHCConfig, $q, CacheFactory, $log); + this.setType('author'); + this.setService($wpApiUsers); + } +} diff --git a/lib/authors/controller.js b/lib/authors/authors.controller.js similarity index 100% rename from lib/authors/controller.js rename to lib/authors/authors.controller.js diff --git a/lib/authors/index.html b/lib/authors/authors.html similarity index 78% rename from lib/authors/index.html rename to lib/authors/authors.html index b3c8b6ed4..c5efc2cdf 100644 --- a/lib/authors/index.html +++ b/lib/authors/authors.html @@ -1,10 +1,10 @@ {{ authorsCtrl.title | translate}} - + - + test diff --git a/lib/authors/service.js b/lib/authors/authors.service.js similarity index 80% rename from lib/authors/service.js rename to lib/authors/authors.service.js index e6c448ee1..bbfac350b 100644 --- a/lib/authors/service.js +++ b/lib/authors/authors.service.js @@ -1,4 +1,4 @@ -import AbstractList from '../abstract/AbstractTypeService.js'; +import AbstractList from '../abstract/AbstractListService.js'; export default class extends AbstractList { constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiUsers) { diff --git a/lib/authors/config.js b/lib/authors/config.js index 3f9c67c71..5f143bd4f 100644 --- a/lib/authors/config.js +++ b/lib/authors/config.js @@ -1,13 +1,22 @@ export default function($stateProvider) { 'ngInject'; - $stateProvider.state('public.authors', { - url: "/authors", - views: { - 'content': { - template: require("./index.html"), - controller: "WPHCAuthorsController as authorsCtrl" + $stateProvider + .state('public.authors', { + url: "/authors", + views: { + 'content': { + template: require("./authors.html"), + controller: "WPHCAuthorsController as authorsCtrl" + } } - } - }); + }).state('public.authors.id', { + url: "/:id", + views: { + 'content@public': { + template: require("./author.html"), + controller: "WPHCAuthorController as postsCtrl" + } + } + }); } diff --git a/lib/authors/index.js b/lib/authors/index.js index e2dc95042..2e3e7b0d0 100644 --- a/lib/authors/index.js +++ b/lib/authors/index.js @@ -1,11 +1,15 @@ import modConfig from './config.js'; -import modController from './controller.js'; -import modService from './service.js'; +import modAuthorController from './author.controller.js'; +import modAuthorsController from './authors.controller.js'; +import modAuthorService from './author.service.js'; +import modAuthorsService from './authors.service.js'; let mod = angular.module('wordpress-hybrid-client.authors', []); mod.config(modConfig); -mod.controller('WPHCAuthorsController', modController); -mod.service('$WPHCAuthors', modService); +mod.controller('WPHCAuthorController', modAuthorController); +mod.controller('WPHCAuthorsController', modAuthorsController); +mod.service('$WPHCAuthor', modAuthorService); +mod.service('$WPHCAuthors', modAuthorsService); export default mod = mod.name; diff --git a/lib/config.coffee b/lib/config.coffee deleted file mode 100644 index 0bb17e549..000000000 --- a/lib/config.coffee +++ /dev/null @@ -1,5 +0,0 @@ -config = if IS_PROD then require "../config.prod" else require "../config" - -module.exports = app = angular.module 'wordpress-hybrid-client.config', [] - -app.constant '$WPHCConfig', angular.extend config, WPHC.config || {} diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 000000000..8f6c6bb51 --- /dev/null +++ b/lib/config.js @@ -0,0 +1,18 @@ +import defaultConfig from '../config.default.json'; +import devConfig from '../config.dev.json'; +import prodConfig from '../config.prod.json'; +import deepExtend from 'deep-extend'; + +let config = {}; + +if (IS_PROD) { + config = deepExtend(defaultConfig, prodConfig, _.get(window, 'WPHC.config')); +} else { + config = deepExtend(defaultConfig, devConfig, _.get(window, 'WPHC.config')); +} + +let mod = angular.module('wordpress-hybrid-client.config', []); + +mod.constant('$WPHCConfig', config); + +export default mod; diff --git a/lib/directives/author/author.coffee b/lib/directives/author/author.coffee index d1d85c7f8..0dd558cc2 100644 --- a/lib/directives/author/author.coffee +++ b/lib/directives/author/author.coffee @@ -8,6 +8,11 @@ module.exports = angular.module('wordpress-hybrid-client.directives').directive template: require './author.html' bindToController: true controllerAs: 'authorCtrl' - controller: ($log, $scope, $element) -> + controller: ($log, $scope, $element, $attrs, $state) -> vm = @ + vm.addLink = typeof $attrs.addLink isnt 'undefined'; + vm.onClick = () -> + if vm.addLink + $state.go 'public.authors.id', + id: vm.author.id return @ diff --git a/lib/directives/author/author.html b/lib/directives/author/author.html index e36ddc3b4..ce6ea82a9 100644 --- a/lib/directives/author/author.html +++ b/lib/directives/author/author.html @@ -1,5 +1,6 @@ -
+

{{::authorCtrl.author.name}}

{{authorCtrl.date | amDateFormat:'LL'}} +
diff --git a/lib/directives/authors/index.html b/lib/directives/authors/index.html new file mode 100644 index 000000000..a24a7590b --- /dev/null +++ b/lib/directives/authors/index.html @@ -0,0 +1,8 @@ + diff --git a/lib/directives/authors/index.js b/lib/directives/authors/index.js new file mode 100644 index 000000000..5bedabcd1 --- /dev/null +++ b/lib/directives/authors/index.js @@ -0,0 +1,18 @@ +export default function() { + return { + bindToController: true, + replace: false, + controller: Controller, + controllerAs: 'authorsCtrl', + restrict: 'E', + scope: { + authors: '=' + }, + template: require('./index.html') + }; + + function Controller($log, $scope) { + 'ngInject'; + var vm = this; + } +} diff --git a/lib/directives/directives.module.coffee b/lib/directives/directives.module.coffee deleted file mode 100644 index dc1a9f973..000000000 --- a/lib/directives/directives.module.coffee +++ /dev/null @@ -1,21 +0,0 @@ -require "angular-recursion" -module.exports = angular.module 'wordpress-hybrid-client.directives', [ - "RecursionHelper", - 'vAccordion' -] - -require "./bindAndCompileHtml/bindAndCompileHtml.coffee" -require "./postToolbar/postToolbar.coffee" -require "./taxonomies/taxonomies.coffee" -require "./emptyList/emptyList.coffee" -require "./inputEsc/inputEsc.coffee" -require "./hideWhen/hideWhen.coffee" -require "./showWhen/showWhen.coffee" -require "./comments/comments.coffee" -require "./comment/comment.coffee" -require "./author/author.coffee" -require "./loader/loader.coffee" -require "./posts/posts.coffee" -require "./post/post.coffee" -require "./menu/menu.coffee" -require "./href/href.coffee" diff --git a/lib/directives/directives.scss b/lib/directives/directives.scss index 652a494fc..4854a051c 100644 --- a/lib/directives/directives.scss +++ b/lib/directives/directives.scss @@ -1,3 +1,5 @@ +@import './page/index.scss'; +@import './pages/index.scss'; @import './posts/style.scss'; @import './post/style.scss'; @import './postToolbar/style.scss'; diff --git a/lib/directives/index.js b/lib/directives/index.js new file mode 100644 index 000000000..869f9d0d8 --- /dev/null +++ b/lib/directives/index.js @@ -0,0 +1,31 @@ +import 'angular-recursion'; +import page from './page/index.js'; +import pages from './pages/index.js'; +import authors from './authors/index.js'; + +let mod = angular.module('wordpress-hybrid-client.directives', [ + 'RecursionHelper', + 'vAccordion' +]); + +require("./bindAndCompileHtml/bindAndCompileHtml.coffee"); +require("./postToolbar/postToolbar.coffee"); +require("./taxonomies/taxonomies.coffee"); +require("./emptyList/emptyList.coffee"); +require("./inputEsc/inputEsc.coffee"); +require("./hideWhen/hideWhen.coffee"); +require("./showWhen/showWhen.coffee"); +require("./comments/comments.coffee"); +require("./comment/comment.coffee"); +require("./author/author.coffee"); +require("./loader/loader.coffee"); +require("./posts/posts.coffee"); +require("./post/post.coffee"); +require("./menu/menu.coffee"); +require("./href/href.coffee"); + +mod.directive('wphcPage', page); +mod.directive('wphcPages', pages); +mod.directive('wphcAuthors', authors); + +export default mod = mod.name; diff --git a/lib/directives/page/index.html b/lib/directives/page/index.html new file mode 100644 index 000000000..9ce97470f --- /dev/null +++ b/lib/directives/page/index.html @@ -0,0 +1,21 @@ +
+
+
+

+
+

+ + +
+ + + +
diff --git a/lib/directives/page/index.js b/lib/directives/page/index.js new file mode 100644 index 000000000..d33967525 --- /dev/null +++ b/lib/directives/page/index.js @@ -0,0 +1,19 @@ +export default function() { + return { + bindToController: true, + replace: false, + controller: Controller, + controllerAs: 'pageCtrl', + restrict: 'E', + scope: { + page: '=' + }, + template: require('./index.html') + }; + + function Controller($log, $scope, $WPHCPost) { + 'ngInject'; + + var vm = this; + } +} diff --git a/lib/directives/page/index.scss b/lib/directives/page/index.scss new file mode 100644 index 000000000..6b5bbb06a --- /dev/null +++ b/lib/directives/page/index.scss @@ -0,0 +1,14 @@ +wphc-page { + .item-author { + background: none; + border-bottom: 1px solid $item-light-border; + margin-bottom: 20px; + margin-top: -10px; + } + + .item-title-without-image { + line-height: 35px; + margin-top: 10px; + } + @include post-item("../img/post-img-border.png"); +} diff --git a/lib/directives/pages/index.html b/lib/directives/pages/index.html new file mode 100644 index 000000000..57be53a63 --- /dev/null +++ b/lib/directives/pages/index.html @@ -0,0 +1,19 @@ +
+
+
+
+
+

+
+ + {{'posts.featured' | translate}} +
+
+
+

+
+ +
+
+
+
diff --git a/lib/directives/pages/index.js b/lib/directives/pages/index.js new file mode 100644 index 000000000..a62cbd166 --- /dev/null +++ b/lib/directives/pages/index.js @@ -0,0 +1,38 @@ +export default function() { + return { + bindToController: true, + replace: false, + controller: Controller, + controllerAs: 'pagesCtrl', + restrict: 'E', + scope: { + pages: '=' + }, + template: require('./index.html') + }; + + function Controller($log, $scope, $WPHCPost) { + 'ngInject'; + + var vm = this; + vm.featureImages = []; + + $scope.$watchCollection('pagesCtrl.pages', function(newValue, oldValue) { + if (!newValue) { + return; + } + _.each(newValue, function(page) { + if (vm.featureImages[page.id]) { + return; + } + $WPHCPost.getFeatureImage(page.featured_image).then(function(image) { + if (!image) { + return; + } + return vm.featureImages[page.id] = image.media_details.sizes.medium.source_url; + }); + }); + }); + + } +} diff --git a/lib/directives/pages/index.scss b/lib/directives/pages/index.scss new file mode 100644 index 000000000..f550829bd --- /dev/null +++ b/lib/directives/pages/index.scss @@ -0,0 +1,5 @@ +wphc-pages { + .card { + @include post-item("../img/post-img-border.png"); + } +} diff --git a/lib/directives/post/post.html b/lib/directives/post/post.html index 45f7d5334..0eb040a43 100644 --- a/lib/directives/post/post.html +++ b/lib/directives/post/post.html @@ -7,7 +7,7 @@

- +
diff --git a/lib/directives/post/style.scss b/lib/directives/post/style.scss index fec7d274a..dc2665a54 100644 --- a/lib/directives/post/style.scss +++ b/lib/directives/post/style.scss @@ -1,4 +1,4 @@ -.post { +wphc-post { .item-author { background: none; border-bottom: 1px solid $item-light-border; diff --git a/lib/directives/posts/posts.coffee b/lib/directives/posts/posts.coffee index 41fdeac2b..18aa89b90 100644 --- a/lib/directives/posts/posts.coffee +++ b/lib/directives/posts/posts.coffee @@ -11,14 +11,14 @@ module.exports = angular.module('wordpress-hybrid-client.directives').directive restrict: 'E' transclude: true scope: - posts: "=", - showToolbar: "=" + posts: "=" template: require './posts.html' bindToController: true controllerAs: 'postCtrl' controller: ($log, $scope, $WPHCPost, $attrs) -> vm = @ vm.featureImages = [] + vm.showAuthor = typeof $attrs.showAuthor isnt 'undefined'; $scope.$watchCollection 'postCtrl.posts', (newValue, oldValue) -> return if !newValue diff --git a/lib/directives/posts/posts.html b/lib/directives/posts/posts.html index 2f4d30d47..6641846b5 100644 --- a/lib/directives/posts/posts.html +++ b/lib/directives/posts/posts.html @@ -3,7 +3,7 @@
-

+

{{'posts.featured' | translate}} @@ -11,16 +11,16 @@

-

+

{{'posts.featured' | translate}}
- +
- diff --git a/lib/directives/posts/style.scss b/lib/directives/posts/style.scss index 631143650..bd50fd728 100644 --- a/lib/directives/posts/style.scss +++ b/lib/directives/posts/style.scss @@ -1,8 +1,5 @@ wphc-posts { .card { - margin: 0 0 20px; - cursor: pointer; - box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12); @include post-item("../img/post-img-border.png"); } .sticky-post{ diff --git a/lib/directives/taxonomies/taxonomies.html b/lib/directives/taxonomies/taxonomies.html index a610f1981..5b0b1a427 100644 --- a/lib/directives/taxonomies/taxonomies.html +++ b/lib/directives/taxonomies/taxonomies.html @@ -1,5 +1,5 @@
-

diff --git a/lib/filters/index.js b/lib/filters/index.js new file mode 100644 index 000000000..0eec4f418 --- /dev/null +++ b/lib/filters/index.js @@ -0,0 +1,7 @@ +import truncate from './truncate.js'; + +let mod = angular.module('wordpress-hybrid-client.filters', []); + +mod.filter('truncate', truncate); + +export default mod = mod.name; diff --git a/lib/filters/truncate.js b/lib/filters/truncate.js new file mode 100644 index 000000000..91771ad14 --- /dev/null +++ b/lib/filters/truncate.js @@ -0,0 +1,14 @@ +// https://github.com/a8m/angular-filter/blob/master/src/_filter/string/truncate.js + +export default function() { + return function(input, length, suffix, preserve) { + + length = _.isUndefined(length) ? input.length : length; + preserve = preserve || false; + suffix = suffix || ''; + + if (!_.isString(input) || (input.length <= length)) return input; + + return input.substring(0, (preserve) ? ((input.indexOf(' ', length) === -1) ? input.length : input.indexOf(' ', length)) : length) + suffix; + }; +} diff --git a/lib/index.coffee b/lib/index.coffee index 59b3a81e6..5fbc5ddd8 100644 --- a/lib/index.coffee +++ b/lib/index.coffee @@ -6,15 +6,18 @@ require './angular-ios9-uiwebview.patch.js' require 'angular-translate' require 'angular-cache' require 'angular-moment' -require 'angular-filter' require 'moment' require './font/font.coffee' require 'expose?_!lodash' require 'wp-api-angularjs' +require './config.js' pagesModule = require './pages/index.js' postsModule = require './posts/index.js' searchModule = require './search/index.js' authorsModule = require './authors/index.js' +taxonomiesModule = require './taxonomies/index.js' +filtersModule = require './filters/index.js' +directivesModule = require './directives/index.js' # Style entry point require './scss/bootstrap' @@ -22,20 +25,20 @@ require './scss/bootstrap' module.exports = app = angular.module 'wordpress-hybrid-client', [ 'ionic' 'ngIOS9UIWebViewPatch' - require('./config').name + 'wordpress-hybrid-client.config' 'ui.router' 'wp-api-angularjs' 'pascalprecht.translate' 'angular-cache' 'angularMoment' - 'angular.filter' + filtersModule pagesModule - require('./taxonomies/taxonomies.module').name - require('./bookmark/bookmark.module').name - require('./post/post.module').name + taxonomiesModule postsModule searchModule authorsModule + require('./bookmark/bookmark.module').name + require('./post/post.module').name require('./menu/menu.module').name require('./cordova/cordova.module').name require('./params/params.module').name @@ -45,10 +48,10 @@ module.exports = app = angular.module 'wordpress-hybrid-client', [ require('./cacheImg/cacheImg.module').name require('./syntaxHighlighter/syntaxHighlighter.module').name require('./init/init.module').name - require('./directives/directives.module').name + directivesModule ] -app.config ($stateProvider) -> +app.config ($stateProvider, $urlRouterProvider) -> $stateProvider .state 'public', url: "/public" @@ -58,6 +61,11 @@ app.config ($stateProvider) -> template: require "./views/ion-menu.html" controller: "WPHCMainController as main" + $urlRouterProvider.otherwise ($injector, $location) -> + $WPHCConfig = $injector.get('$WPHCConfig'); + $state = $injector.get('$state'); + $state.go _.get($WPHCConfig, 'menu.defaultState.state'), _.get($WPHCConfig, 'menu.defaultState.params') + ### ANGULAR CONF ### diff --git a/lib/pages/config.js b/lib/pages/config.js index 09caf4e91..0636ab8f3 100644 --- a/lib/pages/config.js +++ b/lib/pages/config.js @@ -1,13 +1,22 @@ export default function($stateProvider) { 'ngInject'; - $stateProvider.state('public.pages', { - url: "/pages", - views: { - 'content': { - template: require("./index.html"), - controller: "WPHCPagesController as pagesCtrl" + $stateProvider + .state('public.pages', { + url: "/pages", + views: { + 'content': { + template: require("./pages.html"), + controller: "WPHCPagesController as pagesCtrl" + } } - } - }); + }).state('public.pages.id', { + url: "/:id", + views: { + 'content@public': { + template: require("./page.html"), + controller: "WPHCPageController as pageCtrl" + } + } + }); } diff --git a/lib/pages/index.js b/lib/pages/index.js index dc9944b2f..eae50e5c0 100644 --- a/lib/pages/index.js +++ b/lib/pages/index.js @@ -1,11 +1,15 @@ import modConfig from './config.js'; -import modController from './controller.js'; -import modService from './service.js'; +import modPageController from './page.controller.js'; +import modPagesController from './pages.controller.js'; +import modPageService from './page.service.js'; +import modPagesService from './pages.service.js'; let mod = angular.module('wordpress-hybrid-client.pages', []); mod.config(modConfig); -mod.controller('WPHCPagesController', modController); -mod.service('$WPHCPages', modService); +mod.controller('WPHCPageController', modPageController); +mod.controller('WPHCPagesController', modPagesController); +mod.service('$WPHCPage', modPageService); +mod.service('$WPHCPages', modPagesService); export default mod = mod.name; diff --git a/lib/pages/page.controller.js b/lib/pages/page.controller.js new file mode 100644 index 000000000..73478c2c0 --- /dev/null +++ b/lib/pages/page.controller.js @@ -0,0 +1,13 @@ +import AbstractItem from '../abstract/AbstractItem.js'; + +export default class extends AbstractItem { + + constructor($WPHCPage, $WPHCConfig, $q, $scope, $filter, $stateParams) { + 'ngInject'; + + super($WPHCConfig, $q, $scope, $stateParams); + this.setType('page'); + // this.setTitle($filter('translate')('pages.title')); + this.setService($WPHCPage); + } +} diff --git a/lib/pages/page.html b/lib/pages/page.html new file mode 100644 index 000000000..5e3ea3de4 --- /dev/null +++ b/lib/pages/page.html @@ -0,0 +1,8 @@ + + {{ pageCtrl.title | translate}} + + + + + + diff --git a/lib/pages/page.service.js b/lib/pages/page.service.js new file mode 100644 index 000000000..7a63de416 --- /dev/null +++ b/lib/pages/page.service.js @@ -0,0 +1,11 @@ +import AbstractItemService from '../abstract/AbstractItemService.js'; + +export default class extends AbstractItemService { + constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiPages, $stateParams) { + 'ngInject'; + + super($WPHCConfig, $q, CacheFactory, $log, $stateParams); + this.setType('page'); + this.setService($wpApiPages); + } +} diff --git a/lib/pages/controller.js b/lib/pages/pages.controller.js similarity index 65% rename from lib/pages/controller.js rename to lib/pages/pages.controller.js index 48bbe76d2..b01e507de 100644 --- a/lib/pages/controller.js +++ b/lib/pages/pages.controller.js @@ -2,11 +2,10 @@ import AbstractList from '../abstract/AbstractList.js'; export default class extends AbstractList { - constructor($WPHCPages, $WPHCConfig, $q, $scope, $filter) { + constructor($WPHCPages, $WPHCConfig, $q, $scope, $filter, $stateParams) { 'ngInject'; - super($WPHCConfig, $q, $scope); - this.showToolbar = false; + super($WPHCConfig, $q, $scope, $stateParams); this.setType('pages'); this.setTitle($filter('translate')('pages.title')); this.setService($WPHCPages); diff --git a/lib/pages/index.html b/lib/pages/pages.html similarity index 86% rename from lib/pages/index.html rename to lib/pages/pages.html index ed9bb2e5a..ae5b5be2d 100644 --- a/lib/pages/index.html +++ b/lib/pages/pages.html @@ -4,7 +4,7 @@ - + test diff --git a/lib/pages/service.js b/lib/pages/pages.service.js similarity index 58% rename from lib/pages/service.js rename to lib/pages/pages.service.js index 9a6eddf90..99b92d88a 100644 --- a/lib/pages/service.js +++ b/lib/pages/pages.service.js @@ -1,10 +1,10 @@ -import AbstractList from '../abstract/AbstractTypeService.js'; +import AbstractList from '../abstract/AbstractListService.js'; export default class extends AbstractList { - constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiPages) { + constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiPages, $stateParams) { 'ngInject'; - super($WPHCConfig, $q, CacheFactory, $log); + super($WPHCConfig, $q, CacheFactory, $log, $stateParams); this.setType('pages'); this.setService($wpApiPages); } diff --git a/lib/posts/controller.js b/lib/posts/controller.js index 6bacbb1d8..9fa1c2f62 100644 --- a/lib/posts/controller.js +++ b/lib/posts/controller.js @@ -2,11 +2,10 @@ import AbstractList from '../abstract/AbstractList.js'; export default class extends AbstractList { - constructor($WPHCPosts, $WPHCConfig, $q, $scope, $filter) { + constructor($WPHCPosts, $WPHCConfig, $q, $scope, $filter, $stateParams) { 'ngInject'; - super($WPHCConfig, $q, $scope); - this.showToolbar = true; + super($WPHCConfig, $q, $scope, $stateParams); this.setType('posts'); this.setTitle($filter('translate')('posts.title')); this.setService($WPHCPosts); diff --git a/lib/posts/index.html b/lib/posts/index.html index 6edc68821..c4fc1b421 100644 --- a/lib/posts/index.html +++ b/lib/posts/index.html @@ -4,7 +4,7 @@ - + test diff --git a/lib/posts/service.js b/lib/posts/service.js index 32f1ea347..eaf8fd8d5 100644 --- a/lib/posts/service.js +++ b/lib/posts/service.js @@ -1,10 +1,10 @@ -import AbstractList from '../abstract/AbstractTypeService.js'; +import AbstractList from '../abstract/AbstractListService.js'; export default class extends AbstractList { - constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiPosts) { + constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiPosts, $stateParams) { 'ngInject'; - super($WPHCConfig, $q, CacheFactory, $log); + super($WPHCConfig, $q, CacheFactory, $log, $stateParams); this.setType('posts'); this.setService($wpApiPosts); } diff --git a/lib/search/controller.js b/lib/search/controller.js index cc1b5504b..b077048e7 100644 --- a/lib/search/controller.js +++ b/lib/search/controller.js @@ -2,10 +2,10 @@ import AbstractList from '../abstract/AbstractList.js'; export default class extends AbstractList { - constructor($WPHCSearch, $WPHCConfig, $q, $scope, $filter) { + constructor($WPHCSearch, $WPHCConfig, $q, $scope, $filter, $stateParams) { 'ngInject'; - super($WPHCConfig, $q, $scope); + super($WPHCConfig, $q, $scope, $stateParams); this.searchQuery = ''; this.showToolbar = true; this.setType('search'); diff --git a/lib/search/service.js b/lib/search/service.js index 737e03e4d..ff4366403 100644 --- a/lib/search/service.js +++ b/lib/search/service.js @@ -1,10 +1,10 @@ -import AbstractList from '../abstract/AbstractTypeService.js'; +import AbstractList from '../abstract/AbstractListService.js'; export default class extends AbstractList { - constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiPosts) { + constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiPosts, $stateParams) { 'ngInject'; - super($WPHCConfig, $q, CacheFactory, $log); + super($WPHCConfig, $q, CacheFactory, $log, $stateParams); this.setType('search'); this.setService($wpApiPosts); } diff --git a/lib/taxonomies/category.service.js b/lib/taxonomies/category.service.js new file mode 100644 index 000000000..6d43b275f --- /dev/null +++ b/lib/taxonomies/category.service.js @@ -0,0 +1,16 @@ +import AbstractList from '../abstract/AbstractListService.js'; + +export default class extends AbstractList { + constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiTerms, $stateParams) { + 'ngInject'; + + + super($WPHCConfig, $q, CacheFactory, $log, $stateParams); + this.setType('category'); + this.setService($wpApiTerms); + } + + getHttpPromise(query) { + return this.service.getCategoryList(query); + } +} diff --git a/lib/taxonomies/config.js b/lib/taxonomies/config.js new file mode 100644 index 000000000..e4ed21ea3 --- /dev/null +++ b/lib/taxonomies/config.js @@ -0,0 +1,23 @@ +export default function($stateProvider) { + 'ngInject'; + + $stateProvider + .state('public.taxonomies', { + url: "/taxonomies/:term", + views: { + 'content': { + template: require("./index.html"), + controller: "WPHCTaxonomiesController as taxonomiesCtrl" + } + } + }) + .state('public.taxonomies.slug', { + url: "/:slug", + views: { + 'content@public': { + template: require("../posts/index.html"), + controller: "WPHCTaxonomiesPostsController as postsCtrl" + } + } + }); +} diff --git a/lib/taxonomies/controller.js b/lib/taxonomies/controller.js new file mode 100644 index 000000000..09d730a04 --- /dev/null +++ b/lib/taxonomies/controller.js @@ -0,0 +1,21 @@ +import AbstractList from '../abstract/AbstractList.js'; + +export default class extends AbstractList { + + constructor($WPHCTaxonomiesCategory, $WPHCTaxonomiesTag, $WPHCConfig, $q, $scope, $filter, $stateParams) { + 'ngInject'; + + super($WPHCConfig, $q, $scope, $stateParams); + console.log('WPHCTaxonomiesController') + this.showToolbar = true; + this.setType('taxonomies'); + if ($stateParams.term === 'category') { + this.setTitle($filter('translate')('categories.title')); + this.setService($WPHCTaxonomiesCategory); + } else if ($stateParams.term === 'post_tag') { + this.setTitle($filter('translate')('tags.title')); + this.setService($WPHCTaxonomiesTag); + } + this.term = $stateParams.term; + } +} diff --git a/lib/taxonomies/index.html b/lib/taxonomies/index.html new file mode 100644 index 000000000..625cec3c7 --- /dev/null +++ b/lib/taxonomies/index.html @@ -0,0 +1,10 @@ + + {{ taxonomiesCtrl.title | translate}} + + + + + + test + + diff --git a/lib/taxonomies/index.js b/lib/taxonomies/index.js new file mode 100644 index 000000000..106aa0cf7 --- /dev/null +++ b/lib/taxonomies/index.js @@ -0,0 +1,17 @@ +import modConfig from './config.js'; +import modController from './controller.js'; +import modPostsController from './posts.controller.js'; +import modService from './service.js'; +import modTagService from './tag.service.js'; +import modCategoryService from './category.service.js'; + +let mod = angular.module('wordpress-hybrid-client.taxonomies', []); + +mod.config(modConfig); +mod.controller('WPHCTaxonomiesController', modController); +mod.controller('WPHCTaxonomiesPostsController', modPostsController); +mod.service('$WPHCTaxonomiesCategory', modCategoryService); +mod.service('$WPHCTaxonomiesTag', modTagService); +mod.service('$WPHCTaxonomies', modService); + +export default mod = mod.name; diff --git a/lib/taxonomies/taxonomies.modal.html b/lib/taxonomies/modal.html similarity index 100% rename from lib/taxonomies/taxonomies.modal.html rename to lib/taxonomies/modal.html diff --git a/lib/taxonomies/posts.controller.js b/lib/taxonomies/posts.controller.js new file mode 100644 index 000000000..2916827b1 --- /dev/null +++ b/lib/taxonomies/posts.controller.js @@ -0,0 +1,41 @@ +import AbstractList from '../abstract/AbstractList.js'; + +export default class extends AbstractList { + + constructor($WPHCPosts, $WPHCConfig, $q, $scope, $filter, $stateParams) { + 'ngInject'; + + super($WPHCConfig, $q, $scope, $stateParams); + this.showToolbar = true; + this.setType('taxonomiesPosts'); + this.setService($WPHCPosts); + this.term = $stateParams.term; + this.$filter = $filter; + this.setTitle(this.getTitle($stateParams.term, $stateParams.slug)); + } + + getQuery() { + var query = super.getQuery(); + if (this.$stateParams.term === 'category') { + query["filter[category_name]"] = this.$stateParams.slug + } else if (this.$stateParams.term === 'post_tag') { + query["filter[tag]"] = this.$stateParams.slug + } + return query; + } + + getTitle(term, slug) { + let trans = ''; + if (term === "category") { + trans = slug ? 'category.title' : 'categories.title'; + } else if (term === "post_tag") { + trans = slug ? 'tag.title' : 'tags.title'; + } + if (slug) { + return this.$filter('translate')(trans, { + name: decodeURIComponent(slug) + }); + } + return this.$filter('translate')(trans); + } +} diff --git a/lib/taxonomies/posts.html b/lib/taxonomies/posts.html new file mode 100644 index 000000000..e25ebbfd1 --- /dev/null +++ b/lib/taxonomies/posts.html @@ -0,0 +1,10 @@ + + {{ taxonomiesPostsCtrl.title | translate}} + + + + + + test + + diff --git a/lib/taxonomies/service.js b/lib/taxonomies/service.js new file mode 100644 index 000000000..1f6d9a930 --- /dev/null +++ b/lib/taxonomies/service.js @@ -0,0 +1,32 @@ +export default class { + constructor($ionicModal, $rootScope) { + 'ngInject'; + + this.$ionicModal = $ionicModal; + this.$rootScope = $rootScope; + this.modal = null; + } + + showTaxonomiesInModal(translation, list, term) { + let self = this; + if (!this.modal) { + this.modal = this.$ionicModal.fromTemplate(require('./modal.html'), { + scope: this.$rootScope.$new(), + animation: 'slide-in-up' + }); + this.modal.scope.modal = this.modal; + } + + this.modal.scope.taxonomies = { + title: translation, + term: null, + list: [] + } + + this.modal.show().then(() => { + self.modal.scope.taxonomies.term = term + self.modal.scope.taxonomies.list = list + }); + } + +} diff --git a/lib/taxonomies/tag.service.js b/lib/taxonomies/tag.service.js new file mode 100644 index 000000000..4c29fe146 --- /dev/null +++ b/lib/taxonomies/tag.service.js @@ -0,0 +1,15 @@ +import AbstractList from '../abstract/AbstractListService.js'; + +export default class extends AbstractList { + constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiTerms, $stateParams) { + 'ngInject'; + + super($WPHCConfig, $q, CacheFactory, $log, $stateParams); + this.setType('tag'); + this.setService($wpApiTerms); + } + + getHttpPromise(query) { + return this.service.getTagList(query); + } +} diff --git a/lib/taxonomies/taxonomies.config.coffee b/lib/taxonomies/taxonomies.config.coffee deleted file mode 100644 index baea6fc0c..000000000 --- a/lib/taxonomies/taxonomies.config.coffee +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = angular.module('wordpress-hybrid-client.taxonomies').config ($stateProvider) -> - $stateProvider - # .state 'public.taxonomies', - # url: "/taxonomies" - # abstract: true - .state 'public.taxonomies', - url: "/taxonomies/:term" - views: - 'content@public': - template: require "./taxonomies" - controller: "WPHCTaxonomiesController as taxonomies" - .state 'public.taxonomies.slug', - url: "/:slug" - views: - 'content@public': - template: require "../posts/posts.html" - controller: "WPHCTaxonomiesPostsController as posts" diff --git a/lib/taxonomies/taxonomies.controller.coffee b/lib/taxonomies/taxonomies.controller.coffee deleted file mode 100644 index 8acb80cba..000000000 --- a/lib/taxonomies/taxonomies.controller.coffee +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = angular.module('wordpress-hybrid-client.taxonomies').controller 'WPHCTaxonomiesController', ($log, $scope, $WPHCTaxonomies, $state) -> - $log.info 'WPHCTaxonomiesController' - - vm = @ - - vm.list = undefined - vm.title = $WPHCTaxonomies.getTitle $state.params.term - vm.term = $state.params.term - vm.init = -> - return $WPHCTaxonomies.getList($state.params.term) - .then (response) -> - vm.list = response.data.filter (item) -> - item.count > 0 # remove useless taxo - return response - return @ diff --git a/lib/taxonomies/taxonomies.html b/lib/taxonomies/taxonomies.html deleted file mode 100644 index 0fef00510..000000000 --- a/lib/taxonomies/taxonomies.html +++ /dev/null @@ -1,8 +0,0 @@ - - {{ taxonomies.title | translate}} - - - - - - diff --git a/lib/taxonomies/taxonomies.module.coffee b/lib/taxonomies/taxonomies.module.coffee deleted file mode 100644 index bd74fe9ba..000000000 --- a/lib/taxonomies/taxonomies.module.coffee +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = app = angular.module 'wordpress-hybrid-client.taxonomies', [] - -require './taxonomies.config' -require './taxonomies.controller' -require './taxonomies.posts.controller' -require './taxonomies.service' diff --git a/lib/taxonomies/taxonomies.posts.controller.coffee b/lib/taxonomies/taxonomies.posts.controller.coffee deleted file mode 100644 index e0af792b0..000000000 --- a/lib/taxonomies/taxonomies.posts.controller.coffee +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = angular.module('wordpress-hybrid-client.taxonomies').controller 'WPHCTaxonomiesPostsController', ($log, $scope, $controller, $WPHCTaxonomies, $state, $WPHCPosts) -> - parent = $controller 'WPHCPostsController', - $scope: $scope - parent.title = $WPHCTaxonomies.getTitle $state.params.term, $state.params.slug - parent.getQuery = () -> - query = $WPHCPosts.getQuery parent.page - if $state.params.term is 'post_tag' - query["filter[tag]"] = $state.params.slug - else if $state.params.term is 'category' - query["filter[category_name]"] = $state.params.slug - query - return parent diff --git a/lib/taxonomies/taxonomies.service.coffee b/lib/taxonomies/taxonomies.service.coffee deleted file mode 100644 index e3d9c4354..000000000 --- a/lib/taxonomies/taxonomies.service.coffee +++ /dev/null @@ -1,61 +0,0 @@ -md5 = require 'MD5' - -module.exports = angular.module('wordpress-hybrid-client.taxonomies').factory '$WPHCTaxonomies', ($log, $rootScope, $filter, $wpApiTerms, $q, $WPHCConfig, CacheFactory, $ionicModal) -> - $log.info '$WPHCTaxonomies' - - modal = null - - getCache = () -> - if CacheFactory.get 'taxonomies' - return CacheFactory.get 'taxonomies' - CacheFactory 'taxonomies', $WPHCConfig.taxonomies.cache - - showTaxonomiesInModal: (translation, list, term) -> - # init the modal only on demand - if !modal - modal = $ionicModal.fromTemplate require('./taxonomies.modal.html'), - scope: $rootScope.$new() - animation: 'slide-in-up' - modal.scope.modal = modal - - modal.scope.taxonomies = - title: translation - term : null - list : [] - - modal.show().then -> - modal.scope.taxonomies.term = term - modal.scope.taxonomies.list = list - - getTitle: (term, slug) -> - trans = '' - switch term - when "post_tag" - trans = if slug then 'tag.title' else 'tags.title' - when "category" - trans = if slug then 'category.title' else 'categories.title' - - if slug - $filter('translate') trans, - name: decodeURIComponent slug - else - $filter('translate') trans - - getList: (term) -> - deferred = $q.defer() - hash = md5 $WPHCConfig.api.baseUrl + term - listCache = getCache().get 'list-' + hash - if listCache - deferred.resolve listCache - else - promise = null - if term is 'category' - promise = $wpApiTerms.getCategoryList() - else - promise = $wpApiTerms.getTagList() - promise.then (response) -> - getCache().put 'list-' + hash, response - deferred.resolve response - .catch (error) -> - deferred.reject error - deferred.promise diff --git a/lib/translations/de.json b/lib/translations/de.json index ec7da100a..cd7b732cd 100644 --- a/lib/translations/de.json +++ b/lib/translations/de.json @@ -6,11 +6,13 @@ "attemptToConnect": "Verbinden: Versuch(e) {{attempt}} von {{attemptMax}}.", "yes": "Ja", "no" : "Nein", + "emptyList" : "Keine Inhalte bisher!", "menu": { "title": "Menü", "home": "Startseite", "tags": "Tags", "pages": "Pages", + "posts": "Posts", "authors": "Authors", "search": "Suche", "bookmarks": "Lesezeichen", @@ -56,12 +58,14 @@ "authors": { "title": "Authors" }, + "author": { + "title": "Author: {{name}}" + }, "pages": { "title": "Pages" }, "posts": { - "title": "Startseite", - "empty": "Keine Inhalte bisher!", + "title": "Posts", "featured": "Hervorgehoben" }, "post": { diff --git a/lib/translations/en.json b/lib/translations/en.json index 97c13ad82..f49783b91 100644 --- a/lib/translations/en.json +++ b/lib/translations/en.json @@ -12,6 +12,7 @@ "home": "Home", "tags": "Tags", "pages": "Pages", + "posts": "Posts", "authors": "Authors", "search": "Search", "bookmarks": "Bookmarks", @@ -57,6 +58,9 @@ "authors": { "title": "Authors" }, + "author": { + "title": "Author: {{name}}" + }, "pages": { "title": "Pages" }, diff --git a/lib/translations/es.json b/lib/translations/es.json index 405ecb186..da80969da 100644 --- a/lib/translations/es.json +++ b/lib/translations/es.json @@ -6,11 +6,13 @@ "attemptToConnect": "Attempt to connect {{attempt}} of {{attemptMax}}.", "yes": "Sí", "no" : "No", + "emptyList" : "No se han encontrado publicaciones!", "menu": { "title": "Menu", "home": "Inicio", "tags": "Etiquetas", "pages": "Pages", + "posts": "Posts", "authors": "Authors", "search": "Buscar", "bookmarks": "Favoritos", @@ -56,12 +58,14 @@ "authors": { "title": "Authors" }, + "author": { + "title": "Author: {{name}}" + }, "pages": { "title": "Pages" }, "posts": { - "title": "Inicio", - "empty": "No se han encontrado publicaciones!", + "title": "Posts", "featured": "Destacado" }, "post": { diff --git a/lib/translations/fr.json b/lib/translations/fr.json index 92b8e5869..6d7674f40 100644 --- a/lib/translations/fr.json +++ b/lib/translations/fr.json @@ -6,11 +6,13 @@ "attemptToConnect": "Tentative de connection {{attempt}} sur {{attemptMax}}.", "yes": "Oui", "no" : "Non", + "emptyList" : "La liste est vide!", "menu": { "title": "Menu", "home": "Accueil", "tags": "Tags", "pages": "Pages", + "posts": "Articles", "authors": "Auteurs", "search": "Chercher", "bookmarks": "Signets", @@ -54,14 +56,16 @@ "shared": "partagé avec succès!" }, "authors": { - "title": "Authors" + "title": "Auteurs" + }, + "author": { + "title": "Auteurs: {{name}}" }, "pages": { "title": "Pages" }, "posts": { - "title": "Accueil", - "empty": "La liste est vide!", + "title": "Articles", "featured": "A la Une" }, "post": { diff --git a/lib/translations/pl.json b/lib/translations/pl.json index f9b4405d4..6e6cdddfa 100644 --- a/lib/translations/pl.json +++ b/lib/translations/pl.json @@ -6,12 +6,14 @@ "attemptToConnect": "{{attempt}} próba połączenia z {{attemptMax}}.", "yes": "Tak", "no" : "Nie", + "emptyList" : "Nic tu nie ma!", "menu": { "title": "Menu", "home": "Home", "tags": "Tagi", "pages": "Pages", "authors": "Authors", + "posts": "Posts", "search": "Szukaj", "bookmarks": "Zakładki", "socialNetworks": "Społeczności", @@ -56,12 +58,14 @@ "authors": { "title": "Authors" }, + "author": { + "title": "Author: {{name}}" + }, "pages": { "title": "Pages" }, "posts": { - "title": "Home", - "empty": "Nic tu nie ma :(", + "title": "Posts", "featured": "Wyróżnione" }, "post": { diff --git a/lib/translations/zh.json b/lib/translations/zh.json index 0141a2cc0..15505e66b 100644 --- a/lib/translations/zh.json +++ b/lib/translations/zh.json @@ -6,12 +6,14 @@ "attemptToConnect": "正在尝试第 {{attempt}} 次连接(最多 {{attemptMax}} 次)", "yes": "是", "no" : "否", + "emptyList" : "暂时没有文章!", "menu": { "title": "菜单", "home": "首页", "tags": "标签", "pages": "Pages", "authors": "Authors", + "posts": "Posts", "search": "搜索", "bookmarks": "收藏", "socialNetworks": "社交网络", @@ -56,12 +58,14 @@ "authors": { "title": "Authors" }, + "author": { + "title": "Author: {{name}}" + }, "pages": { "title": "Pages" }, "posts": { - "title": "首页", - "empty": "暂时没有文章!", + "title": "Posts", "featured": "推荐" }, "post": { diff --git a/package.json b/package.json index 0b249ebcc..9b70b0af7 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "coffee-script": "^1.10.0", "cordova": "~5.3.1", "css-loader": "^0.18.0", + "deep-extend": "^0.4.0", "exports-loader": "^0.6.2", "expose-loader": "^0.7.0", "file-loader": "^0.8.4", @@ -83,7 +84,6 @@ "dependencies": { "MD5": "^1.2.1", "angular-cache": "^4.0.0", - "angular-filter": "^0.5.4", "angular-highlightjs": "^0.4.1", "angular-moment": "^0.10.0", "angular-recursion": "^1.0.5", diff --git a/webpack.config.js b/webpack.config.js index ee3717bb8..cf021f167 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -5,7 +5,8 @@ var path = require('path'), wwwPath = path.join(__dirname, 'www'), pkg = require('./package.json'), cordovaLib = require('cordova').cordova_lib, - projectConfig = require('./config.json'), + deepExtend = require('deep-extend'), + projectConfig = deepExtend(require('./config.default.json'), require('./config.dev.json')), HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 8b031c65b..06b16eeda 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -6,7 +6,8 @@ var path = require('path'), pkg = require('./package.json'), cordovaLib = require('cordova').cordova_lib, extend = require('util')._extend, - projectConfig = require('./config.prod.json'), + deepExtend = require('deep-extend'), + projectConfig = deepExtend(require('./config.default.json'), require('./config.prod.json')), webpackConfig = require('./webpack.config.js'), HtmlWebpackPlugin = require('html-webpack-plugin');