Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
516220bd
Commit
516220bd
authored
Oct 09, 2017
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: delete a page
parent
fc764b7e
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
169 additions
and
3 deletions
+169
-3
app.js
client/js/app.js
+2
-0
modal-delete-page.vue
client/js/components/modal-delete-page.vue
+66
-0
index.js
client/js/store/index.js
+2
-0
modal-delete-page.js
client/js/store/modules/modal-delete-page.js
+14
-0
nav.scss
client/scss/components/nav.scss
+5
-1
pages.js
server/controllers/pages.js
+25
-0
entries.js
server/libs/entries.js
+26
-0
git.js
server/libs/git.js
+23
-0
browser.json
server/locales/en/browser.json
+3
-2
view.pug
server/views/pages/view.pug
+3
-0
yarn.lock
yarn.lock
+0
-0
No files found.
client/js/app.js
View file @
516220bd
...
...
@@ -38,6 +38,7 @@ import historyComponent from './components/history.vue'
import
loadingSpinnerComponent
from
'./components/loading-spinner.vue'
import
modalCreatePageComponent
from
'./components/modal-create-page.vue'
import
modalCreateUserComponent
from
'./components/modal-create-user.vue'
import
modalDeletePageComponent
from
'./components/modal-delete-page.vue'
import
modalDeleteUserComponent
from
'./components/modal-delete-user.vue'
import
modalDiscardPageComponent
from
'./components/modal-discard-page.vue'
import
modalMovePageComponent
from
'./components/modal-move-page.vue'
...
...
@@ -86,6 +87,7 @@ Vue.component('history', historyComponent)
Vue
.
component
(
'loadingSpinner'
,
loadingSpinnerComponent
)
Vue
.
component
(
'modalCreatePage'
,
modalCreatePageComponent
)
Vue
.
component
(
'modalCreateUser'
,
modalCreateUserComponent
)
Vue
.
component
(
'modalDeletePage'
,
modalDeletePageComponent
)
Vue
.
component
(
'modalDeleteUser'
,
modalDeleteUserComponent
)
Vue
.
component
(
'modalDiscardPage'
,
modalDiscardPageComponent
)
Vue
.
component
(
'modalMovePage'
,
modalMovePageComponent
)
...
...
client/js/components/modal-delete-page.vue
0 → 100644
View file @
516220bd
<
template
lang=
"pug"
>
transition(:duration="400")
.modal(v-show='isShown', v-cloak)
transition(name='modal-background')
.modal-background(v-show='isShown')
.modal-container
transition(name='modal-content')
.modal-content(v-show='isShown')
header.is-red
span
{{
$t
(
'modal.deletepagetitle'
)
}}
p.modal-notify(v-bind:class='{ "is-active": isLoading }'): i
section
span
{{
$t
(
'modal.deletepagewarning'
)
}}
footer
a.button.is-grey.is-outlined(v-on:click='discard')
{{
$t
(
'modal.discard'
)
}}
a.button.is-red(v-on:click='deletePage')
{{
$t
(
'modal.delete'
)
}}
</
template
>
<
script
>
export
default
{
name
:
'modal-delete-page'
,
props
:
[
'currentPath'
],
data
()
{
return
{
isLoading
:
false
}
},
computed
:
{
isShown
()
{
return
this
.
$store
.
state
.
modalDeletePage
.
shown
}
},
methods
:
{
discard
()
{
this
.
isLoading
=
false
this
.
$store
.
dispatch
(
'modalDeletePage/close'
)
},
deletePage
()
{
let
self
=
this
this
.
isLoading
=
true
this
.
$http
.
delete
(
window
.
location
.
href
).
then
(
resp
=>
{
return
resp
.
json
()
}).
then
(
resp
=>
{
if
(
resp
.
ok
)
{
window
.
location
.
assign
(
'/'
)
}
else
{
self
.
isLoading
=
false
self
.
$store
.
dispatch
(
'alert'
,
{
style
:
'red'
,
icon
:
'ui-2_square-remove-09'
,
msg
:
resp
.
msg
})
}
}).
catch
(
err
=>
{
self
.
isLoading
=
false
self
.
$store
.
dispatch
(
'alert'
,
{
style
:
'red'
,
icon
:
'ui-2_square-remove-09'
,
msg
:
'Error: '
+
err
.
body
.
msg
})
})
}
}
}
</
script
>
client/js/store/index.js
View file @
516220bd
...
...
@@ -10,6 +10,7 @@ import editorVideo from './modules/editor-video'
import
modalCreatePage
from
'./modules/modal-create-page'
import
modalCreateUser
from
'./modules/modal-create-user'
import
modalDeleteUser
from
'./modules/modal-delete-user'
import
modalDeletePage
from
'./modules/modal-delete-page'
import
modalDiscardPage
from
'./modules/modal-discard-page'
import
modalMovePage
from
'./modules/modal-move-page'
import
modalProfile2fa
from
'./modules/modal-profile-2fa'
...
...
@@ -39,6 +40,7 @@ export default new Vuex.Store({
editorVideo
,
modalCreatePage
,
modalCreateUser
,
modalDeletePage
,
modalDeleteUser
,
modalDiscardPage
,
modalMovePage
,
...
...
client/js/store/modules/modal-delete-page.js
0 → 100644
View file @
516220bd
export
default
{
namespaced
:
true
,
state
:
{
shown
:
false
},
getters
:
{},
mutations
:
{
shownChange
:
(
state
,
shownState
)
=>
{
state
.
shown
=
shownState
}
},
actions
:
{
open
({
commit
})
{
commit
(
'shownChange'
,
true
)
},
close
({
commit
})
{
commit
(
'shownChange'
,
false
)
}
}
}
client/scss/components/nav.scss
View file @
516220bd
...
...
@@ -173,7 +173,11 @@
&
.is-outlined
{
background-color
:
mc
(
$primary
,
'500'
);
color
:
mc
(
$primary
,
'100'
);
}
}
&
.is-icon-only
i
{
margin-right
:
0
;
}
&
:hover
{
background-color
:
mc
(
$primary
,
'700'
);
...
...
server/controllers/pages.js
View file @
516220bd
...
...
@@ -288,4 +288,29 @@ router.put('/*', (req, res, next) => {
})
})
/**
* Delete document
*/
router
.
delete
(
'/*'
,
(
req
,
res
,
next
)
=>
{
if
(
!
res
.
locals
.
rights
.
write
)
{
return
res
.
json
({
ok
:
false
,
error
:
lang
.
t
(
'errors:forbidden'
)
})
}
let
safePath
=
entryHelper
.
parsePath
(
req
.
path
)
entries
.
remove
(
safePath
,
req
.
user
).
then
(()
=>
{
res
.
json
({
ok
:
true
})
}).
catch
((
err
)
=>
{
res
.
json
({
ok
:
false
,
error
:
err
.
message
})
})
})
module
.
exports
=
router
server/libs/entries.js
View file @
516220bd
...
...
@@ -389,6 +389,32 @@ module.exports = {
},
/**
* Delete a document
*
* @param {String} entryPath The current entry path
* @param {Object} author The author user object
* @return {Promise} Promise of the operation
*/
remove
(
entryPath
,
author
)
{
if
(
_
.
isEmpty
(
entryPath
)
||
entryPath
===
'home'
)
{
return
Promise
.
reject
(
new
Error
(
lang
.
t
(
'errors:invalidpath'
)))
}
return
git
.
deleteDocument
(
entryPath
,
author
).
then
(()
=>
{
// Delete old cache version
let
oldEntryCachePath
=
entryHelper
.
getCachePath
(
entryPath
)
fs
.
unlinkAsync
(
oldEntryCachePath
).
catch
((
err
)
=>
{
return
true
})
// eslint-disable-line handle-callback-err
// Delete old index entry
search
.
delete
(
entryPath
)
// Delete entry
return
db
.
Entry
.
deleteOne
({
_id
:
entryPath
})
})
},
/**
* Generate a starter page content based on the entry path
*
* @param {String} entryPath The entry path
...
...
server/libs/git.js
View file @
516220bd
...
...
@@ -246,6 +246,29 @@ module.exports = {
},
/**
* Delete a document.
*
* @param {String} entryPath The entry path
* @return {Promise<Boolean>} Resolve on success
*/
deleteDocument
(
entryPath
,
author
)
{
let
self
=
this
let
gitFilePath
=
entryPath
+
'.md'
return
this
.
_git
.
exec
(
'rm'
,
[
gitFilePath
]).
then
((
cProc
)
=>
{
let
out
=
cProc
.
stdout
.
toString
()
if
(
_
.
includes
(
out
,
'fatal'
))
{
let
errorMsg
=
_
.
capitalize
(
_
.
head
(
_
.
split
(
_
.
replace
(
out
,
'fatal: '
,
''
),
','
)))
throw
new
Error
(
errorMsg
)
}
let
commitUsr
=
securityHelper
.
sanitizeCommitUser
(
author
)
return
self
.
_git
.
exec
(
'commit'
,
[
'-m'
,
lang
.
t
(
'git:deleted'
,
{
path
:
gitFilePath
}),
'--author="'
+
commitUsr
.
name
+
' <'
+
commitUsr
.
email
+
'>"'
]).
catch
((
err
)
=>
{
if
(
_
.
includes
(
err
.
stdout
,
'nothing to commit'
))
{
return
true
}
})
})
},
/**
* Commits uploads changes.
*
* @param {String} msg The commit message
...
...
server/locales/en/browser.json
View file @
516220bd
...
...
@@ -77,6 +77,8 @@
"delete"
:
"Delete"
,
"deletefiletitle"
:
"Delete?"
,
"deletefilewarn"
:
"Are you sure you want to delete"
,
"deletepagewarning"
:
"Are you sure you want to delete this page? This action cannot be undone!"
,
"deletepagetitle"
:
"Delete this page?"
,
"deleteusertitle"
:
"Delete User Account?"
,
"deleteuserwarning"
:
"Are you sure you want to delete this user account? This action cannot be undone!"
,
"discard"
:
"Discard"
,
...
...
@@ -113,4 +115,4 @@
"placeholder"
:
"Search..."
,
"results"
:
"Search Results"
}
}
\ No newline at end of file
}
server/views/pages/view.pug
View file @
516220bd
...
...
@@ -12,6 +12,8 @@ block rootNavRight
loading-spinner
.nav-item
if rights.write && pageData.meta.path !== 'home'
a.button.is-outlined.is-icon-only(@click='$store.dispatch("modalDeletePage/open")')
i.nc-icon-outline.ui-1_trash
a.button.is-outlined(v-on:click='$store.dispatch("modalMovePage/open")')
i.nc-icon-outline.arrows-1_shuffle-98
span= t('nav.move')
...
...
@@ -83,4 +85,5 @@ block content
modal-create-page(basepath=pageData.meta.path)
modal-move-page(current-path=pageData.meta.path)
modal-delete-page(current-path=pageData.meta.path)
anchor
yarn.lock
View file @
516220bd
This diff was suppressed by a .gitattributes entry.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment