From 299d40d1a4492658da5572aac95ff1367776bc6a Mon Sep 17 00:00:00 2001 From: ABNER SILVA DE OLIVEIRA Date: Tue, 10 May 2016 19:48:40 -0300 Subject: [PATCH] updated to use statistics array property in statistic block to fill the statistic block content --- src/app/layout/blocks/statistics/statistics-block.component.spec.ts | 109 +++++++++++++++++++++++-------------------------------------------------------------------------------------- src/app/layout/blocks/statistics/statistics-block.component.ts | 15 --------------- src/app/layout/blocks/statistics/statistics-block.html | 4 ++-- src/lib/ng-noosfero-api/interfaces/statistics_block.ts | 22 ++++++---------------- 4 files changed, 31 insertions(+), 119 deletions(-) diff --git a/src/app/layout/blocks/statistics/statistics-block.component.spec.ts b/src/app/layout/blocks/statistics/statistics-block.component.spec.ts index 5a0771b..fd76e27 100644 --- a/src/app/layout/blocks/statistics/statistics-block.component.spec.ts +++ b/src/app/layout/blocks/statistics/statistics-block.component.spec.ts @@ -17,100 +17,37 @@ describe("Components", () => { providers: helpers.provideFilters("translateFilter"), properties: { block: { - user_counter: 1, users: 10, enterprise_counter: 1, enterprises: 20, - product_counter: 1, products: 30, community_counter: 1, communities: 40, - category_counter: 1, categories: 50, tag_counter: 1, tags: 60, - comment_counter: 1, comments: 70, hit_counter: 1, hits: 80 + statistics: [ + { + name: "users", + display: true, + quantity: 10 + }, + { + name: "communities", + display: true, + quantity: 20 + }, + { + name: "hits", + display: false, + quantity: null + } + ] } } - // this.counters.push({ 'should_display': this.block.enterprise_counter, 'value': this.block.enterprises, 'name': 'enterprises' }) - // this.counters.push({ 'should_display': this.block.product_counter, 'value': this.block.products, 'name': 'products' }) - // this.counters.push({ 'should_display': this.block.community_counter, 'value': this.block.communities, 'name': 'communities' }) - // this.counters.push({ 'should_display': this.block.category_counter, 'value': this.block.categories, 'name': 'categories' }) - // this.counters.push({ 'should_display': this.block.tag_counter, 'value': this.block.tags, 'name': 'tags' }) - // this.counters.push({ 'should_display': this.block.comment_counter, 'value': this.block.comments, 'name': 'comments' }) - // this.counters.push({ 'should_display': this.block.hit_counter, 'value': this.block.hits, 'name': 'hits' }) }); helper = new ComponentTestHelper(cls, done); }); - it("get user counter information in array", () => { - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 10, 'name': 'users' }); + it("shows statistics marked with display equals 'true'", () => { + expect(helper.debugElement.queryAll("li.statistic").length).toEqual(2); + expect(helper.debugElement.query("span.users").text()).toEqual("10"); + expect(helper.debugElement.query("span.communities").text()).toEqual("20"); }); - it("get user enterprise information in array", () => { - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 20, 'name': 'enterprises' }); + it("does not shows statistics marked with display equals 'false'", () => { + expect(helper.debugElement.queryAll("span.hits").length).toEqual(0); }); - - it("get product counter information in array", () => { - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 30, 'name': 'products' }); - }); - - it("get community counter information in array", () => { - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 40, 'name': 'communities' }); - }); - - it("get category counter information in array", () => { - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 50, 'name': 'categories' }); - }); - - it("get tag counter information in array", () => { - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 60, 'name': 'tags' }); - }); - - it("get comment counter information in array", () => { - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 70, 'name': 'comments' }); - }); - - it("get hit counter information in array", () => { - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 80, 'name': 'hits' }); - }); - - it("should render the user count information", () => { - expect(helper.find('.list-group-item.users').length).toEqual(1, "The statistics-block should have a list item with users class"); - }); - - it("should render the enterprise count information", () => { - expect(helper.find('.list-group-item.enterprises').length).toEqual(1, "The statistics-block should have a list item with enterprises class"); - }); - - it("should render the product count information", () => { - expect(helper.find('.list-group-item.products').length).toEqual(1, "The statistics-block should have a list item with products class"); - }); - - it("should render the community count information", () => { - expect(helper.find('.list-group-item.communities').length).toEqual(1, "The statistics-block should have a list item with communities class"); - }); - - it("should render the category count information", () => { - expect(helper.find('.list-group-item.categories').length).toEqual(1, "The statistics-block should have a list item with categories class"); - }); - - it("should render the tag count information", () => { - expect(helper.find('.list-group-item.tags').length).toEqual(1, "The statistics-block should have a list item with tags class"); - }); - - it("should render the comment count information", () => { - expect(helper.find('.list-group-item.comments').length).toEqual(1, "The statistics-block should have a list item with comments class"); - }); - - it("should render the hit count information", () => { - expect(helper.find('.list-group-item.hits').length).toEqual(1, "The statistics-block should have a list item with hits class"); - }); - - // it("should not render user count information if has no configuration on block", () => { - // helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); - // expect(helper.component.counters).toContain({ 'should_display': 0, 'value': 0, 'name': 'users' }); - // expect(helper.find('.list-group-item.users').length).toEqual(0, "The statistics-block should not have a list item with users class"); - // }); - }); }); diff --git a/src/app/layout/blocks/statistics/statistics-block.component.ts b/src/app/layout/blocks/statistics/statistics-block.component.ts index 71f8b39..a724baa 100644 --- a/src/app/layout/blocks/statistics/statistics-block.component.ts +++ b/src/app/layout/blocks/statistics/statistics-block.component.ts @@ -6,21 +6,6 @@ import {Input, Inject, Component} from "ng-forward"; }) export class StatisticsBlockComponent { - @Input() block: noosfero.StatisticsBlock; @Input() owner: any; - - counters: any = []; - - ngOnInit() { - this.counters.push({ 'should_display': this.block.user_counter, 'value': this.block.users, 'name': 'users' }); - this.counters.push({ 'should_display': this.block.enterprise_counter, 'value': this.block.enterprises, 'name': 'enterprises' }); - this.counters.push({ 'should_display': this.block.product_counter, 'value': this.block.products, 'name': 'products' }); - this.counters.push({ 'should_display': this.block.community_counter, 'value': this.block.communities, 'name': 'communities' }); - this.counters.push({ 'should_display': this.block.category_counter, 'value': this.block.categories, 'name': 'categories' }); - this.counters.push({ 'should_display': this.block.tag_counter, 'value': this.block.tags, 'name': 'tags' }); - this.counters.push({ 'should_display': this.block.comment_counter, 'value': this.block.comments, 'name': 'comments' }); - this.counters.push({ 'should_display': this.block.hit_counter, 'value': this.block.hits, 'name': 'hits' }); - - } } diff --git a/src/app/layout/blocks/statistics/statistics-block.html b/src/app/layout/blocks/statistics/statistics-block.html index 6ffb45c..aa27ad5 100644 --- a/src/app/layout/blocks/statistics/statistics-block.html +++ b/src/app/layout/blocks/statistics/statistics-block.html @@ -1,7 +1,7 @@
    -
  • - {{counter.value}} +
  • + {{counter.quantity}} {{"statistics." + counter.name | translate}}
  • diff --git a/src/lib/ng-noosfero-api/interfaces/statistics_block.ts b/src/lib/ng-noosfero-api/interfaces/statistics_block.ts index 94a97e0..4fba50f 100644 --- a/src/lib/ng-noosfero-api/interfaces/statistics_block.ts +++ b/src/lib/ng-noosfero-api/interfaces/statistics_block.ts @@ -1,20 +1,10 @@ namespace noosfero { + interface StatisticInfo { + name: string; + quantity: number; + display: boolean; + } export interface StatisticsBlock extends Block { - user_counter: boolean; - users: number; - enterprise_counter: boolean; - enterprises: number; - product_counter: boolean; - products: number; - community_counter: boolean; - communities: number; - category_counter: boolean; - categories: number; - tag_counter: boolean; - tags: number; - comment_counter: boolean; - comments: number; - hit_counter: boolean; - hits: number; + statistics: StatisticInfo[]; } } -- libgit2 0.21.2