Commit 8c7b12aa8b8c987c39c5b7e178df0f4ef932af06
1 parent
9cb82c98
Exists in
master
and in
26 other branches
refactoring communities block
Showing
10 changed files
with
102 additions
and
100 deletions
Show diff stats
src/app/layout/blocks/communities-block/communities-block.component.spec.ts
@@ -1,51 +0,0 @@ | @@ -1,51 +0,0 @@ | ||
1 | -import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; | ||
2 | -import {Provider, Input, provide, Component} from 'ng-forward'; | ||
3 | - | ||
4 | -import {CommunitiesBlockComponent} from './communities-block.component'; | ||
5 | - | ||
6 | -const htmlTemplate: string = '<noosfero-communities-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-communities-block>'; | ||
7 | - | ||
8 | -const tcb = new TestComponentBuilder(); | ||
9 | - | ||
10 | -describe("Components", () => { | ||
11 | - describe("Communities Block Component", () => { | ||
12 | - | ||
13 | - beforeEach(angular.mock.module("templates")); | ||
14 | - | ||
15 | - let state = jasmine.createSpyObj("state", ["go"]); | ||
16 | - let providers = [ | ||
17 | - new Provider('truncateFilter', { useValue: () => { } }), | ||
18 | - new Provider('stripTagsFilter', { useValue: () => { } }), | ||
19 | - new Provider('$state', { useValue: state }), | ||
20 | - new Provider('CommunityService', { | ||
21 | - useValue: { | ||
22 | - getByOwner: (owner: any, params: any): any => { | ||
23 | - return Promise.resolve({ data: [{ identifier: "community1" }] }); | ||
24 | - } | ||
25 | - } | ||
26 | - }), | ||
27 | - ]; | ||
28 | - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [CommunitiesBlockComponent], providers: providers }) | ||
29 | - class BlockContainerComponent { | ||
30 | - block = { type: 'Block', settings: {} }; | ||
31 | - owner = { name: 'profile-name' }; | ||
32 | - } | ||
33 | - | ||
34 | - it("get communities", done => { | ||
35 | - tcb.createAsync(BlockContainerComponent).then(fixture => { | ||
36 | - let block: CommunitiesBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
37 | - expect(block.profiles).toEqual([{ identifier: "community1" }]); | ||
38 | - done(); | ||
39 | - }); | ||
40 | - }); | ||
41 | - | ||
42 | - it("render the profile image for each community", done => { | ||
43 | - tcb.createAsync(BlockContainerComponent).then(fixture => { | ||
44 | - fixture.debugElement.getLocal("$rootScope").$apply(); | ||
45 | - expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); | ||
46 | - done(); | ||
47 | - }); | ||
48 | - }); | ||
49 | - | ||
50 | - }); | ||
51 | -}); |
src/app/layout/blocks/communities-block/communities-block.component.ts
@@ -1,24 +0,0 @@ | @@ -1,24 +0,0 @@ | ||
1 | -import {Input, Inject, Component} from "ng-forward"; | ||
2 | -import {CommunityService} from "../../../../lib/ng-noosfero-api/http/community.service"; | ||
3 | - | ||
4 | -@Component({ | ||
5 | - selector: "noosfero-communities-block", | ||
6 | - templateUrl: 'app/layout/blocks/communities-block/communities-block.html', | ||
7 | -}) | ||
8 | -@Inject(CommunityService) | ||
9 | -export class CommunitiesBlockComponent { | ||
10 | - | ||
11 | - @Input() block: noosfero.Block; | ||
12 | - @Input() owner: noosfero.Profile; | ||
13 | - | ||
14 | - profiles: any = []; | ||
15 | - | ||
16 | - constructor(private communityService: CommunityService) { } | ||
17 | - | ||
18 | - ngOnInit() { | ||
19 | - let limit: number = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5; | ||
20 | - this.communityService.getByOwner(this.owner, { limit: limit }).then((result: noosfero.RestResult<noosfero.Community[]>) => { | ||
21 | - this.profiles = result.data; | ||
22 | - }); | ||
23 | - } | ||
24 | -} |
src/app/layout/blocks/communities-block/communities-block.html
src/app/layout/blocks/communities-block/communities-block.scss
@@ -1,16 +0,0 @@ | @@ -1,16 +0,0 @@ | ||
1 | -.communities-block { | ||
2 | - .profile { | ||
3 | - margin: 10px; | ||
4 | - img, i.profile-image { | ||
5 | - width: 60px; | ||
6 | - } | ||
7 | - img { | ||
8 | - display: inline-block; | ||
9 | - vertical-align: top; | ||
10 | - } | ||
11 | - i.profile-image { | ||
12 | - text-align: center; | ||
13 | - font-size: 4.5em; | ||
14 | - } | ||
15 | - } | ||
16 | -} |
src/app/layout/blocks/communities/communities-block.component.spec.ts
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; | ||
2 | +import {Provider, Input, provide, Component} from 'ng-forward'; | ||
3 | + | ||
4 | +import {CommunitiesBlockComponent} from './communities-block.component'; | ||
5 | + | ||
6 | +const htmlTemplate: string = '<noosfero-communities-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-communities-block>'; | ||
7 | + | ||
8 | +const tcb = new TestComponentBuilder(); | ||
9 | + | ||
10 | +describe("Components", () => { | ||
11 | + describe("Communities Block Component", () => { | ||
12 | + | ||
13 | + beforeEach(angular.mock.module("templates")); | ||
14 | + | ||
15 | + let state = jasmine.createSpyObj("state", ["go"]); | ||
16 | + let providers = [ | ||
17 | + new Provider('truncateFilter', { useValue: () => { } }), | ||
18 | + new Provider('stripTagsFilter', { useValue: () => { } }), | ||
19 | + new Provider('$state', { useValue: state }), | ||
20 | + new Provider('CommunityService', { | ||
21 | + useValue: { | ||
22 | + getByOwner: (owner: any, params: any): any => { | ||
23 | + return Promise.resolve({ data: [{ identifier: "community1" }] }); | ||
24 | + } | ||
25 | + } | ||
26 | + }), | ||
27 | + ]; | ||
28 | + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [CommunitiesBlockComponent], providers: providers }) | ||
29 | + class BlockContainerComponent { | ||
30 | + block = { type: 'Block', settings: {} }; | ||
31 | + owner = { name: 'profile-name' }; | ||
32 | + } | ||
33 | + | ||
34 | + it("get communities", done => { | ||
35 | + tcb.createAsync(BlockContainerComponent).then(fixture => { | ||
36 | + let block: CommunitiesBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
37 | + expect(block.profiles).toEqual([{ identifier: "community1" }]); | ||
38 | + done(); | ||
39 | + }); | ||
40 | + }); | ||
41 | + | ||
42 | + it("render the profile image for each community", done => { | ||
43 | + tcb.createAsync(BlockContainerComponent).then(fixture => { | ||
44 | + fixture.debugElement.getLocal("$rootScope").$apply(); | ||
45 | + expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); | ||
46 | + done(); | ||
47 | + }); | ||
48 | + }); | ||
49 | + | ||
50 | + }); | ||
51 | +}); |
src/app/layout/blocks/communities/communities-block.component.ts
0 → 100644
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +import {Input, Inject, Component} from "ng-forward"; | ||
2 | +import {CommunityService} from "../../../../lib/ng-noosfero-api/http/community.service"; | ||
3 | + | ||
4 | +@Component({ | ||
5 | + selector: "noosfero-communities-block", | ||
6 | + templateUrl: 'app/layout/blocks/communities/communities-block.html', | ||
7 | +}) | ||
8 | +@Inject(CommunityService) | ||
9 | +export class CommunitiesBlockComponent { | ||
10 | + | ||
11 | + @Input() block: noosfero.Block; | ||
12 | + @Input() owner: noosfero.Profile; | ||
13 | + | ||
14 | + profiles: any = []; | ||
15 | + | ||
16 | + constructor(private communityService: CommunityService) { } | ||
17 | + | ||
18 | + ngOnInit() { | ||
19 | + let limit: number = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5; | ||
20 | + this.communityService.getByOwner(this.owner, { limit: limit }).then((result: noosfero.RestResult<noosfero.Community[]>) => { | ||
21 | + this.profiles = result.data; | ||
22 | + }); | ||
23 | + } | ||
24 | +} |
src/app/layout/blocks/communities/communities-block.html
0 → 100644
src/app/layout/blocks/communities/communities-block.scss
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +.communities-block { | ||
2 | + .profile { | ||
3 | + margin: 10px; | ||
4 | + img, i.profile-image { | ||
5 | + width: 60px; | ||
6 | + } | ||
7 | + img { | ||
8 | + display: inline-block; | ||
9 | + vertical-align: top; | ||
10 | + } | ||
11 | + i.profile-image { | ||
12 | + text-align: center; | ||
13 | + font-size: 4.5em; | ||
14 | + } | ||
15 | + } | ||
16 | +} |
src/app/main/main.component.ts
@@ -16,7 +16,7 @@ import {ProfileImageBlockComponent} from "../layout/blocks/profile-image-block/p | @@ -16,7 +16,7 @@ import {ProfileImageBlockComponent} from "../layout/blocks/profile-image-block/p | ||
16 | import {RawHTMLBlockComponent} from "../layout/blocks/raw-html/raw-html.component"; | 16 | import {RawHTMLBlockComponent} from "../layout/blocks/raw-html/raw-html.component"; |
17 | 17 | ||
18 | import {MembersBlockComponent} from "./../layout/blocks/members-block/members-block.component"; | 18 | import {MembersBlockComponent} from "./../layout/blocks/members-block/members-block.component"; |
19 | -import {CommunitiesBlockComponent} from "./../layout/blocks/communities-block/communities-block.component"; | 19 | +import {CommunitiesBlockComponent} from "./../layout/blocks/communities/communities-block.component"; |
20 | import {NoosferoTemplate} from "../shared/pipes/noosfero-template.filter"; | 20 | import {NoosferoTemplate} from "../shared/pipes/noosfero-template.filter"; |
21 | import {DateFormat} from "../shared/pipes/date-format.filter"; | 21 | import {DateFormat} from "../shared/pipes/date-format.filter"; |
22 | 22 | ||
@@ -79,11 +79,11 @@ export class EnvironmentContent { | @@ -79,11 +79,11 @@ export class EnvironmentContent { | ||
79 | * NoosferoTemplate, DateFormat, RawHTMLBlock | 79 | * NoosferoTemplate, DateFormat, RawHTMLBlock |
80 | * @description | 80 | * @description |
81 | * The Main controller for the Noosfero Angular Theme application. | 81 | * The Main controller for the Noosfero Angular Theme application. |
82 | - * | 82 | + * |
83 | * The main route '/' is defined as the URL for this controller, which routes | 83 | * The main route '/' is defined as the URL for this controller, which routes |
84 | * requests to the {@link main.MainContentComponent} controller and also, the '/profile' route, | 84 | * requests to the {@link main.MainContentComponent} controller and also, the '/profile' route, |
85 | - * which routes requests to the {@link profile.Profile} controller. See {@link profile.Profile} | ||
86 | - * for more details on how various Noosfero profiles are rendered. | 85 | + * which routes requests to the {@link profile.Profile} controller. See {@link profile.Profile} |
86 | + * for more details on how various Noosfero profiles are rendered. | ||
87 | */ | 87 | */ |
88 | @Component({ | 88 | @Component({ |
89 | selector: 'main', | 89 | selector: 'main', |