diff --git a/skolehjem/public/js/serviceWorkerCachedWebpags.js b/skolehjem/public/js/serviceWorkerCachedWebpags.js new file mode 100644 index 0000000..11e18af --- /dev/null +++ b/skolehjem/public/js/serviceWorkerCachedWebpags.js @@ -0,0 +1,81 @@ +const staticCacheName = 'site-static-v2'; +const dynamicCacheName = 'site-dynamic-v1'; +const assets = [ + '/', + '/css/app.css', + '/css/normalize.css', + '/css/webapp.css', + '/css/webappdark.css', + '/home', + '/events' +]; + +// install event +self.addEventListener('install', evt => { + //console.log('service worker installed'); + evt.waitUntil( + caches.open(staticCacheName).then((cache) => { + console.log('caching shell assets'); + return cache.addAll(assets); + }) + ); +}); + +// activate event +self.addEventListener('activate', evt => { + //console.log('service worker activated'); + evt.waitUntil( + caches.keys().then(keys => { + //console.log(keys); + return Promise.all(keys + .filter(key => key !== staticCacheName && key !== dynamicCacheName) + .map(key => caches.delete(key)) + ); + }) + ); +}); + +// fetch event +self.addEventListener('fetch', evt => { + //console.log('fetch event', evt); + evt.respondWith( + caches.match(evt.request).then(cacheRes => { + return cacheRes || fetch(evt.request).then(fetchRes => { + return caches.open(dynamicCacheName).then(cache => { + cache.put(evt.request.url, fetchRes.clone()).then(r => { + return fetchRes; + }); + + }) + }); + }) + ); +}); + + +//Push notification, this is more of a demo you can test in the dev tool +self.addEventListener('push', evt => { + const title = "Test Notification"; + const body = "Det her et en demo på hvordan en notification kan se ud! "; + const icon = "/icons/browserFavIcon.svg" + const tag = "simple-push-example-tag"; + evt.waitUntil( + self.registration.showNotification(title, { + body : body, + icon : icon, + tag : tag + }) + ); +}); + + + +function displayNotification(){ + if(Notification.permission === 'granted'){ + navigator.serviceWorker.getRegistration() + .then(function (reg){ + reg.showNotification('Helloe ') + }) + } +} + diff --git a/skolehjem/public/js/serviceWorkerRegistration.js b/skolehjem/public/js/serviceWorkerRegistration.js new file mode 100644 index 0000000..23f5498 --- /dev/null +++ b/skolehjem/public/js/serviceWorkerRegistration.js @@ -0,0 +1,28 @@ +//Service Worker Registration + +/* +Make sure that we support service worker :) + */ + +if('serviceWorker' in navigator){ + window.addEventListener('load', () => { + navigator.serviceWorker + .register('/js/serviceWorkerCachedWebpags.js') + .then(reg => console.log("Service Worker has been: registered")) + .catch(err => console.log(`Service Worker error: ${err}`)) + }) +} + +/* + +Notification.requestPermission().then(function(permission){ + console.log('Notification permission was:', permission) +}); + + +if('caches' in window){ + console.log("The browser supports caching ") +}else { + console.log("This browser is some junk, it dosen't support caching :(") +} +*/ diff --git a/skolehjem/resources/views/app/news/index.blade.php b/skolehjem/resources/views/app/news/index.blade.php index ed20519..f4f162e 100644 --- a/skolehjem/resources/views/app/news/index.blade.php +++ b/skolehjem/resources/views/app/news/index.blade.php @@ -1,7 +1,11 @@ @extends("app.layout.base") +@section("title") + Home +@endsection + @section("content") -
+
@@ -127,10 +135,10 @@ {{__('msg.opret')}}{{ date('Y-m-d H:i:s', strtotime($new->created_at))}} @if($new->resource_id !== null) -
+
@endif -
+
{!! $new->content !!}
@@ -142,9 +150,9 @@ {{__('msg.opret')}}{{ date('Y-m-d H:i:s', strtotime($new->created_at))}} @if($new->resource_id !== null) -
+
@endif -
+
@if ($new->type_id == 1 || $new->type_id == 2) {{-- If it's a news or menu then display the whole message --}} {!! $new->content !!} @else {{-- If it's a menu, guide or event. Then display up to 300 characters of text --}} @@ -159,32 +167,32 @@ {{__('msg.opret')}}{{ date('Y-m-d H:i:s', strtotime($new->created_at))}}
@if($new->resource_id !== null) -
+
{{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime(\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->date))->format('d/m/Y \k\l\. H:i') }} {{\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->accountable}}
{!! \App\Helpers::closetags(substr($new->content, 0, 300) ) !!} -
+
@if (count(\App\UserEvent::query()->where('event_id', '=', $new->arrangement_id)->where('user_id', '=', Auth::user()->id)->get()) > 0) - {{__('msg.afmeld')}} + {{__('msg.afmeld')}} @else {{-- ^ If you're already participating in the event, then show a ´cancel´ button - v Else show a ´participate´ button --}} - {{__('msg.tilmeld')}} + {{__('msg.tilmeld')}} @endif - $new->arrangement_id ])}}">{{__('msg.læsmere')}} - $new->arrangement_id ])}}">{{__('msg.sedeltagere')}} + $new->arrangement_id ])}}">{{__('msg.læsmere')}} + $new->arrangement_id ])}}">{{__('msg.sedeltagere')}}
@else
{!! \App\Helpers::closetags(substr($new->content, 0, 300) ) !!}
{{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime(\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->date))->format('d/m/Y \k\l\. H:i') }} {{\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->accountable}}
-
+
@if (count(\App\UserEvent::query()->where('event_id', '=', $new->arrangement_id)->where('user_id', '=', Auth::user()->id)->get()) > 0) - {{__('msg.afmeld')}} + {{__('msg.afmeld')}} @else {{-- ^ If you're already participating in the event, then show a ´cancel´ button - v Else show a ´participate´ button --}} - {{__('msg.tilmeld')}} + {{__('msg.tilmeld')}} @endif - $new->arrangement_id ])}}">{{__('msg.læsmere')}} - $new->arrangement_id ])}}">{{__('msg.sedeltagere')}} + $new->arrangement_id ])}}">{{__('msg.læsmere')}} + $new->arrangement_id ])}}">{{__('msg.sedeltagere')}}
@endif @@ -197,15 +205,15 @@
@if($new->resource_id !== null)
-
{{__('msg.kategori')}}: {{\App\GuidesCategory::query()->where('id', '=', \App\Guide::query()->where('id','=', $new->arrangement_id)->first()->guide_category_id)->first()->guidesCategoryName}}
+
{{__('msg.kategori')}} {{\App\GuidesCategory::query()->where('id', '=', \App\Guide::query()->where('id','=', $new->arrangement_id)->first()->guide_category_id)->first()->guidesCategoryName}}
@endif -