Commit 2ac1b3bdc1a2f46c59fcd04fe1cd7c6c97ad0c43
Exists in
master
and in
33 other branches
Merge branch 'profile-image-migration' into ngforward
Showing
16 changed files
with
101 additions
and
192 deletions
Show diff stats
src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts
0 → 100644
... | ... | @@ -0,0 +1,50 @@ |
1 | +import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; | |
2 | +import {Pipe, Input, provide, Component} from 'ng-forward'; | |
3 | + | |
4 | +import {ProfileImageBlock} from './profile-image-block.component'; | |
5 | + | |
6 | +import * as helpers from "./../../../../spec/helpers"; | |
7 | + | |
8 | +const tcb = new TestComponentBuilder(); | |
9 | + | |
10 | +const htmlTemplate: string = '<noosfero-profile-image-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-profile-image-block>'; | |
11 | + | |
12 | +describe("Components", () => { | |
13 | + | |
14 | + describe("Profile Image Block Component", () => { | |
15 | + | |
16 | + beforeEach(angular.mock.module("templates")); | |
17 | + | |
18 | + @Component( | |
19 | + { | |
20 | + selector: 'test-container-component', | |
21 | + template: htmlTemplate, | |
22 | + directives: [ProfileImageBlock] | |
23 | + }) | |
24 | + class BlockContainerComponent { | |
25 | + block = { type: 'Block' }; | |
26 | + owner = { name: 'profile-name' }; | |
27 | + constructor() { | |
28 | + } | |
29 | + } | |
30 | + | |
31 | + | |
32 | + | |
33 | + it("show image if present", () => { | |
34 | + helpers.tcb.createAsync(BlockContainerComponent).then(fixture => { | |
35 | + var elProfile = fixture.debugElement.componentViewChildren[0]; | |
36 | + expect(elProfile.query('div.profile-image-block').length).toEqual(1); | |
37 | + }); | |
38 | + }); | |
39 | + | |
40 | + //TODO | |
41 | + it("not show image if image is missing", () => { | |
42 | + | |
43 | + }); | |
44 | + | |
45 | + it("has link to the profile", () => { | |
46 | + | |
47 | + }); | |
48 | + | |
49 | + }); | |
50 | +}); | |
0 | 51 | \ No newline at end of file | ... | ... |
src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts
0 → 100644
... | ... | @@ -0,0 +1,14 @@ |
1 | +import {Inject, Input, Component} from "ng-forward"; | |
2 | +import {ProfileImage} from "./../../../components/noosfero/profile-image/profile-image.component"; | |
3 | + | |
4 | +@Component({ | |
5 | + selector: "noosfero-profile-image-block", | |
6 | + templateUrl: 'app/components/noosfero-blocks/profile-image-block/profile-image-block.html', | |
7 | + directives: [ProfileImage] | |
8 | +}) | |
9 | +export class ProfileImageBlock { | |
10 | + | |
11 | + @Input() block: any; | |
12 | + @Input() owner: any; | |
13 | + | |
14 | +} | ... | ... |
src/app/components/noosfero-blocks/profile-image-block/profile-image-block.html
0 → 100644
... | ... | @@ -0,0 +1,6 @@ |
1 | +<div class="center-block text-center profile-image-block"> | |
2 | + <a ui-sref="main.profile.info({profile: ctrl.owner.identifier})"> | |
3 | + <noosfero-profile-image [profile]="ctrl.owner"></noosfero-profile-image> | |
4 | + </a> | |
5 | + <a class="settings-link" target="_self" ui-sref="main.profile.settings({profile: ctrl.owner.identifier})">Control panel</a> | |
6 | +</div> | ... | ... |
src/app/components/noosfero-blocks/profile-image-block/profile-image-block.scss
0 → 100644
src/app/components/noosfero-blocks/profile-image/profile-image.component.spec.ts
... | ... | @@ -1,106 +0,0 @@ |
1 | -import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; | |
2 | -import {Pipe, Input, provide, Component} from 'ng-forward'; | |
3 | - | |
4 | -import {ProfileImageBlock} from './profile-image.component'; | |
5 | - | |
6 | -import {ProfileService} from "./../../../../lib/ng-noosfero-api/http/profile.service"; | |
7 | - | |
8 | -import * as helpers from "./../../../../spec/helpers"; | |
9 | - | |
10 | -const tcb = new TestComponentBuilder(); | |
11 | - | |
12 | -const htmlTemplate: string = '<noosfero-profile-image-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-profile-image-block>'; | |
13 | - | |
14 | - | |
15 | - | |
16 | - | |
17 | -describe("Components", () => { | |
18 | - describe("Profile Image Block Component", () => { | |
19 | - | |
20 | - beforeEach(angular.mock.module("templates")); | |
21 | - | |
22 | - //beforeEach(angular.mock.module("restangular")); | |
23 | - | |
24 | - function buildServiceMock() { | |
25 | - let profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getActivities"]); | |
26 | - | |
27 | - let thenObj = jasmine.createSpyObj("thenObj", ["then"]); | |
28 | - | |
29 | - thenObj.then = (func: Function) => { | |
30 | - func({ | |
31 | - data: { | |
32 | - image: { | |
33 | - name: 'some-thing', | |
34 | - url: 'http://image.com' | |
35 | - } | |
36 | - } | |
37 | - }) | |
38 | - } | |
39 | - | |
40 | - profileServiceMock.getActivities = jasmine.createSpy("getActivities").and.returnValue(thenObj); | |
41 | - | |
42 | - return profileServiceMock; | |
43 | - } | |
44 | - | |
45 | - @Component( | |
46 | - { | |
47 | - selector: 'test-container-component', | |
48 | - template: htmlTemplate, | |
49 | - directives: [ProfileImageBlock], | |
50 | - providers: [helpers.createProviderToValue("ProfileService", buildServiceMock())] | |
51 | - | |
52 | - }) | |
53 | - class BlockContainerComponent { | |
54 | - block = { type: 'Block' }; | |
55 | - owner = { name: 'profile-name' }; | |
56 | - constructor() { | |
57 | - } | |
58 | - } | |
59 | - | |
60 | - | |
61 | - | |
62 | - it("show image if present", () => { | |
63 | - let profileServiceMock = buildServiceMock(); | |
64 | - helpers.tcb.createAsync(BlockContainerComponent).then(fixture => { | |
65 | - var elProfile = fixture.debugElement.componentViewChildren[0]; | |
66 | - expect(elProfile.query('div.profile-image-block').length).toEqual(1); | |
67 | - }); | |
68 | - }); | |
69 | - | |
70 | - //TODO | |
71 | - it("not show image if image is missing", () => { | |
72 | - | |
73 | - }); | |
74 | - | |
75 | - it("has link to the profile", () => { | |
76 | - | |
77 | - }); | |
78 | - | |
79 | - it("get activitities from profileService", () => { | |
80 | - | |
81 | - | |
82 | - let profileServiceMock = buildServiceMock(); | |
83 | - | |
84 | - let profileImageBlock = new ProfileImageBlock(<any>profileServiceMock); | |
85 | - | |
86 | - profileImageBlock.ngOnInit(); | |
87 | - expect(profileServiceMock.getActivities).toHaveBeenCalled(); | |
88 | - expect(profileImageBlock.image.name).toEqual("some-thing"); | |
89 | - }) | |
90 | - | |
91 | - // it("render the profile image", done => { | |
92 | - // tcb.createAsync(BlockContainerComponent).then(fixture => { | |
93 | - // expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); | |
94 | - // done(); | |
95 | - // }); | |
96 | - // }); | |
97 | - // | |
98 | - // it("render the settings link", done => { | |
99 | - // tcb.createAsync(BlockContainerComponent).then(fixture => { | |
100 | - // expect(fixture.debugElement.queryAll(".settings-link").length).toEqual(1); | |
101 | - // done(); | |
102 | - // }); | |
103 | - // }); | |
104 | - | |
105 | - }); | |
106 | -}); | |
107 | 0 | \ No newline at end of file |
src/app/components/noosfero-blocks/profile-image/profile-image.component.ts
... | ... | @@ -1,27 +0,0 @@ |
1 | -import {Inject, Input, Component} from "ng-forward"; | |
2 | -import {ProfileService} from "./../../../../lib/ng-noosfero-api/http/profile.service"; | |
3 | - | |
4 | -@Component({ | |
5 | - selector: "noosfero-profile-image-block", | |
6 | - templateUrl: 'app/components/noosfero-blocks/profile-image/profile-image.html', | |
7 | - providers: [ProfileService] | |
8 | -}) | |
9 | -@Inject(ProfileService) | |
10 | -export class ProfileImageBlock { | |
11 | - | |
12 | - @Input() block: any; | |
13 | - @Input() owner: any; | |
14 | - | |
15 | - image: any; | |
16 | - | |
17 | - constructor(private profileService: ProfileService) { | |
18 | - | |
19 | - } | |
20 | - | |
21 | - ngOnInit() { | |
22 | - this.profileService.getActivities(null, {}).then((resp:any) => { | |
23 | - this.image = resp.data.image; | |
24 | - }) | |
25 | - } | |
26 | - | |
27 | -} |
src/app/components/noosfero-blocks/profile-image/profile-image.html
... | ... | @@ -1,6 +0,0 @@ |
1 | -<div class="center-block text-center profile-image-block"> | |
2 | - <a ui-sref="main.profile.info({profile: ctrl.owner.identifier})"> | |
3 | - <noosfero-profile-image profile="ctrl.owner"></noosfero-profile-image> | |
4 | - </a> | |
5 | - <a class="settings-link" target="_self" ui-sref="main.profile.settings({profile: ctrl.owner.identifier})">Control panel</a> | |
6 | -</div> |
src/app/components/noosfero-blocks/profile-image/profile-image.scss
src/app/components/noosfero/profile-image/profile-image.component.js
... | ... | @@ -1,22 +0,0 @@ |
1 | -(function() { | |
2 | - 'use strict'; | |
3 | - | |
4 | - angular | |
5 | - .module('noosferoApp') | |
6 | - .component('noosferoProfileImage', { | |
7 | - restrict: 'E', | |
8 | - templateUrl: 'app/components/noosfero/profile-image/profile-image.html', | |
9 | - bindings: { | |
10 | - profile: '<' | |
11 | - }, | |
12 | - controller: ProfileImageController | |
13 | - }); | |
14 | - | |
15 | - /** @ngInject */ | |
16 | - function ProfileImageController() { | |
17 | - var vm = this; | |
18 | - vm.defaultIcon = 'fa-users'; | |
19 | - if(vm.profile && vm.profile.type==='Person') vm.defaultIcon = 'fa-user'; | |
20 | - } | |
21 | - | |
22 | -})(); |
src/app/components/noosfero/profile-image/profile-image.component.spec.ts
0 → 100644
src/app/components/noosfero/profile-image/profile-image.component.ts
1 | -(function() { | |
2 | - 'use strict'; | |
1 | +import {Inject, Input, Component} from "ng-forward"; | |
2 | +import {Profile} from "./../../../models/interfaces"; | |
3 | 3 | |
4 | - angular | |
5 | - .module('noosferoApp') | |
6 | - .component('noosferoProfileImage', { | |
7 | - templateUrl: 'app/components/noosfero/profile-image/profile-image.html', | |
8 | - bindings: { | |
9 | - profile: '<' | |
10 | - }, | |
11 | - controller: ProfileImageController | |
12 | - }); | |
4 | +@Component({ | |
5 | + selector: "noosfero-profile-image", | |
6 | + templateUrl: 'app/components/noosfero/profile-image/profile-image.html', | |
7 | +}) | |
8 | +export class ProfileImage { | |
13 | 9 | |
14 | - /** @ngInject */ | |
15 | - function ProfileImageController() { | |
16 | - var vm = this; | |
17 | - vm.defaultIcon = 'fa-users'; | |
18 | - if(vm.profile && vm.profile.type==='Person') vm.defaultIcon = 'fa-user'; | |
19 | - } | |
10 | + @Input() profile: Profile; | |
11 | + defaultIcon: any; | |
12 | + | |
13 | + ngOnInit() { | |
14 | + this.defaultIcon = 'fa-users'; | |
15 | + console.debug("On ProfileImage ngOnInit. Profile: " + this.profile) | |
16 | + if (this.profile && this.profile.type === 'Person') { | |
17 | + this.defaultIcon = 'fa-user'; | |
18 | + } | |
19 | + } | |
20 | +} | |
20 | 21 | |
21 | -})(); | ... | ... |
src/app/components/noosfero/profile-image/profile-image.html
1 | -<span title="{{$ctrl.profile.name}}"> | |
2 | - <img ng-if="$ctrl.profile.image" ng-src="{{$ctrl.profile.image.url}}" class="img-responsive profile-image"> | |
3 | - <i ng-if="!$ctrl.profile.image" class="fa {{$ctrl.defaultIcon}} fa-5x profile-image"></i> | |
1 | +<span title="{{ctrl.profile.name}}"> | |
2 | + <img ng-if="ctrl.profile.image" ng-src="{{ctrl.profile.image.url}}" class="img-responsive profile-image"> | |
3 | + <i ng-if="!ctrl.profile.image" class="fa {{ctrl.defaultIcon}} fa-5x profile-image"></i> | |
4 | 4 | </span> | ... | ... |
src/app/index.ts
... | ... | @@ -28,6 +28,4 @@ NoosferoApp.addConstants("AUTH_EVENTS", AUTH_EVENTS); |
28 | 28 | NoosferoApp.addConfig(noosferoModuleConfig); |
29 | 29 | NoosferoApp.run(noosferoAngularRunBlock); |
30 | 30 | |
31 | -require("./components/noosfero/profile-image/profile-image.component.js"); | |
32 | - | |
33 | 31 | NoosferoApp.addConfig(routeConfig); | ... | ... |
src/app/main/main.component.ts
... | ... | @@ -8,7 +8,8 @@ import {Boxes} from "../components/noosfero-boxes/boxes.component"; |
8 | 8 | import {Block} from "../components/noosfero-blocks/block.component"; |
9 | 9 | import {LinkListBlock} from "../components/noosfero-blocks/link-list/link-list.component"; |
10 | 10 | import {RecentDocumentsBlock} from "../components/noosfero-blocks/recent-documents/recent-documents.component"; |
11 | -import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image/profile-image.component"; | |
11 | +import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image-block/profile-image-block.component"; | |
12 | + | |
12 | 13 | import {MembersBlock} from "../components/noosfero-blocks/members-block/members-block.component"; |
13 | 14 | import {NoosferoTemplate} from "../components/noosfero/noosfero-template.filter"; |
14 | 15 | ... | ... |
src/app/models/interfaces.ts
src/lib/ng-noosfero-api/http/profile.service.spec.ts
... | ... | @@ -61,12 +61,12 @@ describe("Services", () => { |
61 | 61 | }); |
62 | 62 | |
63 | 63 | it("should resolve the current profile", (done) => { |
64 | - let profile: Profile = { id: 1, identifier: "profile1" }; | |
64 | + let profile = { id: 1, identifier: "profile1" }; | |
65 | 65 | profileService.getCurrentProfile().then((currentProfile: Profile) => { |
66 | 66 | expect(currentProfile).toEqual(currentProfile); |
67 | 67 | done(); |
68 | 68 | }); |
69 | - profileService.setCurrentProfile(profile); | |
69 | + profileService.setCurrentProfile(<Profile>profile); | |
70 | 70 | $rootScope.$apply(); |
71 | 71 | }); |
72 | 72 | ... | ... |