├── .io-config.json ├── src ├── services │ ├── constants.ts │ ├── index.ts │ ├── util │ │ └── util.service.ts │ ├── auth │ │ └── auth.service.ts │ └── wp │ │ └── wp.service.ts ├── assets │ └── icon │ │ └── favicon.ico ├── app │ ├── main.ts │ ├── app.html │ ├── app.scss │ ├── app.component.ts │ └── app.module.ts ├── manifest.json ├── declarations.d.ts ├── pages │ ├── postDetail │ │ ├── post-detail.component.ts │ │ └── post-detail.html │ ├── profile │ │ ├── profile.html │ │ └── profile.ts │ ├── storesPosts │ │ ├── stores-posts.html │ │ └── stores-posts.component.ts │ └── home │ │ ├── home.html │ │ └── home.ts ├── components │ ├── commentsList │ │ ├── commentsList.html │ │ └── commentsList.component.ts │ ├── loginForm │ │ ├── login-form.html │ │ └── loginForm.component.ts │ ├── commentForm │ │ ├── commentForm.html │ │ └── commentForm.component.ts │ └── signupForm │ │ ├── signupForm.component.ts │ │ └── signupForm.html ├── index.html ├── theme │ └── variables.scss └── service-worker.js ├── resources ├── icon.png ├── splash.png ├── ios │ ├── icon │ │ ├── icon.png │ │ ├── icon-40.png │ │ ├── icon-50.png │ │ ├── icon-60.png │ │ ├── icon-72.png │ │ ├── icon-76.png │ │ ├── icon@2x.png │ │ ├── icon-40@2x.png │ │ ├── icon-40@3x.png │ │ ├── icon-50@2x.png │ │ ├── icon-60@2x.png │ │ ├── icon-60@3x.png │ │ ├── icon-72@2x.png │ │ ├── icon-76@2x.png │ │ ├── icon-83.5@2x.png │ │ ├── icon-small.png │ │ ├── icon-small@2x.png │ │ └── icon-small@3x.png │ └── splash │ │ ├── Default-667h.png │ │ ├── Default-736h.png │ │ ├── Default~iphone.png │ │ ├── Default@2x~iphone.png │ │ ├── Default-568h@2x~iphone.png │ │ ├── Default-Landscape-736h.png │ │ ├── Default-Landscape~ipad.png │ │ ├── Default-Portrait~ipad.png │ │ ├── Default-Landscape@2x~ipad.png │ │ └── Default-Portrait@2x~ipad.png └── android │ ├── icon │ ├── drawable-hdpi-icon.png │ ├── drawable-ldpi-icon.png │ ├── drawable-mdpi-icon.png │ ├── drawable-xhdpi-icon.png │ ├── drawable-xxhdpi-icon.png │ └── drawable-xxxhdpi-icon.png │ └── splash │ ├── drawable-land-hdpi-screen.png │ ├── drawable-land-ldpi-screen.png │ ├── drawable-land-mdpi-screen.png │ ├── drawable-land-xhdpi-screen.png │ ├── drawable-port-hdpi-screen.png │ ├── drawable-port-ldpi-screen.png │ ├── drawable-port-mdpi-screen.png │ ├── drawable-port-xhdpi-screen.png │ ├── drawable-land-xxhdpi-screen.png │ ├── drawable-land-xxxhdpi-screen.png │ ├── drawable-port-xxhdpi-screen.png │ └── drawable-port-xxxhdpi-screen.png ├── ionic.config.json ├── tslint.json ├── .editorconfig ├── .gitignore ├── tsconfig.json ├── package.json └── config.xml /.io-config.json: -------------------------------------------------------------------------------- 1 | {"app_id":"02620f47"} -------------------------------------------------------------------------------- /src/services/constants.ts: -------------------------------------------------------------------------------- 1 | export const SITE_URL:string = "http://sumsy.com"; -------------------------------------------------------------------------------- /resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/icon.png -------------------------------------------------------------------------------- /resources/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/splash.png -------------------------------------------------------------------------------- /resources/ios/icon/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon.png -------------------------------------------------------------------------------- /src/assets/icon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/src/assets/icon/favicon.ico -------------------------------------------------------------------------------- /ionic.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deals", 3 | "app_id": "02620f47", 4 | "v2": true, 5 | "typescript": true 6 | } 7 | -------------------------------------------------------------------------------- /resources/ios/icon/icon-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-40.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-50.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-60.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-72.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-76.png -------------------------------------------------------------------------------- /resources/ios/icon/icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-40@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-40@3x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-50@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-50@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-60@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-60@3x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-72@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-72@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-76@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-83.5@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-small.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-small@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-small@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-small@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/icon/icon-small@3x.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-667h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default-667h.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-736h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default-736h.png -------------------------------------------------------------------------------- /resources/ios/splash/Default~iphone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default~iphone.png -------------------------------------------------------------------------------- /resources/ios/splash/Default@2x~iphone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default@2x~iphone.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-hdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/icon/drawable-hdpi-icon.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-ldpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/icon/drawable-ldpi-icon.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-mdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/icon/drawable-mdpi-icon.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-xhdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/icon/drawable-xhdpi-icon.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-xxhdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/icon/drawable-xxhdpi-icon.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-568h@2x~iphone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default-568h@2x~iphone.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Landscape-736h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default-Landscape-736h.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Landscape~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default-Landscape~ipad.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Portrait~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default-Portrait~ipad.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-xxxhdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/icon/drawable-xxxhdpi-icon.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Landscape@2x~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default-Landscape@2x~ipad.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Portrait@2x~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/ios/splash/Default-Portrait@2x~ipad.png -------------------------------------------------------------------------------- /src/services/index.ts: -------------------------------------------------------------------------------- 1 | export * from './util/util.service'; 2 | export * from './auth/auth.service'; 3 | export * from './wp/wp.service'; 4 | export * from './constants'; -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-hdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-land-hdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-ldpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-land-ldpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-mdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-land-mdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-xhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-land-xhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-hdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-port-hdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-ldpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-port-ldpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-mdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-port-mdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-xhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-port-xhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-xxhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-land-xxhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-xxxhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-land-xxxhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-xxhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-port-xxhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-xxxhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyma603/ionic2-wordpress/HEAD/resources/android/splash/drawable-port-xxxhdpi-screen.png -------------------------------------------------------------------------------- /src/app/main.ts: -------------------------------------------------------------------------------- 1 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 2 | 3 | import { AppModule } from './app.module'; 4 | 5 | platformBrowserDynamic().bootstrapModule(AppModule); 6 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-duplicate-variable": true, 4 | "no-unused-variable": [ 5 | true 6 | ] 7 | }, 8 | "rulesDirectory": [ 9 | "node_modules/tslint-eslint-rules/dist/rules" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /src/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Ionic", 3 | "short_name": "Ionic", 4 | "start_url": "index.html", 5 | "display": "standalone", 6 | "icons": [{ 7 | "src": "assets/imgs/logo.png", 8 | "sizes": "512x512", 9 | "type": "image/png" 10 | }], 11 | "background_color": "#4e8ef7", 12 | "theme_color": "#4e8ef7" 13 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | indent_style = space 8 | indent_size = 2 9 | 10 | # We recommend you to keep these unchanged 11 | end_of_line = lf 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | 16 | [*.md] 17 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /src/app/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Menu 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Specifies intentionally untracked files to ignore when using Git 2 | # http://git-scm.com/docs/gitignore 3 | 4 | *~ 5 | *.sw[mnpcod] 6 | *.log 7 | *.tmp 8 | *.tmp.* 9 | log.txt 10 | *.sublime-project 11 | *.sublime-workspace 12 | .vscode/ 13 | npm-debug.log* 14 | 15 | .idea/ 16 | .sass-cache/ 17 | .tmp/ 18 | .versions/ 19 | coverage/ 20 | dist/ 21 | node_modules/ 22 | tmp/ 23 | temp/ 24 | hooks/ 25 | platforms/ 26 | plugins/ 27 | plugins/android.json 28 | plugins/ios.json 29 | www/ 30 | $RECYCLE.BIN/ 31 | 32 | .DS_Store 33 | Thumbs.db 34 | UserInterfaceState.xcuserstate 35 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "lib": [ 8 | "dom", 9 | "es2015" 10 | ], 11 | "module": "es2015", 12 | "moduleResolution": "node", 13 | "sourceMap": true, 14 | "target": "es5" 15 | }, 16 | "include": [ 17 | "src/**/*.ts" 18 | ], 19 | "exclude": [ 20 | "node_modules" 21 | ], 22 | "compileOnSave": false, 23 | "atom": { 24 | "rewriteTsconfig": false 25 | } 26 | } -------------------------------------------------------------------------------- /src/declarations.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Declaration files are how the Typescript compiler knows about the type information(or shape) of an object. 3 | They're what make intellisense work and make Typescript know all about your code. 4 | 5 | A wildcard module is declared below to allow third party libraries to be used in an app even if they don't 6 | provide their own type declarations. 7 | 8 | To learn more about using third party libraries in an Ionic app, check out the docs here: 9 | http://ionicframework.com/docs/v2/resources/third-party-libs/ 10 | 11 | For more info on type definition files, check out the Typescript docs here: 12 | https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html 13 | */ 14 | declare module '*'; -------------------------------------------------------------------------------- /src/pages/postDetail/post-detail.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from '@angular/core'; 2 | import {NavController, NavParams} from 'ionic-angular'; 3 | 4 | @Component({ 5 | templateUrl: 'post-detail.html' 6 | }) 7 | 8 | export class PostDetail { 9 | selectedPost : any; 10 | isEditMode: boolean = false; 11 | 12 | comment: any = { 13 | content: {rendered: ''}, 14 | author: null, 15 | post: null 16 | } 17 | 18 | constructor(private nav: NavController, navParams: NavParams) { 19 | this.selectedPost = navParams.get('post'); 20 | } 21 | 22 | editCommentChanged(selecteComment) { 23 | selecteComment.content.rendered = selecteComment.content.rendered.replace(/
/g, ''); 24 | this.comment = selecteComment; 25 | this.isEditMode = true; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /src/pages/profile/profile.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | Profile 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 |

Don't have an account yet? please go to Sumsy.com to register.

16 |
17 | 18 |
19 | 20 | 21 | 22 |

you have logged in.

23 |

{{ auth.user.user_display_name }}

24 |

{{ auth.user.user_email }}

25 |
26 | 27 |
28 | 29 | 30 |
31 | 32 |
-------------------------------------------------------------------------------- /src/components/commentsList/commentsList.html: -------------------------------------------------------------------------------- 1 |

Comments

2 |
3 | 4 | 5 | 6 | 7 | 8 |

{{comment.author_name}}

9 |

{{comment.date | date:"dd/MM/yyyy"}}

10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Edit | 22 | Delete 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 |
33 | 34 |
35 | No comment yet. 36 |
-------------------------------------------------------------------------------- /src/app/app.scss: -------------------------------------------------------------------------------- 1 | // http://ionicframework.com/docs/v2/theming/ 2 | 3 | 4 | // App Global Sass 5 | // -------------------------------------------------- 6 | // Put style rules here that you want to apply globally. These 7 | // styles are for the entire app and not just one component. 8 | // Additionally, this file can be also used as an entry point 9 | // to import other Sass files to be included in the output CSS. 10 | // 11 | // Shared Sass variables, which can be used to adjust Ionic's 12 | // default Sass variables, belong in "theme/variables.scss". 13 | // 14 | // To declare rules for a specific mode, create a child rule 15 | // for the .md, .ios, or .wp mode classes. The mode class is 16 | // automatically applied to the element in the app. 17 | 18 | .postList ion-label { 19 | white-space: normal; 20 | } 21 | .toolbar-background-md { 22 | border-color: #b2b2b2; 23 | background: #f3745d; 24 | } 25 | .toolbar-title-md{ 26 | color: #fff 27 | } 28 | .bar-button-default-md{ 29 | color: #fff; 30 | } -------------------------------------------------------------------------------- /src/services/util/util.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | import {LoadingController , ToastController} from 'ionic-angular'; 3 | 4 | @Injectable() 5 | export class UtilService { 6 | public loadingController: LoadingController; 7 | 8 | constructor(private toastCtrl: ToastController, private loadingCtrl: LoadingController) { 9 | 10 | } 11 | 12 | getLoader(content) { 13 | let loading = this.loadingCtrl.create({ 14 | content: content 15 | }); 16 | return loading; 17 | } 18 | 19 | getToast(message) { 20 | let toast = this.toastCtrl.create({ 21 | message: message, 22 | duration: 3000, 23 | position: 'top' 24 | }); 25 | return toast; 26 | } 27 | 28 | transformRequest(obj) { 29 | let p, str; 30 | str = []; 31 | for (p in obj) { 32 | str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p])); 33 | } 34 | return str.join('&'); 35 | } 36 | } -------------------------------------------------------------------------------- /src/pages/profile/profile.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | import { AuthService, WpService } from '../../services/index'; 4 | 5 | @Component({ 6 | templateUrl: './profile.html', 7 | }) 8 | export class ProfilePage { 9 | userInfo: any = {}; 10 | 11 | constructor( 12 | private auth: AuthService, 13 | private wp: WpService) { 14 | console.log(this.auth.user); 15 | } 16 | 17 | getInfo() { 18 | console.log(this.auth.token); 19 | this.wp.getCurrentUserProfile().subscribe(data => { 20 | console.log(data); 21 | }, (error) => { 22 | }); 23 | } 24 | 25 | userAddComment() { 26 | let obj = { 27 | author: 1, 28 | content: 'YourCommentHere1', 29 | post: 55 30 | }; 31 | 32 | this.wp.userAddComment(obj) 33 | .subscribe(data => { 34 | console.log(data); 35 | }); 36 | } 37 | 38 | logout() { 39 | this.auth.logout(); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/pages/storesPosts/stores-posts.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | {{selectedStore.name}} 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 |

18 |

19 | 20 |

  • 21 |
  • 22 | 23 |

    24 |
    25 | 26 |
    27 | 28 | 29 | 30 |
    -------------------------------------------------------------------------------- /src/pages/storesPosts/stores-posts.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Http } from '@angular/http'; 3 | import { NavController, NavParams } from 'ionic-angular'; 4 | import 'rxjs/add/operator/map'; 5 | import {PostDetail} from '../postDetail/post-detail.component'; 6 | 7 | @Component({ 8 | selector: 'page-stores-posts', 9 | templateUrl: 'stores-posts.html' 10 | }) 11 | 12 | export class StoresPosts { 13 | 14 | url: string = 'http://sumsy.com/wp-json/wp/v2/deal?_embed' 15 | posts: any; 16 | selectedStore: any; 17 | 18 | constructor(private nav: NavController, private http: Http, navParams: NavParams ) { 19 | 20 | this.selectedStore = navParams.get('store'); 21 | } 22 | 23 | ionViewDidEnter() { 24 | this.http.get(this.url + '&filter[taxonomy]=deal-store&filter[term]='+ this.selectedStore.name) 25 | .map(res => res.json()) 26 | .subscribe(data => { 27 | this.posts = data; 28 | console.log(this.posts); 29 | }); 30 | } 31 | 32 | postTapped(event, post) { 33 | this.nav.push(PostDetail, { 34 | post: post 35 | }); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/components/loginForm/login-form.html: -------------------------------------------------------------------------------- 1 |
    2 | 3 | 4 | Username 5 | 12 | 13 | 14 | 15 | Password 16 | 23 | 24 | 25 | 26 | 27 | 28 |
    Username is required
    29 |
    Password is required
    30 | 31 |
    {{loginStatusMessage}}
    32 | 33 | 34 | 35 |
    -------------------------------------------------------------------------------- /src/components/commentForm/commentForm.html: -------------------------------------------------------------------------------- 1 |
    2 |
    comment is required
    3 | 4 |
    {{statusMessage}}
    5 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
    25 | 26 |

    Add Comment

    27 | 28 |

    Add Comment (login required)

    29 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ionic App 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/components/signupForm/signupForm.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Http } from '@angular/http'; 3 | import { WpService } from '../../services/index'; 4 | 5 | @Component({ 6 | selector: 'signup-form', 7 | templateUrl: './signupForm.html' 8 | }) 9 | 10 | export class SignupFormComponent { 11 | 12 | signupStatusMessage: string; 13 | signupModel: any = {} 14 | isLoading: boolean = false; 15 | 16 | constructor(private wp: WpService, private http: Http) { 17 | } 18 | 19 | signup(e) { 20 | this.isLoading = true; 21 | this.signupStatusMessage = ''; 22 | this.wp.signup(this.signupModel) 23 | .subscribe( 24 | result => { 25 | if (result === true) { 26 | // login successful 27 | this.signupStatusMessage = 'sign up successful!'; 28 | } else { 29 | // login failed - token issue 30 | this.signupStatusMessage = 'Something wrong with token.'; 31 | } 32 | this.isLoading = false; 33 | }, 34 | result => { 35 | //rest call error 36 | this.isLoading = false; 37 | this.signupStatusMessage = 'Username or password is incorrect'; 38 | } 39 | ); 40 | return false; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/components/loginForm/loginForm.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { AuthService } from '../../services/index'; 3 | 4 | @Component({ 5 | selector: 'login-form', 6 | templateUrl: './login-form.html', 7 | }) 8 | export class LoginFormComponent { 9 | 10 | loginStatusMessage: string; 11 | loginModel: any = {} 12 | isLoading: boolean = false; 13 | 14 | constructor(private auth: AuthService) { 15 | } 16 | 17 | login(e) { 18 | this.isLoading = true; 19 | this.loginStatusMessage = ''; 20 | this.auth.login(this.loginModel.username, this.loginModel.password) 21 | .subscribe( 22 | result => { 23 | if (result === true) { 24 | // login successful 25 | this.loginStatusMessage = 'Login successful!'; 26 | } else { 27 | // login failed - token issue 28 | this.loginStatusMessage = 'Something wrong with token.'; 29 | } 30 | this.isLoading = false; 31 | }, 32 | result => { 33 | //rest call error 34 | this.isLoading = false; 35 | this.loginStatusMessage = 'Username or password is incorrect'; 36 | } 37 | ); 38 | return false; 39 | } 40 | 41 | logout() { 42 | this.auth.logout(); 43 | } 44 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-hello-world", 3 | "author": "Ionic Framework", 4 | "homepage": "http://ionicframework.com/", 5 | "private": true, 6 | "scripts": { 7 | "clean": "ionic-app-scripts clean", 8 | "build": "ionic-app-scripts build", 9 | "ionic:build": "ionic-app-scripts build", 10 | "ionic:serve": "ionic-app-scripts serve" 11 | }, 12 | "dependencies": { 13 | "@angular/common": "2.2.1", 14 | "@angular/compiler": "2.2.1", 15 | "@angular/compiler-cli": "2.2.1", 16 | "@angular/core": "2.2.1", 17 | "@angular/forms": "2.2.1", 18 | "@angular/http": "2.2.1", 19 | "@angular/platform-browser": "2.2.1", 20 | "@angular/platform-browser-dynamic": "2.2.1", 21 | "@angular/platform-server": "2.2.1", 22 | "@ionic/storage": "1.1.6", 23 | "angular2-jwt": "^0.1.27", 24 | "auth0-lock": "^10.7.3", 25 | "ionic-angular": "2.0.0-rc.4", 26 | "ionic-native": "2.2.11", 27 | "ionicons": "3.0.0", 28 | "rxjs": "5.0.0-beta.12", 29 | "zone.js": "0.6.26" 30 | }, 31 | "devDependencies": { 32 | "@ionic/app-scripts": "^1.0.0", 33 | "typescript": "2.0.9", 34 | "sw-toolbox": "3.4.0" 35 | }, 36 | "cordovaPlugins": [ 37 | "cordova-plugin-whitelist", 38 | "cordova-plugin-statusbar", 39 | "cordova-plugin-console", 40 | "cordova-plugin-device", 41 | "cordova-plugin-splashscreen", 42 | "ionic-plugin-keyboard" 43 | ], 44 | "cordovaPlatforms": [], 45 | "description": "deals: An Ionic project" 46 | } 47 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, ViewChild } from '@angular/core'; 2 | import { Nav, Platform } from 'ionic-angular'; 3 | import { StatusBar, Splashscreen } from 'ionic-native'; 4 | import { Home } from '../pages/home/home'; 5 | import { ProfilePage } from '../pages/profile/profile'; 6 | import { UtilService } from '../services/index'; 7 | 8 | 9 | @Component({ 10 | templateUrl: 'app.html' 11 | }) 12 | export class MyApp { 13 | @ViewChild(Nav) nav: Nav; 14 | 15 | rootPage: any = Home; 16 | 17 | pages: Array<{title: string, component: any}>; 18 | 19 | constructor(public platform: Platform, public up: UtilService) { 20 | this.initializeApp(); 21 | 22 | // used for an example of ngFor and navigation 23 | this.pages = [ 24 | { title: 'Home', component: Home}, 25 | { title: 'Profile', component: ProfilePage } 26 | ]; 27 | 28 | } 29 | 30 | initializeApp() { 31 | this.platform.ready().then(() => { 32 | //let toast = this.up.getToast("You are not connected to Internet."); 33 | //toast.present(); 34 | 35 | // Okay, so the platform is ready and our plugins are available. 36 | // Here you can do any higher level native things you might need. 37 | StatusBar.styleDefault(); 38 | Splashscreen.hide(); 39 | }); 40 | } 41 | 42 | openPage(page) { 43 | // Reset the content nav to have just this page 44 | // we wouldn't want the back button to show in this scenario 45 | this.nav.setRoot(page.component); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/pages/postDetail/post-detail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{selectedPost.title.rendered}} 5 | 6 | 7 | 8 | 9 | 10 | 11 |
    12 |
    13 | 14 |
    15 |

    16 |
    17 |
    18 |

    Click on Promo code below to copy to clipboard

    19 | 20 |
    21 | 22 |
    23 | 24 |
    25 | 26 |
    Expire: {{selectedPost.deal_details_expirydate}}
    27 | 28 | 29 | 30 | 31 | 32 | 33 |
    34 | 35 |
    36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/pages/home/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | Home page 7 | 8 | 9 | 10 | 11 | 12 | 13 |
    14 | 15 | 16 | 18 | 19 |

    20 |

    21 | 22 |

  • 23 |
  • 24 | 25 |

    26 |
    27 | 28 |
    29 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 |
    -------------------------------------------------------------------------------- /src/components/signupForm/signupForm.html: -------------------------------------------------------------------------------- 1 | 2 |
    3 | become a member 4 |
    5 | 6 |
    7 | 8 | 9 | Username 10 | 17 | 18 | 19 | 20 | 21 | Email 22 | 29 | 30 | 31 | 32 | 33 | Password 34 | 41 | 42 | 43 | 44 | 45 | 46 |
    Username is required
    47 |
    Password is required
    48 | 49 |
    {{signupStatusMessage}}
    50 | 51 | 52 | 53 |
    -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, ErrorHandler } from '@angular/core'; 2 | import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular'; 3 | 4 | import { AuthConfig, AuthHttp } from 'angular2-jwt'; 5 | import { Http } from '@angular/http'; 6 | import { MyApp } from './app.component'; 7 | import { Home } from '../pages/home/home'; 8 | import { ProfilePage } from '../pages/profile/profile'; 9 | import { PostDetail } from '../pages/postDetail/post-detail.component'; 10 | import { StoresPosts } from '../pages/storesPosts/stores-posts.component'; 11 | import { UtilService, AuthService, WpService } from '../services/index'; 12 | import { LoginFormComponent } from '../components/loginForm/loginForm.component'; 13 | import { CommentsListComponent } from '../components/commentsList/commentsList.component'; 14 | import { CommentFormComponent } from '../components/commentForm/commentForm.component'; 15 | import { SignupFormComponent } from '../components/signupForm/signupForm.component'; 16 | 17 | export function getAuthHttp(http) { 18 | return new AuthHttp(new AuthConfig({ 19 | globalHeaders: [{ 'Accept': 'application/json' }], 20 | tokenGetter: (() => localStorage.getItem('id_token')) 21 | }), http); 22 | } 23 | 24 | @NgModule({ 25 | declarations: [ 26 | MyApp, 27 | Home, 28 | PostDetail, 29 | StoresPosts, 30 | ProfilePage, 31 | LoginFormComponent, 32 | CommentsListComponent, 33 | CommentFormComponent, 34 | SignupFormComponent 35 | ], 36 | imports: [ 37 | IonicModule.forRoot(MyApp) 38 | ], 39 | bootstrap: [IonicApp], 40 | entryComponents: [ 41 | MyApp, 42 | Home, 43 | PostDetail, 44 | StoresPosts, 45 | ProfilePage 46 | ], 47 | providers: [ 48 | { provide: ErrorHandler, useClass: IonicErrorHandler }, 49 | UtilService, 50 | AuthService, 51 | WpService, 52 | { provide: AuthHttp, useFactory: getAuthHttp, deps: [Http] } 53 | ] 54 | }) 55 | export class AppModule { } 56 | -------------------------------------------------------------------------------- /config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | deals 4 | An awesome Ionic/Cordova app. 5 | Ionic Framework Team 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/pages/home/home.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Http } from '@angular/http'; 3 | import { NavController } from 'ionic-angular'; 4 | import 'rxjs/add/operator/map'; 5 | import { PostDetail } from '../postDetail/post-detail.component'; 6 | import { StoresPosts } from '../storesPosts/stores-posts.component'; 7 | import { WpService } from '../../services/index'; 8 | 9 | @Component({ 10 | templateUrl: 'home.html' 11 | }) 12 | 13 | export class Home { 14 | posts: any; 15 | loader: any; 16 | isLoading: boolean = false; 17 | noMoreData: boolean = false; 18 | params = { 19 | }; 20 | 21 | constructor( 22 | public navCtrl: NavController, 23 | private http: Http, 24 | private nav:NavController, 25 | private wp: WpService 26 | ) { 27 | 28 | this.params['page'] = 1; 29 | this.isLoading = true; 30 | 31 | this.wp.getPosts(this.params) 32 | .subscribe( 33 | data => { 34 | this.posts = data; 35 | this.isLoading = false; 36 | }, 37 | error => { 38 | this.isLoading = false; 39 | console.log(error); 40 | } 41 | ); 42 | } 43 | 44 | ionViewDidEnter() { 45 | 46 | } 47 | 48 | postTapped(event, post) { 49 | this.nav.push(PostDetail, { 50 | post: post 51 | }); 52 | } 53 | 54 | storeTapped(event, store) { 55 | console.log(store); 56 | this.nav.push(StoresPosts, { 57 | store: store 58 | }); 59 | } 60 | 61 | loadMore(infiniteScroll) { 62 | this.params['page'] = this.params['page'] + 1; 63 | console.log(this.params['page']); 64 | 65 | this.wp.getPosts(this.params) 66 | .subscribe( 67 | data => { 68 | for(let i = 0; i< data.length; i++) { 69 | this.posts.push(data[i]); 70 | } 71 | 72 | infiniteScroll.complete(); 73 | }, 74 | error => { 75 | console.log(error); 76 | infiniteScroll.complete(); 77 | } 78 | ); 79 | } 80 | 81 | } -------------------------------------------------------------------------------- /src/theme/variables.scss: -------------------------------------------------------------------------------- 1 | // Ionic Variables and Theming. For more info, please see: 2 | // http://ionicframework.com/docs/v2/theming/ 3 | $font-path: "../assets/fonts"; 4 | 5 | @import "ionic.globals"; 6 | 7 | 8 | // Shared Variables 9 | // -------------------------------------------------- 10 | // To customize the look and feel of this app, you can override 11 | // the Sass variables found in Ionic's source scss files. 12 | // To view all the possible Ionic variables, see: 13 | // http://ionicframework.com/docs/v2/theming/overriding-ionic-variables/ 14 | 15 | 16 | 17 | 18 | // Named Color Variables 19 | // -------------------------------------------------- 20 | // Named colors makes it easy to reuse colors on various components. 21 | // It's highly recommended to change the default colors 22 | // to match your app's branding. Ionic uses a Sass map of 23 | // colors so you can add, rename and remove colors as needed. 24 | // The "primary" color is the only required color in the map. 25 | 26 | $colors: ( 27 | primary: #f3745d, 28 | secondary: #32db64, 29 | danger: #f53d3d, 30 | light: #f4f4f4, 31 | dark: #222 32 | ); 33 | 34 | 35 | // App iOS Variables 36 | // -------------------------------------------------- 37 | // iOS only Sass variables can go here 38 | 39 | 40 | 41 | 42 | // App Material Design Variables 43 | // -------------------------------------------------- 44 | // Material Design only Sass variables can go here 45 | 46 | 47 | 48 | 49 | // App Windows Variables 50 | // -------------------------------------------------- 51 | // Windows only Sass variables can go here 52 | 53 | 54 | 55 | 56 | // App Theme 57 | // -------------------------------------------------- 58 | // Ionic apps can have different themes applied, which can 59 | // then be future customized. This import comes last 60 | // so that the above variables are used and Ionic's 61 | // default are overridden. 62 | 63 | @import "ionic.theme.default"; 64 | 65 | 66 | // Ionicons 67 | // -------------------------------------------------- 68 | // The premium icon font for Ionic. For more info, please see: 69 | // http://ionicframework.com/docs/v2/ionicons/ 70 | 71 | @import "ionicons"; 72 | 73 | 74 | // Fonts 75 | // -------------------------------------------------- 76 | 77 | @import "roboto"; 78 | @import "noto-sans"; 79 | -------------------------------------------------------------------------------- /src/services/auth/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { JwtHelper, tokenNotExpired } from 'angular2-jwt'; 3 | import { Http, Headers } from '@angular/http'; 4 | import { Observable } from 'rxjs/Rx'; 5 | import { SITE_URL, UtilService } from '../index'; 6 | 7 | @Injectable() 8 | export class AuthService { 9 | 10 | public token: string; 11 | public user: any; 12 | contentHeader: Headers = new Headers({ "Content-Type": "application/json" }); 13 | jwtHelper: JwtHelper = new JwtHelper(); 14 | wpApiURL: string = SITE_URL + '/wp-json/wp/v2'; 15 | wpJWTURL: string = SITE_URL + '/wp-json/jwt-auth/v1'; 16 | 17 | constructor(private http: Http, private util:UtilService) { 18 | let userinfo = localStorage.getItem('current_user'); 19 | this.token = localStorage.getItem('id_token'); 20 | this.user = userinfo ? JSON.parse(userinfo) : {}; 21 | } 22 | 23 | public authenticated() { 24 | return tokenNotExpired('id_token', this.token); 25 | } 26 | 27 | public login(username: string, password: string) { 28 | let loginQuery = { 29 | username: username, 30 | password: password 31 | } 32 | 33 | return this.http.post(this.wpJWTURL + '/token?' + this.util.transformRequest(loginQuery), {}, { headers: this.contentHeader }) 34 | .map(response => { 35 | // login successful if there's a jwt token in the response 36 | let token = response.json() && response.json().token; 37 | if (token) { 38 | // set token property 39 | this.token = token; 40 | localStorage.setItem('id_token', token); 41 | 42 | // store username and jwt token in local storage to keep user logged in between page refreshes 43 | localStorage.setItem('current_user', JSON.stringify(response.json())); 44 | this.user = response.json(); 45 | // return true to indicate successful login 46 | return true; 47 | } else { 48 | // return false to indicate failed login 49 | return false; 50 | } 51 | }) 52 | .catch((error:any) => { 53 | return Observable.throw(false)}); 54 | } 55 | 56 | public logout(): void { 57 | // clear token remove user from local storage to log user out 58 | this.token = null; 59 | localStorage.removeItem('id_token'); 60 | localStorage.removeItem('current_user'); 61 | } 62 | 63 | 64 | 65 | } -------------------------------------------------------------------------------- /src/components/commentForm/commentForm.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, Output, EventEmitter } from "@angular/core"; 2 | import { JwtHelper } from 'angular2-jwt'; 3 | import { NavController } from 'ionic-angular'; 4 | import { WpService, AuthService } from '../../services/index'; 5 | import { ProfilePage } from '../../pages/profile/profile'; 6 | 7 | @Component({ 8 | selector: 'comment-form', 9 | templateUrl: './commentForm.html' 10 | }) 11 | 12 | export class CommentFormComponent { 13 | @Input() postId: number; 14 | @Input() comment: any; 15 | @Input() isEditMode: boolean; 16 | @Output() isEditModeChange = new EventEmitter(); 17 | @Output() commentChange = new EventEmitter(); 18 | jwtHelper: JwtHelper = new JwtHelper(); 19 | statusMessage = ''; 20 | 21 | isEditing: boolean = false; 22 | 23 | 24 | constructor(private wp:WpService, private auth: AuthService, private nav: 25 | NavController) { 26 | } 27 | 28 | ngOnInit() { 29 | this.comment.post = this.postId; 30 | this.comment.author = this.wp.getCurrentAuthorId(); 31 | } 32 | 33 | onCancel() { 34 | this.commentChange.emit({ 35 | content: {rendered: ''}, 36 | author: null, 37 | post: this.postId 38 | }); 39 | this.isEditing = false; 40 | this.isEditModeChange.emit(false); 41 | this.statusMessage = ''; 42 | return false; 43 | } 44 | 45 | showPanel() { 46 | return this.auth.authenticated() && (this.isEditing) || this.isEditMode; 47 | } 48 | 49 | updateComment(form) { 50 | let params = { 51 | content: this.comment.content.rendered, 52 | }; 53 | 54 | this.wp.userUpdateComment(this.comment.id, params) 55 | .subscribe( 56 | data => { 57 | this.statusMessage = "Comment updated successfully!"; 58 | //clear form 59 | form.reset(); 60 | }, 61 | error => { 62 | console.log(error._body); 63 | this.statusMessage = error._body; 64 | } 65 | ); 66 | 67 | } 68 | 69 | submitComment(form) { 70 | console.log(this.comment, form); 71 | let params = { 72 | content: this.comment.content.rendered, 73 | author: this.wp.getCurrentAuthorId(), 74 | post: this.comment.post 75 | }; 76 | console.log(params); 77 | this.comment.author = this.wp.getCurrentAuthorId(); 78 | this.wp.userAddComment(params) 79 | .subscribe( 80 | data => { 81 | this.statusMessage = "Comment added successfully!"; 82 | //clear form 83 | form.reset(); 84 | }, 85 | error => { 86 | console.log(error._body); 87 | this.statusMessage = error._body; 88 | } 89 | ); 90 | } 91 | 92 | commentFormNotAuthClicked() { 93 | this.nav.push(ProfilePage); 94 | } 95 | } -------------------------------------------------------------------------------- /src/components/commentsList/commentsList.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, Output, EventEmitter } from "@angular/core"; 2 | import { Http } from '@angular/http'; 3 | import { AlertController, ToastController } from 'ionic-angular'; 4 | import { SITE_URL, WpService } from '../../services/index'; 5 | 6 | @Component({ 7 | selector: 'comments-list', 8 | templateUrl: './commentsList.html' 9 | }) 10 | 11 | export class CommentsListComponent { 12 | 13 | @Input() postId: number; 14 | @Output() editCommentChanged = new EventEmitter(); 15 | wpApiURL: string = SITE_URL + '/wp-json/wp/v2'; 16 | comments: any = []; 17 | authorId = null; 18 | 19 | constructor( 20 | private http: Http, 21 | private wp: WpService, 22 | private alertCtrl: AlertController, 23 | private toastCtrl: ToastController 24 | ) { 25 | } 26 | 27 | ngOnInit(){ 28 | // Load comments 29 | this.loadComments(this.postId); 30 | } 31 | 32 | loadComments(postId) { 33 | this.wp.getCommentsByPostId({post: postId}).subscribe( 34 | data => { 35 | console.log(data); 36 | this.comments = data; 37 | }, 38 | error => {} 39 | ); 40 | } 41 | 42 | canDeleteComment(authorId) { 43 | //console.log(authorId, this.wp.getCurrentAuthorId(), authorId === this.wp.getCurrentAuthorId()); 44 | return authorId === this.wp.getCurrentAuthorId(); 45 | } 46 | 47 | deleteComment(comment) { 48 | 49 | let confirm = this.alertCtrl.create({ 50 | title: 'Delete Comment', 51 | message: 'Are you sure to delete this comment?', 52 | buttons: [ 53 | { 54 | text: 'Yes', 55 | handler: () => { 56 | let toast = this.toastCtrl.create({ 57 | message: 'processing' 58 | }); 59 | toast.present(); 60 | this.wp.deleteComment(comment).subscribe( 61 | data => { 62 | console.log(data); 63 | toast.dismiss(); 64 | this.showToast('Comment is successfully deleted.'); 65 | }, 66 | error => { 67 | console.log(error); 68 | toast.dismiss(); 69 | this.showToast(error); 70 | } 71 | ); 72 | } 73 | }, 74 | { 75 | text: 'Cancel', 76 | handler: () => { 77 | console.log('delete comment action cancelled'); 78 | } 79 | } 80 | ] 81 | }); 82 | confirm.present(); 83 | } 84 | 85 | editComment(comment) { 86 | this.editCommentChanged.emit(comment); 87 | } 88 | 89 | showToast(message) { 90 | let toast = this.toastCtrl.create({ 91 | message: message, 92 | duration: 3000 93 | }); 94 | toast.present(); 95 | } 96 | 97 | 98 | } -------------------------------------------------------------------------------- /src/services/wp/wp.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Http } from '@angular/http'; 3 | import { AuthHttp, JwtHelper } from 'angular2-jwt'; 4 | import {SITE_URL, UtilService} from '../index'; 5 | 6 | @Injectable() 7 | export class WpService { 8 | 9 | wpApiURL: string = SITE_URL + '/wp-json/wp/v2'; 10 | comments: any = []; 11 | jwtHelper: JwtHelper = new JwtHelper(); 12 | 13 | constructor( 14 | private authHttp: AuthHttp, 15 | private util:UtilService, 16 | private http: Http 17 | ) { 18 | } 19 | 20 | getCurrentUserProfile() { 21 | return this.authHttp.get(this.wpApiURL + '/users/me') 22 | .map(res => res.json()); 23 | } 24 | 25 | signup(paramsObj) { 26 | let params = this.util.transformRequest(paramsObj); 27 | console.log(params); 28 | return this.http.post(this.wpApiURL + '/users/?' + params, JSON.stringify(paramsObj)) 29 | .map( 30 | res => res.json() 31 | ); 32 | } 33 | 34 | 35 | userAddComment(paramsObj) { 36 | let params = this.util.transformRequest(paramsObj); 37 | console.log('sending request'); 38 | return this.authHttp.post(this.wpApiURL + '/comments?' + params, JSON.stringify({})) 39 | .map( 40 | res => { 41 | let newComment = res.json(); 42 | this.comments.push(newComment); 43 | console.log(this.comments); 44 | return newComment; 45 | } 46 | ); 47 | } 48 | 49 | userUpdateComment(id, paramsObj) { 50 | let params = this.util.transformRequest(paramsObj); 51 | console.log('sending request'); 52 | return this.authHttp.put(this.wpApiURL + '/comments/'+ id + '?' + params, JSON.stringify({})) 53 | .map( 54 | res => { 55 | let updatedComment = res.json(); 56 | //this.comments.push(updatedComment); 57 | for(let i=0; i res.json()); 75 | } 76 | 77 | getCommentsByPostId(paramsObj) { 78 | let params = this.util.transformRequest(paramsObj); 79 | return this.http.get(this.wpApiURL + '/comments?' + params) 80 | .map(res => { 81 | this.comments = res.json(); 82 | return this.comments; 83 | }); 84 | } 85 | 86 | deleteComment(comment) { 87 | return this.authHttp.delete(this.wpApiURL + '/comments/' + comment.id) 88 | .map(res => { 89 | console.log(res.json()); 90 | this.comments.splice(this.comments.indexOf(comment), 1) 91 | return res.json(); 92 | }); 93 | } 94 | 95 | public getCurrentAuthorId(): number { 96 | let token:any = localStorage.getItem('id_token'); 97 | if(token) { 98 | token = this.jwtHelper.decodeToken(token); 99 | return Number(token.data.user.id); 100 | } else{ 101 | return null; 102 | } 103 | } 104 | 105 | 106 | } -------------------------------------------------------------------------------- /src/service-worker.js: -------------------------------------------------------------------------------- 1 | // tick this to make the cache invalidate and update 2 | const CACHE_VERSION = 1; 3 | const CURRENT_CACHES = { 4 | 'read-through': 'read-through-cache-v' + CACHE_VERSION 5 | }; 6 | 7 | self.addEventListener('activate', (event) => { 8 | // Delete all caches that aren't named in CURRENT_CACHES. 9 | // While there is only one cache in this example, the same logic will handle the case where 10 | // there are multiple versioned caches. 11 | const expectedCacheNames = Object.keys(CURRENT_CACHES).map((key) => { 12 | return CURRENT_CACHES[key]; 13 | }); 14 | 15 | event.waitUntil( 16 | caches.keys().then((cacheNames) => { 17 | return Promise.all( 18 | cacheNames.map((cacheName) => { 19 | if (expectedCacheNames.indexOf(cacheName) === -1) { 20 | // If this cache name isn't present in the array of "expected" cache names, then delete it. 21 | console.log('Deleting out of date cache:', cacheName); 22 | return caches.delete(cacheName); 23 | } 24 | }) 25 | ); 26 | }) 27 | ); 28 | }); 29 | 30 | // This sample illustrates an aggressive approach to caching, in which every valid response is 31 | // cached and every request is first checked against the cache. 32 | // This may not be an appropriate approach if your web application makes requests for 33 | // arbitrary URLs as part of its normal operation (e.g. a RSS client or a news aggregator), 34 | // as the cache could end up containing large responses that might not end up ever being accessed. 35 | // Other approaches, like selectively caching based on response headers or only caching 36 | // responses served from a specific domain, might be more appropriate for those use cases. 37 | self.addEventListener('fetch', (event) => { 38 | 39 | event.respondWith( 40 | caches.open(CURRENT_CACHES['read-through']).then((cache) => { 41 | return cache.match(event.request).then((response) => { 42 | if (response) { 43 | // If there is an entry in the cache for event.request, then response will be defined 44 | // and we can just return it. 45 | 46 | return response; 47 | } 48 | 49 | // Otherwise, if there is no entry in the cache for event.request, response will be 50 | // undefined, and we need to fetch() the resource. 51 | console.log(' No response for %s found in cache. ' + 52 | 'About to fetch from network...', event.request.url); 53 | 54 | // We call .clone() on the request since we might use it in the call to cache.put() later on. 55 | // Both fetch() and cache.put() "consume" the request, so we need to make a copy. 56 | // (see https://fetch.spec.whatwg.org/#dom-request-clone) 57 | return fetch(event.request.clone()).then((response) => { 58 | 59 | // Optional: add in extra conditions here, e.g. response.type == 'basic' to only cache 60 | // responses from the same domain. See https://fetch.spec.whatwg.org/#concept-response-type 61 | if (response.status < 400 && response.type === 'basic') { 62 | // We need to call .clone() on the response object to save a copy of it to the cache. 63 | // (https://fetch.spec.whatwg.org/#dom-request-clone) 64 | cache.put(event.request, response.clone()); 65 | } 66 | 67 | // Return the original response object, which will be used to fulfill the resource request. 68 | return response; 69 | }); 70 | }).catch((error) => { 71 | // This catch() will handle exceptions that arise from the match() or fetch() operations. 72 | // Note that a HTTP error response (e.g. 404) will NOT trigger an exception. 73 | // It will return a normal response object that has the appropriate error code set. 74 | console.error(' Read-through caching failed:', error); 75 | 76 | throw error; 77 | }); 78 | }) 79 | ); 80 | }); --------------------------------------------------------------------------------