Skip to content

Commit f686ded

Browse files
committed
#399 Add multiline chart
1 parent ab4ddb1 commit f686ded

File tree

8 files changed

+52
-60
lines changed

8 files changed

+52
-60
lines changed

ui/app/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@
177177
<script src="scripts/directives/dashboard/bar.js"></script>
178178
<script src="scripts/directives/dashboard/counter.js"></script>
179179
<script src="scripts/directives/dashboard/donut.js"></script>
180+
<script src="scripts/directives/dashboard/filter-editor.js"></script>
180181
<script src="scripts/directives/dashboard/item.js"></script>
181182
<script src="scripts/directives/dashboard/line.js"></script>
183+
<script src="scripts/directives/dashboard/multiline.js"></script>
182184
<script src="scripts/directives/dateTimePicker.js"></script>
183185
<script src="scripts/directives/dt-picker.js"></script>
184186
<script src="scripts/directives/entityLink.js"></script>

ui/app/scripts/controllers/dashboard/DashboardViewCtrl.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@
4242

4343
this.options = {
4444
dashboardAllowedTypes: ['container'],
45-
containerAllowedTypes: ['bar', 'line', 'donut', 'counter'],
45+
containerAllowedTypes: ['bar', 'line', 'donut', 'counter', 'multiline'],
4646
maxColumns: 3,
4747
cls: DashboardSrv.typeClasses,
4848
labels: {
4949
container: 'Row',
5050
bar: 'Bar',
5151
donut: 'Donut',
5252
line: 'Line',
53-
counter: 'Counter'
53+
counter: 'Counter',
54+
multiline: 'Multi Lines'
5455
},
5556
editLayout: !_.find(this.definition.items, function(row) {
5657
return row.items.length > 0;

ui/app/scripts/directives/dashboard/item.js

+6-52
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
});
4343
}
4444

45-
scope.fieldsForAggregation = function(fields, agg) {
45+
scope.fieldsForAggregation = function(fields, agg) {
4646
if(agg === 'count') {
4747
return [];
4848
} else if(agg === 'sum' || agg === 'avg') {
@@ -77,17 +77,18 @@
7777
modalInstance.result.then(function(definition) {
7878
var entity = scope.component.options.entity;
7979

80-
if(!entity) {
80+
//if(!entity) {
81+
if(!DashboardSrv.hasMinimalConfiguration(scope.component)) {
8182
return;
8283
}
8384

8485
// Set the computed query
85-
definition.query = DashboardSrv.buildFiltersQuery(scope.metadata[entity].attributes, scope.component.options.filters);
86+
definition.query = DashboardSrv.buildFiltersQuery(entity ? scope.metadata[entity].attributes : null, scope.component.options.filters);
8687

8788
// Set the computed querie of series if available
8889
_.each(definition.series, function(serie) {
8990
if(serie.filters) {
90-
serie.query = DashboardSrv.buildFiltersQuery(scope.metadata[entity].attributes, serie.filters);
91+
serie.query = DashboardSrv.buildFiltersQuery(scope.metadata[entity || serie.entity].attributes, serie.filters);
9192
}
9293
})
9394

@@ -99,52 +100,6 @@
99100
});
100101
};
101102

102-
scope.editorFor = function(filter) {
103-
if (filter.type === null) {
104-
return;
105-
}
106-
var field = scope.metadata[scope.component.options.entity].attributes[filter.field];
107-
var type = field.type;
108-
109-
if ((type === 'string' || type === 'number') && field.values.length > 0) {
110-
return 'enumeration';
111-
}
112-
113-
return filter.type;
114-
};
115-
116-
scope.promiseFor = function(filter, query) {
117-
var field = scope.metadata[scope.component.options.entity].attributes[filter.field];
118-
119-
var promise = null;
120-
121-
if(field.type === 'user') {
122-
promise = UserSrv.autoComplete(query);
123-
} else if (field.values.length > 0) {
124-
promise = $q.resolve(
125-
_.map(field.values, function(item, index) {
126-
return {
127-
text: item,
128-
label: field.labels[index] || item
129-
};
130-
})
131-
);
132-
} else {
133-
promise = $q.resolve([]);
134-
}
135-
136-
return promise.then(function(response) {
137-
var list = [];
138-
139-
list = _.filter(response, function(item) {
140-
var regex = new RegExp(query, 'gi');
141-
return regex.test(item.label);
142-
});
143-
144-
return $q.resolve(list);
145-
});
146-
};
147-
148103
scope.addFilter = function() {
149104
scope.component.options.filters = scope.component.options.filters || [];
150105

@@ -158,8 +113,7 @@
158113
scope.component.options.filters.splice(index, 1);
159114
};
160115

161-
scope.setFilterField = function(filter) {
162-
var entity = scope.component.options.entity;
116+
scope.setFilterField = function(filter, entity) {
163117
var field = scope.metadata[entity].attributes[filter.field];
164118

165119
filter.type = field.type;

ui/app/scripts/services/DashboardSrv.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
bar: 'fa-bar-chart',
7474
donut: 'fa-pie-chart',
7575
line: 'fa-line-chart',
76+
multiline: 'fa-area-chart',
7677
counter: 'fa-calculator'
7778
};
7879

@@ -105,6 +106,13 @@
105106
field: null
106107
}
107108
},
109+
{
110+
type: 'multiline',
111+
options: {
112+
title: null,
113+
entity: null
114+
}
115+
},
108116
{
109117
type: 'donut',
110118
options: {
@@ -201,14 +209,27 @@
201209
return defer.promise;
202210
};
203211

212+
this.hasMinimalConfiguration = function(component) {
213+
switch (component.type) {
214+
case 'multiline':
215+
return component.options.series.length === _.without(_.pluck(component.options.series, 'entity'), undefined).length;
216+
default:
217+
return !!component.options.entity;
218+
}
219+
};
220+
204221
this.buildFiltersQuery = function(fields, filters) {
205222
return QueryBuilderSrv.buildFiltersQuery(fields, filters);
206223
};
207224

208225
this.buildChartQuery = function(filter, query) {
209226
var criteria = _.without([filter, query], null, undefined, '', '*');
210227

211-
return criteria.length === 1 ? criteria[0] : { _and: criteria };
228+
if(criteria.length === 0) {
229+
return {};
230+
} else {
231+
return criteria.length === 1 ? criteria[0] : { _and: criteria };
232+
}
212233
}
213234

214235
this.buildPeriodQuery = function(period, field, start, end) {

ui/app/views/directives/dashboard/filters.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
</span>
1212
<select class="form-control" ng-model="filter.field"
1313
ng-options="item.name as item.name for (key, item) in metadata[component.options.entity].attributes"
14-
ng-change="setFilterField(filter)"></select>
14+
ng-change="setFilterField(filter, component.options.entity)"></select>
1515
</div>
1616
</div>
17-
<div class="col-sm-8" ng-include="'views/directives/dashboard/filter-editor.html'"></div>
17+
<!-- <div class="col-sm-8" ng-include="'views/directives/dashboard/filter-editor.html'"></div> -->
18+
<div class="col-sm-8">
19+
<filter-editor metadata="metadata" filter="filter" entity="component.options.entity"></filter-editor>
20+
</div>
1821
</div>
1922
<div ng-if="component.options.filters && component.options.filters.length > 0" class="mv-xs">
2023
<a href ng-click="addFilter()">

ui/app/views/directives/dashboard/item.html

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ <h3 class="box-title">
4747
resize-on="{{resizeOn}}"
4848
mode="mode"></dashboard-line>
4949

50+
<dashboard-multiline ng-switch-when="multiline"
51+
entity="metadata[component.options.entity]"
52+
options="component.options"
53+
filter="filter"
54+
autoload="autoload"
55+
refresh-on="{{refreshOn}}"
56+
resize-on="{{resizeOn}}"
57+
mode="mode"></dashboard-multiline>
58+
5059
<dashboard-counter ng-switch-when="counter"
5160
entity="metadata[component.options.entity]"
5261
options="component.options"

ui/app/views/directives/dashboard/serie.filters.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
</span>
1212
<select class="form-control" ng-model="filter.field"
1313
ng-options="item.name as item.name for (key, item) in metadata[component.options.entity].attributes"
14-
ng-change="setFilterField(filter)"></select>
14+
ng-change="setFilterField(filter, component.options.entity)"></select>
1515
</div>
1616
</div>
17-
<div class="col-sm-8" ng-include="'views/directives/dashboard/filter-editor.html'"></div>
17+
<!-- <div class="col-sm-8" ng-include="'views/directives/dashboard/filter-editor.html'"></div> -->
18+
<div class="col-sm-8">
19+
<filter-editor metadata="metadata" filter="filter" entity="component.options.entity"></filter-editor>
20+
</div>
1821
</div>
1922
<div class="mt-xxs">
2023
<a href ng-click="addSerieFilter(serie)">

ui/app/views/partials/dashboard/view.html

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<div class="box">
32
<div class="box-header with-border">
43
<h3 class="box-title">

0 commit comments

Comments
 (0)