urls & files: set page size to 25, add page nav and sort by create desc

This commit is contained in:
Alice Gaudon 2021-03-30 12:31:47 +02:00
parent 0dfae21005
commit 0de960a168
6 changed files with 16 additions and 2 deletions

View File

@ -26,7 +26,7 @@ export default class FileController extends Controller {
max_upload_size: config.get<string>('max_upload_size'),
allowed_domains: allowedDomains,
default_domain: allowedDomains[config.get<number>('default_url_domain_for_files')],
files: await FileModel.paginateForUser(req, 100, user.getOrFail('id')),
files: await FileModel.paginateForUser(req, 25, user.getOrFail('id')),
});
}

View File

@ -18,7 +18,7 @@ export default class URLRedirectController extends Controller {
res.render('url-shrinker', {
allowed_domains: allowedDomains,
default_domain: allowedDomains[config.get<number>('default_url_domain_for_urls')],
urls: await URLRedirect.paginateForUser(req, 2, user.getOrFail('id')),
urls: await URLRedirect.paginateForUser(req, 25, user.getOrFail('id')),
});
}

View File

@ -15,6 +15,8 @@ export default class FileModel extends Model {
}
public static async paginateForUser(req: Request, perPage: number, user_id: number): Promise<FileModel[]> {
req.params.sortBy = 'created_at';
req.params.sortDirection = 'DESC';
return await this.paginate(req, perPage, this.select().where('user_id', user_id));
}

View File

@ -15,6 +15,8 @@ export default class URLRedirect extends Model {
}
public static async paginateForUser(req: Request, perPage: number, user_id: number): Promise<URLRedirect[]> {
req.params.sortBy = 'created_at';
req.params.sortDirection = 'DESC';
return await this.paginate(req, perPage, this.select().where('user_id', user_id));
}

View File

@ -54,6 +54,9 @@
<section class="panel">
<h2><i data-feather="folder"></i> File list</h2>
{{ macros.paginate(files.pagination, 'file-uploader', 3) }}
<table class="data-table">
<thead>
<tr>
@ -94,6 +97,8 @@
{% endfor %}
</tbody>
</table>
{{ macros.paginate(files.pagination, 'file-uploader', 3) }}
</section>
</div>
{% endblock %}

View File

@ -38,6 +38,9 @@
<section class="panel">
<h2><i data-feather="link"></i> URL list</h2>
{{ macros.paginate(urls.pagination, 'url-shrinker', 3) }}
<table class="data-table">
<thead>
<tr>
@ -62,6 +65,8 @@
{% endfor %}
</tbody>
</table>
{{ macros.paginate(urls.pagination, 'url-shrinker', 3) }}
</section>
</div>
{% endblock %}