From 8c7b12aa8b8c987c39c5b7e178df0f4ef932af06 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Tue, 10 May 2016 09:09:41 -0300 Subject: [PATCH] refactoring communities block --- src/app/layout/blocks/communities-block/communities-block.component.spec.ts | 51 --------------------------------------------------- src/app/layout/blocks/communities-block/communities-block.component.ts | 24 ------------------------ src/app/layout/blocks/communities-block/communities-block.html | 5 ----- src/app/layout/blocks/communities-block/communities-block.scss | 16 ---------------- src/app/layout/blocks/communities/communities-block.component.spec.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/app/layout/blocks/communities/communities-block.component.ts | 24 ++++++++++++++++++++++++ src/app/layout/blocks/communities/communities-block.html | 5 +++++ src/app/layout/blocks/communities/communities-block.scss | 16 ++++++++++++++++ src/app/layout/blocks/communities/index.ts | 2 ++ src/app/main/main.component.ts | 8 ++++---- 10 files changed, 102 insertions(+), 100 deletions(-) delete mode 100644 src/app/layout/blocks/communities-block/communities-block.component.spec.ts delete mode 100644 src/app/layout/blocks/communities-block/communities-block.component.ts delete mode 100644 src/app/layout/blocks/communities-block/communities-block.html delete mode 100644 src/app/layout/blocks/communities-block/communities-block.scss create mode 100644 src/app/layout/blocks/communities/communities-block.component.spec.ts create mode 100644 src/app/layout/blocks/communities/communities-block.component.ts create mode 100644 src/app/layout/blocks/communities/communities-block.html create mode 100644 src/app/layout/blocks/communities/communities-block.scss create mode 100644 src/app/layout/blocks/communities/index.ts diff --git a/src/app/layout/blocks/communities-block/communities-block.component.spec.ts b/src/app/layout/blocks/communities-block/communities-block.component.spec.ts deleted file mode 100644 index bc6eafd..0000000 --- a/src/app/layout/blocks/communities-block/communities-block.component.spec.ts +++ /dev/null @@ -1,51 +0,0 @@ -import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; -import {Provider, Input, provide, Component} from 'ng-forward'; - -import {CommunitiesBlockComponent} from './communities-block.component'; - -const htmlTemplate: string = ''; - -const tcb = new TestComponentBuilder(); - -describe("Components", () => { - describe("Communities Block Component", () => { - - beforeEach(angular.mock.module("templates")); - - let state = jasmine.createSpyObj("state", ["go"]); - let providers = [ - new Provider('truncateFilter', { useValue: () => { } }), - new Provider('stripTagsFilter', { useValue: () => { } }), - new Provider('$state', { useValue: state }), - new Provider('CommunityService', { - useValue: { - getByOwner: (owner: any, params: any): any => { - return Promise.resolve({ data: [{ identifier: "community1" }] }); - } - } - }), - ]; - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [CommunitiesBlockComponent], providers: providers }) - class BlockContainerComponent { - block = { type: 'Block', settings: {} }; - owner = { name: 'profile-name' }; - } - - it("get communities", done => { - tcb.createAsync(BlockContainerComponent).then(fixture => { - let block: CommunitiesBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; - expect(block.profiles).toEqual([{ identifier: "community1" }]); - done(); - }); - }); - - it("render the profile image for each community", done => { - tcb.createAsync(BlockContainerComponent).then(fixture => { - fixture.debugElement.getLocal("$rootScope").$apply(); - expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); - done(); - }); - }); - - }); -}); diff --git a/src/app/layout/blocks/communities-block/communities-block.component.ts b/src/app/layout/blocks/communities-block/communities-block.component.ts deleted file mode 100644 index a59f3ad..0000000 --- a/src/app/layout/blocks/communities-block/communities-block.component.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {Input, Inject, Component} from "ng-forward"; -import {CommunityService} from "../../../../lib/ng-noosfero-api/http/community.service"; - -@Component({ - selector: "noosfero-communities-block", - templateUrl: 'app/layout/blocks/communities-block/communities-block.html', -}) -@Inject(CommunityService) -export class CommunitiesBlockComponent { - - @Input() block: noosfero.Block; - @Input() owner: noosfero.Profile; - - profiles: any = []; - - constructor(private communityService: CommunityService) { } - - ngOnInit() { - let limit: number = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5; - this.communityService.getByOwner(this.owner, { limit: limit }).then((result: noosfero.RestResult) => { - this.profiles = result.data; - }); - } -} diff --git a/src/app/layout/blocks/communities-block/communities-block.html b/src/app/layout/blocks/communities-block/communities-block.html deleted file mode 100644 index 4c4f5ee..0000000 --- a/src/app/layout/blocks/communities-block/communities-block.html +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/src/app/layout/blocks/communities-block/communities-block.scss b/src/app/layout/blocks/communities-block/communities-block.scss deleted file mode 100644 index 7b27995..0000000 --- a/src/app/layout/blocks/communities-block/communities-block.scss +++ /dev/null @@ -1,16 +0,0 @@ -.communities-block { - .profile { - margin: 10px; - img, i.profile-image { - width: 60px; - } - img { - display: inline-block; - vertical-align: top; - } - i.profile-image { - text-align: center; - font-size: 4.5em; - } - } -} diff --git a/src/app/layout/blocks/communities/communities-block.component.spec.ts b/src/app/layout/blocks/communities/communities-block.component.spec.ts new file mode 100644 index 0000000..bc6eafd --- /dev/null +++ b/src/app/layout/blocks/communities/communities-block.component.spec.ts @@ -0,0 +1,51 @@ +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; +import {Provider, Input, provide, Component} from 'ng-forward'; + +import {CommunitiesBlockComponent} from './communities-block.component'; + +const htmlTemplate: string = ''; + +const tcb = new TestComponentBuilder(); + +describe("Components", () => { + describe("Communities Block Component", () => { + + beforeEach(angular.mock.module("templates")); + + let state = jasmine.createSpyObj("state", ["go"]); + let providers = [ + new Provider('truncateFilter', { useValue: () => { } }), + new Provider('stripTagsFilter', { useValue: () => { } }), + new Provider('$state', { useValue: state }), + new Provider('CommunityService', { + useValue: { + getByOwner: (owner: any, params: any): any => { + return Promise.resolve({ data: [{ identifier: "community1" }] }); + } + } + }), + ]; + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [CommunitiesBlockComponent], providers: providers }) + class BlockContainerComponent { + block = { type: 'Block', settings: {} }; + owner = { name: 'profile-name' }; + } + + it("get communities", done => { + tcb.createAsync(BlockContainerComponent).then(fixture => { + let block: CommunitiesBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + expect(block.profiles).toEqual([{ identifier: "community1" }]); + done(); + }); + }); + + it("render the profile image for each community", done => { + tcb.createAsync(BlockContainerComponent).then(fixture => { + fixture.debugElement.getLocal("$rootScope").$apply(); + expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); + done(); + }); + }); + + }); +}); diff --git a/src/app/layout/blocks/communities/communities-block.component.ts b/src/app/layout/blocks/communities/communities-block.component.ts new file mode 100644 index 0000000..0ad4b39 --- /dev/null +++ b/src/app/layout/blocks/communities/communities-block.component.ts @@ -0,0 +1,24 @@ +import {Input, Inject, Component} from "ng-forward"; +import {CommunityService} from "../../../../lib/ng-noosfero-api/http/community.service"; + +@Component({ + selector: "noosfero-communities-block", + templateUrl: 'app/layout/blocks/communities/communities-block.html', +}) +@Inject(CommunityService) +export class CommunitiesBlockComponent { + + @Input() block: noosfero.Block; + @Input() owner: noosfero.Profile; + + profiles: any = []; + + constructor(private communityService: CommunityService) { } + + ngOnInit() { + let limit: number = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5; + this.communityService.getByOwner(this.owner, { limit: limit }).then((result: noosfero.RestResult) => { + this.profiles = result.data; + }); + } +} diff --git a/src/app/layout/blocks/communities/communities-block.html b/src/app/layout/blocks/communities/communities-block.html new file mode 100644 index 0000000..4c4f5ee --- /dev/null +++ b/src/app/layout/blocks/communities/communities-block.html @@ -0,0 +1,5 @@ + diff --git a/src/app/layout/blocks/communities/communities-block.scss b/src/app/layout/blocks/communities/communities-block.scss new file mode 100644 index 0000000..7b27995 --- /dev/null +++ b/src/app/layout/blocks/communities/communities-block.scss @@ -0,0 +1,16 @@ +.communities-block { + .profile { + margin: 10px; + img, i.profile-image { + width: 60px; + } + img { + display: inline-block; + vertical-align: top; + } + i.profile-image { + text-align: center; + font-size: 4.5em; + } + } +} diff --git a/src/app/layout/blocks/communities/index.ts b/src/app/layout/blocks/communities/index.ts new file mode 100644 index 0000000..59a210d --- /dev/null +++ b/src/app/layout/blocks/communities/index.ts @@ -0,0 +1,2 @@ +/* Module Index Entry - generated using the script npm run generate-index */ +export * from "./communities-block.component"; diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 825ba82..1285e8a 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -16,7 +16,7 @@ import {ProfileImageBlockComponent} from "../layout/blocks/profile-image-block/p import {RawHTMLBlockComponent} from "../layout/blocks/raw-html/raw-html.component"; import {MembersBlockComponent} from "./../layout/blocks/members-block/members-block.component"; -import {CommunitiesBlockComponent} from "./../layout/blocks/communities-block/communities-block.component"; +import {CommunitiesBlockComponent} from "./../layout/blocks/communities/communities-block.component"; import {NoosferoTemplate} from "../shared/pipes/noosfero-template.filter"; import {DateFormat} from "../shared/pipes/date-format.filter"; @@ -79,11 +79,11 @@ export class EnvironmentContent { * NoosferoTemplate, DateFormat, RawHTMLBlock * @description * The Main controller for the Noosfero Angular Theme application. - * + * * The main route '/' is defined as the URL for this controller, which routes * requests to the {@link main.MainContentComponent} controller and also, the '/profile' route, - * which routes requests to the {@link profile.Profile} controller. See {@link profile.Profile} - * for more details on how various Noosfero profiles are rendered. + * which routes requests to the {@link profile.Profile} controller. See {@link profile.Profile} + * for more details on how various Noosfero profiles are rendered. */ @Component({ selector: 'main', -- libgit2 0.21.2