-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.cds
106 lines (95 loc) · 4.29 KB
/
index.cds
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using { managed, cuid } from '@sap/cds/common';
namespace sap.changelog;
/**
* Used in cds-plugin.js as template for tracked entities
*/
aspect aspect @(UI.Facets: [{
$Type : 'UI.ReferenceFacet',
ID : 'ChangeHistoryFacet',
Label : '{i18n>ChangeHistory}',
Target: 'changes/@UI.PresentationVariant',
![@UI.PartOfPreview]: false
}]) {
// Essentially: Association to many Changes on changes.changeLog.entityKey = ID;
changes : Association to many ChangeView on changes.entityKey = ID;
key ID : UUID;
}
// This is a helper view to flatten the assoc path to the entityKey
@readonly
view ChangeView as
select from Changes {
*,
entityID as objectID, // no clue why we have to rename this?
parentEntityID as parentObjectID, // no clue why we have to rename this?
changeLog.entityKey as entityKey, // flattening assoc path -> this is the main reason for having this helper view
changeLog.createdAt as createdAt,
changeLog.createdBy as createdBy,
}
excluding {
entityID,
parentEntityID,
};
/**
* Top-level changes entity, e.g. UPDATE Incident by, at, ...
*/
entity ChangeLog : managed, cuid {
serviceEntity : String @title: '{i18n>ChangeLog.serviceEntity}'; // definition name of target entity (on service level) - e.g. ProcessorsService.Incidents
entity : String @title: '{i18n>ChangeLog.entity}'; // definition name of target entity (on db level) - e.g. sap.capire.incidents.Incidents
entityKey : UUID @title: '{i18n>ChangeLog.entityKey}'; // primary key of target entity, e.g. Incidents.ID
createdAt : managed:createdAt;
createdBy : managed:createdBy;
changes : Composition of many Changes on changes.changeLog = $self;
}
/**
* Attribute-level Changes with simple capturing of one-level
* composition trees in parent... elements.
*/
entity Changes {
key ID : UUID @UI.Hidden;
keys : String @title: '{i18n>Changes.keys}';
attribute : String @title: '{i18n>Changes.attribute}';
valueChangedFrom : String @title: '{i18n>Changes.valueChangedFrom}' @UI.MultiLineText;
valueChangedTo : String @title: '{i18n>Changes.valueChangedTo}' @UI.MultiLineText;
// Business meaningful object id
entityID : String @title: '{i18n>Changes.entityID}';
entity : String @title: '{i18n>Changes.entity}'; // similar to ChangeLog.entity, but could be nested entity in a composition tree
serviceEntity : String @title: '{i18n>Changes.serviceEntity}'; // similar to ChangeLog.serviceEntity, but could be nested entity in a composition tree
// Business meaningful parent object id
parentEntityID : String @title: '{i18n>Changes.parentEntityID}';
parentKey : UUID @title: '{i18n>Changes.parentKey}';
serviceEntityPath : String @title: '{i18n>Changes.serviceEntityPath}';
@title: '{i18n>Changes.modification}'
modification : String enum {
create = 'Create';
update = 'Edit';
delete = 'Delete';
};
valueDataType : String @title: '{i18n>Changes.valueDataType}';
changeLog : Association to ChangeLog @title: '{i18n>ChangeLog.ID}' @UI.Hidden;
}
annotate ChangeView with @(UI: {
PresentationVariant: {
Visualizations: ['@UI.LineItem'],
RequestAtLeast: [
parentKey,
serviceEntity,
serviceEntityPath
],
SortOrder : [{
Property : createdAt,
Descending: true
}],
},
LineItem : [
{ Value: modification, @HTML5.CssDefaults: {width:'9%'} },
{ Value: createdAt, @HTML5.CssDefaults: {width:'12%'} },
{ Value: createdBy, @HTML5.CssDefaults: {width:'9%'} },
{ Value: entity, @HTML5.CssDefaults: {width:'11%'} },
{ Value: objectID, @HTML5.CssDefaults: {width:'14%'} },
{ Value: attribute, @HTML5.CssDefaults: {width:'9%'} },
{ Value: valueChangedTo, @HTML5.CssDefaults: {width:'11%'} },
{ Value: valueChangedFrom, @HTML5.CssDefaults: {width:'11%'} },
{ Value: parentObjectID, @HTML5.CssDefaults: {width:'14%'}, ![@UI.Hidden]: true }
],
DeleteHidden : true,
});