-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] User search records page (#349)
- Loading branch information
Showing
10 changed files
with
287 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
const SearchRecord = use('App/Models/SearchRecord'); | ||
const moment = require('moment'); | ||
|
||
class SearchRecordController { | ||
async viewSearchRecords ({ view }) { | ||
const records = (await SearchRecord | ||
.query() | ||
.with('user') | ||
.fetch()).toJSON(); | ||
|
||
return view.render('adminPages.viewSearchRecords', { | ||
records, | ||
moment | ||
}); | ||
} | ||
} | ||
|
||
module.exports = SearchRecordController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */ | ||
const Model = use('Model'); | ||
|
||
class SearchRecord extends Model { | ||
user () { | ||
return this.belongsTo('App/Models/User'); | ||
} | ||
} | ||
|
||
module.exports = SearchRecord; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
/** @type {import('@adonisjs/lucid/src/Schema')} */ | ||
const Schema = use('Schema'); | ||
|
||
class SearchRecordSchema extends Schema { | ||
up () { | ||
this.create('search_records', (table) => { | ||
table.increments(); | ||
table.integer('user_id').unsigned().references('id').inTable('users'); | ||
table.string('type', 20).notNullable(); | ||
table.timestamps(); | ||
}); | ||
} | ||
|
||
down () { | ||
this.drop('search_records'); | ||
} | ||
} | ||
|
||
module.exports = SearchRecordSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.dataTables_filter { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
(function() { | ||
function setTotal() { | ||
$('#total').text(total); | ||
} | ||
|
||
function resetTotal() { | ||
total = 0; | ||
} | ||
|
||
function setStartDate(interval) { | ||
return moment().subtract(interval, 'days').format('YYYY-MM-DD'); | ||
} | ||
|
||
function drawTable() { | ||
resetTotal(); | ||
table.draw(); | ||
setTotal(); | ||
} | ||
|
||
var startDate = setStartDate(7); | ||
var typeFilter = ''; | ||
var table; | ||
var total = 0; | ||
var username = ''; | ||
|
||
$(document).ready(function() { | ||
$.fn.dataTable.ext.search.push( | ||
function( settings, data, dataIndex ) { | ||
var date = data[2]; | ||
var type = data[1]; | ||
var user = data[0]; | ||
|
||
var condition = date > startDate && | ||
(typeFilter === ''? true : (type === typeFilter)) && | ||
(user.toLowerCase().includes(username.toLowerCase())); | ||
|
||
if (condition) { | ||
total++; | ||
} | ||
|
||
return condition; | ||
} | ||
); | ||
|
||
table = $('#searchRecordsTable').DataTable({ | ||
"paging": true, | ||
"order": [[ 2, "desc" ]], | ||
"bLengthChange": false, | ||
"bInfo": false | ||
}); | ||
}); | ||
|
||
//= ======================================================================== | ||
// Search type filter | ||
//= ======================================================================== | ||
$('#dropdownType-All').on('click', function() { | ||
$('#dropdownType').text('All'); | ||
|
||
typeFilter = ''; | ||
drawTable(); | ||
}) | ||
|
||
$('#dropdownType-Fixed').on('click', function() { | ||
$('#dropdownType').text('Fixed'); | ||
|
||
typeFilter = 'fixed'; | ||
drawTable(); | ||
}) | ||
|
||
$('#dropdownType-Flexible').on('click', function() { | ||
$('#dropdownType').text('Flexible'); | ||
|
||
typeFilter = 'flexible'; | ||
drawTable(); | ||
}) | ||
|
||
//= ======================================================================== | ||
// Time filter | ||
//= ======================================================================== | ||
$('#dropdownTime-7d').on('click', function() { | ||
$('#dropdownTime').text('7 days'); | ||
|
||
startDate = setStartDate(7); | ||
drawTable(); | ||
}) | ||
|
||
$('#dropdownTime-30d').on('click', function() { | ||
$('#dropdownTime').text('30 days'); | ||
|
||
startDate = setStartDate(30); | ||
drawTable(); | ||
}) | ||
|
||
$('#dropdownTime-60d').on('click', function() { | ||
$('#dropdownTime').text('60 days'); | ||
|
||
startDate = setStartDate(60); | ||
drawTable(); | ||
}) | ||
|
||
$('#dropdownTime-360d').on('click', function() { | ||
$('#dropdownTime').text('360 days'); | ||
|
||
startDate = setStartDate(360); | ||
drawTable(); | ||
}) | ||
|
||
//= ======================================================================== | ||
// User filter | ||
//= ======================================================================== | ||
$('#user').keyup(function() { | ||
username = $('#user').val(); | ||
drawTable(); | ||
}) | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
@layout('layouts.mainLayout') | ||
|
||
@section('title') | ||
User search records {{-- french --}} | ||
@endsection | ||
|
||
@section('extracss') | ||
{{ style('css/manageBookings') }} | ||
{{ style('css/viewSearchRecords') }} | ||
{{-- Bootstrap link needed for the table formating --}} | ||
<link href='https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css' rel='stylesheet'> | ||
@endsection | ||
|
||
{{-- Manage bookings page content --}} | ||
@section('content') | ||
{{-- Loading page header --}} | ||
@component('components.pageHeader', title='User search records') | ||
@endcomponent | ||
<div class="row mb-4 mt-0"> | ||
<div class="col-12 text-left"> | ||
<div class="row mb-2 mt-0"> | ||
<div class="col-6 col-lg-2 text-left"> | ||
<strong>Type:</strong></br> | ||
<div class="dropdown d-inline"> | ||
<button class="btn btn-secondary dropdown-toggle text-center shadow" type="button" id="dropdownType" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="width:100%"> | ||
All | ||
</button> | ||
<div class="dropdown-menu text-center" id='menu1' aria-labelledby="dropdownType" style="width:100%"> | ||
<a class="dropdown-item" id='dropdownType-All' href="#" selected='selected'>All</a> | ||
<a class="dropdown-item" id='dropdownType-Fixed' href="#">Fixed</a> | ||
<a class="dropdown-item" id='dropdownType-Flexible' href="#">Flexible</a> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="col-6 col-lg-2 text-left"> | ||
<strong>Past:</strong></br> | ||
<div class="dropdown d-inline"> | ||
<button class="btn btn-secondary dropdown-toggle text-center shadow" type="button" id="dropdownTime" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="width:100%"> | ||
7 days | ||
</button> | ||
<div class="dropdown-menu text-center" id='menu2' aria-labelledby="dropdownTime" style="width:100%"> | ||
<a class="dropdown-item" id='dropdownTime-7d' href="#" value=7>7 days</a> | ||
<a class="dropdown-item" id='dropdownTime-30d' href="#">30 days</a> | ||
<a class="dropdown-item" id='dropdownTime-60d' href="#">60 days</a> | ||
<a class="dropdown-item" id='dropdownTime-360d' href="#">360 days</a> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="col-8 col-lg-2 text-left"> | ||
<strong>User:</strong></br> | ||
<input type="text" class="form-control" aria-label="Username" aria-describedby="basic-addon1" width="100%" id='user'> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
@component('components.generalCard', title='Search records') | ||
@slot('body') | ||
<strong>Total: </strong><strong id='total'>{{records.length}}</strong> | ||
<div class="table table-responsive"> | ||
<table id='searchRecordsTable' class='table table-hover' style='width:100%;'> | ||
<thead> | ||
<tr> | ||
<th scope='col' aria-label='Room column' class='text-center'>{{antl.formatMessage('manageBookings.tableName')}}</th> | ||
<th scope='col' aria-label='Room column' class='text-center'>Type</th> | ||
<th scope='col' aria-label='Meeting name column' class='text-center'>{{antl.formatMessage('manageBookings.tableDate')}}</th> | ||
<th scope='col' aria-label='Date column' class='text-center'>{{antl.formatMessage('manageBookings.tableTime')}}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@each(record in records) | ||
{{-- <tr aria-label='{{booking.subject}} row'> --}} | ||
<td class='text-center'><a href='{{ route('viewProfile', {id: record.user_id}) }}'>{{ truncate(record.user.firstname, 5, '.') }} {{ truncate(record.user.lastname, 5, '.') }}</a></td> | ||
<td class='text-center'>{{ record.type }}</td> | ||
<td class='text-center'>{{ moment(record.created_at).format("YYYY-MM-DD"); }}</td> | ||
<td class='text-center'>{{ moment(record.created_at).format("HH:mm"); }}</td> | ||
</tr> | ||
@endeach | ||
</tbody> | ||
</table> | ||
</div> | ||
@endslot | ||
@endcomponent | ||
|
||
@endsection | ||
|
||
{{-- Deals with the search functionality of the table above- searches all fields --}} | ||
@section('extrajs') | ||
<script src='https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js'></script> | ||
<script src='https://cdn.datatables.net/1.10.20/js/dataTables.bootstrap4.min.js'></script> | ||
<script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js'></script> | ||
<script src='js/searchRecords.js'></script> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters