Skip to content

Commit

Permalink
Better date preset picker on reporting screens.
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigo17 committed Jun 2, 2024
1 parent 5027693 commit ff2002a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 99 deletions.
45 changes: 45 additions & 0 deletions source/src/main/webapp/js/global/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,51 @@ function getDateMedium(date) {
}
}

function setTimeRange(id) {
let fromD = new Date();
fromD.setHours(00);
fromD.setMinutes(00);
fromD.setSeconds(00);

let toD = new Date();
toD.setHours(24);
toD.setMinutes(00);
toD.setSeconds(00);

// fromD ;
if (id === 1) { // Previous Month
fromD.setMonth(toD.getMonth() - 1);
} else if (id === 2) { // Previous 3 Months
fromD.setMonth(fromD.getMonth() - 3);
} else if (id === 3) { // Previous 6 Months
fromD.setMonth(fromD.getMonth() - 6);
} else if (id === 4) { // Previous Year
fromD.setMonth(fromD.getMonth() - 12);
} else if (id === 5) { // Previous Week
fromD.setDate(toD.getDate() - 7);
} else if (id === 6) { // Current Day
fromD.setDate(toD.getDate() - 1);
} else if (id === 7) { // This Month
fromD.setDate(1);
} else if (id === 8) { // Last Calendar Month
fromD.setMonth(fromD.getMonth() - 1);
fromD.setDate(1);
toD.setDate(1);
} else if (id === 9) { // Previous Calendar Month
fromD.setMonth(fromD.getMonth() - 2);
fromD.setDate(1);
toD.setMonth(toD.getMonth() - 1);
toD.setDate(1);
}

$('#frompicker').data("DateTimePicker").date(moment(fromD));
$('#topicker').data("DateTimePicker").date(moment(toD));

console.info("From : " + fromD.toLocaleString() + " - To : " + toD.toLocaleString());
}



/**
* Method used to restrict usage of some specific caracters.
* @param {String} val value to test
Expand Down
59 changes: 6 additions & 53 deletions source/src/main/webapp/js/pages/ReportingCampaignOverTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ $.when($.getScript("js/global/global.js")).then(function () {
useCurrent: false //Important! See issue #1075
});

$("#frompicker").on("dp.change", function (e) {
$('#topicker').data("DateTimePicker").minDate(e.date);
});
$("#topicker").on("dp.change", function (e) {
$('#frompicker').data("DateTimePicker").maxDate(e.date);
});
// $("#frompicker").on("dp.change", function (e) {
// $('#topicker').data("DateTimePicker").minDate(e.date);
// });
// $("#topicker").on("dp.change", function (e) {
// $('#frompicker').data("DateTimePicker").maxDate(e.date);
// });


var campaigns = GetURLParameters("campaigns");
Expand Down Expand Up @@ -300,53 +300,6 @@ function updateNbDistinct(data) {
}
}

function setTimeRange(id) {
let fromD = new Date();
fromD.setHours(23);
fromD.setMinutes(59);

let toD = new Date();
toD.setHours(23);
toD.setMinutes(59);

// fromD ;
if (id === 1) { // Previous Month
fromD.setMonth(fromD.getMonth() - 1);
} else if (id === 2) { // Previous 3 Months
fromD.setMonth(fromD.getMonth() - 3);
} else if (id === 3) { // Previous 6 Months
fromD.setMonth(fromD.getMonth() - 6);
} else if (id === 4) { // Previous Year
fromD.setMonth(fromD.getMonth() - 12);
} else if (id === 5) { // Previous Week
fromD.setHours(fromD.getHours() - 168);
} else if (id === 6) { // Current Day
fromD.setHours(fromD.getHours() - 24);
} else if (id === 7) { // This Month
fromD.setDate(1);
} else if (id === 8) { // Last Calendar Month
fromD.setMonth(fromD.getMonth() - 1);
fromD.setDate(1);
// toD.setMonth(toD.getMonth() + 1);
// console.info(toD.toLocaleString());
toD.setDate(0);
// console.info(toD.toLocaleString());
} else if (id === 9) { // Previous Calendar Month
fromD.setMonth(fromD.getMonth() - 2);
fromD.setDate(1);
// console.info(toD.toLocaleString());
toD.setMonth(toD.getMonth() - 1);
console.info(toD.toLocaleString());
toD.setDate(0);
console.info(toD.toLocaleString());
}

$('#frompicker').data("DateTimePicker").date(moment(fromD));
$('#topicker').data("DateTimePicker").date(moment(toD));

// console.info("From : " + fromD.toLocaleString() + " - To : " + toD.toLocaleString());
}

function loadCombos(data) {

var select = $("#countrySelect");
Expand Down
52 changes: 6 additions & 46 deletions source/src/main/webapp/js/pages/ReportingExecutionOverTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ $.when($.getScript("js/global/global.js")).then(function () {
useCurrent: false //Important! See issue #1075
});

$("#frompicker").on("dp.change", function (e) {
$('#topicker').data("DateTimePicker").minDate(e.date);
});
$("#topicker").on("dp.change", function (e) {
$('#frompicker').data("DateTimePicker").maxDate(e.date);
});
// $("#frompicker").on("dp.change", function (e) {
// $('#topicker').data("DateTimePicker").minDate(e.date);
// });
// $("#topicker").on("dp.change", function (e) {
// $('#frompicker').data("DateTimePicker").maxDate(e.date);
// });


var tests = GetURLParameters("tests");
Expand Down Expand Up @@ -337,46 +337,6 @@ function updateNbDistinct(data) {
}
}
}
function setTimeRange(id) {
let fromD = new Date();
fromD.setHours(23);
fromD.setMinutes(59);

let toD = new Date();
toD.setHours(23);
toD.setMinutes(59);

// fromD ;
if (id === 1) { // Previous Month
fromD.setMonth(fromD.getMonth() - 1);
} else if (id === 2) { // Previous 3 Months
fromD.setMonth(fromD.getMonth() - 3);
} else if (id === 3) { // Previous 6 Months
fromD.setMonth(fromD.getMonth() - 6);
} else if (id === 4) { // Previous Year
fromD.setMonth(fromD.getMonth() - 12);
} else if (id === 5) { // Previous Week
fromD.setHours(fromD.getHours() - 168);
} else if (id === 6) { // Current Day
fromD.setHours(fromD.getHours() - 24);
} else if (id === 7) { // This Month
fromD.setDate(1);
} else if (id === 8) { // Last Calendar Month
fromD.setMonth(fromD.getMonth() - 1);
fromD.setDate(1);
toD.setDate(0);
} else if (id === 9) { // Previous Calendar Month
fromD.setMonth(fromD.getMonth() - 2);
fromD.setDate(1);
toD.setMonth(toD.getMonth() - 1);
toD.setDate(0);
}

$('#frompicker').data("DateTimePicker").date(moment(fromD));
$('#topicker').data("DateTimePicker").date(moment(toD));

// console.info("From : " + fromD.toLocaleString() + " - To : " + toD.toLocaleString());
}

function loadCombos(data) {

Expand Down

0 comments on commit ff2002a

Please sign in to comment.