Skip to content
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
28 changes: 21 additions & 7 deletions oreClient/src/main/assets/pages/project/ProjectDocs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ import Editor from '../../components/Editor'
import MemberList from '../../components/MemberList'
import { Category } from '../../enums'
import PageList from '../../components/PageList'
import { genericError, notFound, numberWithCommas } from '../../utils'
import { genericError, notFound, numberWithCommas, slugify } from '../../utils'
import Modal from '../../components/Modal'

export default {
Expand Down Expand Up @@ -339,14 +339,15 @@ export default {
content = page.content ? page.content : 'Welcome to your new page'
}
let action
let pageSlug
if (this.newPage) {
const pageSlug = page.parent ? page.parent + '/' + page.name : page.name
pageSlug = page.parent ? page.parent + '/' + slugify(page.name) : slugify(page.name)
action = API.projectRequest(this.project.namespace, '_pages/' + pageSlug, 'PUT', {
name: page.name,
content,
})
} else {
const pageSlug = page.oldParent ? page.oldParent + '/' + page.oldName : page.oldName
pageSlug = page.oldParent ? page.oldParent + '/' + slugify(page.oldName) : slugify(page.oldName)
action = API.projectRequest(this.project.namespace, '_pages/' + pageSlug, 'PATCH', {
name: page.name,
content,
Expand All @@ -356,9 +357,19 @@ export default {

action
.then((res) => {
const currentJoinedPage = this.joinedPage
this.$refs.editPageModal.toggle()
this.resetPutPage()
this.updatePage(true)
if (currentJoinedPage === pageSlug) {
// TODO: Route to the created page without data races
// We should really call updatePage here too, but then we get a 404
this.$router.push({
name: 'project_home',
params: { project: this.project, permissions: this.permissions },
})
} else {
this.resetPutPage()
this.updatePage(true)
}
})
.catch((err) => {
// TODO: Better error handling here
Expand All @@ -382,15 +393,18 @@ export default {
},
deletePage() {
const page = this.requestPage
const pageSlug = page.parent ? page.parent + '/' + page.name : page.name
const pageSlug = page.parent ? page.parent + '/' + slugify(page.name) : slugify(page.name)

API.projectRequest(this.project.namespace, '_pages/' + pageSlug, 'DELETE')
.then((res) => {
this.$refs.editPageModal.toggle()
this.resetPutPage()

if (pageSlug === this.joinedPage) {
this.$router.push({ name: 'home', params: { project: this.project, permissions: this.permissions } })
this.$router.push({
name: 'project_home',
params: { project: this.project, permissions: this.permissions },
})
} else {
this.updatePage(true)
}
Expand Down
2 changes: 1 addition & 1 deletion oreClient/src/main/assets/pages/project/VersionPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ export default {

this.spinIcon = true
if (Object.entries(patchVersion).length) {
API.versionRequest(this.project.namespace, this.version, 'PATCH', patchVersion).then((res) => {
API.versionRequest(this.project.namespace, this.version, '', 'PATCH', patchVersion).then((res) => {
this.spinIcon = false
this.editVersion = false
this.versionObj = res
Expand Down
10 changes: 10 additions & 0 deletions oreClient/src/main/assets/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ export function genericError(self, error) {
message: error,
})
}

export function compact(str) {
return str.trim().replaceAll(/ +/g, ' ')
}

export function slugify(str) {
const replaceRegex = /[^a-z\-_.0-9]/g
const replaced = compact(str).toLowerCase().replaceAll(' ', '-').replaceAll(replaceRegex, '')
return replaced.substring(0, Math.min(32, replaced.length))
}
1 change: 1 addition & 0 deletions orePlayCommon/app/views/layout/base.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<script @CSPNonce.attr>
window.csrf = '@play.filters.csrf.CSRF.getToken.get.value';
window.isLoggedIn = @request.hasUser;
$.ajaxSetup({headers: {'Csrf-Token': csrf}});
</script>
}

Expand Down