@dra2020/baseclient 1.0.130 → 1.0.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baseclient.js +62 -65
- package/dist/baseclient.js.map +1 -1
- package/dist/detail/detail.d.ts +3 -8
- package/lib/detail/detail.ts +74 -81
- package/package.json +1 -1
package/dist/detail/detail.d.ts
CHANGED
|
@@ -2,21 +2,16 @@ interface DetailItem {
|
|
|
2
2
|
expr?: string;
|
|
3
3
|
text?: string;
|
|
4
4
|
}
|
|
5
|
-
interface DetailLine {
|
|
6
|
-
label: string;
|
|
7
|
-
items: DetailItem[];
|
|
8
|
-
}
|
|
9
5
|
export interface DetailResult {
|
|
10
|
-
k: string;
|
|
11
6
|
n: number;
|
|
12
7
|
v: string;
|
|
13
|
-
t?: string;
|
|
14
8
|
}
|
|
15
9
|
export declare class FormatDetail {
|
|
16
10
|
valid: boolean;
|
|
17
11
|
pattern: string;
|
|
18
|
-
|
|
12
|
+
items: DetailItem[];
|
|
19
13
|
constructor(pattern: string);
|
|
20
|
-
|
|
14
|
+
static prepare(o: any): any;
|
|
15
|
+
format(o: any): DetailResult;
|
|
21
16
|
}
|
|
22
17
|
export {};
|
package/lib/detail/detail.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
//
|
|
2
|
-
// FormatDetail will take
|
|
3
|
-
// Given an object with a set of integer properties, it will evaluate the
|
|
4
|
-
//
|
|
2
|
+
// FormatDetail will take an expression that specifies a format detail lines.
|
|
3
|
+
// Given an object with a set of integer properties, it will evaluate the expression and produce
|
|
4
|
+
// a result { k: string, n: number, v: string } results for displaying the contents of the object.
|
|
5
5
|
//
|
|
6
|
-
// The formatting string
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// Expr can be an arithmetic expression using +-/*() as operators and variables are the field
|
|
6
|
+
// The formatting string is a statement of the form:
|
|
7
|
+
// =expr
|
|
8
|
+
// Expr can be an arithmetic expression using +-/*()?: as operators and variables are the field
|
|
10
9
|
// names of properties on the object passed in. The special field name _tot represents the
|
|
11
10
|
// total of all properties. The expression may also include double-quoted strings that are
|
|
12
11
|
// passed through (e.g. for use as labels = area" sqm")
|
|
@@ -73,101 +72,95 @@ interface DetailItem
|
|
|
73
72
|
text?: string,
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
interface DetailLine
|
|
77
|
-
{
|
|
78
|
-
label: string,
|
|
79
|
-
items: DetailItem[],
|
|
80
|
-
}
|
|
81
|
-
|
|
82
75
|
export interface DetailResult
|
|
83
76
|
{
|
|
84
|
-
k: string, // label
|
|
85
77
|
n: number, // value before formatting
|
|
86
78
|
v: string, // value
|
|
87
|
-
t?: string, // tooltip
|
|
88
79
|
}
|
|
89
80
|
|
|
90
81
|
const reInvalidChars = /[\.\[\]\\]/;
|
|
82
|
+
const reExpr = /^=(.*)$/
|
|
91
83
|
|
|
92
84
|
export class FormatDetail
|
|
93
85
|
{
|
|
94
86
|
valid: boolean;
|
|
95
87
|
pattern: string;
|
|
96
|
-
|
|
88
|
+
items: DetailItem[];
|
|
97
89
|
|
|
98
90
|
constructor(pattern: string)
|
|
99
91
|
{
|
|
100
92
|
this.valid = true;
|
|
101
|
-
this.pattern = pattern;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.lines.push( { label: lhs, items } );
|
|
136
|
-
}
|
|
137
|
-
});
|
|
93
|
+
this.pattern = pattern.trim();
|
|
94
|
+
let a = reExpr.exec(pattern);
|
|
95
|
+
if (a && a.length == 2)
|
|
96
|
+
{
|
|
97
|
+
this.items = [];
|
|
98
|
+
const expr = a[1];
|
|
99
|
+
const parse = expr.split('"');
|
|
100
|
+
let state = 'expr';
|
|
101
|
+
parse.forEach(subexpr => {
|
|
102
|
+
if (state === 'expr')
|
|
103
|
+
{
|
|
104
|
+
if (subexpr.length)
|
|
105
|
+
{
|
|
106
|
+
// Don't allow unsafe actions
|
|
107
|
+
if (reInvalidChars.test(subexpr))
|
|
108
|
+
this.items.push({ text: subexpr });
|
|
109
|
+
else
|
|
110
|
+
this.items.push({ expr: subexpr });
|
|
111
|
+
}
|
|
112
|
+
state = 'text';
|
|
113
|
+
}
|
|
114
|
+
else // state === 'text'
|
|
115
|
+
{
|
|
116
|
+
if (subexpr.length)
|
|
117
|
+
this.items.push({ text: subexpr });
|
|
118
|
+
state = 'expr';
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
{
|
|
124
|
+
this.valid = false;
|
|
125
|
+
this.items = [ { text: 'invalid' } ];
|
|
126
|
+
}
|
|
138
127
|
}
|
|
139
128
|
|
|
140
|
-
|
|
129
|
+
static prepare(o: any): any
|
|
141
130
|
{
|
|
142
|
-
if (
|
|
143
|
-
// Make sure there is a total field
|
|
144
|
-
o = Util.deepCopy(o);
|
|
145
|
-
if (o['Tot'] !== undefined)
|
|
146
|
-
o['_tot'] = o['Tot'];
|
|
147
|
-
else
|
|
131
|
+
if (o)
|
|
148
132
|
{
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
let av = line.items.map(di => {
|
|
160
|
-
if (di.text)
|
|
161
|
-
return di.text;
|
|
162
|
-
else
|
|
163
|
-
{
|
|
164
|
-
let e = new Evaluator(di.expr);
|
|
165
|
-
n = e.eval(o);
|
|
166
|
-
return Util.precisionRound(n, 0).toLocaleString();
|
|
167
|
-
}
|
|
133
|
+
// Make sure there is a total field
|
|
134
|
+
o = Util.deepCopy(o);
|
|
135
|
+
if (o['Tot'] !== undefined)
|
|
136
|
+
o['_tot'] = o['Tot'];
|
|
137
|
+
else
|
|
138
|
+
{
|
|
139
|
+
let t = 0;
|
|
140
|
+
Object.values(o).forEach((v: any) => {
|
|
141
|
+
if (!isNaN(v) && typeof v === 'number')
|
|
142
|
+
t += v;
|
|
168
143
|
});
|
|
169
|
-
|
|
144
|
+
o['_tot'] = t;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return o;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
format(o: any): DetailResult
|
|
151
|
+
{
|
|
152
|
+
if (!o) return { n: 0, v: '' };
|
|
153
|
+
let n: number;
|
|
154
|
+
let av = this.items.map(di => {
|
|
155
|
+
if (di.text)
|
|
156
|
+
return di.text;
|
|
157
|
+
else
|
|
158
|
+
{
|
|
159
|
+
let e = new Evaluator(di.expr);
|
|
160
|
+
n = e.eval(o);
|
|
161
|
+
return Util.precisionRound(n, 0).toLocaleString();
|
|
162
|
+
}
|
|
170
163
|
});
|
|
171
|
-
return
|
|
164
|
+
return { n, v: av.join('') }
|
|
172
165
|
}
|
|
173
166
|
}
|