Commit d299e48d17813e7e44c406436299c410dee5e23e
1 parent
eb097fe2
Use api_content to get articles for discussion block
Showing
1 changed file
with
8 additions
and
30 deletions
Show diff stats
src/plugins/comment_paragraph/block/discussion/discussion-block.component.ts
| 1 | 1 | import {Component, Inject, Input} from "ng-forward"; |
| 2 | -import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service"; | |
| 2 | +import {BlockService} from "../../../../lib/ng-noosfero-api/http/block.service"; | |
| 3 | 3 | |
| 4 | 4 | @Component({ |
| 5 | 5 | selector: "noosfero-comment-paragraph-plugin-discussion-block", |
| 6 | 6 | templateUrl: 'plugins/comment_paragraph/block/discussion/discussion-block.html' |
| 7 | 7 | }) |
| 8 | -@Inject(ArticleService, "$state") | |
| 8 | +@Inject(BlockService, "$state") | |
| 9 | 9 | export class DiscussionBlockComponent { |
| 10 | 10 | |
| 11 | 11 | @Input() block: any; |
| 12 | 12 | @Input() owner: any; |
| 13 | 13 | |
| 14 | - profile: any; | |
| 15 | - documents: any; | |
| 14 | + profile: noosfero.Profile; | |
| 15 | + documents: Array<noosfero.Article>; | |
| 16 | 16 | |
| 17 | - documentsLoaded: boolean = false; | |
| 18 | - | |
| 19 | - constructor(private articleService: ArticleService, private $state: any) { } | |
| 17 | + constructor(private blockService: BlockService, private $state: any) { } | |
| 20 | 18 | |
| 21 | 19 | ngOnInit() { |
| 22 | 20 | this.profile = this.owner; |
| 23 | - this.documents = []; | |
| 24 | - | |
| 25 | - let limit = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 50; | |
| 26 | - let params: any = { content_type: 'CommentParagraphPlugin::Discussion', per_page: limit, order: 'start_date DESC' }; | |
| 27 | - let now = new Date().toISOString(); | |
| 28 | - switch (this.block.settings['discussion_status']) { | |
| 29 | - case 0: | |
| 30 | - params['from_start_date'] = now; | |
| 31 | - break; | |
| 32 | - case 1: | |
| 33 | - params['until_start_date'] = now; | |
| 34 | - params['from_end_date'] = now; | |
| 35 | - break; | |
| 36 | - case 2: | |
| 37 | - params['until_end_date'] = now; | |
| 38 | - break; | |
| 39 | - } | |
| 40 | - console.log(this.block.settings['discussion_status']); | |
| 41 | - this.articleService.getByProfile(this.profile, params) | |
| 42 | - .then((result: noosfero.RestResult<noosfero.Article[]>) => { | |
| 43 | - this.documents = <noosfero.Article[]>result.data; | |
| 44 | - this.documentsLoaded = true; | |
| 45 | - }); | |
| 21 | + this.blockService.getApiContent(this.block).then((content: any) => { | |
| 22 | + this.documents = content.articles; | |
| 23 | + }); | |
| 46 | 24 | } |
| 47 | 25 | |
| 48 | 26 | openDocument(article: any) { | ... | ... |