|
1 | 1 | import { Component } from '@angular/core'; |
2 | 2 | import { IonicPage, NavController, NavParams } from 'ionic-angular'; |
3 | 3 |
|
| 4 | +import { PostPage } from '../post/post'; |
| 5 | +import { ProfilePage } from '../profile/profile'; |
| 6 | +import { AccountPage } from '../account/account'; |
| 7 | + |
| 8 | +import { FirebaseProvider } from '../../providers/firebase/firebase'; |
| 9 | + |
4 | 10 | @IonicPage() |
5 | 11 | @Component({ |
6 | 12 | selector: 'page-posts-manager', |
7 | 13 | templateUrl: 'posts-manager.html', |
8 | 14 | }) |
9 | 15 | export class PostsManagerPage { |
10 | 16 |
|
11 | | - title = 'Manage Posts'; |
| 17 | + title = 'Posts Manager'; |
| 18 | + flaggedPosts: any; |
| 19 | + thereAreFlaggedPosts = false; |
| 20 | + posts: any; |
| 21 | + queryParams: any; |
12 | 22 |
|
13 | 23 | constructor( |
14 | | - public navCtrl: NavController, |
15 | | - public navParams: NavParams |
| 24 | + private navCtrl: NavController, |
| 25 | + private navParams: NavParams, |
| 26 | + private firebase: FirebaseProvider |
16 | 27 | ) { |
17 | 28 | } |
18 | 29 |
|
19 | 30 | ionViewDidLoad() { |
20 | | - console.log('ionViewDidLoad PostsManagerPage'); |
| 31 | + this.loadFlaggedPosts(); |
| 32 | + } |
| 33 | + |
| 34 | + loadFlaggedPosts() { |
| 35 | + let path = 'flagged/posts'; |
| 36 | + this.firebase.list(path).subscribe((flaggedPosts) => { |
| 37 | + console.log("Got flagged posts"); |
| 38 | + console.log(flaggedPosts); |
| 39 | + console.log("There are flagged posts " + this.thereAreFlaggedPosts) |
| 40 | + if (flaggedPosts.length > 0) { |
| 41 | + this.flaggedPosts = flaggedPosts; |
| 42 | + this.thereAreFlaggedPosts = true; |
| 43 | + } |
| 44 | + }) |
| 45 | + } |
| 46 | + |
| 47 | + restorePost(post) { |
| 48 | + console.log("Restoring post"); |
| 49 | + console.log("post"); |
| 50 | + post.onFeed = true; |
| 51 | + post.flagged = false; |
| 52 | + post.flaggedId = null; |
| 53 | + let path = 'posts/' + post.id |
| 54 | + this.firebase.object(path).update(post).then(() => { |
| 55 | + let path = 'flagged/posts/' + post.flaggedID |
| 56 | + this.firebase.object(path).remove().then(() => { |
| 57 | + this.navCtrl.setRoot(AccountPage); |
| 58 | + }); |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + getPosts(searchbar) { |
| 63 | + let search = searchbar.srcElement.value; |
| 64 | + this.firebase.queriedList('posts', 'title', search).subscribe((posts) => { |
| 65 | + console.log("Got posts"); |
| 66 | + console.log(posts); |
| 67 | + if (posts.length > 0) { |
| 68 | + this.posts = [] |
| 69 | + this.posts = posts; |
| 70 | + } |
| 71 | + }); |
| 72 | + } |
| 73 | + |
| 74 | + viewPost(postID) { |
| 75 | + this.navCtrl.push(PostPage, { id: postID }) |
| 76 | + } |
| 77 | + |
| 78 | + viewProfile(uid) { |
| 79 | + this.navCtrl.push(ProfilePage, { uid: uid }) |
21 | 80 | } |
22 | 81 |
|
23 | 82 | } |
0 commit comments