v1.5.12 Added the last things to the preview function, its all working now

This commit is contained in:
Neerholt 2021-04-19 14:42:03 +02:00
parent 493a8aeb34
commit 19fdb63ad2
10 changed files with 73 additions and 19 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Event;
use App\News;
use App\Notification;
use App\Resource;
use App\UserEvent;
use App\User;
use Illuminate\Http\Request;
@ -288,7 +289,11 @@ class EventController extends Controller
}
public function previewPages(Request $request){
$event = Event::find($request->preview);
if(!Resource::find($request->preview)){
$event = Event::find($request->preview);
}else{
$event = Event::where('events.id', '=', $request->preview)->join('resources', 'resources.id', '=', 'events.resource_id')->first();
}
$convertToJsonArray = json_encode($event);
return $convertToJsonArray;
}

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Guide;
use App\News;
use App\Resource;
use Illuminate\Http\Response;
use Illuminate\Http\Request;
use tidy;
@ -277,7 +278,11 @@ class GuideController extends Controller
}
public function previewPages(Request $request){
$event = Guide::find($request->preview);
if(!Resource::find($request->preview)){
$event = Guide::find($request->preview);
}else{
$event = Guide::where('guides.id', '=', $request->preview)->join('resources', 'resources.id', '=', 'events.resource_id')->first();
}
$convertToJsonArray = json_encode($event);
return $convertToJsonArray;
}

View File

@ -22,25 +22,26 @@ class RootController extends Controller
}
public function index() {
$perPage = 5;
if (File::exists(public_path('uploads'))) {
foreach (File::allFiles(public_path('uploads')) as $file) {
$resource = Resource::query()->where('filename', '=', '/uploads/' . $file->getFilename())->get();
foreach (File::allFiles(public_path('uploads')) as $file) {
$resource = Resource::query()->where('filename', '=', '/uploads/' . $file->getFilename())->get();
if(count($resource) < 1)
unlink(public_path() . '/uploads/' . $file->getFilename());
else {
$events = Event::query()->where('resource_id', '=', $resource[0]->id)->get();
$news = News::query()->where('resource_id', '=', $resource[0]->id)->get();
$guides = Guide::query()->where('resource_id', '=', $resource[0]->id)->get();
$users = User::query()->where('resource_id', '=', $resource[0]->id)->get();
if(count($events) < 1 && count($news) < 1 && count($guides) < 1 && count($users) < 1) {
$resource[0]->delete();
if(count($resource) < 1)
unlink(public_path() . '/uploads/' . $file->getFilename());
else {
$events = Event::query()->where('resource_id', '=', $resource[0]->id)->get();
$news = News::query()->where('resource_id', '=', $resource[0]->id)->get();
$guides = Guide::query()->where('resource_id', '=', $resource[0]->id)->get();
$users = User::query()->where('resource_id', '=', $resource[0]->id)->get();
if(count($events) < 1 && count($news) < 1 && count($guides) < 1 && count($users) < 1) {
$resource[0]->delete();
unlink(public_path() . '/uploads/' . $file->getFilename());
}
}
}
}
} else
File::makeDirectory(public_path('uploads'), 0777, true, true);
//All news
$newsCollection = News::query()->orderBy('id', 'desc')->get();

View File

@ -11,11 +11,13 @@ class RemoveEvent extends Migration
*
* @return void
*/
/*
public function up()
{
\Illuminate\Support\Facades\DB::unprepared("CREATE OR REPLACE EVENT `remove_event` ON SCHEDULE EVERY 1 HOUR STARTS '2000-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO
DELETE FROM events WHERE HOUR(TIMEDIFF(NOW(), events.date)) >= 24 AND date(events.date) < CURDATE()");
}
*/
/**
* Reverse the migrations.

View File

@ -11,11 +11,13 @@ class RemoveNews extends Migration
*
* @return void
*/
/*
public function up()
{
\Illuminate\Support\Facades\DB::unprepared("CREATE OR REPLACE EVENT `remove_news` ON SCHEDULE EVERY 1 HOUR STARTS '2000-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO
DELETE FROM news WHERE news_expiration_date < NOW();");
}
*/
/**
* Reverse the migrations.

View File

@ -11,11 +11,13 @@ class RemoveReservation extends Migration
*
* @return void
*/
/*
public function up()
{
\Illuminate\Support\Facades\DB::unprepared("CREATE OR REPLACE EVENT `remove_reservation` ON SCHEDULE EVERY 1 HOUR STARTS '2000-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO
DELETE FROM washing_reservations WHERE time <= DATE_SUB(NOW(), INTERVAL 1 HOUR)");
}
*/
/**
* Reverse the migrations.

View File

@ -73,7 +73,7 @@
<strong><label for="accountable">Aktivitets ansvarlig</label></strong>
<p id="accountable"></p>
<hr>
<img src="{{ asset(\App\Resource::query()->where("id", "=", $events->resource_id)->first()->filename) }}">
<img id="eventimg">
<p id="description"></p>
</center>
</div>
@ -96,6 +96,11 @@
$("#date").html(l.date);
$("#accountable").html(l.accountable);
$("#description").html(l.description);
if (l.filename)
$("#eventimg").attr('src', l.filename);
},
error:function (data) {
console.log(data);
@ -105,11 +110,23 @@
function closeModal() {
modalNews.style.display = "none";
$("#name").html('');
$("#date").html('');
$("#accountable").html('');
$("#description").html('');
$("#eventimg").attr('src', '');
}
window.onmousedown = function(event) {
if (event.target == modalNews) {
modalNews.style.display = "none";
$("#name").html('');
$("#date").html('');
$("#accountable").html('');
$("#description").html('');
$("#eventimg").attr('src', '');
}
}
</script>

View File

@ -95,6 +95,7 @@
<center>
<h1 id="name"></h1>
<hr>
<img id="eventimg">
<strong><label for="guide_articles">Vejledning</label></strong>
<p id="guide_articles"></p>
</center>
@ -116,7 +117,9 @@
console.log(l);
$("#name").html(l.name);
$("#guide_articles").html(l.guide_articles);
//We need to add guide_category_id and resource_id
if (l.filename)
$("#eventimg").attr('src', l.filename);
},
error:function (data) {
console.log(data);
@ -126,11 +129,17 @@
function closeModal() {
modalNews.style.display = "none";
$("#name").html('');
$("#guide_articles").html('');
$("#eventimg").attr('src', '');
}
window.onmousedown = function(event) {
if (event.target == modalNews) {
modalNews.style.display = "none";
$("#name").html('');
$("#guide_articles").html('');
$("#eventimg").attr('src', '');
}
}
</script>

View File

@ -98,6 +98,11 @@
function closeModal() {
modalNews.style.display = "none";
$("#week").html('');
$("#monday").html('');
$("#tuesday").html('');
$("#wednesday").html('');
$("#thursday").html('');
}
window.onmousedown = function(event) {

View File

@ -93,11 +93,17 @@
function closeModal() {
modalNews.style.display = "none";
$("#titleEvent").html('');
$("#dateEvent").html('');
$("#descriptionEvent").html('');
}
window.onmousedown = function(event) {
if (event.target == modalNews) {
modalNews.style.display = "none";
$("#titleEvent").html('');
$("#dateEvent").html('');
$("#descriptionEvent").html('');
}
}
</script>