OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.5 KiB

  1. odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
  2. "use strict";
  3. var BasicRenderer = require('web.BasicRenderer');
  4. var core = require('web.core');
  5. var registry = require('kpi_dashboard.widget_registry');
  6. var BusService = require('bus.BusService');
  7. var qweb = core.qweb;
  8. var DashboardRenderer= BasicRenderer.extend({
  9. className: "o_dashboard_view",
  10. _getDashboardWidget: function (kpi) {
  11. var Widget = registry.getAny([
  12. kpi.widget, 'abstract',
  13. ]);
  14. var widget = new Widget(this, kpi);
  15. return widget;
  16. },
  17. _renderView: function () {
  18. this.$el.html($(qweb.render('dashboard_kpi.dashboard')));
  19. this.$el.css(
  20. 'background-color', this.state.specialData.background_color);
  21. this.$el.find('.gridster')
  22. .css('width', this.state.specialData.width);
  23. this.$grid = this.$el.find('.gridster ul');
  24. var self = this;
  25. this.kpi_widget = {};
  26. _.each(this.state.specialData.item_ids, function (kpi) {
  27. var element = $(qweb.render(
  28. 'kpi_dashboard.kpi', {widget: kpi}));
  29. element.css('background-color', kpi.color);
  30. element.css('color', kpi.font_color);
  31. self.$grid.append(element);
  32. self.kpi_widget[kpi.id] = self._getDashboardWidget(kpi);
  33. self.kpi_widget[kpi.id].appendTo(element);
  34. });
  35. this.$grid.gridster({
  36. widget_margins: [
  37. this.state.specialData.margin_x,
  38. this.state.specialData.margin_y,
  39. ],
  40. widget_base_dimensions: [
  41. this.state.specialData.widget_dimension_x,
  42. this.state.specialData.widget_dimension_y,
  43. ],
  44. cols: this.state.specialData.max_cols,
  45. }).data('gridster').disable();
  46. this.channel = 'kpi_dashboard_' + this.state.res_id;
  47. this.call(
  48. 'bus_service', 'addChannel', this.channel);
  49. this.call('bus_service', 'startPolling');
  50. this.call(
  51. 'bus_service', 'onNotification',
  52. this, this._onNotification
  53. );
  54. if (this.state.specialData.compute_on_fly_refresh > 0) {
  55. // Setting the refresh interval
  56. this.on_fly_interval = setInterval(function () {
  57. self.trigger_up('refresh_on_fly');
  58. }, this.state.specialData.compute_on_fly_refresh *1000);
  59. };
  60. return $.when();
  61. },
  62. on_detach_callback: function () {
  63. // We want to clear the refresh interval once we exit the view
  64. if (this.on_fly_interval) {
  65. clearInterval(this.on_fly_interval)
  66. }
  67. this._super.apply(this, arguments);
  68. },
  69. _onNotification: function (notifications) {
  70. var self = this;
  71. _.each(notifications, function (notification) {
  72. var channel = notification[0];
  73. var message = notification[1];
  74. if (channel === self.channel && message) {
  75. var widget = self.kpi_widget[message.id];
  76. if (widget !== undefined) {
  77. widget._fillWidget(message);
  78. }
  79. }
  80. });
  81. },
  82. });
  83. return DashboardRenderer;
  84. });