Initial schedules support (only UI)
This commit is contained in:
parent
09c44ccaa7
commit
613590e80d
|
@ -331,8 +331,7 @@ CREATE TABLE IF NOT EXISTS `".$prefix."_users` (
|
|||
`registered` int(10) unsigned NOT NULL,
|
||||
`last_login` int(10) unsigned DEFAULT NULL,
|
||||
`force_logout` mediumint(7) unsigned NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `Id` (`id`),
|
||||
PRIMARY KEY (`id`),,
|
||||
UNIQUE KEY `email` (`email`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE IF NOT EXISTS `".$prefix."_profiles` (
|
||||
|
@ -350,7 +349,6 @@ CREATE TABLE IF NOT EXISTS `".$prefix."_profiles` (
|
|||
`availability_minutes` int(11) NOT NULL DEFAULT 0,
|
||||
`image` varchar(1000) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `Id` (`id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE IF NOT EXISTS `".$prefix."_users_confirmations` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
@ -400,14 +398,12 @@ CREATE TABLE IF NOT EXISTS `".$prefix."_options` (
|
|||
`last_edit` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`user_id` INT NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `Id` (`id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE `".$prefix."_dbversion` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`version` INT NOT NULL,
|
||||
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `Id` (`id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE `".$prefix."_api_keys` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
|
@ -415,15 +411,22 @@ CREATE TABLE `".$prefix."_api_keys` (
|
|||
`user` INT NOT NULL,
|
||||
`permissions` VARCHAR(128) NOT NULL DEFAULT 'ALL',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `Id` (`id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE `".$prefix."_bot_telegram` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`chat_id` VARCHAR(128) NOT NULL,
|
||||
`user` INT NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `Id` (`id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=latin1;
|
||||
CREATE TABLE `".$prefix."_schedules` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`user` INT NOT NULL,
|
||||
`profile_name` VARCHAR(500) NOT NULL DEFAULT 'default',
|
||||
`schedules` VARCHAR(1000) NULL DEFAULT NULL,
|
||||
`last_exec` VARCHAR(5) NULL DEFAULT NULL,
|
||||
`last_update` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
) ENGINE = InnoDB;
|
||||
INSERT INTO `".$prefix."_dbversion` (`version`, `timestamp`) VALUES('1', current_timestamp());"
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
|
|
|
@ -0,0 +1,230 @@
|
|||
<?php
|
||||
require("core.php");
|
||||
init_class(false);
|
||||
$user->requirelogin(false);
|
||||
|
||||
// landscape means horizontal
|
||||
// portrait means vertical
|
||||
$orienation = isset($_POST["orientation"]) ? $_POST["orientation"] : "landscape";
|
||||
echo("<!-- orientation: ".$orienation." !-->");
|
||||
$hours = [
|
||||
"0:00", "0:30",
|
||||
"1:00", "1:30",
|
||||
"2:00", "2:30",
|
||||
"3:00", "3:30",
|
||||
"4:00", "4:30",
|
||||
"5:00", "5:30",
|
||||
"6:00", "6:30",
|
||||
"7:00", "7:30",
|
||||
"8:00", "8:30",
|
||||
"9:00", "9:30",
|
||||
"10:00", "10:30",
|
||||
"11:00", "11:30",
|
||||
"12:00", "12:30",
|
||||
"13:00", "13:30",
|
||||
"14:00", "14:30",
|
||||
"15:00", "15:30",
|
||||
"16:00", "16:30",
|
||||
"17:00", "17:30",
|
||||
"18:00", "18:30",
|
||||
"19:00", "19:30",
|
||||
"20:00", "20:30",
|
||||
"21:00", "21:30",
|
||||
"22:00", "22:30",
|
||||
"23:00", "23:30",
|
||||
];
|
||||
$days = [
|
||||
t("Mon",false),
|
||||
t("Tue",false),
|
||||
t("Wed",false),
|
||||
t("Thu",false),
|
||||
t("Fri",false),
|
||||
t("Sat",false),
|
||||
t("Sun",false)
|
||||
];
|
||||
|
||||
$user_id = $user->auth->getUserId();
|
||||
$result = $database->exec("SELECT * FROM `%PREFIX%_schedules` WHERE `user`={$user_id};", true);
|
||||
if(!empty($result)){
|
||||
$old_schedules_db = json_decode($result[0]["schedules"]);
|
||||
foreach ($old_schedules_db as $schedule) {
|
||||
$old_schedules[$schedule[0]][$schedule[1]] = true;
|
||||
}
|
||||
} else {
|
||||
$old_schedules = [];
|
||||
}
|
||||
?>
|
||||
<style>
|
||||
.hour-cell {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
background-color: #ccc;
|
||||
border: 1px solid #fff;
|
||||
}
|
||||
|
||||
.hour-cell.highlighted {
|
||||
background-color: #999;
|
||||
}
|
||||
<?php
|
||||
if($orienation == "landscape"):
|
||||
?>
|
||||
#scheduler_body td {
|
||||
min-width: 40px;
|
||||
}
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</style>
|
||||
<table cellpadding="0" cellspacing="0" id="scheduler_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td style="background-color: white;"></td>
|
||||
<?php
|
||||
if($orienation == "portrait") {
|
||||
for($i=0;$i<7;$i++){
|
||||
echo "<td id='$i' class='day'>{$days[$i]}</td>";
|
||||
}
|
||||
} else if($orienation == "landscape") {
|
||||
foreach($hours as $hour) {
|
||||
$hour_replaced = str_replace(":", "-", $hour);
|
||||
echo "<td id='{$hour_replaced}' class='hour'>$hour</td>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="scheduler_body">
|
||||
<?php
|
||||
if($orienation == "portrait") {
|
||||
foreach($hours as $hour) {
|
||||
echo "<tr>";
|
||||
$hour_replaced = str_replace(":", "-", $hour);
|
||||
echo "<td id='{$hour_replaced}' class='hour'>$hour</td>";
|
||||
for($i=0;$i<7;$i++){
|
||||
$is_schedule_highlighted = (isset($old_schedules[$i][$hour])) ? "highlighted ": "";
|
||||
echo "<td class='hour-cell day-$i hour-{$hour_replaced} {$is_schedule_highlighted}'></td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
} else if($orienation == "landscape") {
|
||||
for($i=0;$i<7;$i++){
|
||||
echo "<tr>";
|
||||
echo "<td id='$i' class='day'>{$days[$i]}</td>";
|
||||
foreach($hours as $hour) {
|
||||
$is_schedule_highlighted = (isset($old_schedules[$i][$hour])) ? "highlighted ": "";
|
||||
$hour_replaced = str_replace(":", "-", $hour);
|
||||
echo "<td class='hour-cell day-$i hour-{$hour_replaced} {$is_schedule_highlighted}'></td>";
|
||||
}
|
||||
echo "<td style='background-color: white;'></td></tr>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
function init_modal() {
|
||||
<?php if($orienation == "landscape"){ ?>$(".modal-dialog").css("max-width", "99%");<?php } ?>
|
||||
|
||||
var isMouseDown = false;
|
||||
$(document)
|
||||
.mouseup(function () {
|
||||
isMouseDown = false;
|
||||
});
|
||||
|
||||
$(".hour-cell")
|
||||
.mousedown(function () {
|
||||
isMouseDown = true;
|
||||
$(this).toggleClass("highlighted");
|
||||
return false; // prevent text selection
|
||||
})
|
||||
.mouseover(function () {
|
||||
if (isMouseDown) {
|
||||
$(this).toggleClass("highlighted");
|
||||
}
|
||||
});
|
||||
|
||||
function selectDay(id){
|
||||
console.log("day selection " + id);
|
||||
if ($(event.target).hasClass("highlighted_all")) {
|
||||
$("#scheduler_body .day-" + id).toggleClass("highlighted");
|
||||
$(event.target).toggleClass("highlighted_all");
|
||||
} else {
|
||||
$("#scheduler_body .day-" + id).addClass("highlighted");
|
||||
$(event.target).addClass("highlighted_all");
|
||||
}
|
||||
}
|
||||
|
||||
function selectHour(id){
|
||||
console.log("hour selection " + id);
|
||||
if ($(event.target).hasClass("highlighted_all")) {
|
||||
$("#scheduler_body .hour-" + id).toggleClass("highlighted");
|
||||
$(event.target).toggleClass("highlighted_all");
|
||||
} else {
|
||||
$("#scheduler_body .hour-" + id).addClass("highlighted");
|
||||
$(event.target).addClass("highlighted_all");
|
||||
}
|
||||
}
|
||||
|
||||
$(".day")
|
||||
.mousedown(function () {
|
||||
isMouseDown = true;
|
||||
let id = event.target.id;
|
||||
selectDay(id);
|
||||
return false; // prevent text selection
|
||||
})
|
||||
.mouseover(function () {
|
||||
if (isMouseDown) {
|
||||
let id = event.target.id;
|
||||
selectDay(id);
|
||||
}
|
||||
});
|
||||
|
||||
$(".hour")
|
||||
.mousedown(function () {
|
||||
isMouseDown = true;
|
||||
let id = event.target.id.replace(":", "-");
|
||||
selectHour(id);
|
||||
return false; // prevent text selection
|
||||
})
|
||||
.mouseover(function () {
|
||||
if (isMouseDown) {
|
||||
let id = event.target.id.replace(":", "-");
|
||||
selectHour(id);
|
||||
}
|
||||
});
|
||||
|
||||
$("#submit_schedules_change")
|
||||
.unbind()
|
||||
.click(submit_changes);
|
||||
}
|
||||
|
||||
function extractSelections(){
|
||||
hours_list = [];
|
||||
$("#scheduler_body td.highlighted").each((key, value) => {
|
||||
let day = value.classList[1].replace("day-","");
|
||||
let hour = value.classList[2].replace("hour-","").replace("-",":");
|
||||
console.log(day,hour,value);
|
||||
hours_list.push([day,hour]);
|
||||
});
|
||||
return hours_list;
|
||||
}
|
||||
|
||||
function submit_changes(){
|
||||
let hours = extractSelections();
|
||||
$.ajax({
|
||||
url: "resources/ajax/ajax_availability_schedule.php",
|
||||
method: "POST",
|
||||
data: {
|
||||
hours: hours
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
toastr.success('<?php t('Schedules updated successfully'); ?>');
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
include_once '../../core.php';
|
||||
init_class(false);
|
||||
$user->requirelogin(false);
|
||||
|
||||
$user_id = $user->auth->getUserId();
|
||||
$result = $database->exec("SELECT * FROM `%PREFIX%_schedules` WHERE `user`={$user_id};", true);
|
||||
if(!empty($result)){
|
||||
$result[0]["schedules"] = json_decode($result[0]["schedules"]);
|
||||
}
|
||||
|
||||
if(isset($_POST["hours"])){
|
||||
$hours = (string) json_encode($_POST["hours"]);
|
||||
echo($hours);
|
||||
if(!empty($result)){
|
||||
$database->exec("UPDATE `%PREFIX%_schedules` SET `schedules` = :schedules WHERE `id` = :id;", false, [":id" => $result[0]["id"], ":schedules" => $hours]);
|
||||
} else {
|
||||
$database->exec("INSERT INTO `%PREFIX%_schedules` (`user`, `schedules`) VALUES (:user, :schedules);", false, [":user" => $user_id, ":schedules" => $hours]);
|
||||
}
|
||||
} else {
|
||||
echo(json_encode(empty($result) ? [] : $result[0]));
|
||||
}
|
|
@ -3,6 +3,32 @@ body:not(table) {
|
|||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
@keyframes gradual_blur {
|
||||
0% {-webkit-filter: blur(0px);}
|
||||
50% {-webkit-filter: blur(2px);}
|
||||
100% {-webkit-filter: blur(5px);}
|
||||
}
|
||||
|
||||
.loading_blur {
|
||||
animation: gradual_blur 1s;
|
||||
animation-fill-mode: forwards;
|
||||
cursor: wait;
|
||||
}
|
||||
|
||||
.loading_no_blur {
|
||||
animation: gradual_blur 1s;
|
||||
animation-direction: reverse;
|
||||
animation-fill-mode: forwards;
|
||||
}
|
||||
|
||||
.loading_overlay {
|
||||
position: absolute;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
center {
|
||||
text-align: center;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,26 @@ toastr.options = {
|
|||
"hideMethod": "fadeOut"
|
||||
}
|
||||
|
||||
$.fn.loading = function(action="start", options) {
|
||||
var opts = $.extend( {}, $.fn.loading.defaults, options );
|
||||
|
||||
if(action == "show") {
|
||||
this.addClass("loading_blur");
|
||||
$( "body" ).append( "<div id='loading_div' class='loading_overlay'><p class=''><b>"+opts.message+"</b></p></div>" );
|
||||
} else if(action == "hide") {
|
||||
this.removeClass("loading_blur");
|
||||
this.addClass("loading_no_blur");
|
||||
setTimeout(() => {
|
||||
this.removeClass("loading_no_blur");
|
||||
}, 1000);
|
||||
$( "#loading_div" ).remove();
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.loading.defaults = {
|
||||
message: "Loading..."
|
||||
};
|
||||
|
||||
console.log("Commit: "+process.env.GIT_VERSION);
|
||||
console.log("Date: "+process.env.GIT_AUTHOR_DATE);
|
||||
console.log("Bundle mode: "+process.env.BUNDLE_MODE);
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
</script>
|
||||
{% endif %}
|
||||
<script src="{{ urlsoftware }}/resources/dist/{{ resource('main.js') }}"></script>
|
||||
<script>$.fn.loading.defaults.message = "{{ 'Loading...'|t }}";</script>
|
||||
{% if enable_technical_support and technical_support_open %}
|
||||
<!-- Smartsupp Live Chat script -->
|
||||
<script type='text/javascript'>
|
||||
|
|
|
@ -2,11 +2,47 @@
|
|||
|
||||
{% block content %}
|
||||
<br>
|
||||
<div>
|
||||
<div id="schedulesModal" class="modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document" style="overflow-x: auto;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">{{ 'Edit availability schedules'|t }}</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="{{ 'Close'|t }}">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body" style="overflow-x: auto;">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="submit_schedules_change" type="button" class="btn btn-primary">{{ 'Save changes'|t }}</button>
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{ 'Close'|t }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$('#schedulesModal').on('show.bs.modal', function (event) {
|
||||
//$( ".modal-body" ).loading("show");
|
||||
$(".modal-body").load("modal_availability_schedule.php", {
|
||||
orientation: window.innerHeight > window.innerWidth ? "portrait" : "landscape"
|
||||
}, function() {
|
||||
init_modal();
|
||||
//$( ".modal-body" ).loading("hide");
|
||||
return true;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<p>{{ 'Are you available in case of alert?'|t }}</p>
|
||||
<button class="btn btn-lg btn-success " onclick="activate('{{ user.id }}')">{{ 'Activate'|t }}</button>
|
||||
<button class="btn btn-lg btn-success" onclick="activate('{{ user.id }}')">{{ 'Activate'|t }}</button>
|
||||
<button class="btn btn-lg btn-danger" style="background-color: red"
|
||||
onclick="deactivate('{{ user.id }}')">{{ 'Deactivate'|t }}</button>
|
||||
<br>
|
||||
<button type="button" class="btn btn-lg" data-toggle="modal" data-target="#schedulesModal">
|
||||
{{ 'Edit availability schedules'|t }}
|
||||
</button>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
|
|
|
@ -101,5 +101,17 @@ return [
|
|||
"Training removed" => "Training removed",
|
||||
"User added" => "User added",
|
||||
"User edited" => "User edited",
|
||||
"User removed" => "User removed"
|
||||
"User removed" => "User removed",
|
||||
"Loading..." => "Loading...",
|
||||
"Schedules updated successfully" => "Schedules updated successfully",
|
||||
"Edit availability schedules" => "Edit availability schedules",
|
||||
"Save changes" => "Save changes",
|
||||
"Close" => "Close",
|
||||
"Mon" => "Mon",
|
||||
"Tue" => "Tue",
|
||||
"Wed" => "Wed",
|
||||
"Thu" => "Thu",
|
||||
"Fri" => "Fri",
|
||||
"Sat" => "Sat",
|
||||
"Sun" => "Sun"
|
||||
];
|
||||
|
|
|
@ -101,5 +101,17 @@ return [
|
|||
"Training removed" => "Esercitazione rimossa",
|
||||
"User added" => "Utente aggiunto",
|
||||
"User edited" => "Utente modificato",
|
||||
"User removed" => "Utente rimosso"
|
||||
"User removed" => "Utente rimosso",
|
||||
"Loading..." => "Caricamento...",
|
||||
"Schedules updated successfully" => "Orari aggiornati con successo",
|
||||
"Edit availability schedules" => "Modifica orari disponibilità",
|
||||
"Save changes" => "Salva le modifiche",
|
||||
"Close" => "Chiudi",
|
||||
"Mon" => "Lun",
|
||||
"Tue" => "Mar",
|
||||
"Wed" => "Mer",
|
||||
"Thu" => "Gio",
|
||||
"Fri" => "Ven",
|
||||
"Sat" => "Sab",
|
||||
"Sun" => "Dom"
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue