Commit 91ffe3fa authored by Vincent Horváth's avatar Vincent Horváth

fixed for init new project

parent a9971a3b
......@@ -21,6 +21,7 @@ public class ComponentGenerator extends AngularGenerator {
private static final String KEY_CLASS = "class";
private static final String KEY_STYLE = "style";
private static final String KEY_TEMPLATE = "template";
private static final String KEY_BFI_TEMPLATE = "bfi-template";
protected static final String POSTFIX = "Generate";
public ComponentGenerator(Model model, String projectRoot) {
......@@ -55,6 +56,12 @@ public class ComponentGenerator extends AngularGenerator {
return templateHelper.getTemplate(KEY_TEMPLATE);
}
@GeneratorSaveTo
@GeneratorMethod(KEY_BFI_TEMPLATE)
public ST bfiTemplate() {
return templateHelper.getTemplate(KEY_BFI_TEMPLATE);
}
public static String getPOSTFIX() {
return POSTFIX;
}
......@@ -67,6 +74,8 @@ public class ComponentGenerator extends AngularGenerator {
return name + File.separator + name + ".component.generate.html";
} else if (KEY_STYLE.equals(key)) {
return name + File.separator + name + ".component." + FILE_STYLE_EXTENSIONS;
}else if (KEY_BFI_TEMPLATE.equals(key)) {
return name + File.separator + name + ".component.bfi.html";
}
return null;
}
......
......@@ -12,6 +12,7 @@ import sk.tuke.bfi.core.generator.annotation.GeneratorSaveTo;
import java.util.HashMap;
import java.util.Map;
import static sk.tuke.bfi.core.entity.model.FieldType.MANY_TO_MANY;
import static sk.tuke.bfi.core.entity.model.FieldType.ONE_TO_MANY;
import static sk.tuke.bfi.core.entity.model.FieldType.ONE_TO_ONE;
......@@ -36,23 +37,34 @@ public class EntityOverwriteGenerator extends AngularGenerator {
StringBuffer fieldBuffer = new StringBuffer();
StringBuffer mapBuffer = new StringBuffer();
Boolean isFirst = true;
String importsEntity ="";
for (Map.Entry<String, BaseEntity> entityEntry : models.entrySet()) {
String name = entityEntry.getKey();
importsEntity +="import {"+name+"} from '../"+name+"';\n";
}
for (Map.Entry<String, BaseEntity> entityEntry : models.entrySet()) {
Model baseEntity = (Model) entityEntry.getValue();
String name = entityEntry.getKey();
if (isFirst) {
template.add("classes", "");
template.add("imports", importsEntity);
} else {
ST tmpTemplate = template;
template = templateHelper.getTemplate(KEY_CLASS);
template.add("classes", tmpTemplate.render());
template.add("imports", "");
}
template.add("className", name);
for (Field field : baseEntity.getFields()) {
String type;
if (field.getType() == ONE_TO_ONE) {
type = field.getRelationShip().getName()+"Generate";
type = field.getRelationShip().getName();
} else if (field.getType() == ONE_TO_MANY) {
type = field.getRelationShip().getName()+"Generate[]";
type = field.getRelationShip().getName()+"[]";
} else if (field.getType() == MANY_TO_MANY) {
type = field.getRelationShip().getName()+"[]";
} else {
type = jsMapperHelper.get(field.getType().toString());
if (type == null) {
......
......@@ -33,10 +33,13 @@ public class InputPreprocessor extends AngularPreprocessor {
switch (field.getEditor()) {
case STRING:
inputElement = getInputText(field, model);
break;
case TEXTAREA:
inputElement = getInputTextarea(field, model);
break;
case SELECT:
inputElement = getInputSelect(field, model);
break;
case MULTI_SELECT:
inputElement = getInputMultiselect(field, model);
}
......
import { Component, OnInit } from '@angular/core';
import {#className#DataService} from '../../services/data/generate/#className#DataServiceGenerate';
import {#className#} from '../../entities/#className#';
@Component({
selector: 'app-#selector#',
......
#imports#
#classes#
export interface #className#Generate {
id: number;
......
......@@ -139,13 +139,13 @@ public class GeneratorImpl implements sk.tuke.bfi.core.generator.Generator {
LOGGER.info("Start generation for frontend.");
for (Map.Entry<String, BaseEntity> entityEntry : frontendInterpreter.getEntities().entrySet()) {
frontendInterpreter.setEntity(entityEntry.getValue());
if( frontendInterpreter.getFile() !=null){
if (frontendInterpreter.getFile() != null) {
frontendInterpreter.beforeGenerate();
}
generateBackendOneToOne(frontendInterpreter);
}
if( frontendInterpreter.getFile() ==null){
if (frontendInterpreter.getFile() == null) {
return;
}
......
......@@ -125,8 +125,14 @@ public abstract class BaseInterpreter implements BaseInterface {
}
public void createProject() {
final File project = new File(getProjectRoot());
if (project.exists() && project.isDirectory()) {
LOGGER.warn("Project is exist " + project.getAbsolutePath());
return;
}
final FileDownloaderHelper fileDownloaderHelper = new FileDownloaderHelper();
final String parentDirectory = new File(getProjectRoot()).getParent();
final String parentDirectory = project.getParent();
final File file;
try {
file = fileDownloaderHelper.download(patternUrl);
......@@ -136,6 +142,7 @@ public abstract class BaseInterpreter implements BaseInterface {
}
File projectFile = new File(parentDirectory + File.separator + patternName);
projectFile.renameTo(new File(getProjectRoot()));
LOGGER.info("Created project " + project.getAbsolutePath());
try {
fileDownloaderHelper.clean();
} catch (IOException e) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment