From: Hamatoma Date: Sat, 20 Apr 2024 15:51:27 +0000 (+0200) Subject: V 0.1.8 Chapter X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=8aedd1418641029e3f310a0acefcf0017709d815;p=gadeku.git V 0.1.8 Chapter Added - TextProcessor - Modul Chapter - ModuleGaDeKuSeeder.php, SPropertyAudioSeeder.php --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 60d33d6..f422fdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# V 0.1.8 Chapter + +## Added +- TextProcessor +- Modul Chapter +- ModuleGaDeKuSeeder.php, SPropertyAudioSeeder.php + + # V 0.1.7 Übersetzungen in Words ## Added: diff --git a/app/Helpers/TextProcessor.php b/app/Helpers/TextProcessor.php new file mode 100644 index 0000000..e6ff8bb --- /dev/null +++ b/app/Helpers/TextProcessor.php @@ -0,0 +1,45 @@ +$text"; + return $rc; + }, + $text + ); + $rc = "

$text2

\n"; + return $rc; + } + public static function starToTrans(string $text): string + { + $rc = preg_replace('/\*(\w[^*]+\w)\*/', '%trans($1)%', $text); + return $rc; + } +} diff --git a/app/Http/Controllers/ChapterController.php b/app/Http/Controllers/ChapterController.php new file mode 100644 index 0000000..6138b74 --- /dev/null +++ b/app/Http/Controllers/ChapterController.php @@ -0,0 +1,235 @@ +btnSubmit === 'btnCancel') { + $rc = redirect('/chapter-index'); + } else { + $fields = $request->all(); + if (count($fields) === 0) { + $records = DB::select('select max(`order`) as maxorder from chapters'); + $order = intval(($records[0]->maxorder + 10) / 10) * 10; + $fields = [ + 'order' => $order, + 'title' => '', + 'info' => '', + 'contents' => '' + ]; + } + $context = new ContextLaraKnife($request, $fields); + $rc = view('chapter.create', [ + 'context' => $context, + ]); + } + return $rc; + } + /** + * Show the form for editing the specified resource. + */ + public function edit(Chapter $chapter, Request $request) + { + if ($request->btnSubmit === 'btnCancel') { + $rc = redirect('/chapter-index'); + } else { + $fields = $request->all(); + if (count($fields) === 0) { + $file = $chapter->audio_id == null ? '' : File::find($chapter->audio_id)->filename; + $fields = [ + 'order' => '', + 'title' => '', + 'info' => '', + 'contents' => '', + 'file' => $file + ]; + } + $context = new ContextLaraKnife($request, $fields, $chapter); + $rc = view('chapter.edit', [ + 'context' => $context, + ]); + } + return $rc; + } + /** + * Remove the specified resource from storage. + */ + public function destroy(Chapter $chapter, Request $request) + { + if ($request->btnSubmit === 'btnDelete') { + $chapter->delete(); + } + return redirect('/chapter-index'); + } + /** + * Display the database records of the resource. + */ + public function index(Request $request) + { + if ($request->btnSubmit === 'btnNew') { + return redirect('/chapter-create'); + } else { + $sql = 'SELECT t0.*' + . ' FROM chapters t0' + ; + $parameters = []; + $fields = $request->all(); + if (count($fields) == 0) { + $fields = [ + 'order' => '', + 'title' => '', + 'info' => '', + 'contents' => '', + '_sortParams' => 'order:asc;id:asc' + ]; + } else { + $conditions = []; + ViewHelper::addConditionPattern($conditions, $parameters, 'title,info,contents', 'text'); + $sql = DbHelper::addConditions($sql, $conditions); + } + $sql = DbHelper::addOrderBy($sql, $fields['_sortParams']); + $pagination = new Pagination($sql, $parameters, $fields); + $records = $pagination->records; + $context = new ContextLaraKnife($request, $fields); + return view('chapter.index', [ + 'context' => $context, + 'records' => $records, + 'pagination' => $pagination + ]); + } + } + /** + * Returns the validation rules. + * @return array The validation rules. + */ + private function rules(bool $isCreate = false): array + { + $rc = [ + 'order' => 'required', + 'title' => 'required', + 'info' => '', + 'contents' => 'required' + ]; + return $rc; + } + public static function routes() + { + Route::get('/chapter-index', [ChapterController::class, 'index'])->middleware('auth'); + Route::post('/chapter-index', [ChapterController::class, 'index'])->middleware('auth'); + Route::get('/chapter-create', [ChapterController::class, 'create'])->middleware('auth'); + Route::put('/chapter-store', [ChapterController::class, 'store'])->middleware('auth'); + Route::post('/chapter-edit/{chapter}', [ChapterController::class, 'edit'])->middleware('auth'); + Route::get('/chapter-edit/{chapter}', [ChapterController::class, 'edit'])->middleware('auth'); + Route::post('/chapter-update/{chapter}', [ChapterController::class, 'update'])->middleware('auth'); + Route::get('/chapter-show/{chapter}/delete', [ChapterController::class, 'show'])->middleware('auth'); + Route::delete('/chapter-show/{chapter}/delete', [ChapterController::class, 'destroy'])->middleware('auth'); + Route::get('/chapter-showpretty/{chapter}', [ChapterController::class, 'showPretty'])->middleware('auth'); + Route::post('/chapter-showpretty/{chapter}', [ChapterController::class, 'showPretty'])->middleware('auth'); + } + /** + * Display the specified resource. + */ + public function show(Chapter $chapter, Request $request) + { + if ($request->btnSubmit === 'btnCancel') { + $rc = redirect('/chapter-index')->middleware('auth'); + } else { + $context = new ContextLaraKnife($request, null, $chapter); + $rc = view('chapter.show', [ + 'context' => $context, + 'mode' => 'delete' + ]); + } + return $rc; + } + + public function showPretty(Chapter $chapter, Request $request) + { + if ($request->btnSubmit === 'btnCancel') { + $rc = redirect('/chapter-index')->middleware('auth'); + } else { + $text = TextProcessor::markupToHtml($chapter->contents); + $link = $chapter->audio_id == null ? null : File::relativeFileLink($chapter->audio_id); + $context = new ContextLaraKnife($request, ['text' => $text, 'link' => $link], $chapter); + $rc = view('chapter.showpretty', [ + 'context' => $context, + 'mode' => 'delete' + ]); + } + return $rc; + + } + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + $rc = null; + if ($request->btnSubmit === 'btnStore') { + $fields = $request->all(); + $validator = Validator::make($fields, $this->rules(true)); + if ($validator->fails()) { + $rc = back()->withErrors($validator)->withInput(); + } else { + $validated = $validator->validated(); + $validated['info'] = strip_tags($validated['info']); + $validated['contents'] = TextProcessor::starToTrans($validated['contents']); + Chapter::create($validated); + } + } + if ($rc == null) { + $rc = redirect('/chapter-index'); + } + return $rc; + } + /** + * Update the specified resource in storage. + */ + public function update(Chapter $chapter, Request $request) + { + $rc = null; + if ($request->btnSubmit === 'btnStore') { + $fields = $request->all(); + $validator = Validator::make($fields, $this->rules(false)); + if ($validator->fails()) { + $rc = back()->withErrors($validator)->withInput(); + } else { + $validated = $validator->validated(); + $validated['info'] = strip_tags($validated['info']); + $validated['contents'] = strip_tags($validated['contents']); + if (empty($chapter->audio_id) && $request->file('file') != null) { + $filename = FileHelper::textToFilename($chapter->title); + $moduleId = Module::idOfModule('chapter'); + $fileId = File::storeFile($request, $chapter->title, 1103, 1091, 'audio file of chapter', $filename, $moduleId , $chapter->id); + $validated['audio_id'] = $fileId; + } + $chapter->update($validated); + } + } + if ($rc == null) { + $rc = redirect('/chapter-index'); + } + return $rc; + } +} diff --git a/app/Models/Chapter.php b/app/Models/Chapter.php new file mode 100644 index 0000000..cd8f508 --- /dev/null +++ b/app/Models/Chapter.php @@ -0,0 +1,22 @@ +id(); + $table->timestamps(); + $table->integer('order'); + $table->string('title'); + $table->text('info'); + $table->text('contents'); + $table->foreignId('audio_id')->nullable()->references('id')->on('files'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('chapters'); + } +}; diff --git a/database/seeders/ChapterSeeder.php b/database/seeders/ChapterSeeder.php new file mode 100644 index 0000000..6587974 --- /dev/null +++ b/database/seeders/ChapterSeeder.php @@ -0,0 +1,24 @@ +insert([ + 'name' => 'chapters', + 'label' => 'Chapters', + 'icon' => 'bi bi-book', + 'section' => 'main', + 'link' => '/chapter-index' + ]); + } +} diff --git a/database/seeders/ModuleGaDeKuSeeder.php b/database/seeders/ModuleGaDeKuSeeder.php new file mode 100644 index 0000000..5c9402f --- /dev/null +++ b/database/seeders/ModuleGaDeKuSeeder.php @@ -0,0 +1,45 @@ + $name])->first() != null; + return $rc; + } + private function insert(string $name, string $table=null){ + if (! $this->exists($name)){ + $table ??= strtolower($name) . 's'; + DB::table('modules')->insert([ + 'name' => $name, + 'tablename' => $table + ]); + } + } + /** + * Run the database seeds. + */ + public function run(): void + { + /* + $this->insert('SProperty'); + $this->insert('Role'); + $this->insert('User'); + $this->insert('Note'); + $this->insert('Menuitem'); + $this->insert('File'); + $this->insert('Module'); + */ + $this->insert('Word'); + $this->insert('Verb'); + $this->insert('Nomen'); + $this->insert('Phrase'); + $this->insert('Chapter'); + } +} diff --git a/database/seeders/SPropertyAudioSeeder.php b/database/seeders/SPropertyAudioSeeder.php new file mode 100644 index 0000000..04fec59 --- /dev/null +++ b/database/seeders/SPropertyAudioSeeder.php @@ -0,0 +1,29 @@ +insert([ + 'id' => 1103, 'scope' => 'filegroup', 'name' => 'Audio file', 'order' => '30', 'shortname' => 'AUDIO' + ]); + DB::table('sproperties')->insert([ + 'id' => 1104, 'scope' => 'filegroup', 'name' => 'Video file', 'order' => '40', 'shortname' => 'VIDEO' + ]); + DB::table('sproperties')->insert([ + 'id' => 1105, 'scope' => 'filegroup', 'name' => 'Image file', 'order' => '50', 'shortname' => 'IMG' + ]); + DB::table('sproperties')->insert([ + 'id' => 1106, 'scope' => 'filegroup', 'name' => 'Document file', 'order' => '60', 'shortname' => 'DOC' + ]); + } +} diff --git a/lang/de_DE.json b/lang/de_DE.json index 9ce4bbc..db6a9ee 100644 --- a/lang/de_DE.json +++ b/lang/de_DE.json @@ -15,6 +15,7 @@ "Category": "Kategorie", "Change": "\u00c4ndern", "Change Password of an User": "Passwort eines Benutzers \u00e4ndern", + "Change of a Chapter": "\u00c4nderung eines Kapitels", "Change of a File": "\u00c4ndern einer Datei", "Change of a Menu Item": "\u00c4ndern einer Men\u00fceintrags", "Change of a Note": "\u00c4ndern einer Notiz", @@ -26,7 +27,11 @@ "Change of a Verb": "\u00c4nderung eines Verbs", "Change of a Word": "\u00c4nderung eines Wortes", "Change of an User": "\u00c4ndern eines Benutzers", + "Chapter": "Kapitel", + "Chapters": "Kapitel", "Confirmation": "Best\u00e4tigung", + "Contents": "Inhalt", + "Creation of a Chapter": "Neues Kapitel", "Creation of a Document": "Hochladen eines Dokuments", "Creation of a File": "Hochladen einer Datei", "Creation of a Menu Item": "Erstellen eine Men\u00fceintrags", @@ -53,6 +58,7 @@ "Duration": "Dauer", "Email": "Email", "English (Britisch)": "Englisch (GB)", + "Exchange of a File": "Austausch einer Datei", "File": "Datei", "Filegroup": "Gruppe", "Filename": "Dateiname", diff --git a/missing.seeders b/missing.seeders index 5c7ba4b..3da93a6 100644 --- a/missing.seeders +++ b/missing.seeders @@ -1,3 +1,3 @@ # Enter the module names separated by " ". # Example: MISSING="User Role Menuitem" -MISSING="" +MISSING="ChapterSeeder SPropertyAudioSeeder ModuleGaDeKuSeeder" diff --git a/public/css/gadeku.css b/public/css/gadeku.css index 97bbb85..74154d5 100644 --- a/public/css/gadeku.css +++ b/public/css/gadeku.css @@ -15,3 +15,9 @@ input, button { background-color: #333; border-color: #CCC; } +.translation { + visibility: hidden; +} +.translation:hover { + visibility: visible; +} \ No newline at end of file diff --git a/resources/lang/sources/gadeku.de.json b/resources/lang/sources/gadeku.de.json index eee27ca..973335d 100644 --- a/resources/lang/sources/gadeku.de.json +++ b/resources/lang/sources/gadeku.de.json @@ -2,10 +2,15 @@ "!comment": "Bitte alphabetisch sortiert eintragen!", "": "", "Adjective": "Adjektiv", +"Change of a Chapter": "Änderung eines Kapitels", "Change of a Noun": "Änderung eines Nomens", "Change of a Phrase": "Änderung eines Satzes", "Change of a Verb": "Änderung eines Verbs", "Change of a Word": "Änderung eines Wortes", +"Chapter": "Kapitel", +"Chapters": "Kapitel", +"Contents": "Inhalt", +"Creation of a Chapter": "Neues Kapitel", "Creation of a Verb": "Neues Verb", "Deletion of a Noun": "Löschen eines Nomens", "Deletion of a Verb": "Löschen eines Verbs", diff --git a/resources/views/chapter/create.blade.php b/resources/views/chapter/create.blade.php new file mode 100644 index 0000000..b4ae9ea --- /dev/null +++ b/resources/views/chapter/create.blade.php @@ -0,0 +1,17 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + @method('PUT') + + + + + + +
+@endsection diff --git a/resources/views/chapter/edit.blade.php b/resources/views/chapter/edit.blade.php new file mode 100644 index 0000000..4e425ba --- /dev/null +++ b/resources/views/chapter/edit.blade.php @@ -0,0 +1,20 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + + + + + + + + +
+@endsection diff --git a/resources/views/chapter/index.blade.php b/resources/views/chapter/index.blade.php new file mode 100644 index 0000000..a1d353c --- /dev/null +++ b/resources/views/chapter/index.blade.php @@ -0,0 +1,35 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + + + + + + + + + + {{__('Order')}} + {{__('Title')}} + {{__('Info')}} + + + + +@foreach ($records as $chapter) + + + {{$chapter->order}} + {{$chapter->title}} + {{$chapter->info}} + + +@endforeach + + + +
+@endsection diff --git a/resources/views/chapter/show.blade.php b/resources/views/chapter/show.blade.php new file mode 100644 index 0000000..ae060a4 --- /dev/null +++ b/resources/views/chapter/show.blade.php @@ -0,0 +1,17 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + @if($mode === 'delete') + @method('DELETE') + @endif + + + + + + + +
+@endsection diff --git a/resources/views/chapter/showpretty.blade.php b/resources/views/chapter/showpretty.blade.php new file mode 100644 index 0000000..15c8853 --- /dev/null +++ b/resources/views/chapter/showpretty.blade.php @@ -0,0 +1,17 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf + +
+ {!! $context->valueOf('text') !!} +
+
+ @if ($context->valueof('link') != null) +
+ +
+ @endif +
+@endsection diff --git a/routes/web.php b/routes/web.php index 1d9b99a..5662c04 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,6 +12,7 @@ use App\Http\Controllers\WordController; use App\Http\Controllers\PhraseController; use App\Http\Controllers\ReviewController; use App\Http\Controllers\MenuitemController; +use App\Http\Controllers\ChapterController; use App\Http\Controllers\SPropertyController; Route::get('/', function () { @@ -32,3 +33,5 @@ VerbController::routes(); PhraseController::routes(); ReviewController::routes(); + +ChapterController::routes();