Kleinanzeigen-Plugin 1.0.0
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
f05c44733f
50 changed files with 3854 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
*.zip
|
||||
33
README.md
Normal file
33
README.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Kleinanzeigen – Plugin für Inhaus
|
||||
|
||||
Der Kleinanzeigenmarkt im Mitarbeiterportal – von Kolleginnen und Kollegen für Kolleginnen und Kollegen.
|
||||
|
||||
- **Verkaufe, Verschenke, Suche, Tausche** in 13 Kategorien (Möbel, Kinder, Fahrräder, Mitfahrgelegenheit, Hilfe …),
|
||||
Preis mit „VB“, Ort bzw. Abholung, optional Telefon, bis zu 8 Fotos (werden verkleinert).
|
||||
- **Freigabe durch die Moderation**: Neue Anzeigen – und inhaltliche Änderungen an freigegebenen – erscheinen erst nach
|
||||
Prüfung durch Personen mit dem Recht **„Kleinanzeigen freigeben und moderieren“**. Zurückgeben mit Begründung.
|
||||
- **30 Tage Laufzeit**, Erinnerung drei Tage vorher, mit einem Klick verlängern; „reserviert“ und „erledigt“ markieren.
|
||||
- **Kontakt**: „Im Chat schreiben“, wenn das Plugin *Nachrichten* (inhaus-plugin-chat) aktiv ist – sonst per E-Mail
|
||||
(die Adresse der anbietenden Person bleibt verborgen, geantwortet wird direkt).
|
||||
- **Merkliste**, **Suche** und Filter, Anzeigen **melden**, Kachel auf der Startseite, Treffer in der globalen Suche,
|
||||
Abschnitt im Wochenüberblick.
|
||||
- Fotos liegen nicht im öffentlichen Ordner – nur angemeldete Mitarbeitende sehen sie.
|
||||
|
||||
Voraussetzung: Inhaus **0.39.0** oder neuer. Optional: Plugin *Nachrichten* für den Kontakt per Chat.
|
||||
|
||||
## Installation
|
||||
|
||||
1. `kleinanzeigen-<version>.zip` unter https://git.loheide.cloud/friloo/inhaus-plugin-kleinanzeigen/releases laden.
|
||||
2. Backend → **Plugins** → hochladen → aktivieren. Updates erscheinen danach automatisch.
|
||||
3. Unter **Rollen** das Recht **„Kleinanzeigen freigeben und moderieren“** vergeben. Ohne solche Rolle geht die Freigabe
|
||||
an die Administration.
|
||||
|
||||
## Entwicklung
|
||||
|
||||
```bash
|
||||
npm install && npm run build # dist/ wird eingecheckt
|
||||
npm run package # kleinanzeigen-<version>.zip
|
||||
```
|
||||
|
||||
Tests laufen in einer Inhaus-Installation mit dem Plugin unter `plugins/kleinanzeigen`:
|
||||
`vendor-dev/bin/phpunit plugins/kleinanzeigen/tests` (der Chat-Test läuft nur, wenn auch `plugins/chat` vorhanden ist).
|
||||
29
bin/package
Executable file
29
bin/package
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Baut kleinanzeigen-<version>.zip zum Hochladen unter Administration → Plugins.
|
||||
* Enthält alles außer Quelltexten fürs Frontend-Build und node_modules.
|
||||
*/
|
||||
$root = dirname(__DIR__);
|
||||
$manifest = json_decode(file_get_contents("{$root}/plugin.json"), true);
|
||||
$target = "{$root}/kleinanzeigen-{$manifest['version']}.zip";
|
||||
$skip = ['node_modules', '.git', 'inhaus-sdk', 'package.json', 'package-lock.json', 'vite.config.js', basename($target)];
|
||||
|
||||
@unlink($target);
|
||||
$zip = new ZipArchive;
|
||||
$zip->open($target, ZipArchive::CREATE);
|
||||
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS));
|
||||
|
||||
foreach ($files as $file) {
|
||||
$relative = substr($file->getPathname(), strlen($root) + 1);
|
||||
|
||||
if (in_array(explode(DIRECTORY_SEPARATOR, $relative)[0], $skip, true) || str_ends_with($relative, '.zip')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$zip->addFile($file->getPathname(), 'kleinanzeigen/'.$relative);
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
echo "Paket: {$target}\n";
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('kleinanzeigen_listings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('type', 10); // sell | give | search | swap
|
||||
$table->string('category', 30);
|
||||
$table->string('title', 120);
|
||||
$table->text('description');
|
||||
$table->unsignedInteger('price_cents')->nullable();
|
||||
$table->boolean('negotiable')->default(false);
|
||||
$table->string('location', 120)->nullable();
|
||||
$table->string('phone', 40)->nullable();
|
||||
// pending | active | rejected | done | expired
|
||||
$table->string('status', 10)->default('pending');
|
||||
$table->boolean('reserved')->default(false);
|
||||
$table->string('review_note', 500)->nullable();
|
||||
$table->foreignId('reviewed_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamp('published_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamp('reminded_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['status', 'published_at']);
|
||||
$table->index(['user_id', 'status']);
|
||||
});
|
||||
|
||||
Schema::create('kleinanzeigen_images', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('listing_id')->constrained('kleinanzeigen_listings')->cascadeOnDelete();
|
||||
$table->string('path', 300);
|
||||
$table->string('thumb_path', 300);
|
||||
$table->unsignedInteger('width')->nullable();
|
||||
$table->unsignedInteger('height')->nullable();
|
||||
$table->unsignedSmallInteger('sort')->default(0);
|
||||
});
|
||||
|
||||
Schema::create('kleinanzeigen_favorites', function (Blueprint $table) {
|
||||
$table->foreignId('listing_id')->constrained('kleinanzeigen_listings')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->timestamp('created_at')->nullable();
|
||||
|
||||
$table->primary(['listing_id', 'user_id']);
|
||||
});
|
||||
|
||||
Schema::create('kleinanzeigen_reports', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('listing_id')->constrained('kleinanzeigen_listings')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('reason', 500);
|
||||
$table->timestamp('resolved_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['listing_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
foreach (['kleinanzeigen_reports', 'kleinanzeigen_favorites', 'kleinanzeigen_images', 'kleinanzeigen_listings'] as $table) {
|
||||
Schema::dropIfExists($table);
|
||||
}
|
||||
}
|
||||
};
|
||||
2
dist/assets/style-CAm2qtFB.css
vendored
Normal file
2
dist/assets/style-CAm2qtFB.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/chunks/ListingCard-DfH_TzXE.js
vendored
Normal file
1
dist/chunks/ListingCard-DfH_TzXE.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"./createLucideIcon-CYyWUN7r.js";import{t}from"./heart-CyCnSX5a.js";import{t as n}from"./image-off-BfSjK3tM.js";import{createBlock as r,createCommentVNode as i,createElementBlock as a,createElementVNode as o,createTextVNode as s,createVNode as c,normalizeClass as l,openBlock as u,toDisplayString as d,unref as f,withCtx as p}from"vue";import{Link as m,router as h}from"@inertiajs/vue3";var g=e({name:`camera`,size:24,node:[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]}),_=e({name:`map-pin`,size:24,node:[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]}),v={class:`ih:group ih:relative ih:flex ih:flex-col ih:overflow-hidden ih:rounded-lg ih:border ih:bg-card ih:shadow-xs ih:transition-shadow ih:hover:shadow-md`},y=[`src`,`alt`],b={key:1,class:`ih:grid ih:size-full ih:place-items-center ih:text-muted-foreground`},x={class:`ih:absolute ih:top-2 ih:left-2 ih:rounded ih:bg-card/95 ih:px-1.5 ih:py-0.5 ih:text-[11px] ih:font-semibold ih:shadow-xs`},S={key:2,class:`ih:absolute ih:bottom-2 ih:left-2 ih:rounded ih:bg-foreground/85 ih:px-1.5 ih:py-0.5 ih:text-[11px] ih:font-semibold ih:text-background`},C={key:3,class:`ih:absolute ih:right-2 ih:bottom-2 ih:inline-flex ih:items-center ih:gap-1 ih:rounded ih:bg-foreground/70 ih:px-1.5 ih:py-0.5 ih:text-[11px] ih:text-background`},w=[`aria-pressed`,`aria-label`],T={class:`ih:flex ih:flex-1 ih:flex-col ih:gap-1 ih:p-3`},E={key:0,class:`ih:text-[15px] ih:font-semibold ih:text-brand-text`},D={key:1,class:`ih:mt-auto ih:flex ih:items-center ih:gap-1 ih:pt-1 ih:text-xs ih:text-muted-foreground`},O={class:`ih:truncate`},k={__name:`ListingCard`,props:{listing:{type:Object,required:!0},compact:{type:Boolean,default:!1}},setup(e){let k=e;function A(){let e=k.listing;e.favorite=!e.favorite,h.visit(`/kleinanzeigen/${e.id}/merken`,{method:e.favorite?`post`:`delete`,preserveScroll:!0,preserveState:!0})}return(h,k)=>(u(),a(`article`,v,[c(f(m),{href:e.listing.url,class:`ih:relative ih:block ih:aspect-[4/3] ih:overflow-hidden ih:bg-muted`},{default:p(()=>[e.listing.thumb_url?(u(),a(`img`,{key:0,src:e.listing.thumb_url,alt:e.listing.title,loading:`lazy`,class:`ih:size-full ih:object-cover ih:transition-transform ih:duration-300 ih:group-hover:scale-[1.03]`},null,8,y)):(u(),a(`span`,b,[c(f(n),{class:`ih:size-8`,"stroke-width":1.5})])),o(`span`,x,d(e.listing.type_label),1),e.listing.reserved?(u(),a(`span`,S,`Reserviert`)):i(``,!0),e.listing.images>1?(u(),a(`span`,C,[c(f(g),{class:`ih:size-3`}),s(d(e.listing.images),1)])):i(``,!0)]),_:1},8,[`href`]),o(`button`,{type:`button`,class:l([`ih:absolute ih:top-2 ih:right-2 ih:grid ih:size-8 ih:place-items-center ih:rounded-full ih:bg-card/95 ih:shadow-xs ih:transition-colors ih:hover:text-brand-text`,e.listing.favorite?`ih:text-brand-text`:`ih:text-muted-foreground`]),"aria-pressed":e.listing.favorite,"aria-label":e.listing.favorite?`Von der Merkliste nehmen`:`Merken`,onClick:A},[c(f(t),{class:l([`ih:size-4`,e.listing.favorite?`ih:fill-current`:``])},null,8,[`class`])],10,w),o(`div`,T,[e.listing.price?(u(),a(`p`,E,d(e.listing.price),1)):i(``,!0),c(f(m),{href:e.listing.url,class:`ih:line-clamp-2 ih:text-sm ih:leading-snug ih:font-medium ih:hover:underline`},{default:p(()=>[s(d(e.listing.title),1)]),_:1},8,[`href`]),e.compact?i(``,!0):(u(),a(`p`,D,[e.listing.location?(u(),r(f(_),{key:0,class:`ih:size-3 ih:shrink-0`})):i(``,!0),o(`span`,O,d([e.listing.location,e.listing.category_label].filter(Boolean).join(` · `)),1)]))])]))}};export{_ as n,k as t};
|
||||
1
dist/chunks/createLucideIcon-CYyWUN7r.js
vendored
Normal file
1
dist/chunks/createLucideIcon-CYyWUN7r.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{h as e,inject as t}from"vue";var n={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":2,"stroke-linecap":`round`,"stroke-linejoin":`round`},r=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim();function i(e){return e!=null}function a(e,t={}){let a=t.attributeNames??{},o=e=>a[e]??e,s=e.size??e.width??n.width,c=e.size??e.height??n.height,l=e.aliases?.filter(e=>typeof e==`string`&&e.trim()!==``).map(e=>`lucide-${e}`)??[],u=[...e.name?[`lucide-${e.name}`]:[],...l],d=t.className?.split(` `).filter(Boolean)??[],f=t.includeDefaultClasses===!1?r(...d):r(`lucide`,...u,...d),p=t.absoluteStrokeWidth?Number(t.strokeWidth??n[`stroke-width`])*Number(e.size??e.width??n.width)/Number(t.size??t.width??n.width):t.strokeWidth??n[`stroke-width`];return[`svg`,{...Object.entries(n).reduce((e,[t,n])=>(e[o(t)]=n,e),{}),...`color`in t&&t.color&&{[o(`stroke`)]:t.color},...`size`in t&&i(t.size)&&{[o(`width`)]:t.size,[o(`height`)]:t.size},...`width`in t&&i(t.width)&&{[o(`width`)]:t.width},...`height`in t&&i(t.height)&&{[o(`height`)]:t.height},[o(`stroke-width`)]:p,...f&&{[o(`class`)]:f},[o(`viewBox`)]:`0 0 ${s} ${c}`,...t.hasA11yProp===!1?{[o(`aria-hidden`)]:`true`}:{},...`attributes`in t&&t.attributes},e.node.map(e=>{let[n,r,i]=e,a=t.nonScalingStroke?{[o(`vector-effect`)]:`non-scaling-stroke`,...r}:r;return i?[n,a,i]:[n,a]})]}var o=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},s=e=>e===``,c=e=>e?.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),l=Symbol(`lucide-icons`);function u(){return t(l,{})}var d=({name:t,iconNode:n,"icon-node":r,icon:i={name:t&&c(t),node:n??r??[],size:24,aliases:[]},absoluteStrokeWidth:l,"absolute-stroke-width":d,nonScalingStroke:f,"non-scaling-stroke":p,strokeWidth:m,"stroke-width":h,size:g,width:_=g,height:v=g,color:y,...b},{slots:x})=>{let{size:S,color:C,strokeWidth:w=2,absoluteStrokeWidth:T=!1,nonScalingStroke:E=!1,class:D=``}=u(),O=s(l)||s(d)||l===!0||d===!0||T===!0,k=s(f)||s(p)||f===!0||p===!0||E===!0;delete b.class;let A=x.default?.(),[,j,M=[]]=a(i,{color:y??C,width:_??g??S,height:v??g??S,strokeWidth:m??h??w,absoluteStrokeWidth:O,nonScalingStroke:k,className:D,hasA11yProp:A!=null&&A.length>0||o(b),attributes:b});return e(`svg`,j,[...M.map(([t,n])=>e(t,n)),...A??[]])};function f(t,n=[]){let r=typeof t==`string`?{name:t,node:n}:t;return(t,{slots:n})=>e(d,{...t,icon:r},n.default?{default:n.default}:void 0)}export{f as t};
|
||||
1
dist/chunks/flag-DsBVcwMd.js
vendored
Normal file
1
dist/chunks/flag-DsBVcwMd.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"./createLucideIcon-CYyWUN7r.js";var t=e({name:`flag`,size:24,node:[[`path`,{d:`M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528`,key:`1jaruq`}]]});export{t};
|
||||
1
dist/chunks/heart-CyCnSX5a.js
vendored
Normal file
1
dist/chunks/heart-CyCnSX5a.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"./createLucideIcon-CYyWUN7r.js";var t=e({name:`heart`,size:24,node:[[`path`,{d:`M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5`,key:`mvr1a0`}]]});export{t};
|
||||
1
dist/chunks/image-off-BfSjK3tM.js
vendored
Normal file
1
dist/chunks/image-off-BfSjK3tM.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"./createLucideIcon-CYyWUN7r.js";var t=e({name:`image-off`,size:24,node:[[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}],[`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`,key:`1bzlo9`}],[`line`,{x1:`13.5`,x2:`6`,y1:`13.5`,y2:`21`,key:`1q0aeu`}],[`line`,{x1:`18`,x2:`21`,y1:`12`,y2:`15`,key:`5mozeu`}],[`path`,{d:`M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59`,key:`mmje98`}],[`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`,key:`43el77`}]]});export{t};
|
||||
1
dist/chunks/loader-circle-DBP4Qhm5.js
vendored
Normal file
1
dist/chunks/loader-circle-DBP4Qhm5.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"./createLucideIcon-CYyWUN7r.js";var t=e({name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]}),n=e({name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]});export{t as n,n as t};
|
||||
1
dist/chunks/plus-CThDQH9c.js
vendored
Normal file
1
dist/chunks/plus-CThDQH9c.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"./createLucideIcon-CYyWUN7r.js";var t=e({name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]});export{t};
|
||||
1
dist/chunks/shield-check-CrHENMih.js
vendored
Normal file
1
dist/chunks/shield-check-CrHENMih.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"./createLucideIcon-CYyWUN7r.js";var t=e({name:`shield-check`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]});export{t};
|
||||
1
dist/chunks/trash-DzQOFBxr.js
vendored
Normal file
1
dist/chunks/trash-DzQOFBxr.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"./createLucideIcon-CYyWUN7r.js";var t=e({name:`pencil-line`,size:24,node:[[`path`,{d:`M13 21h8`,key:`1jsn5i`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}],[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}]]}),n=e({name:`trash`,size:24,node:[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]],aliases:[`trash-2`]});export{t as n,n as t};
|
||||
1
dist/editorial/EditorialListings.js
vendored
Normal file
1
dist/editorial/EditorialListings.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{Fragment as e,createBlock as t,createCommentVNode as n,createElementBlock as r,createElementVNode as i,createTextVNode as a,createVNode as o,openBlock as s,renderList as c,toDisplayString as l,unref as u,withCtx as d}from"vue";import{Link as f}from"@inertiajs/vue3";import{Panel as p}from"@inhaus/ui";var m={key:0,class:`ih:-mx-5 ih:divide-y ih:border-t`},h=[`src`],g={class:`ih:shrink-0 ih:text-xs ih:text-muted-foreground`},_={key:1,class:`ih:text-sm ih:text-muted-foreground`},v={__name:`EditorialListings`,props:{pending:{type:Array,required:!0}},setup(v){return(y,b)=>(s(),t(u(p),{title:`Kleinanzeigen – Freigabe`,"action-label":`Zur Freigabe`,"action-href":`/kleinanzeigen/moderation`},{default:d(()=>[v.pending.length?(s(),r(`ul`,m,[(s(!0),r(e,null,c(v.pending,e=>(s(),r(`li`,{key:e.id,class:`ih:flex ih:items-center ih:gap-3 ih:px-5 ih:py-2.5`},[e.thumb_url?(s(),r(`img`,{key:0,src:e.thumb_url,alt:``,class:`ih:size-10 ih:rounded ih:object-cover`},null,8,h)):n(``,!0),o(u(f),{href:e.url,class:`ih:min-w-0 ih:flex-1 ih:truncate ih:text-sm ih:font-medium ih:hover:underline`},{default:d(()=>[a(l(e.title),1)]),_:2},1032,[`href`]),i(`span`,g,l(e.type_label),1)]))),128))])):(s(),r(`p`,_,`Keine Anzeigen warten auf Freigabe.`))]),_:1}))}};export{v as default};
|
||||
14
dist/inhaus.json
vendored
Normal file
14
dist/inhaus.json
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"components": {
|
||||
"editorial/EditorialListings": "editorial/EditorialListings.js",
|
||||
"pages/Editor": "pages/Editor.js",
|
||||
"pages/Index": "pages/Index.js",
|
||||
"pages/Mine": "pages/Mine.js",
|
||||
"pages/Moderation": "pages/Moderation.js",
|
||||
"pages/Show": "pages/Show.js",
|
||||
"widgets/Latest": "widgets/Latest.js"
|
||||
},
|
||||
"css": [
|
||||
"assets/style-CAm2qtFB.css"
|
||||
]
|
||||
}
|
||||
1
dist/pages/Editor.js
vendored
Normal file
1
dist/pages/Editor.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/pages/Index.js
vendored
Normal file
1
dist/pages/Index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/pages/Mine.js
vendored
Normal file
1
dist/pages/Mine.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/pages/Moderation.js
vendored
Normal file
1
dist/pages/Moderation.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"../chunks/createLucideIcon-CYyWUN7r.js";import{t}from"../chunks/flag-DsBVcwMd.js";import{t as n}from"../chunks/image-off-BfSjK3tM.js";import{Fragment as r,createBlock as i,createCommentVNode as a,createElementBlock as o,createElementVNode as s,createTextVNode as c,createVNode as l,openBlock as u,ref as d,renderList as f,toDisplayString as p,unref as m,watch as h,withCtx as g}from"vue";import{Link as _,router as v,usePage as y}from"@inertiajs/vue3";import{AppLayout as b,Button as x,EmptyState as S,PageHeader as C,Panel as w,Textarea as T,toast as E}from"@inhaus/ui";var D=e({name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]}),O=e({name:`undo-2`,size:24,node:[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]}),k={class:`ih:-mx-5 ih:divide-y ih:border-t`},A={class:`ih:min-w-0 ih:flex-1`},j={class:`ih:text-xs ih:text-muted-foreground`},M={key:1,class:`ih:grid ih:gap-4`},N={class:`ih:grid ih:grid-cols-3 ih:content-start ih:gap-1 ih:md:grid-cols-2`},P=[`src`],F={key:0,class:`ih:col-span-2 ih:grid ih:aspect-[4/3] ih:place-items-center ih:rounded ih:bg-muted ih:text-muted-foreground`},I={class:`ih:min-w-0`},L={class:`ih:text-xs ih:text-muted-foreground`},R={key:0,class:`ih:font-medium ih:text-brand-text`},z={class:`ih:mt-2 ih:line-clamp-4 ih:text-sm ih:whitespace-pre-line`},B={key:1,class:`ih:mt-3 ih:grid ih:gap-2`},V={class:`ih:flex ih:gap-2`},H={key:2,class:`ih:mt-3 ih:flex ih:gap-2`},U={key:2,class:`ih:rounded-lg ih:border ih:bg-card`},W={__name:`Moderation`,props:{pending:{type:Array,required:!0},reported:{type:Array,required:!0}},setup(e){let W=y();h(()=>W.props.flash?.status,e=>e&&E.success(e),{immediate:!0});let G=d({}),K=d(null),q=e=>v.post(`/kleinanzeigen/${e.id}/freigeben`,{},{preserveScroll:!0});function J(e){v.post(`/kleinanzeigen/${e.id}/zurueckgeben`,{note:G.value[e.id]??``},{preserveScroll:!0,onSuccess:()=>K.value=null})}let Y=(e,t)=>v.post(`/kleinanzeigen/${e.id}/meldungen`,{action:t},{preserveScroll:!0});return(d,h)=>(u(),i(m(b),{title:`Kleinanzeigen – Freigabe`},{default:g(()=>[l(m(C),{title:`Freigabe`,description:`Neue und geänderte Anzeigen prüfen. Die anbietende Person bekommt Bescheid.`,breadcrumbs:[{label:`Kleinanzeigen`,href:`/kleinanzeigen`}]}),e.reported.length?(u(),i(m(w),{key:0,title:`Gemeldet`,class:`ih:mb-6`},{default:g(()=>[s(`ul`,k,[(u(!0),o(r,null,f(e.reported,e=>(u(),o(`li`,{key:e.id,class:`ih:flex ih:flex-wrap ih:items-center ih:gap-3 ih:px-5 ih:py-3`},[l(m(t),{class:`ih:size-4 ih:shrink-0 ih:text-destructive`}),s(`div`,A,[l(m(_),{href:e.url,class:`ih:font-medium ih:hover:underline`},{default:g(()=>[c(p(e.title),1)]),_:2},1032,[`href`]),s(`p`,j,p(e.seller)+` · `+p(e.reasons.join(` / `)),1)]),l(m(x),{size:`sm`,variant:`outline`,onClick:t=>Y(e,`keep`)},{default:g(()=>[...h[1]||=[c(`In Ordnung`,-1)]]),_:1},8,[`onClick`]),l(m(x),{size:`sm`,variant:`outline`,class:`ih:text-destructive ih:hover:text-destructive`,onClick:t=>Y(e,`remove`)},{default:g(()=>[...h[2]||=[c(`Offline nehmen`,-1)]]),_:1},8,[`onClick`])]))),128))])]),_:1})):a(``,!0),e.pending.length?(u(),o(`div`,M,[(u(!0),o(r,null,f(e.pending,e=>(u(),o(`article`,{key:e.id,class:`ih:grid ih:gap-4 ih:rounded-lg ih:border ih:bg-card ih:p-4 ih:shadow-xs ih:md:grid-cols-[12rem_minmax(0,1fr)]`},[s(`div`,N,[(u(!0),o(r,null,f(e.photos.slice(0,4),e=>(u(),o(`img`,{key:e.id,src:e.thumb_url,alt:``,class:`ih:aspect-[4/3] ih:w-full ih:rounded ih:object-cover`},null,8,P))),128)),e.photos.length?a(``,!0):(u(),o(`span`,F,[l(m(n),{class:`ih:size-6`})]))]),s(`div`,I,[s(`p`,L,p(e.type_label)+` · `+p(e.category_label)+` · von `+p(e.seller?.name),1),l(m(_),{href:e.url,class:`ih:text-lg ih:font-semibold ih:hover:underline`},{default:g(()=>[c(p(e.title),1)]),_:2},1032,[`href`]),e.price?(u(),o(`p`,R,p(e.price),1)):a(``,!0),s(`p`,z,p(e.description),1),K.value===e.id?(u(),o(`div`,B,[l(m(T),{modelValue:G.value[e.id],"onUpdate:modelValue":t=>G.value[e.id]=t,rows:`2`,maxlength:`500`,placeholder:`Begründung für die anbietende Person`,"aria-label":`Begründung`},null,8,[`modelValue`,`onUpdate:modelValue`]),s(`div`,V,[l(m(x),{size:`sm`,disabled:!(G.value[e.id]??``).trim(),onClick:t=>J(e)},{default:g(()=>[...h[3]||=[c(`Zurückgeben`,-1)]]),_:1},8,[`disabled`,`onClick`]),l(m(x),{size:`sm`,variant:`ghost`,onClick:h[0]||=e=>K.value=null},{default:g(()=>[...h[4]||=[c(`Abbrechen`,-1)]]),_:1})])])):(u(),o(`div`,H,[l(m(x),{size:`sm`,onClick:t=>q(e)},{default:g(()=>[l(m(D)),h[5]||=c(` Freigeben`,-1)]),_:1},8,[`onClick`]),l(m(x),{size:`sm`,variant:`outline`,onClick:t=>K.value=e.id},{default:g(()=>[l(m(O)),h[6]||=c(` Zurückgeben …`,-1)]),_:1},8,[`onClick`])]))])]))),128))])):(u(),o(`div`,U,[l(m(S),{icon:m(D),title:`Alles erledigt`,text:`Keine Anzeigen warten auf Freigabe.`},null,8,[`icon`])]))]),_:1}))}};export{W as default};
|
||||
1
dist/pages/Show.js
vendored
Normal file
1
dist/pages/Show.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/widgets/Latest.js
vendored
Normal file
1
dist/widgets/Latest.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
import{t as e}from"../chunks/ListingCard-DfH_TzXE.js";import{Fragment as t,createBlock as n,createElementBlock as r,createElementVNode as i,openBlock as a,renderList as o,unref as s,withCtx as c}from"vue";import{Panel as l}from"@inhaus/ui";var u={class:`ih:grid ih:grid-cols-2 ih:gap-2`},d={__name:`Latest`,props:{listings:{type:Array,required:!0}},setup(d){return(f,p)=>(a(),n(s(l),{title:`Kleinanzeigen`,"action-label":`Alle Anzeigen`,"action-href":`/kleinanzeigen`},{default:c(()=>[i(`div`,u,[(a(!0),r(t,null,o(d.listings,t=>(a(),n(e,{key:t.id,listing:t,compact:``},null,8,[`listing`]))),128))])]),_:1}))}};export{d as default};
|
||||
63
inhaus-sdk/theme.css
Normal file
63
inhaus-sdk/theme.css
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Automatisch erzeugt (scripts/generate-sdk-shims.mjs) – Design-Tokens des Portals.
|
||||
* In der style.css eines Plugins: @import "../../inhaus-sdk/theme.css";
|
||||
* Farben, Ecken und Schrift folgen so dem Erscheinungsbild der Installation.
|
||||
*
|
||||
* Tailwind-Klassen in Plugins tragen das Präfix „ih:“ (z. B. ih:grid, ih:lg:grid-cols-2, ih:bg-brand).
|
||||
* So kann das CSS eines Plugins nie die Klassen des Portals überschreiben.
|
||||
* Nur Hilfsklassen – Grundstile (Preflight) bringt das Portal selbst mit.
|
||||
*/
|
||||
@import "tailwindcss/theme" layer(theme) prefix(ih);
|
||||
@import "tailwindcss/utilities" layer(utilities);
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
@theme inline {
|
||||
--font-sans: var(--font-body);
|
||||
|
||||
--radius-sm: calc(var(--radius) - 4px);
|
||||
--radius-md: calc(var(--radius) - 2px);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) * 1.5);
|
||||
--radius-2xl: calc(var(--radius) * 2);
|
||||
/* „Pille“: voll gerundet – außer bei „Eckig“ im Erscheinungsbild (dann 0) */
|
||||
--radius-pill: calc(var(--radius) * 1000);
|
||||
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-card: var(--card);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-border: var(--border);
|
||||
--color-input: var(--input);
|
||||
--color-ring: var(--ring);
|
||||
|
||||
--color-brand: var(--brand);
|
||||
--color-brand-foreground: var(--brand-foreground);
|
||||
--color-brand-text: var(--brand-text);
|
||||
--color-accent2: var(--accent2);
|
||||
--color-accent2-foreground: var(--accent2-foreground);
|
||||
--color-accent2-text: var(--accent2-text);
|
||||
--color-brand-soft: var(--brand-soft);
|
||||
--color-brand-soft-foreground: var(--brand-soft-foreground);
|
||||
--color-brand-50: var(--brand-50);
|
||||
--color-brand-100: var(--brand-100);
|
||||
--color-brand-200: var(--brand-200);
|
||||
--color-brand-300: var(--brand-300);
|
||||
--color-brand-400: var(--brand-400);
|
||||
--color-brand-500: var(--brand-500);
|
||||
--color-brand-600: var(--brand-600);
|
||||
--color-brand-700: var(--brand-700);
|
||||
--color-brand-800: var(--brand-800);
|
||||
--color-brand-900: var(--brand-900);
|
||||
--color-brand-950: var(--brand-950);
|
||||
}
|
||||
127
inhaus-sdk/vite.js
Normal file
127
inhaus-sdk/vite.js
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/**
|
||||
* Vite-Voreinstellung für Inhaus-Plugins (Plugin-SDK).
|
||||
*
|
||||
* // vite.config.js im Plugin
|
||||
* import { defineConfig } from 'vite';
|
||||
* import { inhausPlugin } from './inhaus-sdk/vite.js';
|
||||
* export default defineConfig(inhausPlugin());
|
||||
*
|
||||
* Baut jede Vue-Datei unter resources/js/{pages,widgets,blocks,profile,profile-panels,editorial,header}/
|
||||
* als eigenes ES-Modul nach dist/ und schreibt dist/inhaus.json. Vue, Inertia und @inhaus/ui
|
||||
* bleiben extern – das Portal stellt sie per Import Map bereit.
|
||||
*/
|
||||
import { existsSync, globSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import postcss from 'postcss';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
|
||||
export const KINDS = ['pages', 'widgets', 'blocks', 'profile', 'profile-panels', 'editorial', 'header'];
|
||||
export const EXTERNAL = ['vue', '@inertiajs/vue3', '@inhaus/ui'];
|
||||
|
||||
export function inhausPlugin({ root = process.cwd() } = {}) {
|
||||
const input = {};
|
||||
|
||||
for (const kind of KINDS) {
|
||||
for (const file of globSync(`resources/js/${kind}/**/*.vue`, { cwd: root })) {
|
||||
const name = file.replace(`resources/js/${kind}/`, '').replace(/\.vue$/, '');
|
||||
input[`${kind}/${name}`] = resolve(root, file);
|
||||
}
|
||||
}
|
||||
|
||||
if (existsSync(resolve(root, 'resources/css/style.css'))) {
|
||||
input.style = resolve(root, 'resources/css/style.css');
|
||||
}
|
||||
|
||||
if (Object.keys(input).length === 0) {
|
||||
throw new Error('Keine Oberfläche gefunden: Vue-Dateien gehören nach resources/js/<pages|widgets|blocks|profile|profile-panels|editorial|header>/.');
|
||||
}
|
||||
|
||||
return {
|
||||
plugins: [vue(), tailwindcss(), manifest(Object.keys(input)), strongerVariants()],
|
||||
// Plugins laufen unter /plugin-assets/<slug>/<version>/ – Pfade relativ halten
|
||||
base: './',
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
emptyOutDir: true,
|
||||
target: 'es2022',
|
||||
rollupOptions: {
|
||||
input,
|
||||
external: EXTERNAL,
|
||||
preserveEntrySignatures: 'strict',
|
||||
output: {
|
||||
format: 'es',
|
||||
entryFileNames: '[name].js',
|
||||
chunkFileNames: 'chunks/[name]-[hash].js',
|
||||
assetFileNames: 'assets/[name]-[hash][extname]',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** dist/inhaus.json: welche Komponente in welcher Datei steckt, welches CSS dazugehört */
|
||||
function manifest(entries) {
|
||||
return {
|
||||
name: 'inhaus-manifest',
|
||||
generateBundle(_, bundle) {
|
||||
const components = {};
|
||||
const css = [];
|
||||
|
||||
for (const file of Object.values(bundle)) {
|
||||
if (file.type === 'chunk' && file.isEntry && entries.includes(file.name) && file.name !== 'style') {
|
||||
components[file.name] = file.fileName;
|
||||
}
|
||||
|
||||
if (file.type === 'asset' && file.fileName.endsWith('.css')) {
|
||||
css.push(file.fileName);
|
||||
}
|
||||
}
|
||||
|
||||
// Leere Hülle des CSS-Einstiegs nicht ausliefern
|
||||
for (const [key, file] of Object.entries(bundle)) {
|
||||
if (file.type === 'chunk' && file.name === 'style') delete bundle[key];
|
||||
}
|
||||
|
||||
this.emitFile({ type: 'asset', fileName: 'inhaus.json', source: JSON.stringify({ components, css: [...new Set(css)] }, null, 4) });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Mehrere Plugins bringen jeweils eigenes CSS mit, und dieselbe Hilfsklasse (z. B. ih:grid) kann in
|
||||
* mehreren Dateien stehen. Lädt ein anderes Plugin sein CSS später, würde dessen „ih:grid“ sonst
|
||||
* die Varianten dieses Plugins (ih:lg:hidden, ih:hover:…) überstimmen. Deshalb bekommen Regeln
|
||||
* mit Variante (Media Query, :hover …) eine doppelte Klasse – sie gewinnen so immer gegen
|
||||
* einfache Klassen, egal in welcher Reihenfolge die Dateien laden.
|
||||
*/
|
||||
export function strongerVariants() {
|
||||
const pseudo = /(?<!\\):/;
|
||||
const firstClass = /\.((?:\\.|[\w-])+)/;
|
||||
|
||||
return {
|
||||
name: 'inhaus-stronger-variants',
|
||||
enforce: 'post',
|
||||
generateBundle(_, bundle) {
|
||||
for (const file of Object.values(bundle)) {
|
||||
if (file.type !== 'asset' || !file.fileName.endsWith('.css')) continue;
|
||||
|
||||
const root = postcss.parse(String(file.source));
|
||||
|
||||
root.walkRules((rule) => {
|
||||
let conditional = false;
|
||||
|
||||
for (let parent = rule.parent; parent && parent.type !== 'root'; parent = parent.parent) {
|
||||
if (parent.type === 'atrule' && parent.name !== 'layer') conditional = true;
|
||||
}
|
||||
|
||||
rule.selectors = rule.selectors.map((selector) => (conditional || pseudo.test(selector.replace(/^[^.]*/, ''))) && firstClass.test(selector)
|
||||
? selector.replace(firstClass, (match) => match + match)
|
||||
: selector);
|
||||
});
|
||||
|
||||
file.source = root.toString();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
1712
package-lock.json
generated
Normal file
1712
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
21
package.json
Normal file
21
package.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "inhaus-plugin-kleinanzeigen",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"dev": "vite build --watch",
|
||||
"package": "vite build && php bin/package"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.3.3",
|
||||
"@vitejs/plugin-vue": "^6.0.9",
|
||||
"postcss": "^8.5.28",
|
||||
"tailwindcss": "^4.3.3",
|
||||
"vite": "^8.3.1",
|
||||
"vue": "^3.5.43"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lucide/vue": "^1.48.0"
|
||||
}
|
||||
}
|
||||
14
plugin.json
Normal file
14
plugin.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"slug": "kleinanzeigen",
|
||||
"name": "Kleinanzeigen",
|
||||
"version": "1.0.0",
|
||||
"description": "Kleinanzeigen von Kolleginnen und Kollegen für Kolleginnen und Kollegen: verkaufen, verschenken, suchen, tauschen – mit Fotos, Merkliste und Freigabe durch die Moderation. Kontakt über das Chat-Plugin oder per E-Mail.",
|
||||
"author": "Loheide",
|
||||
"namespace": "Inhaus\\Plugins\\Kleinanzeigen\\",
|
||||
"class": "Inhaus\\Plugins\\Kleinanzeigen\\KleinanzeigenPlugin",
|
||||
"requires": {
|
||||
"core": ">=0.39.1",
|
||||
"php": ">=8.3"
|
||||
},
|
||||
"update_url": "https://git.loheide.cloud/api/v1/repos/friloo/inhaus-plugin-kleinanzeigen/releases/latest"
|
||||
}
|
||||
3
resources/css/style.css
Normal file
3
resources/css/style.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/* Tailwind mit den Design-Tokens des Portals – Klassen mit Präfix „ih:“, z. B. ih:bg-brand, ih:text-muted-foreground, ih:rounded-lg */
|
||||
@import "../../inhaus-sdk/theme.css";
|
||||
@source "../js";
|
||||
43
resources/js/components/ListingCard.vue
Normal file
43
resources/js/components/ListingCard.vue
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<script setup>
|
||||
import { Link, router } from '@inertiajs/vue3';
|
||||
import { Camera, Heart, ImageOff, MapPin } from '@lucide/vue';
|
||||
|
||||
const props = defineProps({
|
||||
listing: { type: Object, required: true },
|
||||
compact: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
function toggleFavorite() {
|
||||
const l = props.listing;
|
||||
l.favorite = !l.favorite;
|
||||
router.visit(`/kleinanzeigen/${l.id}/merken`, { method: l.favorite ? 'post' : 'delete', preserveScroll: true, preserveState: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article class="ih:group ih:relative ih:flex ih:flex-col ih:overflow-hidden ih:rounded-lg ih:border ih:bg-card ih:shadow-xs ih:transition-shadow ih:hover:shadow-md">
|
||||
<Link :href="listing.url" class="ih:relative ih:block ih:aspect-[4/3] ih:overflow-hidden ih:bg-muted">
|
||||
<img v-if="listing.thumb_url" :src="listing.thumb_url" :alt="listing.title" loading="lazy" class="ih:size-full ih:object-cover ih:transition-transform ih:duration-300 ih:group-hover:scale-[1.03]" />
|
||||
<span v-else class="ih:grid ih:size-full ih:place-items-center ih:text-muted-foreground"><ImageOff class="ih:size-8" :stroke-width="1.5" /></span>
|
||||
<span class="ih:absolute ih:top-2 ih:left-2 ih:rounded ih:bg-card/95 ih:px-1.5 ih:py-0.5 ih:text-[11px] ih:font-semibold ih:shadow-xs">{{ listing.type_label }}</span>
|
||||
<span v-if="listing.reserved" class="ih:absolute ih:bottom-2 ih:left-2 ih:rounded ih:bg-foreground/85 ih:px-1.5 ih:py-0.5 ih:text-[11px] ih:font-semibold ih:text-background">Reserviert</span>
|
||||
<span v-if="listing.images > 1" class="ih:absolute ih:right-2 ih:bottom-2 ih:inline-flex ih:items-center ih:gap-1 ih:rounded ih:bg-foreground/70 ih:px-1.5 ih:py-0.5 ih:text-[11px] ih:text-background"><Camera class="ih:size-3" />{{ listing.images }}</span>
|
||||
</Link>
|
||||
<button
|
||||
type="button"
|
||||
class="ih:absolute ih:top-2 ih:right-2 ih:grid ih:size-8 ih:place-items-center ih:rounded-full ih:bg-card/95 ih:shadow-xs ih:transition-colors ih:hover:text-brand-text"
|
||||
:class="listing.favorite ? 'ih:text-brand-text' : 'ih:text-muted-foreground'"
|
||||
:aria-pressed="listing.favorite"
|
||||
:aria-label="listing.favorite ? 'Von der Merkliste nehmen' : 'Merken'"
|
||||
@click="toggleFavorite"
|
||||
><Heart class="ih:size-4" :class="listing.favorite ? 'ih:fill-current' : ''" /></button>
|
||||
<div class="ih:flex ih:flex-1 ih:flex-col ih:gap-1 ih:p-3">
|
||||
<p v-if="listing.price" class="ih:text-[15px] ih:font-semibold ih:text-brand-text">{{ listing.price }}</p>
|
||||
<Link :href="listing.url" class="ih:line-clamp-2 ih:text-sm ih:leading-snug ih:font-medium ih:hover:underline">{{ listing.title }}</Link>
|
||||
<p v-if="!compact" class="ih:mt-auto ih:flex ih:items-center ih:gap-1 ih:pt-1 ih:text-xs ih:text-muted-foreground">
|
||||
<MapPin v-if="listing.location" class="ih:size-3 ih:shrink-0" />
|
||||
<span class="ih:truncate">{{ [listing.location, listing.category_label].filter(Boolean).join(' · ') }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
19
resources/js/editorial/EditorialListings.vue
Normal file
19
resources/js/editorial/EditorialListings.vue
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { Panel } from '@inhaus/ui';
|
||||
|
||||
defineProps({ pending: { type: Array, required: true } });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Panel title="Kleinanzeigen – Freigabe" action-label="Zur Freigabe" action-href="/kleinanzeigen/moderation">
|
||||
<ul v-if="pending.length" class="ih:-mx-5 ih:divide-y ih:border-t">
|
||||
<li v-for="l in pending" :key="l.id" class="ih:flex ih:items-center ih:gap-3 ih:px-5 ih:py-2.5">
|
||||
<img v-if="l.thumb_url" :src="l.thumb_url" alt="" class="ih:size-10 ih:rounded ih:object-cover" />
|
||||
<Link :href="l.url" class="ih:min-w-0 ih:flex-1 ih:truncate ih:text-sm ih:font-medium ih:hover:underline">{{ l.title }}</Link>
|
||||
<span class="ih:shrink-0 ih:text-xs ih:text-muted-foreground">{{ l.type_label }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="ih:text-sm ih:text-muted-foreground">Keine Anzeigen warten auf Freigabe.</p>
|
||||
</Panel>
|
||||
</template>
|
||||
145
resources/js/pages/Editor.vue
Normal file
145
resources/js/pages/Editor.vue
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Link, useForm } from '@inertiajs/vue3';
|
||||
import { ChevronLeft, ImagePlus, LoaderCircle, TriangleAlert, X } from '@lucide/vue';
|
||||
import { AppLayout, Button, FormField, Input, PageHeader, Panel, Switch, Textarea, toast } from '@inhaus/ui';
|
||||
|
||||
const props = defineProps({
|
||||
listing: { type: Object, default: null },
|
||||
types: { type: Object, required: true },
|
||||
categories: { type: Object, required: true },
|
||||
maxPhotos: { type: Number, default: 8 },
|
||||
defaultLocation: { type: String, default: null },
|
||||
});
|
||||
|
||||
const l = props.listing;
|
||||
const form = useForm({
|
||||
type: l?.type ?? 'sell',
|
||||
category: l?.category ?? '',
|
||||
title: l?.title ?? '',
|
||||
description: l?.description ?? '',
|
||||
price: l?.price ?? '',
|
||||
negotiable: l?.negotiable ?? false,
|
||||
location: l?.location ?? props.defaultLocation ?? '',
|
||||
phone: l?.phone ?? '',
|
||||
photos: [],
|
||||
remove_photos: [],
|
||||
});
|
||||
|
||||
const existing = ref(l?.photos ?? []);
|
||||
const previews = ref([]);
|
||||
const fileInput = ref(null);
|
||||
const withPrice = computed(() => ['sell', 'search'].includes(form.type));
|
||||
const photoCount = computed(() => existing.value.length + form.photos.length);
|
||||
|
||||
function addPhotos(files) {
|
||||
for (const file of files) {
|
||||
if (!file.type.startsWith('image/')) continue;
|
||||
if (photoCount.value >= props.maxPhotos) {
|
||||
toast.error(`Höchstens ${props.maxPhotos} Fotos.`);
|
||||
break;
|
||||
}
|
||||
|
||||
form.photos.push(file);
|
||||
previews.value.push(URL.createObjectURL(file));
|
||||
}
|
||||
}
|
||||
|
||||
function removeNew(i) {
|
||||
URL.revokeObjectURL(previews.value[i]);
|
||||
form.photos.splice(i, 1);
|
||||
previews.value.splice(i, 1);
|
||||
}
|
||||
|
||||
function removeExisting(photo) {
|
||||
form.remove_photos.push(photo.id);
|
||||
existing.value = existing.value.filter((p) => p.id !== photo.id);
|
||||
}
|
||||
|
||||
function submit() {
|
||||
form.post(l ? `/kleinanzeigen/${l.id}` : '/kleinanzeigen', { forceFormData: true, preserveScroll: true });
|
||||
}
|
||||
|
||||
const willReview = computed(() => l && ['active', 'rejected', 'expired'].includes(l.status));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :title="l ? 'Anzeige bearbeiten' : 'Anzeige aufgeben'">
|
||||
<PageHeader :title="l ? 'Anzeige bearbeiten' : 'Anzeige aufgeben'" :breadcrumbs="[{ label: 'Kleinanzeigen', href: '/kleinanzeigen' }]" />
|
||||
|
||||
<p v-if="l?.review_note" class="ih:mb-4 ih:flex ih:items-start ih:gap-2 ih:rounded-md ih:border ih:border-destructive/30 ih:bg-destructive/5 ih:p-3 ih:text-sm">
|
||||
<TriangleAlert class="ih:mt-0.5 ih:size-4 ih:shrink-0 ih:text-destructive" /> Hinweis der Moderation: {{ l.review_note }}
|
||||
</p>
|
||||
|
||||
<form class="ih:grid ih:max-w-3xl ih:gap-6" @submit.prevent="submit">
|
||||
<Panel>
|
||||
<div class="ih:grid ih:gap-5">
|
||||
<fieldset>
|
||||
<legend class="ih:mb-2 ih:text-sm ih:font-medium">Ich …</legend>
|
||||
<div class="ih:flex ih:flex-wrap ih:gap-2">
|
||||
<label v-for="(label, key) in types" :key="key" class="ih:cursor-pointer ih:rounded-full ih:border ih:px-4 ih:py-1.5 ih:text-sm ih:has-[:checked]:border-brand ih:has-[:checked]:bg-brand ih:has-[:checked]:text-brand-foreground ih:has-[:focus-visible]:ring-3 ih:has-[:focus-visible]:ring-ring/30">
|
||||
<input v-model="form.type" type="radio" name="type" :value="key" class="ih:sr-only" />{{ label.toLowerCase() }}
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<FormField id="ka-title" label="Titel" :error="form.errors.title">
|
||||
<Input id="ka-title" v-model="form.title" maxlength="120" placeholder="z. B. Kinderfahrrad 20 Zoll, blau" />
|
||||
</FormField>
|
||||
|
||||
<FormField id="ka-category" label="Kategorie" :error="form.errors.category">
|
||||
<select id="ka-category" v-model="form.category" class="ih:h-9 ih:w-full ih:rounded-md ih:border ih:border-input ih:bg-card ih:px-2 ih:text-sm">
|
||||
<option value="" disabled>Bitte wählen</option>
|
||||
<option v-for="(label, key) in categories" :key="key" :value="key">{{ label }}</option>
|
||||
</select>
|
||||
</FormField>
|
||||
|
||||
<FormField id="ka-description" label="Beschreibung" :error="form.errors.description" hint="Zustand, Maße, Abholung – alles, was Interessierte wissen möchten.">
|
||||
<Textarea id="ka-description" v-model="form.description" rows="6" maxlength="5000" />
|
||||
</FormField>
|
||||
|
||||
<div v-if="withPrice" class="ih:grid ih:gap-4 ih:sm:grid-cols-2">
|
||||
<FormField id="ka-price" :label="form.type === 'search' ? 'Budget (optional)' : 'Preis in € (leer = auf Anfrage)'" :error="form.errors.price">
|
||||
<Input id="ka-price" v-model="form.price" inputmode="decimal" placeholder="z. B. 25 oder 12,50" />
|
||||
</FormField>
|
||||
<label v-if="form.type === 'sell'" class="ih:flex ih:items-center ih:gap-3 ih:self-end ih:pb-2 ih:text-sm"><Switch v-model="form.negotiable" /> Verhandlungsbasis (VB)</label>
|
||||
</div>
|
||||
|
||||
<div class="ih:grid ih:gap-4 ih:sm:grid-cols-2">
|
||||
<FormField id="ka-location" label="Ort bzw. Abholung" :error="form.errors.location">
|
||||
<Input id="ka-location" v-model="form.location" maxlength="120" placeholder="z. B. Haus A oder Mainz-Gonsenheim" />
|
||||
</FormField>
|
||||
<FormField id="ka-phone" label="Telefon (optional)" :error="form.errors.phone" hint="Wird in der Anzeige gezeigt.">
|
||||
<Input id="ka-phone" v-model="form.phone" type="tel" maxlength="40" />
|
||||
</FormField>
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
<Panel :title="`Fotos (${photoCount}/${maxPhotos})`">
|
||||
<div class="ih:grid ih:grid-cols-3 ih:gap-3 ih:sm:grid-cols-4" @dragover.prevent @drop.prevent="addPhotos([...$event.dataTransfer.files])">
|
||||
<div v-for="photo in existing" :key="photo.id" class="ih:relative ih:aspect-[4/3] ih:overflow-hidden ih:rounded-md ih:border">
|
||||
<img :src="photo.url" alt="" class="ih:size-full ih:object-cover" />
|
||||
<button type="button" class="ih:absolute ih:top-1 ih:right-1 ih:grid ih:size-6 ih:place-items-center ih:rounded-full ih:bg-foreground/75 ih:text-background" aria-label="Foto entfernen" @click="removeExisting(photo)"><X class="ih:size-3.5" /></button>
|
||||
</div>
|
||||
<div v-for="(url, i) in previews" :key="url" class="ih:relative ih:aspect-[4/3] ih:overflow-hidden ih:rounded-md ih:border">
|
||||
<img :src="url" alt="" class="ih:size-full ih:object-cover" />
|
||||
<button type="button" class="ih:absolute ih:top-1 ih:right-1 ih:grid ih:size-6 ih:place-items-center ih:rounded-full ih:bg-foreground/75 ih:text-background" aria-label="Foto entfernen" @click="removeNew(i)"><X class="ih:size-3.5" /></button>
|
||||
</div>
|
||||
<button v-if="photoCount < maxPhotos" type="button" class="ih:flex ih:aspect-[4/3] ih:flex-col ih:items-center ih:justify-center ih:gap-1 ih:rounded-md ih:border-2 ih:border-dashed ih:text-sm ih:text-muted-foreground ih:hover:border-brand ih:hover:text-brand-text" @click="fileInput?.click()">
|
||||
<ImagePlus class="ih:size-6" /> Fotos hinzufügen
|
||||
</button>
|
||||
</div>
|
||||
<input ref="fileInput" type="file" accept="image/*" multiple class="ih:hidden" @change="addPhotos([...$event.target.files]); $event.target.value = ''" />
|
||||
<p v-if="form.errors.photos || form.errors['photos.0']" class="ih:mt-2 ih:text-[13px] ih:text-destructive">{{ form.errors.photos || form.errors['photos.0'] }}</p>
|
||||
<p class="ih:mt-3 ih:text-xs ih:text-muted-foreground">Das erste Foto erscheint in der Übersicht. Fotos sind nur für angemeldete Mitarbeitende sichtbar.</p>
|
||||
</Panel>
|
||||
|
||||
<div class="ih:flex ih:flex-wrap ih:items-center ih:gap-3">
|
||||
<Button type="submit" :disabled="form.processing"><LoaderCircle v-if="form.processing" class="ih:animate-spin" /> {{ l ? 'Speichern' : 'Zur Freigabe einreichen' }}</Button>
|
||||
<Button variant="ghost" as-child><Link :href="l ? '/kleinanzeigen/meine' : '/kleinanzeigen'"><ChevronLeft /> Abbrechen</Link></Button>
|
||||
<p class="ih:text-xs ih:text-muted-foreground">{{ l ? (willReview ? 'Änderungen an Inhalt oder Fotos werden erneut geprüft.' : '') : 'Die Moderation prüft Ihre Anzeige; danach ist sie 30 Tage online.' }}</p>
|
||||
</div>
|
||||
</form>
|
||||
</AppLayout>
|
||||
</template>
|
||||
104
resources/js/pages/Index.vue
Normal file
104
resources/js/pages/Index.vue
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { Link, router, usePage } from '@inertiajs/vue3';
|
||||
import { Heart, ListChecks, Plus, Search, ShieldCheck, ShoppingBag } from '@lucide/vue';
|
||||
import { AppLayout, Button, EmptyState, PageHeader, toast } from '@inhaus/ui';
|
||||
import ListingCard from '../components/ListingCard.vue';
|
||||
|
||||
const props = defineProps({
|
||||
listings: { type: Array, required: true },
|
||||
pagination: { type: Object, required: true },
|
||||
filters: { type: Object, required: true },
|
||||
types: { type: Object, required: true },
|
||||
categories: { type: Object, required: true },
|
||||
counts: { type: Object, default: () => ({}) },
|
||||
pending: { type: Number, default: null },
|
||||
mine: { type: Number, default: 0 },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash?.status, (status) => status && toast.success(status), { immediate: true });
|
||||
|
||||
const query = ref(props.filters.q);
|
||||
let timer;
|
||||
watch(query, (value) => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => apply({ q: value }), 350);
|
||||
});
|
||||
|
||||
function apply(changes) {
|
||||
const params = { ...props.filters, ...changes };
|
||||
router.get('/kleinanzeigen', Object.fromEntries(Object.entries(params).filter(([key, value]) => value && !(key === 'sortierung' && value === 'neu'))), { preserveState: true, preserveScroll: true });
|
||||
}
|
||||
|
||||
const sorts = { neu: 'Neueste zuerst', preis: 'Preis aufsteigend', 'preis-ab': 'Preis absteigend' };
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Kleinanzeigen">
|
||||
<PageHeader title="Kleinanzeigen" description="Von Kolleginnen und Kollegen für Kolleginnen und Kollegen – verkaufen, verschenken, suchen, tauschen.">
|
||||
<template #actions>
|
||||
<Button v-if="pending !== null" variant="outline" as-child>
|
||||
<Link href="/kleinanzeigen/moderation"><ShieldCheck /> Freigabe<span v-if="pending" class="ih:rounded-full ih:bg-brand ih:px-1.5 ih:text-[11px] ih:text-brand-foreground">{{ pending }}</span></Link>
|
||||
</Button>
|
||||
<Button variant="outline" as-child><Link href="/kleinanzeigen/meine"><ListChecks /> Meine Anzeigen<span v-if="mine" class="ih:text-muted-foreground">({{ mine }})</span></Link></Button>
|
||||
<Button as-child><Link href="/kleinanzeigen/neu"><Plus /> Anzeige aufgeben</Link></Button>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<div class="ih:grid ih:gap-6 ih:lg:grid-cols-[15rem_minmax(0,1fr)]">
|
||||
<aside class="ih:grid ih:content-start ih:gap-5">
|
||||
<div class="ih:relative">
|
||||
<Search class="ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground" />
|
||||
<input v-model="query" type="search" placeholder="Suchen" aria-label="Anzeigen durchsuchen" class="ih:h-10 ih:w-full ih:rounded-md ih:border ih:border-input ih:bg-card ih:pr-3 ih:pl-8 ih:text-sm ih:shadow-xs ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none" />
|
||||
</div>
|
||||
|
||||
<nav aria-label="Art" class="ih:flex ih:flex-wrap ih:gap-1.5">
|
||||
<button type="button" class="ih:rounded-full ih:border ih:px-3 ih:py-1 ih:text-[13px]" :class="!filters.typ ? 'ih:border-brand ih:bg-brand ih:text-brand-foreground' : 'ih:bg-card ih:hover:bg-accent'" :aria-pressed="!filters.typ" @click="apply({ typ: null })">Alle</button>
|
||||
<button v-for="(label, key) in types" :key="key" type="button" class="ih:rounded-full ih:border ih:px-3 ih:py-1 ih:text-[13px]" :class="filters.typ === key ? 'ih:border-brand ih:bg-brand ih:text-brand-foreground' : 'ih:bg-card ih:hover:bg-accent'" :aria-pressed="filters.typ === key" @click="apply({ typ: key })">{{ label }}</button>
|
||||
</nav>
|
||||
|
||||
<nav aria-label="Kategorien" class="ih:hidden ih:lg:block">
|
||||
<h2 class="ih:mb-1.5 ih:text-xs ih:font-semibold ih:tracking-wider ih:text-muted-foreground ih:uppercase">Kategorien</h2>
|
||||
<ul class="ih:grid ih:gap-0.5 ih:text-sm">
|
||||
<li><button type="button" class="ih:flex ih:w-full ih:justify-between ih:rounded ih:px-2 ih:py-1.5 ih:text-left" :class="!filters.kategorie ? 'ih:bg-brand-soft ih:font-medium ih:text-brand-text' : 'ih:hover:bg-accent'" @click="apply({ kategorie: null })">Alle Kategorien</button></li>
|
||||
<li v-for="(label, key) in categories" :key="key">
|
||||
<button type="button" class="ih:flex ih:w-full ih:justify-between ih:gap-2 ih:rounded ih:px-2 ih:py-1.5 ih:text-left" :class="filters.kategorie === key ? 'ih:bg-brand-soft ih:font-medium ih:text-brand-text' : 'ih:hover:bg-accent'" @click="apply({ kategorie: key })">
|
||||
<span>{{ label }}</span><span class="ih:text-xs ih:text-muted-foreground ih:tabular-nums">{{ counts[key] ?? 0 }}</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<select class="ih:h-10 ih:rounded-md ih:border ih:bg-card ih:px-2 ih:text-sm ih:lg:hidden" aria-label="Kategorie" :value="filters.kategorie ?? ''" @change="apply({ kategorie: $event.target.value || null })">
|
||||
<option value="">Alle Kategorien</option>
|
||||
<option v-for="(label, key) in categories" :key="key" :value="key">{{ label }} ({{ counts[key] ?? 0 }})</option>
|
||||
</select>
|
||||
</aside>
|
||||
|
||||
<section class="ih:min-w-0">
|
||||
<div class="ih:mb-4 ih:flex ih:flex-wrap ih:items-center ih:gap-3">
|
||||
<p class="ih:flex-1 ih:text-sm ih:text-muted-foreground">{{ pagination.total }} {{ pagination.total === 1 ? 'Anzeige' : 'Anzeigen' }}</p>
|
||||
<button type="button" class="ih:inline-flex ih:items-center ih:gap-1.5 ih:rounded-md ih:border ih:px-3 ih:py-1.5 ih:text-sm" :class="filters.merkliste ? 'ih:border-brand ih:bg-brand-soft ih:text-brand-text' : 'ih:bg-card ih:hover:bg-accent'" :aria-pressed="filters.merkliste" @click="apply({ merkliste: filters.merkliste ? null : 1 })">
|
||||
<Heart class="ih:size-4" :class="filters.merkliste ? 'ih:fill-current' : ''" /> Merkliste
|
||||
</button>
|
||||
<select class="ih:h-9 ih:rounded-md ih:border ih:bg-card ih:px-2 ih:text-sm" aria-label="Sortierung" :value="filters.sortierung" @change="apply({ sortierung: $event.target.value })">
|
||||
<option v-for="(label, key) in sorts" :key="key" :value="key">{{ label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div v-if="listings.length" class="ih:grid ih:grid-cols-2 ih:gap-3 ih:sm:gap-4 ih:md:grid-cols-3 ih:xl:grid-cols-4">
|
||||
<ListingCard v-for="listing in listings" :key="listing.id" :listing="listing" />
|
||||
</div>
|
||||
<div v-else class="ih:rounded-lg ih:border ih:bg-card">
|
||||
<EmptyState :icon="ShoppingBag" :title="filters.q || filters.typ || filters.kategorie || filters.merkliste ? 'Keine passenden Anzeigen' : 'Noch keine Anzeigen'" text="Etwas übrig oder auf der Suche? Geben Sie die erste Anzeige auf." />
|
||||
</div>
|
||||
|
||||
<nav v-if="pagination.last > 1" class="ih:mt-6 ih:flex ih:items-center ih:justify-between ih:text-sm" aria-label="Seiten">
|
||||
<Link v-if="pagination.prev" :href="pagination.prev" preserve-scroll class="ih:font-medium ih:text-brand-text ih:hover:underline">← Zurück</Link><span v-else />
|
||||
<span class="ih:text-muted-foreground">Seite {{ pagination.current }} von {{ pagination.last }}</span>
|
||||
<Link v-if="pagination.next" :href="pagination.next" preserve-scroll class="ih:font-medium ih:text-brand-text ih:hover:underline">Weiter →</Link><span v-else />
|
||||
</nav>
|
||||
</section>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
60
resources/js/pages/Mine.vue
Normal file
60
resources/js/pages/Mine.vue
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<script setup>
|
||||
import { watch } from 'vue';
|
||||
import { Link, router, usePage } from '@inertiajs/vue3';
|
||||
import { CalendarClock, CheckCheck, Heart, ImageOff, PencilLine, Plus, RefreshCw, Tag, Trash2 } from '@lucide/vue';
|
||||
import { AppLayout, Button, EmptyState, PageHeader, formatDate, toast } from '@inhaus/ui';
|
||||
|
||||
defineProps({ listings: { type: Array, required: true } });
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash?.status, (status) => status && toast.success(status), { immediate: true });
|
||||
|
||||
const post = (listing, action) => router.post(`/kleinanzeigen/${listing.id}/${action}`, {}, { preserveScroll: true });
|
||||
const remove = (listing) => window.confirm(`„${listing.title}“ löschen?`) && router.delete(`/kleinanzeigen/${listing.id}`, { preserveScroll: true });
|
||||
|
||||
const badge = {
|
||||
pending: 'ih:bg-accent ih:text-accent-foreground',
|
||||
active: 'ih:bg-brand-soft ih:text-brand-text',
|
||||
rejected: 'ih:bg-destructive/10 ih:text-destructive',
|
||||
done: 'ih:bg-muted ih:text-muted-foreground',
|
||||
expired: 'ih:bg-muted ih:text-muted-foreground',
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Meine Anzeigen">
|
||||
<PageHeader title="Meine Anzeigen" :breadcrumbs="[{ label: 'Kleinanzeigen', href: '/kleinanzeigen' }]">
|
||||
<template #actions><Button as-child><Link href="/kleinanzeigen/neu"><Plus /> Anzeige aufgeben</Link></Button></template>
|
||||
</PageHeader>
|
||||
|
||||
<ul v-if="listings.length" class="ih:grid ih:gap-3">
|
||||
<li v-for="l in listings" :key="l.id" class="ih:flex ih:flex-wrap ih:items-center ih:gap-4 ih:rounded-lg ih:border ih:bg-card ih:p-3 ih:shadow-xs ih:sm:flex-nowrap">
|
||||
<Link :href="l.url" class="ih:block ih:size-20 ih:shrink-0 ih:overflow-hidden ih:rounded-md ih:bg-muted">
|
||||
<img v-if="l.thumb_url" :src="l.thumb_url" alt="" class="ih:size-full ih:object-cover" />
|
||||
<span v-else class="ih:grid ih:size-full ih:place-items-center ih:text-muted-foreground"><ImageOff class="ih:size-6" /></span>
|
||||
</Link>
|
||||
<div class="ih:min-w-0 ih:flex-1">
|
||||
<div class="ih:flex ih:flex-wrap ih:items-center ih:gap-2">
|
||||
<Link :href="l.url" class="ih:font-medium ih:hover:underline">{{ l.title }}</Link>
|
||||
<span class="ih:rounded ih:px-1.5 ih:py-0.5 ih:text-[11px] ih:font-medium" :class="badge[l.status]">{{ l.status_label }}</span>
|
||||
<span v-if="l.reserved" class="ih:rounded ih:bg-foreground ih:px-1.5 ih:py-0.5 ih:text-[11px] ih:font-medium ih:text-background">Reserviert</span>
|
||||
</div>
|
||||
<p class="ih:mt-0.5 ih:flex ih:flex-wrap ih:items-center ih:gap-x-3 ih:text-xs ih:text-muted-foreground">
|
||||
<span>{{ [l.type_label, l.price].filter(Boolean).join(' · ') }}</span>
|
||||
<span v-if="l.status === 'active' && l.expires_at" class="ih:inline-flex ih:items-center ih:gap-1"><CalendarClock class="ih:size-3" /> bis {{ formatDate(l.expires_at) }}</span>
|
||||
<span v-if="l.favorites" class="ih:inline-flex ih:items-center ih:gap-1"><Heart class="ih:size-3" /> {{ l.favorites }}× gemerkt</span>
|
||||
</p>
|
||||
<p v-if="l.status === 'rejected' && l.review_note" class="ih:mt-1 ih:text-xs ih:text-destructive">Hinweis: {{ l.review_note }}</p>
|
||||
</div>
|
||||
<div class="ih:flex ih:shrink-0 ih:flex-wrap ih:gap-1">
|
||||
<Button v-if="['active', 'expired'].includes(l.status)" variant="outline" size="sm" @click="post(l, 'verlaengern')"><RefreshCw /> Verlängern</Button>
|
||||
<Button v-if="l.status === 'active'" variant="ghost" size="sm" @click="post(l, 'reserviert')"><Tag /> {{ l.reserved ? 'Nicht reserviert' : 'Reserviert' }}</Button>
|
||||
<Button v-if="l.status === 'active'" variant="ghost" size="sm" @click="post(l, 'erledigt')"><CheckCheck /> Erledigt</Button>
|
||||
<Button v-if="l.status !== 'done'" variant="ghost" size="icon" :aria-label="`${l.title} bearbeiten`" as-child><Link :href="l.edit_url"><PencilLine /></Link></Button>
|
||||
<Button variant="ghost" size="icon" class="ih:text-muted-foreground ih:hover:text-destructive" :aria-label="`${l.title} löschen`" @click="remove(l)"><Trash2 /></Button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-else class="ih:rounded-lg ih:border ih:bg-card"><EmptyState :icon="Tag" title="Sie haben noch keine Anzeigen" text="Etwas übrig oder auf der Suche? Geben Sie Ihre erste Anzeige auf." /></div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
69
resources/js/pages/Moderation.vue
Normal file
69
resources/js/pages/Moderation.vue
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { Link, router, usePage } from '@inertiajs/vue3';
|
||||
import { Check, Flag, ImageOff, Undo2 } from '@lucide/vue';
|
||||
import { AppLayout, Button, EmptyState, PageHeader, Panel, Textarea, toast } from '@inhaus/ui';
|
||||
|
||||
defineProps({
|
||||
pending: { type: Array, required: true },
|
||||
reported: { type: Array, required: true },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash?.status, (status) => status && toast.success(status), { immediate: true });
|
||||
|
||||
const notes = ref({});
|
||||
const rejecting = ref(null);
|
||||
const approve = (l) => router.post(`/kleinanzeigen/${l.id}/freigeben`, {}, { preserveScroll: true });
|
||||
function reject(l) {
|
||||
router.post(`/kleinanzeigen/${l.id}/zurueckgeben`, { note: notes.value[l.id] ?? '' }, { preserveScroll: true, onSuccess: () => (rejecting.value = null) });
|
||||
}
|
||||
const resolve = (l, action) => router.post(`/kleinanzeigen/${l.id}/meldungen`, { action }, { preserveScroll: true });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Kleinanzeigen – Freigabe">
|
||||
<PageHeader title="Freigabe" description="Neue und geänderte Anzeigen prüfen. Die anbietende Person bekommt Bescheid." :breadcrumbs="[{ label: 'Kleinanzeigen', href: '/kleinanzeigen' }]" />
|
||||
|
||||
<Panel v-if="reported.length" title="Gemeldet" class="ih:mb-6">
|
||||
<ul class="ih:-mx-5 ih:divide-y ih:border-t">
|
||||
<li v-for="l in reported" :key="l.id" class="ih:flex ih:flex-wrap ih:items-center ih:gap-3 ih:px-5 ih:py-3">
|
||||
<Flag class="ih:size-4 ih:shrink-0 ih:text-destructive" />
|
||||
<div class="ih:min-w-0 ih:flex-1">
|
||||
<Link :href="l.url" class="ih:font-medium ih:hover:underline">{{ l.title }}</Link>
|
||||
<p class="ih:text-xs ih:text-muted-foreground">{{ l.seller }} · {{ l.reasons.join(' / ') }}</p>
|
||||
</div>
|
||||
<Button size="sm" variant="outline" @click="resolve(l, 'keep')">In Ordnung</Button>
|
||||
<Button size="sm" variant="outline" class="ih:text-destructive ih:hover:text-destructive" @click="resolve(l, 'remove')">Offline nehmen</Button>
|
||||
</li>
|
||||
</ul>
|
||||
</Panel>
|
||||
|
||||
<div v-if="pending.length" class="ih:grid ih:gap-4">
|
||||
<article v-for="l in pending" :key="l.id" class="ih:grid ih:gap-4 ih:rounded-lg ih:border ih:bg-card ih:p-4 ih:shadow-xs ih:md:grid-cols-[12rem_minmax(0,1fr)]">
|
||||
<div class="ih:grid ih:grid-cols-3 ih:content-start ih:gap-1 ih:md:grid-cols-2">
|
||||
<img v-for="p in l.photos.slice(0, 4)" :key="p.id" :src="p.thumb_url" alt="" class="ih:aspect-[4/3] ih:w-full ih:rounded ih:object-cover" />
|
||||
<span v-if="!l.photos.length" class="ih:col-span-2 ih:grid ih:aspect-[4/3] ih:place-items-center ih:rounded ih:bg-muted ih:text-muted-foreground"><ImageOff class="ih:size-6" /></span>
|
||||
</div>
|
||||
<div class="ih:min-w-0">
|
||||
<p class="ih:text-xs ih:text-muted-foreground">{{ l.type_label }} · {{ l.category_label }} · von {{ l.seller?.name }}</p>
|
||||
<Link :href="l.url" class="ih:text-lg ih:font-semibold ih:hover:underline">{{ l.title }}</Link>
|
||||
<p v-if="l.price" class="ih:font-medium ih:text-brand-text">{{ l.price }}</p>
|
||||
<p class="ih:mt-2 ih:line-clamp-4 ih:text-sm ih:whitespace-pre-line">{{ l.description }}</p>
|
||||
<div v-if="rejecting === l.id" class="ih:mt-3 ih:grid ih:gap-2">
|
||||
<Textarea v-model="notes[l.id]" rows="2" maxlength="500" placeholder="Begründung für die anbietende Person" aria-label="Begründung" />
|
||||
<div class="ih:flex ih:gap-2">
|
||||
<Button size="sm" :disabled="!(notes[l.id] ?? '').trim()" @click="reject(l)">Zurückgeben</Button>
|
||||
<Button size="sm" variant="ghost" @click="rejecting = null">Abbrechen</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="ih:mt-3 ih:flex ih:gap-2">
|
||||
<Button size="sm" @click="approve(l)"><Check /> Freigeben</Button>
|
||||
<Button size="sm" variant="outline" @click="rejecting = l.id"><Undo2 /> Zurückgeben …</Button>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div v-else class="ih:rounded-lg ih:border ih:bg-card"><EmptyState :icon="Check" title="Alles erledigt" text="Keine Anzeigen warten auf Freigabe." /></div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
151
resources/js/pages/Show.vue
Normal file
151
resources/js/pages/Show.vue
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
<script setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Link, router, useForm, usePage } from '@inertiajs/vue3';
|
||||
import { CalendarDays, ChevronLeft, ChevronRight, Flag, Heart, ImageOff, LoaderCircle, Mail, MapPin, MessageCircle, PencilLine, Phone, ShieldCheck, Trash2 } from '@lucide/vue';
|
||||
import { AppLayout, Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, PersonAvatar, Textarea, formatDate, toast } from '@inhaus/ui';
|
||||
import ListingCard from '../components/ListingCard.vue';
|
||||
|
||||
const props = defineProps({
|
||||
listing: { type: Object, required: true },
|
||||
more: { type: Array, default: () => [] },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash?.status, (status) => status && toast.success(status), { immediate: true });
|
||||
|
||||
const l = computed(() => props.listing);
|
||||
const current = ref(0);
|
||||
const photo = computed(() => l.value.photos[current.value]);
|
||||
const step = (delta) => (current.value = (current.value + delta + l.value.photos.length) % l.value.photos.length);
|
||||
|
||||
// Kontakt
|
||||
const contact = useForm({ message: `Hallo ${l.value.seller?.name?.split(' ')[0] ?? ''}, ist „${l.value.title}“ noch zu haben?` });
|
||||
const send = () => contact.post(`/kleinanzeigen/${l.value.id}/kontakt`, { preserveScroll: true, onSuccess: () => contact.reset() });
|
||||
|
||||
// Melden
|
||||
const reporting = ref(false);
|
||||
const report = useForm({ reason: '' });
|
||||
const sendReport = () => report.post(`/kleinanzeigen/${l.value.id}/melden`, { preserveScroll: true, onSuccess: () => { reporting.value = false; report.reset(); } });
|
||||
|
||||
function toggleFavorite() {
|
||||
router.visit(`/kleinanzeigen/${l.value.id}/merken`, { method: l.value.favorite ? 'delete' : 'post', preserveScroll: true });
|
||||
}
|
||||
|
||||
function remove() {
|
||||
window.confirm('Anzeige löschen?') && router.delete(`/kleinanzeigen/${l.value.id}`);
|
||||
}
|
||||
|
||||
const statusNote = computed(() => ({
|
||||
pending: 'Diese Anzeige wartet auf Freigabe und ist noch nicht öffentlich.',
|
||||
rejected: 'Diese Anzeige wurde nicht freigegeben.',
|
||||
done: 'Diese Anzeige ist erledigt.',
|
||||
expired: 'Diese Anzeige ist abgelaufen.',
|
||||
})[l.value.status]);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :title="l.title">
|
||||
<div class="ih:mb-4 ih:flex ih:items-center ih:justify-between ih:gap-3">
|
||||
<Link href="/kleinanzeigen" class="ih:inline-flex ih:items-center ih:gap-1 ih:text-sm ih:font-medium ih:text-muted-foreground ih:hover:text-foreground"><ChevronLeft class="ih:size-4" /> Alle Kleinanzeigen</Link>
|
||||
<div class="ih:flex ih:gap-2">
|
||||
<Button v-if="l.own" variant="outline" size="sm" as-child><Link :href="`/kleinanzeigen/${l.id}/bearbeiten`"><PencilLine /> Bearbeiten</Link></Button>
|
||||
<Button v-if="l.own || l.can_moderate" variant="ghost" size="sm" class="ih:text-destructive ih:hover:text-destructive" @click="remove"><Trash2 /> Löschen</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="statusNote" class="ih:mb-4 ih:rounded-md ih:border ih:bg-muted ih:px-4 ih:py-3 ih:text-sm">
|
||||
{{ statusNote }}<template v-if="l.review_note"> Hinweis: {{ l.review_note }}</template>
|
||||
</p>
|
||||
|
||||
<div class="ih:grid ih:gap-6 ih:lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||||
<div class="ih:grid ih:min-w-0 ih:content-start ih:gap-6">
|
||||
<!-- Galerie -->
|
||||
<section class="ih:overflow-hidden ih:rounded-xl ih:border ih:bg-card" aria-label="Fotos">
|
||||
<div class="ih:relative ih:flex ih:aspect-[4/3] ih:items-center ih:justify-center ih:bg-muted ih:sm:aspect-[16/10]">
|
||||
<img v-if="photo" :src="photo.url" :alt="`${l.title} – Foto ${current + 1}`" class="ih:max-h-full ih:max-w-full ih:object-contain" />
|
||||
<ImageOff v-else class="ih:size-10 ih:text-muted-foreground" :stroke-width="1.5" />
|
||||
<template v-if="l.photos.length > 1">
|
||||
<button type="button" class="ih:absolute ih:left-3 ih:grid ih:size-10 ih:place-items-center ih:rounded-full ih:bg-card/90 ih:shadow" aria-label="Vorheriges Foto" @click="step(-1)"><ChevronLeft class="ih:size-5" /></button>
|
||||
<button type="button" class="ih:absolute ih:right-3 ih:grid ih:size-10 ih:place-items-center ih:rounded-full ih:bg-card/90 ih:shadow" aria-label="Nächstes Foto" @click="step(1)"><ChevronRight class="ih:size-5" /></button>
|
||||
<span class="ih:absolute ih:right-3 ih:bottom-3 ih:rounded ih:bg-foreground/70 ih:px-2 ih:py-0.5 ih:text-xs ih:text-background ih:tabular-nums">{{ current + 1 }} / {{ l.photos.length }}</span>
|
||||
</template>
|
||||
</div>
|
||||
<div v-if="l.photos.length > 1" class="ih:flex ih:gap-2 ih:overflow-x-auto ih:p-3">
|
||||
<button v-for="(p, i) in l.photos" :key="p.id" type="button" class="ih:size-16 ih:shrink-0 ih:overflow-hidden ih:rounded-md ih:border-2" :class="i === current ? 'ih:border-brand' : 'ih:border-transparent ih:opacity-70 ih:hover:opacity-100'" :aria-label="`Foto ${i + 1}`" :aria-current="i === current" @click="current = i">
|
||||
<img :src="p.thumb_url" alt="" class="ih:size-full ih:object-cover" />
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="ih:rounded-xl ih:border ih:bg-card ih:p-5 ih:sm:p-6">
|
||||
<div class="ih:flex ih:flex-wrap ih:items-center ih:gap-2 ih:text-xs">
|
||||
<span class="ih:rounded ih:bg-brand-soft ih:px-2 ih:py-0.5 ih:font-semibold ih:text-brand-text">{{ l.type_label }}</span>
|
||||
<span class="ih:text-muted-foreground">{{ l.category_label }}</span>
|
||||
<span v-if="l.reserved" class="ih:rounded ih:bg-foreground ih:px-2 ih:py-0.5 ih:font-semibold ih:text-background">Reserviert</span>
|
||||
</div>
|
||||
<h1 class="ih:mt-2 ih:text-2xl ih:font-semibold ih:tracking-tight ih:text-balance">{{ l.title }}</h1>
|
||||
<p v-if="l.price" class="ih:mt-1 ih:text-xl ih:font-semibold ih:text-brand-text">{{ l.price }}</p>
|
||||
<dl class="ih:mt-4 ih:flex ih:flex-wrap ih:gap-x-6 ih:gap-y-2 ih:text-sm ih:text-muted-foreground">
|
||||
<div v-if="l.location" class="ih:flex ih:items-center ih:gap-1.5"><dt class="ih:sr-only">Ort</dt><MapPin class="ih:size-4" aria-hidden="true" /><dd>{{ l.location }}</dd></div>
|
||||
<div v-if="l.published_at" class="ih:flex ih:items-center ih:gap-1.5"><dt class="ih:sr-only">Eingestellt</dt><CalendarDays class="ih:size-4" aria-hidden="true" /><dd>seit {{ formatDate(l.published_at) }}</dd></div>
|
||||
</dl>
|
||||
<h2 class="ih:mt-6 ih:mb-2 ih:text-sm ih:font-semibold">Beschreibung</h2>
|
||||
<p class="ih:text-[15px] ih:leading-relaxed ih:whitespace-pre-line">{{ l.description }}</p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<aside class="ih:grid ih:content-start ih:gap-4">
|
||||
<section v-if="l.seller" class="ih:rounded-xl ih:border ih:bg-card ih:p-5">
|
||||
<Link :href="`/personen/${l.seller.id}`" class="ih:flex ih:items-center ih:gap-3 ih:rounded-md ih:hover:bg-accent/50">
|
||||
<PersonAvatar :person="l.seller" class="ih:size-12" />
|
||||
<span class="ih:min-w-0">
|
||||
<span class="ih:block ih:font-semibold">{{ l.seller.name }}</span>
|
||||
<span class="ih:block ih:truncate ih:text-[13px] ih:text-muted-foreground">{{ [l.seller.department, l.seller.location].filter(Boolean).join(' · ') }}</span>
|
||||
</span>
|
||||
</Link>
|
||||
<p v-if="l.seller.listings > 1" class="ih:mt-2 ih:text-xs ih:text-muted-foreground">{{ l.seller.listings }} Anzeigen online</p>
|
||||
|
||||
<form v-if="l.contact" class="ih:mt-4 ih:grid ih:gap-2 ih:border-t ih:pt-4" @submit.prevent="send">
|
||||
<label for="kontakt" class="ih:text-sm ih:font-medium">Nachricht an {{ l.seller.name.split(' ')[0] }}</label>
|
||||
<Textarea id="kontakt" v-model="contact.message" rows="4" maxlength="2000" />
|
||||
<p v-if="contact.errors.message" class="ih:text-[13px] ih:text-destructive">{{ contact.errors.message }}</p>
|
||||
<Button type="submit" :disabled="contact.processing || !contact.message.trim()">
|
||||
<LoaderCircle v-if="contact.processing" class="ih:animate-spin" />
|
||||
<component :is="l.contact === 'chat' ? MessageCircle : Mail" v-else />
|
||||
{{ l.contact === 'chat' ? 'Im Chat schreiben' : 'Per E-Mail schreiben' }}
|
||||
</Button>
|
||||
<p class="ih:text-xs ih:text-muted-foreground">{{ l.contact === 'chat' ? 'Öffnet ein Gespräch unter „Nachrichten“.' : 'Die Antwort kommt per E-Mail; die Adresse der anbietenden Person bleibt verborgen.' }}</p>
|
||||
</form>
|
||||
<a v-if="l.phone" :href="`tel:${l.phone.replace(/[^0-9+]/g, '')}`" class="ih:mt-3 ih:flex ih:items-center ih:gap-2 ih:text-sm ih:font-medium ih:text-brand-text ih:hover:underline"><Phone class="ih:size-4" /> {{ l.phone }}</a>
|
||||
</section>
|
||||
|
||||
<div v-if="!l.own" class="ih:flex ih:gap-2">
|
||||
<Button variant="outline" class="ih:flex-1" :aria-pressed="l.favorite" @click="toggleFavorite"><Heart :class="l.favorite ? 'ih:fill-current ih:text-brand-text' : ''" /> {{ l.favorite ? 'Gemerkt' : 'Merken' }}</Button>
|
||||
<Button variant="ghost" class="ih:text-muted-foreground" @click="reporting = true"><Flag /> Melden</Button>
|
||||
</div>
|
||||
<p v-if="l.can_moderate && l.status === 'pending'" class="ih:flex ih:items-center ih:gap-2 ih:text-sm"><ShieldCheck class="ih:size-4 ih:text-brand-text" /> <Link href="/kleinanzeigen/moderation" class="ih:font-medium ih:text-brand-text ih:hover:underline">Zur Freigabe</Link></p>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<section v-if="more.length" class="ih:mt-10">
|
||||
<h2 class="ih:mb-4 ih:text-lg ih:font-semibold">Das könnte Sie auch interessieren</h2>
|
||||
<div class="ih:grid ih:grid-cols-2 ih:gap-3 ih:md:grid-cols-4">
|
||||
<ListingCard v-for="item in more" :key="item.id" :listing="item" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<Dialog v-model:open="reporting">
|
||||
<DialogContent class="ih:sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Anzeige melden</DialogTitle>
|
||||
<DialogDescription>Was stimmt nicht? Die Moderation sieht sich die Anzeige an.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Textarea v-model="report.reason" rows="3" maxlength="500" placeholder="z. B. unpassend, doppelt, kein Mitarbeiterangebot …" aria-label="Grund" />
|
||||
<DialogFooter>
|
||||
<Button variant="ghost" @click="reporting = false">Abbrechen</Button>
|
||||
<Button :disabled="report.processing || !report.reason.trim()" @click="sendReport">Melden</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</AppLayout>
|
||||
</template>
|
||||
14
resources/js/widgets/Latest.vue
Normal file
14
resources/js/widgets/Latest.vue
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<script setup>
|
||||
import { Panel } from '@inhaus/ui';
|
||||
import ListingCard from '../components/ListingCard.vue';
|
||||
|
||||
defineProps({ listings: { type: Array, required: true } });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Panel title="Kleinanzeigen" action-label="Alle Anzeigen" action-href="/kleinanzeigen">
|
||||
<div class="ih:grid ih:grid-cols-2 ih:gap-2">
|
||||
<ListingCard v-for="l in listings" :key="l.id" :listing="l" compact />
|
||||
</div>
|
||||
</Panel>
|
||||
</template>
|
||||
16
resources/views/mail/contact.blade.php
Normal file
16
resources/views/mail/contact.blade.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Frage zu Ihrer Anzeige</title></head>
|
||||
<body style="margin:0;background:#f4f5f7;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;color:#1a1d21">
|
||||
<div style="max-width:600px;margin:0 auto;padding:24px">
|
||||
<p style="margin:0 0 16px;font-size:15px;font-weight:700;color:{{ $color }}">{{ $portalName }} · Kleinanzeigen</p>
|
||||
<div style="background:#fff;border:1px solid #e3e5e8;border-radius:8px;padding:24px">
|
||||
<p style="margin:0 0 4px;font-size:13px;color:#5f6670">Frage zu Ihrer Anzeige</p>
|
||||
<h1 style="margin:0 0 16px;font-size:18px"><a href="{{ $url }}" style="color:{{ $color }};text-decoration:none">{{ $listing->title }}</a></h1>
|
||||
<p style="margin:0 0 8px;font-size:14px"><strong>{{ $sender->name }}</strong>@if ($sender->job_title) · {{ $sender->job_title }}@endif schreibt:</p>
|
||||
<div style="margin:0 0 20px;padding:12px 16px;background:#f4f5f7;border-radius:6px;font-size:15px;line-height:1.5;white-space:pre-line">{{ $text }}</div>
|
||||
<p style="margin:0;font-size:13px;color:#5f6670">Antworten Sie einfach auf diese E-Mail – sie geht direkt an {{ $sender->name }}.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
30
routes/web.php
Normal file
30
routes/web.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Http\Controllers\ListingController;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Http\Controllers\ModerationController;
|
||||
|
||||
Route::middleware('auth')->prefix('kleinanzeigen')->name('kleinanzeigen.')->group(function () {
|
||||
Route::get('/', [ListingController::class, 'index'])->name('index');
|
||||
Route::get('/meine', [ListingController::class, 'mine'])->name('mine');
|
||||
Route::get('/neu', [ListingController::class, 'create'])->name('create');
|
||||
Route::post('/', [ListingController::class, 'store'])->middleware('throttle:10,60')->name('store');
|
||||
Route::get('/moderation', [ModerationController::class, 'index'])->name('moderation');
|
||||
Route::get('/bilder/{image}/{size}', [ListingController::class, 'image'])->whereIn('size', ['thumb', 'full'])->name('image');
|
||||
|
||||
Route::get('/{listing}', [ListingController::class, 'show'])->whereNumber('listing')->name('show');
|
||||
Route::get('/{listing}/bearbeiten', [ListingController::class, 'edit'])->name('edit');
|
||||
Route::post('/{listing}', [ListingController::class, 'update'])->name('update'); // POST wegen Datei-Upload
|
||||
Route::delete('/{listing}', [ListingController::class, 'destroy'])->name('destroy');
|
||||
Route::post('/{listing}/verlaengern', [ListingController::class, 'extend'])->name('extend');
|
||||
Route::post('/{listing}/erledigt', [ListingController::class, 'done'])->name('done');
|
||||
Route::post('/{listing}/reserviert', [ListingController::class, 'reserve'])->name('reserve');
|
||||
Route::post('/{listing}/merken', [ListingController::class, 'favorite'])->name('favorite');
|
||||
Route::delete('/{listing}/merken', [ListingController::class, 'favorite'])->name('unfavorite');
|
||||
Route::post('/{listing}/kontakt', [ListingController::class, 'contact'])->middleware('throttle:20,60')->name('contact');
|
||||
Route::post('/{listing}/melden', [ListingController::class, 'report'])->middleware('throttle:10,60')->name('report');
|
||||
|
||||
Route::post('/{listing}/freigeben', [ModerationController::class, 'approve'])->name('approve');
|
||||
Route::post('/{listing}/zurueckgeben', [ModerationController::class, 'reject'])->name('reject');
|
||||
Route::post('/{listing}/meldungen', [ModerationController::class, 'resolve'])->name('resolve');
|
||||
});
|
||||
322
src/Http/Controllers/ListingController.php
Normal file
322
src/Http/Controllers/ListingController.php
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Notifications\PortalNotification;
|
||||
use App\Search\GlobalSearch;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Chat\Chat;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Mail\ContactMessage;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Market;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\ListingImage;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Photos;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Presenter;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class ListingController extends Controller
|
||||
{
|
||||
public function __construct(private readonly Market $market, private readonly Photos $photos) {}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$data = $request->validate([
|
||||
'q' => ['nullable', 'string', 'max:100'],
|
||||
'typ' => ['nullable', Rule::in(array_keys(Listing::TYPES))],
|
||||
'kategorie' => ['nullable', Rule::in(array_keys(Listing::CATEGORIES))],
|
||||
'sortierung' => ['nullable', Rule::in(['neu', 'preis', 'preis-ab'])],
|
||||
'merkliste' => ['nullable', 'boolean'],
|
||||
]);
|
||||
$user = $request->user();
|
||||
|
||||
$query = Listing::query()->visible()->with('images')
|
||||
->when($data['typ'] ?? null, fn ($q, $type) => $q->where('type', $type))
|
||||
->when($data['kategorie'] ?? null, fn ($q, $category) => $q->where('category', $category))
|
||||
->when($request->boolean('merkliste'), fn ($q) => $q->whereHas('favoritedBy', fn ($f) => $f->whereKey($user->id)));
|
||||
|
||||
if (filled($data['q'] ?? null)) {
|
||||
GlobalSearch::whereTerms($query, ['title', 'description', 'location'], $data['q']);
|
||||
}
|
||||
|
||||
match ($data['sortierung'] ?? 'neu') {
|
||||
'preis' => $query->orderByRaw('price_cents IS NULL')->orderBy('price_cents'),
|
||||
'preis-ab' => $query->orderByDesc('price_cents'),
|
||||
default => $query->latest('published_at'),
|
||||
};
|
||||
|
||||
$listings = $query->paginate(24)->withQueryString();
|
||||
$favorites = DB::table('kleinanzeigen_favorites')->where('user_id', $user->id)->pluck('listing_id')->all();
|
||||
|
||||
return Inertia::render('kleinanzeigen::Index', [
|
||||
'listings' => collect($listings->items())->map(fn (Listing $l) => Presenter::card($l, $favorites))->all(),
|
||||
'pagination' => ['current' => $listings->currentPage(), 'last' => $listings->lastPage(), 'prev' => $listings->previousPageUrl(), 'next' => $listings->nextPageUrl(), 'total' => $listings->total()],
|
||||
'filters' => ['q' => $data['q'] ?? '', 'typ' => $data['typ'] ?? null, 'kategorie' => $data['kategorie'] ?? null, 'sortierung' => $data['sortierung'] ?? 'neu', 'merkliste' => $request->boolean('merkliste')],
|
||||
'types' => Listing::TYPES,
|
||||
'categories' => Listing::CATEGORIES,
|
||||
'counts' => Listing::query()->visible()->selectRaw('category, count(*) as c')->groupBy('category')->pluck('c', 'category'),
|
||||
'pending' => $user->can('kleinanzeigen.moderate') ? Listing::query()->where('status', 'pending')->count() : null,
|
||||
'mine' => Listing::query()->where('user_id', $user->id)->whereIn('status', ['pending', 'active'])->count(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request, Listing $listing): Response
|
||||
{
|
||||
$this->ensureVisible($request, $listing);
|
||||
$listing->load(['images', 'user']);
|
||||
|
||||
return Inertia::render('kleinanzeigen::Show', [
|
||||
'listing' => Presenter::detail($listing, $request->user(), $this->market),
|
||||
'more' => Listing::query()->visible()->with('images')->whereKeyNot($listing->id)
|
||||
->where(fn ($q) => $q->where('user_id', $listing->user_id)->orWhere('category', $listing->category))
|
||||
->orderByRaw('user_id = ? DESC', [$listing->user_id])->latest('published_at')->limit(4)->get()
|
||||
->map(fn (Listing $l) => Presenter::card($l))->all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function mine(Request $request): Response
|
||||
{
|
||||
return Inertia::render('kleinanzeigen::Mine', [
|
||||
'listings' => Listing::query()->where('user_id', $request->user()->id)->with('images')->withCount('favoritedBy')
|
||||
->orderByRaw("FIELD(status, 'pending', 'rejected', 'active', 'expired', 'done')")->latest('updated_at')->get()
|
||||
->map(fn (Listing $l) => [...Presenter::card($l), 'review_note' => $l->review_note, 'favorites' => $l->favorited_by_count, 'edit_url' => route('kleinanzeigen.edit', $l)])->all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): Response
|
||||
{
|
||||
return $this->editor(null);
|
||||
}
|
||||
|
||||
public function edit(Request $request, Listing $listing): Response
|
||||
{
|
||||
$this->ensureOwner($request, $listing);
|
||||
|
||||
return $this->editor($listing->load('images'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $this->validated($request, null);
|
||||
$listing = Listing::query()->create([...$data, 'user_id' => $request->user()->id, 'status' => 'pending']);
|
||||
$this->syncPhotos($request, $listing);
|
||||
$this->market->submitted($listing);
|
||||
|
||||
return to_route('kleinanzeigen.mine')->with('status', 'Danke! Ihre Anzeige wird geprüft und dann freigeschaltet.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
$this->ensureOwner($request, $listing);
|
||||
$data = $this->validated($request, $listing);
|
||||
$listing->fill($data);
|
||||
$contentChanged = $listing->isDirty(Market::REVIEW_FIELDS);
|
||||
$listing->save();
|
||||
$photosChanged = $this->syncPhotos($request, $listing);
|
||||
|
||||
// Inhaltliche Änderungen gehen erneut in die Freigabe
|
||||
if ($listing->status !== 'pending' && $listing->status !== 'done' && ($contentChanged || $photosChanged || $listing->status === 'rejected')) {
|
||||
$wasActive = $listing->status === 'active';
|
||||
$this->market->submitted($listing, $wasActive);
|
||||
|
||||
return to_route('kleinanzeigen.mine')->with('status', 'Gespeichert – die Änderungen werden geprüft.');
|
||||
}
|
||||
|
||||
return to_route('kleinanzeigen.mine')->with('status', 'Gespeichert.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
abort_unless($listing->user_id === $request->user()->id || $request->user()->can('kleinanzeigen.moderate'), 403);
|
||||
$this->photos->deleteAll($listing);
|
||||
$listing->delete();
|
||||
|
||||
return to_route($listing->user_id === $request->user()->id ? 'kleinanzeigen.mine' : 'kleinanzeigen.index')->with('status', 'Anzeige gelöscht.');
|
||||
}
|
||||
|
||||
public function extend(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
$this->ensureOwner($request, $listing);
|
||||
$this->market->extend($listing);
|
||||
|
||||
return back()->with('status', 'Verlängert bis '.$listing->expires_at->format('d.m.Y').'.');
|
||||
}
|
||||
|
||||
public function done(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
$this->ensureOwner($request, $listing);
|
||||
$listing->forceFill(['status' => 'done', 'reserved' => false])->save();
|
||||
|
||||
return back()->with('status', 'Als erledigt markiert – die Anzeige ist nicht mehr sichtbar.');
|
||||
}
|
||||
|
||||
public function reserve(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
$this->ensureOwner($request, $listing);
|
||||
$listing->forceFill(['reserved' => ! $listing->reserved])->save();
|
||||
|
||||
return back()->with('status', $listing->reserved ? 'Als reserviert markiert.' : 'Wieder verfügbar.');
|
||||
}
|
||||
|
||||
public function favorite(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
$this->ensureVisible($request, $listing);
|
||||
$request->isMethod('delete')
|
||||
? $listing->favoritedBy()->detach($request->user()->id)
|
||||
: $listing->favoritedBy()->syncWithoutDetaching([$request->user()->id => ['created_at' => now()]]);
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
/** Kontakt: Direktnachricht im Chat (falls installiert), sonst E-Mail */
|
||||
public function contact(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
$this->ensureVisible($request, $listing);
|
||||
$user = $request->user();
|
||||
abort_if($listing->user_id === $user->id || ! $listing->user?->is_active, 422);
|
||||
$data = $request->validate(['message' => ['required', 'string', 'max:2000']], [], ['message' => 'Nachricht']);
|
||||
|
||||
if ($this->market->chatAvailable($user, $listing->user)) {
|
||||
$chat = app(Chat::class);
|
||||
$conversation = $chat->direct($user, $listing->user);
|
||||
$chat->send($conversation, $user, "Zu deiner Anzeige „{$listing->title}“:\n".route('kleinanzeigen.show', $listing)."\n\n".trim($data['message']));
|
||||
|
||||
return redirect('/chat/'.$conversation->id);
|
||||
}
|
||||
|
||||
Mail::to($listing->user)->queue(new ContactMessage($listing, $user, trim($data['message'])));
|
||||
|
||||
return back()->with('status', 'Nachricht gesendet – die Antwort kommt per E-Mail.');
|
||||
}
|
||||
|
||||
public function report(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
$this->ensureVisible($request, $listing);
|
||||
$data = $request->validate(['reason' => ['required', 'string', 'max:500']], [], ['reason' => 'Grund']);
|
||||
|
||||
DB::table('kleinanzeigen_reports')->insertOrIgnore([
|
||||
'listing_id' => $listing->id, 'user_id' => $request->user()->id, 'reason' => trim($data['reason']), 'created_at' => now(), 'updated_at' => now(),
|
||||
]);
|
||||
Notification::send($this->market->moderators(), new PortalNotification('Anzeige gemeldet: '.Str::limit($listing->title, 60), Str::limit($data['reason'], 120), route('kleinanzeigen.moderation', absolute: false), 'flag'));
|
||||
|
||||
return back()->with('status', 'Danke für den Hinweis – die Moderation sieht es sich an.');
|
||||
}
|
||||
|
||||
public function image(Request $request, ListingImage $image, string $size): StreamedResponse
|
||||
{
|
||||
$listing = $image->listing;
|
||||
$this->ensureVisible($request, $listing);
|
||||
$path = $size === 'thumb' ? $image->thumb_path : $image->path;
|
||||
abort_unless(Storage::disk(Photos::DISK)->exists($path), 404);
|
||||
|
||||
return Storage::disk(Photos::DISK)->response($path, null, [
|
||||
'Content-Type' => 'image/webp',
|
||||
'Cache-Control' => 'private, max-age=604800',
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
]);
|
||||
}
|
||||
|
||||
private function editor(?Listing $listing): Response
|
||||
{
|
||||
return Inertia::render('kleinanzeigen::Editor', [
|
||||
'listing' => $listing ? [
|
||||
'id' => $listing->id,
|
||||
'type' => $listing->type,
|
||||
'category' => $listing->category,
|
||||
'title' => $listing->title,
|
||||
'description' => $listing->description,
|
||||
'price' => $listing->price_cents === null ? '' : number_format($listing->price_cents / 100, 2, ',', ''),
|
||||
'negotiable' => $listing->negotiable,
|
||||
'location' => $listing->location,
|
||||
'phone' => $listing->phone,
|
||||
'status' => $listing->status,
|
||||
'review_note' => $listing->review_note,
|
||||
'photos' => $listing->images->map(fn (ListingImage $i) => ['id' => $i->id, 'url' => route('kleinanzeigen.image', [$i, 'thumb'])])->all(),
|
||||
] : null,
|
||||
'types' => Listing::TYPES,
|
||||
'categories' => Listing::CATEGORIES,
|
||||
'maxPhotos' => Photos::MAX,
|
||||
'defaultLocation' => request()->user()->location,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function validated(Request $request, ?Listing $listing): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'type' => ['required', Rule::in(array_keys(Listing::TYPES))],
|
||||
'category' => ['required', Rule::in(array_keys(Listing::CATEGORIES))],
|
||||
'title' => ['required', 'string', 'max:120'],
|
||||
'description' => ['required', 'string', 'max:5000'],
|
||||
'price' => ['nullable', 'string', 'max:12', 'regex:/^\d{1,7}([.,]\d{1,2})?$/'],
|
||||
'negotiable' => ['boolean'],
|
||||
'location' => ['nullable', 'string', 'max:120'],
|
||||
'phone' => ['nullable', 'string', 'max:40', 'regex:/^[0-9 +()\/-]+$/'],
|
||||
'photos' => ['nullable', 'array', 'max:'.Photos::MAX],
|
||||
'photos.*' => ['image', 'mimes:jpg,jpeg,png,webp,gif', 'max:15360'],
|
||||
'remove_photos' => ['nullable', 'array'],
|
||||
'remove_photos.*' => ['integer'],
|
||||
], ['price.regex' => 'Bitte einen Betrag wie 25 oder 12,50 eingeben.', 'phone.regex' => 'Bitte nur Ziffern, Leerzeichen und + ( ) / -.'], [
|
||||
'type' => 'Art', 'category' => 'Kategorie', 'title' => 'Titel', 'description' => 'Beschreibung', 'price' => 'Preis', 'photos.*' => 'Foto',
|
||||
]);
|
||||
|
||||
$withPrice = in_array($data['type'], ['sell', 'search'], true) && filled($data['price'] ?? null);
|
||||
|
||||
return [
|
||||
'type' => $data['type'],
|
||||
'category' => $data['category'],
|
||||
'title' => trim($data['title']),
|
||||
'description' => trim($data['description']),
|
||||
'price_cents' => $withPrice ? (int) round((float) str_replace(',', '.', $data['price']) * 100) : null,
|
||||
'negotiable' => $withPrice && (bool) ($data['negotiable'] ?? false),
|
||||
'location' => filled($data['location'] ?? null) ? trim($data['location']) : null,
|
||||
'phone' => filled($data['phone'] ?? null) ? trim($data['phone']) : null,
|
||||
];
|
||||
}
|
||||
|
||||
/** Fotos entfernen bzw. hinzufügen – true, wenn sich etwas geändert hat */
|
||||
private function syncPhotos(Request $request, Listing $listing): bool
|
||||
{
|
||||
$changed = false;
|
||||
|
||||
foreach ($listing->images()->whereKey((array) $request->input('remove_photos', []))->get() as $image) {
|
||||
$this->photos->delete($image);
|
||||
$changed = true;
|
||||
}
|
||||
|
||||
$sort = (int) $listing->images()->max('sort');
|
||||
|
||||
foreach ((array) $request->file('photos', []) as $file) {
|
||||
if ($listing->images()->count() >= Photos::MAX) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->photos->store($listing, $file, ++$sort);
|
||||
$changed = true;
|
||||
}
|
||||
|
||||
return $changed;
|
||||
}
|
||||
|
||||
private function ensureVisible(Request $request, Listing $listing): void
|
||||
{
|
||||
$user = $request->user();
|
||||
abort_unless($listing->isVisible() || $listing->user_id === $user->id || $user->can('kleinanzeigen.moderate'), 404);
|
||||
}
|
||||
|
||||
private function ensureOwner(Request $request, Listing $listing): void
|
||||
{
|
||||
abort_unless($listing->user_id === $request->user()->id, 403);
|
||||
}
|
||||
}
|
||||
66
src/Http/Controllers/ModerationController.php
Normal file
66
src/Http/Controllers/ModerationController.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Market;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Presenter;
|
||||
|
||||
/**
|
||||
* Freigabe neuer und geänderter Anzeigen, gemeldete Anzeigen.
|
||||
*/
|
||||
class ModerationController extends Controller
|
||||
{
|
||||
public function __construct(private readonly Market $market) {}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
Gate::authorize('kleinanzeigen.moderate');
|
||||
$reports = DB::table('kleinanzeigen_reports')->whereNull('resolved_at')->get()->groupBy('listing_id');
|
||||
|
||||
return Inertia::render('kleinanzeigen::Moderation', [
|
||||
'pending' => Listing::query()->where('status', 'pending')->with(['images', 'user'])->oldest('updated_at')->limit(100)->get()
|
||||
->map(fn (Listing $l) => Presenter::detail($l, $request->user(), $this->market))->all(),
|
||||
'reported' => Listing::query()->whereKey($reports->keys())->with(['images', 'user'])->get()
|
||||
->map(fn (Listing $l) => [...Presenter::card($l), 'seller' => $l->user?->name, 'reasons' => $reports[$l->id]->pluck('reason')->all()])->all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function approve(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
Gate::authorize('kleinanzeigen.moderate');
|
||||
$this->market->approve($listing, $request->user());
|
||||
|
||||
return back()->with('status', 'Freigegeben: „'.$listing->title.'“');
|
||||
}
|
||||
|
||||
public function reject(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
Gate::authorize('kleinanzeigen.moderate');
|
||||
$data = $request->validate(['note' => ['required', 'string', 'max:500']], [], ['note' => 'Begründung']);
|
||||
$this->market->reject($listing, $request->user(), trim($data['note']));
|
||||
|
||||
return back()->with('status', 'Zurückgegeben: „'.$listing->title.'“');
|
||||
}
|
||||
|
||||
/** Gemeldete Anzeige: in Ordnung (Meldungen erledigen) oder offline nehmen */
|
||||
public function resolve(Request $request, Listing $listing): RedirectResponse
|
||||
{
|
||||
Gate::authorize('kleinanzeigen.moderate');
|
||||
$data = $request->validate(['action' => ['required', 'in:keep,remove'], 'note' => ['nullable', 'string', 'max:500']]);
|
||||
DB::table('kleinanzeigen_reports')->where('listing_id', $listing->id)->whereNull('resolved_at')->update(['resolved_at' => now()]);
|
||||
|
||||
if ($data['action'] === 'remove') {
|
||||
$this->market->reject($listing, $request->user(), $data['note'] ?: 'Nach einem Hinweis offline genommen.');
|
||||
}
|
||||
|
||||
return back()->with('status', $data['action'] === 'remove' ? 'Offline genommen.' : 'Meldungen erledigt.');
|
||||
}
|
||||
}
|
||||
68
src/KleinanzeigenPlugin.php
Normal file
68
src/KleinanzeigenPlugin.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Digest\Digest;
|
||||
use App\Editorial\Editorial;
|
||||
use App\Models\User;
|
||||
use App\Plugins\Plugin;
|
||||
use App\Search\GlobalSearch;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Schedule;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
|
||||
/**
|
||||
* Kleinanzeigen – von Kolleginnen und Kollegen für Kolleginnen und Kollegen.
|
||||
*/
|
||||
class KleinanzeigenPlugin extends Plugin
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->make(Navigation::class)->add('kleinanzeigen', 'Kleinanzeigen', '/kleinanzeigen', active: 'kleinanzeigen.*', sort: 78);
|
||||
$this->app->make(Abilities::class)->define('kleinanzeigen.moderate', 'Kleinanzeigen freigeben und moderieren', 'Kleinanzeigen', portal: true);
|
||||
|
||||
$this->app->make(GlobalSearch::class)->add('kleinanzeigen', 'Kleinanzeigen', 'shopping-bag', function (User $user, string $search, int $limit) {
|
||||
$query = Listing::query()->visible();
|
||||
GlobalSearch::whereTerms($query, ['title', 'description', 'location'], $search);
|
||||
|
||||
return $query->latest('published_at')->limit($limit)->get()->map(fn (Listing $l) => [
|
||||
'title' => $l->title,
|
||||
'url' => '/kleinanzeigen/'.$l->id,
|
||||
'excerpt' => GlobalSearch::excerpt($l->description, $search),
|
||||
'meta' => collect([Listing::TYPES[$l->type], $l->priceLabel(), $l->location])->filter()->implode(' · '),
|
||||
])->all();
|
||||
}, sort: 70);
|
||||
|
||||
// Startseite: die neuesten Anzeigen
|
||||
$this->app->make(Widgets::class)->add('kleinanzeigen.latest', 'kleinanzeigen::Latest', 'aside', sort: 40, props: function () {
|
||||
$listings = Listing::query()->visible()->with('images')->latest('published_at')->limit(4)->get();
|
||||
|
||||
return $listings->isEmpty() ? null : ['listings' => $listings->map(fn (Listing $l) => Presenter::card($l))->all()];
|
||||
}, label: 'Kleinanzeigen', mobileSort: 45);
|
||||
|
||||
// Redaktion: was auf Freigabe wartet
|
||||
$this->app->make(Editorial::class)->add('kleinanzeigen', 'Kleinanzeigen', 'kleinanzeigen::EditorialListings', 36,
|
||||
fn (User $user) => $user->can('kleinanzeigen.moderate'),
|
||||
fn () => ['pending' => Listing::query()->where('status', 'pending')->with('images')->oldest('updated_at')->limit(20)->get()->map(fn (Listing $l) => Presenter::card($l))->all()]);
|
||||
|
||||
if (class_exists(Digest::class)) {
|
||||
$this->app->make(Digest::class)->add('kleinanzeigen', 'Neue Kleinanzeigen', 60, fn (User $user, CarbonImmutable $since) => Listing::query()
|
||||
->visible()->where('published_at', '>=', $since)->latest('published_at')->limit(6)->get()
|
||||
->map(fn (Listing $l) => ['title' => $l->title, 'url' => route('kleinanzeigen.show', $l), 'meta' => collect([Listing::TYPES[$l->type], $l->priceLabel()])->filter()->implode(' · ')])->all());
|
||||
}
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
Schedule::call(fn () => $this->app->make(Market::class)->housekeeping())->dailyAt('06:10')->name('kleinanzeigen-housekeeping')->withoutOverlapping(30);
|
||||
}
|
||||
|
||||
public function uninstall(): void
|
||||
{
|
||||
Storage::disk(Photos::DISK)->deleteDirectory('kleinanzeigen');
|
||||
}
|
||||
}
|
||||
43
src/Mail/ContactMessage.php
Normal file
43
src/Mail/ContactMessage.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen\Mail;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\Branding;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
|
||||
/**
|
||||
* Nachricht zu einer Anzeige per E-Mail (ohne Chat-Plugin). Die Adresse der anbietenden
|
||||
* Person bleibt verborgen; geantwortet wird direkt an die fragende Person.
|
||||
*/
|
||||
class ContactMessage extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
public function __construct(public Listing $listing, public User $sender, public string $text) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Frage zu Ihrer Anzeige: '.$this->listing->title,
|
||||
replyTo: [new Address($this->sender->email, $this->sender->name)],
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(view: 'kleinanzeigen::mail.contact', with: [
|
||||
'portalName' => app(Branding::class)->portalName(),
|
||||
'color' => app(Branding::class)->primaryColor(),
|
||||
'url' => route('kleinanzeigen.show', $this->listing),
|
||||
]);
|
||||
}
|
||||
}
|
||||
104
src/Market.php
Normal file
104
src/Market.php
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
use App\Plugins\PluginAccess;
|
||||
use App\Plugins\PluginManager;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
use Inhaus\Plugins\Chat\Chat;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
|
||||
/**
|
||||
* Kleinanzeigen von Kolleginnen und Kollegen: Freigabe durch die Moderation, 30 Tage Laufzeit,
|
||||
* verlängerbar. Inhaltliche Änderungen an freigegebenen Anzeigen gehen erneut in die Freigabe.
|
||||
*/
|
||||
class Market
|
||||
{
|
||||
public const REVIEW_FIELDS = ['type', 'category', 'title', 'description', 'price_cents', 'phone'];
|
||||
|
||||
/** Nach dem Anlegen oder einer inhaltlichen Änderung: zur Freigabe */
|
||||
public function submitted(Listing $listing, bool $wasActive = false): void
|
||||
{
|
||||
$listing->forceFill(['status' => 'pending', 'review_note' => null])->save();
|
||||
|
||||
Notification::send($this->moderators()->reject(fn (User $u) => $u->id === $listing->user_id), new PortalNotification(
|
||||
($wasActive ? 'Geänderte Anzeige prüfen: ' : 'Neue Anzeige prüfen: ').Str::limit($listing->title, 60),
|
||||
Listing::TYPES[$listing->type].' · '.Listing::CATEGORIES[$listing->category],
|
||||
route('kleinanzeigen.moderation', absolute: false),
|
||||
'shopping-bag',
|
||||
));
|
||||
}
|
||||
|
||||
public function approve(Listing $listing, User $moderator): void
|
||||
{
|
||||
$listing->forceFill([
|
||||
'status' => 'active',
|
||||
'review_note' => null,
|
||||
'reviewed_by' => $moderator->id,
|
||||
'published_at' => $listing->published_at ?? now(),
|
||||
'expires_at' => $listing->expires_at?->isFuture() ? $listing->expires_at : now()->addDays(Listing::LIFETIME_DAYS),
|
||||
])->save();
|
||||
|
||||
$listing->user?->notify(new PortalNotification('Ihre Anzeige ist online: '.Str::limit($listing->title, 60), 'Sie ist bis zum '.$listing->expires_at->format('d.m.Y').' sichtbar.', route('kleinanzeigen.show', $listing, false), 'shopping-bag'));
|
||||
}
|
||||
|
||||
public function reject(Listing $listing, User $moderator, string $note): void
|
||||
{
|
||||
$listing->forceFill(['status' => 'rejected', 'review_note' => $note, 'reviewed_by' => $moderator->id])->save();
|
||||
|
||||
$listing->user?->notify(new PortalNotification('Anzeige nicht freigegeben: '.Str::limit($listing->title, 60), Str::limit($note, 120), route('kleinanzeigen.edit', $listing, false), 'shopping-bag'));
|
||||
}
|
||||
|
||||
public function extend(Listing $listing): void
|
||||
{
|
||||
abort_unless(in_array($listing->status, ['active', 'expired'], true), 422, 'Diese Anzeige lässt sich nicht verlängern.');
|
||||
$listing->forceFill(['status' => 'active', 'expires_at' => now()->addDays(Listing::LIFETIME_DAYS), 'reminded_at' => null])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Täglich: bald ablaufende Anzeigen ankündigen, abgelaufene beenden.
|
||||
*/
|
||||
public function housekeeping(): void
|
||||
{
|
||||
Listing::query()->where('status', 'active')->whereNull('reminded_at')->whereBetween('expires_at', [now(), now()->addDays(3)])->with('user')
|
||||
->each(function (Listing $listing) {
|
||||
$listing->forceFill(['reminded_at' => now()])->save();
|
||||
$listing->user?->notify(new PortalNotification('Anzeige läuft bald ab: '.Str::limit($listing->title, 60), 'Am '.$listing->expires_at->format('d.m.').' – mit einem Klick verlängern.', route('kleinanzeigen.mine', absolute: false), 'shopping-bag'));
|
||||
});
|
||||
|
||||
Listing::query()->where('status', 'active')->where('expires_at', '<=', now())->update(['status' => 'expired']);
|
||||
}
|
||||
|
||||
public function isFavorite(Listing $listing, User $user): bool
|
||||
{
|
||||
return DB::table('kleinanzeigen_favorites')->where('listing_id', $listing->id)->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
/** Ist das Chat-Plugin aktiv und für beide nutzbar? */
|
||||
public function chatAvailable(User $a, User $b): bool
|
||||
{
|
||||
$access = app(PluginAccess::class);
|
||||
|
||||
return class_exists(Chat::class)
|
||||
&& app(PluginManager::class)->isLoaded('chat')
|
||||
&& $access->allows('chat', $a) && $access->allows('chat', $b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wer Anzeigen freigibt: Recht „kleinanzeigen.moderate“ über eine Rolle – sonst die Administration.
|
||||
*
|
||||
* @return Collection<int, User>
|
||||
*/
|
||||
public function moderators(): Collection
|
||||
{
|
||||
$holders = fn (string $ability) => User::query()->active()->whereHas('roles.grants', fn ($q) => $q->where('ability', $ability))->limit(50)->get();
|
||||
$moderators = $holders('kleinanzeigen.moderate');
|
||||
|
||||
return $moderators->isNotEmpty() ? $moderators : $holders('*');
|
||||
}
|
||||
}
|
||||
113
src/Models/Listing.php
Normal file
113
src/Models/Listing.php
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable([
|
||||
'user_id', 'type', 'category', 'title', 'description', 'price_cents', 'negotiable', 'location', 'phone',
|
||||
'status', 'reserved', 'review_note', 'reviewed_by', 'published_at', 'expires_at', 'reminded_at',
|
||||
])]
|
||||
class Listing extends Model
|
||||
{
|
||||
public const LIFETIME_DAYS = 30;
|
||||
|
||||
public const TYPES = [
|
||||
'sell' => 'Verkaufe',
|
||||
'give' => 'Verschenke',
|
||||
'search' => 'Suche',
|
||||
'swap' => 'Tausche',
|
||||
];
|
||||
|
||||
public const CATEGORIES = [
|
||||
'moebel' => 'Möbel & Wohnen',
|
||||
'haushalt' => 'Haushalt & Garten',
|
||||
'elektronik' => 'Elektronik',
|
||||
'kinder' => 'Kinder & Baby',
|
||||
'kleidung' => 'Kleidung & Schuhe',
|
||||
'freizeit' => 'Freizeit, Sport & Hobby',
|
||||
'buecher' => 'Bücher, Filme & Musik',
|
||||
'fahrzeuge' => 'Fahrräder & Fahrzeuge',
|
||||
'tiere' => 'Tierbedarf',
|
||||
'wohnung' => 'Wohnung & Vermietung',
|
||||
'mitfahren' => 'Mitfahrgelegenheit',
|
||||
'hilfe' => 'Hilfe & Dienstleistungen',
|
||||
'sonstiges' => 'Sonstiges',
|
||||
];
|
||||
|
||||
public const STATUSES = [
|
||||
'pending' => 'Wartet auf Freigabe',
|
||||
'active' => 'Online',
|
||||
'rejected' => 'Nicht freigegeben',
|
||||
'done' => 'Erledigt',
|
||||
'expired' => 'Abgelaufen',
|
||||
];
|
||||
|
||||
protected $table = 'kleinanzeigen_listings';
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'negotiable' => 'boolean',
|
||||
'reserved' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
'reminded_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<ListingImage, $this>
|
||||
*/
|
||||
public function images(): HasMany
|
||||
{
|
||||
return $this->hasMany(ListingImage::class)->orderBy('sort');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsToMany<User, $this>
|
||||
*/
|
||||
public function favoritedBy(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'kleinanzeigen_favorites')->withPivot('created_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Für alle sichtbar: freigegeben und nicht abgelaufen.
|
||||
*
|
||||
* @param Builder<Listing> $query
|
||||
*/
|
||||
public function scopeVisible(Builder $query): void
|
||||
{
|
||||
$query->where('status', 'active')->where('expires_at', '>', now());
|
||||
}
|
||||
|
||||
public function isVisible(): bool
|
||||
{
|
||||
return $this->status === 'active' && $this->expires_at?->isFuture();
|
||||
}
|
||||
|
||||
public function priceLabel(): ?string
|
||||
{
|
||||
return match (true) {
|
||||
$this->type === 'give' => 'Zu verschenken',
|
||||
$this->type === 'swap' => 'Zum Tauschen',
|
||||
$this->price_cents === null => $this->type === 'search' ? null : 'Preis auf Anfrage',
|
||||
default => number_format($this->price_cents / 100, $this->price_cents % 100 ? 2 : 0, ',', '.').' €'.($this->negotiable ? ' VB' : ''),
|
||||
};
|
||||
}
|
||||
}
|
||||
23
src/Models/ListingImage.php
Normal file
23
src/Models/ListingImage.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['listing_id', 'path', 'thumb_path', 'width', 'height', 'sort'])]
|
||||
class ListingImage extends Model
|
||||
{
|
||||
protected $table = 'kleinanzeigen_images';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Listing, $this>
|
||||
*/
|
||||
public function listing(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Listing::class);
|
||||
}
|
||||
}
|
||||
63
src/Photos.php
Normal file
63
src/Photos.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen;
|
||||
|
||||
use App\Support\Images;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\ListingImage;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
use Intervention\Image\Encoders\WebpEncoder;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Fotos einer Anzeige: verkleinert (max. 1600 px) und als Vorschau (4:3) gespeichert – nicht
|
||||
* im öffentlichen Upload-Ordner, sondern nur für angemeldete Personen abrufbar.
|
||||
*/
|
||||
class Photos
|
||||
{
|
||||
public const DISK = 'local';
|
||||
|
||||
public const MAX = 8;
|
||||
|
||||
public function store(Listing $listing, UploadedFile $file, int $sort): ListingImage
|
||||
{
|
||||
$base = 'kleinanzeigen/'.$listing->id.'/'.Str::random(24);
|
||||
|
||||
try {
|
||||
return Images::withLocalCopy($file, function (string $local) use ($listing, $base, $sort) {
|
||||
Images::raiseMemoryLimitFor($local);
|
||||
$manager = ImageManager::usingDriver(Driver::class);
|
||||
$image = $manager->decodePath($local)->scaleDown(1600, 1600);
|
||||
$disk = Storage::disk(self::DISK);
|
||||
$disk->put("{$base}.webp", $image->encode(new WebpEncoder(quality: 82))->toString());
|
||||
$width = $image->width();
|
||||
$height = $image->height();
|
||||
$disk->put("{$base}-thumb.webp", $image->coverDown(640, 480)->encode(new WebpEncoder(quality: 78))->toString());
|
||||
|
||||
return $listing->images()->create(['path' => "{$base}.webp", 'thumb_path' => "{$base}-thumb.webp", 'width' => $width, 'height' => $height, 'sort' => $sort]);
|
||||
});
|
||||
} catch (ValidationException $e) {
|
||||
throw $e;
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
|
||||
throw ValidationException::withMessages(['images' => "„{$file->getClientOriginalName()}“ ließ sich nicht als Bild lesen."]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(ListingImage $image): void
|
||||
{
|
||||
Storage::disk(self::DISK)->delete([$image->path, $image->thumb_path]);
|
||||
$image->delete();
|
||||
}
|
||||
|
||||
public function deleteAll(Listing $listing): void
|
||||
{
|
||||
Storage::disk(self::DISK)->deleteDirectory('kleinanzeigen/'.$listing->id);
|
||||
}
|
||||
}
|
||||
76
src/Presenter.php
Normal file
76
src/Presenter.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Kleinanzeigen;
|
||||
|
||||
use App\Models\User;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\ListingImage;
|
||||
|
||||
class Presenter
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function card(Listing $listing, array $favorites = []): array
|
||||
{
|
||||
$cover = $listing->images->first();
|
||||
|
||||
return [
|
||||
'id' => $listing->id,
|
||||
'title' => $listing->title,
|
||||
'type' => $listing->type,
|
||||
'type_label' => Listing::TYPES[$listing->type] ?? $listing->type,
|
||||
'category' => $listing->category,
|
||||
'category_label' => Listing::CATEGORIES[$listing->category] ?? $listing->category,
|
||||
'price' => $listing->priceLabel(),
|
||||
'location' => $listing->location,
|
||||
'status' => $listing->status,
|
||||
'status_label' => Listing::STATUSES[$listing->status] ?? $listing->status,
|
||||
'reserved' => $listing->reserved,
|
||||
'thumb_url' => $cover ? route('kleinanzeigen.image', [$cover, 'thumb']) : null,
|
||||
'images' => $listing->images->count(),
|
||||
'favorite' => in_array($listing->id, $favorites, true),
|
||||
'published_at' => $listing->published_at?->toIso8601String(),
|
||||
'expires_at' => $listing->expires_at?->toIso8601String(),
|
||||
'url' => route('kleinanzeigen.show', $listing),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function detail(Listing $listing, User $viewer, Market $market): array
|
||||
{
|
||||
$own = $listing->user_id === $viewer->id;
|
||||
$seller = $listing->user;
|
||||
|
||||
return [
|
||||
...self::card($listing, $market->isFavorite($listing, $viewer) ? [$listing->id] : []),
|
||||
'description' => $listing->description,
|
||||
'price_cents' => $listing->price_cents,
|
||||
'negotiable' => $listing->negotiable,
|
||||
'phone' => $listing->phone,
|
||||
'review_note' => $own || $viewer->can('kleinanzeigen.moderate') ? $listing->review_note : null,
|
||||
'photos' => $listing->images->map(fn (ListingImage $i) => [
|
||||
'id' => $i->id,
|
||||
'url' => route('kleinanzeigen.image', [$i, 'full']),
|
||||
'thumb_url' => route('kleinanzeigen.image', [$i, 'thumb']),
|
||||
'width' => $i->width,
|
||||
'height' => $i->height,
|
||||
])->values()->all(),
|
||||
'seller' => $seller ? [
|
||||
'id' => $seller->id,
|
||||
'name' => $seller->name,
|
||||
'initials' => $seller->initials,
|
||||
'avatar_url' => $seller->avatarUrl(96),
|
||||
'job_title' => $seller->job_title,
|
||||
'department' => $seller->department,
|
||||
'location' => $seller->location,
|
||||
'listings' => Listing::query()->visible()->where('user_id', $seller->id)->count(),
|
||||
] : null,
|
||||
'own' => $own,
|
||||
'can_moderate' => $viewer->can('kleinanzeigen.moderate'),
|
||||
'contact' => $own || ! $seller ? null : ($market->chatAvailable($viewer, $seller) ? 'chat' : 'mail'),
|
||||
];
|
||||
}
|
||||
}
|
||||
60
tests/ChatContactTest.php
Normal file
60
tests/ChatContactTest.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Plugins\Kleinanzeigen;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Kontakt über das Chat-Plugin – nur, wenn es in dieser Installation liegt (plugins/chat).
|
||||
*/
|
||||
class ChatContactTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private ?string $previousState = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$file = getcwd().'/storage/app/plugins.json';
|
||||
$this->previousState = is_file($file) ? file_get_contents($file) : null;
|
||||
$state = json_decode($this->previousState ?? '{}', true) ?: [];
|
||||
$state['kleinanzeigen'] = ['enabled' => true];
|
||||
$state['chat'] = ['enabled' => true];
|
||||
file_put_contents($file, json_encode($state));
|
||||
|
||||
parent::setUp();
|
||||
|
||||
if (! is_dir(base_path('plugins/chat'))) {
|
||||
$this->markTestSkipped('Chat-Plugin nicht installiert.');
|
||||
}
|
||||
|
||||
Storage::fake('local');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$file = storage_path('app/plugins.json');
|
||||
$this->previousState === null ? @unlink($file) : file_put_contents($file, $this->previousState);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_contact_opens_a_chat_with_the_seller(): void
|
||||
{
|
||||
$seller = User::factory()->create();
|
||||
$buyer = User::factory()->create();
|
||||
$listing = Listing::query()->create(['user_id' => $seller->id, 'type' => 'give', 'category' => 'moebel', 'title' => 'Sofa', 'description' => 'Abholen in Mainz', 'status' => 'active', 'published_at' => now(), 'expires_at' => now()->addDays(5)]);
|
||||
|
||||
$this->actingAs($buyer)->get("/kleinanzeigen/{$listing->id}")->assertInertia(fn (Assert $p) => $p->where('listing.contact', 'chat'));
|
||||
$location = $this->actingAs($buyer)->post("/kleinanzeigen/{$listing->id}/kontakt", ['message' => 'Kann ich es Samstag holen?'])->assertRedirect()->headers->get('Location');
|
||||
$this->assertMatchesRegularExpression('#/chat/\d+$#', $location);
|
||||
|
||||
$this->actingAs($seller)->getJson('/chat/api/gespraeche/'.basename($location).'/nachrichten')->assertOk()
|
||||
->assertJsonPath('messages.0.body', "Zu deiner Anzeige „Sofa“:\n".route('kleinanzeigen.show', $listing)."\n\nKann ich es Samstag holen?");
|
||||
}
|
||||
}
|
||||
152
tests/KleinanzeigenTest.php
Normal file
152
tests/KleinanzeigenTest.php
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Plugins\Kleinanzeigen;
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Mail\ContactMessage;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Market;
|
||||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Läuft innerhalb einer Inhaus-Installation, in der das Plugin unter plugins/kleinanzeigen liegt:
|
||||
* vendor-dev/bin/phpunit plugins/kleinanzeigen/tests
|
||||
*/
|
||||
class KleinanzeigenTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private ?string $previousState = null;
|
||||
|
||||
private User $moderator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
// Plugin aktivieren, bevor die Anwendung startet – so laufen seine Migrationen mit
|
||||
$file = getcwd().'/storage/app/plugins.json';
|
||||
$this->previousState = is_file($file) ? file_get_contents($file) : null;
|
||||
$state = json_decode($this->previousState ?? '{}', true) ?: [];
|
||||
$state['kleinanzeigen'] = ['enabled' => true];
|
||||
$state['chat'] = ['enabled' => false];
|
||||
file_put_contents($file, json_encode($state));
|
||||
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake('local');
|
||||
$role = Role::query()->create(['name' => 'Marktaufsicht']);
|
||||
$role->grants()->create(['ability' => 'kleinanzeigen.moderate']);
|
||||
$this->moderator = User::factory()->withRoles([$role])->create();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$file = storage_path('app/plugins.json');
|
||||
$this->previousState === null ? @unlink($file) : file_put_contents($file, $this->previousState);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
private function payload(array $overrides = []): array
|
||||
{
|
||||
return ['type' => 'sell', 'category' => 'fahrzeuge', 'title' => 'Kinderfahrrad 20 Zoll', 'description' => 'Gut erhalten, blau.', 'price' => '45,50', 'negotiable' => true, ...$overrides];
|
||||
}
|
||||
|
||||
public function test_new_listings_need_approval_then_go_online_for_30_days(): void
|
||||
{
|
||||
Notification::fake();
|
||||
$seller = User::factory()->create();
|
||||
$buyer = User::factory()->create();
|
||||
|
||||
$this->actingAs($seller)->post('/kleinanzeigen', [...$this->payload(), 'photos' => [UploadedFile::fake()->image('rad.jpg', 2400, 1800)]])->assertRedirect('/kleinanzeigen/meine');
|
||||
$listing = Listing::query()->firstOrFail();
|
||||
$this->assertSame('pending', $listing->status);
|
||||
$this->assertSame(4550, $listing->price_cents);
|
||||
$this->assertSame(1600, $listing->images()->first()->width);
|
||||
Notification::assertSentTo($this->moderator, PortalNotification::class);
|
||||
|
||||
$this->actingAs($buyer)->get("/kleinanzeigen/{$listing->id}")->assertNotFound();
|
||||
$this->actingAs($buyer)->get('/kleinanzeigen')->assertInertia(fn (Assert $p) => $p->has('listings', 0));
|
||||
$this->actingAs($buyer)->post("/kleinanzeigen/{$listing->id}/freigeben")->assertForbidden();
|
||||
|
||||
$this->actingAs($this->moderator)->post("/kleinanzeigen/{$listing->id}/freigeben")->assertRedirect();
|
||||
$listing->refresh();
|
||||
$this->assertSame('active', $listing->status);
|
||||
$this->assertTrue($listing->expires_at->between(now()->addDays(29), now()->addDays(31)));
|
||||
Notification::assertSentTo($seller, PortalNotification::class, fn ($n) => str_contains($n->title, 'online'));
|
||||
|
||||
$this->actingAs($buyer)->get('/kleinanzeigen?typ=sell&kategorie=fahrzeuge&q=Fahrrad')->assertInertia(fn (Assert $p) => $p
|
||||
->has('listings', 1)->where('listings.0.price', '45,50 € VB'));
|
||||
$image = $listing->images()->first();
|
||||
$this->actingAs($buyer)->get("/kleinanzeigen/bilder/{$image->id}/thumb")->assertOk()->assertHeader('Content-Type', 'image/webp');
|
||||
}
|
||||
|
||||
public function test_content_changes_go_back_to_review_and_rejection_has_a_reason(): void
|
||||
{
|
||||
Notification::fake();
|
||||
$seller = User::factory()->create();
|
||||
$listing = Listing::query()->create([...collect($this->payload())->except('price')->all(), 'user_id' => $seller->id, 'status' => 'active', 'published_at' => now(), 'expires_at' => now()->addDays(10)]);
|
||||
|
||||
// Nur „reserviert“ ändert nichts an der Freigabe
|
||||
$this->actingAs($seller)->post("/kleinanzeigen/{$listing->id}/reserviert");
|
||||
$this->assertTrue($listing->fresh()->reserved);
|
||||
$this->assertSame('active', $listing->fresh()->status);
|
||||
|
||||
$this->actingAs($seller)->post("/kleinanzeigen/{$listing->id}", $this->payload(['title' => 'Kinderfahrrad – jetzt mit Klingel']));
|
||||
$this->assertSame('pending', $listing->fresh()->status);
|
||||
|
||||
$this->actingAs($this->moderator)->post("/kleinanzeigen/{$listing->id}/zurueckgeben", ['note' => 'Bitte ein Foto ergänzen.']);
|
||||
$this->assertSame('rejected', $listing->fresh()->status);
|
||||
Notification::assertSentTo($seller, PortalNotification::class, fn ($n) => $n->body === 'Bitte ein Foto ergänzen.');
|
||||
|
||||
$other = User::factory()->create();
|
||||
$this->actingAs($other)->post("/kleinanzeigen/{$listing->id}", $this->payload())->assertForbidden();
|
||||
$this->actingAs($other)->get("/kleinanzeigen/{$listing->id}/bearbeiten")->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_contact_by_mail_without_chat_hides_the_address(): void
|
||||
{
|
||||
Mail::fake();
|
||||
$seller = User::factory()->create(['email' => 'verkauf@example.org']);
|
||||
$buyer = User::factory()->create(['email' => 'kauf@example.org']);
|
||||
$listing = Listing::query()->create([...collect($this->payload())->except('price')->all(), 'user_id' => $seller->id, 'status' => 'active', 'published_at' => now(), 'expires_at' => now()->addDays(10)]);
|
||||
|
||||
$this->actingAs($buyer)->get("/kleinanzeigen/{$listing->id}")->assertInertia(fn (Assert $p) => $p->where('listing.contact', 'mail')->missing('listing.seller.email'));
|
||||
$this->actingAs($buyer)->post("/kleinanzeigen/{$listing->id}/kontakt", ['message' => 'Ist das Rad noch da?'])->assertSessionHas('status');
|
||||
|
||||
Mail::assertQueued(ContactMessage::class, fn (ContactMessage $m) => $m->hasTo('verkauf@example.org') && $m->hasReplyTo('kauf@example.org'));
|
||||
$this->actingAs($seller)->post("/kleinanzeigen/{$listing->id}/kontakt", ['message' => 'selbst'])->assertStatus(422);
|
||||
}
|
||||
|
||||
public function test_favorites_reports_and_housekeeping(): void
|
||||
{
|
||||
Notification::fake();
|
||||
$seller = User::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
$soon = Listing::query()->create([...collect($this->payload())->except('price')->all(), 'user_id' => $seller->id, 'status' => 'active', 'published_at' => now()->subDays(28), 'expires_at' => now()->addDays(2)]);
|
||||
$old = Listing::query()->create([...collect($this->payload(['title' => 'Alt']))->except('price')->all(), 'user_id' => $seller->id, 'status' => 'active', 'published_at' => now()->subDays(40), 'expires_at' => now()->subDay()]);
|
||||
|
||||
$this->actingAs($user)->post("/kleinanzeigen/{$soon->id}/merken");
|
||||
$this->actingAs($user)->get('/kleinanzeigen?merkliste=1')->assertInertia(fn (Assert $p) => $p->has('listings', 1)->where('listings.0.favorite', true));
|
||||
|
||||
$this->actingAs($user)->post("/kleinanzeigen/{$soon->id}/melden", ['reason' => 'Doppelt eingestellt']);
|
||||
Notification::assertSentTo($this->moderator, PortalNotification::class, fn ($n) => str_contains($n->title, 'gemeldet'));
|
||||
$this->actingAs($this->moderator)->get('/kleinanzeigen/moderation')->assertInertia(fn (Assert $p) => $p->has('reported', 1)->where('reported.0.reasons.0', 'Doppelt eingestellt'));
|
||||
|
||||
app(Market::class)->housekeeping();
|
||||
$this->assertSame('expired', $old->fresh()->status);
|
||||
$this->assertNotNull($soon->fresh()->reminded_at);
|
||||
Notification::assertSentTo($seller, PortalNotification::class, fn ($n) => str_contains($n->title, 'läuft bald ab'));
|
||||
|
||||
$this->actingAs($seller)->post("/kleinanzeigen/{$old->id}/verlaengern");
|
||||
$this->assertSame('active', $old->fresh()->status);
|
||||
$this->assertTrue($old->fresh()->expires_at->isAfter(now()->addDays(29)));
|
||||
}
|
||||
}
|
||||
5
vite.config.js
Normal file
5
vite.config.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { defineConfig } from 'vite';
|
||||
import { inhausPlugin } from './inhaus-sdk/vite.js';
|
||||
|
||||
// Baut resources/js/{pages,widgets,blocks,…} nach dist/ (siehe inhaus-sdk/vite.js)
|
||||
export default defineConfig(inhausPlugin());
|
||||
Loading…
Add table
Add a link
Reference in a new issue