Browse Source

Jul 25 : [UPDT] Updated 'advanced_dynamic_dashboard'

pull/267/head
AjmalCybro 2 years ago
parent
commit
861f98c058
  1. 2
      advanced_dynamic_dashboard/__manifest__.py
  2. 26
      advanced_dynamic_dashboard/models/dashboard_block.py
  3. 25
      advanced_dynamic_dashboard/static/src/js/dynamic_dashboard.js
  4. 56
      advanced_dynamic_dashboard/static/src/xml/dynamic_dashboard_template.xml

2
advanced_dynamic_dashboard/__manifest__.py

@ -21,7 +21,7 @@
################################################################################
{
'name': "Advanced Dynamic Dashboard",
'version': '16.0.1.0.0',
'version': '16.0.1.0.1',
'category': 'Productivity',
'summary': """Create Configurable Dashboards Easily""",
'description': """Create Configurable Advanced Dynamic Dashboard to get the

26
advanced_dynamic_dashboard/models/dashboard_block.py

@ -20,6 +20,8 @@
#
################################################################################
from ast import literal_eval
from datetime import datetime
from odoo import fields, models
from odoo.osv import expression
@ -87,11 +89,33 @@ class DashboardBlock(models.Model):
help="Enable to edit chart and tile",
default=False, invisible=True)
def get_dashboard_vals(self, action_id):
def get_dashboard_vals(self, action_id, start_date=None, end_date=None):
"""Fetch block values from js and create chart"""
block_id = []
for rec in self.env['dashboard.block'].sudo().search(
[('client_action_id', '=', int(action_id))]):
if rec.filter is False:
rec.filter = "[]"
filter_list = literal_eval(rec.filter)
# Remove existing date filters if they exist
filter_list = [filter_item for filter_item in filter_list if not (
isinstance(filter_item, tuple) and filter_item[
0] == 'create_date')]
if start_date and start_date != 'null':
start_date_obj = datetime.strptime(start_date, '%Y-%m-%d')
filter_list.append(
('create_date', '>=', start_date_obj.strftime('%Y-%m-%d')))
if end_date and end_date != 'null':
end_date_obj = datetime.strptime(end_date, '%Y-%m-%d')
filter_list.append(
('create_date', '<=', end_date_obj.strftime('%Y-%m-%d')))
rec.filter = repr(filter_list)
vals = {'id': rec.id, 'name': rec.name, 'type': rec.type,
'graph_type': rec.graph_type, 'icon': rec.fa_icon,
'cols': rec.graph_size,

25
advanced_dynamic_dashboard/static/src/js/dynamic_dashboard.js

@ -20,6 +20,8 @@ odoo.define('advanced_dynamic_dashboard.Dashboard', function (require) {
'click #edit_layout': '_onClick_edit_layout',
'click #save_layout': '_onClick_save_layout',
'change #theme-toggle': 'switch_mode',
'change #start-date': '_onchangeFilter',
'change #end-date': '_onchangeFilter',
'mouseenter #theme-change-icon': 'show_mode_text',
'mouseleave #theme-change-icon': 'hide_mode_text',
'click .tile': '_onClick_tile',
@ -76,6 +78,27 @@ odoo.define('advanced_dynamic_dashboard.Dashboard', function (require) {
this.$el.find('.theme_icon').toggleClass('bi-moon-stars-fill', !isDarkTheme);
this.$el.find('.dropdown-export').toggleClass('dropdown-menu-dark', isDarkTheme);
},
_onchangeFilter: function() {
var start_date = $('#start-date').val();
var end_date = $('#end-date').val();
var self = this;
if (!start_date) {
start_date = "null";
}
if (!end_date) {
end_date = "null";
}
this._rpc({
model: 'dashboard.block',
method: 'get_dashboard_vals',
args: [[], this.action_id, start_date, end_date],
}).then(function (result) {
self.block_ids = result;
self.$('.o_dynamic_dashboard').empty(); // Clear existing blocks before rendering
self.render_dashboards(); // Re-render the dashboard with updated data
self.gridstack_init(self); // Reinitialize gridstack after rendering
});
},
get_colors: function (x_axis) {//Function fetch random color values and set chart color
return x_axis.map(() => `rgb(${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)})`);
},
@ -314,7 +337,7 @@ odoo.define('advanced_dynamic_dashboard.Dashboard', function (require) {
this.fetch_data().then(function () {//Fetch all datas
self.render_dashboards();
self.gridstack_init(self);
location.reload();
location.reload();
});
},
search_chart: function (e) {// Fetch search input value and filter the chart and tile.

56
advanced_dynamic_dashboard/static/src/xml/dynamic_dashboard_template.xml

@ -45,39 +45,31 @@
data-chart_type="radar">Radar Chart</a>
</div>
</label>
<label class="navbar-items layout-switch"
id="edit-layout-label">
<button class="navbar-items btn-search_edit btn btn-primary my-2 mx-2 my-sm-0"
type="button"
id="edit_layout">Edit
Layout
</button>
<button class="navbar-items btn-search_edit btn btn-primary my-2 mx-2 my-sm-0"
type="button"
id="save_layout">Save Layout
</button>
</label>
<label class="navbar-items toggle-btn"
id="theme-change-icon">
<input type="checkbox" class="toggle"
id="theme-toggle"/>
<i class="theme_icon bi bi-moon-stars-fill"/>
</label>
<label class="search-group">
<div class="navbar-items btn-group search-box">
<input class="form-control mr-sm-2" type="text"
placeholder="Search"
id="search-input-chart"
aria-label="Search"/>
<span id="searchclear">
<i class='fa fa-times search-clear'/>
</span>
</div>
<button class="navbar-items btn-search_edit btn btn-outline-primary my-2 my-sm-0 search-btn"
type="button"
id="search-button">Search</button>
<label class="navbar-items layout-switch" id="edit-layout-label">
<button class="navbar-items btn-search_edit btn btn-primary my-2 mx-2 my-sm-0" type="button" id="edit_layout">Edit Layout</button>
<button class="navbar-items btn-search_edit btn btn-primary my-2 mx-2 my-sm-0" type="button" id="save_layout">Save Layout</button>
</label>
<label class="navbar-items toggle-btn" id="theme-change-icon">
<input type="checkbox" class="toggle" id="theme-toggle" />
<i class="theme_icon bi bi-moon-stars-fill" />
</label>
<div class="search-group" style="margin-right: 30px;">
<!-- Search Bar -->
<div class="navbar-items btn-group search-box">
<input class="form-control mr-sm-2" type="text" placeholder="Search" id="search-input-chart" aria-label="Search" />
<span id="searchclear">
<i class='fa fa-times search-clear' />
</span>
</div>
<button class="navbar-items btn-search_edit btn btn-outline-primary my-2 my-sm-0 search-btn" type="button" id="search-button">Search</button>
</div>
<!-- Date Inputs -->
<div class="date-inputs" style="position: absolute; right: 50.5em;">
<label for="start-date" style="color: black; margin-right: 5px;">Start Date:</label>
<input type="date" id="start-date" name="start-date" style="color: black; border: 1px solid #4e4e4e; background-color: white; padding: 5px 10px; border-radius: 5px;"/>
<label for="end-date" style="color: black; margin-right: 5px;">End Date:</label>
<input type="date" id="end-date" name="end-date" style="color: black; border: 1px solid #4e4e4e; background-color: white; padding: 5px 10px; border-radius: 5px;"/>
</div>
</ul>
</div>
</div>

Loading…
Cancel
Save