Skip to content

Commit cfa640b

Browse files
authored
Merge pull request #15 from tattersoftware/pages
Pages
2 parents 91544b1 + b3c101a commit cfa640b

File tree

29 files changed

+623
-249
lines changed

29 files changed

+623
-249
lines changed

.github/workflows/analyze.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
uses: actions/cache@v2
4747
with:
4848
path: ${{ steps.composer-cache.outputs.dir }}
49-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
49+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
5050
restore-keys: ${{ runner.os }}-composer-
5151

5252
- name: Create PHPStan cache directory

README.md

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ File uploads and management, for CodeIgniter 4
66
1. Install with Composer: `> composer require tatter/files`
77
2. Migrate the database: `> php spark migrate -all`
88
2. Seed the database: `> php spark db:seed "Tatter\Files\Database\Seeds\FileSeeder"`
9-
3. Start managing files: https://[yourdomain.com]/files
9+
3. Start managing files: https://example.com/files
1010

1111
## Features
1212

1313
The Files module is a self-contained set of routes and functions that adds uploading and
1414
CRUD controls to any project. It uses [DropzoneJS](https://www.dropzonejs.com) for
15-
drag-and-drop uploads, and supports a number of extensions for directing files to other
16-
locations (WIP).
15+
drag-and-drop uploads, and supports a number of extensions for generating file thumbnails
16+
and exporting files to various destinations.
1717

1818
## Installation
1919

@@ -41,14 +41,21 @@ writable/files/*
4141
## Configuration (optional)
4242

4343
The library's default behavior can be altered by extending its config file. Copy
44-
**bin/Files.php** to **app/Config/** and follow the instructions
44+
**examples/Files.php** to **app/Config/** and follow the instructions
4545
in the comments. If no config file is found in **app/Config** the library will use its own.
4646

4747
## Usage
4848

4949
Default routes:
5050
* **files/index** - If user is allowed `mayList()` then shows all files, otherwise tries to fall back to the current logged in user
51-
* **files/user** - Shows files for a single user; if no user ID is supplied it defaults to the current logged in user
51+
* **files/user/{userId}** - Shows files for a single user; if no user ID is supplied it defaults to the current logged in user
52+
* **files/thumbnail/{fileId}** - Displays the thumbnail for a file
53+
54+
CRUD:
55+
* **files/new** - Basic Dropzone form
56+
* **files/upload** - Accepts AJAX upload requests from Dropzone
57+
* **files/delete/{fileId}** - Removes a file
58+
* **files/rename/{fileId}** - Accepts POST data to rename a file
5259

5360
Available formats:
5461
* **?format=cards** - Default view with thumbnail on responsive layout
@@ -63,3 +70,51 @@ group for global file access.
6370

6471
By default the **files/** routes are available as soon as the module is installed. In most
6572
cases you will want to use Route Filters to restrict some or all of the routes.
73+
74+
## Extending
75+
76+
**Controllers/Files.php** is the heart of the module, using cascading options to choose
77+
which files to display when. This controller has a `setData()` method to allow you to
78+
intercept this process to provide your own settings at any point. Simply extend the
79+
controller to your own and then provide whatever changes you would like, followed
80+
by the `display()` method. E.g.:
81+
82+
```
83+
<?php namespace App\Controller;
84+
85+
class WidgetFiles
86+
{
87+
public function index($widgetId)
88+
{
89+
$this->setData([
90+
'format' => 'cards',
91+
'files' => model(WidgetModel::class)->getFiles($widgetId),
92+
'layout' => 'manage',
93+
]);
94+
95+
return $this->display();
96+
}
97+
}
98+
99+
```
100+
101+
These are the default options for `setData()`, but you may also supply anything else you
102+
need in your view:
103+
104+
* `source` - The name of the controller method making the call
105+
* `layout` - The view layout to use (see **Config/Files.php**)
106+
* `files` - An array of Files to display
107+
* `selected` - Files to pre-select (for the `select` format)
108+
* `userId` - ID of a user to filter for Files`
109+
* `username` - Display name of the user for the default layout title
110+
* `ajax` - Whether to process the request as an AJAX call (skips layout wrapping)
111+
* `search` - Search term to filter Files
112+
* `sort` - File sort field
113+
* `order` - File sort order
114+
* `format` - Display format for files (cards, list, select, or your own!)
115+
* `perPage` - Number of items to display per page
116+
* `page` - Page number (leave `null` for default Pager handling)
117+
* `pager` - `Pager` instance to handle pagination
118+
* `access` - Whether the files can be modified, "manage" or "display"
119+
* `exports` - Destinations a File may be sent to (see `Tatter\Exports`)
120+
* `bulks` - Bulk destinations for a group of Files (see `Tatter\Exports`)

bin/Files.php

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

examples/Files.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php namespace Config;
2+
3+
/***
4+
*
5+
* This file contains example values to alter default library behavior.
6+
* Recommended usage:
7+
* 1. Copy the file to app/Config/Files.php
8+
* 2. Change any values
9+
* 3. Remove any lines to fallback to defaults
10+
*
11+
***/
12+
13+
class Files extends \Tatter\Files\Config\Files
14+
{
15+
/**
16+
* Directory to store files (with trailing slash)
17+
*
18+
* @var string
19+
*/
20+
public $storagePath = WRITEPATH . 'files/';
21+
22+
/**
23+
* Layouts to use for general access and for administration
24+
*
25+
* @var array<string, string>
26+
*/
27+
public $layouts = [
28+
'public' => 'Tatter\Files\Views\layout',
29+
'manage' => 'Tatter\Files\Views\layout',
30+
];
31+
32+
/**
33+
* View file aliases
34+
*
35+
* @var string[]
36+
*/
37+
public $views = [
38+
'dropzone' => 'Tatter\Files\Views\Dropzone\config',
39+
];
40+
41+
/**
42+
* Default display format; built in are 'cards', 'list', 'select'
43+
*
44+
* @var string
45+
*/
46+
public $defaultFormat = 'cards';
47+
48+
/**
49+
* Path to the default thumbnail file
50+
*
51+
* @var string
52+
*/
53+
public $defaultThumbnail = 'Tatter\Files\Assets\Unavailable.jpg';
54+
}
File renamed without changes.

src/Commands/MaintainFiles.php

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

src/Config/Files.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Files extends BaseConfig
1414
/**
1515
* Layouts to use for general access and for administration
1616
*
17-
* @var string[]
17+
* @var array<string, string>
1818
*/
1919
public $layouts = [
2020
'public' => 'Tatter\Files\Views\layout',

src/Config/Registrar.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php namespace Tatter\Files\Config;
2+
3+
/**
4+
* Class Registrar
5+
*
6+
* Provides a basic registrar class for testing BaseConfig registration functions.
7+
*/
8+
9+
class Registrar
10+
{
11+
/**
12+
* Override database config
13+
*
14+
* @return array
15+
*/
16+
public static function Pager()
17+
{
18+
return [
19+
'templates' => [
20+
'files_bootstrap' => 'Tatter\Files\Views\pager',
21+
],
22+
];
23+
}
24+
}

src/Config/Routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
$routes->group('files', ['namespace' => '\Tatter\Files\Controllers'], function ($routes)
55
{
66
$routes->get('/', 'Files::index');
7-
$routes->get('index/(:any)', 'Files::index/$1');
7+
$routes->get('user', 'Files::user');
88
$routes->get('user/(:any)', 'Files::user/$1');
9-
//$routes->get('delete/(:num)', 'Files::delete/$1');
9+
$routes->get('delete/(:num)', 'Files::delete/$1');
1010
$routes->get('thumbnail/(:num)', 'Files::thumbnail/$1');
1111

1212
$routes->post('upload', 'Files::upload');

0 commit comments

Comments
 (0)