Commit f730c7a5 by Aan Choesni Herlingga

master file and bug fix storage repository

parent 1b26c899
<?php
namespace App\Http\Controllers\Webprofile\Backend;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Webprofile\CategoriesFile;
use App\Repositories\Webprofile\FileRepository;
class FileController extends Controller
{
private $repo;
public function __construct(FileRepository $repo)
{
$this->repo = $repo;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
if ($request->ajax()) {
$data = $this->repo->get(null, null, ['created_at', 'desc']);
return $this->repo->datatable($data);
}
return view('webprofile.backend.file.index')->withTitle(trans('feature.file'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$categoriesFile = CategoriesFile::where('is_active', 1)->orderBy('name', 'asc')->pluck('name', 'id');
$data = [
'categoriesFile' => $categoriesFile,
];
return view('webprofile.backend.file.create', $data)->withTitle(trans('feature.create_file'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->repo->store($request, 'file');
return redirect()->route('file.index');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$data = $this->repo->findId($id);
$categoriesFile = CategoriesFile::where('is_active', 1)->orderBy('name', 'asc')->pluck('name', 'id');
$data = [
'data' => $data,
'categoriesFile' => $categoriesFile,
];
return view('webprofile.backend.file.edit', $data)->withTitle(trans('feature.edit_file'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$gallery = $this->repo->findId($id);
$edit = $this->repo->update($request, $gallery, 'file');
return redirect()->route('file.index');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$data = $this->repo->findId($id);
$this->repo->destroy($data, 'file');
return response()->json(['done']);
}
}
......@@ -114,11 +114,11 @@ abstract class StorageRepository
{
$setting = webprofilesetting();
if ($model->images) {
if ($model->$tipe) {
if ($setting['external_storage'] == 1) {
Storage::disk('storage')->delete($setting['directory'] . '/' . $tipe . '/' . $model->images);
Storage::disk('storage')->delete($setting['directory'] . '/' . $tipe . '/' . $model->$tipe);
} else {
Storage::disk('local')->delete('public/' . $tipe . '/' . $model->images);
Storage::disk('local')->delete('public/' . $tipe . '/' . $model->$tipe);
}
}
......
......@@ -3,10 +3,10 @@
namespace App\Repositories\Webprofile;
use App\Models\Webprofile\File;
use App\Repositories\Repository;
use App\Repositories\StorageRepository;
use DataTables;
class FileRepository extends Repository
class FileRepository extends StorageRepository
{
protected $model;
......@@ -32,17 +32,39 @@ class FileRepository extends Repository
public function datatable($data)
{
$setting = webprofilesetting();
return DataTables::of($data)
->addIndexColumn()
->addColumn('action', function ($row) {
$btn = '<a href="javascript:void(0)" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="Edit" class="edit btn btn-warning btn-round btn-sm edit">Edit</a>';
$btn = '<a href="' . url('/webprofile/file/' . $row->id . '/edit') . '" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="' . trans('label.edit') . '" class="edit btn btn-warning btn-round btn-sm edit">' . trans('label.edit') . '</a>';
$btn = $btn . ' <a href="javascript:void(0)" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="Delete" class="btn btn-danger btn-round btn-sm delete">Delete</a>';
$btn = $btn . ' <a href="javascript:void(0)" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="' . trans('label.delete') . '" class="btn btn-danger btn-round btn-sm delete">' . trans('label.delete') . '</a>';
$btn = $btn . '<br>';
return $btn;
})
->addColumn('category', function ($row) {
return ucfirst($row->rCategoryFile->name);
})
->addColumn('file', function ($row) use ($setting) {
if ($setting['external_storage'] == 1) {
$str = '<a href="' . $setting['url_static'] . '/' . $setting['directory'] . '/file/' . $row->file . '" style="font-size: 12pt;">'. ucfirst($row->title) .'</a>';
$str .= '<label id="furl_' . $row->id . '" hidden>' . $setting['url_static'] . '/' . $setting['directory'] . '/file/' . $row->file . '</label>';
} else {
$str = '<a href="' . url('/storage/file/' . $row->file) . '" style="font-size: 12pt;">'. ucfirst($row->title) .'</a>';
$str .= '<label id="furl_' . $row->id . '" hidden>' . url('/storage/file/' . $row->file) . '</label>';
}
$str .= '<br>';
$str .= '<button onclick="copyToClipboard(\'#furl_' . $row->id . '\')" class="btn btn-info btn-xs">Copy URL</button>';
return $str;
})
->addColumn('downloaded', function ($row) {
return $row->downloaded;
})
->addColumn('status', function ($row) {
if ($row->is_active == true) {
$str = '<div style="color: green;"><i class="fa fa-check"></i></div>';
......@@ -51,7 +73,7 @@ class FileRepository extends Repository
}
return $str;
})
->rawColumns(['action', 'status'])
->rawColumns(['action', 'status', 'category', 'file', 'downloaded'])
->make(true);
}
}
$(function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var table = $('.data-table').DataTable({
processing: true,
serverSide: true,
responsive: true,
ajax: url,
columns: [
{ data: 'DT_RowIndex', name: 'DT_RowIndex' },
{ data: 'category', name: 'category' },
{ data: 'file', name: 'file' },
{ data: 'status', name: 'status' },
{ data: 'downloaded', name: 'downloaded' },
{ data: 'action', name: 'action', orderable: false, searchable: false },
],
columnDefs: [
{ className: 'text-center', targets: [0, 3, 4, 5]},
{ className: 'text-left', targets: [1, 2]},
],
});
$("body").on("click", ".delete", function (e) {
e.preventDefault();
var id = $(this).data('id');
swal({
title: "Apakah Anda Yakin?",
text: "Anda akan menghapus data ini!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
if (isConfirm) {
swal.close();
setTimeout(function () {
$.ajax({
dataType: 'json',
type: 'DELETE',
url: url + '/' + id,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
}).done(function (data) {
table.draw();
swal({
title: "Data berhasil dihapus!",
type: "success",
timer: "3000"
});
});
}, 1000); // 1 second delay
}
else {
swal("Dibatalkan", "Data batal dihapus", "error");
}
}
);
});
});
$(function () {
//iCheck for checkbox and radio inputs
$('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
checkboxClass: 'icheckbox_minimal-blue',
radioClass: 'iradio_minimal-blue'
});
});
function printErrorMsg(msg) {
$(".print-error-msg").find("ul").html('');
$(".print-error-msg").css('display', 'block');
$.each(msg, function (key, value) {
$(".print-error-msg").find("ul").append('<li>' + value + '</li>');
});
}
function ValidateFile(oInput) {
var _validFileExtensions = [".jpg", ".jpeg", ".png", ".doc", ".docx", ".pdf", ".xls", ".xlsx", ".ppt", ".pptx", ".mp3", ".mp4", ".mkv", "mpeg"];
if (oInput.type == "file") {
var sFileName = oInput.value;
if (sFileName.length > 0) {
var blnValid = false;
for (var j = 0; j < _validFileExtensions.length; j++) {
var sCurExtension = _validFileExtensions[j];
if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
blnValid = true;
pdf = true;
break;
}
}
if (!blnValid) {
swal("Oops...", "Ekstensi File tidak diperbolehkan", "error");
oInput.value = "";
pdf = false;
return false;
}
}
}
return true;
}
function checkFileSizeFile(inputFile) {
var max = 3145728; // 3MB
if (inputFile.files && inputFile.files[0].size > max) {
swal("Oops...", "File terlalu besar (lebih dari 3MB) ! Mohon kompres/perkecil ukuran file", "error");
inputFile.value = null; // Clear the field.
}
}
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).html()).select();
document.execCommand("copy");
$temp.remove();
swal("Copied!", "", "success");
}
\ No newline at end of file
@extends('webprofile.backend.layouts.master')
@section('title')
{{ $title }}
@stop
@section('breadcrumbs')
<li><a href="{{ url('dashboard') }}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.create_file')</li>
@stop
@section('content')
{!! Form::open(array('url' => route('file.store'), 'method' => 'POST', 'id' => 'file', 'class' => 'form-horizontal', 'files' => true)) !!}
{!! csrf_field() !!}
<!-- page start-->
<div class="row">
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>@lang('label.create')</strong> @lang('feature.file')</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group @if ($errors->has('categories_file')) has-error @endif" style="margin-top: 5px;">
<label class="col-md-2 control-label">@lang('feature.categoryfile')</label>
<div class="col-md-10">
{{ Form::select('categories_file', $categoriesFile, old('categories_file'), ['class' => 'form-control select2', 'style' => 'width: 100%; font-size: 16px; height: 40px;', 'id' => 'categories_file', 'placeholder' => trans('feature.categoryfile'), 'required']) }}
@if ($errors->has('categories_file'))
<label id="login-error" class="error" for="login">{{$errors->first('categories_file')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('title')) has-error @endif">
<label class="col-md-2 control-label">@lang('label.name') @lang('feature.file')</label>
<div class="col-md-10">
{{ Form::text('title', old('title'), ['class' => 'form-control']) }}
@if ($errors->has('title'))
<label id="login-error" class="error" for="login">{{$errors->first('title')}}</label>
@endif
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">File</label>
<div class="col-md-10">
{{ Form::file('file', array('class'=>'fileinput btn-danger', 'id'=>'uploadImage', 'data-filename-placement'=>'inside', 'title'=>'Upload', 'onchange'=>'ValidateFile(this); checkFileSizeFile(this);')) }}
<label for="information" class="error">Ekstensi File yang diperbolehkan : ".jpg", ".jpeg", ".png", ".doc", ".docx", ".pdf", ".xls", ".xlsx", ".mp3", ".mp4", ".mkv", "mpeg"</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>@lang('label.publish')</strong></h3>
<ul class="panel-controls">
<li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
</ul>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="col-md-2 control-label">@lang('label.status')</label>
<div class="col-md-6">
<center>
<label class="switch">
{{ Form::checkbox('is_active', 1, true) }}
<span></span>
</label>
</center>
</div>
</div>
</div>
</div>
</div>
<div class="panel-footer">
</div>
</div>
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-footer">
<button class="btn btn-info pull-right">@lang('label.save')</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
<!-- page end-->
@stop
@section('script')
<script src="{!!asset('backend/js/plugins/bootstrap/bootstrap-datepicker.js') !!}"></script>
<script src="{!!asset('backend/js/plugins/bootstrap/bootstrap-timepicker.min.js') !!}"></script>
<script src="{!!asset('backend/js/plugins/bootstrap/bootstrap-file-input.js') !!}"></script>
<script src="{!!asset('backend/js/plugins/summernote/summernote.js') !!}"></script>
<script type="text/javascript">
function PreviewImage() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
};
</script>
@stop
@extends('webprofile.backend.layouts.master')
@section('title')
{{ $title }}
@stop
@section('breadcrumbs')
<li><a href="{{ url('dashboard') }}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.edit_file')</li>
@stop
@section('content')
<!-- page start-->
<div class="row">
{!! Form::model($data, ['route' => ['file.update', $data->id], 'method'=>'patch', 'class' => 'form-horizontal', 'files' => true]) !!}
{!! csrf_field() !!}
<!-- page start-->
<div class="row">
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>@lang('label.edit')</strong> @lang('feature.file')</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group @if ($errors->has('categories_file')) has-error @endif" style="margin-top: 5px;">
<label class="col-md-2 control-label">@lang('feature.categoryfile')</label>
<div class="col-md-10">
{{ Form::select('categories_file', $categoriesFile, old('categories_file'), ['class' => 'form-control select2', 'style' => 'width: 100%; font-size: 16px; height: 40px;', 'id' => 'categories_file', 'placeholder' => trans('feature.categoryfile'), 'required']) }}
@if ($errors->has('categories_file'))
<label id="login-error" class="error" for="login">{{$errors->first('categories_file')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('title')) has-error @endif">
<label class="col-md-2 control-label">@lang('label.name') @lang('feature.file')</label>
<div class="col-md-10">
{{ Form::text('title', old('title'), ['class' => 'form-control']) }}
@if ($errors->has('title'))
<label id="login-error" class="error" for="login">{{$errors->first('title')}}</label>
@endif
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">File</label>
<div class="col-md-10">
{{ Form::file('file', array('class'=>'fileinput btn-danger', 'id'=>'uploadImage', 'data-filename-placement'=>'inside', 'title'=>'Upload', 'onchange'=>'ValidateFile(this); checkFileSizeFile(this);')) }}
<label for="information" class="error">Ekstensi File yang diperbolehkan : ".jpg", ".jpeg", ".png", ".doc", ".docx", ".pdf", ".xls", ".xlsx", ".mp3", ".mp4", ".mkv", "mpeg"</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>@lang('label.publish')</strong></h3>
<ul class="panel-controls">
<li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
</ul>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="col-md-2 control-label">@lang('label.status')</label>
<div class="col-md-6">
<center><label class="switch">
{{ Form::checkbox('is_active', $data->is_active, $data->is_active) }}
<span></span>
</label></center>
</div>
</div>
</div>
</div>
</div>
<div class="panel-footer">
</div>
</div>
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-footer">
<button class="btn btn-info pull-right">@lang('label.save')</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
</div>
<!-- page end-->
@stop
@section('script')
<script src="https://statik.unesa.ac.id/spn_konten_statik/plugins/select2/select2.full.min.js"></script>
{!! Html::script('https://statik.unesa.ac.id/profileunesa_konten_statik/admin/js/plugins/bootstrap/bootstrap-datepicker.js') !!}
{!! Html::script('https://statik.unesa.ac.id/profileunesa_konten_statik/admin/js/plugins/bootstrap/bootstrap-timepicker.min.js') !!}
{!! Html::script('https://statik.unesa.ac.id/profileunesa_konten_statik/admin/js/plugins/bootstrap/bootstrap-file-input.js') !!}
{!! Html::script('https://statik.unesa.ac.id/profileunesa_konten_statik/admin/js/plugins/summernote/summernote.js') !!}
<script type="text/javascript">
function PreviewImage() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
};
$('#categories').select2();
</script>
@stop
@extends('webprofile.backend.layouts.master')
@section('assets')
<link rel="stylesheet" href="{!! asset('backend/js/datatables.net-bs/css/dataTables.bootstrap.min.css') !!}">
<meta name="csrf-token" content="{{ csrf_token() }}">
@endsection
@section('title')
{{ $title }}
@stop
@section('breadcrumbs')
<li><a href="{{ url('dashboard') }}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.file')</li>
@stop
@section('content')
<!-- page start-->
<div class="row">
<div class="col-lg-12">
<!-- START DEFAULT DATATABLE -->
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{!! $title !!}</h3>
<a class="btn btn-info" href="{{ url('webprofile/file/create') }}" style="margin: 0cm 0px 0cm 10px;">@lang('label.create')</a>
<ul class="panel-controls">
<li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
</ul>
</div>
<div class="panel-body">
<table class="table table-hover data-table" width="100%">
<thead>
<tr>
<th width="7%" style="text-align: center;">@lang('label.number')</th>
<th width="15%" style="text-align: center;">@lang('feature.category')</th>
<th style="text-align: center;">@lang('feature.file')</th>
<th width="10%" style="text-align: center;">@lang('label.status')</th>
<th width="10%" style="text-align: center;">@lang('label.download')</th>
<th align="center" width="12%" style="text-align: center;">@lang('label.action')</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- END DEFAULT DATATABLE -->
</div>
</div>
<!-- page end-->
@stop
@section('script')
<script src="{!!asset('backend/js/datatables.net/js/jquery.dataTables.min.js') !!}"></script>
<script src="{!!asset('backend/js/datatables.net-bs/js/dataTables.bootstrap.min.js') !!}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/dataTables.buttons.min.js') }}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/buttons.bootstrap4.min.js') }}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/buttons.colVis.min.js') }}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/buttons.html5.min.js') }}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/buttons.print.min.js') }}"></script>
<script>
var url = "{{ route('file.index') }}";
</script>
{{ Html::script('js/master/file.js') }}
@stop
......@@ -84,7 +84,7 @@
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-footer">
<button class="btn btn-info pull-right">Simpan</button>
<button class="btn btn-info pull-right">@lang('label.save')</button>
</div>
</div>
</div>
......
......@@ -10,6 +10,7 @@ Route::group(['middleware' => 'auth'], function () {
Route::resource('sliders', 'SliderController');
Route::resource('gallery', 'GalleryController');
Route::resource('categoriesfile', 'CategoriesFileController');
Route::resource('file', 'FileController');
});
// });
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment