Compare commits

..

10 Commits

Author SHA1 Message Date
cae791ae27 style: Added Logo to Login
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2024-03-24 19:06:42 +01:00
ee3d211af1 style: Added Easter Eggs 2024-03-24 19:01:47 +01:00
779bc7d91f style: fix Action Column
All checks were successful
continuous-integration/drone Build is passing
2024-03-24 14:47:49 +01:00
53628a319e fix: Git Hash #3
All checks were successful
continuous-integration/drone/push Build is passing
2024-03-24 14:36:50 +01:00
ec92f4bd5d fix: Git Hash #2
All checks were successful
continuous-integration/drone/push Build is passing
2024-03-24 14:33:12 +01:00
4c57faef52 fix: Git Hash #2
All checks were successful
continuous-integration/drone/push Build is passing
2024-03-24 14:29:09 +01:00
f9c83d6459 fix: Git Hash
All checks were successful
continuous-integration/drone/push Build is passing
2024-03-24 14:24:55 +01:00
91592b06d7 style: Mobile Styles
All checks were successful
continuous-integration/drone/push Build is passing
2024-03-24 14:16:13 +01:00
5534f00a7d style: Empty String to number
All checks were successful
continuous-integration/drone/push Build is passing
2024-03-24 01:38:56 +01:00
5c0dab3448 feat: Realtime for Votes + Deadlines 2024-03-24 01:36:16 +01:00
16 changed files with 201 additions and 22 deletions

View File

@@ -23,6 +23,7 @@ steps:
- docker compose exec php php artisan migrate --force
- docker compose exec php php artisan optimize
- docker compose exec php php artisan storage:link
- git config --global --add safe.directory /var/www/html/bookstack.octolabs.net
- npx nuxi cleanup
- pnpm run build
- find /var/www/html/bookstack.octolabs.net -type f -exec chmod 664 {} \\;

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Events\Deadline;
use App\Models\Deadline;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class DeadlineCreated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct(public Deadline $deadline)
{
//
}
public function broadcastAs(): string
{
return 'DeadlineCreated';
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('Deadline'),
];
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Events\Vote;
use App\Models\Vote;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class VoteCreated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct(
public Vote $vote
)
{
//
}
public function broadcastAs(): string
{
return 'VoteCreated';
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('Vote'),
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use App\Events\Deadline\DeadlineCreated;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -16,6 +17,13 @@ class Deadline extends Model
'target_chapter',
];
protected static function booted() :void
{
static::created(static function ($deadline) {
event(new DeadlineCreated($deadline));
});
}
public function bookRecommendation()
{
return $this->belongsTo(BookRecommendation::class);

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use App\Events\Vote\VoteCreated;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -14,6 +15,13 @@ class Vote extends Model
'book_recommendation_id',
];
protected static function booted() :void
{
static::created(static function ($vote) {
broadcast(new VoteCreated($vote))->toOthers();
});
}
public function user()
{
return $this->belongsTo(User::class);

View File

@@ -1,22 +1,31 @@
<script setup lang="ts">
import party from 'party-js'
const config = useRuntimeConfig()
function confirmDeadline(event) {
party.confetti(event)
}
</script>
<template>
<div>
<UDivider />
<UFooter c>
<UFooter>
<template #left>
<div class="text-xs">
Copyright © {{ new Date().getFullYear() }}
<div class="flex items-center gap-4">
<!-- <OctolabsLogo class="fill-primary rotate-45" width="36" /> -->
<div class="text-xs">
Copyright © {{ new Date().getFullYear() }}
</div>
</div>
</template>
<template #center>
Made with by <a class="text-primary hover:text-primary-600 ml-1" href="https://flycro.me" target="_blank">Flycro</a>
Made with <span class="cursor-pointer transition duration-500 hover:scale-125 hover:animate-pulse" @click="confirmDeadline"></span> by <a class="text-primary hover:text-primary-600 ml-1" href="https://flycro.me" target="_blank">Flycro</a>
</template>
<template #right>
<div class="font-mono text-xs">
{{ config.public.packageVersion }} - {{ config.public.gitHash }}
{{ config.public.packageVersion }} - {{ config.public.gitHash !== '' ? config.public.gitHash : '0000000' }}
</div>
</template>
</UFooter>

View File

@@ -0,0 +1,31 @@
<script setup lang="ts">
import { twMerge } from 'tailwind-merge'
const props = defineProps<{
width?: string
height?: string
class?: string
}>()
const cssClasses = computed(() => {
return twMerge([
'fill-current',
props.class,
])
})
</script>
<template>
<svg xmlns="http://www.w3.org/2000/svg" :class="cssClasses" :width="props.width" :height="props.height" viewBox="0 0 101.27 145.9">
<g id="Ebene_2" data-name="Ebene 2">
<g id="Ebene_8" data-name="Ebene 8">
<path d="M50.63 0C22.67 0 0 21.46 0 47.93 0 61.85 6.69 76.49 19.35 85a69.67 69.67 0 0 0 21.59 10c6.49 1.62 13.4 1.7 19.38 1.7 28 0 40.95-22.34 40.95-48.81S78.6 0 50.63 0Zm15.18 65.91c-5.46 5.24-13.51 7.59-20.51 5.71a20.29 20.29 0 0 1-14.43-14.47c-1.49-5.43-.48-12.33 2.88-16.9 2.45-3.34 4.76-6 8.51-8a20.24 20.24 0 0 1 15-2 24.4 24.4 0 0 1 6.67 3.14 22.12 22.12 0 0 1 2.48 2.15 23.32 23.32 0 0 1 6.26 14.76c.07 8.44-5.17 13.98-6.86 15.61Z" class="cls-1" />
<path d="M57.8 49.89c.67-2.92-.89-5.08-3.49-6.15-3.13-1.3-7 .07-9.14 2.5A8.35 8.35 0 0 0 45 57.1c4.53 5.9 14 3.39 15.73-3.68 1.79-7.42-6.38-14.55-13.25-10.23-3.17 2-5.39 7.23-4.11 10.8s5.45 4.43 9.14 3.94c4.58-.62 7.51-5.9 5.11-10M19.62 74.51c-4.41 4-7.87 9.7-6.41 15.89 1.59 6.71 7.23 11.22 5.08 18.75-1.83 6.42-8.36 10-10.34 16.38-1.54 5-.45 9.84 3.78 13 3.1 2.31 6.1-2.9 3-5.18-5.27-3.92 2.69-11.66 5-14.57A21.51 21.51 0 0 0 24.72 107a21 21 0 0 0-2.8-12C20.58 92.51 19 90.3 19 87.43c0-3.62 2.32-6.35 4.87-8.68 2.86-2.61-1.39-6.84-4.24-4.24ZM55.6 88c-9.62 2.3-11.4 12.24-7 20 3 5.23 7.65 11.16 5.78 17.61-1.37 4.72-5.26 7.5-5.63 12.71-.27 3.85 5.73 3.83 6 0s3.7-6.47 5-9.88a18.49 18.49 0 0 0 0-11.76c-1.83-6.1-14.25-20.06-2.57-22.86 3.75-.89 2.16-6.68-1.6-5.78ZM78.89 84.18c10 4.89.34 21.37 1.44 29.69.56 4.26 2.72 7.27 5.31 10.55 4.11 5.2 5.53 10.92 2 17-1.93 3.35 3.26 6.38 5.18 3a20 20 0 0 0 1.93-16.37c-2.06-6.19-8.63-9.79-8.63-16.72 0-10.37 9-25.92-4.23-32.35-3.46-1.69-6.51 3.48-3 5.18Z" class="cls-1" />
</g>
</g>
</svg>
</template>
<style scoped>
</style>

View File

@@ -71,6 +71,18 @@ function resolveStatus(status: string) {
return bookRecommendationStore.statusOptions.find(option => option.value === status)
}
const rows = computed(() => {
// return all bookRecommendationStore.recommendations but add actions
return bookRecommendationStore.recommendations.map((recommendation) => {
return {
...recommendation,
actions: {
class: '!max-w-96',
},
}
})
})
onMounted(() => {
$echo.private(`BookRecommendation`)
.listen('.BookRecommendationUpdated', (e) => {
@@ -83,24 +95,24 @@ onMounted(() => {
bookRecommendationStore.createRecommendationWS(e.bookRecommendation)
})
authStore.socketId = $echo.socketId()
$echo.private(`Vote`)
.listen('.VoteCreated', (e) => {
bookRecommendationStore.createVoteWS(e.vote)
})
})
</script>
<template>
<div>
<NewBookRecommendation />
<UTable :sort="sort" :loading="bookRecommendationStore.fetchRecommendationsStatus === 'pending'" :columns="columns" :rows="bookRecommendationStore.recommendations">
<UTable :ui="{ td: { base: 'max-w-[0] truncate' } }" :sort="sort" :loading="bookRecommendationStore.fetchRecommendationsStatus === 'pending'" :columns="columns" :rows="rows">
<template #created_at-data="{ row }">
<div>{{ dayjs(row.created_at).format('DD.MM.YYYY') }}</div>
</template>
<template #published_at-data="{ row }">
<div>{{ dayjs(row.published_at).format('DD.MM.YYYY') }}</div>
</template>
<template #description-data="{ row }">
<div v-if="row.description">
{{ `${row.description.substring(0, 50)}...` }}
</div>
</template>
<template #votes-data="{ row }">
{{ row.votes.length }}
</template>
@@ -110,7 +122,7 @@ onMounted(() => {
</UBadge>
</template>
<template #actions-data="{ row }">
<div class="flex space-x-2">
<div class="flex max-w-full space-x-2">
<CastVote :row="row" />
<EditBookRecommendation :row="row" />
<DeleteBookRecommendation :row="row" />

View File

@@ -17,12 +17,12 @@ const dayjs = useDayjs()
<div class="hidden w-1/5 md:block">
<img :src="$storage(props.book.cover_image)" :alt="props.book.book_name" class="rounded-lg">
</div>
<div class="w-4/5 space-y-4">
<div class="w-full space-y-4 md:w-4/5">
<div class="space-y-2">
<h1 class="font-sans text-3xl font-bold">
{{ props.book.book_name }}
</h1>
<div class="flex justify-between">
<div class="flex flex-col flex-wrap gap-y-2 md:flex-row md:justify-between">
<div>
<UBadge>
{{ props.book.author }}

View File

@@ -4,6 +4,8 @@ import ConfirmUserDeadline from '~/components/modal/ConfirmUserDeadline.vue'
const props = defineProps<{
bookRecommendationId: number
}>()
const { $echo } = useNuxtApp()
const authStore = useAuthStore()
const { refresh: deadlineRefresh, status: deadlineStatus, data: deadlines } = useFetch(() => `book-recommendations/${props.bookRecommendationId}/deadlines`)
@@ -40,6 +42,13 @@ const rows = computed(() => {
}
})
})
onMounted(() => {
$echo.private(`Deadline`)
.listen('.DeadlineCreated', (e) => {
deadlineRefresh()
})
})
</script>
<template>

View File

@@ -13,8 +13,8 @@ async function runJobs(job: string) {
</script>
<template>
<div class="flex gap-4">
<UCard class="w-1/2">
<div class="flex flex-col gap-4 md:flex-row">
<UCard class="w-full md:w-1/2">
<template #header>
<h1 class="font-sans text-3xl font-bold">
Server Jobs
@@ -24,7 +24,7 @@ async function runJobs(job: string) {
</UButton>
</template>
</UCard>
<UCard class="w-1/2">
<UCard class="w-full md:w-1/2">
<template #header>
<h1 class="font-sans text-3xl font-bold">
Server Logs

View File

@@ -6,7 +6,7 @@ definePageMeta({ middleware: ['role-admin'] })
<template>
<div>
<UCard class="w-1/2">
<UCard class="w-full md:w-1/2">
<template #header>
<h1 class="font-sans text-3xl font-bold">
Benutzer Aktionen

View File

@@ -65,9 +65,9 @@ async function handleMessage(event: { data: any }): Promise<void> {
<div class="mx-auto flex min-h-screen w-full items-center justify-center">
<UCard class="w-96">
<template #header>
<h1 class="text-center text-2xl font-bold">
Login
</h1>
<div class="text-center text-4xl font-bold">
<Logo />
</div>
</template>
<UForm ref="form" :state="state" class="space-y-4" @submit="onSubmit">

View File

@@ -43,7 +43,6 @@ export default defineNuxtPlugin({
// Conditionally add X-Socket-ID header if socket is connected
if (auth.isLoggedIn && auth.socketId) {
console.log('auth.socketId', auth.socketId)
const socketHeaders = {
'X-Socket-ID': auth.socketId,
}

View File

@@ -123,6 +123,17 @@ export const useBookRecommendationStore = defineStore('bookRecommendations', ()
})
}
const createVoteWS = async (data: Partial<Vote>) => {
const index = recommendations.value.findIndex(r => r.id === data.book_recommendation_id)
// check if vote already exists otherwise add an empty array
if (index !== -1) {
if (!recommendations.value[index]?.votes) {
recommendations.value[index].votes = []
}
recommendations.value[index].votes.push(data)
}
}
function resetRecommendations() {
recommendations.value = []
}
@@ -133,6 +144,7 @@ export const useBookRecommendationStore = defineStore('bookRecommendations', ()
updateRecommendationWS,
deleteRecommendationWS,
createRecommendationWS,
createVoteWS,
statusOptions,
fetchRecommendations,
fetchRecommendationsStatus,

View File

@@ -9,3 +9,11 @@ Broadcast::channel('App.Models.User.{ulid}', function ($user, $ulid) {
Broadcast::channel('BookRecommendation', function ($user) {
return $user;
});
Broadcast::channel('Vote', function ($user) {
return $user;
});
Broadcast::channel('Deadline', function ($user) {
return $user;
});