feat:instance added , redirect after login fixed

This commit is contained in:
snehalathad@aissel.com 2024-06-20 11:33:33 +05:30
parent cb08d91dd3
commit 65ebf617c5
7 changed files with 161 additions and 40 deletions

View File

@ -7,19 +7,22 @@ db_configs = [
'user': 'snehalatha', 'user': 'snehalatha',
'password': 'paSsWord@#654', 'password': 'paSsWord@#654',
'host': 'konectar-readreplica-rds.konectar.io', 'host': 'konectar-readreplica-rds.konectar.io',
'database': 'kolm_lite_cardio' 'database': 'kolm_lite_cardio',
'instance':'cardio'
}, },
{ {
'user': 'snehalatha', 'user': 'snehalatha',
'password': 'paSsWord@#654', 'password': 'paSsWord@#654',
'host': 'konectar-readreplica-rds.konectar.io', 'host': 'konectar-readreplica-rds.konectar.io',
'database': 'kolm_lite_veterinary' 'database': 'kolm_lite_veterinary',
'instance':'veterinary'
}, },
{ {
'user': 'snehalatha', 'user': 'snehalatha',
'password': 'paSsWord@#654', 'password': 'paSsWord@#654',
'host': 'konectar-readreplica-rds.konectar.io', 'host': 'konectar-readreplica-rds.konectar.io',
'database': 'kolm_lite_oralhealth' 'database': 'kolm_lite_oralhealth',
'instance':'oralhealth'
} }
] ]
@ -35,7 +38,7 @@ def fetch_records(config):
if connection.is_connected(): if connection.is_connected():
cursor = connection.cursor(dictionary=True) cursor = connection.cursor(dictionary=True)
cursor.execute("SELECT kols.id,CONCAT_WS(' ',kols.first_name,kols.middle_name,kols.last_name) as kol_name, GROUP_CONCAT(DISTINCT projects.name) as project_name, clients.name as client_name,CONCAT(client_users.first_name,client_users.last_name) as user_name, GROUP_CONCAT(DISTINCT log_activities.transaction_name,':',date(log_activities.created_on)) as project_details FROM kols left join user_kols on user_kols.kol_id = kols.id inner join opt_inout_statuses on opt_inout_statuses.id = user_kols.opt_in_out_status left join log_activities on log_activities.miscellaneous1 = user_kols.kol_id left join client_users on client_users.id = user_kols.user_id left join clients on client_users.client_id = clients.id left join project_kols on project_kols.kol_id = user_kols.kol_id left join projects on projects.id = project_kols.project_id where log_activities.module ='opt_in_out' and log_activities.transaction_name in ('New','Opt-in Requested','Opt-out','Opt-in Approved','Opt-in Expired','Opt-in Received','Opt-in') group by kols.id;") cursor.execute(f"SELECT '{ config['instance'] }' as instance, kols.id,CONCAT_WS(' ',kols.first_name,kols.middle_name,kols.last_name) as kol_name, GROUP_CONCAT(DISTINCT projects.name) as project_name, clients.name as client_name,CONCAT(client_users.first_name,client_users.last_name) as user_name, GROUP_CONCAT(DISTINCT log_activities.transaction_name,':',date(log_activities.created_on)) as project_details,case when user_kols.opt_in_out_status = 3 then 'Opted Out' when user_kols.opt_in_out_status = 4 then 'Opted In' else '' end as status FROM kols left join user_kols on user_kols.kol_id = kols.id inner join opt_inout_statuses on opt_inout_statuses.id = user_kols.opt_in_out_status left join log_activities on log_activities.miscellaneous1 = user_kols.kol_id left join client_users on client_users.id = user_kols.user_id left join clients on client_users.client_id = clients.id left join project_kols on project_kols.kol_id = user_kols.kol_id left join projects on projects.id = project_kols.project_id where log_activities.module ='opt_in_out' and log_activities.transaction_name in ('New','Opt-in Requested','Opt-out','Opt-in Approved','Opt-in Expired','Opt-in Received','Opt-in') group by kols.id;")
records = cursor.fetchall() records = cursor.fetchall()
return records return records

View File

@ -16,7 +16,8 @@
"status", "status",
"cs_assigned_poc", "cs_assigned_poc",
"optin_type", "optin_type",
"data_processed_date" "data_processed_date",
"instance"
], ],
"fields": [ "fields": [
{ {
@ -77,12 +78,17 @@
"fieldname": "data_processed_date", "fieldname": "data_processed_date",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Data Processed Date" "label": "Data Processed Date"
},
{
"fieldname": "instance",
"fieldtype": "Data",
"label": "Instance"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"is_virtual": 1, "is_virtual": 1,
"links": [], "links": [],
"modified": "2024-06-18 15:07:09.935741", "modified": "2024-06-19 17:59:49.749353",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Opt management production", "module": "Opt management production",
"name": "optlistprod", "name": "optlistprod",

View File

@ -27,7 +27,8 @@ class optlistprod(Document):
"client_poc" : str(client["user_name"]), "client_poc" : str(client["user_name"]),
"optin_received_date" : optinReceived(str(client["project_details"]),"Opt-in Received"), "optin_received_date" : optinReceived(str(client["project_details"]),"Opt-in Received"),
"optin_approved_date" : optinReceived(str(client["project_details"]),"Opt-in Approved"), "optin_approved_date" : optinReceived(str(client["project_details"]),"Opt-in Approved"),
"status" : optinStatus(str(client["project_details"])), "status" : str(client["status"]),
"instance" : str(client["instance"]),
} }
) )
@ -117,7 +118,8 @@ def getValues():
"client_poc" : str(client["user_name"]), "client_poc" : str(client["user_name"]),
"optin_received_date" : optinReceived(str(client["project_details"]),"Opt-in Received"), "optin_received_date" : optinReceived(str(client["project_details"]),"Opt-in Received"),
"optin_approved_date" : optinReceived(str(client["project_details"]),"Opt-in Approved"), "optin_approved_date" : optinReceived(str(client["project_details"]),"Opt-in Approved"),
"status" : optinStatus(str(client["project_details"])), "status" : str(client["status"]),
"instance" : str(client["instance"]),
} }
for client in records for client in records
] ]

View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>OPT IN ANALYST</title>
<!-- Tabulator CSS -->
</style>
</head>
<body>
<!-- {% extends "templates/web.html" %} -->
{% block content %}
<div id="loader" class="loader"></div>
<p style="padding-left: 5px;"><strong>Opt In Data </strong> </p>
<p> {{ frappe.session.user }}</p>
<div style="padding-left: 5px;">
<button id="download-csv" class="button button1">Download CSV</button>
<button id="download-xlsx" class="button button2">Download XLSX</button>
<button id="download-pdf" class="button button3">Download PDF</button>
</div>
<div style="padding-left: 5px; padding-bottom: 5px;" id="tabulator-table" class="tabulator-table"></div>
{% endblock %}
{% block script %}
<script src="https://unpkg.com/tabulator-tables@5.4.4/dist/js/tabulator.min.js"></script>
<script frappe.csrf_token = "{{frappe.session.csrf_token}}"; ></script>
<script type="text/javascript" src="https://oss.sheetjs.com/sheetjs/xlsx.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.4.0/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.20/jspdf.plugin.autotable.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
// if( is_subscribed )
// {
// window.location.href = '/login?redirect-to=/optanalystview';
// // window.location.replace('/login');
// }
// else
// {
// //window.location.href = '/optanalystview';
// }
frappe.call({
method: 'optmanagementprod.www.optanlaystauth.isUserLoggedIn',
callback: function(r) {
console.log(r.message);
if(!r.message)
{
window.location.href = '/login?redirect-to=/optanalystview';
}
}
});
});
</script>
{% endblock %}
</body>
</html>

View File

@ -36,7 +36,8 @@
0% { transform: rotate(0deg); } 0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); } 100% { transform: rotate(360deg); }
} }
/* .tabulator .tabulator-header .tabulator-col {background-color: #2b9af3;} */ /* //background-color: #2b9af3; */
.tabulator .tabulator-header .tabulator-col { color: black;}
</style> </style>
</head> </head>
<body> <body>
@ -73,35 +74,55 @@
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
const loader = document.getElementById('loader'); const loader = document.getElementById('loader');
const content = document.getElementById('tabulator-table'); const content = document.getElementById('tabulator-table');
var data = []; var data = [];
var table; var table;
frappe.call({ let loading = false;
method: 'optmanagementprod.www.optanalystview.fetch_data',
callback: function(r) {
if (r.message) {
data = r.message;
// Render data in the HTML
console.log(data);
// You can use the data to populate your table or any other HTML element
function loadData() { function loadData() {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(() => { setTimeout(() => {
resolve("Data loaded"); resolve("Data loaded");
}, 3000); // Simulate a 3-second loading time }, 12000); // Simulate a 3-second loading time
}); });
} }
window.loadData = loadData();
frappe.call({
method: 'optmanagementprod.www.optanlaystauth.isUserLoggedIn',
callback: function(r) {
console.log(r.message);
if(!r.message)
{
window.location.href = '/login?redirect-to=/optanalystview';
}
else{
frappe.call({
method: 'optmanagementprod.www.optanalystview.fetch_data',
callback: function(r) {
// console.log(r);
if (r.message.length > 0) {
loading = false;
data = r.message;
loader.setAttribute('style', 'display : none !important');
// Render data in the HTML
// console.log(data);
// You can use the data to populate your table or any other HTML element
// Sample data for the table // Sample data for the table
var tableData = []; var tableData = [];
for(var rec in data) for(var rec in data)
{ {
tableData.push({ tableData.push({
kol_id:rec.kol_id, kol_name:rec["kol_name"],project_name: rec["project_name"], client_name:rec["client_name"], client_poc:rec["client_poc"], cs_Assigned_poc:rec["cs_Assigned_poc"],optin_received_date:rec["optin_received_date"],optin_approved_date:rec["optin_approved_date"],status:rec["status"],optin_type:rec["optin_type"],data_processed_date:rec["data_processed_date"] kol_id:rec.kol_id, kol_name:rec["kol_name"],project_name: rec["project_name"], client_name:rec["client_name"], client_poc:rec["client_poc"],optin_received_date:rec["optin_received_date"] == null ? ' ' : rec["optin_received_date"],optin_approved_date:rec["optin_approved_date"],status:rec["status"],instance:rec["instance"]
// cs_Assigned_poc:rec["cs_Assigned_poc"],optin_type:rec["optin_type"],data_processed_date:rec["data_processed_date"]
}); });
} }
console.log(tableData); // console.log(tableData);
// var tableData = [( // var tableData = [(
// {kol_id:1, kol_name:"Oli Bob",project_name: "", client_name:"12", client_poc:"red", cs_Assigned_poc:""} ) // {kol_id:1, kol_name:"Oli Bob",project_name: "", client_name:"12", client_poc:"red", cs_Assigned_poc:""} )
@ -111,28 +132,31 @@ document.addEventListener('DOMContentLoaded', function() {
table = new Tabulator("#tabulator-table", { table = new Tabulator("#tabulator-table", {
data:data, // Assign data to table data:data, // Assign data to table
layout:"fitDataTable", //layout:"fitDataTable",
// filterMode: "remote", // filterMode: "remote",
pagination:true, pagination:true,
paginationSize: 20, paginationSize: 20,
placeholder:"Awaiting Data, Please wait", placeholder:"No results",
// layout:"fitDataStretch", layout:"fitDataStretch",
ajaxLoaderLoading:"<span>Loading Data</span>",
// ajaxLoaderLoading:"<span>Loading Data</span>",
// paginationMode:"remote", // paginationMode:"remote",
paginationSizeSelector: [5, 10, 50, 100], paginationSizeSelector: [5, 10, 50, 100],
paginationCounter: "rows", paginationCounter: "rows",
columns:[ // Define table columns columns:[ // Define table columns
{title:"KOL ID", field:"kol_id",headerFilterPlaceholder: "Search",hozAlign:"center", headerFilter: true,width:2}, {title:"KOL ID", field:"kol_id",headerFilterPlaceholder: "Search",hozAlign:"center", headerFilter: true,width:150},
{title:"KOL Name", field:"kol_name",headerFilterPlaceholder: "Search", headerFilter: true,}, {title:"KOL Name", field:"kol_name",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Project Name", field:"project_name",headerFilterPlaceholder: "Search", headerFilter: true,width:250}, {title:"Project Name", field:"project_name",headerFilterPlaceholder: "Search", headerFilter: true,width:250},
{title:"Client Name", field:"client_name",headerFilterPlaceholder: "Search", headerFilter: true,}, {title:"Client Name", field:"client_name",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Client POC", field:"client_poc",headerFilterPlaceholder: "Search", headerFilter: true,}, {title:"Client POC", field:"client_poc",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"CS Assigned POC", field:"cs_assigned_poc",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Requested Date", field:"optin_received_date",headerFilterPlaceholder: "Search", headerFilter: true,}, {title:"Requested Date", field:"optin_received_date",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Approved Date", field:"optin_approved_date",headerFilterPlaceholder: "Search", headerFilter: true,}, {title:"Approved Date", field:"optin_approved_date",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Status", field:"status",headerFilterPlaceholder: "Search", headerFilter: true,}, {title:"Status", field:"status",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Opt-In Type", field:"optin_type",headerFilterPlaceholder: "Search", headerFilter: true,}, {title:"Instance", field:"instance",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Data Processed Date", field:"data_processed_date",headerFilterPlaceholder: "Search", headerFilter: true} // {title:"CS Assigned POC", field:"cs_assigned_poc",headerFilterPlaceholder: "Search", headerFilter: true,},
// {title:"Opt-In Type", field:"optin_type",headerFilterPlaceholder: "Search", headerFilter: true,},
// {title:"Data Processed Date", field:"data_processed_date",headerFilterPlaceholder: "Search", headerFilter: true}
], ],
}); });
document.getElementById("download-csv").addEventListener("click", function(){ document.getElementById("download-csv").addEventListener("click", function(){
@ -161,27 +185,40 @@ document.getElementById("download-pdf").addEventListener("click", function(){
}); });
}else{
loading = true;
} }
} }
}); });
async function init() { async function init() {
//console.log(data);
// Hide loader
if(loading){
loader.style.display = 'none';
// loader.setAttribute('style', 'display : none !important');
// Display content
content.innerHTML = table;
content.style.display = 'block';
}else{
// Show loader // Show loader
loader.style.display = 'block'; loader.style.display = 'block';
// Load data // Load data
const data = await loadData(); // const data2 = await loadData();
}
// Hide loader
loader.style.display = 'none';
// Display content
content.innerHTML = table;
content.style.display = 'block';
} }
// Initialize the loader and content // Initialize the loader and content
init(); init();
}
}
});
}); });
</script> </script>
{% endblock %} {% endblock %}

View File

@ -13,9 +13,9 @@ def fetch_data():
"client_name" : str(client["client_name"]), "client_name" : str(client["client_name"]),
"client_poc" : str(client["client_poc"]), "client_poc" : str(client["client_poc"]),
"optin_received_date" : str(client["optin_received_date"]), "optin_received_date" : str(client["optin_received_date"]),
"optin_approved_date" : str(client["optin_approved_date"]), "optin_approved_date" : "empty" if not str(client["optin_approved_date"]) else str(client["optin_approved_date"]),
"status" : str(client["status"]), "status" : str(client["status"]),
"instance" : str(client["instance"]),
} }

View File

@ -0,0 +1,12 @@
import frappe
@frappe.whitelist(allow_guest=True)
def isUserLoggedIn():
is_subscribed = False
if frappe.session.user == "Guest":
is_subscribed = is_subscribed
return is_subscribed
else:
return True