Skip to content

Commit

Permalink
Manage tasks in Vue.js (#666)
Browse files Browse the repository at this point in the history
* Tasks are now edited inline
* Tasks can be marked as completed
* Tasks can be edited
  • Loading branch information
djaiss authored Nov 29, 2017
1 parent 84a1461 commit 7e367d6
Show file tree
Hide file tree
Showing 41 changed files with 1,352 additions and 466 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
UNRELEASED CHANGES:

* Add more usage statistics to reflect latest changes in the DB.
*

RELEASED VERSIONS:

v1.2.0 - 2017-11-29
-------------------

* Add a much better way to manage tasks of a contact
* Tasks can now be mark as completed and can now be edited
* Add more usage statistics to reflect latest changes in the DB

v1.1.0 - 2017-11-26
-------------------

* Add the ability to add multiple contact fields and addresses per contact.
* Add a new Personalization tab under Settings.
* Add the ability to add multiple contact fields and addresses per contact
* Add a new Personalization tab under Settings

v1.0.0 - 2017-11-09
-------------------
Expand Down
11 changes: 2 additions & 9 deletions app/Http/Controllers/Api/ApiTaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Validator;
use App\Contact;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\Database\QueryException;
use App\Http\Resources\Task\Task as TaskResource;
use Illuminate\Database\Eloquent\ModelNotFoundException;
Expand Down Expand Up @@ -56,10 +55,7 @@ public function store(Request $request)
'title' => 'required|max:255',
'description' => 'string|max:1000000',
'completed_at' => 'date',
'status' => [
'required',
Rule::in(['completed', 'inprogress', 'archived']),
],
'completed' => 'boolean|required',
'contact_id' => 'required|integer',
]);

Expand Down Expand Up @@ -109,10 +105,7 @@ public function update(Request $request, $taskId)
'title' => 'required|max:255',
'description' => 'string|max:1000000',
'completed_at' => 'date',
'status' => [
'required',
Rule::in(['completed', 'inprogress', 'archived']),
],
'completed' => 'boolean|required',
'contact_id' => 'required|integer',
]);

Expand Down
137 changes: 44 additions & 93 deletions app/Http/Controllers/Contacts/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,124 +6,78 @@
use App\Contact;
use App\Http\Controllers\Controller;
use App\Http\Requests\People\TasksRequest;
use App\Http\Requests\People\TaskToggleRequest;

class TasksController extends Controller
{
/**
* Display a listing of the resource.
*
* @param Contact $contact
* @return \Illuminate\Http\Response
* Get all the tasks of this contact.
*/
public function index(Contact $contact)
public function get(Contact $contact)
{
return view('people.tasks.index')
->withContact($contact);
$tasks = collect([]);

foreach ($contact->tasks as $task) {
$data = [
'id' => $task->id,
'title' => $task->title,
'description' => $task->description,
'completed' => $task->completed,
'completed_at' => \App\Helpers\DateHelper::getShortDate($task->completed_at),
'edit' => false,
];
$tasks->push($data);
}

return $tasks;
}

/**
* Show the form for creating a new resource.
*
* @param Contact $contact
* @return \Illuminate\Http\Response
*/
public function create(Contact $contact)
{
return view('people.tasks.add')
->withContact($contact)
->withTask(new Task);
}

/**
* Store a newly created resource in storage.
*
* @param TasksRequest $request
* @param Contact $contact
* @return \Illuminate\Http\Response
* Store the task.
*/
public function store(TasksRequest $request, Contact $contact)
{
$task = $contact->tasks()->create(
$request->only([
'title',
'description',
])
+ [
'account_id' => $contact->account_id,
'status' => 'inprogress',
]
);
$task = $contact->tasks()->create([
'account_id' => auth()->user()->account->id,
'title' => $request->get('title'),
'description' => ($request->get('description') == '' ? null : $request->get('description')),
]);

$contact->logEvent('task', $task->id, 'create');

return redirect('/people/'.$contact->id)
->with('success', trans('people.tasks_add_success'));
return $task;
}

/**
* Display the specified resource.
*
* @param Contact $contact
* @param Task $task
* @return \Illuminate\Http\Response
*/
public function show(Contact $contact, Task $task)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param Contact $contact
* @param Task $task
* @return \Illuminate\Http\Response
*/
public function edit(Contact $contact, Task $task)
{
//
}

/**
* Update the specified resource in storage.
*
* @param TasksRequest $request
* @param Contact $contact
* @param Task $task
* @return \Illuminate\Http\Response
* Edit the task field.
*/
public function update(TasksRequest $request, Contact $contact, Task $task)
{
$task->update(
$request->only([
'title',
'status',
'description',
'completed_at',
])
+ ['account_id' => $contact->account_id]
);
$task->update([
'title' => $request->get('title'),
'description' => ($request->get('description') == '' ? null : $request->get('description')),
'completed' => $request->get('completed'),
]);

$contact->logEvent('task', $task->id, 'update');

return redirect('/people/'.$contact->id)
->with('success', trans('people.tasks_update_success'));
return $task;
}

/**
* Update the specified resource in storage.
*
* @param TasksRequest $request
* @param Contact $contact
* @param Task $task
* @return \Illuminate\Http\Response
*/
public function toggle(TasksRequest $request, Contact $contact, Task $task)
public function toggle(TaskToggleRequest $request, Contact $contact, Task $task)
{
$task->toggle();
// check if the state of the task has changed
if ($task->completed) {
$task->completed_at = null;
$task->completed = false;
} else {
$task->completed = true;
$task->completed_at = \Carbon\Carbon::now();
}

return redirect('/people/'.$contact->id)
->with('success', trans('people.tasks_complete_success'));
$contact->logEvent('task', $task->id, 'update');

$task->save();
}

/**
Expand All @@ -138,8 +92,5 @@ public function destroy(Contact $contact, Task $task)
$task->delete();

$contact->events()->forObject($task)->get()->each->delete();

return redirect('/people/'.$contact->id)
->with('success', trans('people.tasks_delete_success'));
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function index()
->get();

// Active tasks
$tasks = $account->tasks()->with('contact')->where('status', 'inprogress')->get();
$tasks = $account->tasks()->with('contact')->where('completed', 0)->get();

$data = [
'events' => $events,
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Requests/People/TaskToggleRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Requests\People;

use Illuminate\Foundation\Http\FormRequest;

class TaskToggleRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [];
}
}
5 changes: 2 additions & 3 deletions app/Http/Requests/People/TasksRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ public function rules()

return [
'title' => 'required|string',
'description' => '',
'completed_at' => 'date|nullable',
'status' => 'in:completed,inprogress,archived|nullable',
'description' => 'nullable',
'completed' => 'required|boolean',
];
}
}
2 changes: 1 addition & 1 deletion app/Http/Resources/Task/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function toArray($request)
'object' => 'task',
'title' => $this->title,
'description' => $this->description,
'status' => $this->status,
'completed' => (bool) $this->completed,
'completed_at' => (is_null($this->completed_at) ? null : $this->completed_at->format(config('api.timestamp_format'))),
'account' => [
'id' => $this->account->id,
Expand Down
44 changes: 13 additions & 31 deletions app/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ class Task extends Model
*
* @var array
*/
protected $dates = ['completed_at'];
protected $dates = ['completed_at', 'archived_at'];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'completed' => 'boolean',
'archived' => 'boolean',
];

/**
* Get the account record associated with the task.
Expand Down Expand Up @@ -56,7 +66,7 @@ public function contact()
*/
public function scopeCompleted(Builder $query)
{
return $query->where('status', 'completed');
return $query->where('completed', true);
}

/**
Expand All @@ -67,34 +77,6 @@ public function scopeCompleted(Builder $query)
*/
public function scopeInProgress(Builder $query)
{
return $query->where('status', 'inprogress');
}

/**
* Toggle task status.
*
* @return static
*/
public function toggle()
{
$this->status = $this->status === 'completed' ? 'inprogress' : 'completed';
$this->save();

return $this;
}

public function getTitle()
{
return $this->title;
}

public function getDescription()
{
return $this->description;
}

public function getCreatedAt()
{
return $this->created_at;
return $query->where('completed', 'false');
}
}
2 changes: 1 addition & 1 deletion config/monica.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@
| bad things will happen.
|
*/
'app_version' => '1.1.0',
'app_version' => '1.2.0',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ChangeTasksTableStructure extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tasks', function (Blueprint $table) {
$table->boolean('completed')->default(0)->after('description');
});

DB::table('tasks')
->where('status', 'completed')
->update(['completed' => 1]);

Schema::table('tasks', function (Blueprint $table) {
$table->dropColumn('status');
});
}
}
Loading

0 comments on commit 7e367d6

Please sign in to comment.