use of com.twinsoft.convertigo.beans.ngx.components.UISharedComponent in project convertigo by convertigo.
the class SharedComponentWizard method sharedComponentAlreadyExists.
protected boolean sharedComponentAlreadyExists(String sharedComponentName) {
UIComponent uic = (UIComponent) getFirstInList();
MobileApplication ma = uic.getProject().getMobileApplication();
ApplicationComponent app = (ApplicationComponent) ma.getApplicationComponent();
for (UISharedComponent uisc : app.getSharedComponentList()) {
if (uisc.getName().equals(sharedComponentName)) {
return true;
}
}
return false;
}
use of com.twinsoft.convertigo.beans.ngx.components.UISharedComponent in project convertigo by convertigo.
the class DirectoryWatcherService method hasComp.
private boolean hasComp(String compName) {
MobileApplication mobileApplication = project.getMobileApplication();
ApplicationComponent app = (ApplicationComponent) mobileApplication.getApplicationComponent();
for (UISharedComponent uisc : app.getSharedComponentList()) {
if (compName.equals(uisc.getName().toLowerCase())) {
return true;
}
}
return false;
}
use of com.twinsoft.convertigo.beans.ngx.components.UISharedComponent in project convertigo by convertigo.
the class NgxBuilder method writeFunctionTempTsFile.
@Override
public void writeFunctionTempTsFile(final IUIComponent uiComponent, String functionMarker) throws EngineException {
UIComponent uic = (UIComponent) uiComponent;
try {
IScriptComponent main = uic.getMainScriptComponent();
if (main != null) {
String tempTsFileName = null, tsContent = null;
File tempTsDir = null;
UIActionStack sharedAction = null;
if (main instanceof ApplicationComponent) {
sharedAction = uic.getSharedAction();
tempTsDir = sharedAction == null ? appDir : servicesDir;
tempTsFileName = sharedAction == null ? "app.component.function.temp.ts" : "actionbeans.service.function.temp.ts";
File appTsFile = sharedAction == null ? new File(appDir, "app.component.ts") : new File(servicesDir, "actionbeans.service.ts");
synchronized (writtenFiles) {
if (writtenFiles.contains(appTsFile)) {
File appTsFileTmp = toTmpFile(appTsFile);
if (appTsFileTmp.exists()) {
appTsFile = appTsFileTmp;
}
}
}
tsContent = FileUtils.readFileToString(appTsFile, "UTF-8");
}
if (main instanceof PageComponent) {
PageComponent page = (PageComponent) main;
String pageName = page.getName();
tempTsDir = pageDir(page);
tempTsFileName = pageName.toLowerCase() + ".function.temp.ts";
if (page.isEnabled()) {
File pageTsFile = new File(tempTsDir, pageName.toLowerCase() + ".ts");
synchronized (writtenFiles) {
if (writtenFiles.contains(pageTsFile)) {
File pageTsFileTmp = toTmpFile(pageTsFile);
if (pageTsFileTmp.exists()) {
pageTsFile = pageTsFileTmp;
}
}
}
tsContent = FileUtils.readFileToString(pageTsFile, "UTF-8");
} else {
tsContent = getPageTsContent(page);
}
}
if (main instanceof UISharedComponent) {
UISharedComponent comp = (UISharedComponent) main;
String compName = comp.getName();
tempTsDir = compDir(comp);
tempTsFileName = compName.toLowerCase() + ".function.temp.ts";
boolean isEnabled = true;
if (isEnabled) {
File compTsFile = new File(tempTsDir, compName.toLowerCase() + ".ts");
synchronized (writtenFiles) {
if (writtenFiles.contains(compTsFile)) {
File compTsFileTmp = toTmpFile(compTsFile);
if (compTsFileTmp.exists()) {
compTsFile = compTsFileTmp;
}
}
}
tsContent = FileUtils.readFileToString(compTsFile, "UTF-8");
} else {
tsContent = getCompTsContent(comp);
}
}
// Replace all Begin_c8o_XXX, End_c8o_XXX except for functionMarker
Pattern pattern = Pattern.compile("/\\*Begin_c8o_(.+)\\*/");
Matcher matcher = pattern.matcher(tsContent);
while (matcher.find()) {
String markerId = matcher.group(1);
if (!markerId.equals(functionMarker)) {
String beginMarker = "/*Begin_c8o_" + markerId + "*/";
String endMarker = "/*End_c8o_" + markerId + "*/";
tsContent = tsContent.replace(beginMarker, "//---" + markerId + "---");
tsContent = tsContent.replace(endMarker, "//---" + markerId + "---");
}
}
// CustomAction : reduce code lines (action's function only)
if (tempTsDir != null && tempTsFileName != null) {
if (uiComponent instanceof UICustomAction) {
UICustomAction uica = (UICustomAction) uic;
tempTsFileName = "CTS" + uica.priority + ".temp.ts";
int index = tsContent.indexOf("export class ");
if (index != -1) {
String classType = uica.getMainClassType();
String sImport = "";
if (main instanceof ApplicationComponent) {
if (uic.getSharedAction() == null) {
sImport = "import { " + classType + " } from './app.component';";
}
} else if (main instanceof PageComponent) {
sImport = "import { " + classType + " } from './" + classType.toLowerCase() + "';";
} else if (main instanceof UISharedComponent) {
sImport = "import { " + classType + " } from './" + classType.toLowerCase() + "';";
}
int i = tsContent.indexOf("{", index);
tsContent = tsContent.substring(0, i + 1) + System.lineSeparator() + uica.getActionCode() + System.lineSeparator() + "}" + System.lineSeparator();
tsContent = tsContent.replace("@Component", sImport + System.lineSeparator() + "@Component");
tsContent = tsContent.replace("export class " + classType + " ", "export class _Type_ ");
}
}
}
// Write file (do not need delay)
tsContent = LsPattern.matcher(tsContent).replaceAll(System.lineSeparator());
File tempTsFile = new File(tempTsDir, tempTsFileName);
FileUtils.write(tempTsFile, tsContent, "UTF-8");
}
} catch (Exception e) {
throw new EngineException("Unable to write function temp ts file", e);
}
}
use of com.twinsoft.convertigo.beans.ngx.components.UISharedComponent in project convertigo by convertigo.
the class NgxBuilder method writeAppServiceTs.
private void writeAppServiceTs(ApplicationComponent app) throws EngineException {
try {
if (app != null) {
Map<String, String> action_ts_imports = new HashMap<>();
Map<String, String> action_ts_functions = new HashMap<>();
// App contributors
for (Contributor contributor : app.getContributors()) {
contributor.forContainer(app, () -> {
action_ts_imports.putAll(contributor.getActionTsImports());
action_ts_functions.putAll(contributor.getActionTsFunctions());
});
}
// Shared components
for (UISharedComponent comp : app.getSharedComponentList()) {
if (comp.isRegular()) {
List<Contributor> contributors = comp.getContributors();
for (Contributor contributor : contributors) {
contributor.forContainer(app, () -> {
action_ts_imports.putAll(contributor.getActionTsImports());
action_ts_functions.putAll(contributor.getActionTsFunctions());
});
}
}
}
// Pages contributors
List<PageComponent> pages = forceEnable ? app.getPageComponentList() : getEnabledPages(app);
for (PageComponent page : pages) {
synchronized (page) {
List<Contributor> contributors = page.getContributors();
for (Contributor contributor : contributors) {
contributor.forContainer(app, () -> {
action_ts_imports.putAll(contributor.getActionTsImports());
action_ts_functions.putAll(contributor.getActionTsFunctions());
});
}
}
}
String c8o_ActionTsImports = "";
for (String comp : action_ts_imports.keySet()) {
if (!getTplServiceActionTsImports().containsKey(comp)) {
if (comp.indexOf(" as ") == -1) {
String comPath = action_ts_imports.get(comp).replace("./pages", "../pages");
c8o_ActionTsImports += "import { " + comp + " } from '" + comPath + "';" + System.lineSeparator();
} else {
c8o_ActionTsImports += "import " + comp + " from '" + action_ts_imports.get(comp) + "';" + System.lineSeparator();
}
}
}
String c8o_ActionTsFunctions = System.lineSeparator();
for (String function : action_ts_functions.values()) {
c8o_ActionTsFunctions += function + System.lineSeparator();
}
File appServiceTpl = new File(ionicTplDir, "src/app/services/actionbeans.service.ts");
String mContent = FileUtils.readFileToString(appServiceTpl, "UTF-8");
mContent = mContent.replaceAll("/\\*\\=c8o_ActionTsImports\\*/", Matcher.quoteReplacement(c8o_ActionTsImports));
mContent = mContent.replaceAll("/\\*\\=c8o_ActionTsFunctions\\*/", Matcher.quoteReplacement(c8o_ActionTsFunctions));
File appServiceTsFile = new File(servicesDir, "actionbeans.service.ts");
writeFile(appServiceTsFile, mContent, "UTF-8");
if (initDone) {
Engine.logEngine.trace("(MobileBuilder) Ionic service ts file generated for 'app'");
}
}
} catch (Exception e) {
throw new EngineException("Unable to write ionic app service ts file", e);
}
}
use of com.twinsoft.convertigo.beans.ngx.components.UISharedComponent in project convertigo by convertigo.
the class NgxBuilder method writeAppPackageJson.
private void writeAppPackageJson(ApplicationComponent app) throws EngineException {
try {
if (app != null) {
Map<String, String> pkg_dependencies = new HashMap<>();
// Menus contributors
for (Contributor contributor : app.getContributors()) {
pkg_dependencies.putAll(contributor.getPackageDependencies());
}
// Pages contributors
List<PageComponent> pages = forceEnable ? app.getPageComponentList() : getEnabledPages(app);
for (PageComponent page : pages) {
synchronized (page) {
List<Contributor> contributors = page.getContributors();
for (Contributor contributor : contributors) {
pkg_dependencies.putAll(contributor.getPackageDependencies());
}
}
}
// Shared components contributors
for (UISharedComponent comp : app.getSharedComponentList()) {
if (comp.isRegular()) {
List<Contributor> contributors = comp.getContributors();
for (Contributor contributor : contributors) {
pkg_dependencies.putAll(contributor.getPackageDependencies());
}
}
}
File appPkgJsonTpl = new File(ionicTplDir, "package.json");
String mContent = FileUtils.readFileToString(appPkgJsonTpl, "UTF-8");
mContent = mContent.replaceAll("\\.\\./DisplayObjects", "../../DisplayObjects");
mContent = mContent.replaceAll("\\{\\{c8o_project\\}\\}", app.getProject().getName());
JSONObject jsonPackage = new JSONObject(mContent);
JSONObject jsonDependencies = jsonPackage.getJSONObject("dependencies");
for (String pkg : pkg_dependencies.keySet()) {
jsonDependencies.put(pkg, pkg_dependencies.get(pkg));
if (!existPackage(pkg)) {
setNeedPkgUpdate(true);
}
}
boolean addNode = !jsonDependencies.has("@types/node");
if (addNode) {
try {
String version = new JSONObject(FileUtils.readFileToString(new File(ionicTplDir, "version.json"), "utf-8")).getString("version");
addNode = version.matches("7\\.[0-7]\\..*");
} catch (Exception e) {
}
if (addNode) {
jsonDependencies.put("@types/node", "12.0.10");
}
}
File appPkgJson = new File(ionicWorkDir, "package.json");
writeFile(appPkgJson, jsonPackage.toString(2), "UTF-8");
if (initDone) {
Engine.logEngine.trace("(MobileBuilder) Ionic package json file generated");
}
}
} catch (Exception e) {
throw new EngineException("Unable to write ionic package json file", e);
}
}
Aggregations