new template

This commit is contained in:
Wolfgang Koch
2021-05-12 10:03:58 +02:00
parent 70d132fed9
commit f952764b48
5 changed files with 241 additions and 0 deletions

BIN
mtx_error_1.txt Normal file

Binary file not shown.

BIN
mtx_error_2.txt Normal file

Binary file not shown.

View File

@@ -0,0 +1,44 @@
using {sap.capire.bookshop} from '_base/db/schema';
using {sap.capire.orders} from '_base/db/schema';
using from '_base/db/capire_common';
using {
cuid, managed, Country, sap.common.CodeList
} from '@sap/cds/common';
namespace Z_bookshop.extension;
// extend existing entity
extend orders.Orders with {
Z_newField : String default 'Default Value';
Z_NewAssociation : Association to one Z_NewEntity;
Z_NewCodeList : Association to one Z_NewCodeList;
Z_NewComposition : Composition of many Z_NewCompEntity on Z_NewComposition.parent = $self;
}
// new entity - as association target
entity Z_NewEntity : cuid, managed
{
description : String;
dateField : Date;
integerField : Integer;
stringField : String;
enumField : String @assert.range enum {high; medium; low} default 'medium';
rangeField : Decimal @assert.range: [ 1.0, 100.0 ] default 50.0;
}
// new entity - as code list
entity Z_NewCodeList : CodeList {
key code : String(11);
}
// new entity - as composition target
entity Z_NewCompEntity : cuid, managed
{
parent : Association to one orders.Orders;
description : String;
dateField : Date;
integerField : Integer;
stringField : String;
}

View File

@@ -0,0 +1,10 @@
using from '_base/srv/admin-service';
using from '_base/srv/cat-service';
using from '_base/srv/orders-service';
using { Z_bookshop.extension as ext } from '../db/extension';
extend service OrdersService with {
entity Z_NewEntity as projection on ext.Z_NewEntity ;
entity Z_NewCodeList as projection on ext.Z_NewCodeList;
}

View File

@@ -0,0 +1,187 @@
using from '_base/app/services';
using OrdersService from './extension_service';
// new entity -- draft enabled
annotate OrdersService.Z_NewEntity with @odata.draft.enabled;
// new codelist entity -- draft enabled
annotate OrdersService.Z_SalesRegion with @odata.draft.enabled;
// new entity -- titles
annotate OrdersService.Z_NewEntity with {
description @title : 'Description';
integerField @title : 'Integer Field Title';
dateField @title : 'Date Field Title';
stringField @title : 'String Field Title';
enumField @title : 'Enum Field Title';
rangeField @title : 'Range Field Title';
}
// new entity -- titles
annotate OrdersService.Z_NewCodeList with {
code @title: 'Code Title';
}
// new entity -- titles
annotate OrdersService.Z_NewCompEntity with {
description @title : 'Description';
integerField @title : 'Integer Field Title';
dateField @title : 'Date Field Title';
stringField @title : 'String Field Title';
}
// new entity in service -- UI
annotate OrdersService.Z_NewEntity with @(UI : {
HeaderInfo : {
TypeName : 'New Entity',
TypeNamePlural : 'New Entities',
Title : {
$Type : 'UI.DataField',
Value : description
}
},
LineItem : [
{Value : description},
{Value : dateField },
{Value : integerField },
{Value : stringField},
{Value : enumField},
{Value : rangeField}
],
Facets : [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target : '@UI.FieldGroup#Main'}
],
FieldGroup #Main : {Data : [
{Value : description},
{Value : dateField },
{Value : integerField },
{Value : stringField},
{Value : enumField},
{Value : rangeField}
]}
} ) ;
// new entity -- UI
annotate OrdersService.Z_NewCodeList with @(
UI: {
HeaderInfo: {
TypeName: 'New Code',
TypeNamePlural: 'New Codes',
Title : {
$Type : 'UI.DataField',
Value : code
}
},
LineItem: [
{Value: code}
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target: '@UI.FieldGroup#Main'}
],
FieldGroup#Main: {
Data: [
{Value: code}
]
}
},
) {
};
// new entity -- UI
annotate OrdersService.Z_NewCompEntity with @(
UI: {
HeaderInfo: {
TypeName: 'New Composition',
TypeNamePlural: 'New Compositions',
Title : {
$Type : 'UI.DataField',
Value : description
}
},
LineItem: [
{Value : description},
{Value : dateField },
{Value : integerField },
{Value : stringField}
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: 'Main', Target: '@UI.FieldGroup#Main'}
],
FieldGroup#Main: {
Data: [
{Value : description},
{Value : dateField },
{Value : integerField },
{Value : stringField}
]
}
},
) {
};
// extend existing entity Orders with new extension fields and new composition
@odata.draft.enabled
annotate OrdersService.Orders with @(
UI: {
SelectionFields: [ createdAt, createdBy ],
LineItem: [
{Value: OrderNo, Label:'OrderNo'},
{Value: Z_newField, Label:'New Field'}, // extension field
{Value: Z_NewAssociation_ID, Label:'New Association'}, // extension field
{Value: Z_NewCodeList_code, Label:'New Code'}, // extension field
{Value: createdAt, Label:'Date'}
],
HeaderInfo: {
TypeName: 'Order', TypeNamePlural: 'Orders',
Title: {
Label: 'Order number ', //A label is possible but it is not considered on the ObjectPage yet
Value: OrderNo
},
Description: {Value: createdBy}
},
Identification: [ //Is the main field group
{Value: createdBy, Label:'Customer'},
{Value: createdAt, Label:'Date'},
{Value: OrderNo },
],
HeaderFacets: [
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Created}', Target: '@UI.FieldGroup#Created'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Modified}', Target: '@UI.FieldGroup#Modified'},
],
Facets: [
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>OrderItems}', Target: 'Items/@UI.LineItem'},
{$Type: 'UI.ReferenceFacet', Label: 'New Composition', Target: 'Z_NewComposition/@UI.LineItem'} // new composition
],
FieldGroup#Details: {
Data: [
{Value: currency_code, Label:'Currency'}, // correction
{Value: Z_newField, Label:'New Field'}, // extension field
{Value: Z_NewAssociation_ID, Label:'New Association'}, // extension field
{Value: Z_NewCodeList_code, Label:'New Code'}, // extension field
]
},
FieldGroup#Created: {
Data: [
{Value: createdBy},
{Value: createdAt},
]
},
FieldGroup#Modified: {
Data: [
{Value: modifiedBy},
{Value: modifiedAt},
]
},
},
) ;