Commit e5bf6243c8b4d46498f368f434b0ca60271c7411
1 parent
dacb4561
Exists in
master
and in
1 other branch
Migrate noosfero activities to ngforward
Showing
15 changed files
with
128 additions
and
71 deletions
Show diff stats
src/app/components/noosfero-activities/activities.component.js
| @@ -1,14 +0,0 @@ | @@ -1,14 +0,0 @@ | ||
| 1 | -(function() { | ||
| 2 | - 'use strict'; | ||
| 3 | - | ||
| 4 | - angular | ||
| 5 | - .module('noosferoApp') | ||
| 6 | - .component('noosferoActivities', { | ||
| 7 | - restrict: 'E', | ||
| 8 | - bindings: { | ||
| 9 | - activities: '<' | ||
| 10 | - }, | ||
| 11 | - templateUrl: 'app/components/noosfero-activities/activities.html' | ||
| 12 | - }); | ||
| 13 | - | ||
| 14 | -})(); |
src/app/components/noosfero-activities/activities.component.spec.ts
0 → 100644
| @@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
| 1 | +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; | ||
| 2 | +import {Pipe, Input, provide, Component} from 'ng-forward'; | ||
| 3 | +import {provideFilters} from '../../../spec/helpers'; | ||
| 4 | + | ||
| 5 | +import {NoosferoActivities} from './activities.component'; | ||
| 6 | + | ||
| 7 | +const tcb = new TestComponentBuilder(); | ||
| 8 | + | ||
| 9 | +const htmlTemplate: string = '<noosfero-activities [activities]="ctrl.activities"></noosfero-activities>'; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +describe("Components", () => { | ||
| 13 | + | ||
| 14 | + describe("Noosfero Activities", () => { | ||
| 15 | + | ||
| 16 | + beforeEach(angular.mock.module("templates")); | ||
| 17 | + | ||
| 18 | + @Component({ | ||
| 19 | + selector: 'test-container-component', | ||
| 20 | + template: htmlTemplate, | ||
| 21 | + directives: [NoosferoActivities], | ||
| 22 | + providers: provideFilters("truncateFilter", "stripTagsFilter") | ||
| 23 | + }) | ||
| 24 | + class BlockContainerComponent { | ||
| 25 | + activities = [{ name: "activity1", verb: "create_article" }, { name: "activity2", verb: "create_article" }]; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + it("render a noosfero activity tag for each activity", done => { | ||
| 29 | + tcb.createAsync(BlockContainerComponent).then(fixture => { | ||
| 30 | + expect(fixture.debugElement.queryAll("noosfero-activity").length).toEqual(2); | ||
| 31 | + done(); | ||
| 32 | + }); | ||
| 33 | + }); | ||
| 34 | + }); | ||
| 35 | + | ||
| 36 | +}); |
src/app/components/noosfero-activities/activities.component.ts
| 1 | -(function() { | ||
| 2 | - 'use strict'; | 1 | +import {Component, Input} from "ng-forward"; |
| 2 | +import {NoosferoActivity} from "./activity/activity.component"; | ||
| 3 | +import {Activity} from "../../models/interfaces"; | ||
| 3 | 4 | ||
| 4 | - angular | ||
| 5 | - .module('noosferoApp') | ||
| 6 | - .component('noosferoActivities', { | ||
| 7 | - bindings: { | ||
| 8 | - activities: '<' | ||
| 9 | - }, | ||
| 10 | - templateUrl: 'app/components/noosfero-activities/activities.html' | ||
| 11 | - }); | 5 | +@Component({ |
| 6 | + selector: "noosfero-activities", | ||
| 7 | + templateUrl: 'app/components/noosfero-activities/activities.html', | ||
| 8 | + directives: [NoosferoActivity] | ||
| 9 | +}) | ||
| 10 | +export class NoosferoActivities { | ||
| 12 | 11 | ||
| 13 | -})(); | 12 | + @Input() activities: Activity[]; |
| 13 | + | ||
| 14 | +} |
src/app/components/noosfero-activities/activities.html
| 1 | <timeline> | 1 | <timeline> |
| 2 | - <timeline-event ng-repeat="activity in $ctrl.activities | orderBy: 'created_at':true"> | ||
| 3 | - <noosfero-activity activity="activity"></noosfero-activity> | 2 | + <timeline-event ng-repeat="activity in ctrl.activities | orderBy: 'created_at':true"> |
| 3 | + <noosfero-activity [activity]="activity"></noosfero-activity> | ||
| 4 | </timeline-event> | 4 | </timeline-event> |
| 5 | </timeline> | 5 | </timeline> |
src/app/components/noosfero-activities/activity/activity.component.js
| @@ -1,24 +0,0 @@ | @@ -1,24 +0,0 @@ | ||
| 1 | -(function() { | ||
| 2 | - 'use strict'; | ||
| 3 | - | ||
| 4 | - angular | ||
| 5 | - .module('noosferoApp') | ||
| 6 | - .component('noosferoActivity', { | ||
| 7 | - restrict: 'E', | ||
| 8 | - bindings: { | ||
| 9 | - activity: '<' | ||
| 10 | - }, | ||
| 11 | - templateUrl: 'app/components/noosfero-activities/activity/activity.html', | ||
| 12 | - replace: true, | ||
| 13 | - controller: ActivityController | ||
| 14 | - }); | ||
| 15 | - | ||
| 16 | - /** @ngInject */ | ||
| 17 | - function ActivityController() { | ||
| 18 | - var vm = this; | ||
| 19 | - vm.getActivityTemplate = function(activity) { | ||
| 20 | - return 'app/components/noosfero-activities/activity/' + activity.verb + '.html'; | ||
| 21 | - } | ||
| 22 | - } | ||
| 23 | - | ||
| 24 | -})(); |
src/app/components/noosfero-activities/activity/activity.component.spec.ts
0 → 100644
| @@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
| 1 | +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; | ||
| 2 | +import {Pipe, Input, provide, Component} from 'ng-forward'; | ||
| 3 | +import {provideFilters} from '../../../../spec/helpers'; | ||
| 4 | + | ||
| 5 | +import {NoosferoActivity} from './activity.component'; | ||
| 6 | + | ||
| 7 | +const tcb = new TestComponentBuilder(); | ||
| 8 | + | ||
| 9 | +const htmlTemplate: string = '<noosfero-activity [activity]="ctrl.activity"></noosfero-activity>'; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +describe("Components", () => { | ||
| 13 | + | ||
| 14 | + describe("Noosfero Activity", () => { | ||
| 15 | + | ||
| 16 | + beforeEach(angular.mock.module("templates")); | ||
| 17 | + | ||
| 18 | + @Component({ | ||
| 19 | + selector: 'test-container-component', | ||
| 20 | + template: htmlTemplate, | ||
| 21 | + directives: [NoosferoActivity], | ||
| 22 | + providers: provideFilters("truncateFilter", "stripTagsFilter") | ||
| 23 | + }) | ||
| 24 | + class BlockContainerComponent { | ||
| 25 | + activity = { name: "activity1", verb: "create_article" }; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + it("render the specific template for an activity verb", done => { | ||
| 29 | + tcb.createAsync(BlockContainerComponent).then(fixture => { | ||
| 30 | + let component: NoosferoActivity = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
| 31 | + expect(component.getActivityTemplate()).toEqual('app/components/noosfero-activities/activity/create_article.html'); | ||
| 32 | + expect(fixture.debugElement.queryAll(".activity.create_article").length).toEqual(1); | ||
| 33 | + done(); | ||
| 34 | + }); | ||
| 35 | + }); | ||
| 36 | + }); | ||
| 37 | + | ||
| 38 | +}); |
src/app/components/noosfero-activities/activity/activity.component.ts
0 → 100644
| @@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
| 1 | +import {Component, Input} from "ng-forward"; | ||
| 2 | +import {Activity} from "../../../models/interfaces"; | ||
| 3 | + | ||
| 4 | +@Component({ | ||
| 5 | + selector: "noosfero-activity", | ||
| 6 | + templateUrl: 'app/components/noosfero-activities/activity/activity.html' | ||
| 7 | +}) | ||
| 8 | +export class NoosferoActivity { | ||
| 9 | + | ||
| 10 | + @Input() activity: Activity; | ||
| 11 | + | ||
| 12 | + getActivityTemplate() { | ||
| 13 | + return 'app/components/noosfero-activities/activity/' + this.activity.verb + '.html'; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | +} |
src/app/components/noosfero-activities/activity/activity.html
src/app/components/noosfero-activities/activity/add_member_in_community.html
| @@ -4,10 +4,10 @@ | @@ -4,10 +4,10 @@ | ||
| 4 | <timeline-panel> | 4 | <timeline-panel> |
| 5 | <timeline-heading> | 5 | <timeline-heading> |
| 6 | <h4 class="timeline-title"> | 6 | <h4 class="timeline-title"> |
| 7 | - <a ui-sref="main.profile.info({profile: $ctrl.activity.user.identifier})"><strong ng-bind="$ctrl.activity.user.name"></strong></a> | 7 | + <a ui-sref="main.profile.info({profile: ctrl.activity.user.identifier})"><strong ng-bind="ctrl.activity.user.name"></strong></a> |
| 8 | <span> has joined the community</span> | 8 | <span> has joined the community</span> |
| 9 | </h4> | 9 | </h4> |
| 10 | - <p><small class="text-muted"><i class="fa fa-clock-o"></i> <span am-time-ago="$ctrl.activity.created_at"></span></small></p> | 10 | + <p><small class="text-muted"><i class="fa fa-clock-o"></i> <span am-time-ago="ctrl.activity.created_at"></span></small></p> |
| 11 | </timeline-heading> | 11 | </timeline-heading> |
| 12 | <div class="timeline-body"></div> | 12 | <div class="timeline-body"></div> |
| 13 | </timeline-panel> | 13 | </timeline-panel> |
src/app/components/noosfero-activities/activity/create_article.html
| @@ -4,22 +4,22 @@ | @@ -4,22 +4,22 @@ | ||
| 4 | <timeline-panel> | 4 | <timeline-panel> |
| 5 | <timeline-heading> | 5 | <timeline-heading> |
| 6 | <h4 class="timeline-title"> | 6 | <h4 class="timeline-title"> |
| 7 | - <a ui-sref="main.profile.info({profile: $ctrl.activity.user.identifier})"><strong ng-bind="$ctrl.activity.user.name"></strong></a> | 7 | + <a ui-sref="main.profile.info({profile: ctrl.activity.user.identifier})"><strong ng-bind="ctrl.activity.user.name"></strong></a> |
| 8 | <span> has published on </span> | 8 | <span> has published on </span> |
| 9 | - <a ui-sref="main.profile.info({profile: $ctrl.activity.target.article.profile.identifier})"> | ||
| 10 | - <strong ng-bind="$ctrl.activity.target.article.profile.name"></strong></span> | 9 | + <a ui-sref="main.profile.info({profile: ctrl.activity.target.article.profile.identifier})"> |
| 10 | + <strong ng-bind="ctrl.activity.target.article.profile.name"></strong></span> | ||
| 11 | </a> | 11 | </a> |
| 12 | </h4> | 12 | </h4> |
| 13 | - <p><small class="text-muted"><i class="fa fa-clock-o"></i> <span am-time-ago="$ctrl.activity.created_at"></span></small></p> | 13 | + <p><small class="text-muted"><i class="fa fa-clock-o"></i> <span am-time-ago="ctrl.activity.created_at"></span></small></p> |
| 14 | </timeline-heading> | 14 | </timeline-heading> |
| 15 | <div class="timeline-body"> | 15 | <div class="timeline-body"> |
| 16 | <div class="article"> | 16 | <div class="article"> |
| 17 | <div class="title"> | 17 | <div class="title"> |
| 18 | - <a ui-sref="main.profile.page({profile: $ctrl.activity.target.article.profile.identifier, page: $ctrl.activity.target.article.path})" | ||
| 19 | - ng-bind="$ctrl.activity.target.article.title"></a> | 18 | + <a ui-sref="main.profile.page({profile: ctrl.activity.target.article.profile.identifier, page: ctrl.activity.target.article.path})" |
| 19 | + ng-bind="ctrl.activity.target.article.title"></a> | ||
| 20 | </div> | 20 | </div> |
| 21 | <div class="lead small"> | 21 | <div class="lead small"> |
| 22 | - <div ng-bind-html="$ctrl.activity.target.article.body | stripTags | truncate: 100 : '...': true"></div> | 22 | + <div ng-bind-html="ctrl.activity.target.article.body | stripTags | truncate: 100 : '...': true"></div> |
| 23 | </div> | 23 | </div> |
| 24 | </div> | 24 | </div> |
| 25 | </div> | 25 | </div> |
src/app/components/noosfero-activities/activity/new_friendship.html
| @@ -4,15 +4,15 @@ | @@ -4,15 +4,15 @@ | ||
| 4 | <timeline-panel> | 4 | <timeline-panel> |
| 5 | <timeline-heading> | 5 | <timeline-heading> |
| 6 | <h4 class="timeline-title"> | 6 | <h4 class="timeline-title"> |
| 7 | - <a ui-sref="main.profile.info({profile: $ctrl.activity.user.identifier})"><strong ng-bind="$ctrl.activity.user.name"></strong></a> | ||
| 8 | - <span> has made <span ng-bind="$ctrl.activity.params.friend_name.length"></span> new friend(s): </span> | 7 | + <a ui-sref="main.profile.info({profile: ctrl.activity.user.identifier})"><strong ng-bind="ctrl.activity.user.name"></strong></a> |
| 8 | + <span> has made <span ng-bind="ctrl.activity.params.friend_name.length"></span> new friend(s): </span> | ||
| 9 | <span class="comma-separated"> | 9 | <span class="comma-separated"> |
| 10 | - <a class="separated-item" ui-sref="main.profile.info({profile: $ctrl.activity.params.friend_url[$index].profile})" ng-repeat="friend in $ctrl.activity.params.friend_name"> | 10 | + <a class="separated-item" ui-sref="main.profile.info({profile: ctrl.activity.params.friend_url[$index].profile})" ng-repeat="friend in ctrl.activity.params.friend_name"> |
| 11 | <strong ng-bind="friend"></strong> | 11 | <strong ng-bind="friend"></strong> |
| 12 | </a> | 12 | </a> |
| 13 | </span> | 13 | </span> |
| 14 | </h4> | 14 | </h4> |
| 15 | - <p><small class="text-muted"><i class="fa fa-clock-o"></i> <span am-time-ago="$ctrl.activity.created_at"></span></small></p> | 15 | + <p><small class="text-muted"><i class="fa fa-clock-o"></i> <span am-time-ago="ctrl.activity.created_at"></span></small></p> |
| 16 | </timeline-heading> | 16 | </timeline-heading> |
| 17 | <div class="timeline-body"></div> | 17 | <div class="timeline-body"></div> |
| 18 | </timeline-panel> | 18 | </timeline-panel> |
src/app/index.ts
| @@ -42,8 +42,6 @@ NoosferoApp.run(noosferoAngularRunBlock); | @@ -42,8 +42,6 @@ NoosferoApp.run(noosferoAngularRunBlock); | ||
| 42 | NoosferoApp.addController("AuthController", AuthController); | 42 | NoosferoApp.addController("AuthController", AuthController); |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | -require("./components/noosfero-activities/activities.component.js"); | ||
| 46 | -require("./components/noosfero-activities/activity/activity.component.js"); | ||
| 47 | require("./components/noosfero/noosfero-template.filter.js"); | 45 | require("./components/noosfero/noosfero-template.filter.js"); |
| 48 | require("./components/noosfero/noosfero.service.js"); | 46 | require("./components/noosfero/noosfero.service.js"); |
| 49 | require("./components/noosfero/profile-image/profile-image.component.js"); | 47 | require("./components/noosfero/profile-image/profile-image.component.js"); |
src/app/models/interfaces.ts
| @@ -51,6 +51,10 @@ export interface Box { | @@ -51,6 +51,10 @@ export interface Box { | ||
| 51 | position: number; | 51 | position: number; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | +export interface Activity { | ||
| 55 | + verb: string; | ||
| 56 | +} | ||
| 57 | + | ||
| 54 | export interface INoosferoLocalStorage extends angular.storage.ILocalStorageService { | 58 | export interface INoosferoLocalStorage extends angular.storage.ILocalStorageService { |
| 55 | currentUser: User; | 59 | currentUser: User; |
| 56 | -} | ||
| 57 | \ No newline at end of file | 60 | \ No newline at end of file |
| 61 | +} |
src/app/profile-info/profile-info.html
| @@ -2,5 +2,5 @@ | @@ -2,5 +2,5 @@ | ||
| 2 | 2 | ||
| 3 | <div class="profile-wall"> | 3 | <div class="profile-wall"> |
| 4 | <h4>Profile Wall</h4> | 4 | <h4>Profile Wall</h4> |
| 5 | - <noosfero-activities activities="vm.activities"></noosfero-activities> | 5 | + <noosfero-activities [activities]="vm.activities"></noosfero-activities> |
| 6 | </div> | 6 | </div> |
src/app/profile/profile.component.ts
| @@ -3,12 +3,14 @@ import {ProfileInfo} from '../profile-info/profile-info.component'; | @@ -3,12 +3,14 @@ import {ProfileInfo} from '../profile-info/profile-info.component'; | ||
| 3 | import {ProfileHome} from '../profile/profile-home.component'; | 3 | import {ProfileHome} from '../profile/profile-home.component'; |
| 4 | import {Cms} from '../cms/cms.component'; | 4 | import {Cms} from '../cms/cms.component'; |
| 5 | import {ContentViewer} from "../content-viewer/content-viewer.component"; | 5 | import {ContentViewer} from "../content-viewer/content-viewer.component"; |
| 6 | +import {NoosferoActivities} from "../components/noosfero-activities/activities.component"; | ||
| 6 | 7 | ||
| 7 | import * as noosferoModels from "./../models/interfaces"; | 8 | import * as noosferoModels from "./../models/interfaces"; |
| 8 | 9 | ||
| 9 | @Component({ | 10 | @Component({ |
| 10 | selector: 'profile', | 11 | selector: 'profile', |
| 11 | - templateUrl: "app/profile/profile.html" | 12 | + templateUrl: "app/profile/profile.html", |
| 13 | + directives: [NoosferoActivities] | ||
| 12 | }) | 14 | }) |
| 13 | @StateConfig([ | 15 | @StateConfig([ |
| 14 | { | 16 | { |