Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: life events #1765

Merged
merged 96 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
e446486
first draft of the migration
djaiss Aug 31, 2018
f2ddb3a
add default categories and types
djaiss Aug 31, 2018
41b7241
Merge branch 'master' into 2018-08-30-life-events
djaiss Aug 31, 2018
ad342ce
Apply fixes from StyleCI
djaiss Aug 31, 2018
da4ba01
Merge branch '2018-08-30-life-events' of github.com:monicahq/monica i…
djaiss Aug 31, 2018
d83aa97
core services for life events
djaiss Aug 31, 2018
d0d72ac
Apply fixes from StyleCI
djaiss Aug 31, 2018
a91fc2b
api + api tests
djaiss Sep 1, 2018
0ef7f31
Apply fixes from StyleCI
djaiss Sep 1, 2018
b1daee4
add life events to fake content seeder
djaiss Sep 1, 2018
cb6af2a
first attempt to display life events
djaiss Sep 1, 2018
00bf554
Apply fixes from StyleCI
djaiss Sep 1, 2018
ac50a8d
create life event: add types and categories icons
djaiss Sep 2, 2018
4b1e727
Apply fixes from StyleCI
djaiss Sep 2, 2018
e2a0601
chore(assets): Update assets
MonicaBot Sep 2, 2018
e01260b
add basic add life event screen
djaiss Sep 2, 2018
9ccd536
chore(assets): Update assets
MonicaBot Sep 2, 2018
7e8a6c3
update the create life event view a little bit
djaiss Sep 3, 2018
9a81222
Merge branch '2018-08-30-life-events' of github.com:monicahq/monica i…
djaiss Sep 3, 2018
00cb273
chore(assets): Update assets
MonicaBot Sep 3, 2018
07e38fd
first step to store the life event
djaiss Sep 3, 2018
e488800
better display of life events
djaiss Sep 4, 2018
80f1cdb
ability to close add modal
djaiss Sep 4, 2018
95acb8c
chore(assets): Update assets
MonicaBot Sep 4, 2018
62e7075
add mouse over effect on listing
djaiss Sep 4, 2018
16aff16
Merge branch '2018-08-30-life-events' of github.com:monicahq/monica i…
djaiss Sep 4, 2018
f2aba92
chore(assets): Update assets
MonicaBot Sep 4, 2018
e73724c
better layout for add life event screen
djaiss Sep 5, 2018
3e2fd79
first step towards changing profile page
djaiss Sep 5, 2018
b948aa3
Apply fixes from StyleCI
djaiss Sep 5, 2018
33ac3fc
chore(assets): Update assets
MonicaBot Sep 5, 2018
83c6d4e
first step to update function
djaiss Sep 6, 2018
7e2a52a
chore(assets): Update assets
MonicaBot Sep 6, 2018
5242d35
better blank display and create screen
djaiss Sep 7, 2018
dffae50
Apply fixes from StyleCI
djaiss Sep 7, 2018
a0a782c
chore(assets): Update assets
MonicaBot Sep 7, 2018
2e57c3b
better layout of the switch buttons
djaiss Sep 7, 2018
bcf93b8
create button in blank screen
djaiss Sep 7, 2018
630aff3
lay off foundations for custom information for each life event type
djaiss Sep 8, 2018
14c1204
chore(assets): Update assets
MonicaBot Sep 8, 2018
0bffb7a
wip
djaiss Sep 9, 2018
2d38953
chore(assets): Update assets
MonicaBot Sep 9, 2018
527e8df
custom date chooser
djaiss Sep 9, 2018
f90e5b2
Merge branch '2018-08-30-life-events' of github.com:monicahq/monica i…
djaiss Sep 9, 2018
8d611d1
chore(assets): Update assets
MonicaBot Sep 9, 2018
c97a439
create life event finally works
djaiss Sep 9, 2018
1582902
lang + fix tests
djaiss Sep 9, 2018
19489d2
merge master
djaiss Sep 9, 2018
c476651
chore(assets): Update assets
MonicaBot Sep 9, 2018
ee3ec1e
fix tests
djaiss Sep 9, 2018
c7af30e
Merge branch '2018-08-30-life-events' of github.com:monicahq/monica i…
djaiss Sep 10, 2018
da4acc3
Merge branch 'master' into 2018-08-30-life-events
djaiss Sep 10, 2018
7b773ab
fix fake data setup
djaiss Sep 10, 2018
ae05b21
i18n complete for add life event screen
djaiss Sep 10, 2018
b117949
chore(assets): Update assets
MonicaBot Sep 10, 2018
091a76e
wip
djaiss Sep 10, 2018
86da2ac
add destroy method
djaiss Sep 14, 2018
e2bd5ba
Apply fixes from StyleCI
djaiss Sep 14, 2018
2b1c1b0
chore(assets): Update assets
MonicaBot Sep 14, 2018
eb9c4f6
final touches for deletion and i18n
djaiss Sep 14, 2018
12be39a
chore(assets): Update assets
MonicaBot Sep 14, 2018
79494f1
Merge branch 'master' into 2018-08-30-life-events
djaiss Sep 18, 2018
323b884
update
djaiss Sep 18, 2018
a40d570
Apply fixes from StyleCI
djaiss Sep 18, 2018
557ba7c
feature complete
djaiss Sep 19, 2018
a0d6414
merge master
djaiss Sep 21, 2018
3b28e06
fix update
djaiss Sep 21, 2018
94916dd
fix destroy
djaiss Sep 21, 2018
ad1cf39
fix select not working
djaiss Sep 21, 2018
bcfdce6
Merge branch 'master' into 2018-08-30-life-events
djaiss Sep 21, 2018
2ece35d
Apply fixes from StyleCI
djaiss Sep 21, 2018
a9bb8bb
fix sonarcloud
djaiss Sep 21, 2018
2f8f65f
Merge branch '2018-08-30-life-events' of github.com:monicahq/monica i…
djaiss Sep 21, 2018
d4cd165
fix sonar
djaiss Sep 21, 2018
ba27ee0
fix sonar
djaiss Sep 21, 2018
6169526
fix again
djaiss Sep 21, 2018
8f81582
Apply fixes from StyleCI
djaiss Sep 21, 2018
78c27ae
Fix psalm
asbiin Sep 21, 2018
5fd168b
Merge branch 'master' into 2018-08-30-life-events
djaiss Sep 21, 2018
6db0122
fix palsm
djaiss Sep 22, 2018
263cb8f
Apply fixes from StyleCI
djaiss Sep 22, 2018
78a889c
Merge branch 'master' into 2018-08-30-life-events
djaiss Sep 22, 2018
d3f8166
fix pslam again, again
djaiss Sep 22, 2018
4b230b1
add details about life events
djaiss Sep 22, 2018
4545098
add changelog
djaiss Sep 22, 2018
789f15e
increase coverage
djaiss Sep 23, 2018
c1390b1
increase coverage
djaiss Sep 23, 2018
f792678
Apply fixes from StyleCI
djaiss Sep 23, 2018
99b46df
fix psalm
djaiss Sep 23, 2018
3a63ecc
Merge branch '2018-08-30-life-events' of github.com:monicahq/monica i…
djaiss Sep 23, 2018
346d341
fix palsm
djaiss Sep 23, 2018
e02734e
fix palsm
djaiss Sep 23, 2018
479c108
Merge branch 'master' into 2018-08-30-life-events
djaiss Sep 24, 2018
797dec4
enhancements
djaiss Sep 25, 2018
38b40e0
add text explaining that dates can be empty
djaiss Sep 25, 2018
df14d29
Merge branch 'master' into 2018-08-30-life-events
djaiss Sep 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
UNRELEASED CHANGES:

* Add ability to track life events
* Fix select boxes not working properly anymore
* Improve search
* Fix reminders displaying wrong date
* Add ability to define the default email address used for support
Expand Down
14 changes: 9 additions & 5 deletions app/Helpers/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use Jenssegers\Date\Date;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;

class DateHelper
Expand Down Expand Up @@ -254,16 +255,19 @@ public static function getNextTheoriticalBillingDate(String $interval)
* @param int min
* @param int max
*
* @return array
* @return Collection
*/
public static function getListOfYears($max = 120, $min = 0)
{
$years = [];
$years = collect([]);
$maxYear = now(static::getTimezone())->subYears($min)->year;
$minYear = now(static::getTimezone())->subYears($max)->year;

for ($year = $maxYear; $year >= $minYear; $year--) {
array_push($years, $year);
$years->push([
'id' => $year,
'name' => $year,
]);
}

return $years;
Expand All @@ -272,7 +276,7 @@ public static function getListOfYears($max = 120, $min = 0)
/**
* Gets a list of all the months in a year.
*
* @return array
* @return Collection
*/
public static function getListOfMonths()
{
Expand All @@ -294,7 +298,7 @@ public static function getListOfMonths()
/**
* Gets a list of all the days in a month.
*
* @return array
* @return Collection
*/
public static function getListOfDays()
{
Expand Down
125 changes: 125 additions & 0 deletions app/Http/Controllers/Api/Contact/ApiLifeEventController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

namespace App\Http\Controllers\Api\Contact;

use Illuminate\Http\Request;
use App\Models\Contact\LifeEvent;
use App\Http\Controllers\Api\ApiController;
use App\Exceptions\MissingParameterException;
use App\Services\Contact\LifeEvent\CreateLifeEvent;
use App\Services\Contact\LifeEvent\UpdateLifeEvent;
use App\Services\Contact\LifeEvent\DestroyLifeEvent;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Http\Resources\LifeEvent\LifeEvent as LifeEventResource;

class ApiLifeEventController extends ApiController
{
/**
* Get the list of life events.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$lifeEvents = auth()->user()->account->lifeEvents()
->orderBy($this->sort, $this->sortDirection)
->paginate($this->getLimitPerPage());

return LifeEventResource::collection($lifeEvents);
}

/**
* Get the detail of a given life event.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function show(Request $request, int $lifeEventId)
{
try {
$lifeEvent = LifeEvent::where('account_id', auth()->user()->account_id)
->findOrFail($lifeEventId);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
}

return new LifeEventResource($lifeEvent);
}

/**
* Store the life event.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
try {
$lifeEvent = (new CreateLifeEvent)->execute(
$request->all()
+
[
'account_id' => auth()->user()->account->id,
]
);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
} catch (MissingParameterException $e) {
return $this->setHTTPStatusCode(500)
->setErrorCode(41)
->respondWithError(config('api.error_codes.41'));
}

return new LifeEventResource($lifeEvent);
}

/**
* Update the life event.
*
* @param Request $request
* @param int $lifeEventId
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $lifeEventId)
{
try {
$lifeEvent = (new UpdateLifeEvent)->execute(
$request->all()
+
[
'account_id' => auth()->user()->account->id,
'life_event_id' => $lifeEventId,
]
);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
} catch (MissingParameterException $e) {
return $this->setHTTPStatusCode(500)
->setErrorCode(41)
->respondWithError(config('api.error_codes.41'));
}

return new LifeEventResource($lifeEvent);
}

/**
* Destroy the life event.
*
* @param Request $request
* @param int $lifeEventId
* @return \Illuminate\Http\Response
*/
public function destroy(Request $request, $lifeEventId)
{
try {
(new DestroyLifeEvent)->execute([
'account_id' => auth()->user()->account->id,
'life_event_id' => $lifeEventId,
]);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
}

return $this->respondObjectDeleted((int) $lifeEventId);
}
}
125 changes: 125 additions & 0 deletions app/Http/Controllers/Contacts/LifeEventsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

namespace App\Http\Controllers\Contacts;

use App\Helpers\DateHelper;
use Illuminate\Http\Request;
use App\Models\Contact\Contact;
use Illuminate\Support\Collection;
use App\Http\Controllers\Controller;
use App\Models\Contact\LifeEventCategory;
use App\Services\Contact\LifeEvent\CreateLifeEvent;
use App\Services\Contact\LifeEvent\DestroyLifeEvent;
use App\Http\Resources\LifeEvent\LifeEventType as LifeEventTypeResource;
use App\Http\Resources\LifeEvent\LifeEventCategory as LifeEventCategoryResource;

class LifeEventsController extends Controller
{
/**
* Get the list of life event categories.
*
* @param Request $request
* @return Collection
*/
public function categories(Request $request)
{
$lifeEventCategories = auth()->user()->account->lifeEventCategories;

return LifeEventCategoryResource::collection($lifeEventCategories);
}

/**
* Get the list of life event types for a given life event category.
* @param Request $request
* @param int $LifeEventCategoryId
* @return Collection
*/
public function types(Request $request, int $lifeEventCategoryId)
{
$lifeEventCategory = LifeEventCategory::findOrFail($lifeEventCategoryId);
$lifeEventTypes = $lifeEventCategory->lifeEventTypes;

return LifeEventTypeResource::collection($lifeEventTypes);
}

/**
* Display the list of life events.
*
* @param Contact $contact
* @return \Illuminate\Http\Response
*/
public function index(Request $request, Contact $contact)
{
$lifeEventsCollection = collect([]);
$lifeEvents = $contact->lifeEvents()->get();

foreach ($lifeEvents as $lifeEvent) {
$data = [
'id' => $lifeEvent->id,
'life_event_type' => $lifeEvent->lifeEventType->name,
'default_life_event_type_key' => $lifeEvent->lifeEventType->default_life_event_type_key,
'name' => $lifeEvent->name,
'note' => $lifeEvent->note,
'happened_at' => DateHelper::getShortDate($lifeEvent->happened_at),
];
$lifeEventsCollection->push($data);
}

return $lifeEventsCollection;
}

/**
* Store the life event.
*
* @param Request $request
* @param Contact $contact
* @return \Illuminate\Http\Response
*/
public function store(Request $request, Contact $contact)
{
$data = [
'account_id' => auth()->user()->account->id,
'contact_id' => $contact->id,
'life_event_type_id' => $request->get('life_event_type_id'),
'happened_at' => $request->get('happened_at'),
'name' => $request->get('name'),
'note' => $request->get('note'),
];

// create the conversation
try {
$lifeEvent = (new CreateLifeEvent)->execute($data);
} catch (\Exception $e) {
return back()
->withInput()
->withErrors(trans('app.error_save'));
}

return $lifeEvent;
}

/**
* Destroy the life event.
* @param Request $request
* @param Contact $contat
* @param LifeEvent $lifeEvent
* @return bool
*/
public function destroy(Request $request, Contact $contat, $lifeEventId)
{
$data = [
'account_id' => auth()->user()->account->id,
'life_event_id' => $lifeEventId,
];

try {
(new DestroyLifeEvent)->execute($data);
} catch (\Exception $e) {
return back()
->withInput()
->withErrors(trans('app.error_save'));
}

return 'done';
}
}
18 changes: 17 additions & 1 deletion app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,30 @@ public function show(Contact $contact)
// list of active features
$modules = $contact->account->modules()->active()->get();

// add `---` at the top of the dropdowns
$days = DateHelper::getListOfDays();
$days->prepend([
'id' => 0,
'name' => '---',
]);

$months = DateHelper::getListOfMonths();
$months->prepend([
'id' => 0,
'name' => '---',
]);

return view('people.profile')
->withLoveRelationships($loveRelationships)
->withFamilyRelationships($familyRelationships)
->withFriendRelationships($friendRelationships)
->withWorkRelationships($workRelationships)
->withReminders($reminders)
->withModules($modules)
->withContact($contact);
->withContact($contact)
->withDays($days)
->withMonths($months)
->withYears(DateHelper::getListOfYears());
}

/**
Expand Down
Loading