6 Commits

Author SHA1 Message Date
954820f46b Added: language to User profile (DB)
The language were set only on session. But now it is
stored with user profile, on DB.

It is important as now I can send alert e-mails to each
user on their own languages and not the activer
user language.

Also, wherever the user logs out and logs in again,
it will see the same site locale.
2018-10-02 23:53:35 -03:00
8157a183c7 Refactoring: just including "use App" to make code a bit cleaner
I was using "\App::setLocale" on code, but it was annoind me.
So I included the "use App" and now I am colling
directly the "App::setLocale".
2018-10-02 23:49:16 -03:00
528d3b4caf Refactoring: TakeController returned item Mail moved to a listener
The TakeController was manually sending the email message
as well as dealing with item return, so I moved the email message
to it's own listener, I created an event for it and moved the
return part to the item model.
2018-09-30 21:37:44 -03:00
4ec2b24885 BugFixing: home page were blank on no items
When we had no items showing on home page, it were just blank.
Turns out that the @empty call that shows the default message
were appearing just when it had no items on a product, instead
of no items at all.

Fixed it moving the paragraph to the right place.
2018-09-29 12:09:18 -03:00
5be29fc3d8 Added: buttons to change language
Now the welcome.blade has two new links to change language.
Other pages has a footer with the language switcher too.
2018-09-29 01:49:02 -03:00
6b20397e9d Help Page translated into PTB
Now the entire website should be translated into PTB.
2018-09-28 19:14:29 -03:00
20 changed files with 436 additions and 85 deletions

38
app/Events/ReturnItem.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
namespace App\Events;
use \App\Item;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ReturnItem
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $item;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Item $item)
{
$this->item = $item;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use Auth;
use \App\User;
use \App\Mail\UserWaiting;
use Illuminate\Http\Request;
@@ -11,15 +12,15 @@ class AlertController extends Controller
public function store(Request $request)
{
$item = User::loggedIn()->items()->find(request('item'));
$item->waiting_user_id = \Auth::id();
$item->waiting_user_id = Auth::id();
$item->timestamps = false;
$item->save();
$loggedUser = \Auth::user()->name;
$loggedUser = Auth::user()->name;
$userWithItem = User::find($item->used_by);
\Mail::to($userWithItem)->send(
new UserWaiting($loggedUser, $userWithItem->name, $item)
);
\Mail::to($userWithItem)
->locale($userWithItem->language)
->send(new UserWaiting($loggedUser, $userWithItem->name, $item));
return redirect('home');
}

View File

@@ -0,0 +1,91 @@
<?php
namespace App\Http\Controllers;
use App;
use Lang;
use App\User;
use Illuminate\Http\Request;
class LanguageController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $locale
* @return \Illuminate\Http\Response
*/
public function update($locale)
{
App::setLocale($locale);
User::setLanguage($locale);
session(['lang' => $locale]);
session()->save();
return back();
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}

View File

@@ -4,8 +4,8 @@ namespace App\Http\Controllers;
use \App\Item;
use \App\User;
use App\Mail\ItemAvailable;
use Illuminate\Http\Request;
use App\Events\ReturnItem;
class TakeController extends Controller
{
@@ -27,19 +27,8 @@ class TakeController extends Controller
public function delete(Request $request)
{
$item = User::loggedIn()->items()->find(request('item'));
$waiting_id = $item->waiting_user_id;
$item->used_by = null;
$item->waiting_user_id = null;
$item->save();
//Send e-mail to waiting user
if ($waiting_id) {
$user = User::find($waiting_id);
\Mail::to($user)->send(
new ItemAvailable($user->name, $item)
);
}
event(new ReturnItem($item));
$item->returnItem();
return redirect('home');
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Http\Middleware;
use App;
use Closure;
class Locale
@@ -15,7 +16,7 @@ class Locale
*/
public function handle($request, Closure $next)
{
\App::setLocale(session('lang'));
App::setLocale(session('lang'));
return $next($request);
}
}

View File

@@ -38,4 +38,16 @@ class Item extends Model
{
return (new static)->where('user_id', \Auth::id());
}
/**
* Return a specified item
*
* @return void
*/
public function returnItem()
{
$this->used_by = null;
$this->waiting_user_id = null;
$this->save();
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Listeners;
use Mail;
use App\User;
use App\Events\ReturnItem;
use App\Mail\ItemAvailable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class AlertReturnedItem
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Send an email to the user that
* is waiting for the item
*
* @param ReturnItem $item
* @return void
*/
public function handle(ReturnItem $event)
{
if ($event->item->waiting_user_id) {
$user = User::find($event->item->waiting_user_id);
Mail::to($user)
->locale($user->language)
->send(new ItemAvailable($user->name, $event->item));
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Listeners;
use App\User;
use IlluminateAuthEventsLogin;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Events\Login;
class SetLanguage
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param IlluminateAuthEventsLogin $event
* @return void
*/
public function handle(Login $event)
{
session(['lang' => User::loggedIn()->language]);
session()->save();
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Mail;
use Lang;
use \App\Item;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
@@ -35,7 +36,7 @@ class UserWaiting extends Mailable
public function build()
{
return $this->subject(
\Lang::getFromJson(
Lang::getFromJson(
':waitinguser wants to use :itemname',
[
'waitinguser' => $this->waitingUser,

View File

@@ -2,6 +2,9 @@
namespace App\Providers;
use App\Events\ReturnItem;
use App\Listeners\SetLanguage;
use App\Listeners\AlertReturnedItem;
use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
@@ -18,6 +21,14 @@ class EventServiceProvider extends ServiceProvider
Registered::class => [
SendEmailVerificationNotification::class,
],
ReturnItem::class => [
AlertReturnedItem::class,
],
'Illuminate\Auth\Events\Login' => [
SetLanguage::class,
],
];
/**

View File

@@ -2,6 +2,7 @@
namespace App;
use Auth;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -46,6 +47,23 @@ class User extends Authenticatable implements MustVerifyEmail
*/
public static function loggedIn()
{
return (new static)->findOrFail(\Auth::id());
return (new static)->findOrFail(Auth::id());
}
/**
* Set the default website language
* for the acual user
*
* @param string $language The language code
*
* @return void
*/
public static function setLanguage(string $language)
{
if (Auth::check()) {
$user = self::loggedIn();
$user->language = $language;
$user->save();
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddLocationToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('language')->after('email_verified_at')->default('en');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('language');
});
}
}

View File

@@ -26,42 +26,48 @@ return [
/**
* Step-by-step
*/
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'step_title' => 'Step-by-step',
'step_sharing_subtitle' => 'Sharing a product/item',
'step_sharing_steps' => '<li>Go to the <strong><a href="/product">Products</a></strong> page;</li>
<li>Include the Product and click on it;</li>
<li>Include an Item that belongs to that Product and click on it;</li>
<li>Add other people with their subscribed e-mail address.</li>',
'step_sharedItem_subtitle' => 'Using a shared item',
'step_sharedItem_steps' => '<li>Go to the <strong><a href="/home">Home</a></strong> page (tip: add this page as a bookmark);</li>
<li>Click on <strong>Take</strong> to take the item you want to use;</li>
<li>When you finish using it, click on <strong>Return</strong> button.</li>',
'step_getAlerted_subtitle' => 'Getting alerted when an item is available',
'step_getAlerted_steps' => '<li>Go to the <strong><a href="/home">Home</a></strong> page (tip: add this page as a bookmark);</li>
<li>Click on <strong>Alert me</strong> next the taken item;</li>
<li>The active user will be alerted you want to use it later. When the person return it, you will be notified.</li>',
/**
* Screens
*/
'' => '',
'screens_title' => 'Screens',
/**
* Home
*/
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'home_title' => 'Home',
'home_body' => '<p>The <strong>Home</strong> is the main screen where you will going to <strong>Take</strong>
and <strong>Return</strong> items.</p>
<p>It shows all items that were shared with you or that you are sharing, unless you remove yourself from there.</p>
<p>If the item has a website, the items name will become a link, so you can just click on it to open.</p>
<p>When the item you want is already taken, you are going to see who got it and for how long.
So you can identify if the person is still using it or if someone just forgot to return it.</p>
<p>You can also ask to be alerted when the item is available. This will notify the active
user that you want to use that item. So the person can return it as soon as they finish using it.</p>',
/**
* Products
*/
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'' => '',
'products_title' => 'Products',
'products_body' => '<p>The <strong>Products</strong> is the screen to include Products and Items.</p>
<p>You can also <strong>add users</strong> to your items from this screen.
To be able to do that you just need to select the item.</p>
<p class="mb-4">When adding a Product, you can specify a webpage (this is optional).</p>',
];

View File

@@ -0,0 +1,74 @@
<?php
/**
* Strings from the Help page
* They are separeted by help group
*/
return [
'helpTitle' => 'Ajuda...',
/**
* What is it?
*/
'whatIsIt' => 'O que é?',
'siteHelpOthers' => '<p><strong>Share&nbsp;It!</strong> é um site que te ajudar a compartilhar seus items com seus amigos.</p>
<p>Mas antes de qualquer coisa, você precisa entender duas ideias básicas:</p>',
'product_item' => '<li><strong>Produto</strong> - Um grupo que contém itens similares</li>
<li><strong>Item</strong> - O item que será compartilhado. Cada item pertence a um <strong>Produto</strong></li>',
'examples' => "<strong><em>Exemplos:</em></strong> Você pode criar os seguintes Produtos/Itens:</p>
<p>
<ul>
<li>Livros -> Don Quixote, O guia do mochileiro das galáxias</li>
<li>Filmes Matrix -> Matrix 1, Matrix 2, Matrix 3</li>
<li>Site Y -> <em>SuaConta</em>*</li>
</ul>
<p><em>* Observe que muitos sites não permitem compartilhar sua conta. Leia atentamente o contrato do serviço antes de incluí-lo aqui.</em></p>",
/**
* Step-by-step
*/
'step_title' => 'Passo a passo',
'step_sharing_subtitle' => 'Compartilhando um produto/item',
'step_sharing_steps' => '<li>Vá para a página <strong><a href="/product">Produtos</a></strong>;</li>
<li>Inclua o Produto e clique nele;</li>
<li>Inclua um item que pertence ao produto cadastrado e clique nele;</li>
<li>Adicione outras pessoas pelo e-mail que elas se cadastram.</li>',
'step_sharedItem_subtitle' => 'Usando um item compartilhado',
'step_sharedItem_steps' => '<li>Vá até a página <strong><a href="/home">Início</a></strong> (dica: adicione essa página aos seus favoritos);</li>
<li>Clique em <strong>Usar</strong> para usar o item que deseja;</li>
<li>Ao terminar de usar, clique no botão <strong>Devolver</strong>.</li>',
'step_getAlerted_subtitle' => 'Sendo avisado quando um item está disponível',
'step_getAlerted_steps' => '<li>Vá até a página <strong><a href="/home">Início</a></strong> (dica: adicione essa página aos seus favoritos);</li>
<li>Clique no botão <strong>Alertar</strong> próximo ao item que está em uso;</li>
<li>O atual usuário será avisado que você quer usar o item. Quando a pessoa devolver, você será notificado.</li>',
/**
* Screens
*/
'screens_title' => 'Páginas',
/**
* Home
*/
'home_title' => 'Início',
'home_body' => '<p>A tela <strong>Início</strong> é a sua página principal. Lá você vai <strong>Usar</strong>
e <strong>Devolver</strong> itens.</p>
<p>Ela exibe todos os itens que estão sendo compartilhados com você ou que você está compartilhando
a menos que você se remova de lá.</p>
<p>Se um item tiver um site cadastrado, ele aparecerá como um link. Então você pode clicar nele para abrir a página.</p>
<p>Quanto o item que você quiser já estiver em uso, você vai ver quem o está usando e por quanto tempo.
Então você pode identificar se a pessoa ainda está usando ou se aparentemente ela esqueceu de retorná-lo.</p>
<p>Você também pode pedir para ser avisado quando o item estiver disponível. Isso vai avisar o usuário ativo
que você está esperando por ele. Então a pessoa pode devolvê-lo assim que ela terminar de usar.</p>',
/**
* Products
*/
'products_title' => 'Produtos',
'products_body' => '<p>A página <strong>Produtos</strong> é a tela usada para incluir Produtos e Itens.</p>
<p>Você também pode <strong>incluir usuários</strong> aos seus items nessa tela.
Para fazer isso, você só precisa clicar no item que deseja compartilhar e incluir outras pessoas.</p>
<p class="mb-4">Ao adicionar um produto, você pode especificar um site (opcional).</p>',
];

View File

@@ -22,31 +22,24 @@
<div class="row justify-content-center mt-4">
<div class="col-md-8">
<div class="card">
<div class="card-header"><strong>Step-by-step</strong></div>
<div class="card-header"><strong>{!! __('help.step_title') !!}</strong></div>
<div class="card-body">
<div>
<strong>Sharing a product/item</strong>
<strong>{!! __('help.step_sharing_subtitle') !!}</strong>
<ol>
<li>Go to the <strong><a href="/product">Products</a></strong> page;</li>
<li>Include the Product and click on it;</li>
<li>Include an Item that belongs to that Product and click on it;</li>
<li>Add other people with their subscribed e-mail address.</li>
{!! __('help.step_sharing_steps') !!}
</ol>
</div>
<div>
<strong>Using a shared item</strong>
<strong>{!! __('help.step_sharedItem_subtitle') !!}</strong>
<ol>
<li>Go to the <strong><a href="/home">Home</a></strong> page (tip: add this page as a bookmark);</li>
<li>Click on <strong>Take</strong> to take the item you want to use;</li>
<li>When you finish using it, click on <strong>Return</strong> button.</li>
{!! __('help.step_sharedItem_steps') !!}
</ol>
</div>
<div>
<strong>Getting alerted when an item is available</strong>
<strong>{!! __('help.step_getAlerted_subtitle') !!}</strong>
<ol>
<li>Go to the <strong><a href="/home">Home</a></strong> page (tip: add this page as a bookmark);</li>
<li>Click on <strong>Alert me</strong> next the taken item;</li>
<li>The active user will be alerted you want to use it later. When the person return it, you will be notified.</li>
{!! __('help.step_getAlerted_steps') !!}
</ol>
</div>
</div>
@@ -56,23 +49,16 @@
<div class="row justify-content-center mt-4">
<div class="col-md-8">
<div class="card">
<div class="card-header"><strong>Screens</strong></div>
<div class="card-header"><strong>{!! __('help.screens_title') !!}</strong></div>
</div>
</div>
</div>
<div class="row justify-content-center mt-4">
<div class="col-md-8">
<div class="card">
<div class="card-header"><strong>Home</strong></div>
<div class="card-header"><strong>{!! __('help.home_title') !!}</strong></div>
<div class="card-body">
<p>The <strong>Home</strong> is the main screen where you will going to <strong>Take</strong>
and <strong>Return</strong> items.</p>
<p>It shows all items that were shared with you or that you are sharing, unless you remove yourself from there.</p>
<p>If the item has a website, the items name will become a link, so you can just click on it to open.</p>
<p>When the item you want is already taken, you are going to see who got it and for how long.
So you can identify if the person is still using it or if someone just forgot to return it.</p>
<p>You can also ask to be alerted when the item is available. This will notify the active
user that you want to use that item. So the person can return it as soon as they finish using it.</p>
{!! __('help.home_body') !!}
</div>
</div>
</div>
@@ -80,12 +66,9 @@
<div class="row justify-content-center mt-4">
<div class="col-md-8">
<div class="card">
<div class="card-header"><strong>Products</strong></div>
<div class="card-header"><strong>{!! __('help.products_title') !!}</strong></div>
<div class="card-body">
<p>The <strong>Products</strong> is the screen to include Products and Items.</p>
<p>You can also <strong>add users</strong> to your items from this screen.
To be able to do that you just need to select the item.</p>
<p class="mb-4">When adding a Product, you can specify a webpage (this is optional).</p>
{!! __('help.products_body') !!}
</div>
</div>
</div>

View File

@@ -33,11 +33,11 @@
</div>
</div>
@empty
<p>@lang('home.no_messages')<a href="/product">@lang('home.share_item')</a></p>
@endforelse
</div>
</div>
@empty
<p>@lang('home.no_messages') <a href="/product">@lang('home.share_item')</a></p>
@endforelse
</div>
</div>

View File

@@ -80,9 +80,11 @@
<div class="alert alert-danger text-center" role="alert">{{ $flashMsg }}</div>
@endif
<main class="py-4">
<main class="py-4 mb-5">
@yield('content')
</main>
@include('layouts.footer')
</div>
</body>

View File

@@ -0,0 +1,19 @@
<div class="my-4"><br></div>
<!-- Footer -->
<footer class="fixed-bottom page-footer font-small mt-5">
<div class="row footer-copyright text-left bg-secondary text-white mt-5 py-3">
<!-- Copyright -->
<div class="col ml-4">
© 2018<?='2018' != date('Y')?'-' . date('Y'):'';?> Copyright&nbsp; <a href="https://brunofontes.net" class="link text-white-50" target="_blank">Bruno Fontes</a>
</div>
<div class="col mr-4 text-right">
<a href="{{ url('/lang/pt-br') }}" class="link text-white">Português</a>
<span class="d-none d-sm-inline"> | </span>
<span class="d-xs-block d-sm-none"> <br> </span>
<a href="{{ url('/lang/en') }}" class="link text-white">English</a>
</div>
<!-- Copyright -->
</div>
</footer>

View File

@@ -102,9 +102,12 @@
@endauth
<a href="/help">@lang('welcome.Help')</a>
</div>
<div>
<br>
<div class="mt-5 mb-5"><br></div>
<div class="links">
<a href="{{ url('/lang/pt-br') }}">Português</a>
<a href="{{ url('/lang/en') }}">English</a>
</div>
<div class="mt-5 mb-5"><br></div>
<div class="links footer">
<a href="https://brunofontes.net">@lang('welcome.byAuthor')</a>
<p>@lang('welcome.copyright')</p>

View File

@@ -15,11 +15,7 @@ Route::get('/', function () {
return view('welcome');
});
Route::get('/lang/{locale}', function ($locale) {
session(['lang' => $locale]);
session()->save();
return back();
});
Route::get('/lang/{locale}', 'LanguageController@update')->name('language');
Route::get('/product', 'ProductController@index')->middleware('verified');
Route::get('/product/{product}', 'ProductController@show')->middleware('verified');