Browse Source

Added file upload validation, added master and file lang

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
c3d4c0a410
  1. 11
      app/Http/Controllers/Projects/FilesController.php
  2. 30
      resources/lang/id/file.php
  3. 43
      resources/lang/id/master.php
  4. 3
      resources/lang/id/project.php
  5. 31
      resources/views/projects/files.blade.php
  6. 10
      tests/Feature/Projects/UploadFilesTest.php

11
app/Http/Controllers/Projects/FilesController.php

@ -26,6 +26,12 @@ class FilesController extends Controller
public function create(Request $request, $fileableId)
{
$this->validate($request, [
'file' => 'required|file|max:10000',
'title' => 'required|max:60',
'description' => 'nullable|max:255',
]);
$fileableExist = array_search($request->get('fileable_type'), $this->fileableTypes);
if ($fileableExist) {
@ -43,11 +49,8 @@ class FilesController extends Controller
private function proccessPhotoUpload($data, $fileableType, $fileableId)
{
// dd(get_class_methods($data['files']));
$file = $data['files'];
// $fileName = md5(uniqid(rand(), true)).'.'.$file->getClientOriginalExtension();
$file = $data['file'];
$fileName = $file->hashName();
// dd($fileName);
$fileData['fileable_id'] = $fileableId;
$fileData['fileable_type'] = $fileableType;

30
resources/lang/id/file.php

@ -0,0 +1,30 @@
<?php
return [
// Labels
'file' => 'File',
'list' => 'Daftar File',
'search' => 'Cari File',
'not_found' => 'File tidak ditemukan',
'empty' => 'Belum ada File',
'back_to_index' => 'Kembali ke daftar File',
// Actions
'create' => 'Upload File Baru',
'created' => 'Upload File baru telah berhasil.',
'edit' => 'Edit File',
'update' => 'Update File',
'updated' => 'Update data File telah berhasil.',
'delete' => 'Hapus File',
'delete_confirm' => 'Anda yakin akan menghapus File ini?',
'deleted' => 'Hapus data File telah berhasil.',
'undeleted' => 'Data File gagal dihapus.',
'undeleteable' => 'Data File tidak dapat dihapus.',
'select' => 'Pilih File',
'upload' => 'Upload File',
'download' => 'Download File',
// Attributes
'name' => 'Nama File',
'description' => 'Deskripsi File',
];

43
resources/lang/id/master.php

@ -1,21 +1,28 @@
<?php
return [
'master' => 'Master',
'masters' => 'Daftar Master',
'name' => 'Nama Master',
'create' => 'Input Master Baru',
'created' => 'Input Master baru telah berhasil.',
'show' => 'Detail Master',
'edit' => 'Edit Master',
'update' => 'Update Master',
'updated' => 'Update data Master telah berhasil.',
'delete' => 'Hapus Master',
'deleted' => 'Hapus data Master telah berhasil.',
'undeleted' => 'Data Master gagal dihapus.',
'search' => 'Cari Master',
'found' => 'Master ditemukan',
'not_found' => 'Master tidak ditemukan',
'empty' => 'Belum ada Master',
'back_to_index' => 'Kembali ke daftar Master',
];
// Labels
'master' => 'Master',
'list' => 'Daftar Master',
'search' => 'Cari Master',
'not_found' => 'Master tidak ditemukan',
'empty' => 'Belum ada Master',
'back_to_index' => 'Kembali ke daftar Master',
// Actions
'create' => 'Input Master Baru',
'created' => 'Input Master baru telah berhasil.',
'show' => 'Detail Master',
'edit' => 'Edit Master',
'update' => 'Update Master',
'updated' => 'Update data Master telah berhasil.',
'delete' => 'Hapus Master',
'delete_confirm' => 'Anda yakin akan menghapus Master ini?',
'deleted' => 'Hapus data Master telah berhasil.',
'undeleted' => 'Data Master gagal dihapus.',
'undeleteable' => 'Data Master tidak dapat dihapus.',
// Attributes
'name' => 'Nama Master',
'description' => 'Deskripsi Master',
];

3
resources/lang/id/project.php

@ -36,4 +36,7 @@ return [
'not_found' => 'Project tidak ditemukan',
'empty' => 'Belum ada Project',
'back_to_index' => 'Kembali ke daftar Project',
// Attribute
'files' => 'List Dokumen',
];

31
resources/views/projects/files.blade.php

@ -19,20 +19,23 @@
<table class="table table-condensed table-striped">
<thead>
<th>{{ trans('app.table_no') }}</th>
<th>{{ trans('file.title') }}</th>
<th class="text-center">{{ trans('file.description') }}</th>
<th>{{ trans('file.file') }}</th>
<th class="text-center">{{ trans('file.download') }}</th>
<th class="text-center">{{ trans('app.action') }}</th>
</thead>
<tbody class="sort-files">
@forelse($files as $key => $file)
<tr id="{{ $file->id }}">
<td>{{ 1 + $key }}</td>
<td>{{ $file->title }}</td>
<td>{{ $file->description }}</td>
<td class="text-center"></td>
<td>
<strong class="">{{ $file->title }}</strong>
<div class="text-info small">{{ $file->description }}</div>
</td>
<td class="text-center"><a href="#"><i class="fa fa-file"></i></a></td>
<td class="text-center">edit</td>
</tr>
@empty
<tr><td colspan="4">{{ trans('file.empty') }}</td></tr>
<tr><td colspan="5">{{ trans('file.empty') }}</td></tr>
@endforelse
</tbody>
</table>
@ -40,15 +43,15 @@
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">Upload new File</h3></div>
<div class="panel-heading"><h3 class="panel-title">{{ trans('file.create') }}</h3></div>
<div class="panel-body">
{!! Form::open(['route' => ['files.upload', $project->id], 'id' => 'upload-files', 'files' => true]) !!}
{{ Form::hidden('fileable_type', get_class($project)) }}
{!! FormField::file('files', ['label' => 'Upload File', 'placeholder' => 'Pilih File']) !!}
{!! FormField::text('title') !!}
{!! FormField::textarea('description') !!}
{!! Form::submit(trans('app.upload_files'), ['class' => 'btn btn-info']) !!}
{!! Form::close() !!}
{!! Form::open(['route' => ['files.upload', $project->id], 'id' => 'upload-file', 'files' => true]) !!}
{{ Form::hidden('fileable_type', get_class($project)) }}
{!! FormField::file('file', ['label' => trans('file.select')]) !!}
{!! FormField::text('title') !!}
{!! FormField::textarea('description') !!}
{!! Form::submit(trans('file.upload'), ['class' => 'btn btn-info']) !!}
{!! Form::close() !!}
</div>
</div>
</div>

10
tests/Feature/Projects/UploadFilesTest.php

@ -13,14 +13,14 @@ class UploadFilesTest extends TestCase
$user = $this->adminUserSigningIn();
$project = factory(Project::class)->create(['owner_id' => $user->id]);
$this->visit(route('projects.files', $project->id));
$this->seeElement('form', ['id' => 'upload-files']);
$this->seeElement('input', ['id' => 'files']);
$this->seeElement('input', ['type' => 'submit', 'value' => trans('app.upload_files')]);
$this->seeElement('form', ['id' => 'upload-file']);
$this->seeElement('input', ['id' => 'file']);
$this->seeElement('input', ['type' => 'submit', 'value' => trans('file.upload')]);
$this->attach(storage_path('app/guitar-640.jpg'), 'files');
$this->attach(storage_path('app/guitar-640.jpg'), 'file');
$this->type('Judul file', 'title');
$this->type('Deskripsi file yang diuplod.', 'description');
$this->press(trans('app.upload_files'));
$this->press(trans('file.upload'));
$this->assertCount(1, $project->files);

Loading…
Cancel
Save