SAAS-870: Schedule widget displays shows in wrong timezone
Timezone conversion done in frontend
This commit is contained in:
parent
0a4651f752
commit
6db75550cc
5 changed files with 84 additions and 128 deletions
|
@ -25,13 +25,41 @@
|
|||
});
|
||||
});
|
||||
|
||||
String.prototype.paddingLeft = function(paddingValue) {
|
||||
return String(paddingValue + this).slice(-paddingValue.length);
|
||||
};
|
||||
|
||||
var schedule_data = <?php echo $this->schedule_data; ?>;
|
||||
console.log(schedule_data);
|
||||
|
||||
var app = angular.module('scheduleWidget', []);
|
||||
app.controller('scheduleController', ['$scope', '$window', function($scope, $window) {
|
||||
$scope.schedule_data = $window.schedule_data["scheduleData"];
|
||||
|
||||
// Loop through every show and assign it to the corresponding day of the week's
|
||||
// show array.
|
||||
angular.forEach($window.schedule_data["shows"], function(value, key) {
|
||||
|
||||
// First we have to create a Date object out of the show time in UTC.
|
||||
// Then we can format the string in the client's local timezone.
|
||||
var start_date = new Date(value.starts + " UTC");
|
||||
var end_date = new Date(value.ends + " UTC");
|
||||
|
||||
// This variable is used to identify which schedule_data object (which day of the week)
|
||||
// we should assign the show to.
|
||||
// NOTE: we have to add 1 to the month because javascript's Date.getMonth()
|
||||
// function returns the month number starting with an index of 0. In PHP,
|
||||
// the months are indexed starting at 1.
|
||||
var format_start_date = start_date.getFullYear() + "-" + (start_date.getMonth()+1) + "-" + start_date.getDate();
|
||||
|
||||
if ($window.schedule_data["weekDays"][format_start_date] !== undefined) {
|
||||
$window.schedule_data["weekDays"][format_start_date]["shows"].push(
|
||||
{
|
||||
"show_start_hour": start_date.getHours().toString().paddingLeft("00")+":"+ start_date.getMinutes().toString().paddingLeft("00"),
|
||||
"show_end_hour": end_date.getHours().toString().paddingLeft("00")+":"+ end_date.getMinutes().toString().paddingLeft("00"),
|
||||
"name": value.name
|
||||
});
|
||||
}
|
||||
});
|
||||
$scope.weekDays = $window.schedule_data["weekDays"];
|
||||
|
||||
$scope.isEmpty = function(obj) {
|
||||
return obj.length == 0;
|
||||
|
@ -43,13 +71,13 @@
|
|||
<body ng-app="scheduleWidget" ng-controller="scheduleController">
|
||||
<div class="schedule tab_content current">
|
||||
<ul class="tabs">
|
||||
<li ng-repeat="x in schedule_data track by $index">
|
||||
<li ng-repeat="x in weekDays track by $index">
|
||||
{{x.dayOfWeek}}<span>{{x.dayOfMonth}}</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="schedule_content">
|
||||
<div ng-repeat="x in schedule_data track by $index" ng-attr-id="{{'day-' + x.dayOfMonth}}" class="schedule_item">
|
||||
<div ng-repeat="x in weekDays track by $index" ng-attr-id="{{'day-' + x.dayOfMonth}}" class="schedule_item">
|
||||
<div ng-if="isEmpty(x.shows)" class="row empty-schedule">Looks like there are no shows scheduled on this day.</div>
|
||||
<div ng-repeat="show in x.shows" class="row">
|
||||
<div class="time_grid">{{show.show_start_hour}} - {{show.show_end_hour}}</div>
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="<?php echo $this->css?>" type="text/css">
|
||||
<script src="<?php echo $this->jquery ?>" type="text/javascript"></script>
|
||||
<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,700' rel='stylesheet' type='text/css'>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('.tabs li').click(function(){
|
||||
var tab_id = $(this).attr('data-tab');
|
||||
|
||||
$('.tabs li').removeClass('active');
|
||||
$('.schedule_item').removeClass('active');
|
||||
|
||||
$(this).addClass('active');
|
||||
$("#"+tab_id).addClass('active');
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="schedule tab_content current">
|
||||
<ul class="tabs">
|
||||
<?php
|
||||
foreach($this->weeklyScheduleData as $day => $data) {
|
||||
$activeClass = $this->currentDayOfMonth == $data["dayOfMonth"] ? "active" : "";
|
||||
echo "<li class='".$activeClass."' data-tab='day-".$data["dayOfMonth"]."'>" . $data["dayOfWeek"] . "<span>" . $data["dayOfMonth"] . "</span></li>";
|
||||
}?>
|
||||
</ul>
|
||||
|
||||
<div class="schedule_content">
|
||||
<?php
|
||||
foreach($this->weeklyScheduleData as $day => $data) {
|
||||
$activeClass = $this->currentDayOfMonth == $data["dayOfMonth"] ? "active" : "";
|
||||
|
||||
echo "<div id='day-".$data["dayOfMonth"]."' class='schedule_item ".$activeClass."'>";
|
||||
if (count($data["shows"]) == 0) {
|
||||
echo "<div class='row empty-schedule'>Looks like there are no shows scheduled on this day.</div>";
|
||||
} else {
|
||||
foreach ($data["shows"] as $show => $showData) {
|
||||
echo "<div class='row'>";
|
||||
echo "<div class='time_grid'>" . $showData["show_start_hour"] . ' - ' . $showData["show_end_hour"] . "</div>";
|
||||
echo "<div class='name_grid'>" . $showData["name"] . "</div>";
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
echo "</div>";
|
||||
}?>
|
||||
</div>
|
||||
|
||||
<div class="weekly-schedule-widget-footer" <?php if ($this->widgetStyle == "premium") echo "style='display:none'"; ?>>
|
||||
<a href="https://airtime.pro" target="_blank">Powered by <span>Airtime Pro</span></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue