Skip to content

Commit

Permalink
Page and other frontend fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Katrix committed Oct 17, 2023
1 parent f5f5758 commit 269db99
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 246 deletions.
1 change: 1 addition & 0 deletions oreClient/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "webpack --config webpack.config.prod.js",
"builddev": "webpack --config webpack.config.dev.js",
"start": "webpack-dev-server --open --hot --config webpack.config.dev.js",
"lint:js": "eslint --ext .js,.mjs,.vue .",
Expand Down
6 changes: 6 additions & 0 deletions oreClient/src/main/assets/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export class API {
level: 'error',
messages: jsonError.api_errors,
})
} else if (jsonError.error) {
store.commit({
type: 'addAlert',
level: 'error',
message: jsonError.error,
})
}

throw res.status
Expand Down
13 changes: 9 additions & 4 deletions oreClient/src/main/assets/components/PageLink.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<li class="list-group-item">
<a
v-if="page.children"
v-if="hasChildren"
:class="expandedChildren ? 'page-collapse' : 'page-expand'"
@click="expandedChildren = !expandedChildren"
>
Expand All @@ -10,15 +10,15 @@
<router-link
v-if="!page.navigational"
v-slot="{ href, navigate }"
:to="{ name: 'pages', params: { page: page.slug } }"
:to="page.isHome ? { name: 'project_home' } : { name: 'pages', params: { page: page.slug } }"
>
<a :href="href" @click="navigate">{{ page.name[page.name.length - 1] }}</a>
</router-link>
<span v-else>
{{ page.name[page.name.length - 1] }}
</span>

<div v-if="permissions.includes('edit_page')" class="pull-right">
<div v-if="permissions.includes('edit_page') && !page.isHome" class="pull-right">
<a href="#" @click="$emit('edit-page', page)">
<FontAwesomeIcon style="padding-left: 5px" :icon="['fas', 'edit']" />
</a>
Expand Down Expand Up @@ -50,6 +50,11 @@ export default {
expandedChildren: false,
}
},
computed: mapState('project', ['permissions']),
computed: {
...mapState('project', ['permissions']),
hasChildren() {
return Object.entries(this.page.children).length > 0
},
},
}
</script>
6 changes: 0 additions & 6 deletions oreClient/src/main/assets/components/PageList.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<ul class="list-group" style="margin-bottom: 0px">
<li v-if="includeHome" class="list-group-item">
<router-link v-slot="{ href, navigate }" :to="{ name: 'project_home' }">
<a :href="href" @click="navigate">Home</a>
</router-link>
</li>

<li
is="page-link"
v-for="page in pages"
Expand Down
3 changes: 2 additions & 1 deletion oreClient/src/main/assets/config.json5
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
security: {
api: {
avatarUrl: "https://auth.spongepowered.org/avatar/{0}?size=120x120"
avatarUrl: "https://auth.spongepowered.org/avatar/{0}?size=120x120",
url: ""
}
},
discourse: {
Expand Down
1 change: 1 addition & 0 deletions oreClient/src/main/assets/config.json5.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
security: {
api: {
avatarUrl: "http://localhost:8000/avatar/{0}?size=120x120"
url: ""
}
},
discourse: {
Expand Down
35 changes: 18 additions & 17 deletions oreClient/src/main/assets/pages/project/ProjectDocs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
</template>
</div>

<page-list :pages="groupedPages" :include-home="true" @edit-page="startEditPage" />
<page-list :pages="groupedPages" @edit-page="startEditPage" />
</div>

<member-list
Expand Down Expand Up @@ -217,33 +217,34 @@ export default {
return jsRoutes.controllers.project
},
groupedPages() {
const nonHome = this.pages.filter((p) => p.slug.length !== 1 || p.slug[0].toLowerCase() !== 'home')
const acc = {}
for (const page of nonHome) {
for (const page of this.pages) {
let obj = acc
for (let i = 0; i < page.slug.length - 1; i++) {
const k = page.slug[i]
for (const k of page.slug.slice(0, -1)) {
if (typeof obj[k] === 'undefined') {
obj[k] = {}
obj[k] = {
children: {},
navigational: false,
slug: [],
name: '',
}
}
if (typeof obj[k].children === 'undefined') {
obj[k].children = {}
}
obj = obj[k].children
obj = acc[k].children
}
const key = page.slug[page.slug.length - 1]
if (typeof obj[key] === 'undefined') {
obj[key] = {}
const oldChildren = obj[key]?.children ?? {}
const isHome = page.slug.length === 1 && page.slug[0] === 'home'
obj[key] = {
slug: page.slug,
name: page.name,
navigational: page.navigational,
children: oldChildren,
isHome,
}
obj[key].slug = page.slug
obj[key].name = page.name
obj[key].navigational = page.navigational
}
return acc
Expand Down
Loading

0 comments on commit 269db99

Please sign in to comment.