Working list/availability implementation
This commit is contained in:
parent
097aa485ff
commit
be4701cce0
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class AvailabilityController extends Controller
|
||||||
|
{
|
||||||
|
public function get(Request $request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"available" => $request->user()->available,
|
||||||
|
"manual_mode" => $request->user()->availability_manual_mode
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAvailability(Request $request)
|
||||||
|
{
|
||||||
|
if($request->input("id")) {
|
||||||
|
$user = User::find($request->input("id"));
|
||||||
|
} else {
|
||||||
|
$user = $request->user();
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->available = $request->input("available", false);
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
return [
|
||||||
|
"updated_user_id" => $user->id,
|
||||||
|
"updated_user_name" => $user->name
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAvailabilityManualMode(Request $request)
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$user->availability_manual_mode = $request->input("manual_mode", false);
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
class UserController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return User::where('hidden', 0)
|
||||||
|
->orderBy('available', 'desc')
|
||||||
|
->orderBy('chief', 'desc')
|
||||||
|
->orderBy('services', 'asc')
|
||||||
|
->orderBy('trainings', 'desc')
|
||||||
|
->orderBy('availability_minutes', 'asc')
|
||||||
|
->orderBy('name', 'asc')
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*/
|
||||||
|
public function show(User $user)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*/
|
||||||
|
public function update(Request $request, User $user)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*/
|
||||||
|
public function destroy(User $user)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,8 @@ class User extends Authenticatable
|
||||||
'email',
|
'email',
|
||||||
'phone_number',
|
'phone_number',
|
||||||
'available',
|
'available',
|
||||||
|
'availability_manual_mode',
|
||||||
|
'availability_minutes',
|
||||||
'chief',
|
'chief',
|
||||||
'driver',
|
'driver',
|
||||||
'services',
|
'services',
|
||||||
|
|
|
@ -15,6 +15,8 @@ return new class extends Migration
|
||||||
$table->string('username')->unique();
|
$table->string('username')->unique();
|
||||||
$table->string('phone_number')->nullable(); //https://github.com/googlei18n/libphonenumber/blob/master/FALSEHOODS.md
|
$table->string('phone_number')->nullable(); //https://github.com/googlei18n/libphonenumber/blob/master/FALSEHOODS.md
|
||||||
$table->boolean('available')->default(false);
|
$table->boolean('available')->default(false);
|
||||||
|
$table->boolean('availability_manual_mode')->default(false);
|
||||||
|
$table->int('availability_minutes')->default(0);
|
||||||
$table->boolean('chief')->default(false);
|
$table->boolean('chief')->default(false);
|
||||||
$table->boolean('driver')->default(false);
|
$table->boolean('driver')->default(false);
|
||||||
$table->integer('services')->default(0);
|
$table->integer('services')->default(0);
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\AuthController;
|
use App\Http\Controllers\AuthController;
|
||||||
|
use App\Http\Controllers\UserController;
|
||||||
|
use App\Http\Controllers\AvailabilityController;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
@ -22,5 +23,11 @@ Route::middleware('auth:sanctum')->group( function () {
|
||||||
Route::get('/me', [AuthController::class, 'me']);
|
Route::get('/me', [AuthController::class, 'me']);
|
||||||
Route::post('/me', [AuthController::class, 'me']);
|
Route::post('/me', [AuthController::class, 'me']);
|
||||||
|
|
||||||
|
Route::get('/list', [UserController::class, 'index']);
|
||||||
|
|
||||||
|
Route::get('/availability', [AvailabilityController::class, 'get']);
|
||||||
|
Route::post('/availability', [AvailabilityController::class, 'updateAvailability']);
|
||||||
|
Route::post('/manual_mode', [AvailabilityController::class, 'updateAvailabilityManualMode']);
|
||||||
|
|
||||||
Route::post('/logout', [AuthController::class, 'logout']);
|
Route::post('/logout', [AuthController::class, 'logout']);
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
<i *ngIf="auth.profile.hasRole('SUPER_ADMIN') && row.id !== auth.profile.auth_user_id" class="fa fa-user me-2" (click)="onUserImpersonate(row.id)"></i>
|
<i *ngIf="auth.profile.hasRole('SUPER_ADMIN') && row.id !== auth.profile.auth_user_id" class="fa fa-user me-2" (click)="onUserImpersonate(row.id)"></i>
|
||||||
<img alt="red helmet" src="./assets/icons/red_helmet.png" width="20px" *ngIf="row.chief">
|
<img alt="red helmet" src="./assets/icons/red_helmet.png" width="20px" *ngIf="row.chief">
|
||||||
<img alt="red helmet" src="./assets/icons/black_helmet.png" width="20px" *ngIf="!row.chief">
|
<img alt="red helmet" src="./assets/icons/black_helmet.png" width="20px" *ngIf="!row.chief">
|
||||||
<ng-container *ngIf="(getTime() - row.online_time) < 30"><u>{{ row.name }}</u></ng-container>
|
<ng-container *ngIf="(getTime() - row.last_access) < 30"><u>{{ row.name }}</u></ng-container>
|
||||||
<ng-container *ngIf="(getTime() - row.online_time) > 30">{{ row.name }}</ng-container>
|
<ng-container *ngIf="(getTime() - row.last_access) > 30">{{ row.name }}</ng-container>
|
||||||
</td>
|
</td>
|
||||||
<td (click)="onChangeAvailability(row.id, row.available ? 0 : 1)">
|
<td (click)="onChangeAvailability(row.id, row.available ? 0 : 1)">
|
||||||
<i class="fa fa-check" style="color:green" *ngIf="row.available"></i>
|
<i class="fa fa-check" style="color:green" *ngIf="row.available"></i>
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- <app-table [sourceType]="'list'" (changeAvailability)="changeAvailibility($event.newState, $event.user)" #table></app-table> -->
|
<app-table [sourceType]="'list'" (changeAvailability)="changeAvailibility($event.newState, $event.user)" #table></app-table>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<button (click)="requestTelegramToken()" class="btn btn-md btn-success mt-3">{{ 'list.connect_telegram_bot'|translate }}</button>
|
<button (click)="requestTelegramToken()" class="btn btn-md btn-success mt-3">{{ 'list.connect_telegram_bot'|translate }}</button>
|
||||||
</div>
|
</div>
|
|
@ -117,18 +117,12 @@ export class ListComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
/*
|
|
||||||
this.loadAvailabilityInterval = setInterval(() => {
|
this.loadAvailabilityInterval = setInterval(() => {
|
||||||
console.log("Refreshing availability...");
|
|
||||||
this.loadAvailability();
|
this.loadAvailability();
|
||||||
}, 10000);
|
}, 30000);
|
||||||
this.auth.authChanged.subscribe({
|
this.auth.authChanged.subscribe({
|
||||||
next: () => {
|
next: () => this.loadAvailability()
|
||||||
this.loadAvailability();
|
|
||||||
this.loadAvailability();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
|
|
Loading…
Reference in New Issue