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 DatagenCollectionSchema = new Schema({
|
||||
name: {type: String, required: true},
|
||||
name: {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 },
|
||||
entries: [ {type: mongoose.Types.ObjectId, ref: "DatagenEntry"} ],
|
||||
});
|
||||
|
@ -1,13 +1,31 @@
|
||||
const express = require('express');
|
||||
const DatagenCollection = require('../models/DatagenCollection');
|
||||
const DatagenEntry = require('../models/DatagenEntry');
|
||||
const router = express.Router();
|
||||
|
||||
// Get characters from a campaign
|
||||
router.get('/:plugin', (req, res) => {
|
||||
res.json({
|
||||
datagens: [
|
||||
{title: "Hello world"}
|
||||
]
|
||||
})
|
||||
router.get('/:module', (req, res) => {
|
||||
let module = req.params.module;
|
||||
|
||||
// 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;
|
@ -32,34 +32,42 @@ async function datagenTask(models) {
|
||||
async function resolveDatagen(models, path, info){
|
||||
// Do locale translation with info somewhere...?
|
||||
const datagenCollection = await DatagenCollection.create({
|
||||
name: info.name,
|
||||
id: info.id,
|
||||
name: info.name, // Display name?
|
||||
id: info.id, // Internal id?
|
||||
package: info.package, // From what plugin?
|
||||
module: info.module, // What module is for?
|
||||
desc: info.desc,
|
||||
package: info.package
|
||||
icon: info.icon,
|
||||
});
|
||||
|
||||
const modelNames = models[info.package].modelNames;
|
||||
modelNames.forEach(modelName => {
|
||||
const modelNames = models[info.module].modelNames;
|
||||
for(let i = 0; i < modelNames.length; i++){
|
||||
let modelName = modelNames[i];
|
||||
if(Object.keys(mongoose.models).includes(modelName)){
|
||||
let modelLastName = modelName.split('/').pop();
|
||||
let modelDataPath = path + "/data/" + modelLastName;
|
||||
if(fs.existsSync(modelDataPath)){
|
||||
const jsonFiles = fs.readdirSync(path + "/data/" + modelLastName, {recursive: true});
|
||||
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()){
|
||||
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){
|
||||
// "Appending " + file + " to model " + modelName + " from " + info.id + " for package " + info.package
|
||||
let fileData = JSON.parse(fs.readFileSync(file));
|
||||
await DatagenEntry.create({
|
||||
return await DatagenEntry.create({
|
||||
id: fileData.id,
|
||||
data: fileData.value,
|
||||
schema: modelName,
|
||||
|
@ -221,6 +221,10 @@ class ClientModule {
|
||||
getDatagen(){
|
||||
return this.#_baseRouter.get(`/datagen/${this.#_id}`);
|
||||
}
|
||||
|
||||
getDatagenData(id){
|
||||
return this.#_baseRouter.get(`/datagen/${this.#_id}/${id}/all`);
|
||||
}
|
||||
}
|
||||
|
||||
class ClientSocket {
|
||||
|
@ -36,12 +36,29 @@ function FetchBookList(){
|
||||
});
|
||||
}
|
||||
|
||||
function OpenBook(){
|
||||
console.log("Open book!");
|
||||
function OpenBook(element){
|
||||
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){
|
||||
return "";
|
||||
console.log(element);
|
||||
return "/plugins/" + element.package + "/" + element.icon;
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
{
|
||||
"package": "dnd-5e",
|
||||
"module": "dnd-5e",
|
||||
"id": "dnd-5e-base",
|
||||
"name": "info.name",
|
||||
"desc": "info.description",
|
||||
"package": "dnd-5e",
|
||||
"name": "Dnd 5e Essential Books",
|
||||
"desc": "This book includes the player manual, dungeon master manual and the monsters manual",
|
||||
"icon": "icon.png",
|
||||
"dependencies": []
|
||||
}
|
Loading…
Reference in New Issue
Block a user