yaml-admin-api 0.0.116 → 0.0.118
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/package.json
CHANGED
|
@@ -14,12 +14,25 @@ const generateChartApi = async (app, db, yml, api_prefix) => {
|
|
|
14
14
|
if (!dashboard)
|
|
15
15
|
return;
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const auth = withConfig({ db, jwt_secret: yml.login["jwt-secret"] });
|
|
18
|
+
|
|
19
|
+
const chartComponents = []
|
|
20
|
+
|
|
21
|
+
if(dashboard.sections) {
|
|
22
|
+
dashboard.sections.forEach(section=>{
|
|
23
|
+
section.components?.filter(m => m.component === 'chart').forEach(m=>{
|
|
24
|
+
chartComponents.push(m)
|
|
25
|
+
});
|
|
26
|
+
})
|
|
27
|
+
} else if(Array.isArray(dashboard)){
|
|
28
|
+
dashboard.filter(m => m.component === 'chart').forEach(m=>{
|
|
29
|
+
chartComponents.push(m)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
18
33
|
if (chartComponents.length === 0)
|
|
19
34
|
return;
|
|
20
35
|
|
|
21
|
-
const auth = withConfig({ db, jwt_secret: yml.login["jwt-secret"] });
|
|
22
|
-
|
|
23
36
|
const createChartDataTypeDate = async (chart, {from_date, filter}) => {
|
|
24
37
|
const r = {
|
|
25
38
|
options: {
|
|
@@ -260,6 +273,42 @@ const generateChartApi = async (app, db, yml, api_prefix) => {
|
|
|
260
273
|
return r
|
|
261
274
|
}
|
|
262
275
|
|
|
276
|
+
const createChartDataTypePie = async (chart, {filter}) => {
|
|
277
|
+
const { x, y } = chart;
|
|
278
|
+
const { field, entity: entity_x, values } = x;
|
|
279
|
+
const entity = entity_x || y?.entity;
|
|
280
|
+
|
|
281
|
+
let a = [];
|
|
282
|
+
if (filter && Object.keys(filter).length > 0)
|
|
283
|
+
a.push({ $match: filter });
|
|
284
|
+
a.push({ $group: { _id: `$${field}`, count: { $sum: 1 } } });
|
|
285
|
+
|
|
286
|
+
if (chart.debug)
|
|
287
|
+
console.log('chart pie', chart.label, entity, JSON.stringify(a, null, 2));
|
|
288
|
+
|
|
289
|
+
const list = await db.collection(entity).aggregate(a).toArray();
|
|
290
|
+
|
|
291
|
+
let labels, series, colors;
|
|
292
|
+
if (values?.length) {
|
|
293
|
+
labels = values.map(v => v.label || v.name);
|
|
294
|
+
series = values.map(v => list.find(l => String(l._id) === String(v.name))?.count || 0);
|
|
295
|
+
colors = values.map(v => v.color).filter(Boolean);
|
|
296
|
+
} else {
|
|
297
|
+
labels = list.map(l => String(l._id));
|
|
298
|
+
series = list.map(l => l.count);
|
|
299
|
+
colors = [];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
options: {
|
|
304
|
+
chart: { id: chart.id },
|
|
305
|
+
labels,
|
|
306
|
+
...(colors.length ? { colors } : {}),
|
|
307
|
+
},
|
|
308
|
+
series,
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
|
|
263
312
|
for (const chart of chartComponents) {
|
|
264
313
|
const { id } = chart;
|
|
265
314
|
console.log('generateChartApi', chart.id)
|
|
@@ -312,7 +361,9 @@ const generateChartApi = async (app, db, yml, api_prefix) => {
|
|
|
312
361
|
filter[s.name] = value;
|
|
313
362
|
});
|
|
314
363
|
|
|
315
|
-
if (
|
|
364
|
+
if (chart.type === 'pie' || chart.type === 'donut') {
|
|
365
|
+
r = await createChartDataTypePie(chart, {filter});
|
|
366
|
+
} else if (x.type == 'date') {
|
|
316
367
|
let {from_date} = req.query //YYYYMMDD
|
|
317
368
|
r = await createChartDataTypeDate(chart, {from_date, filter});
|
|
318
369
|
} else if(x.type == 'field') {
|
package/src/member/member.js
CHANGED
|
@@ -21,7 +21,8 @@ module.exports = async function (app, db, yml, api_prefix) {
|
|
|
21
21
|
app.get(api_prefix + '/member/islogin',
|
|
22
22
|
auth.isAuthenticated,
|
|
23
23
|
async function (req, res) {
|
|
24
|
-
|
|
24
|
+
const { authority, ...member } = req.user;
|
|
25
|
+
res.json({ r: true, authority, member });
|
|
25
26
|
}
|
|
26
27
|
);
|
|
27
28
|
|