Commit 2841288e4b867433b278279ad5a4c9537f6a9d19
1 parent
63a0a102
Exists in
master
and in
10 other branches
Ticket #85: Fields of Interest block
Showing
9 changed files
with
117 additions
and
5 deletions
Show diff stats
.gitignore
src/app/layout/blocks/person-tags-plugin-interests/index.ts
0 → 100644
src/app/layout/blocks/person-tags-plugin-interests/person-tags-plugin-interests-block.component.spec.ts
0 → 100644
... | ... | @@ -0,0 +1,56 @@ |
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 {PersonTagsPluginInterestsBlockComponent} from './person-tags-plugin-interests-block.component'; | |
5 | +import * as helpers from "./../../../../spec/helpers"; | |
6 | + | |
7 | +const htmlTemplate: string = '<noosfero-person-tags-plugin-interests-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-person-tags-plugin-interests-block>'; | |
8 | + | |
9 | +const tcb = new TestComponentBuilder(); | |
10 | + | |
11 | +describe("Components", () => { | |
12 | + describe("Person Tags Interests Block Component", () => { | |
13 | + | |
14 | + let settingsObj = {}; | |
15 | + let person = <noosfero.Person>{ name: "Person" }; | |
16 | + let mockedService = { | |
17 | + getTags: (profile: noosfero.Profile): any => { | |
18 | + return Promise.resolve({ data: ['foo', 'bar'], headers: (name: string) => { return name; } }); | |
19 | + } | |
20 | + }; | |
21 | + beforeEach(angular.mock.module("templates")); | |
22 | + | |
23 | + let state = jasmine.createSpyObj("state", ["go"]); | |
24 | + | |
25 | + | |
26 | + function getProviders() { | |
27 | + return [ | |
28 | + new Provider('$state', { useValue: state }), | |
29 | + new Provider('PersonService', { | |
30 | + useValue: mockedService | |
31 | + }) | |
32 | + ].concat(provideFilters("truncateFilter", "stripTagsFilter")); | |
33 | + } | |
34 | + let componentClass: any = null; | |
35 | + | |
36 | + function getComponent() { | |
37 | + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [PersonTagsPluginInterestsBlockComponent], providers: getProviders() }) | |
38 | + class BlockContainerComponent { | |
39 | + block = { type: 'Block', settings: settingsObj }; | |
40 | + owner = person; | |
41 | + constructor() { | |
42 | + } | |
43 | + } | |
44 | + return BlockContainerComponent; | |
45 | + } | |
46 | + | |
47 | + it("get tags from the person service", done => { | |
48 | + tcb.createAsync(getComponent()).then(fixture => { | |
49 | + let PersonTagsPluginInterestsBlock: PersonTagsPluginInterestsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | |
50 | + expect(PersonTagsPluginInterestsBlock.tags).toEqual(['foo', 'bar']); | |
51 | + done(); | |
52 | + }); | |
53 | + }); | |
54 | + | |
55 | + }); | |
56 | +}); | ... | ... |
src/app/layout/blocks/person-tags-plugin-interests/person-tags-plugin-interests-block.component.ts
0 → 100644
... | ... | @@ -0,0 +1,27 @@ |
1 | +import {Component, Inject, Input} from "ng-forward"; | |
2 | +import {PersonService} from "./../../../../lib/ng-noosfero-api/http/person.service"; | |
3 | +import {Arrays} from "./../../../../lib/util/arrays"; | |
4 | + | |
5 | +@Component({ | |
6 | + selector: "noosfero-person-tags-plugin-interests-block", | |
7 | + templateUrl: 'app/layout/blocks/person-tags-plugin-interests/person-tags-plugin-interests-block.html' | |
8 | +}) | |
9 | +@Inject(PersonService, "$state") | |
10 | +export class PersonTagsPluginInterestsBlockComponent { | |
11 | + | |
12 | + @Input() block: any; | |
13 | + @Input() owner: any; | |
14 | + | |
15 | + profile: any; | |
16 | + tags: any; | |
17 | + | |
18 | + constructor(private personService: PersonService, private $state: any) { } | |
19 | + | |
20 | + ngOnInit() { | |
21 | + this.profile = this.owner; | |
22 | + this.tags = []; | |
23 | + this.personService.getTags(this.owner).then((result: noosfero.RestResult<any>) => { | |
24 | + this.tags = result.data; | |
25 | + }); | |
26 | + } | |
27 | +} | ... | ... |
src/app/layout/blocks/person-tags-plugin-interests/person-tags-plugin-interests-block.html
0 → 100644
src/app/layout/blocks/person-tags-plugin-interests/person-tags-plugin-interests-block.scss
0 → 100644
src/app/main/main.component.ts
... | ... | @@ -16,6 +16,7 @@ import {RecentDocumentsBlockComponent} from "../layout/blocks/recent-documents/r |
16 | 16 | import {ProfileImageBlockComponent} from "../layout/blocks/profile-image/profile-image-block.component"; |
17 | 17 | import {RawHTMLBlockComponent} from "../layout/blocks/raw-html/raw-html-block.component"; |
18 | 18 | import {StatisticsBlockComponent} from "../layout/blocks/statistics/statistics-block.component"; |
19 | +import {PersonTagsPluginInterestsBlockComponent} from "../layout/blocks/person-tags-plugin-interests/person-tags-plugin-interests-block.component"; | |
19 | 20 | import {CustomContentComponent} from "../profile/custom-content/custom-content.component"; |
20 | 21 | |
21 | 22 | import {MembersBlockComponent} from "../layout/blocks/members/members-block.component"; |
... | ... | @@ -82,7 +83,7 @@ export class EnvironmentContent { |
82 | 83 | * @name main.Main |
83 | 84 | * @requires AuthService, Session, Notification, ArticleBlog, ArticleView, Boxes, Block, LinkListBlock, |
84 | 85 | * MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock, MembersBlock, |
85 | - * NoosferoTemplate, DateFormat, RawHTMLBlock | |
86 | + * NoosferoTemplate, DateFormat, RawHTMLBlock, PersonTagsPluginInterestsBlock | |
86 | 87 | * @description |
87 | 88 | * The Main controller for the Noosfero Angular Theme application. |
88 | 89 | * |
... | ... | @@ -100,7 +101,7 @@ export class EnvironmentContent { |
100 | 101 | LinkListBlockComponent, CommunitiesBlockComponent, HtmlEditorComponent, ProfileComponent, |
101 | 102 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, |
102 | 103 | MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, StatisticsBlockComponent, |
103 | - LoginBlockComponent, CustomContentComponent, PermissionDirective | |
104 | + LoginBlockComponent, PersonTagsPluginInterestsBlockComponent, CustomContentComponent, PermissionDirective | |
104 | 105 | ].concat(plugins.mainComponents).concat(plugins.hotspots), |
105 | 106 | providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, |
106 | 107 | "ngAnimate", "ngCookies", "ngStorage", "ngTouch", | ... | ... |
src/lib/ng-noosfero-api/http/person.service.ts
1 | 1 | import { Injectable, Inject } from "ng-forward"; |
2 | 2 | import {RestangularService} from "./restangular_service"; |
3 | +import {ProfileService} from "./profile.service"; | |
3 | 4 | |
4 | 5 | @Injectable() |
5 | -@Inject("Restangular", "$q", "$log") | |
6 | +@Inject("Restangular", "$q", "$log", ProfileService) | |
6 | 7 | export class PersonService extends RestangularService<noosfero.Person> { |
7 | 8 | |
8 | - constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService) { | |
9 | + constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService, protected profileService: ProfileService) { | |
9 | 10 | super(Restangular, $q, $log); |
10 | 11 | } |
11 | 12 | |
... | ... | @@ -20,4 +21,11 @@ export class PersonService extends RestangularService<noosfero.Person> { |
20 | 21 | }; |
21 | 22 | } |
22 | 23 | |
24 | + getTags(profile: noosfero.Profile): ng.IPromise<noosfero.RestResult<any>> { | |
25 | + let p = this.getElement(<number>profile.id).customGET('tags'); | |
26 | + let deferred = this.$q.defer<noosfero.RestResult<any>>(); | |
27 | + p.then(this.getHandleSuccessFunction<noosfero.RestResult<any>>(deferred)); | |
28 | + p.catch(this.getHandleErrorFunction<noosfero.RestResult<any>>(deferred)); | |
29 | + return deferred.promise; | |
30 | + } | |
23 | 31 | } | ... | ... |
src/lib/ng-noosfero-api/http/restangular_service.ts