@sap-ux/fe-fpm-writer 0.19.1 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/event-handler.d.ts +2 -1
- package/dist/common/event-handler.js +6 -7
- package/dist/filter/index.d.ts +12 -0
- package/dist/filter/index.js +89 -0
- package/dist/filter/types.d.ts +52 -0
- package/dist/filter/types.js +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/templates/filter/Controller.js +21 -0
- package/templates/filter/Controller.ts +24 -0
- package/templates/filter/fragment.xml +13 -0
- package/templates/filter/manifest.json +12 -0
|
@@ -26,7 +26,8 @@ export declare const contextParameter: EventHandlerTypescriptParameters;
|
|
|
26
26
|
* @param controllerSuffix - append controller suffix to new file
|
|
27
27
|
* @param typescript - create Typescript file instead of Javascript
|
|
28
28
|
* @param parameters - parameter configurations for the event handler
|
|
29
|
+
* @param templatePath - path to the template without the extension
|
|
29
30
|
* @returns {string} full namespace path to method
|
|
30
31
|
*/
|
|
31
|
-
export declare function applyEventHandlerConfiguration(fs: Editor, config: Partial<InternalCustomElement>, eventHandler: EventHandlerConfiguration | true | string, controllerSuffix?: boolean, typescript?: boolean, parameters?: EventHandlerTypescriptParameters): string;
|
|
32
|
+
export declare function applyEventHandlerConfiguration(fs: Editor, config: Partial<InternalCustomElement>, eventHandler: EventHandlerConfiguration | true | string, controllerSuffix?: boolean, typescript?: boolean, parameters?: EventHandlerTypescriptParameters, templatePath?: string): string;
|
|
32
33
|
//# sourceMappingURL=event-handler.d.ts.map
|
|
@@ -31,9 +31,10 @@ exports.contextParameter = {
|
|
|
31
31
|
* @param controllerSuffix - append controller suffix to new file
|
|
32
32
|
* @param typescript - create Typescript file instead of Javascript
|
|
33
33
|
* @param parameters - parameter configurations for the event handler
|
|
34
|
+
* @param templatePath - path to the template without the extension
|
|
34
35
|
* @returns {string} full namespace path to method
|
|
35
36
|
*/
|
|
36
|
-
function applyEventHandlerConfiguration(fs, config, eventHandler, controllerSuffix = false, typescript, parameters = exports.defaultParameter) {
|
|
37
|
+
function applyEventHandlerConfiguration(fs, config, eventHandler, controllerSuffix = false, typescript, parameters = exports.defaultParameter, templatePath = 'common/EventHandler') {
|
|
37
38
|
if (typeof eventHandler === 'string') {
|
|
38
39
|
// Existing event handler is passed - no need for file creation/update
|
|
39
40
|
return eventHandler;
|
|
@@ -41,8 +42,8 @@ function applyEventHandlerConfiguration(fs, config, eventHandler, controllerSuff
|
|
|
41
42
|
// New event handler function name - 'onPress' is default
|
|
42
43
|
let eventHandlerFnName = 'onPress';
|
|
43
44
|
let insertScript;
|
|
44
|
-
// By default - use config name for
|
|
45
|
-
let fileName =
|
|
45
|
+
// By default - use config name for created file name
|
|
46
|
+
let fileName = config.name;
|
|
46
47
|
if (typeof eventHandler === 'object') {
|
|
47
48
|
if (eventHandler.fnName) {
|
|
48
49
|
eventHandlerFnName = eventHandler.fnName;
|
|
@@ -56,10 +57,8 @@ function applyEventHandlerConfiguration(fs, config, eventHandler, controllerSuff
|
|
|
56
57
|
const ext = typescript ? 'ts' : 'js';
|
|
57
58
|
const controllerPath = (0, path_1.join)(config.path || '', `${fileName}${controllerSuffix ? '.controller' : ''}.${ext}`);
|
|
58
59
|
if (!fs.exists(controllerPath)) {
|
|
59
|
-
fs.copyTpl((0, templates_1.getTemplatePath)(
|
|
60
|
-
|
|
61
|
-
parameters
|
|
62
|
-
});
|
|
60
|
+
fs.copyTpl((0, templates_1.getTemplatePath)(`${templatePath}.${ext}`), controllerPath, Object.assign({ eventHandlerFnName,
|
|
61
|
+
parameters }, config));
|
|
63
62
|
}
|
|
64
63
|
else if (insertScript) {
|
|
65
64
|
// Read current file content
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { CustomFilter } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Add a custom filter to the filter bar of an existing UI5 application.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} basePath - the base path
|
|
7
|
+
* @param {CustomFilter} filterConfig - the custom filter configuration
|
|
8
|
+
* @param {Editor} [fs] - the memfs editor instance
|
|
9
|
+
* @returns {Promise<Editor>} the updated memfs editor instance
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateCustomFilter(basePath: string, filterConfig: CustomFilter, fs?: Editor): Editor;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateCustomFilter = void 0;
|
|
4
|
+
const mem_fs_1 = require("mem-fs");
|
|
5
|
+
const mem_fs_editor_1 = require("mem-fs-editor");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const ejs_1 = require("ejs");
|
|
8
|
+
const validate_1 = require("../common/validate");
|
|
9
|
+
const defaults_1 = require("../common/defaults");
|
|
10
|
+
const templates_1 = require("../templates");
|
|
11
|
+
const file_1 = require("../common/file");
|
|
12
|
+
const event_handler_1 = require("../common/event-handler");
|
|
13
|
+
/**
|
|
14
|
+
* Enhances the provided custom filter configuration with default data.
|
|
15
|
+
*
|
|
16
|
+
* @param {CustomFilter} data - a custom filter configuration object
|
|
17
|
+
* @param {string} manifestPath - path to the project's manifest.json
|
|
18
|
+
* @param {Manifest} manifest - the application manifest
|
|
19
|
+
* @returns enhanced configuration
|
|
20
|
+
*/
|
|
21
|
+
function enhanceConfig(data, manifestPath, manifest) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
// clone input
|
|
24
|
+
const config = data;
|
|
25
|
+
(0, defaults_1.setCommonDefaults)(config, manifestPath, manifest);
|
|
26
|
+
// set default values for requirement, language, the fragment file name
|
|
27
|
+
config.required = (_a = config.required) !== null && _a !== void 0 ? _a : false;
|
|
28
|
+
config.typescript = !!config.typescript;
|
|
29
|
+
config.fragmentFile = (_b = config.fragmentFile) !== null && _b !== void 0 ? _b : config.name;
|
|
30
|
+
if (config.eventHandler === true) {
|
|
31
|
+
config.eventHandler = {};
|
|
32
|
+
}
|
|
33
|
+
if (typeof config.eventHandler === 'object' && !config.eventHandler.fnName) {
|
|
34
|
+
config.eventHandler.fnName = 'filterItems';
|
|
35
|
+
}
|
|
36
|
+
return config;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add a custom filter to the filter bar of an existing UI5 application.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} basePath - the base path
|
|
42
|
+
* @param {CustomFilter} filterConfig - the custom filter configuration
|
|
43
|
+
* @param {Editor} [fs] - the memfs editor instance
|
|
44
|
+
* @returns {Promise<Editor>} the updated memfs editor instance
|
|
45
|
+
*/
|
|
46
|
+
function generateCustomFilter(basePath, filterConfig, fs) {
|
|
47
|
+
if (!fs) {
|
|
48
|
+
fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
|
|
49
|
+
}
|
|
50
|
+
(0, validate_1.validateBasePath)(basePath, fs);
|
|
51
|
+
const manifestPath = (0, path_1.join)(basePath, 'webapp/manifest.json');
|
|
52
|
+
const manifest = fs.readJSON(manifestPath);
|
|
53
|
+
const config = enhanceConfig(filterConfig, manifestPath, manifest);
|
|
54
|
+
// Apply event handler
|
|
55
|
+
if (config.eventHandler) {
|
|
56
|
+
config.eventHandler = (0, event_handler_1.applyEventHandlerConfiguration)(fs, config, config.eventHandler, false, config.typescript, event_handler_1.contextParameter, 'filter/Controller');
|
|
57
|
+
}
|
|
58
|
+
// enhance manifest with the filter definition and controller reference
|
|
59
|
+
const filters = enhanceManifestAndGetFiltersReference(manifest);
|
|
60
|
+
Object.assign(filters, JSON.parse((0, ejs_1.render)(fs.read((0, templates_1.getTemplatePath)(`filter/manifest.json`)), config, {})));
|
|
61
|
+
fs.writeJSON(manifestPath, manifest, undefined, (0, file_1.getJsonSpace)(fs, manifestPath, filterConfig.tabInfo));
|
|
62
|
+
// create a fragment file
|
|
63
|
+
const fragmentPath = (0, path_1.join)(config.path, `${config.fragmentFile}.fragment.xml`);
|
|
64
|
+
fs.copyTpl((0, templates_1.getTemplatePath)(`filter/fragment.xml`), fragmentPath, config);
|
|
65
|
+
return fs;
|
|
66
|
+
}
|
|
67
|
+
exports.generateCustomFilter = generateCustomFilter;
|
|
68
|
+
/**
|
|
69
|
+
* Enhance the target object in the manifest with the required nested objects and return a reference to it.
|
|
70
|
+
*
|
|
71
|
+
* @param {Manifest} manifest - the application manifest
|
|
72
|
+
* @returns Filters object of the first page
|
|
73
|
+
*/
|
|
74
|
+
function enhanceManifestAndGetFiltersReference(manifest) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
var _c, _d, _e, _f;
|
|
77
|
+
if ((_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.targets) {
|
|
78
|
+
const pages = manifest['sap.ui5'].routing.targets;
|
|
79
|
+
const lrPage = Object.values(pages)[0];
|
|
80
|
+
lrPage.options || (lrPage.options = {});
|
|
81
|
+
(_c = lrPage.options).settings || (_c.settings = {});
|
|
82
|
+
(_d = lrPage.options.settings).controlConfiguration || (_d.controlConfiguration = {});
|
|
83
|
+
(_e = lrPage.options.settings.controlConfiguration)['@com.sap.vocabularies.UI.v1.SelectionFields'] || (_e['@com.sap.vocabularies.UI.v1.SelectionFields'] = {});
|
|
84
|
+
(_f = lrPage.options.settings.controlConfiguration['@com.sap.vocabularies.UI.v1.SelectionFields']).filterFields || (_f.filterFields = {});
|
|
85
|
+
return lrPage.options.settings.controlConfiguration['@com.sap.vocabularies.UI.v1.SelectionFields'].filterFields;
|
|
86
|
+
}
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { FilterField } from '../building-block/types';
|
|
2
|
+
import type { CustomElement, InternalCustomElement, Position, EventHandler } from '../common/types';
|
|
3
|
+
/**
|
|
4
|
+
* Properties to create a custom filter.
|
|
5
|
+
*/
|
|
6
|
+
export interface CustomFilter extends CustomElement, EventHandler {
|
|
7
|
+
/**
|
|
8
|
+
* Filter label in the application.
|
|
9
|
+
*/
|
|
10
|
+
label: string;
|
|
11
|
+
/**
|
|
12
|
+
* Property used to filter by.
|
|
13
|
+
*/
|
|
14
|
+
property: string;
|
|
15
|
+
/**
|
|
16
|
+
* ID of the filter comboBox in the embedded filter XML view.
|
|
17
|
+
*/
|
|
18
|
+
controlID: string;
|
|
19
|
+
/**
|
|
20
|
+
* Existing filter XML fragment file name without '.fragment.xml' suffix.
|
|
21
|
+
* If not set, is equal to the name specified in the config.
|
|
22
|
+
*/
|
|
23
|
+
fragmentFile?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the required property of the custom filter.
|
|
26
|
+
*/
|
|
27
|
+
required?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Position of a custom filter relative to an anchor element.
|
|
30
|
+
*/
|
|
31
|
+
position?: Position;
|
|
32
|
+
/**
|
|
33
|
+
* Specifies whether the controller file is generated in Typescript instead of Javascript.
|
|
34
|
+
*/
|
|
35
|
+
typescript?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Represents options available to a page in the manifest.json
|
|
39
|
+
*/
|
|
40
|
+
export interface PageOptions {
|
|
41
|
+
options?: {
|
|
42
|
+
settings?: {
|
|
43
|
+
controlConfiguration?: {
|
|
44
|
+
['@com.sap.vocabularies.UI.v1.SelectionFields']?: {
|
|
45
|
+
filterFields?: FilterField | {};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export type InternalCustomFilter = CustomFilter & InternalCustomElement;
|
|
52
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export { CustomTableColumn } from './column/types';
|
|
|
6
6
|
export { generateCustomColumn } from './column';
|
|
7
7
|
export { CustomSection, CustomSubSection } from './section/types';
|
|
8
8
|
export { generateCustomSection, generateCustomSubSection } from './section';
|
|
9
|
+
export { CustomFilter } from './filter/types';
|
|
10
|
+
export { generateCustomFilter } from './filter';
|
|
9
11
|
export { CustomView } from './view/types';
|
|
10
12
|
export { generateCustomView } from './view';
|
|
11
13
|
export { enableFPM, FPMConfig } from './app';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateControllerExtension = exports.ControllerExtensionPageType = exports.generateBuildingBlock = exports.BuildingBlockType = exports.validateVersion = exports.validateBasePath = exports.enableFPM = exports.generateCustomView = exports.generateCustomSubSection = exports.generateCustomSection = exports.generateCustomColumn = exports.generateCustomAction = exports.TargetControl = exports.generateListReport = exports.generateObjectPage = exports.generateCustomPage = void 0;
|
|
3
|
+
exports.generateControllerExtension = exports.ControllerExtensionPageType = exports.generateBuildingBlock = exports.BuildingBlockType = exports.validateVersion = exports.validateBasePath = exports.enableFPM = exports.generateCustomView = exports.generateCustomFilter = exports.generateCustomSubSection = exports.generateCustomSection = exports.generateCustomColumn = exports.generateCustomAction = exports.TargetControl = exports.generateListReport = exports.generateObjectPage = exports.generateCustomPage = void 0;
|
|
4
4
|
var page_1 = require("./page");
|
|
5
5
|
Object.defineProperty(exports, "generateCustomPage", { enumerable: true, get: function () { return page_1.generateCustomPage; } });
|
|
6
6
|
Object.defineProperty(exports, "generateObjectPage", { enumerable: true, get: function () { return page_1.generateObjectPage; } });
|
|
@@ -14,6 +14,8 @@ Object.defineProperty(exports, "generateCustomColumn", { enumerable: true, get:
|
|
|
14
14
|
var section_1 = require("./section");
|
|
15
15
|
Object.defineProperty(exports, "generateCustomSection", { enumerable: true, get: function () { return section_1.generateCustomSection; } });
|
|
16
16
|
Object.defineProperty(exports, "generateCustomSubSection", { enumerable: true, get: function () { return section_1.generateCustomSubSection; } });
|
|
17
|
+
var filter_1 = require("./filter");
|
|
18
|
+
Object.defineProperty(exports, "generateCustomFilter", { enumerable: true, get: function () { return filter_1.generateCustomFilter; } });
|
|
17
19
|
var view_1 = require("./view");
|
|
18
20
|
Object.defineProperty(exports, "generateCustomView", { enumerable: true, get: function () { return view_1.generateCustomView; } });
|
|
19
21
|
var app_1 = require("./app");
|
package/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
sap.ui.define(["sap/ui/model/Filter", "sap/ui/model/FilterOperator"], function(Filter, FilterOperator) {
|
|
2
|
+
"use strict";
|
|
3
|
+
return {
|
|
4
|
+
<%- eventHandlerFnName %>: function(sValue) {
|
|
5
|
+
switch (sValue) {
|
|
6
|
+
case "0":
|
|
7
|
+
return new Filter({ path: "<%- property %>", operator: FilterOperator.LT, value1: 100 });
|
|
8
|
+
case "1":
|
|
9
|
+
return new Filter({
|
|
10
|
+
filters: [
|
|
11
|
+
new Filter({ path: "<%- property %>", operator: FilterOperator.GT, value1: 100 }),
|
|
12
|
+
new Filter({ path: "<%- property %>", operator: FilterOperator.LT, value1: 500 })
|
|
13
|
+
],
|
|
14
|
+
and: true
|
|
15
|
+
});
|
|
16
|
+
case "2":
|
|
17
|
+
return new Filter({ path: "<%- property %>", operator: FilterOperator.GT, value1: 500 });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Filter from 'sap/ui/model/Filter';
|
|
2
|
+
import FilterOperator from 'sap/ui/model/FilterOperator';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom filter
|
|
6
|
+
* @param sValue selected filter item
|
|
7
|
+
* @returns new Filter
|
|
8
|
+
*/
|
|
9
|
+
export function <%- eventHandlerFnName %>(value: string) {
|
|
10
|
+
switch (value) {
|
|
11
|
+
case "0":
|
|
12
|
+
return new Filter({ path: "<%- property %>", operator: FilterOperator.LT, value1: 100 });
|
|
13
|
+
case "1":
|
|
14
|
+
return new Filter({
|
|
15
|
+
filters: [
|
|
16
|
+
new Filter({ path: "<%- property %>", operator: FilterOperator.GT, value1: 100 }),
|
|
17
|
+
new Filter({ path: "<%- property %>", operator: FilterOperator.LT, value1: 500 })
|
|
18
|
+
],
|
|
19
|
+
and: true
|
|
20
|
+
});
|
|
21
|
+
case "2":
|
|
22
|
+
return new Filter({ path: "<%- property %>", operator: FilterOperator.GT, value1: 500 });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m">
|
|
2
|
+
<ComboBox
|
|
3
|
+
id="<%- controlID %>"
|
|
4
|
+
core:require="{handler: '<%- ns.split('.').join('/') %>/<%- name %>'}"
|
|
5
|
+
selectedKey="{path: 'filterValues>', type: 'sap.fe.macros.filter.type.Value', formatOptions: { operator: '<%- (typeof eventHandler === 'string' ? eventHandler : `${ns}.${name}.${locals.eventHandler?.fnName ?? 'filterItems'}`) %>' }}"
|
|
6
|
+
>
|
|
7
|
+
<items>
|
|
8
|
+
<core:Item key="0" text="Item1"/>
|
|
9
|
+
<core:Item key="1" text="Item2"/>
|
|
10
|
+
<core:Item key="2" text="Item3"/>
|
|
11
|
+
</items>
|
|
12
|
+
</ComboBox>
|
|
13
|
+
</core:FragmentDefinition>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"<%- name %>": {
|
|
3
|
+
"label": "<%- label %>",
|
|
4
|
+
"property": "<%- property %>",
|
|
5
|
+
"template": "<%- `${ns}.${fragmentFile}` %>",
|
|
6
|
+
"required": <%- required -%><%if (typeof position !== 'undefined') {%>,
|
|
7
|
+
"position": {
|
|
8
|
+
"placement": "<%- position.placement %>"<%if (position.anchor !== undefined) {%>,
|
|
9
|
+
"anchor": "<%- position.anchor %>"<% } %>
|
|
10
|
+
}<% } %>
|
|
11
|
+
}
|
|
12
|
+
}
|