Skip to content

Commit 1430698

Browse files
Merge pull request #43 from thethunderturner/feature/files-left
File Uploading and QoL changes
2 parents e763969 + fd301ee commit 1430698

18 files changed

+247
-152
lines changed

ISSUES.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

README.md

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
# This is my package filament-latex
1+
# Filament LaTeX
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/thethunderturner/filament-latex.svg?style=flat-square)](https://packagist.org/packages/thethunderturner/filament-latex)
44
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/thethunderturner/filament-latex/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/thethunderturner/filament-latex/actions?query=workflow%3Arun-tests+branch%3Amain)
55
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/thethunderturner/filament-latex/fix-php-code-styling.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/thethunderturner/filament-latex/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/thethunderturner/filament-latex.svg?style=flat-square)](https://packagist.org/packages/thethunderturner/filament-latex)
77

8-
9-
10-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
8+
Filament LaTeX is a powerful package that allows you to generate PDFs from LaTeX templates. The plugin is still in development, but the basic functionality is implemented.
9+
<div style="display: flex; align-items: center; justify-content: center;">
10+
<img src="assets/filament-latex.png" alt="Filament LaTeX" style="margin-right: 10px; width: 45%;">
11+
<img src="assets/filament-latex-upload.png" alt="Filament LaTeX Upload" style="width: 45%;">
12+
</div>
1113

1214
## Installation
1315

14-
Before you start, make sure you have `textlive-full` or `textlive-base` installed on your system. At the moment the plugin is available only on Unix systems (Linux/MacOS). <br>
15-
You can install `textlive` by running the following command:
16+
Before you start, make sure you have `texlive-full` or `texlive-base` installed on your system. You can install it on an Unix based system (Linux/MacOS) by running:
1617
```bash
1718
sudo apt-get install texlive-full # for debian based systems
1819
sudo pacman -S texlive-full # for arch based systems
1920
brew install texlive-full # for MacOS
2021
```
21-
After you have installed `textlive`, find where the `pdflatex` binary is located by running:
22+
If you are on Windows then please visit the [TeX Live website](https://tug.org/texlive/windows.html) and follow the instructions. \
23+
After you have installed `texlive`, find where the `pdflatex` binary is located by running this in your console:
2224
```bash
23-
which pdflatex
25+
which pdflatex # for Unix based systems
26+
where pdflatex # for Windows
2427
```
2528
Copy and paste the path on the plugin configuration file. <br>
2629
You can install the package via composer:
@@ -40,31 +43,20 @@ You can publish the config file with:
4043
```bash
4144
php artisan vendor:publish --tag="filament-latex-config"
4245
```
43-
46+
After publishing the path, make sure you replace the path of your `pdflatex` binary in the `config/filament-latex.php` file. \
47+
\
4448
Optionally, you can publish the views using
4549

4650
```bash
4751
php artisan vendor:publish --tag="filament-latex-views"
4852
```
4953

50-
This is the contents of the published config file:
51-
52-
```php
53-
return [
54-
];
55-
```
56-
57-
## Usage
58-
54+
You can use the package by adding it to the plugins list of your panel.
5955
```php
60-
$filamentLatex = new TheThunderTurner\FilamentLatex();
61-
echo $filamentLatex->echoPhrase('Hello, TheThunderTurner!');
62-
```
63-
64-
## Testing
65-
66-
```bash
67-
composer test
56+
->plugins([
57+
// ...
58+
FilamentLatexPlugin::make(),
59+
]);
6860
```
6961

7062
## Changelog

assets/filament-latex-upload.png

161 KB
Loading

assets/filament-latex.png

152 KB
Loading

database/migrations/create_filament_latex_table.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
1111
*/
1212
public function up(): void
1313
{
14-
// Dont forget to delete (DEV ONLY)
15-
if (Schema::hasTable('filament-latex')) {
16-
Schema::dropIfExists('filament-latex');
17-
}
1814
Schema::create('filament-latex', function (Blueprint $table) {
1915
$table->id();
2016
$table->string('name');
2117
$table->text('content')->nullable();
2218
$table->dateTime('deadline');
2319
$table->bigInteger('author_id');
2420
$table->json('collaborators_id')->nullable();
21+
$table->json('attachment')->nullable();
22+
$table->json('attachment_file_names')->nullable();
2523
$table->timestamps();
2624
});
2725
}

phpstan.neon.dist

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ parameters:
1010
- src
1111
- resources
1212
reportUnmatchedIgnoredErrors: false
13-
excludePaths:
14-
analyse:
15-
- src/Resources/FilamentLatexResource.php
16-
- src/Resources/FilamentLatexResource/Pages/CreateFilamentLatex.php
17-
- src/Resources/FilamentLatexResource/Pages/EditFilamentLatex.php
18-
- src/Resources/FilamentLatexResource/Pages/ViewFilamentLatex.php
1913
tmpDir: build/phpstan
2014
checkOctaneCompatibility: true
2115
checkModelProperties: true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<x-filament::section class="w-64 rounded-r-none">
2+
<x-slot name="heading">File Upload</x-slot>
3+
4+
{{-- Upload Action --}}
5+
<div>
6+
{{ $this->uploadAction }}
7+
8+
<x-filament-actions::modals />
9+
</div>
10+
11+
<div class="mt-6 h-[79rem] overflow-auto space-y-2">
12+
@forelse($files as $file)
13+
@include('filament-latex::components.file-upload', ['file' => $file])
14+
@empty
15+
<div class="text-gray-500 dark:text-gray-400 text-center">
16+
No files uploaded.
17+
</div>
18+
@endforelse
19+
</div>
20+
</x-filament::section>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div class="p-2 border rounded-md bg-white dark:bg-gray-800 flex items-center justify-between shadow-sm">
2+
<span class="text-sm font-medium text-gray-700 dark:text-gray-300 truncate">
3+
{{ $file }}
4+
</span>
5+
<div>
6+
{{ ($this->deleteAction)(['file' => $file]) }}
7+
8+
<x-filament-actions::modals />
9+
</div>
10+
</div>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<x-filament::section class="w-full rounded-l-none">
2+
<x-slot name="heading">Filament Latex</x-slot>
3+
<div
4+
class="grid grid-cols-2 gap-4"
5+
x-data="{ message: '' }"
6+
x-init="$watch('message', value => {
7+
// Sync with Livewire component
8+
@this.latexContent = value;
9+
})"
10+
>
11+
{{-- Latex Editor --}}
12+
<div
13+
class="w-full border border-gray-200 rounded-lg dark:border-gray-700 h-screen overflow-auto"
14+
x-ignore
15+
ax-load
16+
x-model="message"
17+
ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('filament-latex', 'thethunderturner/filament-latex') }}"
18+
x-data="codeEditor({
19+
content: @js($latexContent),
20+
})"
21+
wire:ignore
22+
>
23+
</div>
24+
25+
{{-- PDF Preview --}}
26+
<div
27+
class="border border-gray-200 rounded-lg dark:border-gray-700"
28+
>
29+
@if($pdfUrl)
30+
<iframe
31+
x-data="{ pdfUrl: @js($pdfUrl) }"
32+
x-on:document-compiled.window="pdfUrl"
33+
class="w-full h-screen"
34+
:src="pdfUrl"
35+
>
36+
</iframe>
37+
@else
38+
<p>No PDF available to preview.</p>
39+
@endif
40+
</div>
41+
</div>
42+
</x-filament::section>

resources/views/page.blade.php

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,16 @@
11
@php
22
$latexContent = $this->latexContent;
33
$pdfUrl = $this->getPdfUrl();
4+
$files = $this->getFiles();
45
@endphp
56

67
<x-filament-panels::page>
78
<div class="inline-flex w-full justify-stretch rounded-md" role="group">
89

910
{{-- File Upload Container --}}
10-
<x-filament::section class="w-64 rounded-r-none">
11-
<x-slot name="heading">File Upload</x-slot>
12-
13-
TBA
14-
</x-filament::section>
11+
@include('filament-latex::components.file-upload-index', ['files' => $files])
1512

1613
{{-- Latex Container --}}
17-
<x-filament::section class="w-full rounded-l-none">
18-
<x-slot name="heading">Filament Latex</x-slot>
19-
<div
20-
class="grid grid-cols-2 gap-4"
21-
x-data="{ message: '' }"
22-
x-init="$watch('message', value => {
23-
// Sync with Livewire component
24-
@this.latexContent = value;
25-
})"
26-
>
27-
{{-- Latex Editor --}}
28-
<div
29-
class="w-full border border-gray-200 rounded-lg dark:border-gray-700 h-[75rem] overflow-auto"
30-
x-ignore
31-
ax-load
32-
x-model="message"
33-
ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('filament-latex', 'thethunderturner/filament-latex') }}"
34-
x-data="codeEditor({
35-
content: @js($latexContent),
36-
})"
37-
wire:ignore
38-
>
39-
</div>
40-
41-
{{-- PDF Preview --}}
42-
<div
43-
class="border border-gray-200 rounded-lg dark:border-gray-700"
44-
>
45-
@if($pdfUrl)
46-
<iframe
47-
x-data="{ pdfUrl: @js($pdfUrl) }"
48-
x-on:document-compiled.window="pdfUrl = @js($pdfUrl) + '?' + new Date().getTime()"
49-
class="w-full h-[75rem]"
50-
:src="pdfUrl"
51-
>
52-
</iframe>
53-
@else
54-
<p>No PDF available to preview.</p>
55-
@endif
56-
</div>
57-
</div>
58-
</x-filament::section>
14+
@include('filament-latex::components.latex-index', ['latexContent' => $latexContent, 'pdfUrl' => $pdfUrl])
5915
</div>
6016
</x-filament-panels::page>

routes/web.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
<?php
22

3+
use Filament\Facades\Filament;
34
use Illuminate\Support\Facades\Route;
45
use TheThunderTurner\FilamentLatex\Http\Controllers\FileController;
56

6-
Route::get(config('filament-latex.storage-url') . '/{recordID}', [FileController::class, 'getPrivateFile'])
7-
->name('pdf.download');
7+
Route::name('filament.')->group(function () {
8+
foreach (Filament::getPanels() as $panel) {
9+
$domains = $panel->getDomains();
10+
11+
foreach ((empty($domains) ? [null] : $domains) as $domain) {
12+
Route::domain($domain)
13+
->middleware($panel->getMiddleware())
14+
->name($panel->getId() . '.')
15+
->prefix($panel->getPath())
16+
->group(function () use ($panel) {
17+
if ($panel->hasPlugin('filament-latex')) {
18+
Route::get(config('filament-latex.storage-url') . '/{recordID}/document', [FileController::class, 'getPrivateFile'])
19+
->middleware('auth')
20+
->name('auth.file');
21+
}
22+
});
23+
}
24+
}
25+
});

src/Concerns/CanUploadFiles.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace TheThunderTurner\FilamentLatex\Concerns;
4+
5+
use Filament\Actions\Action;
6+
use Filament\Forms\Components\FileUpload;
7+
8+
trait CanUploadFiles
9+
{
10+
/**
11+
* Uploads a file.
12+
*/
13+
public function uploadAction(): Action
14+
{
15+
return Action::make('upload')
16+
->color('success')
17+
->label('Upload Files')
18+
->icon('heroicon-o-document-arrow-up')
19+
->requiresConfirmation()
20+
->extraAttributes([
21+
'class' => 'w-full',
22+
])
23+
->form([
24+
FileUpload::make('attachment')
25+
->required()
26+
->disk(config('filament-latex.storage'))
27+
->directory($this->filamentLatex->id . '/files')
28+
->visibility('private')
29+
->preserveFilenames(),
30+
]);
31+
}
32+
33+
/**
34+
* Deletes a file.
35+
*/
36+
public function deleteAction(): Action
37+
{
38+
return Action::make('delete')
39+
->iconButton()
40+
->icon('heroicon-o-trash')
41+
->color('danger')
42+
->requiresConfirmation()
43+
->action(function ($arguments) {
44+
return $this->getStorage()->delete($this->filamentLatex->id . '/files/' . $arguments['file']);
45+
});
46+
}
47+
48+
/**
49+
* Returns an array of files that have been
50+
* uploaded.
51+
*
52+
* All files are uploaded in files/ directory. In the future
53+
* we could add subdirectories for better organization.
54+
*/
55+
public function getFiles(): array
56+
{
57+
return array_map('basename', $this->getStorage()->files($this->filamentLatex->id . '/files'));
58+
}
59+
}

0 commit comments

Comments
 (0)