|
|
|
@ -5,6 +5,7 @@ import { Activitylist } from 'src/app/models/activity';
|
|
|
|
|
import {DatasharingService} from '../../services/datasharing.service';
|
|
|
|
|
import {ActivityService} from 'src/app/services/activity/activity.service';
|
|
|
|
|
import {User} from 'src/app/models/user';
|
|
|
|
|
import {IErrorResponse} from '../../models/interfaces/IErrorResponse';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'home-feed',
|
|
|
|
@ -17,21 +18,25 @@ export class FeedComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
checked = false; // if the "I protected the environment."-box is checked
|
|
|
|
|
view = 'new';
|
|
|
|
|
empty: any;
|
|
|
|
|
textInputValue: string;
|
|
|
|
|
// id of the green activity
|
|
|
|
|
value: any;
|
|
|
|
|
|
|
|
|
|
parentSelectedPostList: Array<Post>;
|
|
|
|
|
parentSelectedPostList: Post[];
|
|
|
|
|
actionlist: Activitylist = new Activitylist();
|
|
|
|
|
|
|
|
|
|
loggedIn = false;
|
|
|
|
|
user: User;
|
|
|
|
|
errorOccurred: boolean;
|
|
|
|
|
|
|
|
|
|
private errorMessage: string;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private feedService: FeedService,
|
|
|
|
|
private data: DatasharingService,
|
|
|
|
|
private activityService: ActivityService
|
|
|
|
|
) { }
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.data.currentUserInfo.subscribe(user => {
|
|
|
|
@ -60,15 +65,23 @@ export class FeedComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
createPost(pElement, activityId: string) {
|
|
|
|
|
if (pElement && activityId && this.checked) {
|
|
|
|
|
this.feedService.createPostActivity(pElement.value, activityId);
|
|
|
|
|
this.feedService.createPostActivity(pElement.value, activityId).subscribe(() => {
|
|
|
|
|
pElement.value = '';
|
|
|
|
|
this.empty = '';
|
|
|
|
|
this.textInputValue = '';
|
|
|
|
|
this.view = 'new';
|
|
|
|
|
}, (error: IErrorResponse) => {
|
|
|
|
|
this.errorOccurred = true;
|
|
|
|
|
this.errorMessage = error.error.errors[0].message;
|
|
|
|
|
});
|
|
|
|
|
} else if (pElement) {
|
|
|
|
|
this.feedService.createPost(pElement.value);
|
|
|
|
|
this.feedService.createPost(pElement.value).subscribe(() => {
|
|
|
|
|
pElement.value = '';
|
|
|
|
|
this.empty = '';
|
|
|
|
|
this.textInputValue = '';
|
|
|
|
|
this.view = 'new';
|
|
|
|
|
}, (error: IErrorResponse) => {
|
|
|
|
|
this.errorOccurred = true;
|
|
|
|
|
this.errorMessage = error.error.errors[0].message;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -84,4 +97,11 @@ export class FeedComponent implements OnInit {
|
|
|
|
|
showMostLiked() {
|
|
|
|
|
this.feedService.getPosts('TOP');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the error message if one exists
|
|
|
|
|
*/
|
|
|
|
|
getErrorMessage() {
|
|
|
|
|
return this.errorMessage;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|