diff --git a/cap-notebook/demoapp/app/admin-books/webapp/controller/custom.controller.js b/cap-notebook/demoapp/app/admin-books/webapp/controller/custom.controller.js index a7fd5a2a7..c7016c1c4 100644 --- a/cap-notebook/demoapp/app/admin-books/webapp/controller/custom.controller.js +++ b/cap-notebook/demoapp/app/admin-books/webapp/controller/custom.controller.js @@ -1,10 +1,17 @@ sap.ui.define( [ "sap/ui/core/mvc/ControllerExtension", - "sap/m/library" + "sap/m/library", + "sap/ui/core/format/DateFormat" ], - function (ControllerExtension,library) { + function (ControllerExtension, library, DateFormat) { "use strict"; + const ChangeCategoryEnum = { + created: "Created", + updated: "Changed", + security: "Access" + // Add more mappings as needed + }; return ControllerExtension.extend("books.controller.custom", { onRowPress: function(oContext) { @@ -27,6 +34,63 @@ sap.ui.define( library.URLHelper.redirect(odataurl, true); }); + }, + onChangelogPress: function(oContext, aSelectedContexts) { + var that =this; + this.base.editFlow + .invokeAction("AdminService.changelog", { + contexts: aSelectedContexts + }) + .then(function (res) { + console.log("Result",res[0].value.getObject().value); + that.updateChangeLogInPropertiesModel(res[0].value.getObject().value); + }); + }, + updateChangeLogInPropertiesModel: function (oChangeLogsForObjectResponse) { + const aChangeLogs = []; + const fileName = JSON.parse(oChangeLogsForObjectResponse).filename; + console.log("Filename: ", fileName); + const aChangeLogsObject = JSON.parse(oChangeLogsForObjectResponse)["changeLogs"]; + console.log("ChangeLogsObject:\n", aChangeLogsObject); + // Take latest changes at the top + for (let idx = aChangeLogsObject.length - 1; idx >= 0; idx--) { + const oChangeLogEntry = aChangeLogsObject[idx]; + const sLastModifiedBy = oChangeLogEntry["user"]; + const sChangeType = oChangeLogEntry["operation"]; + const sChangeTime = oChangeLogEntry["time"]; + let dateTimeFormat = DateFormat.getDateTimeInstance(sap.ui.getCore().getConfiguration().getLocale()); + let changedDate = new Date(sChangeTime); + let changedTime = changedDate?dateTimeFormat.format(new Date(changedDate)) : "" ; + const oChangeLog = { + changedOn: changedTime, + changedBy: sLastModifiedBy, + changeType: ChangeCategoryEnum[sChangeType] + }; + aChangeLogs.push(oChangeLog); + console.log("ChangeLog:\n", oChangeLog); + } + + this.logFragment= this.base.getExtensionAPI().loadFragment({ + name: "books.fragments.changelog", + controller: this + }); + var that = this; + this.logFragment.then(function (dialog) { + if(dialog){ + dialog.attachEventOnce("afterClose", function () { + dialog.destroy(); + }); + var oModel = new sap.ui.model.json.JSONModel(); + oModel.setSizeLimit(100000); + oModel.setData(aChangeLogs); + that.getView().setModel(oModel, "changelog"); + dialog.setTitle(fileName); + dialog.open() + } + }); + }, + close: function (closeBtn) { + closeBtn.getSource().getParent().close(); } }); } diff --git a/cap-notebook/demoapp/app/admin-books/webapp/fragments/changelog.fragment.xml b/cap-notebook/demoapp/app/admin-books/webapp/fragments/changelog.fragment.xml new file mode 100644 index 000000000..0f0884c6d --- /dev/null +++ b/cap-notebook/demoapp/app/admin-books/webapp/fragments/changelog.fragment.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + +
+ + +
+
\ No newline at end of file diff --git a/cap-notebook/demoapp/app/admin-books/webapp/manifest.json b/cap-notebook/demoapp/app/admin-books/webapp/manifest.json index 24cc3f714..243b45fcb 100644 --- a/cap-notebook/demoapp/app/admin-books/webapp/manifest.json +++ b/cap-notebook/demoapp/app/admin-books/webapp/manifest.json @@ -139,6 +139,18 @@ "type": "ResponsiveTable", "selectionMode": "Auto", "rowPress": ".extension.books.controller.custom.onRowPress" + }, + "actions": { + "changelog": { + "enableOnSelect": "single", + "text": "Change Log", + "requiresSelection": true, + "press": ".extension.books.controller.custom.onChangelogPress", + "command": "COMMON", "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } + } } }, "references/@com.sap.vocabularies.UI.v1.LineItem": { @@ -146,6 +158,18 @@ "type": "ResponsiveTable", "selectionMode": "Auto", "rowPress": ".extension.books.controller.custom.onRowPress" + }, + "actions": { + "changelog": { + "enableOnSelect": "single", + "text": "Change Log", + "requiresSelection": true, + "press": ".extension.books.controller.custom.onChangelogPress", + "command": "COMMON", "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } + } } }, "footnotes/@com.sap.vocabularies.UI.v1.LineItem": { @@ -153,6 +177,18 @@ "type": "ResponsiveTable", "selectionMode": "Auto", "rowPress": ".extension.books.controller.custom.onRowPress" + }, + "actions": { + "changelog": { + "enableOnSelect": "single", + "text": "Change Log", + "requiresSelection": true, + "press": ".extension.books.controller.custom.onChangelogPress", + "command": "COMMON", "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } + } } } } @@ -173,6 +209,18 @@ "type": "ResponsiveTable", "selectionMode": "Auto", "rowPress": ".extension.books.controller.custom.onRowPress" + }, + "actions": { + "changelog": { + "enableOnSelect": "single", + "text": "Change Log", + "requiresSelection": true, + "press": ".extension.books.controller.custom.onChangelogPress", + "command": "COMMON", "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } + } } }, "references/@com.sap.vocabularies.UI.v1.LineItem": { @@ -180,6 +228,18 @@ "type": "ResponsiveTable", "selectionMode": "Auto", "rowPress": ".extension.books.controller.custom.onRowPress" + }, + "actions": { + "changelog": { + "enableOnSelect": "single", + "text": "Change Log", + "requiresSelection": true, + "press": ".extension.books.controller.custom.onChangelogPress", + "command": "COMMON", "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } + } } }, "footnotes/@com.sap.vocabularies.UI.v1.LineItem": { @@ -187,6 +247,18 @@ "type": "ResponsiveTable", "selectionMode": "Auto", "rowPress": ".extension.books.controller.custom.onRowPress" + }, + "actions": { + "changelog": { + "enableOnSelect": "single", + "text": "Change Log", + "requiresSelection": true, + "press": ".extension.books.controller.custom.onChangelogPress", + "command": "COMMON", "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } + } } } } @@ -208,6 +280,18 @@ "type": "ResponsiveTable", "selectionMode": "Auto", "rowPress": ".extension.books.controller.custom.onRowPress" + }, + "actions": { + "changelog": { + "enableOnSelect": "single", + "text": "Change Log", + "requiresSelection": true, + "press": ".extension.books.controller.custom.onChangelogPress", + "command": "COMMON", "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } + } } }, "references/@com.sap.vocabularies.UI.v1.LineItem": { @@ -215,6 +299,18 @@ "type": "ResponsiveTable", "selectionMode": "Auto", "rowPress": ".extension.books.controller.custom.onRowPress" + }, + "actions": { + "changelog": { + "enableOnSelect": "single", + "text": "Change Log", + "requiresSelection": true, + "press": ".extension.books.controller.custom.onChangelogPress", + "command": "COMMON", "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } + } } }, "footnotes/@com.sap.vocabularies.UI.v1.LineItem": { @@ -222,6 +318,18 @@ "type": "ResponsiveTable", "selectionMode": "Auto", "rowPress": ".extension.books.controller.custom.onRowPress" + }, + "actions": { + "changelog": { + "enableOnSelect": "single", + "text": "Change Log", + "requiresSelection": true, + "press": ".extension.books.controller.custom.onChangelogPress", + "command": "COMMON", "position": { + "anchor": "StandardAction::Create", + "placement": "After" + } + } } } } diff --git a/cap-notebook/demoapp/db/pom.xml b/cap-notebook/demoapp/db/pom.xml index e1c7d04dd..7a74659e1 100644 --- a/cap-notebook/demoapp/db/pom.xml +++ b/cap-notebook/demoapp/db/pom.xml @@ -16,7 +16,7 @@ com.sap.cds sdm - 1.6.0 + 1.0.0-RC1 diff --git a/cap-notebook/demoapp/db/schema.cds b/cap-notebook/demoapp/db/schema.cds index 0a0a82448..cbf192eb0 100644 --- a/cap-notebook/demoapp/db/schema.cds +++ b/cap-notebook/demoapp/db/schema.cds @@ -92,3 +92,4 @@ entity Writers : managed, cuid { notebooks : Association to many Notebooks on notebooks.writer = $self; } + diff --git a/cap-notebook/demoapp/srv/admin-service.cds b/cap-notebook/demoapp/srv/admin-service.cds index a2afc28c9..d1a897ed9 100644 --- a/cap-notebook/demoapp/srv/admin-service.cds +++ b/cap-notebook/demoapp/srv/admin-service.cds @@ -22,6 +22,7 @@ service AdminService @(requires: ['admin','system-user']) { @mandatory @assert.format:'^(https?:\/\/)(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}|localhost)(:\d{2,5})?(\/[^\s]*)?$' @Common.Label:'URL' url: String @UI.Placeholder: 'Example: https://www.example.com' ); action openAttachment() returns String; + action changelog() returns String; }; entity Books.references as projection on my.Books.references @@ -40,6 +41,7 @@ service AdminService @(requires: ['admin','system-user']) { @mandatory @assert.format:'^(https?:\/\/)(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}|localhost)(:\d{2,5})?(\/[^\s]*)?$' @Common.Label:'URL' url: String @UI.Placeholder: 'Example: https://www.example.com' ); action openAttachment() returns String; + action changelog() returns String; }; entity Books.footnotes as projection on my.Books.footnotes @@ -58,6 +60,7 @@ service AdminService @(requires: ['admin','system-user']) { @mandatory @assert.format:'^(https?:\/\/)(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}|localhost)(:\d{2,5})?(\/[^\s]*)?$' @Common.Label:'URL' url: String @UI.Placeholder: 'Example: https://www.example.com' ); action openAttachment() returns String; + action changelog() returns String; }; entity Pages.attachments as projection on my.Pages.attachments @@ -76,6 +79,7 @@ service AdminService @(requires: ['admin','system-user']) { @mandatory @assert.format:'^(https?:\/\/)(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}|localhost)(:\d{2,5})?(\/[^\s]*)?$' @Common.Label:'URL' url: String @UI.Placeholder: 'Example: https://www.example.com' ); action openAttachment() returns String; + action changelog() returns String; }; entity Pages.references as projection on my.Pages.references @@ -94,6 +98,7 @@ service AdminService @(requires: ['admin','system-user']) { @mandatory @assert.format:'^(https?:\/\/)(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}|localhost)(:\d{2,5})?(\/[^\s]*)?$' @Common.Label:'URL' url: String @UI.Placeholder: 'Example: https://www.example.com' ); action openAttachment() returns String; + action changelog() returns String; }; // Chapters projections @@ -113,6 +118,7 @@ service AdminService @(requires: ['admin','system-user']) { @mandatory @assert.format:'^(https?:\/\/)(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}|localhost)(:\d{2,5})?(\/[^\s]*)?$' @Common.Label:'URL' url: String @UI.Placeholder: 'Example: https://www.example.com' ); action openAttachment() returns String; + action changelog() returns String; }; entity Chapters.references as projection on my.Chapters.references @@ -131,6 +137,7 @@ service AdminService @(requires: ['admin','system-user']) { @mandatory @assert.format:'^(https?:\/\/)(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}|localhost)(:\d{2,5})?(\/[^\s]*)?$' @Common.Label:'URL' url: String @UI.Placeholder: 'Example: https://www.example.com' ); action openAttachment() returns String; + action changelog() returns String; }; entity Chapters.footnotes as projection on my.Chapters.footnotes @@ -149,6 +156,7 @@ service AdminService @(requires: ['admin','system-user']) { @mandatory @assert.format:'^(https?:\/\/)(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}|localhost)(:\d{2,5})?(\/[^\s]*)?$' @Common.Label:'URL' url: String @UI.Placeholder: 'Example: https://www.example.com' ); action openAttachment() returns String; + action changelog() returns String; }; // Pages footnotes projection @@ -168,5 +176,6 @@ service AdminService @(requires: ['admin','system-user']) { @mandatory @assert.format:'^(https?:\/\/)(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}|localhost)(:\d{2,5})?(\/[^\s]*)?$' @Common.Label:'URL' url: String @UI.Placeholder: 'Example: https://www.example.com' ); action openAttachment() returns String; + action changelog() returns String; }; } diff --git a/cap-notebook/demoapp/srv/pom.xml b/cap-notebook/demoapp/srv/pom.xml index 54b72e437..1a18bebd8 100644 --- a/cap-notebook/demoapp/srv/pom.xml +++ b/cap-notebook/demoapp/srv/pom.xml @@ -18,7 +18,7 @@ com.sap.cds sdm - 1.6.0 + 1.0.0-RC1