Skip to content

Commit

Permalink
#399 Add multiline chart
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Dec 14, 2017
1 parent ab4ddb1 commit f686ded
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 60 deletions.
2 changes: 2 additions & 0 deletions ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@
<script src="scripts/directives/dashboard/bar.js"></script>
<script src="scripts/directives/dashboard/counter.js"></script>
<script src="scripts/directives/dashboard/donut.js"></script>
<script src="scripts/directives/dashboard/filter-editor.js"></script>
<script src="scripts/directives/dashboard/item.js"></script>
<script src="scripts/directives/dashboard/line.js"></script>
<script src="scripts/directives/dashboard/multiline.js"></script>
<script src="scripts/directives/dateTimePicker.js"></script>
<script src="scripts/directives/dt-picker.js"></script>
<script src="scripts/directives/entityLink.js"></script>
Expand Down
5 changes: 3 additions & 2 deletions ui/app/scripts/controllers/dashboard/DashboardViewCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@

this.options = {
dashboardAllowedTypes: ['container'],
containerAllowedTypes: ['bar', 'line', 'donut', 'counter'],
containerAllowedTypes: ['bar', 'line', 'donut', 'counter', 'multiline'],
maxColumns: 3,
cls: DashboardSrv.typeClasses,
labels: {
container: 'Row',
bar: 'Bar',
donut: 'Donut',
line: 'Line',
counter: 'Counter'
counter: 'Counter',
multiline: 'Multi Lines'
},
editLayout: !_.find(this.definition.items, function(row) {
return row.items.length > 0;
Expand Down
58 changes: 6 additions & 52 deletions ui/app/scripts/directives/dashboard/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
});
}

scope.fieldsForAggregation = function(fields, agg) {
scope.fieldsForAggregation = function(fields, agg) {
if(agg === 'count') {
return [];
} else if(agg === 'sum' || agg === 'avg') {
Expand Down Expand Up @@ -77,17 +77,18 @@
modalInstance.result.then(function(definition) {
var entity = scope.component.options.entity;

if(!entity) {
//if(!entity) {
if(!DashboardSrv.hasMinimalConfiguration(scope.component)) {
return;
}

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

// Set the computed querie of series if available
_.each(definition.series, function(serie) {
if(serie.filters) {
serie.query = DashboardSrv.buildFiltersQuery(scope.metadata[entity].attributes, serie.filters);
serie.query = DashboardSrv.buildFiltersQuery(scope.metadata[entity || serie.entity].attributes, serie.filters);
}
})

Expand All @@ -99,52 +100,6 @@
});
};

scope.editorFor = function(filter) {
if (filter.type === null) {
return;
}
var field = scope.metadata[scope.component.options.entity].attributes[filter.field];
var type = field.type;

if ((type === 'string' || type === 'number') && field.values.length > 0) {
return 'enumeration';
}

return filter.type;
};

scope.promiseFor = function(filter, query) {
var field = scope.metadata[scope.component.options.entity].attributes[filter.field];

var promise = null;

if(field.type === 'user') {
promise = UserSrv.autoComplete(query);
} else if (field.values.length > 0) {
promise = $q.resolve(
_.map(field.values, function(item, index) {
return {
text: item,
label: field.labels[index] || item
};
})
);
} else {
promise = $q.resolve([]);
}

return promise.then(function(response) {
var list = [];

list = _.filter(response, function(item) {
var regex = new RegExp(query, 'gi');
return regex.test(item.label);
});

return $q.resolve(list);
});
};

scope.addFilter = function() {
scope.component.options.filters = scope.component.options.filters || [];

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

scope.setFilterField = function(filter) {
var entity = scope.component.options.entity;
scope.setFilterField = function(filter, entity) {
var field = scope.metadata[entity].attributes[filter.field];

filter.type = field.type;
Expand Down
23 changes: 22 additions & 1 deletion ui/app/scripts/services/DashboardSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
bar: 'fa-bar-chart',
donut: 'fa-pie-chart',
line: 'fa-line-chart',
multiline: 'fa-area-chart',
counter: 'fa-calculator'
};

Expand Down Expand Up @@ -105,6 +106,13 @@
field: null
}
},
{
type: 'multiline',
options: {
title: null,
entity: null
}
},
{
type: 'donut',
options: {
Expand Down Expand Up @@ -201,14 +209,27 @@
return defer.promise;
};

this.hasMinimalConfiguration = function(component) {
switch (component.type) {
case 'multiline':
return component.options.series.length === _.without(_.pluck(component.options.series, 'entity'), undefined).length;
default:
return !!component.options.entity;
}
};

this.buildFiltersQuery = function(fields, filters) {
return QueryBuilderSrv.buildFiltersQuery(fields, filters);
};

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

return criteria.length === 1 ? criteria[0] : { _and: criteria };
if(criteria.length === 0) {
return {};
} else {
return criteria.length === 1 ? criteria[0] : { _and: criteria };
}
}

this.buildPeriodQuery = function(period, field, start, end) {
Expand Down
7 changes: 5 additions & 2 deletions ui/app/views/directives/dashboard/filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
</span>
<select class="form-control" ng-model="filter.field"
ng-options="item.name as item.name for (key, item) in metadata[component.options.entity].attributes"
ng-change="setFilterField(filter)"></select>
ng-change="setFilterField(filter, component.options.entity)"></select>
</div>
</div>
<div class="col-sm-8" ng-include="'views/directives/dashboard/filter-editor.html'"></div>
<!-- <div class="col-sm-8" ng-include="'views/directives/dashboard/filter-editor.html'"></div> -->
<div class="col-sm-8">
<filter-editor metadata="metadata" filter="filter" entity="component.options.entity"></filter-editor>
</div>
</div>
<div ng-if="component.options.filters && component.options.filters.length > 0" class="mv-xs">
<a href ng-click="addFilter()">
Expand Down
9 changes: 9 additions & 0 deletions ui/app/views/directives/dashboard/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ <h3 class="box-title">
resize-on="{{resizeOn}}"
mode="mode"></dashboard-line>

<dashboard-multiline ng-switch-when="multiline"
entity="metadata[component.options.entity]"
options="component.options"
filter="filter"
autoload="autoload"
refresh-on="{{refreshOn}}"
resize-on="{{resizeOn}}"
mode="mode"></dashboard-multiline>

<dashboard-counter ng-switch-when="counter"
entity="metadata[component.options.entity]"
options="component.options"
Expand Down
7 changes: 5 additions & 2 deletions ui/app/views/directives/dashboard/serie.filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
</span>
<select class="form-control" ng-model="filter.field"
ng-options="item.name as item.name for (key, item) in metadata[component.options.entity].attributes"
ng-change="setFilterField(filter)"></select>
ng-change="setFilterField(filter, component.options.entity)"></select>
</div>
</div>
<div class="col-sm-8" ng-include="'views/directives/dashboard/filter-editor.html'"></div>
<!-- <div class="col-sm-8" ng-include="'views/directives/dashboard/filter-editor.html'"></div> -->
<div class="col-sm-8">
<filter-editor metadata="metadata" filter="filter" entity="component.options.entity"></filter-editor>
</div>
</div>
<div class="mt-xxs">
<a href ng-click="addSerieFilter(serie)">
Expand Down
1 change: 0 additions & 1 deletion ui/app/views/partials/dashboard/view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<div class="box">
<div class="box-header with-border">
<h3 class="box-title">
Expand Down

0 comments on commit f686ded

Please sign in to comment.