Unverified Commit 9a92789d authored by NGPixel's avatar NGPixel

feat: editor create page mode

parent 278a9bef
...@@ -74,17 +74,13 @@ module.exports = async () => { ...@@ -74,17 +74,13 @@ module.exports = async () => {
index: false, index: false,
maxAge: '7d' maxAge: '7d'
})) }))
app.use('/_assets-legacy/svg/twemoji', async (req, res, next) => { app.use('/_assets/svg/twemoji', async (req, res, next) => {
try { try {
WIKI.asar.serve('twemoji', req, res, next) WIKI.asar.serve('twemoji', req, res, next)
} catch (err) { } catch (err) {
res.sendStatus(404) res.sendStatus(404)
} }
}) })
app.use('/_assets-legacy', express.static(path.join(WIKI.ROOTPATH, 'assets-legacy'), {
index: false,
maxAge: '7d'
}))
// ---------------------------------------- // ----------------------------------------
// SSL Handlers // SSL Handlers
......
...@@ -27,6 +27,7 @@ q-header.bg-header.text-white.site-header( ...@@ -27,6 +27,7 @@ q-header.bg-header.text-white.site-header(
q-toolbar.gt-sm( q-toolbar.gt-sm(
style='height: 64px;' style='height: 64px;'
dark dark
v-if='siteStore.features.search'
) )
q-input( q-input(
dark dark
......
...@@ -126,6 +126,17 @@ ...@@ -126,6 +126,17 @@
@click='discardChanges' @click='discardChanges'
) )
q-btn.acrylic-btn( q-btn.acrylic-btn(
v-if='editorStore.mode === `create`'
flat
icon='las la-check'
color='positive'
label='Create Page'
aria-label='Create Page'
no-caps
@click='createPage'
)
q-btn.acrylic-btn(
v-else
flat flat
icon='las la-check' icon='las la-check'
color='positive' color='positive'
...@@ -246,10 +257,49 @@ async function saveChanges () { ...@@ -246,10 +257,49 @@ async function saveChanges () {
$q.loading.hide() $q.loading.hide()
} }
function editPage () { async function createPage () {
$q.dialog({
component: defineAsyncComponent(() => import('../components/TreeBrowserDialog.vue')),
componentProps: {
mode: 'createPage',
folderPath: '',
itemTitle: pageStore.title,
itemFileName: pageStore.path
}
}).onOk(async ({ path, title }) => {
$q.loading.show()
try {
pageStore.$patch({
title,
path
})
await pageStore.pageSave()
$q.notify({
type: 'positive',
message: 'Page created successfully.'
})
editorStore.$patch({
isActive: false
})
} catch (err) {
$q.notify({
type: 'negative',
message: 'Failed to create page.',
caption: err.message
})
}
$q.loading.hide()
})
}
async function editPage () {
$q.loading.show()
await pageStore.pageLoad({ id: pageStore.id, withContent: true })
editorStore.$patch({ editorStore.$patch({
isActive: true, isActive: true,
editor: 'markdown' mode: 'edit',
editor: pageStore.editor
}) })
$q.loading.hide()
} }
</script> </script>
...@@ -230,7 +230,10 @@ const files = computed(() => { ...@@ -230,7 +230,10 @@ const files = computed(() => {
// METHODS // METHODS
async function save () { async function save () {
onDialogOK() onDialogOK({
title: state.title,
path: state.path
})
} }
async function treeLazyLoad (nodeId, { done, fail }) { async function treeLazyLoad (nodeId, { done, fail }) {
......
...@@ -93,7 +93,7 @@ function createHomePage (editor) { ...@@ -93,7 +93,7 @@ function createHomePage (editor) {
pageStore.pageCreate({ pageStore.pageCreate({
editor, editor,
locale: 'en', locale: 'en',
path: '', path: 'home',
title: t('welcome.homeDefault.title'), title: t('welcome.homeDefault.title'),
description: t('welcome.homeDefault.description'), description: t('welcome.homeDefault.description'),
content: t('welcome.homeDefault.content') content: t('welcome.homeDefault.content')
......
...@@ -752,12 +752,7 @@ async function save () { ...@@ -752,12 +752,7 @@ async function save () {
}) })
await adminStore.fetchSites() await adminStore.fetchSites()
if (adminStore.currentSiteId === siteStore.id) { if (adminStore.currentSiteId === siteStore.id) {
siteStore.$patch({ siteStore.loadSite(window.location.hostname)
title: state.config.title,
description: state.config.description,
company: state.config.company,
contentLicense: state.config.contentLicense
})
} }
} catch (err) { } catch (err) {
$q.notify({ $q.notify({
......
...@@ -78,6 +78,34 @@ const gqlQueries = { ...@@ -78,6 +78,34 @@ const gqlQueries = {
} }
} }
${pagePropsFragment} ${pagePropsFragment}
`,
pageByIdWithContent: gql`
query loadPageWithContent (
$id: UUID!
) {
pageById(
id: $id
) {
...PageRead,
content
}
}
${pagePropsFragment}
`,
pageByPathWithContent: gql`
query loadPageWithContent (
$siteId: UUID!
$path: String!
) {
pageByPath(
siteId: $siteId
path: $path
) {
...PageRead,
content
}
}
${pagePropsFragment}
` `
} }
...@@ -92,6 +120,7 @@ export const usePageStore = defineStore('page', { ...@@ -92,6 +120,7 @@ export const usePageStore = defineStore('page', {
content: '', content: '',
createdAt: '', createdAt: '',
description: '', description: '',
editor: '',
icon: 'las la-file-alt', icon: 'las la-file-alt',
id: '', id: '',
isBrowsable: true, isBrowsable: true,
...@@ -140,12 +169,18 @@ export const usePageStore = defineStore('page', { ...@@ -140,12 +169,18 @@ export const usePageStore = defineStore('page', {
/** /**
* PAGE - LOAD * PAGE - LOAD
*/ */
async pageLoad ({ path, id }) { async pageLoad ({ path, id, withContent = false }) {
const editorStore = useEditorStore() const editorStore = useEditorStore()
const siteStore = useSiteStore() const siteStore = useSiteStore()
try { try {
let query
if (withContent) {
query = id ? gqlQueries.pageByIdWithContent : gqlQueries.pageByPathWithContent
} else {
query = id ? gqlQueries.pageById : gqlQueries.pageByPath
}
const resp = await APOLLO_CLIENT.query({ const resp = await APOLLO_CLIENT.query({
query: id ? gqlQueries.pageById : gqlQueries.pageByPath, query,
variables: id ? { id } : { siteId: siteStore.id, path }, variables: id ? { id } : { siteId: siteStore.id, path },
fetchPolicy: 'network-only' fetchPolicy: 'network-only'
}) })
...@@ -221,56 +256,157 @@ export const usePageStore = defineStore('page', { ...@@ -221,56 +256,157 @@ export const usePageStore = defineStore('page', {
*/ */
async pageSave () { async pageSave () {
const editorStore = useEditorStore() const editorStore = useEditorStore()
const siteStore = useSiteStore()
try { try {
const resp = await APOLLO_CLIENT.mutate({ if (editorStore.mode === 'create') {
mutation: gql` const resp = await APOLLO_CLIENT.mutate({
mutation savePage ( mutation: gql`
$id: UUID! mutation createPage (
$patch: PageUpdateInput! $allowComments: Boolean
) { $allowContributions: Boolean
updatePage ( $allowRatings: Boolean
id: $id $content: String!
patch: $patch $description: String!
$editor: String!
$icon: String
$isBrowsable: Boolean
$locale: String!
$path: String!
$publishState: PagePublishState!
$publishEndDate: Date
$publishStartDate: Date
$relations: [PageRelationInput!]
$scriptCss: String
$scriptJsLoad: String
$scriptJsUnload: String
$showSidebar: Boolean
$showTags: Boolean
$showToc: Boolean
$siteId: UUID!
$tags: [String!]
$title: String!
$tocDepth: PageTocDepthInput
) { ) {
operation { createPage (
succeeded allowComments: $allowComments
message allowContributions: $allowContributions
allowRatings: $allowRatings
content: $content
description: $description
editor: $editor
icon: $icon
isBrowsable: $isBrowsable
locale: $locale
path: $path
publishState: $publishState
publishEndDate: $publishEndDate
publishStartDate: $publishStartDate
relations: $relations
scriptCss: $scriptCss
scriptJsLoad: $scriptJsLoad
scriptJsUnload: $scriptJsUnload
showSidebar: $showSidebar
showTags: $showTags
showToc: $showToc
siteId: $siteId
tags: $tags
title: $title
tocDepth: $tocDepth
) {
operation {
succeeded
message
}
} }
} }
`,
variables: {
...pick(this, [
'allowComments',
'allowContributions',
'allowRatings',
'content',
'description',
'icon',
'isBrowsable',
'locale',
'password',
'path',
'publishEndDate',
'publishStartDate',
'publishState',
'relations',
'scriptJsLoad',
'scriptJsUnload',
'scriptCss',
'showSidebar',
'showTags',
'showToc',
'tags',
'title',
'tocDepth'
]),
editor: editorStore.editor,
siteId: siteStore.id
} }
`, })
variables: { const result = resp?.data?.createPage?.operation ?? {}
id: this.id, if (!result.succeeded) {
patch: pick(this, [ throw new Error(result.message)
'allowComments', }
'allowContributions', this.id = resp.data.createPage.page.id
'allowRatings', this.editor = editorStore.editor
// 'content', } else {
'description', const resp = await APOLLO_CLIENT.mutate({
'icon', mutation: gql`
'isBrowsable', mutation savePage (
'locale', $id: UUID!
'password', $patch: PageUpdateInput!
'path', ) {
'publishEndDate', updatePage (
'publishStartDate', id: $id
'publishState', patch: $patch
'relations', ) {
'scriptJsLoad', operation {
'scriptJsUnload', succeeded
'scriptCss', message
'showSidebar', }
'showTags', }
'showToc', }
'tags', `,
'title', variables: {
'tocDepth' id: this.id,
]) patch: pick(this, [
'allowComments',
'allowContributions',
'allowRatings',
'content',
'description',
'icon',
'isBrowsable',
'locale',
'password',
'path',
'publishEndDate',
'publishStartDate',
'publishState',
'relations',
'scriptJsLoad',
'scriptJsUnload',
'scriptCss',
'showSidebar',
'showTags',
'showToc',
'tags',
'title',
'tocDepth'
])
}
})
const result = resp?.data?.updatePage?.operation ?? {}
if (!result.succeeded) {
throw new Error(result.message)
} }
})
const result = resp?.data?.updatePage?.operation ?? {}
if (!result.succeeded) {
throw new Error(result.message)
} }
// Update editor state timestamps // Update editor state timestamps
const curDate = DateTime.utc() const curDate = DateTime.utc()
......
...@@ -26,7 +26,9 @@ export const useSiteStore = defineStore('site', { ...@@ -26,7 +26,9 @@ export const useSiteStore = defineStore('site', {
showSidebar: true, showSidebar: true,
overlay: null, overlay: null,
features: { features: {
ratingsMode: 'off' ratingsMode: 'off',
reasonForChange: 'required',
search: false
}, },
editors: { editors: {
asciidoc: false, asciidoc: false,
...@@ -87,6 +89,8 @@ export const useSiteStore = defineStore('site', { ...@@ -87,6 +89,8 @@ export const useSiteStore = defineStore('site', {
footerExtra footerExtra
features { features {
ratingsMode ratingsMode
reasonForChange
search
} }
editors { editors {
asciidoc { asciidoc {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment