Skip to content

Commit 77fab39

Browse files
feat - users manager
1 parent 7c00a6d commit 77fab39

File tree

11 files changed

+212
-34
lines changed

11 files changed

+212
-34
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/home/home.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export class HomePage {
5353
this.postsLoaded = false;
5454
this.requestUID().then((uid) => {
5555
this.uid = uid;
56-
this.loadHome();
56+
this.checkIfProfileBlocked().subscribe(() => {
57+
this.loadHome();
58+
})
5759
});
5860
this.initPushNotification();
5961
}
@@ -71,7 +73,6 @@ export class HomePage {
7173
}
7274

7375
loadHome() {
74-
this.checkIfProfileBlocked();
7576
this.startLoader();
7677
this.timestampFeed().subscribe(() => {
7778
if (this.feedTimestamp.day == 'Sunday') { this.sunday = true }
@@ -234,10 +235,14 @@ export class HomePage {
234235
}
235236

236237
checkIfProfileBlocked() {
237-
this.requestProfile().subscribe((profile) => {
238-
if (profile.blocked) {
239-
this.handleBlocked();
240-
}
238+
return Observable.create((observer) => {
239+
return this.requestProfile().subscribe((profile) => {
240+
if (profile.blocked) {
241+
this.handleBlocked();
242+
} else {
243+
observer.next()
244+
}
245+
});
241246
});
242247
}
243248

@@ -287,6 +292,8 @@ export class HomePage {
287292

288293
handleBlocked() {
289294
this.navCtrl.setRoot(LoginPage);
295+
this.firebase.logOut();
296+
this.storage.clear();
290297
this.presentBlocked();
291298
}
292299

@@ -296,7 +303,7 @@ export class HomePage {
296303
message: 'This account has been blocked',
297304
buttons: [
298305
{
299-
text: 'Okay',
306+
text: 'Ok',
300307
}
301308
]
302309
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<header></header>
1212
<ion-row *ngIf="this.thereAreFlaggedPosts">
1313
<ion-col text-center>
14-
<h2>Reported Posts</h2>
14+
<h3>Reported Posts</h3>
1515
</ion-col>
1616
</ion-row>
1717
<div *ngIf="this.thereAreFlaggedPosts" class="flagged-posts">

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,22 @@ describe('PostsManagerPage', () => {
144144
expect(component.title).toBe('Posts Manager');
145145
});
146146

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')
153-
});
154-
155147
it('should load flagged posts on view load', () => {
156148
spyOn(component, 'loadFlaggedPosts').and.returnValue({ subscribe: () => {}});
157149
component.ionViewDidLoad();
158150
expect(component.loadFlaggedPosts).toHaveBeenCalled();
159151
});
160152

153+
it('should display reported posts if there are any', () => {
154+
component.thereAreFlaggedPosts = true;
155+
fixture.detectChanges();
156+
let de: DebugElement;
157+
let el: HTMLElement;
158+
de = fixture.debugElement.query(By.css('h3'));
159+
el = de.nativeElement.innerHTML
160+
expect(el).toContain('Reported Posts')
161+
});
162+
161163
it('should restore post', fakeAsync(() => {
162164
component.firebase.list('testPath').push('post')
163165
tick();

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ export class PostsManagerPage {
3434
loadFlaggedPosts() {
3535
let path = 'flagged/posts';
3636
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)
4037
if (flaggedPosts.length > 0) {
4138
this.flaggedPosts = flaggedPosts;
4239
this.thereAreFlaggedPosts = true;
@@ -45,8 +42,6 @@ export class PostsManagerPage {
4542
}
4643

4744
restorePost(post) {
48-
console.log("Restoring post");
49-
console.log("post");
5045
post.onFeed = true;
5146
post.flagged = false;
5247
post.flaggedId = null;
@@ -62,8 +57,6 @@ export class PostsManagerPage {
6257
getPosts(searchbar) {
6358
let search = searchbar.srcElement.value;
6459
this.firebase.queriedList('posts', 'title', search).subscribe((posts) => {
65-
console.log("Got posts");
66-
console.log(posts);
6760
if (posts.length > 0) {
6861
this.posts = []
6962
this.posts = posts;

src/pages/profile/profile.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<ion-icon name="ios-options"></ion-icon>
1010
</button>
1111
</ion-buttons>
12+
<ion-buttons *ngIf="editor" end>
13+
<button ion-button icon-only (click)="blockUser()">
14+
<ion-icon name="ios-flag"></ion-icon>
15+
</button>
16+
</ion-buttons>
1217
</ion-navbar>
1318
</ion-header>
1419

src/pages/profile/profile.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class ProfilePage {
3434
twitter: any;
3535
linkedin: any;
3636
refreshing: any;
37+
editor = false;
3738

3839
constructor(
3940
private navCtrl: NavController,
@@ -60,6 +61,8 @@ export class ProfilePage {
6061
if (mine) {
6162
this.mine = true;
6263
this.checkForFlaggedPosts();
64+
} else {
65+
this.checkIfEditor();
6366
}
6467
});
6568
this.syncProfile();
@@ -137,6 +140,15 @@ export class ProfilePage {
137140
});
138141
}
139142

143+
checkIfEditor() {
144+
this.requestUID().then((uid) => {
145+
let path = 'users/' + uid
146+
this.firebase.object(path).subscribe((user) => {
147+
if (user.editor) this.editor = true;
148+
});
149+
});
150+
}
151+
140152
requestUID() {
141153
return this.storage.ready().then(() => {
142154
return this.storage.get(('uid'));
@@ -372,4 +384,25 @@ export class ProfilePage {
372384
this.navCtrl.push(CreateStatementPage);
373385
}
374386

387+
blockUser() {
388+
console.log("Block user clicked");
389+
this.profile.blocked = true;
390+
let path = '/users/' + this.uid;
391+
this.firebase.object(path).update(this.profile).then(() => {
392+
this.firebase.list('flagged/users').push(this.profile).then((token) => {
393+
this.addIDToFlaggedUser(token).then(() => {
394+
this.navCtrl.setRoot(AccountPage);
395+
});
396+
});
397+
});
398+
}
399+
400+
addIDToFlaggedUser(token) {
401+
let path = 'flagged/users/' + token.key;
402+
let post = {
403+
flaggedID: token.key
404+
}
405+
return this.firebase.object(path).update(post)
406+
}
407+
375408
}

src/pages/users-manager/users-manager.html

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,52 @@
66
<ion-title color='primary'>{{title}}</ion-title>
77
</ion-navbar>
88
</ion-header>
9-
10-
11-
<ion-content padding>
12-
9+
<ion-content>
10+
<header></header>
11+
<ion-row *ngIf="this.thereAreBlockedUsers">
12+
<ion-col text-center>
13+
<h3>Blocked Users</h3>
14+
</ion-col>
15+
</ion-row>
16+
<div *ngIf="this.thereAreBlockedUsers" class="flagged-users">
17+
<ion-list>
18+
<ion-item (click)="viewProfile(blockedUser.id)" *ngFor="let blockedUser of blockedUsers">
19+
<ion-row text-center>
20+
<ion-col>
21+
{{ blockedUser.name }}
22+
</ion-col>
23+
<ion-col>
24+
<button id="unblockUserButton" ion-button (click)="unblockUser(blockedUser)" color="primary" round>Unblock User</button>
25+
</ion-col>
26+
</ion-row>
27+
</ion-item>
28+
</ion-list>
29+
</div>
30+
<div class="flagged-users" *ngIf="!this.thereAreBlockedUsers">
31+
<ion-row>
32+
<ion-col text-center>
33+
<h6>There are no blocked users</h6>
34+
</ion-col>
35+
</ion-row>
36+
</div>
37+
<ion-searchbar placeholder="Search By User Email" (ionInput)="getUsers($event)"></ion-searchbar>
38+
<ion-card (click)="viewProfile(user.uid)" *ngFor="let user of users">
39+
<ion-row text-center>
40+
<ion-col>
41+
<b>
42+
<h4>{{ user?.name}} </h4>
43+
</b>
44+
</ion-col>
45+
</ion-row>
46+
<ion-row text-center>
47+
<ion-col>
48+
<img class="avatar" src="{{ user?.photo }}">
49+
</ion-col>
50+
</ion-row>
51+
<ion-row text-center *ngIf="user?.bio">
52+
<ion-col>
53+
<h6 class="bio">{{ user?.bio}} </h6>
54+
</ion-col>
55+
</ion-row>
56+
</ion-card>
1357
</ion-content>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
page-users-manager {
22

3+
.flagged-users {
4+
border-top: thick solid color($colors, primary);
5+
border-bottom: thick solid color($colors, primary);
6+
}
7+
8+
.avatar {
9+
display: round;
10+
margin-left: auto ;
11+
margin-right: auto;
12+
max-width: 150px;
13+
border-radius: 50%;
14+
text-align: center;
15+
}
16+
317
}

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,40 @@ describe('UsersManagerPage', () => {
131131
it('should be created', () => {
132132
expect(component instanceof UsersManagerPage).toBe(true);
133133
});
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+
});
134142

135-
it('should have title called Manage Users', () => {
136-
expect(component.title).toBe('Manage Users');
143+
it('should have title called Users Manager', () => {
144+
expect(component.title).toBe('Users Manager');
145+
});
146+
147+
it('should load blocked users on view load', () => {
148+
spyOn(component, 'loadBlockedUsers').and.returnValue({ subscribe: () => {}});
149+
component.ionViewDidLoad();
150+
expect(component.loadBlockedUsers).toHaveBeenCalled();
137151
});
138152

153+
it('should display blocked users if there are any', () => {
154+
component.thereAreBlockedUsers = true;
155+
fixture.detectChanges();
156+
let de: DebugElement;
157+
let el: HTMLElement;
158+
de = fixture.debugElement.query(By.css('h3'));
159+
el = de.nativeElement.innerHTML
160+
expect(el).toContain('Blocked Users')
161+
});
162+
163+
it('should unblock user', fakeAsync(() => {
164+
component.firebase.list('testPath').push('user')
165+
tick();
166+
fixture.detectChanges();
167+
expect(listSpy).toHaveBeenCalled();
168+
expect(pushSpy).toHaveBeenCalled();
169+
}));
139170
});

0 commit comments

Comments
 (0)