Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New view for ts #59

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions generators/newview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -47,14 +49,26 @@ 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",
message: "Do you want to add an OPA5 page object?",
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([
{
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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] : "");

Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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!");
}

}
47 changes: 47 additions & 0 deletions generators/newview/templates/src/view/$ViewName.view.$ViewEnding
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<% if (viewtype === 'XML') { %> <mvc:View controllerName="<%=appId%>.controller.<%=viewname%>"
displayBlock="true"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<Page title="{i18n>title}" id="<%= isSubgeneratorCall ? 'idAppControl' : viewname %>" >
<content></content>
</Page>
</mvc:View><% } if (viewtype === 'HTML') { -%>
<template data-controller-name="<%=appId%>.controller.<%=viewname%>">
<div data-sap-ui-type="sap.m.App" id="<%= isSubgeneratorCall ? 'idAppControl' : viewname %>" >
<div data-sap-ui-type="sap.m.Page" data-title="{i18n>title}">
<div data-sap-ui-aggregation="content">
</div>
</div>
</div>
</template><% } 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: []
})
});
}
});
});<% } -%>