Professional Documents
Culture Documents
Completa Modo TV: Commit Authored 2 Weeks Ago by
Completa Modo TV: Commit Authored 2 Weeks Ago by
Completa Modo TV: Commit Authored 2 Weeks Ago by
Completa modo tv
app/Events/TurnCalled.php → app/Events/TurnStateChanged.php
... ... @@ -2,6 +2,7 @@
2 2
3 3 namespace App\Events;
4 4
5 + use App\PendingTurn;
5 6 use Illuminate\Broadcasting\Channel;
6 7 use Illuminate\Broadcasting\InteractsWithSockets;
7 8 use Illuminate\Broadcasting\PresenceChannel;
... ... @@ -10,20 +11,20 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
10 11 use Illuminate\Foundation\Events\Dispatchable;
11 12 use Illuminate\Queue\SerializesModels;
12 13
13 - class TurnCalled implements ShouldBroadcast
14 + class TurnStateChanged implements ShouldBroadcast
14 15 {
15 16 use Dispatchable, InteractsWithSockets, SerializesModels;
16 17
17 - public $data;
18 + public $pendingTurn;
18 19
19 20 /**
20 21 * Create a new event instance.
21 22 *
22 23 * @return void
23 24 */
24 - public function __construct($data)
25 + public function __construct($pendingTurn)
25 26 {
26 - $this->data = $data;
27 + $this->pendingTurn = is_array($pendingTurn) ? $pendingTurn : $pendingTurn->toArray();
27 28 }
28 29
29 30 /**
... ...
app/Http/Controllers/API/PendingTurnController.php 0 → 100644
1 + <?php
2 +
3 + namespace App\Http\Controllers\API;
4 +
5 + use App\Http\Controllers\Controller;
6 + use App\PendingTurn;
7 + use Illuminate\Http\Request;
8 +
9 + class PendingTurnController extends Controller
10 +{
11 + public function allFromToday()
12 + {
13 + $pendingTurns = PendingTurn::getAllFromToday();
14 + return response()->json(['status' => 'success', 'data' => compact('pendingTurns')]);
15 + }
16 +
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 1/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
17 +}
app/Http/Controllers/API/TurnController.php
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 2/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
69 65 ]);
70 66
71 67 $dateIni = date_create(\Carbon\Carbon::make($data['dateIni'])->subHours(5));
72 - $recorData = [
73 - ['path' => 'state', 'value' => 'Atendiendo'],
68 +
69 + $turn = Turn::update($id, [
70 + ['path' => 'state', 'value' => TurnState::ATENDIENDO],
74 71 ['path' => 'dateIni', 'value' => $dateIni]
75 - ];
72 + ]);
73 +
74 + Queue::update($turn->field('idQueue'), [
75 + ['path' => 'state', 'value' => TurnState::ATENDIENDO],
76 + ]);
77 +
78 + $pendingTurn = PendingTurn::first('idTurn', '=', $turn->id());
79 + $pendingTurn = $pendingTurn->updateInstance([
80 + ['path' => 'state', 'value' => TurnState::ATENDIENDO],
81 + ]);
82 +
83 + event(new TurnStateChanged($pendingTurn));
76 84
77 - $turn = Turn::update($id, $recorData);
78 85 return response()->json(['status' => 'success', 'data' => compact('turn')]);
79 86 }
80 87
... ... @@ -85,16 +92,41 @@ class TurnController extends Controller
85 92 ]);
86 93
87 94 $dateFin = date_create(\Carbon\Carbon::make($data['dateFin'])->subHours(5));
88 - $recorData = [
89 - ['path' => 'state', 'value' => 'Terminado'],
95 +
96 + $turn = Turn::update($id, [
97 + ['path' => 'state', 'value' => TurnState::TERMINADO],
90 98 ['path' => 'dateFin', 'value' => $dateFin]
91 - ];
99 + ]);
92 100
93 - $turn = Turn::update($id, $recorData);
94 101 $queue = Queue::update($turn->field('idQueue'), [
95 - ['path' => 'state', 'value' => 'Terminado'],
102 + ['path' => 'state', 'value' => TurnState::TERMINADO],
96 103 ]);
97 104
105 + $pendingTurn = PendingTurn::first('idTurn', '=', $turn->id());
106 + $pendingTurnData = $pendingTurn->deleteInstance();
107 + $pendingTurnData['state'] = TurnState::TERMINADO;
108 +
109 + event(new TurnStateChanged($pendingTurnData));
110 +
111 + return response()->json(['status' => 'success', 'data' => compact('turn', 'queue')]);
112 + }
113 +
114 + public function cancel(Request $request, $id)
115 + {
116 + $turn = Turn::update($id, [
117 + ['path' => 'state', 'value' => TurnState::CANCELADO],
118 + ]);
119 +
120 + $queue = Queue::update($turn->field('idQueue'), [
121 + ['path' => 'state', 'value' => TurnState::CANCELADO],
122 + ]);
123 +
124 + $pendingTurn = PendingTurn::first('idTurn', '=', $turn->id());
125 + $pendingTurnData = $pendingTurn->deleteInstance();
126 + $pendingTurnData['state'] = TurnState::CANCELADO;
127 +
128 + event(new TurnStateChanged($pendingTurnData));
129 +
98 130 return response()->json(['status' => 'success', 'data' => compact('turn', 'queue')]);
99 131 }
100 132 }
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 3/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
app/Http/Controllers/HomeController.php
... ... @@ -2,8 +2,6 @@
2 2
3 3 namespace App\Http\Controllers;
4 4
5 - use App\Events\TurnCalled;
6 -
7 5 class HomeController extends Controller
8 6 {
9 7
... ...
app/Http/Controllers/QueueController.php
... ... @@ -47,8 +47,8 @@ class QueueController extends Controller
47 47 ]);
48 48
49 49 $client = Client::create([
50 - 'createdAt' => date_create(),
51 - 'createdBy' => \LfAuth::id(),
50 + 'createAt' => date_create(),
51 + 'creteBy' => \LfAuth::id(),
52 52 'state' => 'Activo',
53 53 'identification' => $data['identification'],
54 54 'location' => [
... ... @@ -63,25 +63,28 @@ class QueueController extends Controller
63 63 $client = Client::first('identification', '=', $data['identification']);
64 64 }
65 65
66 + // Crear la queue
66 67 $recordData = [
67 68 'idBranch' => $data['id-branch'],
68 69 'idCompany' => $data['id-company'],
69 70 'idService' => $data['id-service'],
70 71 'isPriority' => (bool)$request->has('is-priority'),
71 72 'uid' => $client->field('uid'),
72 - 'createdBy' => \LfAuth::id(),
73 - 'createdAt' => date_create(),
73 + 'createAt' => date_create(),
74 + 'creteBy' => \LfAuth::id(),
74 75 ];
75 76
76 77 if ($request->has('scheduled')) {
77 78 $recordData['date'] = date_create($data['date']);
78 79 $recordData['state'] = 'Agendado';
80 + notify()->success('', 'Se creó el turno');
79 81 $queue = Queue::create($recordData);
80 82 return redirect()->route('queue.index');
81 83 } else {
82 84 $recordData['order'] = Queue::getNextOrder();
83 85 $recordData['state'] = 'Activo';
84 86 $queue = Queue::create($recordData);
87 + notify()->success('', 'Se creó el turno');
85 88 return redirect()->route('queue.index', ['queue' => $queue->id()]);
86 89 }
87 90
... ...
app/Http/Controllers/TurnController.php
... ... @@ -4,12 +4,14 @@ namespace App\Http\Controllers;
4 4
5 5 use App\Client;
6 6 use App\Queue;
7 + use App\Turn;
7 8 use Illuminate\Http\Request;
8 9
9 10 class TurnController extends Controller
10 11 {
11 12 public function index()
12 13 {
13 - return view('turns.index');
14 + $unfinishedTurn = Turn::getUnfinishedTurnByEmployee(\State::get('employee.id')); //TODO: Completar
esto. recuperar el turno sin termninar cuando recarga pagina turnos
15 + return view('turns.index', compact('unfinishedTurn'));
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 4/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
14 16 }
15 17 }
app/PendingTurn.php
... ... @@ -8,4 +8,8 @@ class PendingTurn extends LarafireModel
8 8 {
9 9 protected $collectionName = 'pendingTurns';
10 10
11 + public static function getAllFromToday()
12 + {
13 + return static::rowsToInstances(static::createdToday()->documents()->rows());
14 + }
11 15 }
app/Queue.php
app/Support/Functions.php → app/Support/Globals.php
... ... @@ -7,3 +7,17 @@ if (!function_exists('fixCreateIndexUrl')) {
7 7 }
8 8 }
9 9
10 + if (!function_exists('feedback')) {
11 + function feedback($type, $message)
12 + {
13 + session()->put('feedback', ['type' => $type, 'message' => $message]);
14 + }
15 +}
16 +
17 + abstract class TurnState
18 +{
19 + const ESPERANDO = 'Esperando';
20 + const ATENDIENDO = 'Atendiendo';
21 + const TERMINADO = 'Terminado';
22 + const CANCELADO = 'Cancelado';
23 +}
app/Support/LarafireModel.php
... ... @@ -14,16 +14,12 @@ class LarafireModel implements JsonSerializable
14 14 private $collection;
15 15 private $firebaseObject;
16 16 protected $collectionName;
17 - private static $isInstance = false;
18 - public static $instance;
19 17
20 18 public function __construct()
21 19 {
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 5/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
22 20 $this->firestore = app('firebase.firestore');
23 21 $this->collection = $this->firestore->database()->collection($this->collectionName);
24 22 $this->firebaseObject = null;
25 - self::$isInstance = true;
26 - self::$instance = $this;
27 23 }
28 24
29 25
... ... @@ -31,11 +27,11 @@ class LarafireModel implements JsonSerializable
31 27
32 28 public static function rowsToInstances(array $rows)
33 29 {
34 - return array_map(function($row) {
30 + return collect(array_map(function($row) {
35 31 $instance = self::getNewInstance();
36 32 $instance->firebaseObject = $row;
37 33 return $instance;
38 - }, $rows);
34 + }, $rows));
39 35 }
40 36
41 37
... ... @@ -47,19 +43,11 @@ class LarafireModel implements JsonSerializable
47 43 return new $className;
48 44 }
49 45
50 - private static function getInstance()
51 - {
52 - if (self::$instance === null) {
53 - self::$instance = self::getNewInstance();
54 - }
55 - return self::$instance;
56 - }
57 -
58 46 public static function all()
59 47 {
60 48 $instance = self::getNewInstance();
61 49 $rows = $instance->collection->documents()->rows();
62 - return collect(self::rowsToInstances($rows));
50 + return self::rowsToInstances($rows);
63 51 }
64 52
65 53 public static function find($id)
... ... @@ -74,6 +62,13 @@ class LarafireModel implements JsonSerializable
74 62 return $instance;
75 63 }
76 64
65 + public static function findOrFail($id)
66 + {
67 + $instance = self::find($id);
68 + if (!$instance) throw new ModelNotFoundException('Model not found');
69 + return $instance;
70 + }
71 +
77 72 public static function where($field, $operation, $value)
78 73 {
79 74 $instance = self::getNewInstance();
... ... @@ -120,13 +115,6 @@ class LarafireModel implements JsonSerializable
120 115 return $instance;
121 116 }
122 117
123 - public static function findOrFail($id)
124 - {
125 - $instance = self::find($id);
126 - if (!$instance) throw new ModelNotFoundException('Model not found');
127 - return $instance;
128 - }
129 -
130 118 public static function orderBy($field, $direction = 'ASC') //PERO
131 119 {
132 120 // $instance = self::getInstance();
... ... @@ -144,8 +132,8 @@ class LarafireModel implements JsonSerializable
144 132 {
145 133 $instance = self::getNewInstance();
146 134 // dd('le',$instance);
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 6/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 7/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
app/Turn.php
... ... @@ -3,6 +3,7 @@
3 3 namespace App;
4 4
5 5 use App\Support\LarafireModel;
6 + use TurnState;
6 7
7 8 class Turn extends LarafireModel
8 9 {
... ... @@ -16,5 +17,11 @@ class Turn extends LarafireModel
16 17 return count($records) > 0;
17 18 }
18 19
19 -
20 + public static function getUnfinishedTurnByEmployee($employeeId)
21 + {
22 + $turns = Turn::where('idEmployee', '=', $employeeId)
23 + ->where('state', 'in', [TurnState::ESPERANDO, TurnState::ATENDIENDO])
24 + ->documents()->rows();
25 + return count($turns) > 0 ? Turn::rowsToInstances($turns)[0] : null;
26 + }
20 27 }
bootstrap/cache/config.php
composer.json
... ... @@ -51,7 +51,7 @@
51 51 "app/Support/LarafireCollection.php",
52 52 "app/Support/LarafireFunctions.php",
53 53 "app/Support/State.php",
54 - "app/Support/Functions.php"
54 + "app/Support/Globals.php"
55 55 ]
56 56 },
57 57 "autoload-dev": {
... ...
config/notify.php
... ... @@ -2,7 +2,7 @@
2 2
3 3 return [
4 4
5 - 'default' => 'toastr',
5 + 'default' => 'sweetalert2',
6 6
7 7 'toastr' => [
8 8
... ... @@ -74,6 +74,6 @@ return [
74 74 'warning',
75 75 ],
76 76
77 - 'options' => [],
77 + 'options' => ['showConfirmButton' => false, 'timer' => 4000],
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 8/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
78 78 ],
79 79 ];
public/images/educacion-vial.jpg 0 → 100644
72.4 KB
public/js/master.js
... ... @@ -9,9 +9,21 @@ window.Progress = {
9 9 }
10 10 }
11 11
12 -
13 12 window.addEventListener("beforeunload", function (e) {
14 13 const loader = document.getElementById("loader");
15 14 loader.classList.add('d-flex');
16 15 loader.classList.remove('d-none');
17 16 })
17 +
18 + const Toast = Swal.mixin({
19 + toast: true,
20 + position: 'center',
21 + showConfirmButton: false,
22 + timer: 4000,
23 + timerProgressBar: true,
24 + onOpen: (toast) => {
25 + toast.addEventListener('mouseenter', Swal.stopTimer)
26 + toast.addEventListener('mouseleave', Swal.resumeTimer)
27 + }
28 + })
29 +
public/videos/educacion-vial.mp4 0 → 100644
File added
resources/views/layouts/app.blade.php
... ... @@ -21,7 +21,8 @@
21 21 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pretty-checkbox@3.0/dist/pretty-
checkbox.min.css">
22 22 <link rel="stylesheet" href="https://unpkg.com/nprogress@0.2.0/nprogress.css">
23 23
24 - @notify_css
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 9/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
resources/views/pages/tv.blade.php
... ... @@ -13,7 +13,13 @@
13 13
14 14 <div class="col-lg-6 d-flex align-items-center" style="height:80vh">
15 15 <div class="w-100">
16 - <img src="http://placehold.it/600x400" style="max-width:100%">
16 + {{-- <img src="{{asset('images/educacion-vial.jpg')}}" style="max-width:100%"> --}}
17 + <video src="{{ asset('videos/educacion-vial.mp4') }}"
18 + autoplay
19 + muted
20 + poster="{{ asset('images/educacion-vial.jpg') }}">
21 + Tu navegador no admite el elemento <code>video</code>.
22 + </video>
17 23 </div>
18 24 </div>
19 25
... ... @@ -33,10 +39,12 @@
33 39 <table class="table">
34 40 <thead>
35 41 <th class="text-center">Turno</th>
42 + <th class="text-center">Nombre</th>
36 43 <th class="text-center">Lugar</th>
37 44 </thead>
38 45 <tr v-for="turn in calledTurns">
39 46 <td class="text-center">@{{ turn.order }}</td>
47 + <td class="text-center">@{{ turn.name }}</td>
40 48 <td class="text-center">@{{ turn.label }}</td>
41 49 </tr>
42 50 </table>
... ... @@ -94,9 +102,31 @@
94 102 }
95 103 },
96 104 methods: {
97 - handleNewTurn(data) {
98 - this.callingTurns.push(data)
99 - this.calledTurns.push(data)
105 + handleNewTurn(turn) {
106 + this.callingTurns.push(turn)
107 + this.calledTurns.push(turn)
108 + },
109 + handleStartedAttendingTurn(turn) {
110 + const callingTurnsFiltered = this.callingTurns.filter(callingTurn => {
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 10/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 11/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
resources/views/queue/index.blade.php
resources/views/turns/index.blade.php
1 1 @extends('layouts.app', ['title' => 'Turnos'])
2 2 @section('content')
3 3 <div class="container" id="turns">
4 -
5 4 <div class="row">
6 5 <div class="col text-center d-flex flex-column align-items-center">
6 +
7 7 <a href="#"
8 8 class="btn mb-4 btn-primary btn-xl"
9 9 v-show="status == 'idling'"
... ... @@ -13,8 +13,8 @@
13 13 <a href="#"
14 14 class="btn mb-4 btn-warning btn-xl"
15 15 v-show="status == 'waiting'"
16 - @click.prevent="cancelTurnAndCallNext">
17 - CANCELAR TURNO Y LLAMAR A SIGUIENTE
16 + @click.prevent="cancelTurn">
17 + CANCELAR TURNO
18 18 </a>
19 19
20 20 <div v-show="status != 'idling'">
... ... @@ -67,9 +67,6 @@
67 67 Progress.start()
68 68 axios.get(@json(route('api.turns.create')))
69 69 .then((res) => {
70 - if (res.data.status == 'failed') {
71 - return bootbox.alert('Hay un turno en llamada. Por favor, intente
cuando el turno haya sido respondido.')
72 - }
73 70 if (res.data.status == 'success') {
74 71 this.client = res.data.data.client
75 72 this.queue = res.data.data.queue
... ... @@ -96,7 +93,8 @@
96 93 this.startTimer()
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 12/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
97 94 }
98 95 }).catch(err => {
99 - bootbox.alert('Ocurrió un error al comunicarse con el servidor.')
96 + bootbox.alert("<p>Ocurrió un error al llamar al siguiente turno.</p>"
97 + +err.response.data?.message?.toUpperCase())
100 98 console.log('err',err)
101 99 }).then(() => Progress.done())
102 100 },
... ... @@ -104,19 +102,39 @@
104 102 Progress.start()
105 103 axios.put('/api/turns/'+this.turn.id+'/finish', {
106 104 _token: $('[name=csrf-token]').attr('content'),
107 - state: 'Terminado',
108 105 dateFin: new Date()
109 106 }).then(res => {
110 107 if (res.data.status == 'success') {
111 108 this.status = 'idling'
112 - this.startTimer()
109 + this.stopTimer()
110 + this.resetAppData()
113 111 }
114 112 }).catch(err => {
115 - bootbox.alert('Ocurrió un error al comunicarse con el servidor.')
113 + bootbox.alert("<p>Ocurrió un error al llamar al siguiente turno.</p>"
114 + +err.response.data?.message?.toUpperCase())
116 115 console.log('err',err)
117 116 }).then(() => Progress.done())
118 - this.status = 'idling'
119 - this.stopTimer()
117 + },
118 + cancelTurn() {
119 + Progress.start()
120 + axios.put('/api/turns/'+this.turn.id+'/cancel', {
121 + _token: $('[name=csrf-token]').attr('content'),
122 + }).then(res => {
123 + if (res.data.status == 'success') {
124 + this.status = 'idling'
125 + this.resetAppData()
126 + }
127 + }).catch(err => {
128 + bootbox.alert("<p>Ocurrió un error al llamar al siguiente turno.</p>"
129 + +err.response.data?.message?.toUpperCase())
130 + console.log('err',err)
131 + }).then(() => Progress.done())
132 + },
133 + resetAppData() {
134 + this.client = null
135 + this.queue = null
136 + this.turn = null
137 + this.userClient = null
120 138 },
121 139 startTimer() {
122 140 this.timer.start(/* config */)
... ...
routes/web.php
... ... @@ -73,9 +73,16 @@ Route::group([
73 73 'as' => 'turns.'
74 74 ], function() {
75 75 Route::get('create','TurnController@create')->name('create'); //TODO: Debe ser post
76 - Route::get('state','TurnController@state')->name('state');
77 76 Route::put('{id}/start','TurnController@start')->name('start');
78 77 Route::put('{id}/finish','TurnController@finish')->name('finish');
78 + Route::put('{id}/cancel','TurnController@cancel')->name('cancel');
79 + });
80 +
81 + Route::group([
82 + 'prefix' => 'pending-turns',
83 + 'as' => 'prending-turns.'
84 + ], function() {
85 + Route::get('all-from-today','PendingTurnController@allFromToday')->name('all-from-today');
79 86 });
80 87 });
81 88
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 13/14
29/6/2020 Completa modo tv (9a612e96) · Commits · Guillermo Agudelo / transito-frontend · GitLab
https://gitlab.com/guille.agudelo/transito-frontend/-/commit/9a612e9693e682f8d8795dfab19b572e5fa78413 14/14