From 6ed25b7bae3c7a5c6562ab2ca52dd47bf292eb6e Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Thu, 5 Dec 2019 12:17:44 +0100 Subject: [PATCH] FEAT #12510 TIME 2 contactGroupList with new contacts --- .../indexing_searching/details.php | 2 + migration/19.12/1912-postScript.sql | 2 +- phpunit.xml | 1 - rest/index.php | 2 +- sql/delete_all_ressources.sql | 14 --- sql/index_creation.sql | 9 +- sql/reinit_sequences.sql | 5 +- .../controllers/ContactGroupController.php | 88 ++++--------------- .../models/ContactGroupModelAbstract.php | 16 ++-- .../controllers/AutoCompleteController.php | 19 ++-- ...ntacts-group-administration.component.html | 16 +--- ...contacts-group-administration.component.ts | 27 ++---- src/frontend/app/profile.component.html | 23 ++--- src/frontend/app/profile.component.ts | 24 ++--- .../app/contact/ContactTypeControllerTest.php | 27 ------ 15 files changed, 63 insertions(+), 212 deletions(-) delete mode 100755 test/unitTests/app/contact/ContactTypeControllerTest.php diff --git a/apps/maarch_entreprise/indexing_searching/details.php b/apps/maarch_entreprise/indexing_searching/details.php index 9f63f3b868d..83cb0de2b96 100755 --- a/apps/maarch_entreprise/indexing_searching/details.php +++ b/apps/maarch_entreprise/indexing_searching/details.php @@ -663,6 +663,8 @@ if ($stmt->rowCount() == 0) { $_SESSION['adresses']['addressid'] = array(); $_SESSION['adresses']['contactid'] = array(); + $path_to_script = ''; // removed + if (empty($disabledAttr)) { echo "<div id='input_multi_contact_add' style=''>"; echo "<input type='text' placeholder='"._CONTACTS_USERS_SEARCH."' name='{$key}' id='{$key}' value='' title='' alt='' size='40' style='width:140px;'/>"; diff --git a/migration/19.12/1912-postScript.sql b/migration/19.12/1912-postScript.sql index eff13d1a4cf..a9344037d5f 100644 --- a/migration/19.12/1912-postScript.sql +++ b/migration/19.12/1912-postScript.sql @@ -22,7 +22,7 @@ DROP TABLE IF EXISTS contacts_v2; ALTER TABLE acknowledgement_receipts ALTER COLUMN contact_id set not null; ALTER TABLE acknowledgement_receipts DROP COLUMN IF EXISTS contact_address_id; ALTER TABLE contacts_groups_lists ALTER COLUMN contact_id set not null; -ALTER TABLE contacts_groups_lists DROP COLUMN IF EXISTS contact_address_id; +ALTER TABLE contacts_groups_lists DROP COLUMN IF EXISTS contact_addresses_id; ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_contact_id; ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_address_id; ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_user; diff --git a/phpunit.xml b/phpunit.xml index 86d93eb907b..7ed7690e603 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,7 +11,6 @@ <file>test/unitTests/app/basket/BasketControllerTest.php</file> <file>test/unitTests/app/contact/ContactControllerTest.php</file> <file>test/unitTests/app/contact/ContactGroupControllerTest.php</file> - <file>test/unitTests/app/contact/ContactTypeControllerTest.php</file> <file>test/unitTests/app/customField/CustomFieldControllerTest.php</file> <file>test/unitTests/core/CoreControllerTest.php</file> <file>test/unitTests/app/docserver/DocserverControllerTest.php</file> diff --git a/rest/index.php b/rest/index.php index 87467b27865..763aac0e415 100755 --- a/rest/index.php +++ b/rest/index.php @@ -126,7 +126,7 @@ $app->get('/contactsGroups/{id}', \Contact\controllers\ContactGroupController::c $app->put('/contactsGroups/{id}', \Contact\controllers\ContactGroupController::class . ':update'); $app->delete('/contactsGroups/{id}', \Contact\controllers\ContactGroupController::class . ':delete'); $app->post('/contactsGroups/{id}/contacts', \Contact\controllers\ContactGroupController::class . ':addContacts'); -$app->delete('/contactsGroups/{id}/contacts/{addressId}', \Contact\controllers\ContactGroupController::class . ':deleteContact'); +$app->delete('/contactsGroups/{id}/contacts/{contactId}', \Contact\controllers\ContactGroupController::class . ':deleteContact'); $app->get('/contactsFilling', \Contact\controllers\ContactController::class . ':getFilling'); $app->put('/contactsFilling', \Contact\controllers\ContactController::class . ':updateFilling'); diff --git a/sql/delete_all_ressources.sql b/sql/delete_all_ressources.sql index fa72af7c557..1eb0abee27d 100755 --- a/sql/delete_all_ressources.sql +++ b/sql/delete_all_ressources.sql @@ -1,19 +1,5 @@ /* Warning : This script erase all data in the application Maarch. It keeps in database parameters */ -/*TRUNCATE TABLE contacts_v2; -ALTER SEQUENCE contact_v2_id_seq restart WITH 1; - -TRUNCATE TABLE contact_addresses; -ALTER SEQUENCE contact_addresses_id_seq restart WITH 1; - -TRUNCATE TABLE contact_types; -ALTER SEQUENCE contact_types_id_seq restart WITH 1; - -TRUNCATE TABLE contact_purposes; -ALTER SEQUENCE contact_purposes_id_seq restart WITH 1;*/ - -TRUNCATE TABLE contacts_res; - TRUNCATE TABLE listinstance; ALTER SEQUENCE listinstance_id_seq restart WITH 1; diff --git a/sql/index_creation.sql b/sql/index_creation.sql index 747ebfee4dc..edce9ca7dbc 100755 --- a/sql/index_creation.sql +++ b/sql/index_creation.sql @@ -26,9 +26,9 @@ CREATE INDEX item_mode_idx ON listinstance (item_mode); CREATE INDEX listinstance_difflist_type_idx ON listinstance (difflist_type); -- contacts -CREATE INDEX firstname_contacts_idx ON contacts_v2 (firstname); -CREATE INDEX lastname_contacts_idx ON contacts_v2 (lastname); -CREATE INDEX society_idx ON contacts_v2 (society); +CREATE INDEX firstname_idx ON contacts (firstname); +CREATE INDEX lastname_idx ON contacts (lastname); +CREATE INDEX company_idx ON contacts (society); -- doctypes_first_level CREATE INDEX doctypes_first_level_label_idx ON doctypes_first_level (doctypes_first_level_label); @@ -75,8 +75,5 @@ CREATE INDEX user_id_res_mark_as_read_idx ON res_mark_as_read (user_id); -- listmodels CREATE INDEX object_id_listmodels_idx ON listmodels (object_id); --- contact_addresses -CREATE INDEX contact_id_contact_addresses_idx ON contact_addresses (contact_id); - -- resource_contacts CREATE INDEX resource_contacts_res_id_idx ON resource_contacts (res_id); diff --git a/sql/reinit_sequences.sql b/sql/reinit_sequences.sql index c0660ddbbb7..e64c417d1bd 100755 --- a/sql/reinit_sequences.sql +++ b/sql/reinit_sequences.sql @@ -5,10 +5,7 @@ Select setval('user_signatures_seq', (select max(id)+1 from user_signatures), fa Select setval('templates_seq', (select max(template_id)+1 from templates), false); Select setval('groupbasket_redirect_system_id_seq', (select max(system_id)+1 from groupbasket_redirect), false); Select setval('actions_id_seq', (select max(id)+1 from actions), false); -Select setval('contact_addresses_id_seq', (select max(id)+1 from contact_addresses), false); -Select setval('contact_v2_id_seq', (select max(contact_id)+1 from contacts_v2), false); -Select setval('contact_purposes_id_seq', (select max(id)+1 from contact_purposes), false); -select setval('contact_types_id_seq', (select max(id)+1 from contact_types), false); +Select setval('contacts_id_seq', (select max(contact_id)+1 from contacts), false); select setval('doctypes_type_id_seq', (select max(type_id)+1 from doctypes), false); select setval('doctypes_first_level_id_seq', (select max(doctypes_first_level_id)+1 from doctypes_first_level), false); select setval('doctypes_second_level_id_seq', (select max(doctypes_second_level_id)+1 from doctypes_second_level), false); diff --git a/src/app/contact/controllers/ContactGroupController.php b/src/app/contact/controllers/ContactGroupController.php index f4b9d1e4bef..124057f1815 100755 --- a/src/app/contact/controllers/ContactGroupController.php +++ b/src/app/contact/controllers/ContactGroupController.php @@ -21,7 +21,7 @@ use History\controllers\HistoryController; use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; -use SrcCore\models\ValidatorModel; +use SrcCore\controllers\AutoCompleteController; use User\models\UserModel; class ContactGroupController @@ -200,15 +200,15 @@ class ContactGroupController return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } - $rawList = ContactGroupModel::getListById(['select' => ['contact_addresses_id'], 'id' => $aArgs['id']]); + $rawList = ContactGroupModel::getListById(['select' => ['contact_id'], 'id' => $aArgs['id']]); $list = []; foreach ($rawList as $rawListItem) { - $list[] = $rawListItem['contact_addresses_id']; + $list[] = $rawListItem['contact_id']; } - foreach ($data['contacts'] as $addressId) { - if (!in_array($addressId, $list)) { - ContactGroupModel::addContact(['id' => $aArgs['id'], 'addressId' => $addressId]); + foreach ($data['contacts'] as $contactId) { + if (!in_array($contactId, $list)) { + ContactGroupModel::addContact(['id' => $aArgs['id'], 'contactId' => $contactId]); } } @@ -240,7 +240,7 @@ class ContactGroupController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - ContactGroupModel::deleteContact(['id' => $aArgs['id'], 'addressId' => $aArgs['addressId']]); + ContactGroupModel::deleteContact(['id' => $aArgs['id'], 'contactId' => $aArgs['contactId']]); HistoryController::add([ 'tableName' => 'contacts_groups_lists', @@ -256,85 +256,27 @@ class ContactGroupController public static function getFormattedListById(array $aArgs) { - $list = ContactGroupModel::getListById(['select' => ['contact_addresses_id'], 'id' => $aArgs['id']]); + $list = ContactGroupModel::getListById(['select' => ['contact_id'], 'id' => $aArgs['id']]); $contacts = []; $position = 0; foreach ($list as $listItem) { - $contact = ContactModel::getOnView([ + $contact = ContactModel::get([ 'select' => [ - 'ca_id', 'firstname', 'lastname', 'contact_lastname', 'contact_firstname', 'society', 'address_num', - 'address_street', 'address_town', 'address_postal_code', 'is_corporate_person' + 'id', 'firstname', 'lastname', 'company', 'address_number', 'address_street', 'address_town', 'address_postcode' ], - 'where' => ['ca_id = ?'], - 'data' => [$listItem['contact_addresses_id']] + 'where' => ['id = ?'], + 'data' => [$listItem['contact_id']] ]); if (!empty($contact[0])) { - $contacts[] = ContactGroupController::getFormattedContact(['contact' => $contact[0], 'position' => $position])['contact']; + $contact = AutoCompleteController::getFormattedContactV2(['contact' => $contact[0], 'position' => $position])['contact']; + $contact['position'] = !empty($position) ? $position : 0; + $contacts[] = $contact; ++$position; } } return ['list' => $contacts]; } - - public static function getFormattedContact(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['contact']); - ValidatorModel::arrayType($aArgs, ['contact']); - ValidatorModel::intType($aArgs, ['position']); - - $address = ''; - if (empty($aArgs['position'])) { - $aArgs['position'] = 0; - } - if ($aArgs['contact']['is_corporate_person'] == 'Y') { - $address.= $aArgs['contact']['firstname']; - $address.= (empty($address) ? $aArgs['contact']['lastname'] : " {$aArgs['contact']['lastname']}"); - if (!empty($address)) { - $address.= ', '; - } - if (!empty($aArgs['contact']['address_num'])) { - $address.= $aArgs['contact']['address_num'] . ' '; - } - if (!empty($aArgs['contact']['address_street'])) { - $address.= $aArgs['contact']['address_street'] . ' '; - } - if (!empty($aArgs['contact']['address_town'])) { - $address.= $aArgs['contact']['address_town'] . ' '; - } - if (!empty($aArgs['contact']['address_postal_code'])) { - $address.= $aArgs['contact']['address_postal_code'] . ' '; - } - $contact = [ - 'position' => $aArgs['position'], - 'addressId' => $aArgs['contact']['ca_id'], - 'contact' => $aArgs['contact']['society'], - 'address' => $address - ]; - } else { - if (!empty($aArgs['contact']['address_num'])) { - $address.= $aArgs['contact']['address_num'] . ' '; - } - if (!empty($aArgs['contact']['address_street'])) { - $address.= $aArgs['contact']['address_street'] . ' '; - } - if (!empty($aArgs['contact']['address_town'])) { - $address.= $aArgs['contact']['address_town'] . ' '; - } - if (!empty($aArgs['contact']['address_postal_code'])) { - $address.= $aArgs['contact']['address_postal_code'] . ' '; - } - - $contact = [ - 'position' => $aArgs['position'], - 'addressId' => $aArgs['contact']['ca_id'], - 'contact' => "{$aArgs['contact']['contact_firstname']} {$aArgs['contact']['contact_lastname']} {$aArgs['contact']['society']}", - 'address' => $address - ]; - } - - return ['contact' => $contact]; - } } diff --git a/src/app/contact/models/ContactGroupModelAbstract.php b/src/app/contact/models/ContactGroupModelAbstract.php index a5d4d3a4684..5c36e243e21 100755 --- a/src/app/contact/models/ContactGroupModelAbstract.php +++ b/src/app/contact/models/ContactGroupModelAbstract.php @@ -128,14 +128,14 @@ abstract class ContactGroupModelAbstract public static function addContact(array $aArgs) { - ValidatorModel::notEmpty($aArgs, ['id', 'addressId']); - ValidatorModel::intVal($aArgs, ['id', 'addressId']); + ValidatorModel::notEmpty($aArgs, ['id', 'contactId']); + ValidatorModel::intVal($aArgs, ['id', 'contactId']); DatabaseModel::insert([ 'table' => 'contacts_groups_lists', 'columnsValues' => [ - 'contacts_groups_id' => $aArgs['id'], - 'contact_addresses_id' => $aArgs['addressId'] + 'contacts_groups_id' => $aArgs['id'], + 'contact_id' => $aArgs['contactId'] ] ]); @@ -144,13 +144,13 @@ abstract class ContactGroupModelAbstract public static function deleteContact(array $aArgs) { - ValidatorModel::notEmpty($aArgs, ['id', 'addressId']); - ValidatorModel::intVal($aArgs, ['id', 'addressId']); + ValidatorModel::notEmpty($aArgs, ['id', 'contactId']); + ValidatorModel::intVal($aArgs, ['id', 'contactId']); DatabaseModel::delete([ 'table' => 'contacts_groups_lists', - 'where' => ['contacts_groups_id = ?', 'contact_addresses_id = ?'], - 'data' => [$aArgs['id'], $aArgs['addressId']] + 'where' => ['contacts_groups_id = ?', 'contact_id = ?'], + 'data' => [$aArgs['id'], $aArgs['contactId']] ]); return true; diff --git a/src/core/controllers/AutoCompleteController.php b/src/core/controllers/AutoCompleteController.php index 1ce0d230a3e..ea7f29889ca 100755 --- a/src/core/controllers/AutoCompleteController.php +++ b/src/core/controllers/AutoCompleteController.php @@ -15,7 +15,6 @@ namespace SrcCore\controllers; use Contact\controllers\ContactController; -use Contact\controllers\ContactGroupController; use Contact\models\ContactModel; use Entity\models\EntityModel; use Respect\Validation\Validator; @@ -467,34 +466,28 @@ class AutoCompleteController $data = $request->getQueryParams(); $check = Validator::stringType()->notEmpty()->validate($data['search']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['type']); if (!$check) { return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } $searchItems = explode(' ', $data['search']); - $fields = '(contact_firstname ilike ? OR contact_lastname ilike ? OR firstname ilike ? OR lastname ilike ? OR society ilike ? - OR address_num ilike ? OR address_street ilike ? OR address_town ilike ? OR address_postal_code ilike ?)'; + $fields = '(firstname ilike ? OR lastname ilike ? OR company ilike ? + OR address_number ilike ? OR address_street ilike ? OR address_town ilike ? OR address_postcode ilike ?)'; $where = []; $requestData = []; - if ($data['type'] != 'all') { - $where = ['contact_type = ?']; - $requestData = [$data['type']]; - } foreach ($searchItems as $item) { if (strlen($item) >= 2) { $where[] = $fields; - for ($i = 0; $i < 9; $i++) { + for ($i = 0; $i < 7; $i++) { $requestData[] = "%{$item}%"; } } } - $contacts = ContactModel::getOnView([ + $contacts = ContactModel::get([ 'select' => [ - 'ca_id', 'firstname', 'lastname', 'contact_lastname', 'contact_firstname', 'society', 'address_num', - 'address_street', 'address_town', 'address_postal_code', 'is_corporate_person' + 'id', 'firstname', 'lastname', 'company', 'address_number', 'address_street', 'address_town', 'address_postcode' ], 'where' => $where, 'data' => $requestData, @@ -503,7 +496,7 @@ class AutoCompleteController $data = []; foreach ($contacts as $contact) { - $data[] = ContactGroupController::getFormattedContact(['contact' => $contact])['contact']; + $data[] = AutoCompleteController::getFormattedContactV2(['contact' => $contact])['contact']; } return $response->withJson($data); diff --git a/src/frontend/app/administration/contact/contacts-group-administration.component.html b/src/frontend/app/administration/contact/contacts-group-administration.component.html index f12e4bd8458..c74124ba424 100755 --- a/src/frontend/app/administration/contact/contacts-group-administration.component.html +++ b/src/frontend/app/administration/contact/contacts-group-administration.component.html @@ -44,16 +44,6 @@ </mat-tab> <mat-tab label="{{lang.addContacts}}" *ngIf="!creationMode"> <div class="row" style="margin:0px;"> - <div class="col-sm-4"> - <mat-form-field> - <mat-select [(ngModel)]="contactTypeSearch" placeholder="{{lang.chooseContactType}}" id="contactTypeSearch" name="contactTypeSearch"> - <mat-option value="all">{{lang.all}}</mat-option> - <mat-option *ngFor="let contactType of contactTypes" [value]="contactType.id"> - {{contactType.label}} - </mat-option> - </mat-select> - </mat-form-field> - </div> <div class="col-md-8" style="padding:5px;"> <mat-form-field hintLabel="3 caractères minium"> <span matPrefix> @@ -78,8 +68,8 @@ </mat-checkbox> </mat-header-cell> <mat-cell *matCellDef="let element" style="flex:1;"> - <mat-checkbox id="check_{{element.addressId}}" color="primary" (click)="$event.stopPropagation()" (change)="$event ? selection.toggle(element.addressId) : null" - [disabled]="isInGrp(element)" [checked]="selection.isSelected(element.addressId)"> + <mat-checkbox id="check_{{element.id}}" color="primary" (click)="$event.stopPropagation()" (change)="$event ? selection.toggle(element.id) : null" + [disabled]="isInGrp(element)" [checked]="selection.isSelected(element.id)"> </mat-checkbox> </mat-cell> </ng-container> @@ -92,7 +82,7 @@ <mat-cell *matCellDef="let element" style="flex:3;"> {{element.address}} </mat-cell> </ng-container> <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> - <mat-row *matRowDef="let element; columns: displayedColumns;" (click)="selectAddress(element.addressId);" [ngStyle]="{'opacity': !isInGrp(element) ? '' : '0.5'}" + <mat-row *matRowDef="let element; columns: displayedColumns;" (click)="selectContact(element.id);" [ngStyle]="{'opacity': !isInGrp(element) ? '' : '0.5'}" style="cursor: pointer;"></mat-row> </mat-table> <div class="form-group"> diff --git a/src/frontend/app/administration/contact/contacts-group-administration.component.ts b/src/frontend/app/administration/contact/contacts-group-administration.component.ts index 98a6ba38a6f..fe506ee01f6 100755 --- a/src/frontend/app/administration/contact/contacts-group-administration.component.ts +++ b/src/frontend/app/administration/contact/contacts-group-administration.component.ts @@ -28,11 +28,8 @@ export class ContactsGroupAdministrationComponent implements OnInit { creationMode: boolean; contactsGroup: any = {}; - contactTypes: any = {}; nbContact : number; - contactTypeSearch: string; - loading: boolean = false; initAutoCompleteContact = true; @@ -49,8 +46,8 @@ export class ContactsGroupAdministrationComponent implements OnInit { masterToggle(event: any) { if (event.checked) { this.dataSource.data.forEach((row: any) => { - if (!$j("#check_" + row.addressId + '-input').is(":disabled")) { - this.selection.select(row.addressId); + if (!$j("#check_" + row.id + '-input').is(":disabled")) { + this.selection.select(row.id); } }); } else { @@ -83,7 +80,7 @@ export class ContactsGroupAdministrationComponent implements OnInit { debounceTime(500), filter(value => value.length > 2), distinctUntilChanged(), - switchMap(data => this.http.get('../../rest/autocomplete/contacts/groups', { params: { "search": data, "type": this.contactTypeSearch } })) + switchMap(data => this.http.get('../../rest/autocomplete/contacts/groups', { params: { "search": data } })) ).subscribe((response: any) => { this.searchResult = response; this.dataSource = new MatTableDataSource(this.searchResult); @@ -94,7 +91,6 @@ export class ContactsGroupAdministrationComponent implements OnInit { ngOnInit(): void { this.loading = true; - this.contactTypeSearch = 'all'; this.route.params.subscribe(params => { if (typeof params['id'] == "undefined") { @@ -111,11 +107,6 @@ export class ContactsGroupAdministrationComponent implements OnInit { this.creationMode = false; - this.http.get('../../rest/contactsTypes') - .subscribe((data: any) => { - this.contactTypes = data.contactsTypes; - }); - this.http.get('../../rest/contactsGroups/' + params['id']) .subscribe((data: any) => { this.contactsGroup = data.contactsGroup; @@ -183,7 +174,7 @@ export class ContactsGroupAdministrationComponent implements OnInit { } removeContact(contact: any, row: any) { - this.http.delete("../../rest/contactsGroups/" + this.contactsGroup.id + "/contacts/" + contact['addressId']) + this.http.delete("../../rest/contactsGroups/" + this.contactsGroup.id + "/contacts/" + contact['id']) .subscribe(() => { var lastElement = this.contactsGroup.contacts.length - 1; this.contactsGroup.contacts[row] = this.contactsGroup.contacts[lastElement]; @@ -206,19 +197,19 @@ export class ContactsGroupAdministrationComponent implements OnInit { } } - isInGrp(address: any): boolean { + isInGrp(contact: any): boolean { let isInGrp = false; this.contactsGroup.contacts.forEach((row: any) => { - if (row.addressId == address.addressId) { + if (row.id == contact.id) { isInGrp = true; } }); return isInGrp; } - selectAddress(addressId:any) { - if (!$j("#check_" + addressId + '-input').is(":disabled")) { - this.selection.toggle(addressId); + selectContact(id:any) { + if (!$j("#check_" + id + '-input').is(":disabled")) { + this.selection.toggle(id); } } } diff --git a/src/frontend/app/profile.component.html b/src/frontend/app/profile.component.html index 78461384680..13afce9a26e 100755 --- a/src/frontend/app/profile.component.html +++ b/src/frontend/app/profile.component.html @@ -628,21 +628,8 @@ </mat-expansion-panel-header> <div id="contactsGroupFormAdd"> <div class="row" style="margin:0px;"> - <div class="col-sm-4"> - <mat-form-field> - <mat-select [(ngModel)]="contactTypeSearch" - placeholder="{{lang.chooseContactType}}" - id="contactTypeSearch" name="contactTypeSearch"> - <mat-option value="all">{{lang.all}}</mat-option> - <mat-option *ngFor="let contactType of contactTypes" - [value]="contactType.id"> - {{contactType.label}} - </mat-option> - </mat-select> - </mat-form-field> - </div> <div class="col-md-8" style="padding:5px;"> - <mat-form-field hintLabel="3 caractères minium"> + <mat-form-field hintLabel="3 caractères minimum"> <span matPrefix> <mat-icon class="fa fa-user-plus" color="primary"> </mat-icon> @@ -678,11 +665,11 @@ </mat-checkbox> </mat-header-cell> <mat-cell *matCellDef="let element" style="flex:1;"> - <mat-checkbox id="check_{{element.addressId}}" + <mat-checkbox id="check_{{element.id}}" color="primary" (click)="$event.stopPropagation()" - (change)="$event ? selection.toggle(element.addressId) : null" + (change)="$event ? selection.toggle(element.id) : null" [disabled]="isInGrp(element)" - [checked]="selection.isSelected(element.addressId)"> + [checked]="selection.isSelected(element.id)"> </mat-checkbox> </mat-cell> </ng-container> @@ -703,7 +690,7 @@ </mat-header-row> <mat-row *matRowDef="let element; columns: displayedColumnsContactsListAutocomplete;" - (click)="selectAddress(element.addressId);" + (click)="selectContact(element.id);" [ngStyle]="{'opacity': !isInGrp(element) ? '' : '0.5'}" style="cursor: pointer;"></mat-row> </mat-table> diff --git a/src/frontend/app/profile.component.ts b/src/frontend/app/profile.component.ts index 7e12f8cd47f..7ca25f67ce4 100755 --- a/src/frontend/app/profile.component.ts +++ b/src/frontend/app/profile.component.ts @@ -114,12 +114,10 @@ export class ProfileComponent implements OnInit { contactsGroup: any = { public: false }; //Group contacts List Autocomplete - contactTypeSearch: string = "all"; initAutoCompleteContact = true; searchTerm: FormControl = new FormControl(); searchResult: any = []; - contactTypes: string[] = []; displayedColumnsContactsListAutocomplete: string[] = ['select', 'contact', 'address']; dataSourceContactsListAutocomplete: any; @ViewChild('paginatorGroupsListAutocomplete', { static: false }) paginatorGroupsListAutocomplete: MatPaginator; @@ -127,8 +125,8 @@ export class ProfileComponent implements OnInit { masterToggle(event: any) { if (event.checked) { this.dataSourceContactsListAutocomplete.data.forEach((row: any) => { - if (!$j("#check_" + row.addressId + '-input').is(":disabled")) { - this.selection.select(row.addressId); + if (!$j("#check_" + row.id + '-input').is(":disabled")) { + this.selection.select(row.id); } }); } else { @@ -179,7 +177,7 @@ export class ProfileComponent implements OnInit { debounceTime(500), filter(value => value.length > 2), distinctUntilChanged(), - switchMap(data => this.http.get('../../rest/autocomplete/contacts/groups', { params: { "search": data, "type": this.contactTypeSearch } })) + switchMap(data => this.http.get('../../rest/autocomplete/contacts/groups', { params: { "search": data } })) ).subscribe((response: any) => { this.searchResult = response; this.dataSourceContactsListAutocomplete = new MatTableDataSource(this.searchResult); @@ -316,10 +314,6 @@ export class ProfileComponent implements OnInit { loadContactsGroup(contactsGroup: any) { this.contactsListMode = true; - this.http.get('../../rest/contactsTypes') - .subscribe((data: any) => { - this.contactTypes = data.contactsTypes; - }); this.http.get('../../rest/contactsGroups/' + contactsGroup.id) .subscribe((data: any) => { @@ -361,7 +355,7 @@ export class ProfileComponent implements OnInit { } removeContact(contact: any, row: any) { - this.http.delete("../../rest/contactsGroups/" + this.contactsGroup.id + "/contacts/" + contact['addressId']) + this.http.delete("../../rest/contactsGroups/" + this.contactsGroup.id + "/contacts/" + contact['id']) .subscribe(() => { var lastElement = this.contactsGroup.contacts.length - 1; this.contactsGroup.contacts[row] = this.contactsGroup.contacts[lastElement]; @@ -384,19 +378,19 @@ export class ProfileComponent implements OnInit { } } - isInGrp(address: any): boolean { + isInGrp(contact: any): boolean { let isInGrp = false; this.contactsGroup.contacts.forEach((row: any) => { - if (row.addressId == address.addressId) { + if (row.id == contact.id) { isInGrp = true; } }); return isInGrp; } - selectAddress(addressId: any) { - if (!$j("#check_" + addressId + '-input').is(":disabled")) { - this.selection.toggle(addressId); + selectContact(id: any) { + if (!$j("#check_" + id + '-input').is(":disabled")) { + this.selection.toggle(id); } } diff --git a/test/unitTests/app/contact/ContactTypeControllerTest.php b/test/unitTests/app/contact/ContactTypeControllerTest.php deleted file mode 100755 index ecc6ae981af..00000000000 --- a/test/unitTests/app/contact/ContactTypeControllerTest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * Copyright Maarch since 2008 under licence GPLv3. - * See LICENCE.txt file at the root folder for more details. - * This file is part of Maarch software. - * - */ - -use PHPUnit\Framework\TestCase; - -class ContactTypeControllerTest extends TestCase -{ - public function testGet() - { - $contactTypeController = new \Contact\controllers\ContactTypeController(); - - // GET - $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); - $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $contactTypeController->get($request, new \Slim\Http\Response()); - $responseBody = json_decode((string)$response->getBody()); - - $this->assertInternalType('array', $responseBody->contactsTypes); - $this->assertNotEmpty($responseBody->contactsTypes); - } -} -- GitLab