From 338aae2ef7b6a2d9dbbbe8421cb8d783ae57e4aa Mon Sep 17 00:00:00 2001 From: Michel Felipe Date: Fri, 29 Jul 2016 19:17:54 -0300 Subject: [PATCH] Minor refactory and sintax adjusts --- src/app/layout/blocks/profile-image/profile-image-block.component.spec.ts | 12 ++++++------ src/app/profile/image/image.component.spec.ts | 59 ++++++++++++++++++++++++++++------------------------------- src/app/profile/image/image.component.ts | 17 ++++++++--------- src/app/profile/image/image.html | 8 ++++---- src/app/profile/image/image.scss | 5 +---- src/app/profile/image/profile-image-editor.component.spec.ts | 12 ++++++------ src/app/profile/image/profile-image-editor.component.ts | 22 +++++++++++----------- src/app/profile/image/profile-image-editor.html | 6 +++--- src/app/profile/info/profile-info.scss | 22 +++++++++++++--------- src/languages/en.json | 1 + src/languages/pt.json | 1 + src/lib/ng-noosfero-api/http/person.service.ts | 8 ++++---- 12 files changed, 86 insertions(+), 87 deletions(-) diff --git a/src/app/layout/blocks/profile-image/profile-image-block.component.spec.ts b/src/app/layout/blocks/profile-image/profile-image-block.component.spec.ts index da5207f..ab5b209 100644 --- a/src/app/layout/blocks/profile-image/profile-image-block.component.spec.ts +++ b/src/app/layout/blocks/profile-image/profile-image-block.component.spec.ts @@ -1,7 +1,7 @@ -import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; -import {Pipe, Input, provide, Component} from 'ng-forward'; +import { TestComponentBuilder, ComponentFixture } from 'ng-forward/cjs/testing/test-component-builder'; +import { Pipe, Input, provide, Component } from 'ng-forward'; -import {ProfileImageBlockComponent} from './profile-image-block.component'; +import { ProfileImageBlockComponent } from './profile-image-block.component'; import * as helpers from "./../../../../spec/helpers"; @@ -14,7 +14,7 @@ describe("Components", () => { describe("Profile Image Block Component", () => { beforeEach(angular.mock.module("templates")); - let personService = jasmine.createSpyObj("personService", ["upload"]); + let personService = jasmine.createSpyObj("personService", ["upload"]); let profileService = jasmine.createSpyObj("ProfileService", ["isMember", "addMember", "removeMember"]); profileService.isMember = jasmine.createSpy("isMember").and.returnValue(Promise.resolve(false)); @@ -25,8 +25,8 @@ describe("Components", () => { directives: [ProfileImageBlockComponent], providers: [ helpers.createProviderToValue('SessionService', helpers.mocks.sessionWithCurrentUser({})), - helpers.createProviderToValue("PersonService", personService), - helpers.createProviderToValue("$uibModal", helpers.mocks.$modal), + helpers.createProviderToValue("PersonService", personService), + helpers.createProviderToValue("$uibModal", helpers.mocks.$modal), helpers.createProviderToValue('ProfileService', profileService), helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService) ].concat(helpers.provideFilters("translateFilter")) diff --git a/src/app/profile/image/image.component.spec.ts b/src/app/profile/image/image.component.spec.ts index 12a9e0b..a648878 100644 --- a/src/app/profile/image/image.component.spec.ts +++ b/src/app/profile/image/image.component.spec.ts @@ -4,14 +4,14 @@ * @description * This file contains the tests for the {@link components.noosfero.profile-image.ProfileImage} component. */ -import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper'; -import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; -import {Pipe, Input, provide, Component} from 'ng-forward'; -import {PersonService} from "../../../lib/ng-noosfero-api/http/person.service"; +import { ComponentTestHelper, createClass } from '../../../spec/component-test-helper'; +import { TestComponentBuilder, ComponentFixture } from 'ng-forward/cjs/testing/test-component-builder'; +import { Pipe, Input, provide, Component } from 'ng-forward'; +import { PersonService } from "../../../lib/ng-noosfero-api/http/person.service"; import * as helpers from "../../../spec/helpers"; -import {ProfileImageComponent} from "./image.component"; +import { ProfileImageComponent } from "./image.component"; const htmlTemplate: string = ''; @@ -46,33 +46,30 @@ describe("Components", () => { expect(helper.component['$uibModal'].open).toHaveBeenCalled(); }); - /* - it("show community users image if profile is not Person", done => { - helpers.tcb.createAsync(ProfileImageComponent).then(fixture => { - let profileImageComponent: ProfileImageComponent = fixture.componentInstance; - let profile = { id: 1, identifier: "myprofile", type: "Community" }; - profileImageComponent.profile = profile; - profileImageComponent.ngOnInit(); - - // Check the attribute - expect(profileImageComponent.defaultIcon).toBe("fa-users", "The default icon should be community users"); - // var elProfile = fixture.debugElement.componentViewChildren[0]; - // expect(elProfile.query('div.profile-image-block').length).toEqual(1); - done(); - }); + + it("show community users image if profile is not Person", (done) => { + + let profile = { id: 1, identifier: "myprofile", type: "Community" }; + helper.component.profile = profile; + helper.component.ngOnInit(); + + // Check the attribute + expect(helper.component.defaultIcon).toBe("fa-users", "The default icon should be community users"); + // var elProfile = fixture.debugElement.componentViewChildren[0]; + // expect(elProfile.query('div.profile-image-block').length).toEqual(1); + done(); + }); - it("show Person image if profile is Person", done => { - tcb.createAsync(ProfileImageComponent).then(fixture => { - let profileImageComponent: ProfileImageComponent = fixture.componentInstance; - let profile = { id: 1, identifier: "myprofile", type: "Person" }; - profileImageComponent.profile = profile; - profileImageComponent.ngOnInit(); - // Check the attribute - expect(profileImageComponent.defaultIcon).toEqual("fa-user", "The default icon should be person user"); - done(); - }); - });*/ + it("show Person image if profile is Person", (done) => { + + let profile = { id: 1, identifier: "myprofile", type: "Person" }; + helper.component.profile = profile; + helper.component.ngOnInit(); + // Check the attribute + expect(helper.component.defaultIcon).toEqual("fa-user", "The default icon should be person user"); + done(); + }); }); -}); \ No newline at end of file +}); diff --git a/src/app/profile/image/image.component.ts b/src/app/profile/image/image.component.ts index db49635..950020f 100644 --- a/src/app/profile/image/image.component.ts +++ b/src/app/profile/image/image.component.ts @@ -1,6 +1,6 @@ -import {Inject, Input, Component, provide} from "ng-forward"; -import {PersonService} from "../../../lib/ng-noosfero-api/http/person.service"; -import {ProfileImageEditorComponent} from "./profile-image-editor.component"; +import { Inject, Input, Component, provide } from "ng-forward"; +import { PersonService } from "../../../lib/ng-noosfero-api/http/person.service"; +import { ProfileImageEditorComponent } from "./profile-image-editor.component"; /** * @ngdoc controller @@ -11,7 +11,7 @@ import {ProfileImageEditorComponent} from "./profile-image-editor.component"; @Component({ selector: "noosfero-profile-image", templateUrl: 'app/profile/image/image.html', - providers: [ provide('personService', { useClass: PersonService }) ] + providers: [provide('personService', { useClass: PersonService })] }) @Inject(PersonService, "$uibModal", "$scope") export class ProfileImageComponent { @@ -20,7 +20,7 @@ export class ProfileImageComponent { * @ngdoc property * @name profile * @propertyOf components.noosfero.profile-image.ProfileImage - * @description + * @description * The Noosfero {@link models.Profile} holding the image. */ @Input() profile: noosfero.Profile; @@ -41,7 +41,7 @@ export class ProfileImageComponent { croppedDataUrl: any; modalInstance: any; - constructor(private personService: PersonService, private $uibModal: any, private $scope: ng.IScope) { + constructor(private personService: PersonService, private $uibModal: ng.ui.bootstrap.IModalService, private $scope: ng.IScope) { } fileSelected(file: any, errFiles: any) { @@ -79,8 +79,8 @@ export class ProfileImageComponent { * @ngdoc method * @name ngOnInit * @methodOf components.noosfero.profile-image.ProfileImage - * @description - * Initializes the icon names to their corresponding values depending on the profile type passed to the controller + * @description + * Initializes the icon names to their corresponding values depending on the profile type passed to the controller */ ngOnInit() { this.defaultIcon = 'fa-users'; @@ -90,4 +90,3 @@ export class ProfileImageComponent { } } - diff --git a/src/app/profile/image/image.html b/src/app/profile/image/image.html index 37f3475..41e23d6 100644 --- a/src/app/profile/image/image.html +++ b/src/app/profile/image/image.html @@ -1,4 +1,4 @@ -
+
@@ -10,12 +10,12 @@
{{"profile.image.upload" | translate}}
- +
- +
diff --git a/src/app/profile/image/image.scss b/src/app/profile/image/image.scss index 8bc935c..d41268f 100644 --- a/src/app/profile/image/image.scss +++ b/src/app/profile/image/image.scss @@ -37,9 +37,8 @@ i.profile-image { } .select-photo-container { - //overflow: hidden; position: absolute; - z-index: -1; + z-index: -1; background: #000; background: rgba(0, 0, 0, .6); background: linear-gradient(transparent, rgba(0, 0, 0, .6) 70%, rgba(0, 0, 0, .6) 100%); @@ -58,7 +57,6 @@ i.profile-image { .upload-button { -webkit-font-smoothing: antialiased; color: #fff; - //word-wrap: break-word; } .upload-container { @@ -95,4 +93,3 @@ form .progress { background: orange; width: 0; } - diff --git a/src/app/profile/image/profile-image-editor.component.spec.ts b/src/app/profile/image/profile-image-editor.component.spec.ts index 78a2877..cd99f97 100644 --- a/src/app/profile/image/profile-image-editor.component.spec.ts +++ b/src/app/profile/image/profile-image-editor.component.spec.ts @@ -1,8 +1,8 @@ -import {Pipe, Input, provide, Component} from 'ng-forward'; -import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper'; +import { Pipe, Input, provide, Component } from 'ng-forward'; +import { ComponentTestHelper, createClass } from '../../../spec/component-test-helper'; import * as helpers from "../../../spec/helpers"; -import {ProfileImageEditorComponent} from "./profile-image-editor.component"; +import { ProfileImageEditorComponent } from "./profile-image-editor.component"; describe("Components", () => { @@ -11,6 +11,7 @@ describe("Components", () => { beforeEach(angular.mock.module("templates")); let expectedData = "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAgAElEQ…Cm2OLHvfdNPte3zrH709Q0esN1LPQ0t7DL696ERpu+9/8BVPLIpElf7VYAAAAASUVORK5CYII="; + let testDataUrl = "data:image/png;base64," + expectedData; let profile = { name: "profile_name", id: 1, identifier: "test" }; let modal = helpers.mocks.$modal; @@ -28,7 +29,7 @@ describe("Components", () => { let comp = new ProfileImageEditorComponent(picFile, this.profile, personServiceMock, modalInstance); it("get data", done => { - let testDataUrl = "data:image/png;base64," + expectedData; + let result = comp.getData(testDataUrl); expect(result).toBe(expectedData); done(); @@ -44,7 +45,6 @@ describe("Components", () => { }); it("upload image", done => { - let testDataUrl = "data:image/png;base64," + expectedData; let imageName = "image1"; personServiceMock = jasmine.createSpyObj("personServiceMock", ["uploadImage"]); console.log("PersonServiceMock:", personServiceMock); @@ -54,7 +54,7 @@ describe("Components", () => { comp.uploadImage(testDataUrl, imageName); deferredUploadImage.resolve(); $rootScope.$apply(); - expect(comp.$uibModalInstance.close).toHaveBeenCalled(); + expect(comp.modalInstance.close).toHaveBeenCalled(); done(); }); diff --git a/src/app/profile/image/profile-image-editor.component.ts b/src/app/profile/image/profile-image-editor.component.ts index 7d0244b..757bd77 100644 --- a/src/app/profile/image/profile-image-editor.component.ts +++ b/src/app/profile/image/profile-image-editor.component.ts @@ -1,6 +1,6 @@ -import {StateConfig, Component, Input, Output, Inject, provide} from 'ng-forward'; -import {TranslateProfile} from "../../shared/pipes/translate-profile.filter"; -import {PersonService} from "../../../lib/ng-noosfero-api/http/person.service"; +import { StateConfig, Component, Input, Output, Inject, provide } from 'ng-forward'; +import { TranslateProfile } from "../../shared/pipes/translate-profile.filter"; +import { PersonService } from "../../../lib/ng-noosfero-api/http/person.service"; export class ProfileImageEditorComponent { @@ -9,17 +9,17 @@ export class ProfileImageEditorComponent { static $inject = ["picFile", "profile", "personService", "$uibModalInstance"]; constructor(public picFile: any, public profile: noosfero.Profile, public personService: PersonService, - public $uibModalInstance: any) { + public modalInstance: ng.ui.bootstrap.IModalServiceInstance) { } uploadImage(dataUrl: any, name: any) { - let base64_image_json = this.getBase64ImageJson(dataUrl, name); - this.personService.uploadImage(this.profile, base64_image_json).then( (result: any) => { - this.$uibModalInstance.close(name); + let base64ImageJson = this.getBase64ImageJson(dataUrl, name); + this.personService.uploadImage(this.profile, base64ImageJson).then((result: any) => { + this.modalInstance.close(name); }); } - getBase64ImageJson(dataUrl: any, name: any) { + getBase64ImageJson(dataUrl: any, name: any): any { let data = this.getData(dataUrl); let image_name = this.getImageName(name); return { @@ -29,15 +29,15 @@ export class ProfileImageEditorComponent { }; } - getImageName(name: any) { + getImageName(name: any): string { return this.profile.name + "_" + name; } - getData(dataUrl: any) { + getData(dataUrl: any): string { return dataUrl.substring(dataUrl.indexOf('base64,') + 7); } cancel() { - this.$uibModalInstance.close(); + this.modalInstance.close(); } } diff --git a/src/app/profile/image/profile-image-editor.html b/src/app/profile/image/profile-image-editor.html index 585792e..e58eb74 100644 --- a/src/app/profile/image/profile-image-editor.html +++ b/src/app/profile/image/profile-image-editor.html @@ -10,7 +10,7 @@
-
+
Upload Successful
- - + +
diff --git a/src/app/profile/info/profile-info.scss b/src/app/profile/info/profile-info.scss index 3b507b0..8aff555 100644 --- a/src/app/profile/info/profile-info.scss +++ b/src/app/profile/info/profile-info.scss @@ -1,6 +1,8 @@ -.profile-info .upload-camera-container { - top: 55%; - left: 39px; +.profile-info { + .upload-camera-container { + top: 55%; + left: 39px; + } } .profile-info-editable { @@ -9,13 +11,15 @@ height: 28px; } -.profile-info-editable .upload-button { - font-size: 0.8em; - padding-top: 9px; - padding-left: 6px; - font-weight: bold; +.profile-info-editable { + .upload-button { + font-size: 0.8em; + padding-top: 9px; + padding-left: 6px; + font-weight: bold; + } } .profile-info-extrainfo { margin-top: 10px; -} \ No newline at end of file +} diff --git a/src/languages/en.json b/src/languages/en.json index a6f0ddf..fefa50c 100644 --- a/src/languages/en.json +++ b/src/languages/en.json @@ -23,6 +23,7 @@ "profile.others_info": "Others", "profile.community.title": "Community", "profile.person.title": "Person", + "profile.image.edit": "Crop photo", "profile.image.upload": "Upload Photo", "activities.title": "Activities", "activities.create_article.description": "has published on", diff --git a/src/languages/pt.json b/src/languages/pt.json index f34900d..fe64608 100644 --- a/src/languages/pt.json +++ b/src/languages/pt.json @@ -23,6 +23,7 @@ "profile.others_info": "Outras informações", "profile.community.title": "Comunidade", "profile.person.title": "Pessoa", + "profile.image.edit": "Recortar photo", "profile.image.upload": "Enviar photo", "activities.title": "Atividades", "activities.create_article.description": "publicou em", diff --git a/src/lib/ng-noosfero-api/http/person.service.ts b/src/lib/ng-noosfero-api/http/person.service.ts index 914ffbc..b85e8eb 100644 --- a/src/lib/ng-noosfero-api/http/person.service.ts +++ b/src/lib/ng-noosfero-api/http/person.service.ts @@ -1,6 +1,6 @@ import { Injectable, Inject } from "ng-forward"; -import {RestangularService} from "./restangular_service"; -import {ProfileService} from "./profile.service"; +import { RestangularService } from "./restangular_service"; +import { ProfileService } from "./profile.service"; @Injectable() @Inject("Restangular", "$q", "$log", ProfileService) @@ -29,12 +29,12 @@ export class PersonService extends RestangularService { return deferred.promise; } - uploadImage(profile: noosfero.Profile, base64_image_json: any) { + uploadImage(profile: noosfero.Profile, base64ImageJson: any) { let headers = { 'Content-Type': 'application/json' }; let deferred = this.$q.defer>(); // TODO dynamically copy the selected attributes to update let attributesToUpdate: any = { - person: { image_builder: base64_image_json } + person: { image_builder: base64ImageJson } }; let restRequest: ng.IPromise> = this.getElement(profile.id).customPOST(attributesToUpdate, null, null, headers); -- libgit2 0.21.2