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}/download", documentController::downloadDocument, Role.USER)
|
||||||
server.get("/document/{extId}/edit", documentController::editDocumentForm, Role.USER)
|
server.get("/document/{extId}/edit", documentController::editDocumentForm, Role.USER)
|
||||||
server.post("/document/{extId}/edit", documentController::editDocumentAction, 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}/download", documentController::downloadFile, Role.USER)
|
||||||
|
server.get("/file/{extId}/delete", documentController::deleteFileAction, Role.USER)
|
||||||
|
|
||||||
server.exception(UnauthorizedResponse::class.java) { e, ctx ->
|
server.exception(UnauthorizedResponse::class.java) { e, ctx ->
|
||||||
ctx.tempolin(
|
ctx.tempolin(
|
||||||
|
|
|
@ -89,6 +89,7 @@ class DocumentController(val modifiers: TemplateModifiers, val repository: Sqlit
|
||||||
referenceDate = formDtf.format(referenceDate),
|
referenceDate = formDtf.format(referenceDate),
|
||||||
tags = { tags.map { TagsBlock(it) } },
|
tags = { tags.map { TagsBlock(it) } },
|
||||||
description = description,
|
description = description,
|
||||||
|
fileId = { selectedFiles.map { FileIdBlock(it.extId.value) }.asSequence() },
|
||||||
files = FileList(
|
files = FileList(
|
||||||
modifiers = modifiers,
|
modifiers = modifiers,
|
||||||
delete = true,
|
delete = true,
|
||||||
|
@ -147,6 +148,15 @@ class DocumentController(val modifiers: TemplateModifiers, val repository: Sqlit
|
||||||
ctx.result(file.content)
|
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) {
|
fun editDocumentForm(ctx: Context) {
|
||||||
val session = ctx.requireSession()
|
val session = ctx.requireSession()
|
||||||
val extId = ctx.pathParam("extId")
|
val extId = ctx.pathParam("extId")
|
||||||
|
@ -212,4 +222,13 @@ class DocumentController(val modifiers: TemplateModifiers, val repository: Sqlit
|
||||||
|
|
||||||
ctx.redirectPRG("/document/$extId")
|
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,25 +153,26 @@ 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) =
|
||||||
database.databaseQueries.getDocumentsByYearMonth(
|
"%04d%02d".format(year, month).let { date ->
|
||||||
account_id = accountId,
|
database.databaseQueries.getDocumentsByYearMonth(
|
||||||
yearMonth = date,
|
account_id = accountId,
|
||||||
state = state
|
yearMonth = date,
|
||||||
).executeAsList().map {
|
state = state
|
||||||
Document(
|
).executeAsList().map {
|
||||||
id = it.id,
|
Document(
|
||||||
extId = it.ext_id,
|
id = it.id,
|
||||||
title = it.title,
|
extId = it.ext_id,
|
||||||
description = it.description,
|
title = it.title,
|
||||||
tags = it.tags,
|
description = it.description,
|
||||||
created = it.created,
|
tags = it.tags,
|
||||||
referenceDate = it.reference_date,
|
created = it.created,
|
||||||
state = it.state,
|
referenceDate = it.reference_date,
|
||||||
files = emptyList()
|
state = it.state,
|
||||||
)
|
files = emptyList()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun updateDocument(
|
fun updateDocument(
|
||||||
accountId: Long,
|
accountId: Long,
|
||||||
|
@ -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();
|
SELECT last_insert_rowid();
|
||||||
|
|
||||||
setDocumentState:
|
setDocumentState:
|
||||||
UPDATE document SET state=? WHERE ext_id=?;
|
UPDATE document SET state=? WHERE account_id=? AND ext_id=?;
|
||||||
|
|
||||||
setDocumentStates:
|
setDocumentsState:
|
||||||
UPDATE document SET state=? WHERE ext_id IN ?;
|
UPDATE document SET state=? WHERE account_id=? AND ext_id IN ?;
|
||||||
|
|
||||||
setFilesStates:
|
setFileState:
|
||||||
UPDATE file SET state=? WHERE ext_id IN ?;
|
UPDATE file SET state=? WHERE account_id=? AND ext_id=?;
|
||||||
|
|
||||||
|
setFilesState:
|
||||||
|
UPDATE file SET state=? WHERE account_id=? AND ext_id IN ?;
|
||||||
|
|
|
@ -10,4 +10,9 @@
|
||||||
|
|
||||||
{template $files}
|
{template $files}
|
||||||
|
|
||||||
<p><a href="/document/{*$extId}/edit">edit</a></p>
|
<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>
|
<textarea name="description" rows="40" cols="80">{*$description}</textarea>
|
||||||
</label></p>
|
</label></p>
|
||||||
|
|
||||||
|
{for $fileId}
|
||||||
|
<input type="hidden" name="file_id" value="{*$extId}">
|
||||||
|
{/for}
|
||||||
|
|
||||||
<p><input type="submit" value="create"></p>
|
<p><input type="submit" value="create"></p>
|
||||||
|
|
||||||
{template $files}
|
{template $files}
|
||||||
|
|
|
@ -1,24 +1,32 @@
|
||||||
<h1>Filemure Limbo</h1>
|
<h1>Filemure Limbo</h1>
|
||||||
|
|
||||||
<p>{$limboFileCount} Files</p>
|
<p>{$limboFileCount} Files</p>
|
||||||
<form action="/document/new" method="get">
|
<form id="newdoc" action="/document/new" method="get">
|
||||||
<table>
|
</form>
|
||||||
<tr>
|
<table>
|
||||||
<th>-</th>
|
<tr>
|
||||||
<th>Filename</th>
|
<th>-</th>
|
||||||
<th>Type</th>
|
<th>Filename</th>
|
||||||
<th>Size</th>
|
<th>Type</th>
|
||||||
<th>Uploaded</th>
|
<th>Size</th>
|
||||||
</tr>
|
<th>Uploaded</th>
|
||||||
{for $file}
|
<th>view</th>
|
||||||
<tr>
|
<th>delete</th>
|
||||||
<td><label><input type="checkbox" name="file_id" value="{*$extId}"></label></td>
|
</tr>
|
||||||
<td>{*$file}</td>
|
{for $file}
|
||||||
<td>{*$type}</td>
|
<tr>
|
||||||
<td>{*$size}</td>
|
<td><label><input type="checkbox" name="file_id" value="{*$extId}" form="newdoc"></label></td>
|
||||||
<td>{*$uploaded}</td>
|
<td>{*$file}</td>
|
||||||
</tr>
|
<td>{*$type}</td>
|
||||||
{/for}
|
<td>{*$size}</td>
|
||||||
</table>
|
<td>{*$uploaded}</td>
|
||||||
<input type="submit" value="new document">
|
<td><a href="/file/{*$extId}/download">
|
||||||
</form>
|
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="newdoc">
|
||||||
|
|
Loading…
Reference in a new issue