Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
msalsas committed Jul 25, 2018
2 parents 618f2a2 + cb631e7 commit 0b0c208
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 227 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
composer.lock
vendor
4 changes: 2 additions & 2 deletions DependencyInjection/MsalsasVotingExtension.php
Expand Up @@ -48,8 +48,8 @@ public function prepend(ContainerBuilder $container)
$twigConfig = [];
$twigConfig['globals']['msalsas_voting_voter'] = "@msalsas_voting.voter";
$twigConfig['globals']['msalsas_voting_clicker'] = "@msalsas_voting.clicker";
$twigConfig['paths']['%kernel.project_dir%/vendor/msalsas/voting-bundle/Resources/views'] = "msalsas_voting";
$twigConfig['paths']['%kernel.project_dir%/vendor/msalsas/voting-bundle/Resources/public'] = "msalsas_voting.public";
$twigConfig['paths'][__DIR__ . '/../Resources/views'] = "msalsas_voting";
$twigConfig['paths'][__DIR__ . '/../Resources/public'] = "msalsas_voting.public";
$container->prependExtensionConfig('twig', $twigConfig);
}

Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -14,6 +14,7 @@ Features include:
- Clicks or views
- Built in CSS
- Publish posts
- Modal for errors

[![Build Status](https://travis-ci.org/msalsas/MsalsasVotingBundle.svg?branch=master)](https://travis-ci.org/msalsas/MsalsasVotingBundle) [![Code Coverage](https://scrutinizer-ci.com/g/msalsas/MsalsasVotingBundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/msalsas/MsalsasVotingBundle/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/msalsas/MsalsasVotingBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/msalsas/MsalsasVotingBundle/?branch=master) [![Latest Stable Version](https://poser.pugx.org/msalsas/voting-bundle/v/stable.svg)](https://packagist.org/packages/msalsas/voting-bundle)

Expand Down
43 changes: 35 additions & 8 deletions Resources/doc/index.rst
Expand Up @@ -29,7 +29,7 @@ For more information about translations, check `Symfony documentation`_.
Installation
------------

Installation is a quick 7 step process:
Installation is a quick 7 step process (4 if you use Flex):

1. Download MsalsasVotingBundle using composer
2. Enable the Bundle
Expand All @@ -55,7 +55,11 @@ Composer will install the bundle to your project's ``vendor/msalsas/voting-bundl
Step 2: Enable the bundle
~~~~~~~~~~~~~~~~~~~~~~~~~

Enable the bundle in the kernel::
.. note::

If you're using Flex, this is done automatically

Enable the bundle in the kernel:

<?php
// app/AppKernel.php
Expand Down Expand Up @@ -83,6 +87,10 @@ properties or methods you find useful. This is *your* ``Reference`` class.
Step 4: Configure the MsalsasVotingBundle
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::

If you're using Flex, this is done automatically

Add the following configuration to your ``config/packages/msalsas_voting.yaml`` file.

.. configuration-block::
Expand All @@ -107,6 +115,10 @@ Add the following configuration to your ``config/packages/msalsas_voting.yaml``
Step 5: Create MsalsasVotingBundle routes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::

If you're using Flex, this is done automatically

Now that you have activated and configured the bundle, you have to create the routing file.
You can edit the paths to whatever you want, but including ``{id}``.

Expand Down Expand Up @@ -148,6 +160,7 @@ For displaying the voting widgets you have to use macros:
{% import "@msalsas_voting/msalsas_voting_widget.html.twig" as msalsas_voting_widget %} # Import macros
{{ msalsas_voting_widget.shakeItCSS() }} # Import CSS macro (optional)
{{ msalsas_voting_widget.shakeItJS() }} # Import JS macro
{{ msalsas_voting_widget.shakeItModal() }} # Import Modal macro (for errors)

<article class="post">
{{ msalsas_voting_widget.shakeIt(post.id) }} # Import the voting widget
Expand All @@ -165,10 +178,21 @@ For displaying the voting widgets you have to use macros:
Also, you have to import `Font Awesome`_ if you want to show the bottom bar icons


Instead of using ``msalsas_voting_widget.shakeItCSS()`` and ``msalsas_voting_widget.shakeItJS()``
you can import ``vendor/msalsas/voting-bundle/Resources/public/css/msalsas_voting_styles.css``,
``vendor/msalsas/voting-bundle/Resources/public/js/msalsas_voting_shakeIt.js`` and
``vendor/msalsas/voting-bundle/Resources/public/js/msalsas_voting_bottomBar.js`` with your assets.
Instead of using

``msalsas_voting_widget.shakeItCSS()``

``msalsas_voting_widget.shakeItJS()``

you can import

``vendor/msalsas/voting-bundle/Resources/public/css/msalsas_voting_styles.css``

``vendor/msalsas/voting-bundle/Resources/public/js/msalsas_voting_shakeIt.js``

with your assets.

If you don't use ``shakeItModal`` errors will be displayed with ``alert``.

.. _Font Awesome: https://fontawesome.com/how-to-use/on-the-web/setup/getting-started?using=web-fonts-with-css

Expand All @@ -184,8 +208,11 @@ The following documents are available:

`1. Clicks or views`_.

`2. Configuration reference`_.
`2. Publishing`_.

`3. Configuration reference`_.

.. _1. Clicks or views: ./clicks_or_views.rst
.. _2. Configuration reference: ./configuration_reference.rst
.. _2. Publishing: ./publish.rst
.. _3. Configuration reference: ./configuration_reference.rst

49 changes: 49 additions & 0 deletions Resources/public/css/msalsas_voting_styles.css
Expand Up @@ -124,4 +124,53 @@
font-size: 11px;
width: 75px;
border-radius: 0;
}

/*Modal*/
#msalsas-modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}

/* Modal Content/Box */
.msalsas-modal-content {
background-color: #FFEEC7;
margin: 15% auto;
padding: 20px;
border: 1px solid #e35614;
min-width: 250px;
text-align: center;
width: 25%;
height: 18.5ex;
overflow: hidden;
border-radius: 3px;
}
#msalsas-modal-text {
font-weight: bold;
font-size: 20px;
margin-top: 30px;
text-align: center;
}

.msalsas-close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
line-height: 15px;
}

.msalsas-close:hover,
.msalsas-close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
37 changes: 35 additions & 2 deletions Resources/public/js/msalsas_voting_bottomBar.js
Expand Up @@ -36,14 +36,47 @@
buttonElem.innerHTML = '<span>' + window.msalsasVoting_Selected.text + '</span>';
} else if(http.readyState == 4 && http.status >= 400) {
if (http.responseText.length < 50) {
alert(http.responseText);
showModal(http.responseText);
} else {
alert('Error');
showModal('Error');
}
}
};
if (window.msalsasVoting_Selected.value !== '0') {
http.send(window.msalsasVoting_Selected.value);
}
}

function showModal(message) {
message = message.replace (/(^")|("$)/g, '');
var modal = document.getElementById('msalsas-modal');
var span = document.getElementsByClassName("msalsas-close")[0];

if (!modal || !span) {
alert(message);
return;
}
document.getElementById('msalsas-modal-text').innerText = message;
modal.style.display = "block";

if (span.addEventListener) {
span.addEventListener('click', closeModal, false);
} else {
span.attachEvent('onclick', closeModal);
}

if (window.addEventListener) {
window.addEventListener('click', closeModal, false);
} else {
window.attachEvent('onclick', closeModal);
}
}

function closeModal(event) {
var modal = document.getElementById('msalsas-modal');
var span = document.getElementsByClassName("msalsas-close")[0];
if (event.target === modal || event.target === span) {
modal.style.display = "none";
}
}
})();
35 changes: 34 additions & 1 deletion Resources/public/js/msalsas_voting_shakeIt.js
Expand Up @@ -34,9 +34,42 @@
var buttonElem = document.getElementById('msalsas-voting-a-shake-' + id);
buttonElem.innerHTML = '<span>' + shakenText + '</span>';
} else if(http.readyState == 4 && http.status >= 400) {
alert(http.responseText);
showModal(http.responseText);
}
};
http.send();
}

function showModal(message) {
message = message.replace (/(^")|("$)/g, '');
var modal = document.getElementById('msalsas-modal');
var span = document.getElementsByClassName("msalsas-close")[0];

if (!modal || !span) {
alert(message);
return;
}
document.getElementById('msalsas-modal-text').innerText = message;
modal.style.display = "block";

if (span.addEventListener) {
span.addEventListener('click', closeModal, false);
} else {
span.attachEvent('onclick', closeModal);
}

if (window.addEventListener) {
window.addEventListener('click', closeModal, false);
} else {
window.attachEvent('onclick', closeModal);
}
}

function closeModal(event) {
var modal = document.getElementById('msalsas-modal');
var span = document.getElementsByClassName("msalsas-close")[0];
if (event.target === modal || event.target === span) {
modal.style.display = "none";
}
}
})();
9 changes: 9 additions & 0 deletions Resources/views/msalsas_voting_widget.html.twig
Expand Up @@ -70,6 +70,15 @@ file that was distributed with this source code. #}
</div>
{% endmacro bottomBar %}

{% macro shakeItModal() %}
<div id="msalsas-modal">
<div class="msalsas-modal-content">
<span class="msalsas-close">&times;</span>
<p id="msalsas-modal-text">Error</p>
</div>
</div>
{% endmacro %}

{% macro shakeItCSS() %}
<style>{{ source('@msalsas_voting.public/css/msalsas_voting_styles.css') }}</style>
{% endmacro shakeItCSS %}
Expand Down
10 changes: 6 additions & 4 deletions Tests/DependencyInjection/MsalsasVotingExtensionTest.php
Expand Up @@ -95,10 +95,12 @@ public function testPrependConfig()
$this->assertTrue($twigConfig[0]['globals']['msalsas_voting_voter'] === "@msalsas_voting.voter");
$this->assertTrue(isset($twigConfig[0]['globals']['msalsas_voting_clicker']));
$this->assertTrue($twigConfig[0]['globals']['msalsas_voting_clicker'] === "@msalsas_voting.clicker");
$this->assertTrue(isset($twigConfig[0]['paths']['%kernel.project_dir%/vendor/msalsas/voting-bundle/Resources/views']));
$this->assertTrue($twigConfig[0]['paths']['%kernel.project_dir%/vendor/msalsas/voting-bundle/Resources/views'] === "msalsas_voting");
$this->assertTrue(isset($twigConfig[0]['paths']['%kernel.project_dir%/vendor/msalsas/voting-bundle/Resources/public']));
$this->assertTrue($twigConfig[0]['paths']['%kernel.project_dir%/vendor/msalsas/voting-bundle/Resources/public'] === "msalsas_voting.public");

$mainDir = substr(__DIR__, 0, strpos(__DIR__, '/Tests/DependencyInjection') );
$this->assertTrue(isset($twigConfig[0]['paths'][$mainDir . '/DependencyInjection/../Resources/views']));
$this->assertTrue($twigConfig[0]['paths'][$mainDir . '/DependencyInjection/../Resources/views'] === "msalsas_voting");
$this->assertTrue(isset($twigConfig[0]['paths'][$mainDir . '/DependencyInjection/../Resources/public']));
$this->assertTrue($twigConfig[0]['paths'][$mainDir . '/DependencyInjection/../Resources/public'] === "msalsas_voting.public");
}

/**
Expand Down

0 comments on commit 0b0c208

Please sign in to comment.