Project

General

Profile

« Previous | Next » 

Revision 57639

[Monitor Dashboard]: 1. Create indicator Modal 2. Add new fields on stakeholder elements. 3. Add getFullUrl on indicatorUtils.

View differences:

indicator-utils.ts
1
import {ChartHelper, Indicator, IndicatorPath} from "./entities/stakeholder";
1
import {ChartHelper, IndicatorPath} from "./entities/stakeholder";
2 2

  
3 3
export class IndicatorUtils {
4 4

  
......
18 18

  
19 19
  isActiveIcon: string = 'brightness_1';
20 20

  
21
  public getFullUrl(indicatorPath: IndicatorPath):string{
21
  public getFullUrl(indicatorPath: IndicatorPath): string {
22 22
    let replacedUrl = indicatorPath.chartObject;
23
    if(indicatorPath.parameters) {
23
    if (indicatorPath.parameters) {
24 24
      Object.entries(indicatorPath.parameters).forEach((key, value) => {
25 25
        replacedUrl = replacedUrl.replace(ChartHelper.prefix + key + ChartHelper.suffix, value.toString());
26 26
      });
......
28 28
    return indicatorPath.url + encodeURIComponent(replacedUrl);
29 29
  }
30 30

  
31
  generateIndicatorByChartUrl(url:string): Indicator{
32
    let indicator = new Indicator("","","chart","small",true,true,[]);
33
    let indicatorPath = new IndicatorPath("","","","",[]);
34
    indicator.indicatorPaths.push(indicatorPath);
35
    if(url.indexOf("json=")!=-1){
36
      indicatorPath.url = url.split("json=")[0]+"json=";
37
      indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length-1];
31
  generateIndicatorByChartUrl(source: string, url: string, type: string = null): IndicatorPath {
32
    let indicatorPath = new IndicatorPath("", source, "", "", []);
33
    if (source === 'stats-tool') {
34
      indicatorPath.url = url.split("json=")[0] + "json=";
35
      indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1];
38 36
      indicatorPath.chartObject = decodeURIComponent(url.split("json=")[1]);
39
      indicatorPath.source = "stats-tool";
40 37
      let chart = JSON.parse(indicatorPath.chartObject);
41 38
      indicatorPath.type = this.extractType(chart, indicatorPath);
42
      this.extractTitle(chart,indicatorPath);
43
      this.extractXTitle(chart,indicatorPath);
44
      this.extractYTitle(chart,indicatorPath);
45
      this.extractFunder(chart,indicatorPath);
46
      this.extractStartYear(chart,indicatorPath);
47
      this.extractEndYear(chart,indicatorPath);
39
      this.extractTitle(chart, indicatorPath);
40
      this.extractXTitle(chart, indicatorPath);
41
      this.extractYTitle(chart, indicatorPath);
42
      this.extractFunder(chart, indicatorPath);
43
      this.extractStartYear(chart, indicatorPath);
44
      this.extractEndYear(chart, indicatorPath);
48 45
      indicatorPath.chartObject = JSON.stringify(chart);
49
    }else if(url.indexOf("data=")!=-1){
50
      indicatorPath.url = url.split("data=")[0]+"data=";
46
    } else if (source === 'old') {
47
      indicatorPath.url = url.split("data=")[0] + "data=";
51 48
      indicatorPath.chartObject = decodeURIComponent(url.split("data=")[1]);
52
      indicatorPath.source = "old";
49
    } else {
50
      indicatorPath.url = url;
51
      indicatorPath.type = type;
53 52
    }
54
    return indicator;
53
    return indicatorPath;
55 54
  }
56 55

  
57
  private extractType(obj,indicatorPath:IndicatorPath ):string{
58
    let defaultTypes = ["column","bar","pie"];
59
    let type= obj["chartDescription"]["queries"][0]["type"];
60
    if(defaultTypes.indexOf(type)==-1){
56
  private extractType(obj, indicatorPath: IndicatorPath): string {
57
    let defaultTypes = ["column", "bar", "pie"];
58
    let type = obj["chartDescription"]["queries"][0]["type"];
59
    if (defaultTypes.indexOf(type) == -1) {
61 60
      type = defaultTypes [0];
62
    }else{
63
      obj["chartDescription"]["queries"][0]["type"] = ChartHelper.prefix+"type"+ChartHelper.suffix;
64
      indicatorPath.parameters.set("type",type);
61
    } else {
62
      obj["chartDescription"]["queries"][0]["type"] = ChartHelper.prefix + "type" + ChartHelper.suffix;
63
      indicatorPath.parameters.set("type", type);
65 64
    }
66 65
    return type;
67 66
  }
68
  private extractFunder(obj,indicatorPath:IndicatorPath ){
67

  
68
  private extractFunder(obj, indicatorPath: IndicatorPath) {
69 69
    let funderName;
70
    for(let filter of obj["chartDescription"]["queries"][0]["query"]["filters"]){
71
      if(filter["groupFilters"][0]["field"].indexOf(".funder")!=-1){
72
        funderName= filter["groupFilters"][0]["values"][0];
73
        filter["groupFilters"][0]["values"][0] = ChartHelper.prefix+"funder_name"+ChartHelper.suffix;
74
        indicatorPath.parameters.set("funder_name",funderName);
70
    for (let filter of obj["chartDescription"]["queries"][0]["query"]["filters"]) {
71
      if (filter["groupFilters"][0]["field"].indexOf(".funder") != -1) {
72
        funderName = filter["groupFilters"][0]["values"][0];
73
        filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "funder_name" + ChartHelper.suffix;
74
        indicatorPath.parameters.set("funder_name", funderName);
75 75
      }
76 76
    }
77 77
  }
78
  private extractStartYear(obj,indicatorPath:IndicatorPath ){
78

  
79
  private extractStartYear(obj, indicatorPath: IndicatorPath) {
79 80
    let start_year;
80
    for(let filter of obj["chartDescription"]["queries"][0]["query"]["filters"]){
81
      for(let gfilter of filter["groupFilters"]) {
81
    for (let filter of obj["chartDescription"]["queries"][0]["query"]["filters"]) {
82
      for (let gfilter of filter["groupFilters"]) {
82 83
        if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf(">") != -1) {
83 84
          start_year = gfilter["values"][0];
84 85
          gfilter["values"][0] = ChartHelper.prefix + "start_year" + ChartHelper.suffix;
......
87 88
      }
88 89
    }
89 90
  }
90
  private extractEndYear(obj,indicatorPath:IndicatorPath ){
91

  
92
  private extractEndYear(obj, indicatorPath: IndicatorPath) {
91 93
    let end_year;
92
    for(let filter of obj["chartDescription"]["queries"][0]["query"]["filters"]){
93
      for(let gfilter of filter["groupFilters"]) {
94
    for (let filter of obj["chartDescription"]["queries"][0]["query"]["filters"]) {
95
      for (let gfilter of filter["groupFilters"]) {
94 96
        if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf("<") != -1) {
95 97
          end_year = gfilter["values"][0];
96 98
          gfilter["values"][0] = ChartHelper.prefix + "end_year" + ChartHelper.suffix;
......
99 101
      }
100 102
    }
101 103
  }
102
  private extractTitle(obj,indicatorPath:IndicatorPath ){
103
    let title= obj["chartDescription"]["title"]["text"];
104
    if(obj["chartDescription"]["title"]){
105
      obj["chartDescription"]["title"]["text"] = ChartHelper.prefix+"title"+ChartHelper.suffix;
106
      indicatorPath.parameters.set("title",title);
107 104

  
105
  private extractTitle(obj, indicatorPath: IndicatorPath) {
106
    let title = obj["chartDescription"]["title"]["text"];
107
    if (obj["chartDescription"]["title"]) {
108
      obj["chartDescription"]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
109
      indicatorPath.parameters.set("title", title);
110

  
108 111
    }
109 112
  }
110
  private extractXTitle(obj,indicatorPath:IndicatorPath ){
111
    let title= obj["chartDescription"]["xAxis"]["title"]["text"];
112
    if(obj["chartDescription"]["xAxis"]["title"]){
113
      obj["chartDescription"]["xAxis"]["title"]["text"] = ChartHelper.prefix+"xAxisTitle"+ChartHelper.suffix;
114
      indicatorPath.parameters.set("xAxisTitle",title);
113

  
114
  private extractXTitle(obj, indicatorPath: IndicatorPath) {
115
    let title = obj["chartDescription"]["xAxis"]["title"]["text"];
116
    if (obj["chartDescription"]["xAxis"]["title"]) {
117
      obj["chartDescription"]["xAxis"]["title"]["text"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
118
      indicatorPath.parameters.set("xAxisTitle", title);
115 119
    }
116 120
  }
117
  private extractYTitle(obj,indicatorPath:IndicatorPath ){
118
    let title= obj["chartDescription"]["yAxis"]["title"]["text"];
119
    if(obj["chartDescription"]["yAxis"]["title"]){
120
      obj["chartDescription"]["yAxis"]["title"]["text"] = ChartHelper.prefix+"yAxisTitle"+ChartHelper.suffix;
121
      indicatorPath.parameters.set("yAxisTitle",title);
121

  
122
  private extractYTitle(obj, indicatorPath: IndicatorPath) {
123
    let title = obj["chartDescription"]["yAxis"]["title"]["text"];
124
    if (obj["chartDescription"]["yAxis"]["title"]) {
125
      obj["chartDescription"]["yAxis"]["title"]["text"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
126
      indicatorPath.parameters.set("yAxisTitle", title);
122 127
    }
123 128
  }
124 129

  

Also available in: Unified diff