mirror of
https://github.com/cydrobolt/polr.git
synced 2024-11-09 11:42:28 +01:00
Add datetimepicker to aallow modification of date bounds for StatController
This commit is contained in:
parent
29d6c1c4c1
commit
c7bb9b00fa
@ -13,9 +13,22 @@ class StatsController extends Controller {
|
||||
const DAYS_TO_FETCH = 30;
|
||||
|
||||
public function displayStats(Request $request, $short_url) {
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'left_bound' => 'date',
|
||||
'right_bound' => 'date'
|
||||
]);
|
||||
|
||||
if ($validator->fails() && !session('error')) {
|
||||
// Do not flash error if there is already an error flashed
|
||||
return redirect()->back()->with('error', 'Invalid date bounds.');
|
||||
}
|
||||
|
||||
$user_left_bound = $request->input('left_bound');
|
||||
$user_right_bound = $request->input('right_bound');
|
||||
|
||||
// Carbon bounds for StatHelper
|
||||
$left_bound = Carbon::now()->subDays(self::DAYS_TO_FETCH);
|
||||
$right_bound = Carbon::now();
|
||||
$left_bound = $user_left_bound ?: Carbon::now()->subDays(self::DAYS_TO_FETCH);
|
||||
$right_bound = $user_right_bound ?: Carbon::now();
|
||||
|
||||
if (!$this->isLoggedIn()) {
|
||||
return redirect(route('login'))->with('error', 'Please login to view link stats.');
|
||||
@ -38,8 +51,17 @@ class StatsController extends Controller {
|
||||
return redirect(route('admin'))->with('error', 'You do not have permission to view stats for this link.');
|
||||
}
|
||||
|
||||
// Fetch base rows for StatHelper
|
||||
$stats = new StatsHelper($link_id, $left_bound, $right_bound);
|
||||
try {
|
||||
// Initialize StatHelper
|
||||
$stats = new StatsHelper($link_id, $left_bound, $right_bound);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
if (!session('error')) {
|
||||
// Do not flash error if there is already an error flashed
|
||||
return redirect()->back()->with('error', 'Invalid date bounds.
|
||||
The right date bound must be more recent than the left bound.');
|
||||
}
|
||||
}
|
||||
|
||||
$day_stats = $stats->getDayStats();
|
||||
$country_stats = $stats->getCountryStats();
|
||||
@ -51,6 +73,9 @@ class StatsController extends Controller {
|
||||
'country_stats' => $country_stats,
|
||||
'referer_stats' => $referer_stats,
|
||||
|
||||
'left_bound' => ($user_left_bound ?: ''),
|
||||
'right_bound' => ($user_right_bound ?: ''),
|
||||
|
||||
'no_div_padding' => true
|
||||
]);
|
||||
}
|
||||
|
5
public/css/bootstrap-datetimepicker.min.css
vendored
Normal file
5
public/css/bootstrap-datetimepicker.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
||||
.stats-header {
|
||||
.stats-header h3 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
@ -97,10 +97,16 @@ polr.controller('StatsCtrl', function($scope, $compile) {
|
||||
|
||||
};
|
||||
|
||||
$scope.initDatePickers = function () {
|
||||
$('#left-bound-picker').datetimepicker();
|
||||
$('#right-bound-picker').datetimepicker();
|
||||
}
|
||||
|
||||
$scope.init = function () {
|
||||
$scope.initDayChart();
|
||||
$scope.initRefererChart();
|
||||
$scope.initCountryChart();
|
||||
$scope.initDatePickers();
|
||||
};
|
||||
|
||||
$scope.init();
|
||||
|
2
public/js/bootstrap-datetimepicker.min.js
vendored
Normal file
2
public/js/bootstrap-datetimepicker.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
public/js/moment.min.js
vendored
Normal file
7
public/js/moment.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -4,23 +4,49 @@
|
||||
<link rel='stylesheet' href='/css/datatables.min.css'>
|
||||
<link rel='stylesheet' href='/css/stats.css'>
|
||||
<link rel='stylesheet' href='/css/jquery-jvectormap.css'>
|
||||
|
||||
<link rel='stylesheet' href='/css/bootstrap-datetimepicker.min.css'>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div ng-controller="StatsCtrl" class="ng-root">
|
||||
<div class="stats-header">
|
||||
<div class="stats-header bottom-padding">
|
||||
<h3>Stats</h3>
|
||||
<p>
|
||||
<b>Short Link: </b>
|
||||
<a target="_blank" href="{{ env('APP_PROTOCOL') }}/{{ env('APP_ADDRESS') }}/{{ $link->short_url }}">
|
||||
{{ env('APP_ADDRESS') }}/{{ $link->short_url }}
|
||||
</a>
|
||||
</p>
|
||||
<p>
|
||||
<b>Long Link: </b>
|
||||
<a target="_blank" href="{{ $link->long_url }}">{{ $link->long_url }}</a>
|
||||
</p>
|
||||
<div class="row">
|
||||
<div class="col-md-3 col-md-offset-3">
|
||||
<p>
|
||||
<b>Short Link: </b>
|
||||
<a target="_blank" href="{{ env('APP_PROTOCOL') }}/{{ env('APP_ADDRESS') }}/{{ $link->short_url }}">
|
||||
{{ env('APP_ADDRESS') }}/{{ $link->short_url }}
|
||||
</a>
|
||||
</p>
|
||||
<p>
|
||||
<b>Long Link: </b>
|
||||
<a target="_blank" href="{{ $link->long_url }}">{{ str_limit($link->long_url, 50) }}</a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<form action="" method="GET">
|
||||
<div class="form-group">
|
||||
<div class='input-group date' id='left-bound-picker'>
|
||||
<input type="text" class="form-control" name="left_bound" value="{{ e($left_bound) }}">
|
||||
<span class="input-group-addon">
|
||||
<span class="glyphicon glyphicon-calendar"></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class='input-group date' id='right-bound-picker'>
|
||||
<input type="text" class="form-control" name="right_bound" value="{{ e($right_bound) }}">
|
||||
<span class="input-group-addon">
|
||||
<span class="glyphicon glyphicon-calendar"></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Refresh" class="form-control">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row bottom-padding">
|
||||
@ -58,9 +84,6 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -81,6 +104,7 @@ var countryData = JSON.parse('{!! json_encode($country_stats) !!}');
|
||||
<script src='/js/datatables.min.js'></script>
|
||||
<script src='/js/jquery-jvectormap.min.js'></script>
|
||||
<script src='/js/jquery-jvectormap-world-mill.js'></script>
|
||||
<script src='/js/moment.min.js'></script>
|
||||
<script src='/js/bootstrap-datetimepicker.min.js'></script>
|
||||
<script src='/js/StatsCtrl.js'></script>
|
||||
|
||||
@endsection
|
||||
|
Loading…
Reference in New Issue
Block a user