Skip to content

Commit

Permalink
Fix screen-bundle integration (#3)
Browse files Browse the repository at this point in the history
* Changed campaign icon
* Added support for screen-bundle
  • Loading branch information
tuj authored May 20, 2019
1 parent 86820fd commit 65e952a
Show file tree
Hide file tree
Showing 12 changed files with 4,556 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# os2display/campaign-bundle

## 2.1.0

* Added support for screen-bundle.
* Fixed gulp setup.
* Changed campaign icon.
* Fixed translation.

## 2.0.0

* Symfony 3.4 upgrade.
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
- { name: kernel.event_listener, event: os2display.core.pre_push_channels, method: prePushChannels }
- { name: kernel.event_listener, event: os2display.core.pre_push_channel, method: prePushChannel }
- { name: kernel.event_listener, event: os2display.core.post_push_channels, method: postPushChannels }
- { name: kernel.event_listener, event: os2display.core.pre_push_screen_serialization, method: prePushScreenSerialization }

os2display.campaign_manager:
class: Os2Display\CampaignBundle\Service\CampaignManager
Expand Down
8 changes: 3 additions & 5 deletions Resources/public/apps/campaignApp/campaignApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ angular.module('campaignApp').service('campaignAppSetup', [
if (apiData && apiData.active_campaigns && apiData.active_campaigns.length > 0) {
var message = '<p>' + $translate.instant('messages.active_campaign_exists') + '</p>';

var iconSource = 'bundles/os2displayadmin/images/icons/exclamation-icon.png';
var iconSource = 'bundles/os2displaycampaign/assets/icons/campaign.png';

var html =
'<div class="campaign-info">' +
' <div tooltips tooltip-template="' + message + '" tooltip-side="top">' +
' <img class="campaign-info--icon" src="' + iconSource + '" title="">' +
' </div>' +
'<div class="campaign-info--icon-wrapper" tooltips tooltip-template="' + message + '" tooltip-side="top">' +
' <img class="campaign-info--icon" src="' + iconSource + '" title="">' +
'</div>';

busService.$emit(data.returnEvent, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"help": {
"title": "Hjælp til kampagner",
"description": "Med kampagner har du mulighed for helt at overtage en eller flere skærme, som i forvejen et opsat til at vise indholde fra kanaler. Således vil alt andet indhold end den givne kampagne være skjult i hele kampagne perioenden. Efter kampagne perionden vil skærmene vende tilbage til det opringeligt planlagte indhold.",
"description": "Med kampagner har du mulighed for helt at overtage en eller flere skærme, som i forvejen er opsat til at vise indhold fra kanaler. Således vil alt andet indhold end den givne kampagne være skjult i hele kampagnens løbetid. Efter kampagnen er udløbet vil skærmene vende tilbage til det oprindeligt planlagte indhold.",
"close": "Luk vinduet"
},
"filter_placeholder": "Filtrér",
Expand Down
2 changes: 1 addition & 1 deletion Resources/public/assets/build/os2displaycampaign.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/assets/build/os2displaycampaign.min.js

Large diffs are not rendered by default.

Binary file added Resources/public/assets/icons/campaign.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Resources/sass/_campaign-info.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
height: 20px;
}

&--icon-wrapper {
margin-bottom: 5px;
}

&--message {
max-width: 800px;
}
Expand Down
78 changes: 78 additions & 0 deletions Service/CampaignService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Os2Display\CampaignBundle\Service;

use Os2Display\CampaignBundle\Entity\Campaign;
use Os2Display\CoreBundle\Entity\Screen;
use Os2Display\CoreBundle\Events\PostPushChannelsEvent;
use Os2Display\CoreBundle\Events\PrePushChannelEvent;
use Os2Display\CoreBundle\Events\PrePushChannelsEvent;
use Os2Display\CoreBundle\Events\PrePushScreenSerializationEvent;
use Symfony\Component\DependencyInjection\Container;

/**
Expand Down Expand Up @@ -42,6 +44,7 @@ public static function getSubscribedEvents()
PrePushChannelsEvent::EVENT_PRE_PUSH_CHANNELS => 'prePushChannels',
PrePushChannelEvent::EVENT_PRE_PUSH_CHANNEL => 'prePushChannel',
PostPushChannelsEvent::EVENT_POST_PUSH_CHANNELS => 'postPushChannels',
PrePushScreenSerializationEvent::NAME => 'prePushScreenSerialization'
];
}

Expand All @@ -51,6 +54,7 @@ public static function getSubscribedEvents()
* Calculate campaign changes.
*
* @param \Os2Display\CoreBundle\Events\PrePushChannelsEvent $event
* @throws \Exception
*/
public function prePushChannels(PrePushChannelsEvent $event)
{
Expand Down Expand Up @@ -274,4 +278,78 @@ private function calculateCampaignChanges()

return $results;
}

/**
* Modify which channels should be shown for screen.
*
* @param \Os2Display\CoreBundle\Events\PrePushScreenSerializationEvent $event
*/
public function prePushScreenSerialization(PrePushScreenSerializationEvent $event)
{
$screenObject = $event->getScreenObject();

$screen = $this->doctrine->getRepository(Screen::class)->findOneById($screenObject->screen->id);

$now = new \DateTime();

$queryBuilder = $this->doctrine->getManager()->createQueryBuilder();

$campaigns = $queryBuilder->select('campaign')
->from(Campaign::class, 'campaign')
->where(
':now between campaign.scheduleFrom and campaign.scheduleTo'
)
->andWhere($queryBuilder->expr()->orX(
':screen member of campaign.screens',
':groups member of campaign.screenGroups'
))
->setParameter('screen', $screen)
->setParameter('groups', $screen->getGroups())
->setParameter('now', $now)
->getQuery()->getResult();

// If the screen is not affected by a campaign return.
if (count($campaigns) == 0) {
return;
}

// If the screen is affected by campaigns, remove the channels from
// region 1.
foreach ($screenObject->channels as $id => $channel) {
$regions = [];
foreach ($channel->regions as $region) {
if ($region != 1) {
$region[] = $region;
}
}

$channel->regions = $regions;
}

// Only add channels that apply to a region.
$channels = [];
foreach ($screenObject->channels as $key => $channel) {
if (!empty($channel->regions)) {
$channels[$key] = $channel;
}
}

// Add campaign channels to screen object.
foreach ($campaigns as $campaign) {
$campaignChannels = $campaign->getChannels();
foreach ($campaignChannels as $channel) {
if (!isset($channels[$channel->getId()])) {
$channels[$channel->getId()] = (object)[
'regions' => [1],
'added_by_campaign' => true,
];
}
}
}

$screenObject->channels = $channels;

// Set event variable.
$event->setScreenObject($screenObject);
}
}
14 changes: 8 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var gulp = require('gulp-help')(require('gulp'));
var gulp = require('gulp');

// Plugins.
var jshint = require('gulp-jshint');
Expand Down Expand Up @@ -29,13 +29,13 @@ var banner = [
/**
* Process SCSS using libsass
*/
gulp.task('sass', 'Compile the sass .', function () {
gulp.task('sass', function () {
'use strict';

var adminBuildDir = 'Resources/public/assets/build';
var sassPath = 'Resources/sass/*.scss';

gulp.src(sassPath)
return gulp.src(sassPath)
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
Expand Down Expand Up @@ -79,7 +79,7 @@ var adminJsPath = (function () {
/**
* Run Javascript through JSHint.
*/
gulp.task('jshint', 'Runs JSHint on js', function () {
gulp.task('jshint', function () {
return gulp.src(adminJsPath)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
Expand All @@ -88,7 +88,7 @@ gulp.task('jshint', 'Runs JSHint on js', function () {
/**
* Build single app.js file.
*/
gulp.task('js', 'Build all custom js files into one minified js file.', function () {
gulp.task('js', function () {
return gulp.src(adminJsPath)
.pipe(concat('os2displaycampaign.js'))
.pipe(ngAnnotate())
Expand All @@ -102,10 +102,12 @@ gulp.task('js', 'Build all custom js files into one minified js file.', function
/**
* Build single app.js file.
*/
gulp.task('js-src', 'Report all source files for "js" task.', function () {
gulp.task('js-src', function (done) {
adminJsPath.forEach(function (path) {
process.stdout.write(path + '\n');
});

done();
});

/**
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
"description": "",
"version": "1.0.0",
"private": true,
"dependencies": {
"gulp": "^3.9.1",
"dependencies": {},
"devDependencies": {
"bootstrap": "^4.1.1",
"gulp": "^4.0.2",
"gulp-concat": "^2.6.1",
"gulp-header": "^2.0.5",
"gulp-help": "^1.6.1",
"gulp-header": "^2.0.7",
"gulp-if": "^2.0.2",
"gulp-jshint": "^2.1.0",
"gulp-ng-annotate": "^2.1.0",
"gulp-notify": "^3.2.0",
"gulp-rename": "^1.3.0",
"gulp-sass": "^4.0.1",
"gulp-uglify": "^3.0.0",
"gulp-rename": "^1.4.0",
"gulp-sass": "^4.0.2",
"gulp-uglify": "^3.0.2",
"gulp-util": "^3.0.8",
"hoek": "^5.0.3",
"js-yaml": "^3.12.0",
"jshint": "^2.9.5",
"gulp-watch": "^5.0.0",
"js-yaml": "^3.13.1",
"jshint": "^2.10.2",
"jshint-stylish": "^2.2.1",
"yargs": "^12.0.1"
"yargs": "^13.2.4"
},
"devDependencies": {
"bootstrap": "^4.1.1",
"gulp-watch": "^5.0.0"
"scripts": {
"gulp": "node_modules/gulp/bin/gulp.js"
}
}
Loading

0 comments on commit 65e952a

Please sign in to comment.