チェックイン削除機能の実装

This commit is contained in:
shibafu 2017-11-03 17:48:58 +09:00
parent e9b19e7be1
commit abf8b05253
8 changed files with 193 additions and 144 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\User;
use Validator;
use App\Ejaculation;
use Illuminate\Http\Request;
@ -53,8 +54,11 @@ class EjaculationController extends Controller
// TODO: not implemented
}
public function destroy()
public function destroy($id)
{
// TODO: not implemented
$ejaculation = Ejaculation::findOrFail($id);
$user = User::findOrFail($ejaculation->user_id);
$ejaculation->delete();
return redirect()->route('profile', ['name' => $user->name])->with('status', '削除しました。');
}
}

View File

@ -22,6 +22,7 @@ class UserController extends Controller
// チェックインの取得
$query = Ejaculation::select(DB::raw(<<<'SQL'
id,
to_char(ejaculated_date, 'YYYY/MM/DD HH24:MI') AS ejaculated_date,
note,
is_private,

View File

@ -0,0 +1,18 @@
<div id="{{ $id }}" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ $title }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
{{ $slot }}
</div>
<div class="modal-footer">
{{ $footer }}
</div>
</div>
</div>
</div>

View File

@ -1,7 +1,7 @@
@extends('layouts.base')
@section('head')
@endsection
@push('head')
@endpush
@section('content')
<div class="container">

View File

@ -12,7 +12,7 @@
<link href="{{ asset('css/open-iconic-bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/tissue.css') }}" rel="stylesheet">
@yield('head')
@stack('head')
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
@ -66,6 +66,16 @@
@endguest
</div>
</nav>
@if (session('status'))
<div class="container">
<div id="status" class="alert alert-success alert-dismissible fade show" role="alert">
{{ session('status') }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
</div>
@endif
@yield('content')
<footer class="tis-footer mt-4">
<div class="container-fluid p-3 p-md-4">
@ -83,8 +93,14 @@
<script>
$(function(){
$('[data-toggle="tooltip"]').tooltip();
$('.alert').alert();
@if (session('status'))
setTimeout(function () {
$('#status').alert('close');
}, 5000);
@endif
});
</script>
@yield('script')
@stack('script')
</body>
</html>

View File

@ -0,0 +1,49 @@
@extends('layouts.base')
@section('content')
<div class="container">
<div class="row">
<div class="col-lg-4">
<div class="card mb-4">
<div class="card-body">
<img src="{{ $user->getProfileImageUrl(64) }}" class="rounded mb-1">
<h4 class="card-title"><a class="text-dark" href="{{ route('profile', ['name' => $user->name]) }}">{{ $user->display_name }}</a></h4>
<h6 class="card-subtitle mb-4"><a class="text-muted" href="{{ route('profile', ['name' => $user->name]) }}">&commat;{{ $user->name }}</a></h6>
<h6 class="font-weight-bold"><span class="oi oi-timer"></span> 現在のセッション</h6>
@if (isset($currentSession))
<p class="card-text mb-0">{{ $currentSession }}経過</p>
<p class="card-text">({{ $ejaculations[0]['ejaculated_date'] }} にリセット)</p>
@else
<p class="card-text mb-0">計測がまだ始まっていません</p>
<p class="card-text">(一度チェックインすると始まります)</p>
@endif
<h6 class="font-weight-bold"><span class="oi oi-graph"></span> 概況</h6>
<p class="card-text mb-0">平均記録: {{ Formatter::formatInterval($summary[0]->average) }}</p>
<p class="card-text mb-0">最長記録: {{ Formatter::formatInterval($summary[0]->longest) }}</p>
<p class="card-text mb-0">最短記録: {{ Formatter::formatInterval($summary[0]->shortest) }}</p>
<p class="card-text mb-0">合計時間: {{ Formatter::formatInterval($summary[0]->total_times) }}</p>
<p class="card-text">通算回数: {{ $summary[0]->total_checkins }}</p>
</div>
</div>
</div>
<div class="col-lg-8">
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link {{ Route::currentRouteName() === 'profile' ? 'active' : '' }}" href="{{ route('profile') }}">タイムライン</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#stats">グラフ</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#okazu">オカズ</a>
</li>
</ul>
<div class="tab-content">
@yield('tab-content')
</div>
</div>
</div>
</div>
@endsection

View File

@ -1,74 +1,18 @@
@extends('layouts.base')
@extends('user.base')
@section('head')
<style>
#ejaculations .title {
font-size: large;
}
#ejaculations .note {
margin: 8px 0;
}
.no-border {
border: none;
}
.pagination {
padding-bottom: 1rem;
}
</style>
@endsection
@section('content')
<div class="container">
<div class="row">
<div class="col-lg-4">
<div class="card mb-4">
<div class="card-body">
<img src="{{ $user->getProfileImageUrl(64) }}" class="rounded mb-1">
<h4 class="card-title"><a class="text-dark" href="{{ route('profile', ['name' => $user->name]) }}">{{ $user->display_name }}</a></h4>
<h6 class="card-subtitle mb-4"><a class="text-muted" href="{{ route('profile', ['name' => $user->name]) }}">&commat;{{ $user->name }}</a></h6>
<h6 class="font-weight-bold"><span class="oi oi-timer"></span> 現在のセッション</h6>
@if (isset($currentSession))
<p class="card-text mb-0">{{ $currentSession }}経過</p>
<p class="card-text">({{ $ejaculations[0]['ejaculated_date'] }} にリセット)</p>
@else
<p class="card-text mb-0">計測がまだ始まっていません</p>
<p class="card-text">(一度チェックインすると始まります)</p>
@endif
<h6 class="font-weight-bold"><span class="oi oi-graph"></span> 概況</h6>
<p class="card-text mb-0">平均記録: {{ Formatter::formatInterval($summary[0]->average) }}</p>
<p class="card-text mb-0">最長記録: {{ Formatter::formatInterval($summary[0]->longest) }}</p>
<p class="card-text mb-0">最短記録: {{ Formatter::formatInterval($summary[0]->shortest) }}</p>
<p class="card-text mb-0">合計時間: {{ Formatter::formatInterval($summary[0]->total_times) }}</p>
<p class="card-text">通算回数: {{ $summary[0]->total_checkins }}</p>
</div>
</div>
</div>
<div class="col-lg-8">
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#timeline" data-toggle="tab" role="tab">タイムライン</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#stats" data-toggle="tab" role="tab">グラフ</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#okazu" data-toggle="tab" role="tab">オカズ</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="timeline" role="tabpanel">
<ul class="list-group">
@section('tab-content')
<ul class="list-group">
@forelse ($ejaculations as $ejaculation)
<li class="list-group-item border-bottom-only pt-3 pb-3">
<!-- span -->
<div class="d-flex justify-content-between">
<h5>{{ $ejaculation['ejaculated_span'] ?? '精通' }} <small class="text-muted">{{ $ejaculation['before_date'] }}{{ !empty($ejaculation['before_date']) ? ' ' : '' }}{{ $ejaculation['ejaculated_date'] }}</small></h5>
@if ($user->id === Auth::user()->id)
<div>
<a class="text-secondary timeline-action-item" href="#" data-toggle="tooltip" data-placement="bottom" title="修正"><span class="oi oi-pencil"></span></a>
<a class="text-secondary timeline-action-item" href="#" data-toggle="tooltip" data-placement="bottom" title="削除"><span class="oi oi-trash"></span></a>
<a class="text-secondary timeline-action-item" href="#"><span class="oi oi-pencil" data-toggle="tooltip" data-placement="bottom" title="修正"></span></a>
<a class="text-secondary timeline-action-item" href="#" data-toggle="modal" data-target="#deleteCheckinModal" data-id="{{ $ejaculation['id'] }}" data-date="{{ $ejaculation['ejaculated_date'] }}"><span class="oi oi-trash" data-toggle="tooltip" data-placement="bottom" title="削除"></span></a>
</div>
@endif
</div>
<!-- tags -->
@if ($ejaculation['is_private']) {{-- TODO: タグを付けたら、タグが空じゃないかも判定に加える --}}
@ -106,8 +50,8 @@
<p>まだチェックインしていません。</p>
</li>
@endforelse
</ul>
<ul class="pagination mt-4 justify-content-center">
</ul>
<ul class="pagination mt-4 justify-content-center">
<li class="page-item {{ $ejaculations->currentPage() === 1 ? 'disabled' : '' }}">
<a class="page-link" href="{{ $ejaculations->previousPageUrl() }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
@ -123,20 +67,36 @@
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</div>
<div class="tab-pane" id="stats" role="tabpanel">
<div class="alert alert-light" role="alert">
ここには何のグラフを置くか決めていません。
</div>
</div>
<div class="tab-pane" id="okazu" role="tabpanel">
<div class="alert alert-light" role="alert">
ここには過去のチェックインに添付したオカズがリストアップされます。
</div>
</div>
</div>
</div>
</div>
</div>
</ul>
@component('components.modal', ['id' => 'deleteCheckinModal'])
@slot('title')
削除確認
@endslot
<span class="date-label"></span> のチェックインを削除してもよろしいですか?
<form action="{{ route('checkin.destroy', ['id' => '@']) }}" method="post">
{{ csrf_field() }}
{{ method_field('DELETE') }}
</form>
@slot('footer')
<button type="button" class="btn btn-secondary" data-dismiss="modal">キャンセル</button>
<button type="button" class="btn btn-danger">削除</button>
@endslot
@endcomponent
@endsection
@push('script')
<script>
$('#deleteCheckinModal').on('show.bs.modal', function (event) {
var target = $(event.relatedTarget);
var modal = $(this);
modal.find('.modal-body .date-label').text(target.data('date'));
modal.data('id', target.data('id'));
}).find('.btn-danger').on('click', function (event) {
var modal = $('#deleteCheckinModal');
var form = modal.find('form');
form.attr('action', form.attr('action').replace('@', modal.data('id')));
form.submit();
});
</script>
@endpush

View File

@ -23,4 +23,5 @@ Route::get('/user/{name?}', 'UserController@profile')->name('profile');
Route::middleware('auth')->group(function () {
Route::get('/checkin', 'EjaculationController@create')->name('checkin');
Route::post('/checkin', 'EjaculationController@store')->name('checkin');
Route::delete('/checkin/{id}', 'EjaculationController@destroy')->name('checkin.destroy');
});