Some bits for ReactJS-based client.
This commit is contained in:
parent
115d254baf
commit
4f52b571c9
27 changed files with 2326 additions and 202 deletions
|
@ -1,8 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
const passport = require('../lib/passport');
|
||||
const router = new express.Router();
|
||||
const router = require('../lib/router-async').create();
|
||||
const _ = require('../lib/translate')._;
|
||||
const namespaces = require('../lib/models/namespaces');
|
||||
|
||||
|
@ -15,54 +14,50 @@ router.all('/*', (req, res, next) => {
|
|||
next();
|
||||
});
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.render('namespaces/namespaces', {
|
||||
router.getAsync('/', async (req, res) => {
|
||||
res.render('react-root', {
|
||||
title: _('Namespaces'),
|
||||
useFancyTree: true
|
||||
reactEntryPoint: 'namespaces'
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/list/ajax', (req, res, next) => {
|
||||
router.getAsync('/list/ajax', async (req, res) => {
|
||||
const entries = {};
|
||||
const roots = [];
|
||||
|
||||
namespaces.list().then(rows => {
|
||||
for (let row of rows) {
|
||||
let entry;
|
||||
if (!entries[row.id]) {
|
||||
entry = {
|
||||
children: []
|
||||
};
|
||||
entries[row.id] = entry;
|
||||
} else {
|
||||
entry = entries[row.id];
|
||||
}
|
||||
const rows = await namespaces.list();
|
||||
|
||||
if (row.parent) {
|
||||
if (entries[row.parent]) {
|
||||
entries[row.parent] = {
|
||||
children: []
|
||||
};
|
||||
}
|
||||
|
||||
entries[row.parent].children.push(entry);
|
||||
|
||||
} else {
|
||||
roots.push(entry);
|
||||
}
|
||||
|
||||
entry.title = row.name;
|
||||
entry.key = row.id;
|
||||
for (let row of rows) {
|
||||
let entry;
|
||||
if (!entries[row.id]) {
|
||||
entry = {
|
||||
children: []
|
||||
};
|
||||
entries[row.id] = entry;
|
||||
} else {
|
||||
entry = entries[row.id];
|
||||
}
|
||||
|
||||
console.log(roots);
|
||||
return res.json(roots);
|
||||
if (row.parent) {
|
||||
if (entries[row.parent]) {
|
||||
entries[row.parent] = {
|
||||
children: []
|
||||
};
|
||||
}
|
||||
|
||||
}).catch(err => {
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
});
|
||||
});
|
||||
entries[row.parent].children.push(entry);
|
||||
|
||||
} else {
|
||||
roots.push(entry);
|
||||
}
|
||||
|
||||
entry.title = row.name;
|
||||
entry.key = row.id;
|
||||
}
|
||||
|
||||
return res.json(roots);
|
||||
});
|
||||
|
||||
router.getAsync('')
|
||||
|
||||
module.exports = router;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue