Skip to content

Commit 004aec6

Browse files
committed
Revert code changes to disable upload button
1 parent 1b9238e commit 004aec6

6 files changed

Lines changed: 6 additions & 1321 deletions

File tree

.github/workflows/cfdeploy.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ jobs:
5555
- name: Verify and Checkout Deploy Branch 🔄
5656
run: |
5757
git fetch origin
58-
echo "📂 Verifying 'local_deploy' branch..."
59-
if git rev-parse --verify origin/local_deploy; then
60-
git checkout local_deploy
58+
echo "📂 Verifying 'revertChangesToDisableUploadBtn' branch..."
59+
if git rev-parse --verify origin/revertChangesToDisableUploadBtn; then
60+
git checkout revertChangesToDisableUploadBtn
6161
echo "✅ Branch checked out successfully!"
6262
else
63-
echo "❌ Branch 'local_deploy' not found. Please verify the branch name."
63+
echo "❌ Branch 'revertChangesToDisableUploadBtn' not found. Please verify the branch name."
6464
exit 1
6565
fi
6666

README.md

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ This plugin can be consumed by the CAP application deployed on BTP to store thei
2626
- Localization of error messages and UI fields: Provides the capability to have the UI fields and error messages translated to the local language of the leading application.
2727
- Attachment Upload Status: Upload Status is the new field which displays the upload status of attachment when being uploaded.
2828
- Active entity attachment creation: Provides the capability to create attachments directly on active (non-draft) entities.
29-
- Upload button visibility control: Provides the capability to automatically show or hide the Upload button based on the configured `maxCount` limit.
3029
- Download attachments: Provides the capability to download multiple selected file attachments at once with smart button enablement.
3130

3231
## Table of Contents
@@ -49,7 +48,6 @@ This plugin can be consumed by the CAP application deployed on BTP to store thei
4948
- [Support for Localization](#support-for-localization)
5049
- [Support for Attachment Upload Status](#support-for-attachment-upload-status)
5150
- [Support for Attachment creation in Active Entities](#support-for-attachment-creation-in-active-entities)
52-
- [Support for Upload Button Visibility Control](#support-for-upload-button-visibility-control)
5351
- [Support for Download Attachments](#support-for-download-attachments)
5452
- [Known Restrictions](#known-restrictions)
5553
- [Support, Feedback, Contributing](#support-feedback-contributing)
@@ -1398,74 +1396,6 @@ To create attachments on active entities, the leading application needs to trigg
13981396
Insert.into("MyService.MyEntity.attachments").entry(attachmentData)
13991397
);
14001398

1401-
## Support for Upload Button Visibility Control
1402-
1403-
The plugin can automatically **hide the Upload button** once the configured `maxCount` is reached, and **re-enable it** when an attachment is deleted and the count drops back below the limit. This gives end users immediate visual feedback about whether further uploads are allowed, without relying solely on an error message after the attempt.
1404-
1405-
### How It Works
1406-
1407-
1. **On upload (create):** After a successful upload, the plugin compares the current attachment count with `maxCount`. If the count reaches or exceeds `maxCount`, a boolean flag on the parent entity (e.g. `isAttachmentsUploadable`) is set to `false`. The UI reads this flag via a `Capabilities` annotation and hides the Upload button.
1408-
2. **On delete:** After an attachment is deleted, if the remaining count is below `maxCount`, the same flag is set back to `true` and the Upload button reappears.
1409-
1410-
### Usage in Leading Applications
1411-
1412-
#### Step 1Add a boolean field to the parent entity
1413-
1414-
Add a boolean field for each attachment facet that should have Upload button control. The field name must follow the pattern `is<FacetName>Uploadable` where `<FacetName>` is the capitalised name of the composition (e.g. `attachments` → `isAttachmentsUploadable`).
1415-
1416-
```cds
1417-
entity Books {
1418-
key ID : UUID;
1419-
...
1420-
isAttachmentsUploadable : Boolean default true;
1421-
attachments : Composition of many Attachments @SDM.Attachments:{ maxCount: 4 };
1422-
}
1423-
```
1424-
1425-
> **Note:** Initialise the field to `true` so the Upload button is visible before any attachment is added.
1426-
1427-
#### Step 2 — Annotate the composition at the service layer
1428-
1429-
Use the `@Capabilities.InsertRestrictions.Insertable` annotation to bind the Upload button visibility to the flag on the parent entity:
1430-
1431-
```cds
1432-
annotate MyService.Books.attachments with @(
1433-
Capabilities: {
1434-
InsertRestrictions: {
1435-
Insertable: up_.isAttachmentsUploadable
1436-
}
1437-
}
1438-
);
1439-
```
1440-
1441-
The `up_` navigation property refers to the parent `Books` entity. The UI framework reads this annotation and enables or disables the Upload button accordingly.
1442-
1443-
#### Multiple facets
1444-
1445-
For each additional facet, add its own boolean field and annotation:
1446-
1447-
```cds
1448-
entity Books {
1449-
key ID : UUID;
1450-
...
1451-
isAttachmentsUploadable : Boolean default true;
1452-
isReferencesUploadable : Boolean default true;
1453-
attachments : Composition of many Attachments @SDM.Attachments:{ maxCount: 4 };
1454-
references : Composition of many Attachments @SDM.Attachments:{ maxCount: 3 };
1455-
}
1456-
```
1457-
1458-
```cds
1459-
annotate MyService.Books.attachments with @(
1460-
Capabilities: { InsertRestrictions: { Insertable: up_.isAttachmentsUploadable } }
1461-
);
1462-
annotate MyService.Books.references with @(
1463-
Capabilities: { InsertRestrictions: { Insertable: up_.isReferencesUploadable } }
1464-
);
1465-
```
1466-
1467-
> **Note:** No additional Java or configuration changes are required in the leading application. The plugin derives the field name from the facet's composition name automatically.
1468-
14691399
## Support for Download Attachments
14701400

14711401
This plugin provides the capability to download multiple selected file attachments at once. The Download button is automatically disabled when any link-type attachment is selected, since links are meant to be opened in the browser and not downloaded as files.

sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,76 +1138,4 @@ private String resolveUpIdKey(CdsModel model, String parentEntity, String compos
11381138

11391139
return null;
11401140
}
1141-
1142-
/**
1143-
* Looks up the parent ID (up__ID) of an attachment by its objectId.
1144-
*
1145-
* @param attachmentEntity the attachment entity to query
1146-
* @param persistenceService the persistence service
1147-
* @param objectId the SDM objectId of the attachment
1148-
* @param upIdKey the field name for the parent ID (e.g. "up__ID")
1149-
* @return the parent ID string, or null if not found
1150-
*/
1151-
public String getUpIdByObjectId(
1152-
CdsEntity attachmentEntity,
1153-
PersistenceService persistenceService,
1154-
String objectId,
1155-
String upIdKey) {
1156-
logger.debug(
1157-
"Fetching {} for objectId: {} from entity: {}",
1158-
upIdKey,
1159-
objectId,
1160-
attachmentEntity.getQualifiedName());
1161-
CqnSelect q =
1162-
Select.from(attachmentEntity)
1163-
.columns(upIdKey)
1164-
.where(doc -> doc.get("objectId").eq(objectId));
1165-
Result result = persistenceService.run(q);
1166-
return result
1167-
.first()
1168-
.map(row -> row.get(upIdKey) != null ? row.get(upIdKey).toString() : null)
1169-
.orElse(null);
1170-
}
1171-
1172-
/**
1173-
* Updates the isUploadable flag on the parent entity row that owns the attachment composition.
1174-
* One row updated instead of N attachment rows.
1175-
*
1176-
* @param parentEntity the parent CDS entity (e.g. Books or Books_drafts)
1177-
* @param persistenceService the persistence service
1178-
* @param parentId the parent entity's key value
1179-
* @param parentKeyField the parent entity's key field name (e.g. "ID")
1180-
* @param isUploadable the new value of the isUploadable flag
1181-
*/
1182-
public long updateIsUploadableOnParentEntity(
1183-
CdsEntity parentEntity,
1184-
PersistenceService persistenceService,
1185-
String parentId,
1186-
String parentKeyField,
1187-
String facetField,
1188-
boolean isUploadable) {
1189-
logger.debug(
1190-
"Updating {}={} on parent entity: {} for {}={}",
1191-
facetField,
1192-
isUploadable,
1193-
parentEntity.getQualifiedName(),
1194-
parentKeyField,
1195-
parentId);
1196-
Map<String, Object> updatedFields = new HashMap<>();
1197-
updatedFields.put(facetField, isUploadable);
1198-
CqnUpdate updateQuery =
1199-
Update.entity(parentEntity)
1200-
.data(updatedFields)
1201-
.where(e -> e.get(parentKeyField).eq(parentId));
1202-
Result updateResult = persistenceService.run(updateQuery);
1203-
logger.info(
1204-
"Updated {}={} for {} row(s) on {} where {}={}",
1205-
facetField,
1206-
isUploadable,
1207-
updateResult.rowCount(),
1208-
parentEntity.getQualifiedName(),
1209-
parentKeyField,
1210-
parentId);
1211-
return updateResult.rowCount();
1212-
}
12131141
}

0 commit comments

Comments
 (0)