Commit 6574dcf055f5adb0497fb10d7b92fdc563cd0b30
Exists in
master
and in
26 other branches
Merge branch 'hide-empty-block' into 'master'
Hide empty blocks Depends on !19 See merge request !23
Showing
5 changed files
with
21 additions
and
3 deletions
Show diff stats
src/app/layout/boxes/display-blocks.filter.spec.ts
... | ... | @@ -82,5 +82,19 @@ describe("Filters", () => { |
82 | 82 | expect(filter.transform(<any>blocks, true, <noosfero.User>{})).toEqual([]); |
83 | 83 | done(); |
84 | 84 | }); |
85 | + | |
86 | + it("filter blocks when hide is true", done => { | |
87 | + let blocks = [{ hide: true }]; | |
88 | + let filter = new DisplayBlocks(translatorService); | |
89 | + expect(filter.transform(<any>blocks, true, null)).toEqual([]); | |
90 | + done(); | |
91 | + }); | |
92 | + | |
93 | + it("not filter blocks when hide is not true", done => { | |
94 | + let blocks = [{ id: 1, hide: false }, { id: 2 }]; | |
95 | + let filter = new DisplayBlocks(translatorService); | |
96 | + expect(filter.transform(<any>blocks, true, null)).toEqual(blocks); | |
97 | + done(); | |
98 | + }); | |
85 | 99 | }); |
86 | 100 | }); | ... | ... |
src/app/layout/boxes/display-blocks.filter.ts
... | ... | @@ -12,7 +12,8 @@ export class DisplayBlocks { |
12 | 12 | blocks = blocks || []; |
13 | 13 | for (let block of blocks) { |
14 | 14 | if (this.visible(block, isHomepage) && this.displayToUser(block, currentUser) && |
15 | - this.displayOnLanguage(block, this.translatorService.currentLanguage())) { | |
15 | + this.displayOnLanguage(block, this.translatorService.currentLanguage()) | |
16 | + && !block.hide) { | |
16 | 17 | selected.push(block); |
17 | 18 | } |
18 | 19 | } | ... | ... |
src/lib/ng-noosfero-api/interfaces/block.ts
src/plugins/comment_paragraph/block/discussion/discussion-block.component.spec.ts
... | ... | @@ -14,7 +14,7 @@ describe("Components", () => { |
14 | 14 | let helper: ComponentTestHelper<DiscussionBlockComponent>; |
15 | 15 | let settingsObj = {}; |
16 | 16 | let mockedBlockService = { |
17 | - getApiContent: (block: noosfero.Block): any => { | |
17 | + getApiContent: (content: any): any => { | |
18 | 18 | return Promise.resolve({ articles: [{ name: "article1" }], headers: (name: string) => { return name; } }); |
19 | 19 | } |
20 | 20 | }; |
... | ... | @@ -36,13 +36,14 @@ describe("Components", () => { |
36 | 36 | template: htmlTemplate, |
37 | 37 | directives: [DiscussionBlockComponent], |
38 | 38 | providers: providers, |
39 | - properties: {} | |
39 | + properties: { block: {} } | |
40 | 40 | }); |
41 | 41 | helper = new ComponentTestHelper<DiscussionBlockComponent>(cls, done); |
42 | 42 | }); |
43 | 43 | |
44 | 44 | it("get discussions from the block service", () => { |
45 | 45 | expect(helper.component.documents).toEqual([{ name: "article1" }]); |
46 | + expect(helper.component.block.hide).toEqual(false); | |
46 | 47 | }); |
47 | 48 | |
48 | 49 | it("go to article page when open a document", () => { | ... | ... |
src/plugins/comment_paragraph/block/discussion/discussion-block.component.ts
... | ... | @@ -20,6 +20,7 @@ export class DiscussionBlockComponent { |
20 | 20 | this.profile = this.owner; |
21 | 21 | this.blockService.getApiContent(this.block).then((content: any) => { |
22 | 22 | this.documents = content.articles; |
23 | + this.block.hide = !this.documents || this.documents.length === 0; | |
23 | 24 | }); |
24 | 25 | } |
25 | 26 | ... | ... |