Merge branch 'master' of ssh.dev.azure.com:v3/HackKu/HackKu%202020/backend

This commit is contained in:
garrettmills 2020-02-09 04:37:32 -06:00
commit 3f9730955a
3 changed files with 33 additions and 24 deletions

View File

@ -33,6 +33,7 @@
}
.nav {
margin-left: -1rem;
width: 100%;
}
@ -49,6 +50,9 @@
.nav-link {
color: beige;
}
.contents {
padding: 2em;
}
</style>
</head>
@ -57,11 +61,10 @@
<div class="row">
<div class="col-sm-3 navsec">
<nav class="navbar navbar-dark bg-dark flex-column">
<a class="navbar-brand" href="#">Noded</a>
<nav class="nav nav-pills flex-column">
<a class="navbar-brand" href="#"><img src="/logo/Asset+1.svg" width="30" height="30" class="d-inline-block align-top" alt="">Noded</a>
<div class="nav nav-pills flex-column">
%%SIDEBAR%%
</nav>
</nav>
</div>
</nav>
</div>
<div class="col-sm-9 contents">

View File

@ -44,7 +44,6 @@ class Export extends Controller {
/* Archive directory */
const exec = require('child_process').exec;
console.log('zip -9jpr ' + path.resolve(temp_dir, '../archive.zip') + ' ' + path.resolve(temp_dir) + '/')
exec('cd ' + path.resolve(temp_dir) + '; zip -r archive.zip *', (error) => {
if (error) {
console.error(`exec error: ${error}`);
@ -93,8 +92,8 @@ class Export extends Controller {
const html_name = page.Name.replace(/\s/g, '_') + '.html'
mapping[page.UUID] = html_name
}
console.log(page0)
const sidebar_html = await this._generate_sidebar(mapping, page0) //generates the sidebar contents
const sidebar_html = await this._generate_sidebar(mapping, user) //generates the sidebar contents
const temp_dir = path.resolve(os.tmpdir(), uuid()) //make temporary directory
await fs.mkdir(temp_dir)
@ -102,16 +101,13 @@ class Export extends Controller {
for (const page of pages) {
const fs = require('fs').promises
const contents = (await fs.readFile(path.resolve(this.app.directories.assets, 'export-template.html'))).toString('utf8')
console.log(page)
//console.log({contents})
const content_html = await this._generate_html(page)
//console.log({content_html, sidebar_html})
const page_html = contents.replace('%%SIDEBAR%%', sidebar_html).replace('%%CONTENTS%%', content_html)
const page_html = contents.replace('%%CONTENTS%%', content_html).replace('%%SIDEBAR%%', sidebar_html)
await fs.writeFile(path.resolve(temp_dir, mapping[page.UUID]), page_html)
}
/* Archive directory */
const exec = require('child_process').exec;
exec('zip -r ' + path.resolve(temp_dir, 'archive.zip') + ' ' + path.resolve(temp_dir), (error) => {
exec('cd ' + path.resolve(temp_dir) + '; zip -r archive.zip *', (error) => {
if (error) {
console.error(`exec error: ${error}`);
return res.error(500);
@ -120,22 +116,32 @@ class Export extends Controller {
return res.sendFile(`${path.resolve(temp_dir, 'archive.zip')}`)
})
}
async _generate_sidebar(mapping, upper_node) { //generate sidebar from mapping array and upper_node
async _generate_sidebar(mapping, user) {// the absolutely dreadful method to create, sidebar
const Page = this.models.get('api:Page')
console.log(upper_node)
console.log(upper_node.ChildPageIds == 'undefined')
if (upper_node.ChildPageIds == 'undefined') {
return '<a class="nav-link" href="' + mapping[upper_node.UUID] + '">' + upper_node.Name + '</a>'
} else {
let base = '<nav class="nav nav-pills flex-column">'
for (const childrenId of upper_node.ChildPageIds) {
base += (await this._generate_sidebar(await Page.findOne({ UUID: childrenId })))
const Node = this.models.get('api:Node')
const virt_root = await user.get_root_page()
return await this._sidebar_recurse(mapping, virt_root)
}
async _sidebar_recurse(mapping, parent) {
const Page = this.models.get('api:Page')
const Node = this.models.get('api:Node')
const children = await Page.find({ ParentId : parent.UUID})
let base = ''
for (const child of children) {
if (child.ChildPageIds.length === 0) {
base += '<a class="nav-link ml-2" href="' + mapping[child.UUID] + '">' + child.Name + '</a>' //mapping[child.UUID] gives filename
} else {
base += '<a class="nav-link ml-2" href="' + mapping[child.UUID] + '">' + child.Name + '</a>'
base += '<div class="nav nav-pills flex-column ml-2">'
base += await this._sidebar_recurse(mapping, child)
base += '</div>'
}
}
console.log({ base })
return base
}
}
async _generate_html(page) { //generate html page from page and node data
const Page = this.models.get('api:Page')
const Node = this.models.get('api:Node')
const nodes = await Node.find({ PageId: page.UUID })
return nodes.map(x => { return x.to_html() }).join('\n')

View File

@ -43,4 +43,4 @@ html
p.flitter-text Welcome, #{user.uid}! <a href="/auth/logout">Log out.</a>
else
.flitter-container
p.flitter-text New to #{_app.name}? <a href=/login" target="_blank">Start here.</a>
p.flitter-text New to #{_app.name}? <a href="/login" target="_blank">Start here.</a>