Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
89bfd2b
composer update
djaiss Mar 4, 2018
2692ec5
wip
djaiss Mar 4, 2018
5aa5143
wip
djaiss Mar 4, 2018
c0a3215
wip
djaiss Mar 5, 2018
f2d6ac8
wip
djaiss Mar 14, 2018
e28d17b
wip
djaiss Mar 15, 2018
1d05bb2
wip
djaiss Mar 16, 2018
ea24eff
wip
djaiss Mar 16, 2018
8feb259
merge master
djaiss Mar 16, 2018
63b2c78
wip
djaiss Mar 17, 2018
a616fea
wip
djaiss Mar 18, 2018
e9658ef
wip
djaiss Mar 18, 2018
4a772a9
wip
djaiss Mar 19, 2018
3480bb3
wip
djaiss Mar 20, 2018
3cb1e73
wip
djaiss Mar 20, 2018
cc9b3fa
wip
djaiss Mar 21, 2018
a167d84
Merge branch 'replace-relationships' of github.com:monicahq/monica in…
djaiss Mar 22, 2018
e6d6a85
wip
djaiss Mar 22, 2018
1f03697
far from being over... depressing
djaiss Mar 22, 2018
7fb1f20
fix stupid mistake I made while freaking tired
djaiss Mar 22, 2018
4ade29d
wip
djaiss Mar 23, 2018
dd7622b
wip
djaiss Mar 23, 2018
99f8f3a
Add better design for displaying a relationship
djaiss Mar 24, 2018
4cf1c10
wip
djaiss Mar 25, 2018
15bc1dd
tests
djaiss Mar 25, 2018
91a6501
final test
djaiss Mar 25, 2018
941f5ee
api
djaiss Mar 26, 2018
1671a86
wip
djaiss Mar 26, 2018
f9d4595
merge master
djaiss Mar 26, 2018
55aae4b
styleci
djaiss Mar 26, 2018
a2edbeb
styleci
djaiss Mar 26, 2018
0b128cc
bump files
djaiss Mar 26, 2018
beb7ecc
tests
djaiss Mar 27, 2018
f855158
merge master
djaiss Mar 27, 2018
a405ea3
fix styleci
djaiss Mar 27, 2018
7f5b09b
wip api
djaiss Mar 28, 2018
eae3fb1
wip api
djaiss Mar 28, 2018
82da42a
wip
djaiss Mar 30, 2018
c558111
wip
djaiss Mar 30, 2018
5f8a665
wip
djaiss Mar 30, 2018
f5e899a
wip
djaiss Mar 30, 2018
2727011
wip
djaiss Mar 30, 2018
bf0dd02
fix tests
djaiss Mar 30, 2018
91ec824
styleci
djaiss Mar 30, 2018
1c63734
merge master
djaiss Mar 31, 2018
1ad5764
fix bug
djaiss Mar 31, 2018
d7ffd47
fix test
djaiss Mar 31, 2018
b9ee161
remove useless test
djaiss Apr 1, 2018
df2e51a
Merge branch 'master' into replace-relationships
djaiss Apr 1, 2018
d0d5441
optimization
djaiss Apr 1, 2018
66b1965
Merge branch 'master' into replace-relationships
djaiss Apr 1, 2018
e7a7087
fix stuff
djaiss Apr 1, 2018
35020f1
Merge branch 'replace-relationships' of github.com:monicahq/monica in…
djaiss Apr 1, 2018
afaae90
fix dashboard
djaiss Apr 2, 2018
4e49981
merge mastr
djaiss Apr 2, 2018
916107c
styleci
djaiss Apr 2, 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
Prev Previous commit
Next Next commit
tests
  • Loading branch information
djaiss committed Mar 25, 2018
commit 15bc1dd43a522beee93ec45ed01cd37a1349cd91
54 changes: 35 additions & 19 deletions app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DB;
use Carbon\Carbon;
use App\RelationshipType;
use Laravel\Cashier\Billable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand Down Expand Up @@ -458,12 +459,12 @@ public function timezone()
* Populates the Contact Field Types table right after an account is
* created.
*/
public function populateContactFieldTypeTable($ignoreMigratedTable = false)
public function populateContactFieldTypeTable($ignoreTableAlreadyMigrated = false)
{
$defaultContactFieldTypes = DB::table('default_contact_field_types')->get();

foreach ($defaultContactFieldTypes as $defaultContactFieldType) {
if (! $ignoreMigratedTable || $defaultContactFieldType->migrated == 0) {
if (! $ignoreTableAlreadyMigrated || $defaultContactFieldType->migrated == 0) {
ContactFieldType::create([
'account_id' => $this->id,
'name' => $defaultContactFieldType->name,
Expand Down Expand Up @@ -504,32 +505,46 @@ public function populateDefaultReminderRulesTable()
*
* @return void
*/
public function populateRelationshipTypesTable($ignoreMigratedTable = false)
public function populateRelationshipTypeGroupsTable($ignoreTableAlreadyMigrated = false)
{
$defaultRelationshipTypeGroups = DB::table('default_relationship_type_groups')->get();
foreach ($defaultRelationshipTypeGroups as $defaultRelationshipTypeGroup) {
if (! $ignoreMigratedTable || $defaultRelationshipTypeGroups->migrated == 0) {
if (! $ignoreTableAlreadyMigrated || $defaultRelationshipTypeGroup->migrated == 0) {
$id = DB::table('relationship_type_groups')->insertGetId([
'account_id' => $this->id,
'name' => $defaultRelationshipTypeGroup->name,
'delible' => $defaultRelationshipTypeGroup->delible,
]);
}
}
}

/**
* Populate the relationship types table based on the default ones.
*
* @param bool $ignoreTableAlreadyMigrated
* @return void
*/
public function populateRelationshipTypesTable($ignoreTableAlreadyMigrated = false)
{
$defaultRelationshipTypes = DB::table('default_relationship_types')->get();

foreach ($defaultRelationshipTypes as $defaultRelationshipType) {

if (! $ignoreTableAlreadyMigrated || $defaultRelationshipType->migrated == 0) {
$defaultRelationshipTypeGroup = DB::table('default_relationship_type_groups')
->where('id', $defaultRelationshipType->relationship_type_group_id)
->first();

$defaultRelationshipTypes = DB::table('default_relationship_types')
->where('relationship_type_group_id', $defaultRelationshipTypeGroup->id)
->get();

foreach ($defaultRelationshipTypes as $defaultRelationshipType) {
if (! $ignoreMigratedTable || $defaultRelationshipType->migrated == 0) {
RelationshipType::create([
'account_id' => $this->id,
'name' => $defaultRelationshipType->name,
'name_reverse_relationship' => $defaultRelationshipType->name_reverse_relationship,
'relationship_type_group_id' => $id,
'delible' => $defaultRelationshipType->delible,
]);
}
}
$relationshipTypeGroup = $this->getRelationshipTypeGroupByType($defaultRelationshipTypeGroup->name);

RelationshipType::create([
'account_id' => $this->id,
'name' => $defaultRelationshipType->name,
'name_reverse_relationship' => $defaultRelationshipType->name_reverse_relationship,
'relationship_type_group_id' => $relationshipTypeGroup->id,
'delible' => $defaultRelationshipType->delible,
]);
}
}
}
Expand Down Expand Up @@ -637,6 +652,7 @@ public static function populateDefaultFields($account)
$account->populateContactFieldTypeTable();
$account->populateDefaultGendersTable();
$account->populateDefaultReminderRulesTable();
$account->populateRelationshipTypeGroupsTable();
$account->populateRelationshipTypesTable();
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Contacts/RelationshipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function edit(Contact $contact, Contact $otherContact)
foreach (auth()->user()->account->relationshipTypes as $relationshipType) {
$arrayRelationshipTypes->push([
'id' => $relationshipType->id,
'name' => $relationshipType->getLocalizedName(),
'name' => $relationshipType->getLocalizedName($contact, true),
]);
}

Expand Down
16 changes: 7 additions & 9 deletions app/RelationshipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ public function relationshipTypeGroup()
*
* @return string
*/
public function getLocalizedName(Contact $contact = null, bool $includeReverse = false, string $gender = 'man')
public function getLocalizedName(Contact $contact = null, bool $includeOpposite = false, string $gender = 'man')
{
// include the reverse of the relation in the string (masculine/feminine)
if (! is_null($contact) && $includeReverse) {
// this is used in the dropdown of the relationship types when creating
// or deleting a relationship.
if (! is_null($contact) && $includeOpposite) {
// in some language, masculine and feminine version of a relationship type is the same.
// we need to keep just one version in that case.
$femaleVersion = trans('app.relationship_type_'.$this->name.'_female');
Expand All @@ -63,7 +65,7 @@ public function getLocalizedName(Contact $contact = null, bool $includeReverse =
return trans('app.relationship_type_'.$this->name.'_with_name', ["name" => $contact->getCompleteName()]);
}

// `Regis Freyd's uncle/aunt`
// otherwise `Regis Freyd's uncle/aunt`
return trans(
'app.relationship_type_'.$this->name.'_with_name',
["name" => $contact->getCompleteName()]
Expand All @@ -79,16 +81,12 @@ public function getLocalizedName(Contact $contact = null, bool $includeReverse =
return trans('app.relationship_type_'.$this->name.'_with_name', ["name" => $contact->getCompleteName()]);
}

// `uncle`
// `aunt`
if (strtolower($gender) == 'woman') {
return trans('app.relationship_type_'.$this->name.'_female');
}

// `uncle`
return trans('app.relationship_type_'.$this->name);
}

public function getReverse()
{
return $this->account->getRelationshipTypeByType($this->name);
}
}
6 changes: 6 additions & 0 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
];
});

$factory->define(App\RelationshipTypeGroup::class, function (Faker\Generator $faker) {
return [
'account_id' => 1,
];
});

$factory->define(App\Offspring::class, function (Faker\Generator $faker) {
return [
'account_id' => 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function up()
{
Account::chunk(200, function ($accounts) {
foreach ($accounts as $account) {
$account->populateRelationshipTypeGroupsTable();
$account->populateRelationshipTypesTable();
}
});
Expand Down
8 changes: 4 additions & 4 deletions database/migrations/2018_03_24_083258_migrate_offsprings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public function up()
DB::table('relationships')->insert([
[
'account_id' => $account->id,
'contact_id_main' => $offspring->contact_id,
'contact_id_secondary' => $offspring->is_the_child_of,
'contact_id_main' => $offspring->is_the_child_of,
'contact_id_secondary' => $offspring->contact_id,
'relationship_type_id' => $relationshipChildTypeId,
'relationship_type_name' => 'child',
],
[
'account_id' => $account->id,
'contact_id_main' => $offspring->is_the_child_of,
'contact_id_secondary' => $offspring->contact_id,
'contact_id_main' => $offspring->contact_id,
'contact_id_secondary' => $offspring->is_the_child_of,
'relationship_type_id' => $relationshipParentTypeId,
'relationship_type_name' => 'parent',
]
Expand Down
5 changes: 1 addition & 4 deletions resources/lang/en/people.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@

// relationships
'relationship_form_add' => 'Add a new relationship',
'relationship_form_edit' => 'Edit an existing relationship',
'relationship_form_is_with' => 'This person is...',
'relationship_form_add_choice' => 'Who is the relationship with?',
'relationship_form_create_contact' => 'Add a new person',
Expand All @@ -160,10 +161,6 @@
'relationship_delete_confirmation' => 'Are you sure you want to delete this relationship? Deletion is permanent.',
'relationship_unlink_confirmation' => 'Are you sure you want to delete this relationship? This person will not be deleted - only the relationship between the two.',

// significant other
'significant_other_sidebar_title' => 'Significant other',
'significant_other_cta' => 'Add significant other',

// tasks
'tasks_blank_title' => 'You don\'t have any tasks yet.',
'tasks_form_title' => 'Title',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@foreach ($relationships as $relationship)
<div>
<div class="sidebar-box-paragraph">
<span class="silver fw3 ba br2 ph1">{{ $relationship->relationshipType->getLocalizedName(null, false, $relationship->withContact->gender->name) }}</span>

{{-- NAME --}}
Expand Down
89 changes: 73 additions & 16 deletions tests/Unit/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Unit;

use DB;
use App\User;
use App\Account;
use App\Reminder;
Expand Down Expand Up @@ -430,22 +431,6 @@ public function test_it_populates_the_account_with_the_right_default_reminder_ru
);
}

public function test_it_populates_the_account_with_the_right_default_relationship_types()
{
$account = factory(Account::class)->create([]);
$account->populateDefaultRelationshipTypesTable();

$this->assertEquals(
1,
$account->relationshipTypes->count()
);

$this->assertDatabaseHas(
'relationship_types',
['name' => 'partner']
);
}

public function test_it_gets_the_relationship_type_object_matching_a_given_name()
{
$account = factory('App\Account')->create([]);
Expand All @@ -467,4 +452,76 @@ public function test_it_gets_the_relationship_type_group_object_matching_a_given

$this->assertInstanceOf('App\RelationshipTypeGroup', $account->getRelationshipTypeGroupByType('love'));
}

public function test_it_populates_default_relationship_type_groups_table_if_tables_havent_been_migrated_yet()
{
$account = factory('App\Account')->create([]);

// Love type
$id = DB::table('default_relationship_type_groups')->insertGetId([
'name' => 'friend_and_family',
]);

$account->populateRelationshipTypeGroupsTable();

$this->assertDatabaseHas('relationship_type_groups', [
'name' => 'friend_and_family',
]);
}

public function test_it_skips_default_relationship_type_groups_table_for_types_already_migrated()
{
$account = factory('App\Account')->create([]);
$id = DB::table('default_relationship_type_groups')->insertGetId([
'name' => 'friend_and_family',
'migrated' => 1,
]);

$account->populateRelationshipTypeGroupsTable(true);

$this->assertDatabaseMissing('relationship_type_groups', [
'name' => 'friend_and_family',
]);
}

public function test_it_populates_default_relationship_types_table_if_tables_havent_been_migrated_yet()
{
$account = factory('App\Account')->create([]);
$id = DB::table('default_relationship_type_groups')->insertGetId([
'name' => 'friend_and_family',
]);

DB::table('default_relationship_types')->insert([
'name' => 'fuckfriend',
'relationship_type_group_id' => $id,
]);

$account->populateRelationshipTypeGroupsTable();
$account->populateRelationshipTypesTable();

$this->assertDatabaseHas('relationship_types', [
'name' => 'fuckfriend',
]);
}

public function test_it_skips_default_relationship_types_table_for_types_already_migrated()
{
$account = factory('App\Account')->create([]);
$id = DB::table('default_relationship_type_groups')->insertGetId([
'name' => 'friend_and_family',
]);

DB::table('default_relationship_types')->insert([
'name' => 'fuckfriend',
'relationship_type_group_id' => $id,
'migrated' => 1,
]);

$account->populateRelationshipTypeGroupsTable();
$account->populateRelationshipTypesTable(true);

$this->assertDatabaseMissing('relationship_types', [
'name' => 'fuckfriend',
]);
}
}
Loading