Skip to content

feat/AB#74292 People picker #1792

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

Open
wants to merge 35 commits into
base: 2.x.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
47dbb83
working as users
TaiKamilla Sep 4, 2023
128df74
working as people
TaiKamilla Sep 4, 2023
08a7cbc
Merge branch '2.1.x' into feat/AB#74292_ABC-Create-people-picker-ques…
NathanHGit Sep 6, 2023
b9e6263
merge beta
MwanPygmay Sep 26, 2023
8767a34
added support for people question in grids and summary cards, and rep…
MwanPygmay Sep 27, 2023
18ada65
Merge branch 'beta' into feat/AB#74292_ABC-Create-people-picker-quest…
TaiKamilla Oct 4, 2023
41ae038
clean up after beta merge
TaiKamilla Oct 4, 2023
e922878
new naming
TaiKamilla Oct 6, 2023
9a72c60
remove console.log
TaiKamilla Oct 6, 2023
bc4147e
It works
TaiKamilla Oct 9, 2023
8028c98
cleaner
TaiKamilla Oct 9, 2023
41bedaf
remove unnecessary queries
TaiKamilla Oct 9, 2023
9f2883a
Merge branch '2.x.x' into feat/AB#74292_ABC-Create-people-picker-ques…
NathanHGit Mar 20, 2024
ac20a54
feat: add people id and fix minor issues
NathanHGit Mar 20, 2024
8610c0c
feat: add people dropdown
NathanHGit Mar 22, 2024
f936fbd
feat: handle people filtering
NathanHGit Mar 25, 2024
57b7932
load people choices on grid update
NathanHGit Mar 27, 2024
ab46147
fix empty value and wrong column width
NathanHGit Mar 27, 2024
7274101
handle two-word search
NathanHGit Mar 29, 2024
bc3cf28
changed number of search char to be 2
MwanPygmay Apr 17, 2024
85a5e3f
Merge branch '2.x.x' into feat/AB#74292_ABC-Create-people-picker-ques…
AntoineRelief Apr 24, 2024
40816f2
add safeguard in widget service
AntoineRelief Apr 24, 2024
3044f78
add placeholder to people picker
AntoineRelief Apr 25, 2024
dfc388f
now fetching records ten by ten + start of single picker
MwanPygmay Apr 30, 2024
c780b7e
now support seeing details in grid
MwanPygmay May 2, 2024
2ddb3ed
renaming + add support in grids
MwanPygmay May 3, 2024
494c027
add support for summary cards and editor
MwanPygmay May 3, 2024
c9284de
improve a bit hasNextPage
MwanPygmay May 3, 2024
061ed6a
now loading waits for metaquery
MwanPygmay May 3, 2024
d103daa
add support for filter
MwanPygmay May 6, 2024
0e9bf5b
refactor
MwanPygmay May 17, 2024
8201aaf
Merge branch '2.x.x' into feat/AB#74292_ABC-Create-people-picker-ques…
AntoineRelief Jun 14, 2024
5f25625
disable meta data loading in summary card if not needed
AntoineRelief Jun 14, 2024
796f297
merge 2.x.x
MwanPygmay Jun 27, 2024
02401ea
add support for filters, add support in grids for singlepeople
MwanPygmay Jun 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@
</div>
</ng-template>

<!-- PEOPLE EDITOR -->
<ng-template #peopleEditor>
<div class="w-60">
<label>{{ 'common.value.one' | translate }}</label>
<shared-people-dropdown
[control]="$any(form.get('value'))"
[initialSelectionIDs]="form.get('value')?.value"
[multiselect]="field.multiSelect"
></shared-people-dropdown>
</div>
</ng-template>

<!-- DATE EDITOR -->
<ng-template #dateEditor>
<div uiFormFieldDirective [defaultMargin]="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export class FilterRowComponent
/** Reference to context editor template */
@ViewChild('contextEditor', { static: false })
contextEditor!: TemplateRef<any>;
/** Reference to people editor template */
@ViewChild('peopleEditor', { static: false })
peopleEditor!: TemplateRef<any>;
/** Current field */
public field?: any;
/** Template reference to the editor */
Expand Down Expand Up @@ -219,6 +222,10 @@ export class FilterRowComponent
this.editor = this.dateEditor;
break;
}
case 'people': {
this.editor = this.peopleEditor;
break;
}
default: {
this.editor = this.textEditor;
}
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/src/lib/components/filter/filter.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DateModule,
TooltipModule,
} from '@oort-front/ui';
import { PeopleDropdownComponent } from '../../survey/components/people-dropdown/people-dropdown.component';

/**
* Composite Filter module.
Expand All @@ -29,6 +30,7 @@ import {
DateModule,
FormWrapperModule,
TooltipModule,
PeopleDropdownComponent,
],
exports: [FilterComponent],
})
Expand Down
81 changes: 72 additions & 9 deletions libs/shared/src/lib/components/ui/core-grid/core-grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
} from '../../../models/record.model';
import { GridLayout } from './models/grid-layout.model';
import { GridActions, GridSettings } from './models/grid-settings.model';
import { get, isEqual, isNil } from 'lodash';
import { get, isArray, isEqual, isNil } from 'lodash';
import { GridService } from '../../../services/grid/grid.service';
import { TranslateService } from '@ngx-translate/core';
import { DatePipe } from '../../../pipes/date/date.pipe';
Expand All @@ -49,7 +49,7 @@ import { DateTranslateService } from '../../../services/date-translate/date-tran
import { ApplicationService } from '../../../services/application/application.service';
import { UnsubscribeComponent } from '../../utils/unsubscribe/unsubscribe.component';
import { debounceTime, filter, takeUntil } from 'rxjs/operators';
import { firstValueFrom, from, merge, Subject } from 'rxjs';
import { firstValueFrom, from, lastValueFrom, merge, Subject } from 'rxjs';
import { SnackbarService, UILayoutService } from '@oort-front/ui';
import { ConfirmService } from '../../../services/confirm/confirm.service';
import { ContextService } from '../../../services/context/context.service';
Expand Down Expand Up @@ -517,6 +517,7 @@ export class CoreGridComponent
}
}
}

this.getRecords();
},
error: (err: any) => {
Expand Down Expand Up @@ -1073,8 +1074,9 @@ export class CoreGridComponent
});
dialogRef.closed
.pipe(takeUntil(this.destroy$))
.subscribe((value: any) => {
.subscribe(async (value: any) => {
if (value) {
await this.loadPeopleChoices(value);
this.reloadData();
}
});
Expand Down Expand Up @@ -1156,6 +1158,64 @@ export class CoreGridComponent
}
}

/**
* Load more people choices if needed
*
* @param value new updated or added record
*/
public async loadPeopleChoices(value: any) {
const newIds: any[] = [];

// Loop over metaFields to verify if there are new users
for (const metaField in this.metaFields) {
const choices: string[] = isArray(value.data.data[metaField])
? value.data.data[metaField]
: [value.data.data[metaField]];
if (
['people', 'singlepeople'].includes(this.metaFields[metaField]?.type) &&
choices
) {
newIds.push(
...choices
// Filter new users
.filter(
(choice: any) =>
!this.metaFields[metaField].choices.some(
(obj: any) => obj.value === choice
)
)
.map((choice: any) => ({
id: choice,
// Saving the field name to address new choices after fetching
field: metaField,
}))
);
}
}

if (newIds.length) {
// Fetch new users
const newChoices = await lastValueFrom(
this.gridService.getNewPeopleChoices(newIds.map((el) => el.id))
);

// Assign the choices to the correct field
newChoices.forEach((choice: any) => {
const fieldName = newIds.find((el) => el.id === choice.value)?.field;
if (fieldName) {
this.metaFields[fieldName].choices.push(choice);
}
});

this.fields = this.gridService.getFields(
this.settings?.query?.fields || [],
this.metaFields,
this.defaultLayout.fields || {},
''
);
}
}

/**
* Opens the form corresponding to selected row in order to update it
*
Expand All @@ -1174,12 +1234,15 @@ export class CoreGridComponent
},
autoFocus: false,
});
dialogRef.closed.pipe(takeUntil(this.destroy$)).subscribe((value: any) => {
if (value) {
this.validateRecords(ids);
this.reloadData();
}
});
dialogRef.closed
.pipe(takeUntil(this.destroy$))
.subscribe(async (value: any) => {
if (value) {
await this.loadPeopleChoices(value);
this.validateRecords(ids);
this.reloadData();
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
<kendo-grid-column
*ngIf="
field.type !== 'JSON' &&
(!field.meta || field.meta.type !== 'referenceData')
(!field.meta || field.meta.type !== 'referenceData') &&
!(field.meta.type === 'singlepeople')
"
[field]="field.name"
[title]="field.title"
Expand Down Expand Up @@ -653,7 +654,64 @@
</div>
</ng-template>
</kendo-grid-column>
<!-- MULTI SELECT QUESTION TYPES ( checkbox / tagbox / owner / users ) -->
<!-- SINGLE PEOPLE -->
<kendo-grid-column
*ngIf="field.meta.type === 'singlepeople'"
[field]="field.name"
[filterable]="true"
[title]="field.title"
[editor]="field.editor"
[editable]="false"
[width]="field.width"
[hidden]="field.hidden"
[minResizableWidth]="50"
class="no-padding"
>
<ng-template
kendoGridFilterMenuTemplate
let-filter
let-column="column"
let-filterService="filterService"
>
<shared-grid-filter-menu
[isNotArray]="true"
[filter]="filter"
[filterService]="filterService"
[data]="field.meta.choices || []"
[field]="field.name"
textField="text"
valueField="value"
>
</shared-grid-filter-menu>
</ng-template>
<ng-template
kendoGridFilterCellTemplate
let-filter
let-dataItem="dataItem"
>
<shared-grid-filter
[isNotArray]="true"
[filter]="filter"
[data]="field.meta.choices || []"
[field]="field.name"
textField="text"
valueField="value"
>
</shared-grid-filter>
</ng-template>
<ng-template #refSpan kendoGridCellTemplate let-dataItem="dataItem">
<div class="textbox-container" [style]="dataItem.style[field.name]">
<div
class="truncate"
[uiTooltip]="dataItem.text[field.name]"
tooltipEnableBy="truncate"
>
{{ dataItem.text[field.name] }}
</div>
</div>
</ng-template>
</kendo-grid-column>
<!-- MULTI SELECT QUESTION TYPES ( checkbox / tagbox / owner / users / people ) -->
<kendo-grid-column
*ngIf="
field.type === 'JSON' && multiSelectTypes.includes(field.meta.type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const MULTISELECT_TYPES: string[] = [
'tagbox',
'owner',
'users',
'people',
];

/** Settings for pager */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,13 @@ export class EditorComponent extends BaseWidgetComponent implements OnInit {
rows: metaData.rows,
};
}
//add choices for people questions
if (metaData && metaData.choices) {
return {
...field,
choices: metaData.choices,
};
}
return field;
});
} catch (err) {
Expand Down
Loading