Skip to content

Commit

Permalink
[UPDT]drag and drop kanban stage save in recruitment
Browse files Browse the repository at this point in the history
  • Loading branch information
horilla-opensource committed Jul 27, 2023
1 parent 01591b7 commit d85bd5e
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 157 deletions.
4 changes: 3 additions & 1 deletion recruitment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Stage(models.Model):
stage_type = models.CharField(
max_length=20, choices=stage_types, default="interview"
)
sequence = models.IntegerField(null=True)
sequence = models.IntegerField(null=True,default=0)
is_active = models.BooleanField(default=True)
objects = models.Manager()

Expand All @@ -142,6 +142,8 @@ class Meta:

permissions = (("archive_Stage", "Archive Stage"),)
unique_together = ["recruitment_id", "stage"]
ordering = ["sequence"]



class Candidate(models.Model):
Expand Down
306 changes: 154 additions & 152 deletions recruitment/static/pipeline/pipelineDrag.js
Original file line number Diff line number Diff line change
@@ -1,176 +1,178 @@
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
let cookieValue = null;
if (document.cookie && document.cookie !== "") {
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === name + "=") {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
return cookieValue;
}


var candidateId = null

$(".candidate").mousedown(function(){
window['candidateId'] = $(this).attr('data-candidate-id');
return cookieValue;
}

var candidateId = null;

$(".candidate").mousedown(function () {
window["candidateId"] = $(this).attr("data-candidate-id");
});

var stageSequence = null;
var recruitmentId = null;
var oldSequences = [];
var stages = [];
var elements = [];

function stageSequenceGet(stage) {
var sequence = {};
var stageId = stage.attr("id");
console.log(stageId);
var stageContainers = stage.parent().parent().find("[data-container]");
let totalStages = stageContainers.length;
$.each(stageContainers, function (index, element) {
sequence[$(element).attr("data-stage-id")] = index + 1;
});


var stageSequence = null
var recruitmentId = null
var oldSequences = []
var stages = []
var elements = []

$('.stage').mousedown(function () {
window['stageSequence'] = $(this).attr('data-stage-sequence');
window['recruitmentId'] = $(this).attr('data-recruitment-id');
$('.stage').each(function(i, obj) {
if (recruitmentId == $(obj).attr('data-recruitment-id')) {
window['stages'].push($(obj).attr('data-stage-id'))
window['oldSequences'].push($(obj).attr('data-stage-sequence'))
}
});
$.ajax({
type: "POST",
url: "/recruitment/stage-sequence-update",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
sequence: JSON.stringify(sequence),
},
success: function (response) {
console.log(response);
},
});

$('.stage').mouseup(function () {
var newSequences = []
$('.stage').each(function(i, obj) {
if (recruitmentId == $(obj).attr('data-recruitment-id') || $(obj).attr('data-recruitment-id') == undefined ) {

newSequences.push($(obj).attr('data-stage-sequence'))
if ($(obj).attr('data-recruitment-id') != undefined) {
window['elements'].push(obj)
}

}
});

if (newSequences.includes(undefined)) {
var newSequences = newSequences.filter(e => e !== stageSequence )
var newSequences = newSequences.map(elem => elem === undefined ? stageSequence : elem);

console.log("---------");
console.log(sequence);
}
$(".stage").mousedown(function () {
window["stageSequence"] = $(this).attr("data-stage-sequence");
window["recruitmentId"] = $(this).attr("data-recruitment-id");
$(".stage").each(function (i, obj) {
if (recruitmentId == $(obj).attr("data-recruitment-id")) {
window["stages"].push($(obj).attr("data-stage-id"));
window["oldSequences"].push($(obj).attr("data-stage-sequence"));
}


oldSequences =JSON.stringify(oldSequences)
stages = JSON.stringify(stages)
if (oldSequences !== JSON.stringify(newSequences)) {
$.ajax({
type: "POST",
url: "/recruitment/stage-sequence-update",
data: {
'csrfmiddlewaretoken': getCookie('csrftoken'),
'recruitmentId':recruitmentId,
'stages':JSON.stringify(stages),
'newSequences':JSON.stringify(newSequences),
},
success: function (response) {
// console.log(response);
}
});
});
});

$(".stage").mouseup(function () {
var newSequences = [];
setTimeout(() => {
stageSequenceGet($(this));
}, 0);
$(".stage").each(function (i, obj) {
if (
recruitmentId == $(obj).attr("data-recruitment-id") ||
$(obj).attr("data-recruitment-id") == undefined
) {
newSequences.push($(obj).attr("data-stage-sequence"));
if ($(obj).attr("data-recruitment-id") != undefined) {
window["elements"].push(obj);
}
}


elements.forEach(function(element) {
for (let index = 0; index < newSequences.length; index++) {
const sequence = newSequences[index];
if (sequence==$(element).attr('data-stage-sequence')) {
$(element).attr('data-stage-sequence',`${index+1}`)
return
}
});

if (newSequences.includes(undefined)) {
var newSequences = newSequences.filter((e) => e !== stageSequence);
var newSequences = newSequences.map((elem) =>
elem === undefined ? stageSequence : elem
);
}

oldSequences = JSON.stringify(oldSequences);
stages = JSON.stringify(stages);

elements.forEach(function (element) {
for (let index = 0; index < newSequences.length; index++) {
const sequence = newSequences[index];
if (sequence == $(element).attr("data-stage-sequence")) {
$(element).attr("data-stage-sequence", `${index + 1}`);
return;
}
});



window['stageSequence'] = null
window['recruitmentId'] = null
window['oldSequences'] = []
window['elements'] = []
window['stages'] = []

}
});

function countSequence(element) {
// let childs = element.parent().find(".change-cand")
let childs = $(".change-cand")
let data = {}
$.each(childs, function (index, elem) {
$(elem).attr("data-sequence", index + 1);
data[elem.getAttribute("data-candidate-id")] = index + 1
});
window["stageSequence"] = null;
window["recruitmentId"] = null;
window["oldSequences"] = [];
window["elements"] = [];
window["stages"] = [];
});

function countSequence(element) {
// let childs = element.parent().find(".change-cand")
let childs = $(".change-cand");
let data = {};
$.each(childs, function (index, elem) {
$(elem).attr("data-sequence", index + 1);
data[elem.getAttribute("data-candidate-id")] = index + 1;
});
$.ajax({
type: "post",
url: "/recruitment/candidate-sequence-update",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
sequenceData: JSON.stringify(data),
},
dataType: "dataType",
success: function (response) {
$("#ohMessages").append(`
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated oh-alert--${response.type}">
${response.message}
</div>`);
},
});
}

$("[data-container='candidate']").on("DOMNodeInserted", function (e) {
var candidate = $(e.target);
setInterval(countSequence(candidate), 500);
// countSequence(candidate)
var stageId = $(this).attr("data-stage-id");
candidateId = $(candidate).attr("data-candidate-id");
if (candidateId != null) {
$.ajax({
type: "post",
url: "/recruitment/candidate-sequence-update",
url: `/recruitment/candidate-stage-update/${candidateId}/`,
data: {
csrfmiddlewaretoken:getCookie("csrftoken"),
sequenceData:JSON.stringify(data),
csrfmiddlewaretoken: getCookie("csrftoken"),
stageId: stageId,
},
dataType: "dataType",
success: function (response) {
var candidateId = $(this).attr("data-candidate-id");
setInterval(countSequence(candidate), 500);

// console.log(response);
$("#ohMessages").append(`
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated oh-alert--${response.type}">
${response.message}
</div>`);
}
},
});

}

$("[data-container='candidate']").on('DOMNodeInserted', function (e) {
var candidate = $(e.target);
setInterval(countSequence(candidate),500)
// countSequence(candidate)
var stageId = $(this).attr('data-stage-id');
candidateId = $(candidate).attr('data-candidate-id');
if (candidateId != null) {
$.ajax({
type: "post",
url: `/recruitment/candidate-stage-update/${candidateId}/`,
data: {
'csrfmiddlewaretoken': getCookie('csrftoken'),
'stageId':stageId
},
success: function (response) {
var candidateId = $(this).attr('data-candidate-id');
setInterval(countSequence(candidate),500)

// console.log(response);
$("#ohMessages").append(`
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated oh-alert--${response.type}">
${response.message}
</div>`);
});

}
});
}

});



$('.schedule').change(function (e) {
date = this.value
candidateId = $(this).data('candidate-id');
$.ajax({
type: "post",
url: `/recruitment/candidate-schedule-date-update`,
data:{
'csrfmiddlewaretoken': getCookie('csrftoken'),
'candidateId':candidateId,
'date':date
},
success: function (response) {
// console.log(response);
}
});

$(".schedule").change(function (e) {
date = this.value;
candidateId = $(this).data("candidate-id");
$.ajax({
type: "post",
url: `/recruitment/candidate-schedule-date-update`,
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
candidateId: candidateId,
date: date,
},
success: function (response) {
// console.log(response);
},
});
});
7 changes: 4 additions & 3 deletions recruitment/templates/pipeline/pipeline_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% if request.user|stage_manages:rec or perms.recruitment.view_stage %}
<div class="oh-tabs__content " id="tab_rec_{{rec.id}}">
<div class="ui-sortable">
<div class="oh-kanban ui-sortable">
<div class="oh-kanban ui-sortable drop-target">
{% for stage in rec.stage_set.all|dictsort:"sequence" %}

<div
Expand All @@ -39,7 +39,6 @@
>
<div class="oh-kanban__section-head stage" style="cursor: pointer;" data-recruitment-id='{{rec.id}}'>
<div class="d-flex">

<span class="oh-badge oh-badge--secondary oh-badge--small oh-badge--round ms-2 mr-2" data-rec-stage-badge="{{rec.id}}" id="stageCount{{stage.id}}">{{stage.candidate_set.all|length}}</span>
<span class="oh-kanban__section-title" data-type="label"
><input
Expand All @@ -52,7 +51,8 @@
hx-swap='none'
style="width: 160px;"
readonly=""
/></span>
/>
</span>
</div>

<div class="oh-kanban__head-actions oh-kanban__dropdown" >
Expand Down Expand Up @@ -284,6 +284,7 @@
</div>

{% include 'pipeline/footer_components.html' %}
<script src="{% static 'kanban/stageSequence.js' %}"></script>



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% for rec in recruitment %}
<div class="oh-tabs__content " id="tab_rec_{{rec.id}}">
<div class="ui-sortable">
<div class="oh-kanban ui-sortable">
<div class="oh-kanban ui-sortable" id="stageDropTarget">
{% for stage in rec.stage_set.all|dictsort:"sequence" %}
<div
class="oh-kanban__section "
Expand Down
1 change: 1 addition & 0 deletions recruitment/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@
path("dashboard-pipeline", views.dashboard_pipeline, name="recruitment-pipeline"),
path("get-open-positions", views.get_open_position, name="get-open-position"),
path("candidate-sequence-update", views.candidate_sequence_update, name="candidate-sequence-update"),
path("stage-sequence-update",views.stage_sequence_update,name="stage-sequence-update")
]
Loading

0 comments on commit d85bd5e

Please sign in to comment.