Commit 299d40d1a4492658da5572aac95ff1367776bc6a

Authored by ABNER SILVA DE OLIVEIRA
1 parent c1b134be

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
... ... @@ -17,100 +17,37 @@ describe("Components", () => {
17 17 providers: helpers.provideFilters("translateFilter"),
18 18 properties: {
19 19 block: {
20   - user_counter: 1, users: 10, enterprise_counter: 1, enterprises: 20,
21   - product_counter: 1, products: 30, community_counter: 1, communities: 40,
22   - category_counter: 1, categories: 50, tag_counter: 1, tags: 60,
23   - comment_counter: 1, comments: 70, hit_counter: 1, hits: 80
  20 + statistics: [
  21 + {
  22 + name: "users",
  23 + display: true,
  24 + quantity: 10
  25 + },
  26 + {
  27 + name: "communities",
  28 + display: true,
  29 + quantity: 20
  30 + },
  31 + {
  32 + name: "hits",
  33 + display: false,
  34 + quantity: null
  35 + }
  36 + ]
24 37 }
25 38 }
26   - // this.counters.push({ 'should_display': this.block.enterprise_counter, 'value': this.block.enterprises, 'name': 'enterprises' })
27   - // this.counters.push({ 'should_display': this.block.product_counter, 'value': this.block.products, 'name': 'products' })
28   - // this.counters.push({ 'should_display': this.block.community_counter, 'value': this.block.communities, 'name': 'communities' })
29   - // this.counters.push({ 'should_display': this.block.category_counter, 'value': this.block.categories, 'name': 'categories' })
30   - // this.counters.push({ 'should_display': this.block.tag_counter, 'value': this.block.tags, 'name': 'tags' })
31   - // this.counters.push({ 'should_display': this.block.comment_counter, 'value': this.block.comments, 'name': 'comments' })
32   - // this.counters.push({ 'should_display': this.block.hit_counter, 'value': this.block.hits, 'name': 'hits' })
33 39 });
34 40 helper = new ComponentTestHelper<StatisticsBlockComponent>(cls, done);
35 41 });
36 42  
37   - it("get user counter information in array", () => {
38   - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; });
39   - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 10, 'name': 'users' });
  43 + it("shows statistics marked with display equals 'true'", () => {
  44 + expect(helper.debugElement.queryAll("li.statistic").length).toEqual(2);
  45 + expect(helper.debugElement.query("span.users").text()).toEqual("10");
  46 + expect(helper.debugElement.query("span.communities").text()).toEqual("20");
40 47 });
41 48  
42   - it("get user enterprise information in array", () => {
43   - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; });
44   - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 20, 'name': 'enterprises' });
  49 + it("does not shows statistics marked with display equals 'false'", () => {
  50 + expect(helper.debugElement.queryAll("span.hits").length).toEqual(0);
45 51 });
46   -
47   - it("get product counter information in array", () => {
48   - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; });
49   - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 30, 'name': 'products' });
50   - });
51   -
52   - it("get community counter information in array", () => {
53   - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; });
54   - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 40, 'name': 'communities' });
55   - });
56   -
57   - it("get category counter information in array", () => {
58   - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; });
59   - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 50, 'name': 'categories' });
60   - });
61   -
62   - it("get tag counter information in array", () => {
63   - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; });
64   - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 60, 'name': 'tags' });
65   - });
66   -
67   - it("get comment counter information in array", () => {
68   - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; });
69   - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 70, 'name': 'comments' });
70   - });
71   -
72   - it("get hit counter information in array", () => {
73   - helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; });
74   - expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 80, 'name': 'hits' });
75   - });
76   -
77   - it("should render the user count information", () => {
78   - expect(helper.find('.list-group-item.users').length).toEqual(1, "The statistics-block should have a list item with users class");
79   - });
80   -
81   - it("should render the enterprise count information", () => {
82   - expect(helper.find('.list-group-item.enterprises').length).toEqual(1, "The statistics-block should have a list item with enterprises class");
83   - });
84   -
85   - it("should render the product count information", () => {
86   - expect(helper.find('.list-group-item.products').length).toEqual(1, "The statistics-block should have a list item with products class");
87   - });
88   -
89   - it("should render the community count information", () => {
90   - expect(helper.find('.list-group-item.communities').length).toEqual(1, "The statistics-block should have a list item with communities class");
91   - });
92   -
93   - it("should render the category count information", () => {
94   - expect(helper.find('.list-group-item.categories').length).toEqual(1, "The statistics-block should have a list item with categories class");
95   - });
96   -
97   - it("should render the tag count information", () => {
98   - expect(helper.find('.list-group-item.tags').length).toEqual(1, "The statistics-block should have a list item with tags class");
99   - });
100   -
101   - it("should render the comment count information", () => {
102   - expect(helper.find('.list-group-item.comments').length).toEqual(1, "The statistics-block should have a list item with comments class");
103   - });
104   -
105   - it("should render the hit count information", () => {
106   - expect(helper.find('.list-group-item.hits').length).toEqual(1, "The statistics-block should have a list item with hits class");
107   - });
108   -
109   - // it("should not render user count information if has no configuration on block", () => {
110   - // helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; });
111   - // expect(helper.component.counters).toContain({ 'should_display': 0, 'value': 0, 'name': 'users' });
112   - // expect(helper.find('.list-group-item.users').length).toEqual(0, "The statistics-block should not have a list item with users class");
113   - // });
114   -
115 52 });
116 53 });
... ...
src/app/layout/blocks/statistics/statistics-block.component.ts
... ... @@ -6,21 +6,6 @@ import {Input, Inject, Component} from &quot;ng-forward&quot;;
6 6 })
7 7  
8 8 export class StatisticsBlockComponent {
9   -
10 9 @Input() block: noosfero.StatisticsBlock;
11 10 @Input() owner: any;
12   -
13   - counters: any = [];
14   -
15   - ngOnInit() {
16   - this.counters.push({ 'should_display': this.block.user_counter, 'value': this.block.users, 'name': 'users' });
17   - this.counters.push({ 'should_display': this.block.enterprise_counter, 'value': this.block.enterprises, 'name': 'enterprises' });
18   - this.counters.push({ 'should_display': this.block.product_counter, 'value': this.block.products, 'name': 'products' });
19   - this.counters.push({ 'should_display': this.block.community_counter, 'value': this.block.communities, 'name': 'communities' });
20   - this.counters.push({ 'should_display': this.block.category_counter, 'value': this.block.categories, 'name': 'categories' });
21   - this.counters.push({ 'should_display': this.block.tag_counter, 'value': this.block.tags, 'name': 'tags' });
22   - this.counters.push({ 'should_display': this.block.comment_counter, 'value': this.block.comments, 'name': 'comments' });
23   - this.counters.push({ 'should_display': this.block.hit_counter, 'value': this.block.hits, 'name': 'hits' });
24   -
25   - }
26 11 }
... ...
src/app/layout/blocks/statistics/statistics-block.html
1 1 <div class="statistics-block">
2 2 <ul class="list-group">
3   - <li ng-repeat="counter in ctrl.counters" class="list-group-item {{counter.name}}" ng-show="counter.should_display" >
4   - <span class="badge {{counter.name}}">{{counter.value}}</span>
  3 + <li ng-repeat="counter in ctrl.block.statistics" class="list-group-item statistic {{counter.name}}" ng-if="counter.display" >
  4 + <span class="badge {{counter.name}}">{{counter.quantity}}</span>
5 5 {{"statistics." + counter.name | translate}}
6 6 </li>
7 7  
... ...
src/lib/ng-noosfero-api/interfaces/statistics_block.ts
1 1 namespace noosfero {
  2 + interface StatisticInfo {
  3 + name: string;
  4 + quantity: number;
  5 + display: boolean;
  6 + }
2 7 export interface StatisticsBlock extends Block {
3   - user_counter: boolean;
4   - users: number;
5   - enterprise_counter: boolean;
6   - enterprises: number;
7   - product_counter: boolean;
8   - products: number;
9   - community_counter: boolean;
10   - communities: number;
11   - category_counter: boolean;
12   - categories: number;
13   - tag_counter: boolean;
14   - tags: number;
15   - comment_counter: boolean;
16   - comments: number;
17   - hit_counter: boolean;
18   - hits: number;
  8 + statistics: StatisticInfo[];
19 9 }
20 10 }
... ...