Commit 9ae229e6b5ea11e064b3d6ed92b224d754081306
1 parent
7f10a7cf
Exists in
master
and in
35 other branches
Migrate recent documents block to ngforward
Showing
7 changed files
with
106 additions
and
37 deletions
Show diff stats
src/app/components/noosfero-blocks/recent-documents/recent-documents.component.js
... | ... | @@ -1,33 +0,0 @@ |
1 | -(function() { | |
2 | - 'use strict'; | |
3 | - | |
4 | - angular | |
5 | - .module('noosferoApp') | |
6 | - .component('noosferoRecentDocumentsBlock', { | |
7 | - restrict: 'E', | |
8 | - templateUrl: 'app/components/noosfero-blocks/recent-documents/recent-documents.html', | |
9 | - bindings: { | |
10 | - block: '<', | |
11 | - owner: '<' | |
12 | - }, | |
13 | - controller: RecentDocumentsController | |
14 | - }); | |
15 | - | |
16 | - /** @ngInject */ | |
17 | - function RecentDocumentsController(noosfero, $state) { | |
18 | - var vm = this; | |
19 | - vm.profile = vm.owner; | |
20 | - vm.documents = []; | |
21 | - | |
22 | - vm.openDocument = function(article) { | |
23 | - $state.go("main.profile.page", {page: article.path, profile: article.profile.identifier}); | |
24 | - } | |
25 | - | |
26 | - var limit = vm.block.settings.limit || 5; | |
27 | - //FIXME get all text articles | |
28 | - noosfero.profiles.one(vm.profile.id).one('articles').get({content_type: 'TinyMceArticle', per_page: limit}).then(function(response) { | |
29 | - vm.documents = response.data.articles; | |
30 | - }); | |
31 | - } | |
32 | - | |
33 | -})(); |
src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts
0 → 100644
... | ... | @@ -0,0 +1,52 @@ |
1 | +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; | |
2 | +import {Provider, Input, provide, Component} from 'ng-forward'; | |
3 | + | |
4 | +import {RecentDocumentsBlock} from './recent-documents.component'; | |
5 | + | |
6 | +const htmlTemplate: string = '<noosfero-recent-documents-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-recent-documents-block>'; | |
7 | + | |
8 | +const tcb = new TestComponentBuilder(); | |
9 | + | |
10 | +describe("Recent Documents Block Component", () => { | |
11 | + | |
12 | + beforeEach(angular.mock.module("templates")); | |
13 | + | |
14 | + let state = jasmine.createSpyObj("state", ["go"]); | |
15 | + let providers = [ | |
16 | + new Provider('truncateFilter', { useValue: () => { } }), | |
17 | + new Provider('stripTagsFilter', { useValue: () => { } }), | |
18 | + new Provider('$state', { useValue: state }), | |
19 | + new Provider('ArticleService', { | |
20 | + useValue: { | |
21 | + getByProfile: (profileId: number, filters: any): any => { | |
22 | + return Promise.resolve({ data: { articles: [{ name: "article1" }] } }); | |
23 | + } | |
24 | + } | |
25 | + }), | |
26 | + ]; | |
27 | + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlock], providers: providers }) | |
28 | + class BlockContainerComponent { | |
29 | + block = { type: 'Block', settings: {} }; | |
30 | + owner = { name: 'profile-name' }; | |
31 | + constructor() { | |
32 | + } | |
33 | + } | |
34 | + | |
35 | + it("get recent documents from the article service", done => { | |
36 | + tcb.createAsync(BlockContainerComponent).then(fixture => { | |
37 | + let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance; | |
38 | + expect(recentDocumentsBlock.documents).toEqual([{ name: "article1" }]); | |
39 | + done(); | |
40 | + }); | |
41 | + }); | |
42 | + | |
43 | + it("go to article page when open a document", done => { | |
44 | + tcb.createAsync(BlockContainerComponent).then(fixture => { | |
45 | + let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance; | |
46 | + recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } }); | |
47 | + expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" }); | |
48 | + done(); | |
49 | + }); | |
50 | + }); | |
51 | + | |
52 | +}); | ... | ... |
src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts
0 → 100644
... | ... | @@ -0,0 +1,35 @@ |
1 | +import {Component, Inject, Input} from "ng-forward"; | |
2 | +import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service"; | |
3 | + | |
4 | +@Component({ | |
5 | + selector: "noosfero-recent-documents-block", | |
6 | + templateUrl: 'app/components/noosfero-blocks/recent-documents/recent-documents.html' | |
7 | +}) | |
8 | +@Inject(ArticleService, "$state") | |
9 | +export class RecentDocumentsBlock { | |
10 | + | |
11 | + @Input() block: any; | |
12 | + @Input() owner: any; | |
13 | + | |
14 | + profile: any; | |
15 | + documents: any; | |
16 | + | |
17 | + constructor(private ArticleService: ArticleService, private $state: any) { | |
18 | + } | |
19 | + | |
20 | + ngOnInit() { | |
21 | + this.profile = this.owner; | |
22 | + this.documents = []; | |
23 | + | |
24 | + var limit = (this.block && this.block.settings) ? this.block.settings.limit : null || 5; | |
25 | + //FIXME get all text articles | |
26 | + this.ArticleService.getByProfile(this.profile.id, { content_type: 'TinyMceArticle', per_page: limit }).then((response: any) => { | |
27 | + this.documents = response.data.articles; | |
28 | + }); | |
29 | + } | |
30 | + | |
31 | + openDocument(article: any) { | |
32 | + this.$state.go("main.profile.page", { page: article.path, profile: article.profile.identifier }); | |
33 | + } | |
34 | + | |
35 | +} | ... | ... |
src/app/components/noosfero-blocks/recent-documents/recent-documents.html
1 | -<div deckgrid source="$ctrl.documents" class="deckgrid"> | |
2 | - <div class="a-card panel media" ng-click="mother.$ctrl.openDocument(card);"> | |
1 | +<div deckgrid source="ctrl.documents" class="deckgrid"> | |
2 | + <div class="a-card panel media" ng-click="mother.ctrl.openDocument(card);"> | |
3 | 3 | <div class="author media-left" ng-show="card.author.image"> |
4 | 4 | <img ng-src="{{card.author.image.url}}" class="img-circle"> |
5 | 5 | </div> | ... | ... |
src/app/index.ts
... | ... | @@ -47,7 +47,6 @@ require("./components/noosfero-activities/activities.component.js"); |
47 | 47 | require("./components/noosfero-activities/activity/activity.component.js"); |
48 | 48 | require("./components/noosfero-blocks/members-block/members-block.component.js"); |
49 | 49 | require("./components/noosfero-blocks/profile-image/profile-image.component.js"); |
50 | -require("./components/noosfero-blocks/recent-documents/recent-documents.component.js"); | |
51 | 50 | require("./components/noosfero/noosfero-template.filter.js"); |
52 | 51 | require("./components/noosfero/noosfero.service.js"); |
53 | 52 | require("./components/noosfero/profile-image/profile-image.component.js"); | ... | ... |
src/app/main/main.component.ts
... | ... | @@ -7,6 +7,7 @@ import {Profile} from "../profile/profile.component"; |
7 | 7 | 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 | +import {RecentDocumentsBlock} from "../components/noosfero-blocks/recent-documents/recent-documents.component"; | |
10 | 11 | |
11 | 12 | |
12 | 13 | import {AuthService} from "./../components/auth/auth_service"; |
... | ... | @@ -30,7 +31,7 @@ export class MainContent { |
30 | 31 | @Component({ |
31 | 32 | selector: 'main', |
32 | 33 | template: '<div ng-view></div>', |
33 | - directives: [NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock, MainBlock, Navbar], | |
34 | + directives: [NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock, MainBlock, RecentDocumentsBlock, Navbar], | |
34 | 35 | providers: [AuthService, Session] |
35 | 36 | }) |
36 | 37 | @StateConfig([ | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +import { Injectable, Inject } from "ng-forward"; | |
2 | + | |
3 | +@Injectable() | |
4 | +@Inject("Restangular") | |
5 | +export class ArticleService { | |
6 | + | |
7 | + constructor(private Restangular: any) { | |
8 | + | |
9 | + } | |
10 | + | |
11 | + getByProfile(profileId: number, filters: any) { | |
12 | + return this.Restangular.service('profiles').one(profileId).one('articles').get(filters); | |
13 | + } | |
14 | + | |
15 | +} | ... | ... |