Adds document deletion and file deletion
This commit is contained in:
parent
0d93394008
commit
c44fa80d7f
7 changed files with 94 additions and 45 deletions
|
@ -44,8 +44,10 @@ class FilemureApp(repository: SqliteRepository) {
|
|||
server.get("/document/{extId}/download", documentController::downloadDocument, Role.USER)
|
||||
server.get("/document/{extId}/edit", documentController::editDocumentForm, Role.USER)
|
||||
server.post("/document/{extId}/edit", documentController::editDocumentAction, Role.USER)
|
||||
server.post("/document/{extId}/delete", documentController::deleteDocumentAction, Role.USER)
|
||||
|
||||
server.get("/file/{extId}/download", documentController::downloadFile, Role.USER)
|
||||
server.get("/file/{extId}/delete", documentController::deleteFileAction, Role.USER)
|
||||
|
||||
server.exception(UnauthorizedResponse::class.java) { e, ctx ->
|
||||
ctx.tempolin(
|
||||
|
|
|
@ -89,6 +89,7 @@ class DocumentController(val modifiers: TemplateModifiers, val repository: Sqlit
|
|||
referenceDate = formDtf.format(referenceDate),
|
||||
tags = { tags.map { TagsBlock(it) } },
|
||||
description = description,
|
||||
fileId = { selectedFiles.map { FileIdBlock(it.extId.value) }.asSequence() },
|
||||
files = FileList(
|
||||
modifiers = modifiers,
|
||||
delete = true,
|
||||
|
@ -147,6 +148,15 @@ class DocumentController(val modifiers: TemplateModifiers, val repository: Sqlit
|
|||
ctx.result(file.content)
|
||||
}
|
||||
|
||||
fun deleteFileAction(ctx: Context) {
|
||||
val session = ctx.requireSession()
|
||||
val extId = ExtId(ctx.pathParam("extId"))
|
||||
|
||||
repository.setFileState(session.id, extId = extId, state = State.ARCHIVED)
|
||||
|
||||
ctx.redirectPRG("/")
|
||||
}
|
||||
|
||||
fun editDocumentForm(ctx: Context) {
|
||||
val session = ctx.requireSession()
|
||||
val extId = ctx.pathParam("extId")
|
||||
|
@ -212,4 +222,13 @@ class DocumentController(val modifiers: TemplateModifiers, val repository: Sqlit
|
|||
|
||||
ctx.redirectPRG("/document/$extId")
|
||||
}
|
||||
|
||||
fun deleteDocumentAction(ctx: Context) {
|
||||
val session = ctx.requireSession()
|
||||
val extId = ExtId(ctx.pathParam("extId"))
|
||||
|
||||
repository.setDocumentState(accountId = session.id, extId = extId, State.DELETED)
|
||||
|
||||
ctx.redirectPRG("/")
|
||||
}
|
||||
}
|
|
@ -153,7 +153,8 @@ class SqliteRepository(url: String) {
|
|||
}
|
||||
}
|
||||
|
||||
fun getDocumentsByYearMonth(accountId: Long, year: Int, month: Int, state: State = State.ACTIVE) = "%04d%02d".format(year, month).let { date ->
|
||||
fun getDocumentsByYearMonth(accountId: Long, year: Int, month: Int, state: State = State.ACTIVE) =
|
||||
"%04d%02d".format(year, month).let { date ->
|
||||
database.databaseQueries.getDocumentsByYearMonth(
|
||||
account_id = accountId,
|
||||
yearMonth = date,
|
||||
|
@ -246,4 +247,11 @@ class SqliteRepository(url: String) {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun setDocumentState(accountId: Long, extId: ExtId, state: State) {
|
||||
database.databaseQueries.setDocumentState(account_id = accountId, ext_id = extId, state = state)
|
||||
}
|
||||
fun setFileState(accountId: Long, extId: ExtId, state: State) {
|
||||
database.databaseQueries.setFileState(account_id = accountId, ext_id = extId, state = state)
|
||||
}
|
||||
}
|
|
@ -199,10 +199,13 @@ getLastInsertRowId:
|
|||
SELECT last_insert_rowid();
|
||||
|
||||
setDocumentState:
|
||||
UPDATE document SET state=? WHERE ext_id=?;
|
||||
UPDATE document SET state=? WHERE account_id=? AND ext_id=?;
|
||||
|
||||
setDocumentStates:
|
||||
UPDATE document SET state=? WHERE ext_id IN ?;
|
||||
setDocumentsState:
|
||||
UPDATE document SET state=? WHERE account_id=? AND ext_id IN ?;
|
||||
|
||||
setFilesStates:
|
||||
UPDATE file SET state=? WHERE ext_id IN ?;
|
||||
setFileState:
|
||||
UPDATE file SET state=? WHERE account_id=? AND ext_id=?;
|
||||
|
||||
setFilesState:
|
||||
UPDATE file SET state=? WHERE account_id=? AND ext_id IN ?;
|
||||
|
|
|
@ -11,3 +11,8 @@
|
|||
{template $files}
|
||||
|
||||
<p><a href="/document/{*$extId}/edit">edit</a></p>
|
||||
|
||||
|
||||
<form action="/document/{*$extId}/delete" method="post">
|
||||
<input type="submit" value="delete">
|
||||
</form>
|
|
@ -13,6 +13,10 @@
|
|||
<textarea name="description" rows="40" cols="80">{*$description}</textarea>
|
||||
</label></p>
|
||||
|
||||
{for $fileId}
|
||||
<input type="hidden" name="file_id" value="{*$extId}">
|
||||
{/for}
|
||||
|
||||
<p><input type="submit" value="create"></p>
|
||||
|
||||
{template $files}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<h1>Filemure Limbo</h1>
|
||||
|
||||
<p>{$limboFileCount} Files</p>
|
||||
<form action="/document/new" method="get">
|
||||
<form id="newdoc" action="/document/new" method="get">
|
||||
</form>
|
||||
<table>
|
||||
<tr>
|
||||
<th>-</th>
|
||||
|
@ -9,16 +10,23 @@
|
|||
<th>Type</th>
|
||||
<th>Size</th>
|
||||
<th>Uploaded</th>
|
||||
<th>view</th>
|
||||
<th>delete</th>
|
||||
</tr>
|
||||
{for $file}
|
||||
<tr>
|
||||
<td><label><input type="checkbox" name="file_id" value="{*$extId}"></label></td>
|
||||
<td><label><input type="checkbox" name="file_id" value="{*$extId}" form="newdoc"></label></td>
|
||||
<td>{*$file}</td>
|
||||
<td>{*$type}</td>
|
||||
<td>{*$size}</td>
|
||||
<td>{*$uploaded}</td>
|
||||
<td><a href="/file/{*$extId}/download">
|
||||
view
|
||||
</a></td>
|
||||
<td>
|
||||
<form action="/file/{*$extId}/delete"><input type="submit" value="delete"></form>
|
||||
</td>
|
||||
</tr>
|
||||
{/for}
|
||||
</table>
|
||||
<input type="submit" value="new document">
|
||||
</form>
|
||||
<input type="submit" value="new document" form="newdoc">
|
||||
|
|
Loading…
Reference in a new issue