Skip to content

Commit

Permalink
Merge pull request #12 from kumasakatakashi/refactor-view-partial
Browse files Browse the repository at this point in the history
Refactor view partial
  • Loading branch information
kumasakatakashi committed Jul 3, 2019
2 parents 87609f9 + 8682c41 commit 49b919b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 75 deletions.
5 changes: 2 additions & 3 deletions app/Http/Controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ public function detect(DetectImageRequest $request)
// OCR実行
$text = $this->ocrService->detect($filepath);

$message = new \Illuminate\Support\MessageBag();
if (empty($text)) {
$message->add('filepath', '画像内に認識可能な文字がありません');
session()->flash('warning', '画像内に認識可能な文字がありません');
}

return view('image.index')->with([
'filepath' => $filepath,
'result_text' => $text
])->withErrors($message);
]);
}
}
111 changes: 41 additions & 70 deletions resources/views/image/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,77 +1,48 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">画像文字認識</div>
</div>
<div class="card-body">
<!-- エラーメッセージ -->
@if ($errors->any())
<div class="alert alert-danger alert-dismissible" id="alertfadeout">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<ul style="margin-bottom:0px">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<!-- アップロードフォーム -->
{!! Form::open(['url' => '/upload', 'method' => 'post', 'files' => true]) !!}
<div class="form-group">
{!! Form::label('lefile', '画像ファイル:') !!}
{!! Form::file('file', ['id' => 'lefile', 'style' => 'display:none']) !!}
<div class="input-group">
<input type="text" id="photoCover" class="form-control" placeholder="select file..." readonly="readonly">
<span class="input-group-btn">
<button type="button" class="btn btn-primary" onclick="$('input[id=lefile]').click();">Browse</button>
</span>
</div>
</div>
{{ csrf_field() }}
<div class="form-group">
{!! Form::submit('アップロード', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
<!-- アップロード画像表示 -->
@isset($filepath)
<hr>
<a href="{{ $filepath }}" data-lightbox="detectimage">
<img src="{{ $filepath }}" width="200" height="150" />
</a>
<!-- OCR認識フォーム -->
<hr>
{!! Form::open(['url' => '/detect', 'method' => 'post', 'files' => false]) !!}
<div class="form-group">
{!! Form::hidden('filepath', $filepath) !!}
{!! Form::submit('文字認識', ['class' => 'btn btn-danger']) !!}
</div>
{!! Form::close() !!}
@endisset
<!-- 認識結果表示 -->
@isset($result_text)
<div class="form-group">
{!! Form::textarea('result_text', $result_text, ['class' => 'form-control', 'rows' => '20']) !!}
<div class="card">
<div class="card-header">画像文字認識</div>
</div>
<div class="card-body">
<!-- エラーメッセージ表示 -->
@include('layouts.error')
<!-- アップロードフォーム -->
{!! Form::open(['url' => '/upload', 'method' => 'post', 'files' => true]) !!}
<div class="form-group">
{!! Form::label('lefile', '画像ファイル:') !!}
{!! Form::file('file', ['id' => 'lefile', 'style' => 'display:none']) !!}
<div class="input-group">
<input type="text" id="photoCover" class="form-control" placeholder="select file..." readonly="readonly">
<span class="input-group-btn">
<button type="button" class="btn btn-primary" onclick="$('input[id=lefile]').click();">Browse</button>
</span>
</div>
@endisset
</div>
{{ csrf_field() }}
<div class="form-group">
{!! Form::submit('アップロード', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
<!-- アップロード画像表示 -->
@isset($filepath)
<hr>
<a href="{{ $filepath }}" data-lightbox="detectimage">
<img src="{{ $filepath }}" width="200" height="150" />
</a>
<!-- OCR認識フォーム -->
<hr>
{!! Form::open(['url' => '/detect', 'method' => 'post', 'files' => false]) !!}
<div class="form-group">
{!! Form::hidden('filepath', $filepath) !!}
{!! Form::submit('文字認識', ['class' => 'btn btn-danger']) !!}
</div>
{!! Form::close() !!}
@endisset
<!-- 認識結果表示 -->
@isset($result_text)
<div class="form-group">
{!! Form::textarea('result_text', $result_text, ['class' => 'form-control', 'rows' => '20']) !!}
</div>
@endisset
</div>
</div>
<script>
$(function(){
$('input[id=lefile]').change(function(){
$('input[id=photoCover]').val($(this).val().replace("C:\\fakepath\\", ""));
});
});
$(document).ready(function(){
$(window).on('load', function(){
window.setTimeout("$('#alertfadeout').fadeOut()", 3000);
});
});
</script>
@endsection
22 changes: 20 additions & 2 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
<!-- Styles -->
<link href="{{ asset('css/lightbox.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/app.css') }}" rel="stylesheet">

<script>
$(document).ready(function(){
$(window).on('load', function(){
window.setTimeout("$('#alertfadeout').fadeOut()", 3000);
});
});
$(function(){
$('input[id=lefile]').change(function(){
$('input[id=photoCover]').val($(this).val().replace("C:\\fakepath\\", ""));
});
});
</script>
</head>
<body>
<div id="app">
Expand Down Expand Up @@ -81,9 +94,14 @@
-->
</div>
</nav>

<main class="py-4">
@yield('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
@yield('content')
</div>
</div>
</div>
</main>
</div>
</body>
Expand Down
24 changes: 24 additions & 0 deletions resources/views/layouts/error.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- エラーメッセージ -->
@if ($errors->any())
<div class="alert alert-danger alert-dismissible" id="alertfadeout">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<ul style="margin-bottom:0px">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<!-- ワーニングメッセージ -->
@if (session('warning'))
<div class="alert alert-danger alert-dismissible" id="alertfadeout">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<ul style="margin-bottom:0px">
<li>{{ session('warning') }}</li>
</ul>
</div>
@endif

0 comments on commit 49b919b

Please sign in to comment.