Skip to content

Commit fe411be

Browse files
authored
feat: Allow to duplicate records when seeing form details & user can create new records
AB#118658
1 parent b85bfb4 commit fe411be

File tree

6 files changed

+42
-4
lines changed

6 files changed

+42
-4
lines changed

libs/shared/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
"downloadObject": "Download {{name}}",
182182
"downloadTemplate": "Get template",
183183
"duplicate": "Duplicate",
184+
"duplicateRecord": "Duplicate record",
184185
"edit": "Edit",
185186
"email": {
186187
"customTemplate": "Custom template",

libs/shared/src/i18n/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
"downloadObject": "Télécharger {{name}}",
182182
"downloadTemplate": "Télécharger le modèle",
183183
"duplicate": "Dupliquer",
184+
"duplicateRecord": "Dupliquer l'enregistrement",
184185
"edit": "Modifier",
185186
"email": {
186187
"customTemplate": "Modèle personnalisé",

libs/shared/src/i18n/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
"downloadObject": "****** {{name}}",
182182
"downloadTemplate": "******",
183183
"duplicate": "******",
184+
"duplicateRecord": "******",
184185
"edit": "******",
185186
"email": {
186187
"customTemplate": "******",

libs/shared/src/lib/components/record-modal/graphql/queries.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const GET_RECORD_BY_ID = gql`
1919
form {
2020
id
2121
structure
22+
canCreateRecords
2223
permissions {
2324
recordsUnicity
2425
}
@@ -42,6 +43,7 @@ export const GET_FORM_STRUCTURE = gql`
4243
form(id: $id) {
4344
id
4445
structure
46+
canCreateRecords
4547
metadata {
4648
name
4749
automated

libs/shared/src/lib/components/record-modal/record-modal.component.html

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,30 @@
22
<ng-container ngProjectAs="header">
33
<ng-container *ngIf="!loading">
44
<div class="flex flex-wrap justify-between items-center gap-4 mb-4">
5+
<!-- Record summary -->
56
<shared-record-summary
67
*ngIf="!data.compareTo"
78
[record]="record"
89
(showHistory)="onShowHistory()"
910
></shared-record-summary>
1011

11-
<shared-form-actions
12-
[survey]="survey"
13-
[surveyNext]="surveyNext || undefined"
14-
></shared-form-actions>
12+
<div class="flex gap-4 items-center mr-4">
13+
<!-- Translate form -->
14+
<shared-form-actions
15+
[survey]="survey"
16+
[surveyNext]="surveyNext || undefined"
17+
></shared-form-actions>
18+
19+
<!-- Open form to duplicate record -->
20+
<ui-button
21+
*ngIf="form?.canCreateRecords && !data.compareTo"
22+
variant="primary"
23+
category="secondary"
24+
(click)="onDuplicate()"
25+
>
26+
{{ 'common.duplicateRecord' | translate }}
27+
</ui-button>
28+
</div>
1529
</div>
1630
<ui-tabs
1731
[selectedIndex]="(selectedPageIndex$ | async)!"

libs/shared/src/lib/components/record-modal/record-modal.component.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,25 @@ export class RecordModalComponent
263263
this.dialogRef.close(true as any);
264264
}
265265

266+
/**
267+
* Open a create form modal prefilled with this record's data
268+
*/
269+
public async onDuplicate(): Promise<void> {
270+
if (!this.form?.id) return;
271+
const { FormModalComponent } = await import(
272+
'../form-modal/form-modal.component'
273+
);
274+
this.dialog.open(FormModalComponent, {
275+
disableClose: true,
276+
data: {
277+
template: this.form.id,
278+
prefillData: this.record?.data,
279+
askForConfirm: false,
280+
},
281+
autoFocus: false,
282+
});
283+
}
284+
266285
/**
267286
* Opens the history of the record in a modal.
268287
*/

0 commit comments

Comments
 (0)