Commit 0f9e6899064522e9c4fad7d63930a49326bf2e34
1 parent
eb097fe2
Exists in
master
and in
26 other branches
Use api_content to get articles for discussion block
Showing
2 changed files
with
62 additions
and
30 deletions
Show diff stats
src/plugins/comment_paragraph/block/discussion/discussion-block.component.spec.ts
0 → 100644
@@ -0,0 +1,54 @@ | @@ -0,0 +1,54 @@ | ||
1 | +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; | ||
2 | +import {Provider, Input, provide, Component} from 'ng-forward'; | ||
3 | +import {provideFilters} from '../../../../spec/helpers'; | ||
4 | +import {DiscussionBlockComponent} from './discussion-block.component'; | ||
5 | +import {ComponentTestHelper, createClass} from './../../../../spec/component-test-helper'; | ||
6 | + | ||
7 | +const htmlTemplate: string = '<noosfero-comment-paragraph-plugin-discussion-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-comment-paragraph-plugin-discussion-block>'; | ||
8 | + | ||
9 | +const tcb = new TestComponentBuilder(); | ||
10 | + | ||
11 | +describe("Components", () => { | ||
12 | + describe("Discussion Block Component", () => { | ||
13 | + | ||
14 | + let helper: ComponentTestHelper<DiscussionBlockComponent>; | ||
15 | + let settingsObj = {}; | ||
16 | + let mockedBlockService = { | ||
17 | + getApiContent: (block: noosfero.Block): any => { | ||
18 | + return Promise.resolve({ articles: [{ name: "article1" }], headers: (name: string) => { return name; } }); | ||
19 | + } | ||
20 | + }; | ||
21 | + let profile = { name: 'profile-name' }; | ||
22 | + | ||
23 | + let state = jasmine.createSpyObj("state", ["go"]); | ||
24 | + | ||
25 | + let providers = [ | ||
26 | + new Provider('$state', { useValue: state }), | ||
27 | + new Provider('BlockService', { | ||
28 | + useValue: mockedBlockService | ||
29 | + }), | ||
30 | + ].concat(provideFilters("truncateFilter", "stripTagsFilter", "translateFilter", "amDateFormatFilter")); | ||
31 | + | ||
32 | + beforeEach(angular.mock.module("templates")); | ||
33 | + | ||
34 | + beforeEach((done) => { | ||
35 | + let cls = createClass({ | ||
36 | + template: htmlTemplate, | ||
37 | + directives: [DiscussionBlockComponent], | ||
38 | + providers: providers, | ||
39 | + properties: {} | ||
40 | + }); | ||
41 | + helper = new ComponentTestHelper<DiscussionBlockComponent>(cls, done); | ||
42 | + }); | ||
43 | + | ||
44 | + it("get discussions from the block service", () => { | ||
45 | + expect(helper.component.documents).toEqual([{ name: "article1" }]); | ||
46 | + }); | ||
47 | + | ||
48 | + it("go to article page when open a document", () => { | ||
49 | + let block = helper.component; | ||
50 | + block.openDocument({ path: "path", profile: { identifier: "identifier" } }); | ||
51 | + expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" }); | ||
52 | + }); | ||
53 | + }); | ||
54 | +}); |
src/plugins/comment_paragraph/block/discussion/discussion-block.component.ts
1 | import {Component, Inject, Input} from "ng-forward"; | 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 | @Component({ | 4 | @Component({ |
5 | selector: "noosfero-comment-paragraph-plugin-discussion-block", | 5 | selector: "noosfero-comment-paragraph-plugin-discussion-block", |
6 | templateUrl: 'plugins/comment_paragraph/block/discussion/discussion-block.html' | 6 | templateUrl: 'plugins/comment_paragraph/block/discussion/discussion-block.html' |
7 | }) | 7 | }) |
8 | -@Inject(ArticleService, "$state") | 8 | +@Inject(BlockService, "$state") |
9 | export class DiscussionBlockComponent { | 9 | export class DiscussionBlockComponent { |
10 | 10 | ||
11 | @Input() block: any; | 11 | @Input() block: any; |
12 | @Input() owner: any; | 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 | ngOnInit() { | 19 | ngOnInit() { |
22 | this.profile = this.owner; | 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 | openDocument(article: any) { | 26 | openDocument(article: any) { |