Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
fix: top failed==top apis when a tenant is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
aelamrani committed Mar 14, 2019
1 parent 951d95e commit 0b586b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 119 deletions.
26 changes: 16 additions & 10 deletions src/components/widget/widget.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ const WidgetComponent: ng.IComponentOptions = {
$scope.$on('onTimeframeChange', function (event, timeframe) {
let query;

if (that.$state.params['q'] && that.widget.chart.request.query) {
query = that.$state.params['q'] + ' AND ' + that.widget.chart.request.query;
} else if (that.$state.params['q']) {
query = that.$state.params['q'];
} else if (that.widget.chart.request.query) {
if (that.widget.chart.request.query) {
query = that.widget.chart.request.query;
}

Expand All @@ -47,17 +43,16 @@ const WidgetComponent: ng.IComponentOptions = {
interval: timeframe.interval,
from: timeframe.from,
to: timeframe.to,
query: query
query: query,
additionalQuery: that.widget.chart.request.additionalQuery
});

that.reload();
});

$scope.$on('onQueryFilterChange', function (event, query) {
// Associate the new query filter to the chart request
_.assignIn(that.widget.chart.request, {
query: query.query
});
that.widget.chart.request.additionalQuery = query.query;

// Reload only if not the same widget which applied the latest filter
if (that.widget.$uid !== query.source) {
Expand All @@ -72,7 +67,18 @@ const WidgetComponent: ng.IComponentOptions = {
let chart = this.widget.chart;

// Prepare arguments
let args = [this.widget.root, chart.request];
let chartRequest = _.cloneDeep(chart.request);
if (chartRequest.additionalQuery) {
if (chartRequest.query) {
if (!_.includes(chartRequest.query, this.widget.chart.request.additionalQuery)) {
chartRequest.query += ' AND ' + this.widget.chart.request.additionalQuery;
}
} else {
chartRequest.query = this.widget.chart.request.additionalQuery;
}
delete chartRequest.additionalQuery;
}
let args = [this.widget.root, chartRequest];

if (! this.widget.root) {
args.splice(0,1);
Expand Down
114 changes: 5 additions & 109 deletions src/management/platform/dashboard/dashboard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class DashboardController {
subhead: 'Ordered by API calls',
chart: {
type: 'table',
selectable: true,
link: 'api',
columns: ['API', 'Hits'],
paging: 5,
Expand All @@ -68,6 +69,7 @@ class DashboardController {
subhead: 'Ordered by application calls',
chart: {
type: 'table',
selectable: true,
link: 'application',
columns: ['Application', 'Hits'],
paging: 5,
Expand Down Expand Up @@ -192,14 +194,12 @@ class DashboardController {
}
}];

var _that = this;

_.forEach(this.$scope.platformDashboard, function (widget) {
_.forEach(this.$scope.platformDashboard, (widget) => {
_.merge(widget, {
chart: {
service: {
caller: _that.AnalyticsService,
function: _that.AnalyticsService.analytics
caller: this.AnalyticsService,
function: this.AnalyticsService.analytics
}
}
});
Expand All @@ -214,16 +214,6 @@ class DashboardController {

this.initPagination();
this.searchEvents = this.searchEvents.bind(this);

// Refresh widget on each timeframe change
/*
this.$scope.$on('timeframeChange', function (event, timeframe) {
_that.lastFrom = timeframe.from;
_that.lastTo = timeframe.to;
_that.searchEvents();
});
*/
}

onTimeframeChange(timeframe) {
Expand All @@ -233,24 +223,6 @@ class DashboardController {
this.searchEvents();
}

undoAPI() {
this.updateCharts();
this.searchEvents();
}

selectAPI() {
this.updateCharts();
this.searchEvents();
}

undoApplication() {
this.updateCharts();
}

selectApplication() {
this.updateCharts();
}

selectEvent(eventType) {
let idx = this.selectedEventTypes.indexOf(eventType);
if (idx > -1) {
Expand Down Expand Up @@ -280,28 +252,6 @@ class DashboardController {
});
}

searchAPI(query) {
if (query) {
return this.ApiService.list().then(function(response) {
return _.filter(response.data,
function(api: any) {
return api.name.toUpperCase().indexOf(query.toUpperCase()) > -1;
});
});
}
}

searchApplication(query) {
if (query) {
return this.ApplicationService.list().then(function(response) {
return _.filter(response.data,
function(application: any) {
return application.name.toUpperCase().indexOf(query.toUpperCase()) > -1;
});
});
}
}

initPagination() {
this.query = {
limit: 10,
Expand All @@ -312,60 +262,6 @@ class DashboardController {
getEventLabel(label) {
return this.eventLabels[label];
}

updateCharts() {
var _this = this;
var i;

var queryFilter = '';
if (this.selectedAPIs.length) {
queryFilter = ' AND(';
for (i = 0; i < this.selectedAPIs.length; i++) {
queryFilter += 'api:' + this.selectedAPIs[i].id + (this.selectedAPIs.length - 1 === i ? ')' : ' OR ');
}
}

if (this.selectedApplications.length) {
queryFilter = ' AND(';
for (i = 0; i < this.selectedApplications.length; i++) {
queryFilter += 'application:' + this.selectedApplications[i].id + (this.selectedApplications.length - 1 === i ? ')' : ' OR ');
}
}

_.forEach(this.analyticsData.tops, function (top) {
_this.$scope.fetchData = true;
var request = top.request.call(_this.AnalyticsService,
_this.analyticsData.range.from,
_this.analyticsData.range.to,
_this.analyticsData.range.interval,
top.key,
top.query + queryFilter,
top.field,
top.orderField,
top.orderDirection,
top.orderType,
top.size);

request.then(response => {
if (response.data && response.data.values) {
if (Object.keys(response.data.values).length) {
top.results = _.map(response.data.values, function (value, key) {
return {
topKey: key,
topValue: value,
model: top.field,
metadata: (response.data) ? response.data.metadata[key] : undefined
};
});
_this.$scope.paging[top.key] = 1;
} else {
delete top.results;
}
}
_this.$scope.fetchData = false;
});
});
}
}

export default DashboardController;

0 comments on commit 0b586b9

Please sign in to comment.