Szkolenia ciag dalszy

This commit is contained in:
czup 2019-12-25 22:35:20 +01:00
parent c2dd5a8929
commit f09c4ba2d4
12 changed files with 472 additions and 63 deletions

View File

@ -0,0 +1,104 @@
<?php
namespace App\Http\Controllers;
use App\trainings;
use App\trainingsFirefighters;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\View;
class trainingsController extends Controller
{
public function create(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$trainings = DB::table('trainings')->where("fireStationID", '=', auth()->user()->fireStationID)
->whereNull('deleted_at')->get();
foreach($trainings as $training) {
$id = $training->id;
$fireFighters[$id] = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID)
->leftJoin('trainingsFirefighters', function ($join) use ($id) {
$join->on('users.id', '=', 'trainingsFirefighters.firefighterID');
$join->where('trainingsFirefighters.trainingID', '=', $id);
})
->select('trainingsFirefighters.*', 'users.name', 'users.surname', 'users.id as userID')
->get();
}
return View::make("trainings")->with(compact( "trainings", "fireFighters"));
} else{
return view('trainings');
}
}
public function addForm(){
}
public function addTrainingsFireFighters($id){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )
->leftJoin('trainingsFirefighters', function ($join) use($id){
$join->on('users.id', '=', 'trainingsFirefighters.firefighterID');
$join->where('trainingsFirefighters.trainingID', '=', $id);
})
->select('trainingsFirefighters.*', 'users.name', 'users.surname', 'users.id as userID')
->get();
$training = DB::table('trainings')->where("id", '=', $id)
->whereNull('deleted_at')->first();
return View::make("trainingsAddFireFighters")->with(compact( "training", "fireFighters"));
} else{
return view('trainings');
}
}
public function ajaxRequest(){
$this->validate(request(), [
'firefighterID' => 'required',
'trainingID' => 'required',
'dateOfComplete' => 'required',
'dateOfExpiry' => 'required',
],
[
'required' => ':attribute jest wymagany(a).',
]);
$request = request();
$trainingFirefighter = trainingsFirefighters::where([
['firefighterID', '=', $request->firefighterID],
['trainingID', '=', $request-> trainingID]
])->first();
if($trainingFirefighter == null){
// CREATE
$trainings = trainingsFirefighters::create([
'firefighterID' => $request-> firefighterID,
'trainingID' => $request-> trainingID,
'dateOfComplete' => $request-> dateOfComplete,
'dateOfExpiry' => $request-> dateOfExpiry,
'lifetime' => 1,
]);
}else{
// UPDATE
$trainingFirefighter->update([
'dateOfComplete' => $request-> dateOfComplete,
'dateOfExpiry' => $request-> dateOfExpiry,
]);
}
// $input = $request->all();
//
// return response()->json(['success'=>'Got Simple Ajax Request.']);
}
public function update(){
}
}

12
app/trainings.php Normal file
View File

@ -0,0 +1,12 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class trainings extends Model
{
protected $primaryKey = 'id';
protected $fillable = ['fireStationID', 'trainingName'];
}

View File

@ -0,0 +1,13 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class trainingsFirefighters extends Model
{
protected $primaryKey = 'id';
protected $table = 'trainingsFirefighters';
protected $fillable = ['trainingID', 'firefighterID', 'dateOfComplete', 'dateOfExpiry', 'lifetime'];
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTrainingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('trainings', function (Blueprint $table) {
$table->increments('id');
$table->integer('fireStationID');
$table->string('trainingName');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('trainings');
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTrainingsFireFightersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('trainingsFirefighters', function (Blueprint $table) {
$table->increments('id');
$table->integer('firefighterID');
$table->integer('trainingID');
$table->date('dateOfComplete');
$table->date('dateOfExpiry');
$table->boolean('lifetime');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('trainingsFirefighters');
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddSoftdeleteColumnToTrainingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('trainings', function (Blueprint $table) {
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('trainings', function (Blueprint $table) {
//
});
}
}

View File

@ -4,6 +4,7 @@
@parent
<ul>
<a href="/sprzet"><li>Sprzęt<img src="img/left_menu_icon/more.png"></li></a>
<a href="/szkolenia"><li>Badania/Szkolenia<img src="img/left_menu_icon/more.png"></li></a>
{{-- <li>Edytuj<img src="img/left_menu_icon/edit.png"></li> --}}
{{-- <li>Usuń<img src="img/left_menu_icon/delete.png"></li> --}}
</ul>

View File

@ -5,11 +5,14 @@
<title>E-OSP</title>
<link rel="stylesheet" href="{{ asset('css/theme.css') }}">
<link rel="stylesheet" href="{{asset('css/app.css')}}">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
{{-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">--}}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
</head>
<body>
@if( auth()->check() )

View File

@ -93,7 +93,6 @@
<script>
function showMoreInformation(operationID){
if( $('#more'+operationID).val() == "Więcej"){
$('#more'+operationID).val("Ukryj");
$("#moreInformation"+operationID).css('visibility', 'visible');

View File

@ -0,0 +1,98 @@
@extends('layout.app')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
@section('left-menu')
@parent
<ul>
<a href="sprzet/add"><li>Dodaj<img src="../img/left_menu_icon/add.png"></li></a>
<li>Edytuj<img src="../img/left_menu_icon/edit.png"></li>
<li>Usuń<img src="../img/left_menu_icon/delete.png"></li>
</ul>
@stop
@section('center-area')
@parent
@if( auth()->check())
@if( auth()->user()->fireStationID == NULL)
Jednostka nie istnieje
@else
<p align='center'>
<form method="POST" action="/szkolenia">
{{ csrf_field() }}
<div class="form-group">
<label for="name">Nazwa Szkolenia/Badana:</label>
<input type="text" class="form-control" id="name" name="name" value="{{ old('name') }} ">
</div>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Dodaj</button>
</div>
@include('inc.formerrors')
</form>
<table class='firefighterViewTable'>
<tr class='table-header'>
<td>Nazwa Szkolenia</td>
<td>Ilość z ukończonym</td>
<td>Akcje</td>
@foreach($trainings as $training)
<tr>
<form action="{{ route('equipment.destroy', $training->id)}}" method="post">
<td id="name{{ $training->id }}">{{ $training->trainingName }}</td>
<td id="amount{{ $training->id }}">5</td>
<td><input type="button" onclick="showMoreInformation('{{$training->id}}')" id="more{{$training->id}}" value="Więcej">
<a href="{{ URL::asset('sprzet/edit/'.$training->id) }}"><input type="button" onclick="" value="Edytuj"> </a>
<a href="{{ URL::asset('szkolenia/addTrainingsFireFighters/'.$training->id) }}"><input type="button" onclick="" value="Dodaj zbadanych"></a>
{{ csrf_field() }}
@method('DELETE')
<button class="btn btn-danger" type="submit">Usuń</button>
</td>
</form>
</tr>
<tr id="moreInformation{{$training->id}}" style="visibility:collapse;" bgcolor="#C0C0C0">
<td colspan="3">
<table>
<thead>
<td>Imię i Nazwisko</td>
<td>Ważne od:</td>
<td>Ważne do:</td>
</thead>
<tbody>
@foreach($fireFighters[$training->id] as $fireFighter)
@if($fireFighter->dateOfComplete != null and $fireFighter->dateOfExpiry != null)
<tr id="{{$fireFighter->userID}}">
<td>{{$fireFighter->name}} {{$fireFighter->surname}}</td>
<td>{{$fireFighter->dateOfComplete}}</td>
<td>{{$fireFighter->dateOfExpiry}}</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</td>
</tr>
@endforeach
</table>
</p>
@endif
@else
Brak autoryzacji
@endif
@stop
<script>
function showMoreInformation(operationID){
if( $('#more'+operationID).val() == "Więcej"){
$('#more'+operationID).val("Ukryj");
$("#moreInformation"+operationID).css('visibility', 'visible');
} else{
$('#more'+operationID).val("Więcej");
$("#moreInformation"+operationID).css('visibility', 'collapse');
}
}
</script>

View File

@ -1,7 +1,11 @@
@extends('layout.app')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<title>Add Edit Delete Table Row Example using JQuery - ItSolutionStuff.com</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<meta name="csrf-token" content="{{ csrf_token() }}" />
@section('left-menu')
@parent
<ul>
@ -11,6 +15,7 @@
</ul>
@stop
@section('center-area')
@parent
@ -18,21 +23,29 @@
@if( auth()->user()->fireStationID == NULL)
Jednostka nie istnieje
@else
<form method="POST" action="/szkolenia" id="dynamic_form">
{{ csrf_field() }}
<center><h1>{{$training->trainingName}}</h1></center>
<table id="editableTable" class='table table-bordered'>
<div class=form-group">
<div id="fireFightersTrainings">
<thead>
<td>Imię i Nazwisko</td>
<td>Ważne od:</td>
<td>Ważne do:</td>
<td>Akcje</td>
</thead>
</div>
</div>
<tbody>
@foreach($fireFighters as $fireFighter)
<tr id="{{$fireFighter->userID}}">
<td>{{$fireFighter->name}} {{$fireFighter->surname}}</td>
<td>{{$fireFighter->dateOfComplete}}</td>
<td>{{$fireFighter->dateOfExpiry}}</td>
<td><button class="btn btn-warning" type="submit" style="display:none" id="{{$fireFighter->userID}}" onclick="cancelButton('{{$fireFighter->userID}}')">Anuluj</button> <button class="btn btn-success" type="submit" style="display:none" id="{{$fireFighter->userID}}" onclick="updateButton('{{$fireFighter->userID}}')">Zapisz</button> <button class="btn btn-info" type="submit" id="{{$fireFighter->userID}}" onclick="editButton('{{$fireFighter->userID}}')">Edytuj</button> <button class="btn btn-danger btn-delete" type="submit" id="{{$fireFighter->userID}}">Usuń</button></td>
</tr>
@endforeach
</tbody>
</table>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz badania</button>
</div>
@include('inc.formerrors')
</form>
@endif
@else
Brak autoryzacji
@ -40,59 +53,118 @@
@stop
<script type="text/javascript">
<script>
$(document).ready(function(){
function editButton(firefighterID){
$('.btn-info', '#'+firefighterID).css('display', 'none');
$('.btn-warning', '#'+firefighterID).css('display', 'inline');
$('.btn-success', '#'+firefighterID).css('display', 'inline');
$('.btn-info', '#'+firefighterID).parents("tr").find("td:eq(1)").html('<input type="date" name="dateOfComplete">');
$('.btn-info', '#'+firefighterID).parents("tr").find("td:eq(2)").html('<input type="date" name="dateOfExpiry">');
}
var count = 1;
dynamic_field(count);
function cancelButton(firefighterID){
$('.btn-info', '#'+firefighterID).css('display', 'inline');
$('.btn-warning', '#'+firefighterID).css('display', 'none');
$('.btn-success', '#'+firefighterID).css('display', 'none');
function dynamic_field(number)
{
$('.btn-info', '#'+firefighterID).parents("tr").find("td:eq(1)").html('{{$fireFighter->dateOfComplete}}');
$('.btn-info', '#'+firefighterID).parents("tr").find("td:eq(2)").html('{{$fireFighter->dateOfExpiry}}');
}
html = '<div id="singleFireFighter"><label for="location">Strażak:</label>';
html += '<select name="fireFighterTraining[]" class="form-control">';
html += '<option value="">--- Wybierz strażaka ---</option>';
html += '@foreach ($fireFighters as $fireFighter)';
html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';
html += '@endforeach';
html += '</select>';
html += '<label>Data ukończenia: </label><input type="date" name="dateOfComplete[]">'
html += '<label> Koniec ważności: </label><input type="date" id="dateOfExpiry">'
html += 'Bezterminowo: <input type="checkbox" id="lifeless">'
if(number > 1)
{
html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>';
$('#fireFightersTrainings').append(html);
function updateButton(firefighterID){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
else
{
html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>';
$('#fireFightersTrainings').html(html);
}
}
$(document).on('click', '#add', function(){
count++;
dynamic_field(count);
});
$(document).on('click', '.remove', function(){
count--;
$(this).closest("#singleFireFighter").remove();
$.ajax({
type: 'post',
url: '/szkolenia/addTrainingsFireFighters/',
data: {
'firefighterID': firefighterID,
'trainingID': '{{$training->id}}',
'dateOfComplete': $('input[name=dateOfComplete]').val(),
'dateOfExpiry': $('input[name=dateOfExpiry]').val()
},
success: function(data) {
if ((data.errors)) {
$('.error').removeClass('hidden');
$('.error').text(data.errors.name);
} else {
$('.error').remove();
$('.btn-info', '#'+firefighterID).parents("tr").find("td:eq(1)").html($('input[name=dateOfComplete]').val());
$('.btn-info', '#'+firefighterID).parents("tr").find("td:eq(2)").html($('input[name=dateOfExpiry]').val());
}
},
});
$('#lifeless').change(function(){
if($(this).is(':checked'))
$('#dateOfExpiry').prop('disabled', true)
else
$('#dateOfExpiry').prop('disabled', false)
})
});
$('.btn-info', '#'+firefighterID).css('display', 'inline');
$('.btn-warning', '#'+firefighterID).css('display', 'none');
$('.btn-success', '#'+firefighterID).css('display', 'none');
{{--$('.btn-info', '#'+firefighterID).parents("tr").find("td:eq(1)").html('{{$fireFighter->dateOfComplete}}');--}}
{{--$('.btn-info', '#'+firefighterID).parents("tr").find("td:eq(2)").html('{{$fireFighter->dateOfExpiry}}');--}}
}
// $("form").submit(function(e){
// e.preventDefault();
// var name = $("input[name='name']").val();
// var email = $("input[name='email']").val();
//
// $(".data-table tbody").append("<tr data-name='"+name+"' data-email='"+email+"'><td>"+name+"</td><td>"+email+"</td><td><button class='btn btn-info btn-xs btn-edit'>Edit</button><button class='btn btn-danger btn-xs btn-delete'>Delete</button></td></tr>");
//
// $("input[name='name']").val('');
// $("input[name='email']").val('');
// });
//
// $("body").on("click", ".btn-delete", function(){
// $(this).parents("tr").remove();
// });
//
// $("body").on("click", ".btn-edit", function(){
// var name = $(this).parents("tr").attr('data-name');
// var email = $(this).parents("tr").attr('data-email');
//
// $(this).parents("tr").find("td:eq(0)").html('<input name="edit_name" value="'+name+'">');
// $(this).parents("tr").find("td:eq(1)").html('<input name="edit_email" value="'+email+'">');
//
// $(this).parents("tr").find("td:eq(2)").prepend("<button class='btn btn-info btn-xs btn-update'>Update</button><button class='btn btn-warning btn-xs btn-cancel'>Cancel</button>")
// $(this).hide();
// });
//
// $("body").on("click", ".btn-cancel", function(){
// var name = $(this).parents("tr").attr('data-name');
// var email = $(this).parents("tr").attr('data-email');
//
// $(this).parents("tr").find("td:eq(0)").text(name);
// $(this).parents("tr").find("td:eq(1)").text(email);
//
// $(this).parents("tr").find(".btn-edit").show();
// $(this).parents("tr").find(".btn-update").remove();
// $(this).parents("tr").find(".btn-cancel").remove();
// });
//
// $("body").on("click", ".btn-update", function(){
// var name = $(this).parents("tr").find("input[name='edit_name']").val();
// var email = $(this).parents("tr").find("input[name='edit_email']").val();
//
// $(this).parents("tr").find("td:eq(0)").text(name);
// $(this).parents("tr").find("td:eq(1)").text(email);
//
// $(this).parents("tr").attr('data-name', name);
// $(this).parents("tr").attr('data-email', email);
//
// $(this).parents("tr").find(".btn-edit").show();
// $(this).parents("tr").find(".btn-cancel").remove();
// $(this).parents("tr").find(".btn-update").remove();
// });
</script>

View File

@ -74,6 +74,11 @@ Route::get('/sprzet/edit/{id}', 'EquipmentController@editForm');
Route::post('/sprzet/edit', 'EquipmentController@update');
Route::resource('equipment', 'EquipmentController');
Route::get('/szkolenia', 'trainingsController@create');
Route::post('/szkolenia', 'trainingsController@store');
Route::get('/szkolenia/addTrainingsFireFighters/{id}', 'trainingsController@addTrainingsFireFighters');
Route::post('/szkolenia/addTrainingsFireFighters/', 'trainingsController@ajaxRequest');
Route::get('register/verify/{confirmationCode}', [
'as' => 'confirmation_path',
'uses' => 'RegistrationController@confirm'