Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Live Notification on all the page of the dashboard!
Browse files Browse the repository at this point in the history
Live notification with Mercure!
  • Loading branch information
Kayoshi-dev committed May 15, 2020
2 parents 72ff9ca + c4b9754 commit 8f518b6
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 33 deletions.
15 changes: 14 additions & 1 deletion assets/js/dashboard.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
import '../scss/dashboard.scss';
import '../scss/dashboard.scss';
import Vue from "vue";
import Toasted from "vue-toasted";
import Notification from "../vue/Notification";

Vue.use(Toasted, {
iconPack: 'fontawesome'
});

new Vue({
components: { Notification },
template: "<Notification/>",
// router
}).$mount("#notification");
1 change: 0 additions & 1 deletion assets/js/newchild.js

This file was deleted.

25 changes: 25 additions & 0 deletions assets/scss/_menu.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@import "variables";

.center-icon {
line-height: 50px;
}

.grey-navbar {
background-color: $navbar-grey;
}

.passive-bell {
position: relative;
cursor: pointer;
}

.new-notification {
position: absolute;
content: "";
height: 5px;
width: 5px;
border-radius: 50%;
top: 18px;
right: 4px;
background-color: red;
}
1 change: 1 addition & 0 deletions assets/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $card-main-grey: #E2E2E2;
$card-secondary-grey: #C4C4C4;
$grey-light: #ededed;
$label-color: #707070;
$navbar-grey: #F2F2F2;

$pure-white: #FFFFFF;

Expand Down
3 changes: 2 additions & 1 deletion assets/scss/dashboard.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "variables";
@import "menu";

// Usefull class to center your content in the <main> tag
.main-full-height {
height: calc(100vh - 82px);
height: calc(100vh - 83px);
}
37 changes: 37 additions & 0 deletions assets/vue/Notification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<li class="nav-item text-light center-icon passive-bell">
<img :src="bell" width="30" alt="Icone cloche">
<span id="new-icon"></span>
</li>
</template>

<script>
export default {
name: "Notification",
data: function() {
return {
'bell': '/build/bell-icon.svg'
}
},
mounted() {
// Port hardcodé, réfléchir à mieux
const url = new URL(document.location.origin + ":1337/.well-known/mercure");
url.searchParams.append('topic', `${document.location.origin}/api/notifications/{id}`);
const eventSource = new EventSource(url);
eventSource.onmessage = () => {
document.getElementById('new-icon').classList.add('new-notification')
let toast = this.$toasted.show("Vous avez reçu une nouvelle notification!", {
theme: "toasted-primary",
icon: "bell",
position: "top-right",
duration : 3000
});
};
}
}
</script>

<style scoped>
</style>
2 changes: 1 addition & 1 deletion src/Entity/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Doctrine\ORM\Mapping as ORM;

/**
* @ApiResource()
* @ApiResource(mercure="true")
* @ORM\Entity(repositoryClass="App\Repository\NotificationRepository")
*/
class Notification
Expand Down
50 changes: 50 additions & 0 deletions src/Repository/NotificationRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Repository;

use App\Entity\Notification;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
* @method Notification|null find($id, $lockMode = null, $lockVersion = null)
* @method Notification|null findOneBy(array $criteria, array $orderBy = null)
* @method Notification[] findAll()
* @method Notification[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class NotificationRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Notification::class);
}

// /**
// * @return Notification[] Returns an array of Notification objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('c')
->andWhere('c.exampleField = :val')
->setParameter('val', $value)
->orderBy('c.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/

/*
public function findOneBySomeField($value): ?Notification
{
return $this->createQueryBuilder('c')
->andWhere('c.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}
4 changes: 4 additions & 0 deletions templates/admin/home/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,7 @@
</div>

{% endblock %}

{% block javascripts %}
{{ encore_entry_script_tags('dashboard') }}
{% endblock %}
4 changes: 3 additions & 1 deletion templates/admin/newFood.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@

{% endblock %}


{% block javascripts %}
{{ encore_entry_script_tags('dashboard') }}
{% endblock %}
1 change: 1 addition & 0 deletions templates/admin/newMeal.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{% endblock %}

{% block javascripts %}
{{ encore_entry_script_tags('dashboard') }}
{{ encore_entry_script_tags('newMeal') }}
{% endblock %}

4 changes: 4 additions & 0 deletions templates/admin/notification/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@

</div>

{% endblock %}

{% block javascripts %}
{{ encore_entry_script_tags('dashboard') }}
{% endblock %}
5 changes: 4 additions & 1 deletion templates/dashboard/newchild.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

{% block stylesheets %}

{{ encore_entry_link_tags('newchild') }}
{{ encore_entry_link_tags('dashboard') }}

{% endblock %}
Expand Down Expand Up @@ -47,4 +46,8 @@

</div>

{% endblock %}

{% block javascripts %}
{{ encore_entry_script_tags('dashboard') }}
{% endblock %}
36 changes: 12 additions & 24 deletions templates/partials/menu.html.twig
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
{% block body %}
<nav class="navbar navbar-dark sticky-top flex-md-nowrap p-3" style="background-color: #F2F2F2">
<nav class="navbar grey-navbar sticky-top flex-md-nowrap p-3 border-bottom">

<span class="navbar-brand col-sm-3 col-md-2 mr-0 text-center text-dark">Tableau de bord - <span class="inner-green">ADMIN</span></span>


<ul class="nav justify-content-end">
<li class="nav-item text-light">
<img src="{{ asset('build/bell-icon.svg') }}"class="rounded-circle" width="30">
</li>
<li id="notification"></li>

<li class="nav-item mr-5 ml-5">
<img src="{{ asset('build/avatar-homme.svg') }}"class="rounded-circle" width="50">
<img src="{{ asset('build/avatar-homme.svg') }}" class="rounded-circle" width="50" alt="Image d'avatar">
</li>

</ul>

</nav>

<div class="container-fluid">

<div class="row" style="height: 1080px; background-color: #F2F2F2">
<div class="row main-full-height grey-navbar">

<nav class="col-md-2 d-none d-md-block sidebar" style="background-color: #F2F2F2">
<nav class="col-md-2 d-none d-md-block sidebar grey-navbar border-right">

<div class="sidebar-sticky">

Expand All @@ -38,7 +34,6 @@
<a class="nav-link text-dark" href="#" >
<i class="far fa-chart-bar"></i>
Statistiques

</a>

</li>
Expand All @@ -48,7 +43,6 @@
<a class="nav-link text-dark" href="#" >
<i class="fas fa-utensils"></i>
Menus

</a>

</li>
Expand All @@ -57,7 +51,6 @@
<a class="nav-link text-dark" href="#" >
<i class="far fa-calendar-check"></i>
Réservations

</a>

</li>
Expand All @@ -67,9 +60,7 @@

<a class="nav-link text-dark" href="#">
<i class="far fa-money-bill-alt"></i>

Paiements

</a>

</li>
Expand All @@ -80,29 +71,23 @@
<a class="nav-link text-dark" href="#" >
<i class="far fa-heart"></i>
Plats likés

</a>

</li>

<li class="nav-item">

<a class="nav-link text-dark" href="#">

<i class="fas fa-users"></i>

Utilisateurs

</a>

</li>

</ul>

<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-5 mb-2 text-muted">

<span>Infos personnelles</span>

</h6>

<ul class="nav flex-column mb-2">
Expand All @@ -113,7 +98,6 @@

<i class="far fa-address-card"></i>
Voir mon profil

</a>

</li>
Expand All @@ -124,7 +108,6 @@

<i class="fas fa-unlock-alt"></i>
Modifier le mot de passe

</a>

</li>
Expand Down Expand Up @@ -158,7 +141,6 @@
<a class="nav-link text-danger" href="#">
<i class="fas fa-sign-out-alt"></i>
Déconnexion

</a>

</li>
Expand Down Expand Up @@ -209,4 +191,10 @@
</div>

</div>
{% endblock %}
{% endblock %}
<script>
import Notification from "../../assets/vue/Notification";
export default {
components: {Notification}
}
</script>
3 changes: 0 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ Encore
// New Meal
.addEntry('newMeal', './assets/js/newMeal.js')

// New Child Form
.addEntry('newchild', './assets/js/newchild.js')

.enableVueLoader()

// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
Expand Down

0 comments on commit 8f518b6

Please sign in to comment.