Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #29: Removes unused tabs and adds notifications or errors #38

Merged
merged 1 commit into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/components/ComponentView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,34 @@

<div class="tabs">
<ul>
<li :class="{'is-active': activeTab === 'view'}">
<li v-if="!data.cmsOnly" :class="{'is-active': activeTab === 'view'}">
<router-link
:to="`/${rParams.type}/${rParams.view}/view/${model}`">Vue</router-link>
</li>
<li :class="{'is-active': activeTab === 'model'}">
<li v-if="models[model]" :class="{'is-active': activeTab === 'model'}">
<router-link
:to="`/${rParams.type}/${rParams.view}/model/${model}`">Model</router-link>
</li>
<li :class="{'is-active': activeTab === 'documentation'}">
<li v-if="data.doc" :class="{'is-active': activeTab === 'documentation'}">
<router-link
:to="`/${rParams.type}/${rParams.view}/documentation/${model}`">Documentation</router-link>
</li>
<li :class="{'is-active': activeTab === 'usage'}">
<li v-if="data.html || data.raw" :class="{'is-active': activeTab === 'usage'}">
<router-link
:to="`/${rParams.type}/${rParams.view}/usage/${model}`">Usage</router-link>
</li>
<li :class="{'is-active': activeTab === 'raw'}">
<li v-if="data.raw" :class="{'is-active': activeTab === 'raw'}">
<router-link
:to="`/${rParams.type}/${rParams.view}/raw/${model}`">Raw</router-link>
</li>
<li v-if="data.notifications && data.notifications.length > 0" :class="{'is-active': activeTab === 'notifications'}">
<router-link
:to="`/${rParams.type}/${rParams.view}/notifications/${model}`">Notifications</router-link>
</li>
<li v-if="data.errors && data.errors.length > 0" :class="{'is-active': activeTab === 'errors'}">
<router-link
:to="`/${rParams.type}/${rParams.view}/errors/${model}`">Errors</router-link>
</li>
</ul>
</div>

Expand Down Expand Up @@ -88,6 +96,24 @@
<template v-else-if="activeTab === 'raw'">
<div v-html="data.raw" />
</template>
<template v-else-if="activeTab === 'notifications'">
<ul>
<li
v-for="(notification, index) in data.notifications"
:key="index">
{{ notification.text }}
</li>
</ul>
</template>
<template v-else-if="activeTab === 'errors'">
<ul>
<li
v-for="(errors, index) in data.errors"
:key="index">
{{ errors.text }}
</li>
</ul>
</template>
</div>
</div>
</section>
Expand Down
52 changes: 40 additions & 12 deletions srv/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = function (pathToComponents, pathToPages, pathToAemMocks, backen
if (fs.existsSync(pathToDoc)) {
doc = service.getMarkdownByPath(pathToDoc)
} else {
doc = '<p>DOCUMENTATION IS MISSING!</p>'
doc = false
}

return doc
Expand All @@ -43,55 +43,83 @@ module.exports = function (pathToComponents, pathToPages, pathToAemMocks, backen
processViewHit: async function (req, res) {
const { type, view, viewModel } = req.params
const response = {}
const notifications = []
const errors = []

let path = type === 'pages' ? `${pathToPages}` : `${pathToComponents}`


if (!view) {
path += `/${type}`
const doc = service.getDocumentation(path)

notifications.push({ text: 'view not set' })

response.doc = service.getDocumentation(path)
if (doc) {
response.doc = doc
} else {
notifications.push({ text: 'doc.md not found' })
}
} else {
path += `/${type}/${view}/`

const mock = require(`${path}/mock.js`)
const doc = service.getDocumentation(path, `/doc.md`)

if (!doc) {
notifications.push({ text: 'doc.md not found' })
}
const viewModelName = viewModel || 'default'
const vm = mock.models[viewModelName]

let mock = {}
let vm = {}

if (fs.existsSync(`${path}/mock.js`)) {
mock = require(`${path}/mock.js`)
vm = mock.models[viewModelName]
} else {
notifications.push({ text: 'mock.js file not found' })
}

// define CMS template
let raw
let cmsTemplate = 'FILE NOT FOUND'
let cmsTemplate = ''
let cmsOnly = !fs.existsSync(`${path}/${view}.vue`)
if (backendTemplates === 'hbs') {
if (fs.existsSync(`${path}/views.hbs`)) {
cmsTemplate = fs.readFileSync(`${path}/views.hbs`, {
encoding: 'utf-8'
})
raw = service.getView(cmsTemplate, vm)
} else {
notifications.push({ text: `${path}/views.hbs not found` })
}
} else if (backendTemplates === 'htl') {
try {
cmsTemplate = await service.getHtlTemplate(path, view)
if (cmsTemplate) {
const engine = require('./htl/engine')
raw = await engine(vm.htl, cmsTemplate, {useDir: pathToAemMocks, useOptions: {model: viewModel}})
raw = await engine(vm.htl || {}, cmsTemplate, {useDir: pathToAemMocks, useOptions: {model: viewModel}})
if (raw) {
raw = raw.body
}

if (!raw) {
notifications.push({ text: 'Referenced htl template not found' })
}
} else {
cmsTemplate = 'FILE NOT FOUND'
notifications.push({ text: 'meta.js file not found' })
}
} catch (e) {
console.log(e)
errors.push({ text: e })
}
}

response.models = mock.models
response.models = mock.models || null
response.doc = doc
response.raw = raw
response.html = cmsTemplate
response.cmsOnly = cmsOnly
response.notifications = notifications
response.errors = errors
}

res.json(response)
Expand All @@ -102,10 +130,10 @@ module.exports = function (pathToComponents, pathToPages, pathToAemMocks, backen
try {
meta = require(`${path}/meta`)
} catch (e) {
console.log(e)
return 'MISSING meta.js'
return false
}
const htlPath = `${pathToComponents}/${meta.templatePath}/${meta.component}.html`
// TODO check whether this makes sense
const contentPath = `${pathToComponents}/${meta.templatePath}/.content.xml`
let htlTemplate = false

Expand Down