Skip to content

Commit 7b56a77

Browse files
feat - posts manager
1 parent bc554d1 commit 7b56a77

File tree

12 files changed

+346
-55
lines changed

12 files changed

+346
-55
lines changed

.sourcemaps/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/edit-profile/edit-profile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ export class EditProfilePage {
116116
this.navCtrl.push(PhotoPage);
117117
}
118118

119-
}
119+
}

src/pages/home/home.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ <h3>It's iShallBe Sunday!</h3>
3232
<br><br>
3333
</ion-col>
3434
</ion-row>
35-
<ion-row *ngIf="!pin?.saturday" justify-content-center align-items-center style="height: 100%">
35+
<ion-row justify-content-center align-items-center style="height: 100%">
3636
<h4 class="slide-title" [innerHTML]="pin.title"></h4><br>
3737
<img class="pin-image" (click)="viewPin(pin.id)" *ngIf="pin?.image" src="{{ pin?.url }}" />
3838
<h5 class="affirmation" (click)="viewPin(pin.id)" [innerHTML]="pin.content"></h5>
3939
<button *ngIf="pin?.tuesday" (click)="openLink(pin.url)" text-center ion-button small round>
4040
<ion-icon name="play"></ion-icon>
4141
</button>
4242
</ion-row>
43-
<div *ngIf="!pin?.saturday" class="pin-interaction-counts" (click)="viewPin(pin.id)">
43+
<div class="pin-interaction-counts" (click)="viewPin(pin.id)">
4444
<p>
4545
<a *ngIf="pin.likeCount > 1 || pin.likeCount == 0" class="subdued">{{ pin?.likeCount}} Likes</a>
4646
<a *ngIf="pin.likeCount == 1" class="subdued">{{ pin?.likeCount}} Like</a>
4747
<a *ngIf="pin.commentCount > 1 || pin.commentCount == 0" class="subdued" margin-left>{{ pin?.commentCount}} Comments</a>
4848
<a *ngIf="pin.commentCount == 1" class="subdued" margin-left>{{ pin?.commentCount}} Comment</a>
4949
</p>
5050
</div>
51-
<ion-grid *ngIf="!pin?.saturday" class="pin-actions">
51+
<ion-grid class="pin-actions">
5252
<ion-row >
5353
<ion-col width-50 text-center (click)="togglePinLike(pin)">
5454
<ion-icon name="thumbs-up" color="primary" *ngIf="pin?.userLiked"></ion-icon>
@@ -60,13 +60,6 @@ <h5 class="affirmation" (click)="viewPin(pin.id)" [innerHTML]="pin.content"></h5
6060
</ion-row>
6161
</ion-grid>
6262
<br>
63-
<ion-row *ngIf="pin?.saturday">
64-
<ion-col text-center>
65-
<h1 class="slide-title" [innerHTML]="pin.title"></h1>
66-
<div class="saturday-icon"><b><ion-icon name="ios-arrow-round-forward"></ion-icon></b></div>
67-
<h2 class="affirmation" [innerHTML]="pin.content"></h2>
68-
</ion-col>
69-
</ion-row>
7063
</ion-slide>
7164
</ion-slides>
7265
</div>
@@ -86,7 +79,6 @@ <h2 class="affirmation" [innerHTML]="pin.content"></h2>
8679
<ion-avatar (click)="viewProfile(post.uid)" padding-top item-left>
8780
<img src="{{ post?.face }}">
8881
</ion-avatar>
89-
<ion-icon *ngIf="post.flagged" (click)="flaggedMessage()" name="alert" color="danger" item-right></ion-icon>
9082
<h2 padding-top ion-text color="primary" class="post-author">{{ post?.name }}</h2>
9183
<h3>
9284
<b>{{ post?.title}}</b>

src/pages/home/home.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,4 @@ export class HomePage {
487487
console.log('error in device registration:', err);
488488
});
489489
}
490-
}
490+
}

src/pages/post/post.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component } from '@angular/core';
22
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
33

44
import { ProfilePage } from '../profile/profile';
5+
import { HomePage } from '../home/home';
56

67
import { FirebaseProvider } from '../../providers/firebase/firebase';
78

@@ -118,7 +119,7 @@ export class PostPage {
118119
removePost() {
119120
let path = '/posts/' + this.post.id
120121
this.firebase.object(path).remove().then(() => {
121-
this.navCtrl.setRoot(ProfilePage);
122+
this.navCtrl.setRoot(ProfilePage);
122123
});
123124
}
124125

@@ -435,8 +436,13 @@ export class PostPage {
435436
{
436437
text: 'Confirm',
437438
handler: () => {
438-
this.flagPost().then(() => {
439-
this.removeFromFeed();
439+
this.post;
440+
this.removeFromFeed().then(() => {
441+
this.flagPost().then((token) => {
442+
this.addIDToFlaggedPost(token).then(() => {
443+
this.navCtrl.setRoot(HomePage);
444+
});
445+
});
440446
});
441447
}
442448
}
@@ -446,15 +452,21 @@ export class PostPage {
446452
}
447453

448454
flagPost() {
449-
let path = "/flagged/"
455+
let path = "/flagged/posts"
456+
this.post.flagged = true;
457+
this.post.onFeed = false;
450458
return this.firebase.list(path).push(this.post);
451459
}
452460

453461
removeFromFeed() {
454462
let path = "/posts/" + this.post.id;
463+
return this.firebase.object(path).remove();
464+
}
465+
466+
addIDToFlaggedPost(token) {
467+
let path = 'flagged/posts/' + token.key;
455468
let post = {
456-
flagged: true,
457-
onFeed: false
469+
flaggedID: token.key
458470
}
459471
return this.firebase.object(path).update(post)
460472
}

src/pages/posts-manager/posts-manager.html

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,64 @@
77
</ion-navbar>
88
</ion-header>
99

10-
<ion-content padding>
11-
10+
<ion-content>
11+
<header></header>
12+
<ion-row>
13+
<ion-col text-center>
14+
<h2>Reported Posts</h2>
15+
</ion-col>
16+
</ion-row>
17+
<div class="flagged-posts" *ngIf="this.thereAreFlaggedPosts">
18+
<ion-list>
19+
<ion-item (click)="viewPost(flaggedPost.id)" *ngFor="let flaggedPost of flaggedPosts">
20+
<ion-row text-center>
21+
<ion-col>
22+
{{ flaggedPost.title }}
23+
</ion-col>
24+
<ion-col>
25+
<button id="RestorePostButton" ion-button (click)="restorePost(flaggedPost)" color="primary" round>Restore Post</button>
26+
</ion-col>
27+
</ion-row>
28+
</ion-item>
29+
</ion-list>
30+
</div>
31+
<div class="flagged-posts" *ngIf="!this.thereAreFlaggedPosts">
32+
<ion-row>
33+
<ion-col text-center>
34+
<h6>There are no reported posts</h6>
35+
</ion-col>
36+
</ion-row>
37+
</div>
38+
<ion-searchbar (ionInput)="getPosts($event)"></ion-searchbar>
39+
<ion-list>
40+
<ion-card id="profilePosts" class="posts" *ngFor="let post of posts">
41+
<ion-item class="post-header">
42+
<ion-avatar (click)="viewProfile(post.uid)" padding-top item-left>
43+
<img src="{{ post?.face }}">
44+
</ion-avatar>
45+
<ion-icon *ngIf="post.flagged" (click)="flaggedMessage()" name="alert" color="danger" item-right></ion-icon>
46+
<h2 padding-top ion-text color="primary" class="post-author">{{ post?.name }}</h2>
47+
<h3>
48+
<b>{{ post?.title}}</b>
49+
</h3>
50+
<span class="post-time">
51+
{{ post?.time }}
52+
</span>
53+
</ion-item>
54+
<div text-center (click)="viewPost(post.$key)">
55+
<img class="full-image" src="{{ post?.url }}">
56+
<div class="post-content">
57+
<h2 text-center padding>{{ post?.content}}</h2>
58+
</div>
59+
<div (click)="viewPost(post?.$key)" class="interactions" padding-left>
60+
<a *ngIf="post.likeCount > 1 || post.likeCount == 0" class="subdued">{{ post?.likeCount}} Likes</a>
61+
<a *ngIf="post.likeCount == 1" class="subdued">{{ post?.likeCount}} Like</a>
62+
<a *ngIf="post.commentCount > 1 || post.commentCount == 0" class="subdued" margin-left>{{ post?.commentCount}} Comments</a>
63+
<a *ngIf="post.commentCount == 1" class="subdued" margin-left>{{ post?.commentCount}} Comment</a>
64+
<br>
65+
<br>
66+
</div>
67+
</div>
68+
</ion-card>
69+
</ion-list>
1270
</ion-content>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
11
page-posts-manager {
2+
3+
.flagged-posts {
4+
border-top: thick solid color($colors, primary);
5+
border-bottom: thick solid color($colors, primary);
6+
}
27

8+
.slide-title {
9+
font-weight: bold
10+
}
11+
12+
.slide-image {
13+
max-height: 150px;
14+
}
15+
16+
.feature-slides {
17+
background-color: color($colors, light-yellow);
18+
}
19+
20+
.post-header {
21+
background: linear-gradient(to Top, #faf6ed, #fff);
22+
}
23+
24+
.full-image {
25+
border-top: thick solid color($colors, secondary);
26+
border-bottom: thick solid color($colors, secondary);
27+
}
28+
29+
.post-body {
30+
border-top: 1px solid $borderColor;
31+
border-bottom: 1px solid $borderColor;
32+
33+
p {
34+
font-size: 0.8em;
35+
}
36+
37+
a.subdued {
38+
color: $textColor;
39+
font-size: 0.8em;
40+
}
41+
}
42+
43+
.item-complex{
44+
padding-right: 0 !important;
45+
}
46+
47+
.post-author {
48+
align-self: center;
49+
}
50+
51+
h3.post-author {
52+
font-weight: normal;
53+
}
54+
55+
356
}

src/pages/posts-manager/posts-manager.spec.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,40 @@ describe('PostsManagerPage', () => {
130130

131131
it('should be created', () => {
132132
expect(component instanceof PostsManagerPage).toBe(true);
133-
});
133+
});
134+
135+
it('should display header component', () => {
136+
let de: DebugElement;
137+
let el: HTMLElement;
138+
de = fixture.debugElement.query(By.css('header'));
139+
el = de.nativeElement.src;
140+
expect(el).toBeUndefined();
141+
});
142+
143+
it('should have title called Posts Manager', () => {
144+
expect(component.title).toBe('Posts Manager');
145+
});
134146

135-
it('should have title called Manage Posts', () => {
136-
expect(component.title).toBe('Manage Posts');
147+
it('should display reported posts', () => {
148+
let de: DebugElement;
149+
let el: HTMLElement;
150+
de = fixture.debugElement.query(By.css('h2'));
151+
el = de.nativeElement.innerHTML
152+
expect(el).toContain('Reported Posts')
137153
});
138154

155+
it('should load flagged posts on view load', () => {
156+
spyOn(component, 'loadFlaggedPosts').and.returnValue({ subscribe: () => {}});
157+
component.ionViewDidLoad();
158+
expect(component.loadFlaggedPosts).toHaveBeenCalled();
159+
});
160+
161+
it('should restore post', fakeAsync(() => {
162+
component.firebase.list('testPath').push('post')
163+
tick();
164+
fixture.detectChanges();
165+
expect(listSpy).toHaveBeenCalled();
166+
expect(pushSpy).toHaveBeenCalled();
167+
}));
168+
139169
});
Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,82 @@
11
import { Component } from '@angular/core';
22
import { IonicPage, NavController, NavParams } from 'ionic-angular';
33

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+
410
@IonicPage()
511
@Component({
612
selector: 'page-posts-manager',
713
templateUrl: 'posts-manager.html',
814
})
915
export class PostsManagerPage {
1016

11-
title = 'Manage Posts';
17+
title = 'Posts Manager';
18+
flaggedPosts: any;
19+
thereAreFlaggedPosts = false;
20+
posts: any;
21+
queryParams: any;
1222

1323
constructor(
14-
public navCtrl: NavController,
15-
public navParams: NavParams
24+
private navCtrl: NavController,
25+
private navParams: NavParams,
26+
private firebase: FirebaseProvider
1627
) {
1728
}
1829

1930
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 })
2180
}
2281

2382
}

0 commit comments

Comments
 (0)