@@ -5,13 +5,13 @@ scriptContent:
55 → : |
66 '/*Begin_c8o_CompImport*/
77 import { C8Oforms_PopOverSourceCompletion } from ''../c8oforms.popoversourcecompletion/c8oforms-popoversourcecompletion'';
8- import {KeyValue} from ''@angular/common'';
8+ import { KeyValue } from ''@angular/common'';
99 import { environment } from ''src/environments/environment'';
1010 /*End_c8o_CompImport*/
1111 /*Begin_c8o_CompDeclaration*/
1212 /*End_c8o_CompDeclaration*/
1313 /*Begin_c8o_CompConstructor*/
14- window["dtse"]= this;
14+ window["dtse"] = this;
1515 /*End_c8o_CompConstructor*/
1616 /*Begin_c8o_CompInitialization*/
1717 //this.buildFilters();
@@ -31,63 +31,144 @@ scriptContent:
3131 /*Begin_c8o_CompAfterViewChecked*/
3232 /*End_c8o_CompAfterViewChecked*/
3333 /*Begin_c8o_CompFunction*/
34- public isJSON(el){
35- try{
34+ public isJSON(el) {
35+ try {
3636 JSON.parse(el)
3737 return true;
3838 }
39- catch(e){
39+ catch (e) {
4040 return false;
4141 }
4242 }
43- public keys(el){
44- if(el != null){
43+ public keys(el) {
44+ if (el != null) {
4545 return Object.keys(el);
4646 }
4747 return null;
4848 }
49- public cptString(key, el){
49+ public cptString(key, el) {
5050 el = JSON.parse(el);
51- let str = this.translate.instant(key) + ": ";
52- if (Array.isArray(el[key])){
53- str += el[key].join(", ")
54- } else{
55- str += el[key]
56- }
57- return str;
51+ let str = this.translate.instant(key) + ": ";
52+ if (Array.isArray(el[key])) {
53+ str += el[key].join(", ")
54+ } else {
55+ str += el[key]
56+ }
57+ return str;
5858 }
59-
60- public async buildFilters(){
61- try{
59+
60+ public async buildFilters() {
61+ try {
6262 this.local.compl = null;
63- if(this.pageOwner.getTypeByActions(this.sources, this.isSource) == ''filter''){
64- let baseURL = environment.production ? window.location.href.substring(0, (window.location.href.indexOf("/projects/") + 10 ) ) : "http://localhost:18080/convertigo/projects/";
63+ if (this.pageOwner.getTypeByActions(this.sources, this.isSource) == ''filter'') {
64+ let baseURL = environment.production ? window.location.href.substring(0, (window.location.href.indexOf("/projects/") + 10) ) : "http://localhost:18080/convertigo/projects/";
6565 let req = this.pageOwner.getEnabled(this.sources);
6666 this.sources[req].vars
6767 let defaultVars = {};
6868 let regex = /\$\$(?:START)?(\d+)(.*?)(?:END)?(?:\d+)?\$\$/
69- try{
70- defaultVars = defaultVars = Object.keys(this.sources[req].vars).map((x=>{ return {key: x, value: this.sources[req].vars[x].str != undefined ? this.sources[req].vars[x].str.replace(regex, "") : "" }})).reduce((obj, item) => Object.assign(obj, { [item.key]: item.value }), {});
69+ try {
70+ defaultVars = defaultVars = Object.keys(this.sources[req].vars).map((x => { return { key: x, value: this.sources[req].vars[x].str != undefined ? this.sources[req].vars[x].str.replace(regex, "") : "" } })).reduce((obj, item) => Object.assign(obj, { [item.key]: item.value }), {});
7171 }
72- catch(e){
73-
72+ catch (e) {
73+
7474 }
75- let res = await this.c8o.callJsonObject(req,{ model: true, ...defaultVars}).async();
76- if(res.data && res.data[0]){
75+ let res = await this.c8o.callJsonObject(req, { model: true, ...defaultVars }).async();
76+ if (res.data && res.data[0]) {
7777 this.local.compl = Object.keys(res.data[0]);
7878 }
7979 }
8080 //else{
8181 //}
8282 }
83- catch(e){
84-
83+ catch (e) {
84+
8585 }
86-
86+
8787 }
8888 private onCompare(_left: KeyValue<any, any>, _right: KeyValue<any, any>): number {
8989 return -1;
9090 }
91+ public async __convertTsToText(sourceStr) {
92+ try {
93+ if (sourceStr == null) {
94+ return "";
95+ }
96+ var raw = "" + sourceStr;
97+ var body = raw.trim();
98+ if (body.indexOf("(async ()=>{") === 0) {
99+ var startReturn = body.indexOf("return ");
100+ if (startReturn !== -1) {
101+ body = body.substring(startReturn + 7);
102+ }
103+ var closing = body.lastIndexOf("})();");
104+ if (closing !== -1) {
105+ body = body.substring(0, closing);
106+ }
107+ }
108+ body = body.trim();
109+ if (body.indexOf("return ") === 0) {
110+ body = body.substring(7);
111+ }
112+ body = body.trim();
113+ if (body.lastIndexOf(";") === body.length - 1) {
114+ body = body.substring(0, body.length - 1);
115+ }
116+ body = body.trim();
117+ if (body === "") {
118+ return "";
119+ }
120+ var translated = body;
121+ if (this.c8oforms_monacoeditor && typeof this.c8oforms_monacoeditor.parse === "function") {
122+ try {
123+ translated = await this.c8oforms_monacoeditor.parse(body);
124+ }
125+ catch (parseError) {
126+ translated = body;
127+ }
128+ }
129+ var builder = "";
130+ var tokenRegex = /(\$\$(?:START)?\d+(?:[\s\S]*?)(?:END)?(?:\d+)?\$\$|"(?:\\.|[^"\\])*")/g;
131+ var lastIndex = 0;
132+ var match;
133+ var cleanup = function(fragment) {
134+ return fragment.replace(/[+\s;\r\n()]/g, "");
135+ };
136+ while ((match = tokenRegex.exec(translated)) != null) {
137+ if (match.index > lastIndex) {
138+ var between = cleanup(translated.substring(lastIndex, match.index));
139+ if (between.length > 0) {
140+ return raw;
141+ }
142+ }
143+ var token = match[0];
144+ if (token.indexOf("$$") === 0) {
145+ builder += token;
146+ }
147+ else {
148+ var literal = token;
149+ var value = "";
150+ try {
151+ value = JSON.parse(literal);
152+ }
153+ catch (ex) {
154+ value = literal.substring(1, literal.length - 1);
155+ }
156+ builder += value;
157+ }
158+ lastIndex = match.index + match[0].length;
159+ }
160+ if (lastIndex < translated.length) {
161+ var tail = cleanup(translated.substring(lastIndex));
162+ if (tail.length > 0) {
163+ return raw;
164+ }
165+ }
166+ return builder;
167+ }
168+ catch (error) {
169+ return sourceStr == null ? "" : "" + sourceStr;
170+ }
171+ };
91172 /*End_c8o_CompFunction*/
92173 '
93174↓GridRow [ngx.components.UIDynamicElement-1610637187950] :
@@ -3306,7 +3387,7 @@ scriptContent:
33063387 }
33073388 let token = match[0];
33083389 let tsExpr = page.pageOwner.transform$toTsMonaco(token);
3309- parts.push(tsExpr && tsExpr !== "" ? tsExpr : " ''");
3390+ parts.push(tsExpr && tsExpr !== "" ? tsExpr : ''""'' );
33103391 lastIndex = match.index + match[0].length;
33113392 }
33123393 if(lastIndex < sourceStr.length){
@@ -4146,7 +4227,7 @@ scriptContent:
41464227 }
41474228 let token = match[0];
41484229 let tsExpr = page.pageOwner.transform$toTsMonaco(token);
4149- parts.push(tsExpr && tsExpr !== "" ? tsExpr : " ''");
4230+ parts.push(tsExpr && tsExpr !== "" ? tsExpr : ''""'' );
41504231 lastIndex = match.index + match[0].length;
41514232 }
41524233 if(lastIndex < sourceStr.length){
@@ -4564,40 +4645,51 @@ scriptContent:
45644645 → : |
45654646 ' try {
45664647 page.local.props = null;
4567- if(this.global?.settings?.formulas){
4568- if(page.currentEdit){
4648+ if (this.global?.settings?.formulas) {
4649+ if (page.currentEdit) {
45694650 page.currentEdit.editor._editor.bodyElement.style.backgroundColor = "#FFF3CD";
45704651 }
4571- page.local.props = {props: {type: ''text''}};
4652+ let convertedFormulas = "";
4653+ if (page.currentObject?.type === "ts") {
4654+ convertedFormulas = await page.__convertTsToText(page.currentObject?.str);
4655+ }
4656+ page.local.props = convertedFormulas === ""
4657+ ? { props: { type: "text" } }
4658+ : { props: { type: "text", str: convertedFormulas, html: false } };
45724659 return true;
45734660 }
45744661 else{
45754662 let alertController = page.getInstance(AlertController);
4576- // send an alert to confirm data will be lost
45774663 const alert = await alertController.create({
4578- header: page.translate.instant("header_pwamsg"),
4579- subHeader: page.translate.instant("compat_aa"),
4580- buttons: [
4581- {
4582- text: page.translate.instant("cancel_pwamsg"),
4583- role: '' cancel'' ,
4584- },
4585- {
4586- text: page.translate.instant("continue_pwamsg"),
4587- role: '' confirm'' ,
4588- },
4664+ header: page.translate.instant("header_pwamsg"),
4665+ subHeader: page.translate.instant("compat_aa"),
4666+ buttons: [
4667+ {
4668+ text: page.translate.instant("cancel_pwamsg"),
4669+ role: " cancel" ,
4670+ },
4671+ {
4672+ text: page.translate.instant("continue_pwamsg"),
4673+ role: " confirm" ,
4674+ },
45894675 ]
4590- });
4591- await alert.present();
4592- let res = await alert.onDidDismiss();
4593- let str = "";
4594- page.local.props = {props: {type: ''text'', str: ""}};
4595- return res.role === ''confirm'';
4676+ });
4677+ await alert.present();
4678+ let res = await alert.onDidDismiss();
4679+ if (res.role !== "confirm") {
4680+ return false;
4681+ }
4682+ let converted = "";
4683+ if (page.currentEdit) {
4684+ page.currentEdit.editor._editor.bodyElement.style.backgroundColor = "#FFF3CD";
4685+ }
4686+ page.local.props = { props: { type: "text", str: converted, html: false } };
4687+ return true;
45964688 }
45974689
45984690 } catch (e) {
4599-
46004691 }
4692+
46014693 '
46024694 ↓IfElse [ngx.components.UIDynamicIf-1747155141696] :
46034695 beanData : ' {"ionBean":"IfElseAction"}'
@@ -4704,7 +4796,7 @@ scriptContent:
47044796 }
47054797 let token = match[0];
47064798 let tsExpr = page.pageOwner.transform$toTsMonaco(token);
4707- parts.push(tsExpr && tsExpr !== "" ? tsExpr : " ''");
4799+ parts.push(tsExpr && tsExpr !== "" ? tsExpr : ''""'' );
47084800 lastIndex = match.index + match[0].length;
47094801 }
47104802 if(lastIndex < sourceStr.length){
@@ -4971,4 +5063,4 @@ scriptContent:
49715063↓subIndex [ngx.components.UICompVariable-1743089013339] :
49725064 value : null
49735065↓loop [ngx.components.UICompVariable-1743423846953] :
4974- value : false
5066+ value : false
0 commit comments