From 9b3a27c9804db1b9a5d72e43ca85b6579815de3f Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Tue, 10 May 2016 09:20:41 -0300 Subject: [PATCH] refactoring recent documents block --- src/app/layout/blocks/recent-documents/index.ts | 2 +- src/app/layout/blocks/recent-documents/recent-documents-block.component.spec.ts | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/app/layout/blocks/recent-documents/recent-documents-block.component.ts | 41 +++++++++++++++++++++++++++++++++++++++++ src/app/layout/blocks/recent-documents/recent-documents-block.html | 18 ++++++++++++++++++ src/app/layout/blocks/recent-documents/recent-documents-block.scss | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/app/layout/blocks/recent-documents/recent-documents.component.spec.ts | 80 -------------------------------------------------------------------------------- src/app/layout/blocks/recent-documents/recent-documents.component.ts | 41 ----------------------------------------- src/app/layout/blocks/recent-documents/recent-documents.html | 18 ------------------ src/app/layout/blocks/recent-documents/recent-documents.scss | 65 ----------------------------------------------------------------- src/app/main/main.component.ts | 2 +- 10 files changed, 206 insertions(+), 206 deletions(-) create mode 100644 src/app/layout/blocks/recent-documents/recent-documents-block.component.spec.ts create mode 100644 src/app/layout/blocks/recent-documents/recent-documents-block.component.ts create mode 100644 src/app/layout/blocks/recent-documents/recent-documents-block.html create mode 100644 src/app/layout/blocks/recent-documents/recent-documents-block.scss delete mode 100644 src/app/layout/blocks/recent-documents/recent-documents.component.spec.ts delete mode 100644 src/app/layout/blocks/recent-documents/recent-documents.component.ts delete mode 100644 src/app/layout/blocks/recent-documents/recent-documents.html delete mode 100644 src/app/layout/blocks/recent-documents/recent-documents.scss diff --git a/src/app/layout/blocks/recent-documents/index.ts b/src/app/layout/blocks/recent-documents/index.ts index 875a233..31d6c34 100644 --- a/src/app/layout/blocks/recent-documents/index.ts +++ b/src/app/layout/blocks/recent-documents/index.ts @@ -1,2 +1,2 @@ /* Module Index Entry - generated using the script npm run generate-index */ -export * from "./recent-documents.component"; +export * from "./recent-documents-block.component"; diff --git a/src/app/layout/blocks/recent-documents/recent-documents-block.component.spec.ts b/src/app/layout/blocks/recent-documents/recent-documents-block.component.spec.ts new file mode 100644 index 0000000..ff0895e --- /dev/null +++ b/src/app/layout/blocks/recent-documents/recent-documents-block.component.spec.ts @@ -0,0 +1,80 @@ +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; +import {Provider, Input, provide, Component} from 'ng-forward'; +import {provideFilters} from '../../../../spec/helpers'; +import {RecentDocumentsBlockComponent} from './recent-documents-block.component'; + +const htmlTemplate: string = ''; + +const tcb = new TestComponentBuilder(); + +describe("Components", () => { + describe("Recent Documents Block Component", () => { + + let settingsObj = {}; + let mockedArticleService = { + getByProfile: (profile: noosfero.Profile, filters: any): any => { + return Promise.resolve({ data: [{ name: "article1" }], headers: (name: string) => { return name; } }); + } + }; + let profile = { name: 'profile-name' }; + beforeEach(angular.mock.module("templates")); + + let state = jasmine.createSpyObj("state", ["go"]); + + + function getProviders() { + return [ + new Provider('$state', { useValue: state }), + new Provider('ArticleService', { + useValue: mockedArticleService + }), + ].concat(provideFilters("truncateFilter", "stripTagsFilter")); + } + let componentClass: any = null; + + function getComponent() { + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlockComponent], providers: getProviders() }) + class BlockContainerComponent { + block = { type: 'Block', settings: settingsObj }; + owner = profile; + constructor() { + } + } + return BlockContainerComponent; + } + + + it("get recent documents from the article service", done => { + tcb.createAsync(getComponent()).then(fixture => { + let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + expect(recentDocumentsBlock.documents).toEqual([{ name: "article1" }]); + done(); + }); + }); + + it("go to article page when open a document", done => { + tcb.createAsync(getComponent()).then(fixture => { + let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } }); + expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" }); + done(); + }); + }); + + it("it uses default limit 5 if not defined on block", done => { + settingsObj = null; + mockedArticleService = jasmine.createSpyObj("mockedArticleService", ["getByProfile"]); + (mockedArticleService).mocked = true; + let thenMocked = jasmine.createSpy("then"); + mockedArticleService.getByProfile = jasmine.createSpy("getByProfile").and.returnValue({then: thenMocked}); + let getByProfileFunct = mockedArticleService.getByProfile; + tcb.createAsync(getComponent()).then(fixture => { + let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } }); + expect(getByProfileFunct).toHaveBeenCalledWith(profile, { content_type: 'TinyMceArticle', per_page: 5 }); + done(); + }); + }); + + }); +}); diff --git a/src/app/layout/blocks/recent-documents/recent-documents-block.component.ts b/src/app/layout/blocks/recent-documents/recent-documents-block.component.ts new file mode 100644 index 0000000..54e9c2e --- /dev/null +++ b/src/app/layout/blocks/recent-documents/recent-documents-block.component.ts @@ -0,0 +1,41 @@ +import {Component, Inject, Input} from "ng-forward"; +import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service"; + +@Component({ + selector: "noosfero-recent-documents-block", + templateUrl: 'app/layout/blocks/recent-documents/recent-documents-block.html' +}) +@Inject(ArticleService, "$state") +export class RecentDocumentsBlockComponent { + + @Input() block: any; + @Input() owner: any; + + profile: any; + documents: any; + + documentsLoaded: boolean = false; + + constructor(private articleService: ArticleService, private $state: any) { + } + + ngOnInit() { + this.profile = this.owner; + this.documents = []; + + let limit = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5; + // FIXME get all text articles + // FIXME make the getByProfile a generic method where we tell the type passing a class TinyMceArticle + // and the promise should be of type TinyMceArticle[], per example + this.articleService.getByProfile(this.profile, { content_type: 'TinyMceArticle', per_page: limit }) + .then((result: noosfero.RestResult) => { + this.documents = result.data; + this.documentsLoaded = true; + }); + } + + openDocument(article: any) { + this.$state.go("main.profile.page", { page: article.path, profile: article.profile.identifier }); + } + +} diff --git a/src/app/layout/blocks/recent-documents/recent-documents-block.html b/src/app/layout/blocks/recent-documents/recent-documents-block.html new file mode 100644 index 0000000..1421cfe --- /dev/null +++ b/src/app/layout/blocks/recent-documents/recent-documents-block.html @@ -0,0 +1,18 @@ +
+
+
+ +
+
+
+ +
+ + + +
+
+ +
+
+
diff --git a/src/app/layout/blocks/recent-documents/recent-documents-block.scss b/src/app/layout/blocks/recent-documents/recent-documents-block.scss new file mode 100644 index 0000000..74cf5e9 --- /dev/null +++ b/src/app/layout/blocks/recent-documents/recent-documents-block.scss @@ -0,0 +1,65 @@ +.block.recentdocumentsblock { + .deckgrid[deckgrid]::before { + font-size: 0; /* See https://github.com/akoenig/angular-deckgrid/issues/14#issuecomment-35728861 */ + visibility: hidden; + } + .author { + img { + width: 30px; + height: 30px; + } + } + .header { + .subheader { + color: #C1C1C1; + font-size: 10px; + } + } + .post-lead { + color: #8E8E8E; + font-size: 14px; + } + .article-image { + margin: 10px 0; + } +} + +.col-md-2-5 { + .deckgrid[deckgrid]::before { + content: '1 .deck-column'; + } +} + +.col-md-7 { + .block.recentdocumentsblock { + background-color: transparent; + border: 0; + + .deckgrid[deckgrid]::before { + content: '3 .deck-column'; + } + + .panel-heading { + display: none; + } + .panel-body { + padding: 0; + } + + .deckgrid { + .column { + float: left; + } + + .deck-column { + @extend .col-md-4; + padding: 0; + + .a-card { + padding: 10px; + margin: 3px; + } + } + } + } +} diff --git a/src/app/layout/blocks/recent-documents/recent-documents.component.spec.ts b/src/app/layout/blocks/recent-documents/recent-documents.component.spec.ts deleted file mode 100644 index 6125633..0000000 --- a/src/app/layout/blocks/recent-documents/recent-documents.component.spec.ts +++ /dev/null @@ -1,80 +0,0 @@ -import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; -import {Provider, Input, provide, Component} from 'ng-forward'; -import {provideFilters} from '../../../../spec/helpers'; -import {RecentDocumentsBlockComponent} from './recent-documents.component'; - -const htmlTemplate: string = ''; - -const tcb = new TestComponentBuilder(); - -describe("Components", () => { - describe("Recent Documents Block Component", () => { - - let settingsObj = {}; - let mockedArticleService = { - getByProfile: (profile: noosfero.Profile, filters: any): any => { - return Promise.resolve({ data: [{ name: "article1" }], headers: (name: string) => { return name; } }); - } - }; - let profile = { name: 'profile-name' }; - beforeEach(angular.mock.module("templates")); - - let state = jasmine.createSpyObj("state", ["go"]); - - - function getProviders() { - return [ - new Provider('$state', { useValue: state }), - new Provider('ArticleService', { - useValue: mockedArticleService - }), - ].concat(provideFilters("truncateFilter", "stripTagsFilter")); - } - let componentClass: any = null; - - function getComponent() { - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlockComponent], providers: getProviders() }) - class BlockContainerComponent { - block = { type: 'Block', settings: settingsObj }; - owner = profile; - constructor() { - } - } - return BlockContainerComponent; - } - - - it("get recent documents from the article service", done => { - tcb.createAsync(getComponent()).then(fixture => { - let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; - expect(recentDocumentsBlock.documents).toEqual([{ name: "article1" }]); - done(); - }); - }); - - it("go to article page when open a document", done => { - tcb.createAsync(getComponent()).then(fixture => { - let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; - recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } }); - expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" }); - done(); - }); - }); - - it("it uses default limit 5 if not defined on block", done => { - settingsObj = null; - mockedArticleService = jasmine.createSpyObj("mockedArticleService", ["getByProfile"]); - (mockedArticleService).mocked = true; - let thenMocked = jasmine.createSpy("then"); - mockedArticleService.getByProfile = jasmine.createSpy("getByProfile").and.returnValue({then: thenMocked}); - let getByProfileFunct = mockedArticleService.getByProfile; - tcb.createAsync(getComponent()).then(fixture => { - let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; - recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } }); - expect(getByProfileFunct).toHaveBeenCalledWith(profile, { content_type: 'TinyMceArticle', per_page: 5 }); - done(); - }); - }); - - }); -}); \ No newline at end of file diff --git a/src/app/layout/blocks/recent-documents/recent-documents.component.ts b/src/app/layout/blocks/recent-documents/recent-documents.component.ts deleted file mode 100644 index ac18d68..0000000 --- a/src/app/layout/blocks/recent-documents/recent-documents.component.ts +++ /dev/null @@ -1,41 +0,0 @@ -import {Component, Inject, Input} from "ng-forward"; -import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service"; - -@Component({ - selector: "noosfero-recent-documents-block", - templateUrl: 'app/layout/blocks/recent-documents/recent-documents.html' -}) -@Inject(ArticleService, "$state") -export class RecentDocumentsBlockComponent { - - @Input() block: any; - @Input() owner: any; - - profile: any; - documents: any; - - documentsLoaded: boolean = false; - - constructor(private articleService: ArticleService, private $state: any) { - } - - ngOnInit() { - this.profile = this.owner; - this.documents = []; - - let limit = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5; - // FIXME get all text articles - // FIXME make the getByProfile a generic method where we tell the type passing a class TinyMceArticle - // and the promise should be of type TinyMceArticle[], per example - this.articleService.getByProfile(this.profile, { content_type: 'TinyMceArticle', per_page: limit }) - .then((result: noosfero.RestResult) => { - this.documents = result.data; - this.documentsLoaded = true; - }); - } - - openDocument(article: any) { - this.$state.go("main.profile.page", { page: article.path, profile: article.profile.identifier }); - } - -} diff --git a/src/app/layout/blocks/recent-documents/recent-documents.html b/src/app/layout/blocks/recent-documents/recent-documents.html deleted file mode 100644 index 1421cfe..0000000 --- a/src/app/layout/blocks/recent-documents/recent-documents.html +++ /dev/null @@ -1,18 +0,0 @@ -
-
-
- -
-
-
- -
- - - -
-
- -
-
-
diff --git a/src/app/layout/blocks/recent-documents/recent-documents.scss b/src/app/layout/blocks/recent-documents/recent-documents.scss deleted file mode 100644 index 74cf5e9..0000000 --- a/src/app/layout/blocks/recent-documents/recent-documents.scss +++ /dev/null @@ -1,65 +0,0 @@ -.block.recentdocumentsblock { - .deckgrid[deckgrid]::before { - font-size: 0; /* See https://github.com/akoenig/angular-deckgrid/issues/14#issuecomment-35728861 */ - visibility: hidden; - } - .author { - img { - width: 30px; - height: 30px; - } - } - .header { - .subheader { - color: #C1C1C1; - font-size: 10px; - } - } - .post-lead { - color: #8E8E8E; - font-size: 14px; - } - .article-image { - margin: 10px 0; - } -} - -.col-md-2-5 { - .deckgrid[deckgrid]::before { - content: '1 .deck-column'; - } -} - -.col-md-7 { - .block.recentdocumentsblock { - background-color: transparent; - border: 0; - - .deckgrid[deckgrid]::before { - content: '3 .deck-column'; - } - - .panel-heading { - display: none; - } - .panel-body { - padding: 0; - } - - .deckgrid { - .column { - float: left; - } - - .deck-column { - @extend .col-md-4; - padding: 0; - - .a-card { - padding: 10px; - margin: 3px; - } - } - } - } -} diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 8989b88..3ac006c 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -11,7 +11,7 @@ import {EnvironmentComponent} from "../environment/environment.component"; import {EnvironmentHomeComponent} from "../environment/environment-home.component"; import {PeopleBlockComponent} from "../layout/blocks/people/people-block.component"; import {LinkListBlockComponent} from "./../layout/blocks/link-list/link-list-block.component"; -import {RecentDocumentsBlockComponent} from "../layout/blocks/recent-documents/recent-documents.component"; +import {RecentDocumentsBlockComponent} from "../layout/blocks/recent-documents/recent-documents-block.component"; import {ProfileImageBlockComponent} from "../layout/blocks/profile-image/profile-image-block.component"; import {RawHTMLBlockComponent} from "../layout/blocks/raw-html/raw-html-block.component"; -- libgit2 0.21.2