Quellcode durchsuchen

performance issues with too many jobs added at once

master
patrick vor 6 Jahren
Ursprung
Commit
4b02928b15
2 geänderte Dateien mit 63 neuen und 29 gelöschten Zeilen
  1. +57
    -29
      js/bts_timesheet.js
  2. +6
    -0
      ts.php

+ 57
- 29
js/bts_timesheet.js Datei anzeigen

@@ -223,6 +223,9 @@
value = value.toLowerCase();
var selector = get_selector_for_filter_people(input);
$.each( $(selector).find('div.peopleitem'), function(index, e){
//uncheck everyone
$(e).find('input[type="checkbox"]').prop('checked', false);
var html = $(e).find('div[name="title"] a').html();
html = html.toLowerCase();
if (-1 != html.indexOf(value)){//we find it;
@@ -245,17 +248,18 @@
$(document).on('click', 'div.divTableHead.bdelete', function(){
var o = new Job({empty:true});
add_new_empty_job();
});

function add_new_empty_job(){
var o = new Job({empty:true});
$('div.workspace').append(o.el);
o.el.get(0).scrollIntoView();
dtp_init();
}
$(document).on('click', 'div[name="copyschedule"]', function(e){
e.stopPropagation();
if (!confirm('add 10 empty new jobs?'))
return;
for (var i=1; i<=10; i++){
var o = new Job({empty:true});
}
add_new_empty_job();
});
$(document).on('click', 'div.divTableCell.bdelete', function(){
@@ -311,17 +315,16 @@
var table = $(this).closest('div.divTable');
var job = table.data().job;
clone_data_create_new_job(job.get_record_from_ui());
dtp_init();
});
class Job{ //save data for the record, and display it as GUI
constructor(data){
var html = jQuery("#job_item").html();
this.el = $(html);
jQuery('div.workspace').append(this.el);
//jQuery('div.workspace').append(this.el);
this.load_data(data);
dtp_init();
this.init_start_rating()
this.init_start_rating();
}
init_start_rating(){
@@ -330,7 +333,6 @@
var r = $(this).attr('data-rating');
self.mark_dirty();
self.set_rating(r);
})
this.el.find("div.brating").mouseenter(function(){
@@ -912,8 +914,11 @@
var value = $(e).attr('value');
if( -1 != value.indexOf(strDate) ) //found
{
var j = $(e).closest('div.divTable').data().job;
jobs.push(j);
var el = $(e).closest('div.divTable');
if (el.is(":visible")){
var j = el.data().job;
jobs.push(j);
}
}
});
});
@@ -921,6 +926,8 @@
jobs.forEach(function(e){
clone_data_create_new_job(e.get_record_from_ui(),7);//add 7 days
});
dtp_init();
debounced_calculate();
});
$('div.weekly div.weekname.next').click(function(){
@@ -944,12 +951,16 @@
$('div.week1,div.week2').click(function(e){
e.stopPropagation();
$(this).toggleClass('filtered');
filter_workspace_by_weeks();
do_filter_workspace();
});
function copy_single_day_to_next_week(el){
var j = $(el).closest('div.divTable').data().job;
clone_data_create_new_job(j.get_data_from_ui() , 7); // +7 days
var tb = $(el).closest('div.divTable');
if (tb.is(':visible')){
var j = $(tb).data().job;
clone_data_create_new_job(j.get_record_from_ui() , 7); // +7 days
}
dtp_init();
}
function clone_data_create_new_job(val, num_of_shifted_days){
@@ -1030,9 +1041,13 @@
finish: format_date(last),
}, function(response, status, xhr){
if (response.status =='success'){
var job_els = [];
response.jobs.forEach(function(job){
new Job(job);
console.log('loading job... %o', job);
var o = new Job(job);
job_els.push(o.el);
});
show_jobs(job_els);
//filter it if reqired
do_filter_workspace();
}else{
@@ -1043,6 +1058,13 @@
}
function show_jobs(job_els){
if (job_els.length >0){
$('div.workspace').append(job_els);
job_els[0].get(0).scrollIntoView();
}
}
function format_date(date){
var dd = date.getDate();
var mm = date.getMonth() + 1; //January is 0!
@@ -1075,6 +1097,8 @@
$('div.workspace > div.divTable').remove();
//clear datetime picker
$('div.xdsoft_datetimepicker').remove();
//
show_loading_jobs();
}
$('button[name="confirmschedule"]').click(function(){
@@ -1088,20 +1112,27 @@
function do_filter_workspace(){
var staffs =[];
$('div.stafflist div.peopleitem :checked').each(function(i, e){
var id = $(e).parent().attr('data-id');
//console.log("%o, id=%s", e, id);
staffs.push(id.substring(1));
if ($(e).parent().is(':visible')){
var id = $(e).parent().attr('data-id');
//console.log("%o, id=%s", e, id);
staffs.push(id.substring(1));
}
});
var clients =[];
$('div.clientlist div.peopleitem :checked').each(function(i, e){
var id = $(e).parent().attr('data-id');
//console.log("%o, id=%s", e, id);
clients.push(id.substring(1));
if ($(e).parent().is(':visible')){
var id = $(e).parent().attr('data-id');
//console.log("%o, id=%s", e, id);
clients.push(id.substring(1));
}
});
console.log('filter worksspace');
filter_workspace(staffs, clients);
calculate_total_hour_and_money();
console.log('filter by weeks');
filter_workspace_by_weeks();
debounced_calculate();
}
function filter_workspace(staffs, clients){
@@ -1140,11 +1171,8 @@
if ((hide_week1 && job.is_week1()) ||
(hide_week2 && job.is_week2()) ){
$(e).fadeOut();
}else{
$(e).fadeIn();
}
});
debounced_calculate();
}
var debounced_calculate = debounce(calculate_total_hour_and_money, 2000);

+ 6
- 0
ts.php Datei anzeigen

@@ -464,6 +464,7 @@ class AcareOffice{
//ajax browse job with different filters
function list_job(){
$func_start = time();
check_ajax_referer('acaresydney');
$start = $_POST['start'];
$finish = $_POST['finish'];
@@ -491,6 +492,11 @@ class AcareOffice{
);
}
}
$func_end = time();
$func_diff = $func_end - $func_start;
$response['duration_start'] = $func_start;
$response['duration_end'] = $func_end;
$response['duration'] = $func_diff;
wp_send_json($response);
wp_die();
}

Laden…
Abbrechen
Speichern