From b0f7b2f5edc242a1d8e3935153e81ed2d705ead5 Mon Sep 17 00:00:00 2001
From: Henloh <56073307+henloh@users.noreply.github.com>
Date: Thu, 8 Sep 2022 15:09:50 +0200
Subject: [PATCH 1/3] ui5-ts-app added subgenerator newview for TS
---
generators/newview/index.js | 37 ++++++++++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/generators/newview/index.js b/generators/newview/index.js
index dc9ce47..3368802 100644
--- a/generators/newview/index.js
+++ b/generators/newview/index.js
@@ -2,6 +2,8 @@ const Generator = require("yeoman-generator");
const fileaccess = require("../../helpers/fileaccess");
const utils = require("../utils");
+const AppTypes = {ts: "ts", js: "js"};
+
module.exports = class extends Generator {
static displayName = "Add a new view to an existing project";
@@ -47,6 +49,13 @@ module.exports = class extends Generator {
name: "createcontroller",
message: "Would you like to create a corresponding controller as well?"
},
+ {
+ type: "list",
+ name: "apptype",
+ message: "Which app type do you use?",
+ choices: [AppTypes.js, AppTypes.ts],
+ default: AppTypes.ts
+ },
{
type: "confirm",
name: "addPO",
@@ -54,7 +63,12 @@ module.exports = class extends Generator {
default: false
}
];
-
+ var namespace = "com.myorg";
+ var application = "myUI5App";
+ try {
+ namespace = this.config._cachedStore["generator-ui5-ts-app"].namespace;
+ application = this.config._cachedStore["generator-ui5-ts-app"].application;
+ } catch (error) { }
if (!this.config.getAll().viewtype) {
aPrompt = aPrompt.concat([
{
@@ -63,7 +77,7 @@ module.exports = class extends Generator {
message:
"Seems like this project has not been generated with Easy-UI5. Please enter the name your project.",
validate: utils.validateAlhpaNumericStartingWithLetter,
- default: "myUI5App"
+ default: application
},
{
type: "input",
@@ -75,7 +89,7 @@ module.exports = class extends Generator {
}
return "Please use alpha numeric characters and dots only for the namespace.";
},
- default: "com.myorg"
+ default: namespace
},
{
type: "list",
@@ -97,6 +111,7 @@ module.exports = class extends Generator {
this.options.oneTimeConfig = this.config.getAll();
this.options.oneTimeConfig.viewname = answers.viewname;
this.options.oneTimeConfig.createcontroller = answers.createcontroller;
+ this.options.oneTimeConfig.apptype = answers.apptype;
this.options.oneTimeConfig.addToRoute = answers.addToRoute;
this.options.oneTimeConfig.modulename = answers.modulename || (!!modules ? modules[0] : "");
@@ -131,14 +146,22 @@ module.exports = class extends Generator {
}
async writing() {
- const sViewFileName = "webapp/view/$ViewName.view.$ViewEnding";
- const sControllerFileName = "webapp/controller/$ViewName.controller.js";
+ const sAppType = this.options.oneTimeConfig.apptype;
+ var Path;
+ if (sAppType === AppTypes.js) {
+ Path = "webapp"
+ } else {
+ Path = "src"
+ }
+
+ const sViewFileName = Path + "/view/$ViewName.view.$ViewEnding";
+ const sControllerFileName = Path + "/controller/$ViewName.controller." + sAppType;
const sViewType = this.options.oneTimeConfig.viewtype;
const sViewName = this.options.oneTimeConfig.viewname;
const sModuleName = this.options.oneTimeConfig.modulename;
this.options.oneTimeConfig.isSubgeneratorCall = this.options.isSubgeneratorCall;
- const bBaseControllerExists = this.fs.exists(sModuleName + "/webapp/controller/BaseController.js");
+ const bBaseControllerExists = this.fs.exists(sModuleName + `/${Path}/controller/BaseController.${sAppType}`);
var sControllerToExtend = "sap/ui/core/mvc/Controller";
if (bBaseControllerExists) {
sControllerToExtend = this.options.oneTimeConfig.appURI + "/controller/BaseController";
@@ -168,7 +191,7 @@ module.exports = class extends Generator {
}
if (this.options.oneTimeConfig.addToRoute) {
- await fileaccess.manipulateJSON.call(this, "/" + sModuleName + "/webapp/manifest.json", function (json) {
+ await fileaccess.manipulateJSON.call(this, `/${sModuleName}/${Path}/manifest.json`, function (json) {
const ui5Config = json["sap.ui5"];
const targetName = "Target" + sViewName;
From 9258aa78a021bdb72640b10484bd9c43cd28ee0d Mon Sep 17 00:00:00 2001
From: Henloh <56073307+henloh@users.noreply.github.com>
Date: Thu, 8 Sep 2022 15:15:04 +0200
Subject: [PATCH 2/3] ui5-ts-app added subgenerator newview for TS
---
.../src/controller/$ViewName.controller.ts | 15 ++++++
.../src/view/$ViewName.view.$ViewEnding | 47 +++++++++++++++++++
2 files changed, 62 insertions(+)
create mode 100644 generators/newview/templates/src/controller/$ViewName.controller.ts
create mode 100644 generators/newview/templates/src/view/$ViewName.view.$ViewEnding
diff --git a/generators/newview/templates/src/controller/$ViewName.controller.ts b/generators/newview/templates/src/controller/$ViewName.controller.ts
new file mode 100644
index 0000000..1c74a82
--- /dev/null
+++ b/generators/newview/templates/src/controller/$ViewName.controller.ts
@@ -0,0 +1,15 @@
+import MessageBox from "sap/m/MessageBox";
+import BaseController from "./BaseController";
+import formatter from "../model/formatter";
+
+/**
+ * @namespace <%=appId%>.controller
+ */
+export default class <%=viewname%> extends BaseController {
+ private formatter = formatter;
+
+ public sayHello() : void {
+ MessageBox.show("Hello World!");
+ }
+
+}
\ No newline at end of file
diff --git a/generators/newview/templates/src/view/$ViewName.view.$ViewEnding b/generators/newview/templates/src/view/$ViewName.view.$ViewEnding
new file mode 100644
index 0000000..18cd681
--- /dev/null
+++ b/generators/newview/templates/src/view/$ViewName.view.$ViewEnding
@@ -0,0 +1,47 @@
+<% if (viewtype === 'XML') { %>
+
+
+
+<% } if (viewtype === 'HTML') { -%>
+
+
+<% } if (viewtype === 'JSON') { -%>
+{
+ "Type": "sap.ui.core.mvc.JSONView",
+ "controllerName": "<%=appId%>.controller.<%=viewname%>",
+ "content": [{
+ "Type": "sap.m.App",
+ "id": "<%= isSubgeneratorCall ? 'idAppControl' : viewname %>",
+ "pages": [{
+ "Type": "sap.m.Page",
+ "title": "{i18n>title}",
+ "content": []
+ }]
+ }]
+}<% } if (viewtype === 'JS') { -%>
+sap.ui.define([ ], function() {
+"use strict";
+ sap.ui.jsview("<%=appId%>.view.<%=viewname%>", {
+
+ getControllerName: function () {
+ return "<%=appId%>.controller.<%=viewname%>";
+ },
+
+ createContent: function () {
+ return new sap.m.App(this.createId("<%= isSubgeneratorCall ? 'idAppControl' : viewname %>"), {
+ pages: new sap.m.Page({
+ title: "{i18n>title}",
+ content: []
+ })
+ });
+ }
+ });
+});<% } -%>
From ed6c0a505b827feabd4f8e0e7358581beac5561c Mon Sep 17 00:00:00 2001
From: Henloh <56073307+henloh@users.noreply.github.com>
Date: Thu, 8 Sep 2022 17:46:01 +0200
Subject: [PATCH 3/3] ui5-ts-app added subgenerator newview for TS src