Project

General

Profile

1
import {SafeResourceUrl} from "@angular/platform-browser";
2

    
3
export const ChartHelper = {
4
  prefix: "((__",
5
  suffix: "__))"
6
};
7

    
8
export type StakeholderType = 'funder' | 'ri' | 'project' | 'organization';
9
export type IndicatorType = 'number' | 'chart';
10
export type IndicatorWidth = 'small' | 'medium' | 'large';
11
export type IndicatorPathType = 'table' | 'bar' | 'column' | 'pie' | 'line' | 'other';
12
export type SourceType = 'statistics' | 'search' | 'metrics' | 'stats-tool' | 'old' | 'image';
13

    
14
export class Stakeholder {
15
  _id: string;
16
  type: StakeholderType;
17
  name: string;
18
  index_id;
19
  index_name: string;
20
  index_shortName: string;
21
  alias: string;
22
  defaultId: string;
23
  isActive: boolean;
24
  isPublic: boolean;
25
  creationDate: Date = null;
26
  updateDate: Date;
27
  managers: string[];
28
  logoUrl:string;
29
  topics: Topic[];
30

    
31
  constructor(id: string, type: StakeholderType, index_id, index_name: string, index_shortName: string, alias: string, isActive: boolean, isPublic: boolean, logoUrl:string, defaultId: string = null) {
32
    this.initializeFunder(id, type, index_id, index_name, index_shortName, defaultId, alias, isActive, isPublic, logoUrl);
33
    this.topics = [];
34
    this.managers = [];
35
  }
36

    
37
  initializeFunder(id: string, type: StakeholderType, index_id, index_name: string, index_shortName: string, defaultId: string, alias: string, isActive: boolean, isPublic: boolean, logoUrl:string) {
38
    this._id = id;
39
    this.type = type;
40
    this.index_id = index_id;
41
    this.index_name = index_name;
42
    this.index_shortName = index_shortName;
43
    this.defaultId = defaultId;
44
    this.alias = alias;
45
    this.isActive = isActive;
46
    this.isPublic = isPublic;
47
    this.logoUrl = logoUrl;
48
  }
49
}
50

    
51
export class Topic {
52
  _id: string;
53
  name: string;
54
  alias: string;
55
  description: string;
56
  isActive: boolean;
57
  isPublic: boolean;
58
  defaultId: string;
59
  categories: Category[];
60

    
61
  constructor(name: string, description: string, alias: string, isActive: boolean, isPublic: boolean, defaultId: string = null) {
62
    this._id = null;
63
    this.name = name;
64
    this.description = description;
65
    this.alias = alias;
66
    this.isActive = isActive;
67
    this.isPublic = isPublic;
68
    this.defaultId = defaultId;
69
    this.categories = [];
70
  }
71
}
72

    
73
export class Category {
74
  _id: string;
75
  name: string;
76
  alias: string;
77
  description: string;
78
  isActive: boolean;
79
  isPublic: boolean;
80
  defaultId: string;
81
  subCategories: SubCategory[];
82

    
83
  constructor(name: string, description: string, alias: string, isActive: boolean, isPublic: boolean, defaultId: string = null) {
84
    this._id = null;
85
    this.name = name;
86
    this.description = description;
87
    this.alias = alias;
88
    this.isActive = isActive;
89
    this.isPublic = isPublic;
90
    this.defaultId = defaultId;
91
    this.subCategories = [];
92
  }
93
}
94

    
95
export class SubCategory {
96
  _id: string;
97
  name: string;
98
  alias: string;
99
  description: string;
100
  isActive: boolean;
101
  isPublic: boolean;
102
  defaultId: string;
103
  charts: Section[];
104
  numbers: Section[];
105
  recommendedFor:string[];
106

    
107
  constructor(name: string, description: string, alias: string, isActive: boolean, isPublic: boolean, defaultId: string = null) {
108
    this._id = null;
109
    this.name = name;
110
    this.description = description;
111
    this.alias = alias;
112
    this.isActive = isActive;
113
    this.isPublic = isPublic;
114
    this.defaultId = defaultId;
115
    this.charts = [];
116
    this.numbers = [];
117
    this.recommendedFor= [];
118
  }
119

    
120
}
121

    
122
export class Section {
123
  _id: string;
124
  title: string;
125
  defaultId: string;
126
  stakeholderAlias: string;
127
  type: IndicatorType;
128
  indicators: Indicator[];
129
  
130
  constructor(type: IndicatorType, title: string = null, defaultId: string = null, stakeholderAlias: string = null) {
131
    this._id = null;
132
    this.title = title;
133
    this.type = type;
134
    this.defaultId = defaultId;
135
    this.stakeholderAlias = stakeholderAlias;
136
    this.indicators = [];
137
  }
138
}
139

    
140
export class Indicator {
141
  _id: string;
142
  name: string;
143
  description: string;
144
  type: IndicatorType;
145
  width: IndicatorWidth;
146
  tags: string[];
147
  isActive: boolean;
148
  isPublic: boolean;
149
  defaultId: string;
150
  indicatorPaths: IndicatorPath[];
151
  recommendedFor:string[];
152

    
153
  constructor(name: string, description: string, type: IndicatorType, width: IndicatorWidth, isActive: boolean, isPublic: boolean, indicatorPaths: IndicatorPath[], defaultId: string = null) {
154
    this._id = null;
155
    this.name = name;
156
    this.description = description;
157
    this.type = type;
158
    this.width = width;
159
    this.isActive = isActive;
160
    this.isPublic = isPublic;
161
    this.defaultId = defaultId;
162
    this.indicatorPaths = indicatorPaths;
163
    this.recommendedFor = [];
164
  }
165

    
166
}
167

    
168
export class IndicatorPath {
169
  type: IndicatorPathType;
170
  source: SourceType;
171
  url: string;
172
  safeResourceUrl: SafeResourceUrl; // initialize on front end
173
  jsonPath: string[];
174
  chartObject: string;
175
  parameters: any;
176
  filters: any;
177

    
178
  constructor(type: IndicatorPathType, source: SourceType, url: string, chartObject: string, jsonPath: string[]) {
179
    this.type = type;
180
    this.url = url;
181
    this.source = source;
182
    this.jsonPath = jsonPath;
183
    this.chartObject = chartObject;
184
    this.parameters = {};
185
    this.filters = {};
186
  }
187

    
188
  static createParameters(funderName: string = null, title: string = null, chartType: string = null): any {
189
    return {
190
      index_name: funderName,
191
      title: title,
192
      type: chartType
193
    };
194
  }
195

    
196
  static createResultFilters(dbType: string = null): any {
197
    return {
198
      fundingL0: '{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}',
199
      start_year: '{"groupFilters":[{"field":"' + dbType + '.year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}',
200
      end_year: '{"groupFilters":[{"field":"' + dbType + '.year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}'
201
    };
202
  }
203
}
    (1-1/1)