Skip to content

Commit

Permalink
Schedule meta and various fixes (#1942)
Browse files Browse the repository at this point in the history
* Schedule Grid : Fix start and end time representation in the table for events with user created dayparts
* Schedule : Fix Display select group issue on add and edit event forms
* Members form : Fix saving cog icon stuck on the save button on error
* Schedule : add meta data and name.
* Schedule : Fix condition in grouping results for Display select.
* Schedule : Remove standalone schedule grid page, as it is no longer in use.
* Schedule : modifiedBy should be userId.
  • Loading branch information
PeterMis authored Jul 26, 2023
1 parent bb53ec9 commit 9a4f68a
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 395 deletions.
44 changes: 44 additions & 0 deletions db/migrations/20230725141000_schedule_meta_data_migration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/

use Phinx\Migration\AbstractMigration;

/**
* Add meta data fields to schedule table
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
class ScheduleMetaDataMigration extends AbstractMigration
{
public function change(): void
{
$this->table('schedule')
->addColumn('modifiedBy', 'integer', [
'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_REGULAR,
'null' => true,
'default' => null
])
->addColumn('createdOn', 'datetime', ['null' => true, 'default' => null])
->addColumn('updatedOn', 'datetime', ['null' => true, 'default' => null])
->addColumn('name', 'string', ['limit' => 50, 'null' => true])
->save();
}
}
10 changes: 10 additions & 0 deletions lib/Controller/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ public function add(Request $request, Response $response)
$schedule->actionLayoutCode = $sanitizedParams->getString('actionLayoutCode');
$schedule->maxPlaysPerHour = $sanitizedParams->getInt('maxPlaysPerHour', ['default' => 0]);
$schedule->syncGroupId = $sanitizedParams->getInt('syncGroupId');
$schedule->name = $sanitizedParams->getString('name');

// Set the parentCampaignId for campaign events
if ($schedule->eventTypeId === \Xibo\Entity\Schedule::$CAMPAIGN_EVENT) {
Expand Down Expand Up @@ -1696,6 +1697,8 @@ public function edit(Request $request, Response $response, $id)
$schedule->actionTriggerCode = $sanitizedParams->getString('actionTriggerCode');
$schedule->actionLayoutCode = $sanitizedParams->getString('actionLayoutCode');
$schedule->maxPlaysPerHour = $sanitizedParams->getInt('maxPlaysPerHour', ['default' => 0]);
$schedule->name = $sanitizedParams->getString('name');
$schedule->modifiedBy = $this->getUser()->getId();

// Set the parentCampaignId for campaign events
if ($schedule->eventTypeId === \Xibo\Entity\Schedule::$CAMPAIGN_EVENT) {
Expand Down Expand Up @@ -2237,6 +2240,13 @@ public function grid(Request $request, Response $response)
$event->setUnmatchedProperty('recurringEventDescription', '');
}

if (!$event->isAlwaysDayPart() && !$event->isCustomDayPart()) {
$dayPart = $this->dayPartFactory->getById($event->dayPartId);
$dayPart->adjustForDate(Carbon::createFromTimestamp($event->fromDt));
$event->fromDt = $dayPart->adjustedStart->format('U');
$event->toDt = $dayPart->adjustedEnd->format('U');
}

if ($this->isApi($request)) {
continue;
}
Expand Down
49 changes: 46 additions & 3 deletions lib/Entity/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,31 @@ class Schedule implements \JsonSerializable
*/
public $syncGroupId;

/**
* @SWG\Property(description="The userId of the user that last modified this Schedule")
* @var int
*/
public $modifiedBy;
public $modifiedByName;

/**
* @SWG\Property(description="The Date this Schedule was created on")
* @var string
*/
public $createdOn;

/**
* @SWG\Property(description="The Date this Schedule was las updated on")
* @var string
*/
public $updatedOn;

/**
* @SWG\Property(description="The name of this Scheduled Event")
* @var string
*/
public $name;

/**
* @var ScheduleEvent[]
*/
Expand Down Expand Up @@ -854,7 +879,11 @@ private function add()
`actionLayoutCode`,
`maxPlaysPerHour`,
`parentCampaignId`,
`syncGroupId`
`syncGroupId`,
`modifiedBy`,
`createdOn`,
`updatedOn`,
`name`
)
VALUES (
:eventTypeId,
Expand All @@ -881,7 +910,11 @@ private function add()
:actionLayoutCode,
:maxPlaysPerHour,
:parentCampaignId,
:syncGroupId
:syncGroupId,
:modifiedBy,
:createdOn,
:updatedOn,
:name
)
', [
'eventTypeId' => $this->eventTypeId,
Expand Down Expand Up @@ -911,6 +944,10 @@ private function add()
'maxPlaysPerHour' => $this->maxPlaysPerHour,
'parentCampaignId' => $this->parentCampaignId == 0 ? null : $this->parentCampaignId,
'syncGroupId' => $this->syncGroupId == 0 ? null : $this->syncGroupId,
'modifiedBy' => null,
'createdOn' => Carbon::now()->format(DateFormatHelper::getSystemFormat()),
'updatedOn' => null,
'name' => !empty($this->name) ? $this->name : null
]);
}

Expand Down Expand Up @@ -945,7 +982,10 @@ private function edit()
`actionLayoutCode` = :actionLayoutCode,
`maxPlaysPerHour` = :maxPlaysPerHour,
`parentCampaignId` = :parentCampaignId,
`syncGroupId` = :syncGroupId
`syncGroupId` = :syncGroupId,
`modifiedBy` = :modifiedBy,
`updatedOn` = :updatedOn,
`name` = :name
WHERE eventId = :eventId
', [
'eventTypeId' => $this->eventTypeId,
Expand Down Expand Up @@ -973,6 +1013,9 @@ private function edit()
'maxPlaysPerHour' => $this->maxPlaysPerHour,
'parentCampaignId' => $this->parentCampaignId == 0 ? null : $this->parentCampaignId,
'syncGroupId' => $this->syncGroupId == 0 ? null : $this->syncGroupId,
'modifiedBy' => $this->modifiedBy,
'updatedOn' => Carbon::now()->format(DateFormatHelper::getSystemFormat()),
'name' => $this->name,
'eventId' => $this->eventId,
]);
}
Expand Down
10 changes: 9 additions & 1 deletion lib/Factory/ScheduleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,12 @@ public function query($sortOrder = null, $filterBy = [])
`schedule`.syncGroupId,
`daypart`.isAlways,
`daypart`.isCustom,
`syncgroup`.name AS syncGroupName
`syncgroup`.name AS syncGroupName,
`schedule`.modifiedBy,
`user`.userName as modifiedByName,
`schedule`.createdOn,
`schedule`.updatedOn,
`schedule`.name
';

$body = ' FROM `schedule`
Expand All @@ -399,6 +404,8 @@ public function query($sortOrder = null, $filterBy = [])
ON `command`.commandId = `schedule`.commandId
LEFT OUTER JOIN `syncgroup`
ON `syncgroup`.syncGroupId = `schedule`.syncGroupId
LEFT OUTER JOIN `user`
ON `user`.userId = `schedule`.modifiedBy
WHERE 1 = 1';

if ($parsedFilter->getInt('eventId') !== null) {
Expand Down Expand Up @@ -578,6 +585,7 @@ public function query($sortOrder = null, $filterBy = [])
'recurrenceMonthlyRepeatsOn',
'isGeoAware',
'maxPlaysPerHour',
'modifiedBy'
]
]);
}
Expand Down
55 changes: 28 additions & 27 deletions ui/src/core/xibo-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1477,32 +1477,32 @@ var setupSelectForSchedule = function (dialog) {
$campaignSelect.select2({
dropdownParent: $(dialog),
ajax: {
url: $campaignSelect.data("searchUrl"),
dataType: "json",
url: $campaignSelect.data('searchUrl'),
dataType: 'json',
data: function(params) {
var query = {
isLayoutSpecific: $campaignSelect.data("searchIsLayoutSpecific"),
isLayoutSpecific: $campaignSelect.data('searchIsLayoutSpecific'),
retired: 0,
totalDuration: 0,
name: params.term,
start: 0,
length: 10,
columns: [
{
"data": "isLayoutSpecific"
data: 'isLayoutSpecific'
},
{
"data": "campaign"
data: 'campaign'
}
],
order: [
{
"column": 0,
"dir": "asc"
column: 0,
dir: 'asc'
},
{
"column": 1,
"dir": "asc"
column: 1,
dir: 'asc'
}
]
};
Expand All @@ -1519,8 +1519,8 @@ var setupSelectForSchedule = function (dialog) {

$.each(data.data, function(index, el) {
results.push({
"id": el["campaignId"],
"text": el["campaign"]
id: el['campaignId'],
text: el['campaign']
});
});

Expand All @@ -1540,8 +1540,9 @@ var setupSelectForSchedule = function (dialog) {
var $displaySelect = $('select[name="displayGroupIds[]"]', dialog);
$displaySelect.select2({
ajax: {
url: $displaySelect.data("searchUrl"),
dataType: "json",
url: $displaySelect.data('searchUrl'),
dataType: 'json',
dropdownParent: $(dialog),
data: function(params) {
var query = {
isDisplaySpecific: -1,
Expand All @@ -1551,20 +1552,20 @@ var setupSelectForSchedule = function (dialog) {
length: 10,
columns: [
{
"data": "isDisplaySpecific"
data: 'isDisplaySpecific'
},
{
"data": "displayGroup"
data: 'displayGroup'
}
],
order: [
{
"column": 0,
"dir": "asc"
column: 0,
dir: 'asc'
},
{
"column": 1,
"dir": "asc"
column: 1,
dir: 'asc'
}
]
};
Expand All @@ -1583,13 +1584,13 @@ var setupSelectForSchedule = function (dialog) {
$.each(data.data, function(index, element) {
if (element.isDisplaySpecific === 1) {
displays.push({
"id": element.displayGroupId,
"text": element.displayGroup
id: element.displayGroupId,
text: element.displayGroup
});
} else {
groups.push({
"id": element.displayGroupId,
"text": element.displayGroup
id: element.displayGroupId,
text: element.displayGroup
});
}
});
Expand All @@ -1600,11 +1601,11 @@ var setupSelectForSchedule = function (dialog) {
return {
results: [
{
"text": $displaySelect.data('transGroups'),
"children": groups
text: groups.length > 0 ? $displaySelect.data('transGroups') : null,
children: groups
},{
"text": $displaySelect.data('transDisplay'),
"children": displays
text: displays.length > 0 ? $displaySelect.data('transDisplay') : null,
children: displays
}
],
pagination: {
Expand Down
7 changes: 5 additions & 2 deletions ui/src/core/xibo-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,20 +806,23 @@ function membersFormSubmit(id) {
LoginBox(response.message);
} else {
// Likely just an error that we want to report on
form.find('.saving').remove();
// Remove the saving cog
form.closest('.modal-dialog').find('.saving').remove();
SystemMessageInline(response.message, form.closest('.modal'));
}
}
},
error: function(responseText) {
// Remove the saving cog
form.closest('.modal-dialog').find('.saving').remove();
SystemMessage(responseText, false);
},
});
},
// When the queue completes naturally, execute this function.
complete: function() {
// Remove the save button
form.find('.saving').parent().remove();
form.closest('.modal-dialog').find('.saving').parent().remove();

// Refresh the grids
// (this is a global refresh)
Expand Down
4 changes: 4 additions & 0 deletions views/schedule-form-add.twig
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
data-playlist-get-url="{{ url_for("playlist.search") }}?fullScreenScheduleCheck=true">
<div class="tab-content">
<div class="tab-pane active" id="general">
{% set title %}{% trans "Name" %}{% endset %}
{% set helpText %}{% trans "Optional Name for this Event (1-50 characters)" %}{% endset %}
{{ forms.input("name", title, "", helpText) }}

{% if isScheduleNow %}
{{ forms.hidden("eventTypeId", eventTypeId) }}
{% else %}
Expand Down
4 changes: 4 additions & 0 deletions views/schedule-form-edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
data-playlist-get-url="{{ url_for("playlist.search") }}?fullScreenScheduleCheck=true">
<div class="tab-content">
<div class="tab-pane active" id="general">
{% set title %}{% trans "Name" %}{% endset %}
{% set helpText %}{% trans "Optional Name for this Event (1-50 characters)" %}{% endset %}
{{ forms.input("name", title, event.name, helpText) }}

{% set title %}{% trans "Event Type" %}{% endset %}
{% set helpText %}{% trans "Select the type of event to schedule" %}{% endset %}
{{ forms.dropdown("eventTypeId", "single", title, event.eventTypeId, eventTypes, "eventTypeId", "eventTypeName", helpText) }}
Expand Down
4 changes: 4 additions & 0 deletions views/schedule-form-sync-add.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<div class="tab-pane active" id="general">
{{ forms.hidden("eventTypeId", eventTypeId) }}

{% set title %}{% trans "Name" %}{% endset %}
{% set helpText %}{% trans "Optional Name for this Event (1-50 characters)" %}{% endset %}
{{ forms.input("name", title, "", helpText) }}

{% set title %}{% trans "Sync Group" %}{% endset %}
{% set helpText %}{% trans "Please select existing Sync Group" %}{% endset %}
{% set attributes = [
Expand Down
4 changes: 4 additions & 0 deletions views/schedule-form-sync-edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<div class="tab-pane active" id="general">
{{ forms.hidden("eventTypeId", eventTypeId) }}

{% set title %}{% trans "Name" %}{% endset %}
{% set helpText %}{% trans "Optional Name for this Event (1-50 characters)" %}{% endset %}
{{ forms.input("name", title, event.name, helpText) }}

{% set title %}{% trans "Sync Group" %}{% endset %}
{% set helpText %}{% trans "Please select existing Sync Group" %}{% endset %}
{% set attributes = [
Expand Down
Loading

0 comments on commit 9a4f68a

Please sign in to comment.