Skip to content

Commit

Permalink
Add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbeil committed Nov 18, 2020
1 parent 49c4c6d commit 353e229
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 4 deletions.
4 changes: 4 additions & 0 deletions config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ run:
path: /run/{application}
controller: JoliCode\SecretSanta\Controller\SantaController::run

notes:
path: /notes/{application}
controller: JoliCode\SecretSanta\Controller\SantaController::notes

send_sample_message:
path: /sample-message/{application}
methods: POST
Expand Down
19 changes: 18 additions & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ a {
.big-button.warning-btn:hover {
background-color: var(--color-warning-dark);
}
.big-button.bellow {
color: var(--color-primary);
border: 2px solid var(--color-primary);
background-color: transparent;
}
.hidden {
position: absolute;
width: 1px;
Expand Down Expand Up @@ -742,6 +747,10 @@ textarea {
display: flex;
align-items: center;
}
.user-list .user-item.notes {
min-height: 3.5em;
}

.user-list .no-result {
min-height: 3em;
vertical-align: middle;
Expand All @@ -755,9 +764,17 @@ textarea {
display: none;
}
.user-list .user-item:hover {
background-color: var(--color-gray-light);
background-color: var(--color-gray-light);
cursor: pointer;
}
.user-list .user-item.notes:hover {
background-color: transparent;
cursor: default;
}
.notes input[type="text"] {
margin-right: 20px;
width: 50%;
}
.user-list .user-item * {
margin: 0 0 0 1em;
display: flex;
Expand Down
32 changes: 31 additions & 1 deletion src/Controller/SantaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,20 @@ public function run(Rudolph $rudolph, Request $request, string $application): Re
$errors = $this->validate($selectedUsers, $message);

if (\count($errors) < 1) {
if ($request->request->has('notesRedirect')) {
$request->getSession()->set('setup', [
'selectedUsers' => $request->request->all('users'),
'message' => $request->request->get('message'),
]);

return $this->redirectToRoute('notes', [
'application' => $application->getCode(),
]);
}

$associatedUsers = $rudolph->associateUsers($selectedUsers);
$hash = md5(serialize($associatedUsers));
$notes = $request->request->all('notes');

$secretSanta = new SecretSanta(
$application->getCode(),
Expand All @@ -87,7 +99,8 @@ public function run(Rudolph $rudolph, Request $request, string $application): Re
}),
$associatedUsers,
$application->getAdmin(),
$message
$message,
$notes
);

$request->getSession()->set(
Expand All @@ -113,6 +126,23 @@ public function run(Rudolph $rudolph, Request $request, string $application): Re
return new Response($content);
}

public function notes(Request $request, string $application): Response
{
$setup = $request->getSession()->get('setup');
$application = $this->getApplication($application);

$content = $this->twig->render('santa/application/notes_' . $application->getCode() . '.html.twig', [
'application' => $application->getCode(),
'users' => $application->getUsers(),
'groups' => $application->getGroups(),
'selectedUsers' => $setup['selectedUsers'],
'admin' => $application->getAdmin(),
'message' => $setup['message'],
]);

return new Response($content);
}

public function sendSampleMessage(Request $request, string $application): Response
{
$application = $this->getApplication($application);
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ApiHelper
{
const TOKEN_TYPE_BOT = 'Bot';
private $botToken;

/** @var DiscordClient|null */
private $client;

Expand Down
4 changes: 4 additions & 0 deletions src/Discord/MessageSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function sendSecretMessage(SecretSanta $secretSanta, string $giver, strin
$text .= "\n\nHere is a message from the Secret Santa admin:\n\n```" . $secretSanta->getAdminMessage() . '```';
}

if (!empty($userNote = $secretSanta->getUserNote($receiver))) {
$text .= sprintf("\n\nHere is some notes about <@%s>:\n\n```%s```", $receiver, $userNote);
}

if ($secretSanta->getAdmin()) {
$text .= sprintf("\n\n_Your Secret Santa admin, <@%s>._", $secretSanta->getAdmin()->getIdentifier());
}
Expand Down
11 changes: 10 additions & 1 deletion src/Model/SecretSanta.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class SecretSanta
private $remainingAssociations;
private $admin;
private $adminMessage;
private $notes;

/** @var string[] */
private $errors = [];

/**
* @param User[] $users
* @param array<string, string> $associations
* @param array<int, string> $notes
*/
public function __construct(
string $application,
Expand All @@ -36,7 +38,8 @@ public function __construct(
array $users,
array $associations,
?User $admin,
?string $adminMessage
?string $adminMessage,
array $notes = []
) {
$this->application = $application;
$this->organization = $organization;
Expand All @@ -46,6 +49,7 @@ public function __construct(
$this->remainingAssociations = $associations;
$this->admin = $admin;
$this->adminMessage = $adminMessage;
$this->notes = $notes;
}

public function getApplication(): ?string
Expand Down Expand Up @@ -76,6 +80,11 @@ public function getUser(string $identifier): ?User
return $this->users[$identifier] ?? null;
}

public function getUserNote(string $identifier): string
{
return $this->notes[$identifier] ?? '';
}

/**
* @return array<string, string>
*/
Expand Down
18 changes: 18 additions & 0 deletions src/Slack/MessageSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ public function sendSecretMessage(SecretSanta $secretSanta, string $giver, strin
];
}

if (!empty($userNote = $secretSanta->getUserNote($receiver))) {
$blocks[] = [
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => sprintf('*Here is some notes about <@%s>:*', $receiver),
],
];

$blocks[] = [
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => $userNote,
],
];
}

$blocks[] = [
'type' => 'divider',
];
Expand Down
15 changes: 15 additions & 0 deletions src/Zoom/MessageSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ public function sendSecretMessage(SecretSanta $secretSanta, string $giver, strin
];
}

if (!empty($userNote = $secretSanta->getUserNote($receiver))) {
$body['content']['body'][] = [
'type' => 'message',
'text' => sprintf('*Here is some notes about <!%s|%s>:*',
$receiver,
$receiverUser->getName()
),
];

$body['content']['body'][] = [
'type' => 'message',
'text' => $userNote,
];
}

$body['content']['body'][] = [
'type' => 'message',
'text' => 'That\'s a secret only shared with you! Someone has also been chosen to get you a gift.'
Expand Down
22 changes: 22 additions & 0 deletions templates/santa/application/notes_discord.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'santa/notes.html.twig' %}

{% block user_item %}
<label class="user-item notes">
{% if user.extra.image %}
<img src="{{ user.extra.image }}" alt="{{ user.name }}" />
{% endif %}
<span>{{ user.name }}{% if user.extra.nickname %} ({{ user.extra.nickname }}){% endif %}</span>
{% if groups %}
<span class="user-groups">
{% for group in groups %}
{% if user.identifier in group.userIds %}
<span class="user-group">{{ group.name }}</span>
{% endif %}
{% endfor %}
</span>
{% endif %}

<input name="users[]" type="hidden" value="{{ user.identifier }}">
<input name="notes[{{ user.identifier }}]" type="text" {% if key in input_placeholders|keys %}placeholder="{{ input_placeholders[key] }}"{% endif %} />
</label>
{% endblock %}
20 changes: 20 additions & 0 deletions templates/santa/application/notes_slack.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'santa/run.html.twig' %}

{% block user_item %}
<label class="user-item notes">
<img src="{{ user.extra.image }}" alt="{{ user.name }}" />
<span>{{ user.name }} ({{ user.extra.nickname }})</span>
{% if groups %}
<span class="user-groups">
{% for group in groups %}
{% if user.identifier in group.userIds %}
<span class="user-group">{{ group.name }}</span>
{% endif %}
{% endfor %}
</span>
{% endif %}

<input name="users[]" type="hidden" value="{{ user.identifier }}">
<input name="notes[{{ user.identifier }}]" type="text" {% if key in input_placeholders|keys %}placeholder="{{ input_placeholders[key] }}"{% endif %} />
</label>
{% endblock %}
22 changes: 22 additions & 0 deletions templates/santa/application/notes_zoom.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'santa/run.html.twig' %}

{% block user_item %}
<label class="user-item notes">
{% if user.extra.image %}
<img src="{{ user.extra.image }}" alt="{{ user.name }}" />
{% endif %}
<span>{{ user.name }}</span>
{% if groups %}
<span class="user-groups">
{% for group in groups %}
{% if user.identifier in group.userIds %}
<span class="user-group">{{ group.name }}</span>
{% endif %}
{% endfor %}
</span>
{% endif %}

<input name="users[]" type="hidden" value="{{ user.identifier }}">
<input name="notes[{{ user.identifier }}]" type="text" {% if key in input_placeholders|keys %}placeholder="{{ input_placeholders[key] }}"{% endif %} />
</label>
{% endblock %}
76 changes: 76 additions & 0 deletions templates/santa/notes.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% extends 'base.html.twig' %}

{% set hasRestrictedUser = hasRestrictedUser|default(false) %}

{% block content %}
<div class="run-block">
<form method="post" id="run_form" action="{{ path('run', { application: application }) }}">
<div class="pure-g">
<div class="pure-u-1 user-field run-step">
<h2>Add notes for your participants</h2>

{% apply spaceless %}
<div class="user-list" id="user-list">
{% set key = 0 %}
{% set input_placeholders = {
0: 'Add some notes ...',
1: 'An address ;',
2: 'A food allergy ;',
3: 'Or whatever you want ...',
} %}

{% for user in users %}
{% if user.identifier in selectedUsers %}
{% block user_item %}{% endblock %}
{% set key = key + 1 %}
{% endif %}
{% endfor %}
<div class="no-result is-hidden" id="no-user-matching">
No user matching.
</div>
</div>
{% endapply %}
<p class="help">
A user's note will be sent to the selected participant to send him/her a gift .
</p>
</div>

<div class="pure-u-1 pure-u-lg-1-2">
<div class="run-column">
<div class="message-field run-step">
<h2>
<label class="control-label" for="message">Check your message</label>
</h2>

<input type="hidden" name="message" value="{{ message }}" />
<textarea name="message" id="message" rows="5" disabled="disabled">{{ message }}</textarea>
<p class="help">
This field is only here to check your message.
If you want to edit it, please go to the previous page.
</p>
</div>
</div>
</div>
<div class="pure-u-1 pure-u-lg-1-2">
<div class="run-column run-column-right">
<div class="run-step">
<h2>Ready?</h2>

<p class="is-center">
We are going to shuffle selected users and send them a private message to inform them
of their peer name.
</p>

<div class="is-center">
<button type="submit" class="big-button" id="submit-button">
<span class="fas fa-paper-plane" aria-hidden="true"></span>
Finish and send Secret Santa messages!
</button>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
{% endblock content %}
5 changes: 5 additions & 0 deletions templates/santa/run.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
<span class="fas fa-paper-plane" aria-hidden="true"></span>
Finish and send Secret Santa messages!
</button>

<button type="submit" class="big-button bellow" id="add-button" name="notesRedirect">
<span class="fas fa-user-edit" aria-hidden="true"></span>
Add notes for your participants before sending
</button>
</div>

<p class="is-center">
Expand Down

0 comments on commit 353e229

Please sign in to comment.