You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+86-4Lines changed: 86 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ This plugin can be consumed by the CAP application deployed on BTP to store thei
14
14
- Draft functionality : Provides the capability of working with draft attachments.
15
15
- Display attachments specific to repository: Lists attachments contained in the repository that is configured with the CAP application.
16
16
- Custom properties : Provides the capability to define custom properties for attachments.
17
-
- Maximum allowed uploads: Provides the capability to define the maximum number of uploads allowed for the user.
17
+
- Maximum allowed uploads: Provides the capability to define the maximum number of uploads allowed for the user. Automatically disables the upload button in the UI when the limit is reached.
18
18
- Maximum file size: Provides the capability to specify the maximum file size for attachments.
19
19
- Multiple attachment facets: Provides the capability to define multiple attachment facets/sections in the CAP Entity.
20
20
- Technical user support: Provides the capability to consume the plugin using technical user.
@@ -37,6 +37,7 @@ This plugin can be consumed by the CAP application deployed on BTP to store thei
37
37
-[Support for Multitenancy](#support-for-multitenancy)
38
38
-[Support for Custom Properties](#support-for-custom-properties)
39
39
-[Support for Maximum allowed uploads](#support-for-maximum-allowed-uploads)
40
+
-[Upload Button Auto-Disable in the UI](#upload-button-auto-disable-in-the-ui)
40
41
-[Support for Maximum File Size](#support-for-maximum-file-size)
41
42
-[Support for Multiple attachment facets](#support-for-multiple-attachment-facets)
42
43
-[Support for Technical user](#support-for-technical-user)
@@ -494,9 +495,90 @@ Example for German language in `messages_de.properties`:
494
495
SDM.maxCountErrorMessage = Maximale Anzahl von Anhängen erreicht
495
496
```
496
497
497
-
> **Note**
498
-
>
499
-
> Once the maxCount is configured, it is recommended not to alter it. If the maxCount is altered, the previously uploaded documents will still be visible.
498
+
#### Upload Button Auto-Disable in the UI
499
+
500
+
When `maxCount` is configured, the plugin automatically computes a virtual boolean field (e.g. `isAttachmentsUploadable`) on the parent entity at read time and sets it to `false` when the limit is reached. To wire this up in your Fiori UI so the **Upload button is automatically disabled**, follow the steps below.
501
+
502
+
**1. Declare the virtual field on the parent entity**
503
+
504
+
Add a `virtual` boolean field for each `maxCount` annotated composition directly on the parent entity in your CDS schema. The field name must follow the pattern `is` + capitalised composition name + `Uploadable`:
505
+
506
+
```cds
507
+
entity Books : managed, cuid {
508
+
// ... other fields ...
509
+
virtual isAttachmentsUploadable : Boolean;
510
+
virtual isReferencesUploadable : Boolean;
511
+
512
+
attachments : Composition of many Attachments @SDM.Attachments:{maxCount: 4};
513
+
references : Composition of many Attachments @SDM.Attachments:{maxCount: 2};
514
+
}
515
+
```
516
+
517
+
- For a composition named `attachments` declare `virtual isAttachmentsUploadable : Boolean`.
518
+
- For `references` declare `virtual isReferencesUploadable : Boolean`, and so on.
519
+
- Virtual fields are never stored in the database; the plugin populates them at read time.
520
+
521
+
**2. Disable the Upload button via `InsertRestrictions`**
522
+
523
+
Annotate each attachment entity in your service to bind its insertability to the virtual field on the parent:
- Replace `MyService.Books.attachments` with your service and entity path.
532
+
- Repeat for every composition facet that has a `maxCount`.
533
+
534
+
**3. Refresh the parent after attachment changes via `SideEffects`**
535
+
536
+
After an upload or deletion, Fiori must re-read the parent entity to pick up the updated virtual field and reflect the new button state. Add a named `Common.SideEffects` annotation on the parent entity:
537
+
538
+
```cds
539
+
annotate MyService.Books with @(
540
+
Common.SideEffects #attachmentsUploadable: {
541
+
SourceEntities: ['attachments'],
542
+
TargetProperties: ['']
543
+
}
544
+
);
545
+
```
546
+
547
+
-`SourceEntities: ['attachments']` — triggers the refresh when the `attachments` list changes.
548
+
-`TargetEntities: ['']` — re-fetches the parent entity (`Books`) so the updated `isAttachmentsUploadable` value is returned to the UI.
549
+
- The qualifier (e.g. `#attachmentsUploadable`) can be any unique name; it is only needed to distinguish multiple `SideEffects` annotations on the same entity.
550
+
551
+
**Example with multiple facets**
552
+
553
+
If an entity has several `maxCount`-annotated compositions, add one `virtual field` declaration, one `InsertRestrictions`, and one `SideEffects` per facet:
See this [example](https://github.com/cap-java/sdm/blob/cc537c5c855ad59fa14100a397536ab22f4b1aa7/cap-notebook/demoapp/db/schema.cds#L19) of `virtual field` declaration from a sample Bookshop app.
577
+
578
+
See this [example](https://github.com/cap-java/sdm/blob/cc537c5c855ad59fa14100a397536ab22f4b1aa7/cap-notebook/demoapp/srv/admin-service.cds#L46) of `InsertRestriction` annotation from a sample Bookshop app.
579
+
580
+
See this [example](https://github.com/cap-java/sdm/blob/cc537c5c855ad59fa14100a397536ab22f4b1aa7/cap-notebook/demoapp/srv/admin-service.cds#L279) of `SideEffects` annotation from a sample Bookshop app.
0 commit comments