Falta fer rework de Database window
This commit is contained in:
parent
35c0817bb0
commit
a2253889ce
@ -2,9 +2,11 @@ const mongoose = require("mongoose");
|
|||||||
const Schema = mongoose.Schema;
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
const DatagenCollectionSchema = new Schema({
|
const DatagenCollectionSchema = new Schema({
|
||||||
name: {type: String, required: true},
|
name: {type: String, required: true },
|
||||||
id: { type: String, required: true },
|
id: { type: String, required: true },
|
||||||
package: { type: String, required: true},
|
module: { type: String, required: true},
|
||||||
|
package: { type: String, required: true },
|
||||||
|
icon: {type: String},
|
||||||
desc: { type: String },
|
desc: { type: String },
|
||||||
entries: [ {type: mongoose.Types.ObjectId, ref: "DatagenEntry"} ],
|
entries: [ {type: mongoose.Types.ObjectId, ref: "DatagenEntry"} ],
|
||||||
});
|
});
|
||||||
|
@ -1,13 +1,31 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
const DatagenCollection = require('../models/DatagenCollection');
|
||||||
|
const DatagenEntry = require('../models/DatagenEntry');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
// Get characters from a campaign
|
// Get characters from a campaign
|
||||||
router.get('/:plugin', (req, res) => {
|
router.get('/:module', (req, res) => {
|
||||||
res.json({
|
let module = req.params.module;
|
||||||
datagens: [
|
|
||||||
{title: "Hello world"}
|
// Should trim this response
|
||||||
]
|
DatagenCollection.find({module}).then(data => {
|
||||||
})
|
res.json({datagens: data});
|
||||||
|
}).catch(err => res.json({status: "err", err: err}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/:module/:id/all', (req, res) => {
|
||||||
|
let module = req.params.module;
|
||||||
|
let id = req.params.id;
|
||||||
|
|
||||||
|
console.log(module);
|
||||||
|
console.log(id);
|
||||||
|
|
||||||
|
DatagenCollection.find({module, id}).then(col => {
|
||||||
|
if(!col) { res.json({status: "err", msg: "not found"}); return; }
|
||||||
|
DatagenEntry.find({datagen_collection: col}).then(data => {
|
||||||
|
res.json({elements: data});
|
||||||
|
});
|
||||||
|
}).catch(err => res.json({status: "err", err: err}));
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
@ -32,34 +32,42 @@ async function datagenTask(models) {
|
|||||||
async function resolveDatagen(models, path, info){
|
async function resolveDatagen(models, path, info){
|
||||||
// Do locale translation with info somewhere...?
|
// Do locale translation with info somewhere...?
|
||||||
const datagenCollection = await DatagenCollection.create({
|
const datagenCollection = await DatagenCollection.create({
|
||||||
name: info.name,
|
name: info.name, // Display name?
|
||||||
id: info.id,
|
id: info.id, // Internal id?
|
||||||
|
package: info.package, // From what plugin?
|
||||||
|
module: info.module, // What module is for?
|
||||||
desc: info.desc,
|
desc: info.desc,
|
||||||
package: info.package
|
icon: info.icon,
|
||||||
});
|
});
|
||||||
|
|
||||||
const modelNames = models[info.package].modelNames;
|
const modelNames = models[info.module].modelNames;
|
||||||
modelNames.forEach(modelName => {
|
for(let i = 0; i < modelNames.length; i++){
|
||||||
|
let modelName = modelNames[i];
|
||||||
if(Object.keys(mongoose.models).includes(modelName)){
|
if(Object.keys(mongoose.models).includes(modelName)){
|
||||||
let modelLastName = modelName.split('/').pop();
|
let modelLastName = modelName.split('/').pop();
|
||||||
let modelDataPath = path + "/data/" + modelLastName;
|
let modelDataPath = path + "/data/" + modelLastName;
|
||||||
if(fs.existsSync(modelDataPath)){
|
if(fs.existsSync(modelDataPath)){
|
||||||
const jsonFiles = fs.readdirSync(path + "/data/" + modelLastName, {recursive: true});
|
const jsonFiles = fs.readdirSync(path + "/data/" + modelLastName, {recursive: true});
|
||||||
let modelPath = path + "/data/" + modelLastName;
|
let modelPath = path + "/data/" + modelLastName;
|
||||||
jsonFiles.forEach(file => {
|
for(let j = 0; j < jsonFiles.length; j++){
|
||||||
|
let file = jsonFiles[j];
|
||||||
if(fs.lstatSync(modelPath + "/" + file).isFile()){
|
if(fs.lstatSync(modelPath + "/" + file).isFile()){
|
||||||
appendDatagen(modelPath + "/" + file, modelName, info, datagenCollection);
|
const newDatagen = await appendDatagen(modelPath + "/" + file, modelName, info, datagenCollection);
|
||||||
}
|
datagenCollection.entries.push(newDatagen._id);
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
await datagenCollection.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function appendDatagen(file, modelName, info, datagenCollection){
|
async function appendDatagen(file, modelName, info, datagenCollection){
|
||||||
// "Appending " + file + " to model " + modelName + " from " + info.id + " for package " + info.package
|
// "Appending " + file + " to model " + modelName + " from " + info.id + " for package " + info.package
|
||||||
let fileData = JSON.parse(fs.readFileSync(file));
|
let fileData = JSON.parse(fs.readFileSync(file));
|
||||||
await DatagenEntry.create({
|
return await DatagenEntry.create({
|
||||||
id: fileData.id,
|
id: fileData.id,
|
||||||
data: fileData.value,
|
data: fileData.value,
|
||||||
schema: modelName,
|
schema: modelName,
|
||||||
|
@ -221,6 +221,10 @@ class ClientModule {
|
|||||||
getDatagen(){
|
getDatagen(){
|
||||||
return this.#_baseRouter.get(`/datagen/${this.#_id}`);
|
return this.#_baseRouter.get(`/datagen/${this.#_id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDatagenData(id){
|
||||||
|
return this.#_baseRouter.get(`/datagen/${this.#_id}/${id}/all`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClientSocket {
|
class ClientSocket {
|
||||||
|
@ -36,12 +36,29 @@ function FetchBookList(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function OpenBook(){
|
function OpenBook(element){
|
||||||
console.log("Open book!");
|
console.log(element);
|
||||||
|
console.log("!!!!!");
|
||||||
|
dndModule.getDatagenData(element.id).then(response => {
|
||||||
|
console.log(response.data);
|
||||||
|
Api.createWindow(PluginData.windows.database, {
|
||||||
|
title: element.name,
|
||||||
|
id: 'campaign-items-window',
|
||||||
|
elements: response.data.elements,
|
||||||
|
topper: {
|
||||||
|
icon: "/plugins/" + element.package + "/" + element.icon,
|
||||||
|
title: element.name,
|
||||||
|
description: element.desc
|
||||||
|
},
|
||||||
|
close: () => Api.clearWindow("campaign-items-window")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function BookIcon(element){
|
function BookIcon(element){
|
||||||
return "";
|
console.log(element);
|
||||||
|
return "/plugins/" + element.package + "/" + element.icon;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
{
|
{
|
||||||
"package": "dnd-5e",
|
"module": "dnd-5e",
|
||||||
"id": "dnd-5e-base",
|
"id": "dnd-5e-base",
|
||||||
"name": "info.name",
|
"package": "dnd-5e",
|
||||||
"desc": "info.description",
|
"name": "Dnd 5e Essential Books",
|
||||||
|
"desc": "This book includes the player manual, dungeon master manual and the monsters manual",
|
||||||
|
"icon": "icon.png",
|
||||||
"dependencies": []
|
"dependencies": []
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user