[UPDT] BASE: Added empty HTML for department chart in dashboard
This commit is contained in:
@@ -1,53 +1,84 @@
|
||||
$(document).ready(function () {
|
||||
function recruitmentChart(dataSet, labels) {
|
||||
const data = {
|
||||
labels: labels,
|
||||
datasets: dataSet,
|
||||
};
|
||||
// Create chart using the Chart.js library
|
||||
window['myChart'] = {}
|
||||
const ctx = document.getElementById("recruitmentChart1").getContext("2d");
|
||||
myChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: data,
|
||||
options: {
|
||||
onClick: (e, activeEls) => {
|
||||
let datasetIndex = activeEls[0].datasetIndex;
|
||||
let dataIndex = activeEls[0].index;
|
||||
let datasetLabel = e.chart.data.datasets[datasetIndex].label;
|
||||
let value = e.chart.data.datasets[datasetIndex].data[dataIndex];
|
||||
let label = e.chart.data.labels[dataIndex];
|
||||
localStorage.removeItem("savedFilters");
|
||||
window.location.href = "/recruitment/candidate-view" +"?recruitment="+datasetLabel+"&stage_id__stage_type="+ label.toLowerCase()
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
$.ajax({
|
||||
url: "/recruitment/dashboard-pipeline",
|
||||
type: "GET",
|
||||
success: function (response) {
|
||||
// Code to handle the response
|
||||
// response = {'dataSet': [{'label': 'Odoo developer 2023-03-30', 'data': [3, 0, 5, 3]}, {'label': 'React developer 2023-03-31', 'data': [0, 1, 1, 0]}, {'label': 'Content Writer 2023-04-01', 'data': [1, 0, 0, 0]}], 'labels': ['Initial', 'Test', 'Interview', 'Hired']}
|
||||
dataSet = response.dataSet;
|
||||
labels = response.labels;
|
||||
recruitmentChart(dataSet, labels);
|
||||
},
|
||||
});
|
||||
function isChartEmpty(chartData) {
|
||||
if (!chartData) {
|
||||
return true;
|
||||
}
|
||||
for (let i = 0; i < chartData.length; i++) {
|
||||
if (chartData[i] && chartData[i].data) {
|
||||
const hasNonZeroValues = chartData[i].data.some((value) => value !== 0);
|
||||
if (hasNonZeroValues) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$('#chart1').click(function (e) {
|
||||
var chartType = myChart.config.type
|
||||
if (chartType === 'line') {
|
||||
chartType = 'bar';
|
||||
} else if(chartType==='bar') {
|
||||
chartType = 'doughnut';
|
||||
} else if(chartType==='doughnut'){
|
||||
chartType = 'pie'
|
||||
}else if(chartType==='pie'){
|
||||
chartType = 'line'
|
||||
}
|
||||
myChart.config.type = chartType;
|
||||
myChart.update();
|
||||
});
|
||||
|
||||
function recruitmentChart(dataSet, labels) {
|
||||
const data = {
|
||||
labels: labels,
|
||||
datasets: dataSet,
|
||||
};
|
||||
// Create chart using the Chart.js library
|
||||
window["myChart"] = {};
|
||||
const ctx = document.getElementById("recruitmentChart1").getContext("2d");
|
||||
myChart = new Chart(ctx, {
|
||||
type: "bar",
|
||||
data: data,
|
||||
options: {
|
||||
onClick: (e, activeEls) => {
|
||||
let datasetIndex = activeEls[0].datasetIndex;
|
||||
let dataIndex = activeEls[0].index;
|
||||
let datasetLabel = e.chart.data.datasets[datasetIndex].label;
|
||||
let value = e.chart.data.datasets[datasetIndex].data[dataIndex];
|
||||
let label = e.chart.data.labels[dataIndex];
|
||||
localStorage.removeItem("savedFilters");
|
||||
window.location.href =
|
||||
"/recruitment/candidate-view" +
|
||||
"?recruitment=" +
|
||||
datasetLabel +
|
||||
"&stage_id__stage_type=" +
|
||||
label.toLowerCase();
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
$.ajax({
|
||||
url: "/recruitment/dashboard-pipeline",
|
||||
type: "GET",
|
||||
success: function (response) {
|
||||
// Code to handle the response
|
||||
dataSet = response.dataSet;
|
||||
labels = response.labels;
|
||||
if (isChartEmpty(dataSet)) {
|
||||
$("#recruitmentChart1")
|
||||
.parent()
|
||||
.html(
|
||||
`<div style="height: 325px; display:flex;align-items: center;justify-content: center;" class="">
|
||||
<div style="" class="">
|
||||
<img style="display: block;width: 70px;margin: 20px auto ;" src="/static/images/ui/joiningchart.png" class="" alt=""/>
|
||||
<h3 style="font-size:16px" class="oh-404__subtitle">${response.message}</h3>
|
||||
</div>
|
||||
</div>`
|
||||
);
|
||||
} else {
|
||||
recruitmentChart(dataSet, labels);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
$("#chart1").click(function (e) {
|
||||
var chartType = myChart.config.type;
|
||||
if (chartType === "line") {
|
||||
chartType = "bar";
|
||||
} else if (chartType === "bar") {
|
||||
chartType = "doughnut";
|
||||
} else if (chartType === "doughnut") {
|
||||
chartType = "pie";
|
||||
} else if (chartType === "pie") {
|
||||
chartType = "line";
|
||||
}
|
||||
myChart.config.type = chartType;
|
||||
myChart.update();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -149,7 +149,7 @@ def dashboard(request):
|
||||
|
||||
@login_required
|
||||
@manager_can_enter(perm="recruitment.view_recruitment")
|
||||
def dashboard_pipeline(_):
|
||||
def dashboard_pipeline(request):
|
||||
"""
|
||||
This method is used generate recruitment dataset for the dashboard
|
||||
"""
|
||||
@@ -167,7 +167,7 @@ def dashboard_pipeline(_):
|
||||
"data": data,
|
||||
}
|
||||
)
|
||||
return JsonResponse({"dataSet": data_set, "labels": labels})
|
||||
return JsonResponse({"dataSet": data_set, "labels": labels,"message":_("No data Found...")})
|
||||
|
||||
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user