mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-08-29 11:00:40 +08:00
Add Record List Modal to relate fields
- Add select record button -- Add button styling -- Display button next to chip component - Open record list modal on button click -- Open xlarge and scrollable modal -- Add styling to correctly display scroll - Add jasmine / karma tests
This commit is contained in:
parent
d609bf2c2e
commit
ba49c5a82e
6 changed files with 85 additions and 25 deletions
|
@ -1,23 +1,31 @@
|
||||||
<tag-input #tag
|
<div class="d-flex">
|
||||||
(onAdd)="onAdd($event)"
|
<div class="flex-grow-1">
|
||||||
(onBlur)="resetStatus()"
|
<tag-input #tag
|
||||||
(onRemove)="onRemove()"
|
(onAdd)="onAdd($event)"
|
||||||
[(ngModel)]="selectedValues"
|
(onBlur)="resetStatus()"
|
||||||
[class]="getInvalidClass()"
|
(onRemove)="onRemove()"
|
||||||
[clearOnBlur]="true"
|
[(ngModel)]="selectedValues"
|
||||||
[displayBy]="getRelateFieldName()"
|
[class]="getInvalidClass()"
|
||||||
[inputClass]="getInvalidClass()"
|
[clearOnBlur]="true"
|
||||||
[onTextChangeDebounce]="500"
|
[displayBy]="getRelateFieldName()"
|
||||||
[onlyFromAutocomplete]="true"
|
[inputClass]="getInvalidClass()"
|
||||||
[placeholder]="getPlaceholderLabel()"
|
[onTextChangeDebounce]="500"
|
||||||
[secondaryPlaceholder]="getPlaceholderLabel()"
|
[onlyFromAutocomplete]="true"
|
||||||
maxItems="1">
|
[placeholder]="getPlaceholderLabel()"
|
||||||
<tag-input-dropdown [autocompleteObservable]="search"
|
[secondaryPlaceholder]="getPlaceholderLabel()"
|
||||||
[displayBy]="getRelateFieldName()"
|
maxItems="1">
|
||||||
[keepOpen]="false"
|
<tag-input-dropdown [autocompleteObservable]="search"
|
||||||
[showDropdownIfEmpty]="true">
|
[displayBy]="getRelateFieldName()"
|
||||||
</tag-input-dropdown>
|
[keepOpen]="false"
|
||||||
</tag-input>
|
[showDropdownIfEmpty]="true">
|
||||||
|
</tag-input-dropdown>
|
||||||
|
</tag-input>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<scrm-button [config]="selectButton">
|
||||||
|
</scrm-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<small *ngIf="getMessage()" class="text-danger form-text text-muted">
|
<small *ngIf="getMessage()" class="text-danger form-text text-muted">
|
||||||
<scrm-label [labelKey]="getMessage()" [module]="module"></scrm-label>
|
<scrm-label [labelKey]="getMessage()" [module]="module"></scrm-label>
|
||||||
</small>
|
</small>
|
||||||
|
|
|
@ -23,6 +23,7 @@ import {RelateEditFieldModule} from '@fields/relate/templates/edit/relate.module
|
||||||
import {ModuleNameMapper} from '@services/navigation/module-name-mapper/module-name-mapper.service';
|
import {ModuleNameMapper} from '@services/navigation/module-name-mapper/module-name-mapper.service';
|
||||||
import {moduleNameMapperMock} from '@services/navigation/module-name-mapper/module-name-mapper.service.spec.mock';
|
import {moduleNameMapperMock} from '@services/navigation/module-name-mapper/module-name-mapper.service.spec.mock';
|
||||||
import {waitUntil} from '@app-common/testing/utils.spec';
|
import {waitUntil} from '@app-common/testing/utils.spec';
|
||||||
|
import {RecordListModalModule} from '@containers/record-list-modal/components/record-list-modal/record-list-modal.module';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'relate-edit-field-test-host-component',
|
selector: 'relate-edit-field-test-host-component',
|
||||||
|
@ -37,7 +38,7 @@ class RelateEditFieldTestHostComponent {
|
||||||
name: 'Related Account',
|
name: 'Related Account',
|
||||||
},
|
},
|
||||||
definition: {
|
definition: {
|
||||||
module: 'accounts',
|
module: 'Accounts',
|
||||||
// eslint-disable-next-line camelcase, @typescript-eslint/camelcase
|
// eslint-disable-next-line camelcase, @typescript-eslint/camelcase
|
||||||
id_name: 'account_id',
|
id_name: 'account_id',
|
||||||
rname: 'name'
|
rname: 'name'
|
||||||
|
@ -67,7 +68,8 @@ describe('RelateRecordEditFieldComponent', () => {
|
||||||
RouterTestingModule,
|
RouterTestingModule,
|
||||||
RelateEditFieldModule,
|
RelateEditFieldModule,
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
NoopAnimationsModule
|
NoopAnimationsModule,
|
||||||
|
RecordListModalModule
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: UserPreferenceStore, useValue: userPreferenceStoreMock},
|
{provide: UserPreferenceStore, useValue: userPreferenceStoreMock},
|
||||||
|
@ -163,4 +165,21 @@ describe('RelateRecordEditFieldComponent', () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should have select button', async (done) => {
|
||||||
|
expect(testHostComponent).toBeTruthy();
|
||||||
|
|
||||||
|
testHostFixture.detectChanges();
|
||||||
|
|
||||||
|
await testHostFixture.whenRenderingDone();
|
||||||
|
|
||||||
|
const field = testHostFixture.nativeElement.getElementsByTagName('scrm-relate-edit')[0];
|
||||||
|
|
||||||
|
const select = field.getElementsByClassName('select-button').item(0);
|
||||||
|
|
||||||
|
expect(select).toBeTruthy();
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,9 @@ import {TagInputComponent} from 'ngx-chips';
|
||||||
import {RelateService} from '@services/record/relate/relate.service';
|
import {RelateService} from '@services/record/relate/relate.service';
|
||||||
import {BaseRelateComponent} from '@fields/base/base-relate.component';
|
import {BaseRelateComponent} from '@fields/base/base-relate.component';
|
||||||
import {ModuleNameMapper} from '@services/navigation/module-name-mapper/module-name-mapper.service';
|
import {ModuleNameMapper} from '@services/navigation/module-name-mapper/module-name-mapper.service';
|
||||||
|
import {ButtonInterface} from '@app-common/components/button/button.model';
|
||||||
|
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import {RecordListModalComponent} from '@containers/record-list-modal/components/record-list-modal/record-list-modal.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'scrm-relate-edit',
|
selector: 'scrm-relate-edit',
|
||||||
|
@ -14,14 +17,24 @@ import {ModuleNameMapper} from '@services/navigation/module-name-mapper/module-n
|
||||||
})
|
})
|
||||||
export class RelateEditFieldComponent extends BaseRelateComponent {
|
export class RelateEditFieldComponent extends BaseRelateComponent {
|
||||||
@ViewChild('tag') tag: TagInputComponent;
|
@ViewChild('tag') tag: TagInputComponent;
|
||||||
|
selectButton: ButtonInterface;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected languages: LanguageStore,
|
protected languages: LanguageStore,
|
||||||
protected typeFormatter: DataTypeFormatter,
|
protected typeFormatter: DataTypeFormatter,
|
||||||
protected relateService: RelateService,
|
protected relateService: RelateService,
|
||||||
protected moduleNameMapper: ModuleNameMapper
|
protected moduleNameMapper: ModuleNameMapper,
|
||||||
|
protected modalService: NgbModal
|
||||||
) {
|
) {
|
||||||
super(languages, typeFormatter, relateService, moduleNameMapper);
|
super(languages, typeFormatter, relateService, moduleNameMapper);
|
||||||
|
|
||||||
|
this.selectButton = {
|
||||||
|
klass: ['btn', 'btn-sm', 'btn-outline-secondary', 'select-button'],
|
||||||
|
onClick: (): void => {
|
||||||
|
this.showSelectModal();
|
||||||
|
},
|
||||||
|
icon: 'cursor'
|
||||||
|
} as ButtonInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
@ -58,4 +71,10 @@ export class RelateEditFieldComponent extends BaseRelateComponent {
|
||||||
this.field.formControl.setValue(relateValue);
|
this.field.formControl.setValue(relateValue);
|
||||||
this.field.formControl.markAsDirty();
|
this.field.formControl.markAsDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected showSelectModal(): void {
|
||||||
|
const modal = this.modalService.open(RecordListModalComponent, {size: 'xl', scrollable: true});
|
||||||
|
|
||||||
|
modal.componentInstance.module = this.getRelatedModule();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {TagInputModule} from 'ngx-chips';
|
||||||
import {LabelModule} from '@components/label/label.module';
|
import {LabelModule} from '@components/label/label.module';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {InlineLoadingSpinnerModule} from '@components/inline-loading-spinner/inline-loading-spinner.module';
|
import {InlineLoadingSpinnerModule} from '@components/inline-loading-spinner/inline-loading-spinner.module';
|
||||||
|
import {ButtonModule} from '@components/button/button.module';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [RelateEditFieldComponent],
|
declarations: [RelateEditFieldComponent],
|
||||||
|
@ -16,7 +17,8 @@ import {InlineLoadingSpinnerModule} from '@components/inline-loading-spinner/inl
|
||||||
TagInputModule,
|
TagInputModule,
|
||||||
LabelModule,
|
LabelModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
InlineLoadingSpinnerModule
|
InlineLoadingSpinnerModule,
|
||||||
|
ButtonModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class RelateEditFieldModule {
|
export class RelateEditFieldModule {
|
||||||
|
|
|
@ -345,3 +345,11 @@ button.settings-button.dropdown-toggle::after {
|
||||||
.minimise-button:hover {
|
.minimise-button:hover {
|
||||||
fill: $midnight-grey;
|
fill: $midnight-grey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.select-button {
|
||||||
|
fill: $secondary;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-button:hover {
|
||||||
|
fill: $white;
|
||||||
|
}
|
||||||
|
|
|
@ -128,6 +128,10 @@
|
||||||
background: $dusty-grey;
|
background: $dusty-grey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.modal-dialog-scrollable .modal-body {
|
||||||
|
max-height: calc(100vh - 6.5rem);
|
||||||
|
}
|
||||||
|
|
||||||
/* modal animation */
|
/* modal animation */
|
||||||
.modal-content {
|
.modal-content {
|
||||||
animation-name: modal;
|
animation-name: modal;
|
||||||
|
@ -145,4 +149,4 @@
|
||||||
|
|
||||||
.modal-footer {
|
.modal-footer {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue