mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Added tasks to activity on dashboard
- Creating and updating tasks creates an activity now - Each has its own event - The activity is shown on the dashboard
This commit is contained in:
parent
fdb2aefc66
commit
9095d90842
28
app/Events/TaskWasCreated.php
Normal file
28
app/Events/TaskWasCreated.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php namespace App\Events;
|
||||
|
||||
|
||||
use App\Models\Task;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class TaskWasCreated
|
||||
*/
|
||||
class TaskWasCreated extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Task
|
||||
*/
|
||||
public $task;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Task $task
|
||||
*/
|
||||
public function __construct(Task $task)
|
||||
{
|
||||
$this->task = $task;
|
||||
}
|
||||
}
|
28
app/Events/TaskWasUpdated.php
Normal file
28
app/Events/TaskWasUpdated.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php namespace App\Events;
|
||||
|
||||
|
||||
use App\Models\Task;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class TaskWasUpdated
|
||||
*/
|
||||
class TaskWasUpdated extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Task
|
||||
*/
|
||||
public $task;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Task $task
|
||||
*/
|
||||
public function __construct(Task $task)
|
||||
{
|
||||
$this->task = $task;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\TaskWasCreated;
|
||||
use App\Events\TaskWasUpdated;
|
||||
use Auth;
|
||||
use View;
|
||||
use URL;
|
||||
@ -231,7 +233,14 @@ class TaskController extends BaseController
|
||||
}
|
||||
|
||||
$task = $this->taskRepo->save($publicId, Input::all());
|
||||
Session::flash('message', trans($publicId ? 'texts.updated_task' : 'texts.created_task'));
|
||||
|
||||
if($publicId) {
|
||||
Session::flash('message', trans('texts.updated_task'));
|
||||
event(new TaskWasUpdated($task));
|
||||
} else {
|
||||
Session::flash('message', trans('texts.created_task'));
|
||||
event(new TaskWasCreated($task));
|
||||
}
|
||||
|
||||
if (in_array($action, ['invoice', 'add_to_invoice'])) {
|
||||
return self::bulk();
|
||||
|
@ -459,6 +459,10 @@ if (!defined('CONTACT_EMAIL')) {
|
||||
define('ACTIVITY_TYPE_ARCHIVE_EXPENSE', 35);
|
||||
define('ACTIVITY_TYPE_DELETE_EXPENSE', 36);
|
||||
define('ACTIVITY_TYPE_RESTORE_EXPENSE', 37);
|
||||
|
||||
// tasks
|
||||
define('ACTIVITY_TYPE_CREATE_TASK', 42);
|
||||
define('ACTIVITY_TYPE_UPDATE_TASK', 43);
|
||||
|
||||
define('DEFAULT_INVOICE_NUMBER', '0001');
|
||||
define('RECENTLY_VIEWED_LIMIT', 8);
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php namespace App\Listeners;
|
||||
|
||||
use App\Events\TaskWasCreated;
|
||||
use App\Events\TaskWasUpdated;
|
||||
use App\Models\Invoice;
|
||||
use App\Events\ClientWasCreated;
|
||||
use App\Events\ClientWasDeleted;
|
||||
@ -466,4 +468,30 @@ class ActivityListener
|
||||
$event->fromDeleted ? $payment->getCompletedAmount() : 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an activity when a task was created
|
||||
*
|
||||
* @param TaskWasCreated $event
|
||||
*/
|
||||
public function createdTask(TaskWasCreated $event)
|
||||
{
|
||||
$this->activityRepo->create(
|
||||
$event->task,
|
||||
ACTIVITY_TYPE_CREATE_TASK
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an activity when a task was updated
|
||||
*
|
||||
* @param TaskWasUpdated $event
|
||||
*/
|
||||
public function updatedTask(TaskWasUpdated $event)
|
||||
{
|
||||
$this->activityRepo->create(
|
||||
$event->task,
|
||||
ACTIVITY_TYPE_UPDATE_TASK
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,11 @@ class Activity extends Eloquent
|
||||
return $this->belongsTo('App\Models\Payment')->withTrashed();
|
||||
}
|
||||
|
||||
public function task()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Task')->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@ -93,6 +98,9 @@ class Activity extends Eloquent
|
||||
$credit = $this->credit;
|
||||
$isSystem = $this->is_system;
|
||||
|
||||
/** @var Task $task */
|
||||
$task = $this->task;
|
||||
|
||||
$data = [
|
||||
'client' => link_to($client->getRoute(), $client->getDisplayName()),
|
||||
'user' => $isSystem ? '<i>' . trans('texts.system') . '</i>' : $user->getDisplayName(),
|
||||
@ -103,6 +111,7 @@ class Activity extends Eloquent
|
||||
'payment_amount' => $payment ? $account->formatMoney($payment->amount, $payment) : null,
|
||||
'adjustment' => $this->adjustment ? $account->formatMoney($this->adjustment, $this) : asdf,
|
||||
'credit' => $credit ? $account->formatMoney($credit->amount, $client) : null,
|
||||
'task' => $task ? link_to($task->getRoute(), substr($task->description, 0, 30).'...') : null,
|
||||
];
|
||||
|
||||
return trans("texts.activity_{$activityTypeId}", $data);
|
||||
|
@ -131,4 +131,14 @@ class Task extends EntityModel
|
||||
{
|
||||
return round($this->getDuration() / (60 * 60), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the route to the tasks edit action
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRoute()
|
||||
{
|
||||
return "/tasks/{$this->public_id}/edit";
|
||||
}
|
||||
}
|
||||
|
@ -151,6 +151,14 @@ class EventServiceProvider extends ServiceProvider {
|
||||
'App\Events\UserSettingsChanged' => [
|
||||
'App\Listeners\HandleUserSettingsChanged',
|
||||
],
|
||||
|
||||
// Task events
|
||||
'App\Events\TaskWasCreated' => [
|
||||
'App\Listeners\ActivityListener@createdTask',
|
||||
],
|
||||
'App\Events\TaskWasUpdated' => [
|
||||
'App\Listeners\ActivityListener@updatedTask',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddTaskIdToActivityTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('activities', function (Blueprint $table) {
|
||||
$table->integer('task_id')->after('invitation_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('activities', function (Blueprint $table) {
|
||||
$table->dropColumn('task_id');
|
||||
});
|
||||
}
|
||||
}
|
@ -775,6 +775,8 @@ $LANG = array(
|
||||
'activity_35' => ':user created :vendor',
|
||||
'activity_36' => ':user created :vendor',
|
||||
'activity_37' => ':user created :vendor',
|
||||
'activity_42' => ':user erstellte Aufgabe ":task"',
|
||||
'activity_43' => ':user aktualisierte Aufgabe ":task"',
|
||||
'payment' => 'Zahlung',
|
||||
'system' => 'System',
|
||||
'signature' => 'Email-Signatur',
|
||||
|
@ -774,6 +774,8 @@ $LANG = array(
|
||||
'activity_35' => ':user created :vendor',
|
||||
'activity_36' => ':user created :vendor',
|
||||
'activity_37' => ':user created :vendor',
|
||||
'activity_42' => ':user created task ":task"',
|
||||
'activity_43' => ':user updated task ":task"',
|
||||
'payment' => 'Payment',
|
||||
'system' => 'System',
|
||||
'signature' => 'Email Signature',
|
||||
|
Loading…
Reference in New Issue
Block a user