diff --git a/vripper-core/src/main/kotlin/me/vripper/download/ImageDownloadRunnable.kt b/vripper-core/src/main/kotlin/me/vripper/download/ImageDownloadRunnable.kt index ad8adea..279c1cf 100644 --- a/vripper-core/src/main/kotlin/me/vripper/download/ImageDownloadRunnable.kt +++ b/vripper-core/src/main/kotlin/me/vripper/download/ImageDownloadRunnable.kt @@ -20,6 +20,7 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardCopyOption import java.util.* +import kotlin.io.path.Path import kotlin.io.path.pathString class ImageDownloadRunnable( @@ -43,10 +44,8 @@ class ImageDownloadRunnable( image.status = Status.DOWNLOADING image.downloaded = 0 dataTransaction.updateImage(image) - val downloadDirectory: String synchronized(image.postId.toString().intern()) { val post = dataTransaction.findPostById(context.postId).orElseThrow() - downloadDirectory = post.downloadDirectory if (post.status != Status.DOWNLOADING) { post.status = Status.DOWNLOADING dataTransaction.updatePost(post) @@ -61,13 +60,14 @@ class ImageDownloadRunnable( log.debug( "Sanitizing image name from ${downloadedImage.name} to $sanitizedFileName" ) - checkImageTypeAndRename( - downloadDirectory, downloadedImage, image.index - ) synchronized(image.postId.toString().intern()) { + val post = dataTransaction.findPostById(context.postId).orElseThrow() + val downloadDirectory = Path(post.downloadDirectory, post.folderName).pathString + checkImageTypeAndRename( + downloadDirectory, downloadedImage, image.index + ) if (image.downloaded == image.size && image.size > 0) { image.status = Status.FINISHED - val post = dataTransaction.findPostById(context.postId).orElseThrow() post.done += 1 post.downloaded += image.size dataTransaction.updatePost(post) @@ -102,9 +102,7 @@ class ImageDownloadRunnable( if (existingExtension.isBlank()) "${downloadedImage.name}.$extension" else downloadedImage.name try { val downloadDestinationFolder = Path.of(downloadDirectory) - synchronized(downloadDestinationFolder.pathString.intern()) { - Files.createDirectories(downloadDestinationFolder) - } + Files.createDirectories(downloadDestinationFolder) val image = downloadDestinationFolder.resolve( "${ if (settings.downloadSettings.forceOrder) String.format( diff --git a/vripper-core/src/main/kotlin/me/vripper/entities/Post.kt b/vripper-core/src/main/kotlin/me/vripper/entities/Post.kt index 9d80081..b7e26fc 100644 --- a/vripper-core/src/main/kotlin/me/vripper/entities/Post.kt +++ b/vripper-core/src/main/kotlin/me/vripper/entities/Post.kt @@ -3,6 +3,8 @@ package me.vripper.entities import com.fasterxml.jackson.annotation.JsonFormat import me.vripper.entities.domain.Status import java.time.LocalDateTime +import kotlin.io.path.Path +import kotlin.io.path.pathString data class Post( val id: Long = -1, @@ -17,12 +19,18 @@ data class Post( val hosts: Set, val downloadDirectory: String, @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") val addedOn: LocalDateTime = LocalDateTime.now(), + var folderName: String, var status: Status = Status.STOPPED, var done: Int = 0, var rank: Int = Int.MAX_VALUE, var size: Long = -1, var downloaded: Long = 0, ) { + + fun getDownloadFolder(): String { + return Path(downloadDirectory, folderName).pathString + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false diff --git a/vripper-core/src/main/kotlin/me/vripper/repositories/impl/PostDownloadStateRepositoryImpl.kt b/vripper-core/src/main/kotlin/me/vripper/repositories/impl/PostDownloadStateRepositoryImpl.kt index aea6045..ac7888b 100644 --- a/vripper-core/src/main/kotlin/me/vripper/repositories/impl/PostDownloadStateRepositoryImpl.kt +++ b/vripper-core/src/main/kotlin/me/vripper/repositories/impl/PostDownloadStateRepositoryImpl.kt @@ -23,6 +23,7 @@ class PostDownloadStateRepositoryImpl : this[PostTable.rank] = post.rank this[PostTable.hosts] = post.hosts.joinToString(delimiter) this[PostTable.outputPath] = post.downloadDirectory + this[PostTable.folderName] = post.folderName this[PostTable.postId] = post.postId this[PostTable.threadId] = post.threadId this[PostTable.postTitle] = post.postTitle @@ -90,6 +91,7 @@ class PostDownloadStateRepositoryImpl : it[rank] = post.rank it[size] = post.size it[downloaded] = post.downloaded + it[folderName] = post.folderName } } @@ -102,6 +104,7 @@ class PostDownloadStateRepositoryImpl : this[PostTable.rank] = post.rank this[PostTable.hosts] = post.hosts.joinToString(delimiter) this[PostTable.outputPath] = post.downloadDirectory + this[PostTable.folderName] = post.folderName this[PostTable.postId] = post.postId this[PostTable.threadId] = post.threadId this[PostTable.postTitle] = post.postTitle @@ -171,6 +174,7 @@ class PostDownloadStateRepositoryImpl : val hosts = resultRow[PostTable.hosts].split(delimiter).dropLastWhile { it.isEmpty() }.toSet() val downloadDirectory = resultRow[PostTable.outputPath] + val folderName = resultRow[PostTable.folderName] val addedOn = resultRow[PostTable.addedAt] val rank = resultRow[PostTable.rank] val size = resultRow[PostTable.size] @@ -188,6 +192,7 @@ class PostDownloadStateRepositoryImpl : hosts, downloadDirectory, addedOn, + folderName, status, done, rank, diff --git a/vripper-core/src/main/kotlin/me/vripper/services/AppEndpointService.kt b/vripper-core/src/main/kotlin/me/vripper/services/AppEndpointService.kt index 6a858af..400ce42 100644 --- a/vripper-core/src/main/kotlin/me/vripper/services/AppEndpointService.kt +++ b/vripper-core/src/main/kotlin/me/vripper/services/AppEndpointService.kt @@ -8,9 +8,12 @@ import me.vripper.services.* import me.vripper.tasks.AddPostRunnable import me.vripper.tasks.ThreadLookupRunnable import me.vripper.utilities.GLOBAL_EXECUTOR +import me.vripper.utilities.PathUtils import java.util.* import java.util.concurrent.CompletableFuture import java.util.regex.Pattern +import kotlin.io.path.Path +import kotlin.io.path.exists class AppEndpointService( private val downloadService: DownloadService, @@ -65,7 +68,7 @@ class AppEndpointService( @Synchronized fun restartAll(posIds: List = listOf()) { - downloadService.restartAll(posIds.map { dataTransaction.findPostsByPostId(it) }.filter { it.isPresent } + downloadService.restartAll(posIds.map { dataTransaction.findPostByPostId(it) }.filter { it.isPresent } .map { it.get() }) } @@ -139,6 +142,19 @@ class AppEndpointService( fun logClear() { dataTransaction.deleteAllLogs() + } + fun rename(postId: Long, name: String) { + CompletableFuture.runAsync({ + synchronized(postId.toString().intern()) { + dataTransaction.findPostByPostId(postId).ifPresent { post -> + if (Path(post.downloadDirectory, post.folderName).exists()) { + PathUtils.rename(post.downloadDirectory, post.folderName, name) + } + post.folderName = name + dataTransaction.updatePost(post) + } + } + }, GLOBAL_EXECUTOR) } } \ No newline at end of file diff --git a/vripper-core/src/main/kotlin/me/vripper/services/DataTransaction.kt b/vripper-core/src/main/kotlin/me/vripper/services/DataTransaction.kt index c622565..4ea0266 100644 --- a/vripper-core/src/main/kotlin/me/vripper/services/DataTransaction.kt +++ b/vripper-core/src/main/kotlin/me/vripper/services/DataTransaction.kt @@ -7,6 +7,7 @@ import me.vripper.model.ErrorCount import me.vripper.model.PostItem import me.vripper.repositories.* import me.vripper.utilities.PathUtils +import me.vripper.utilities.PathUtils.sanitize import org.jetbrains.exposed.sql.transactions.transaction import java.util.* import kotlin.io.path.pathString @@ -75,10 +76,11 @@ class DataTransaction( downloadDirectory = PathUtils.calculateDownloadPath( postItem.forum, postItem.threadTitle, - postItem.title, - postItem.postId, settingsService.settings - ).pathString + ).pathString, + folderName = if (settingsService.settings.downloadSettings.appendPostId) "${sanitize(postItem.title)}_${postItem.postId}" else sanitize( + postItem.title + ) ) val images = postItem.imageItemList.mapIndexed { index, imageItem -> Image( @@ -115,7 +117,7 @@ class DataTransaction( } fun finishPost(postId: Long, automatic: Boolean = false) { - val post = findPostsByPostId(postId).orElseThrow() + val post = findPostByPostId(postId).orElseThrow() val imagesInErrorStatus = findByPostIdAndIsError(post.postId) if (imagesInErrorStatus.isNotEmpty()) { post.status = Status.ERROR @@ -239,7 +241,7 @@ class DataTransaction( return transaction { imageRepository.countError() } } - fun findPostsByPostId(postId: Long): Optional { + fun findPostByPostId(postId: Long): Optional { return transaction { postDownloadStateRepository.findByPostId(postId) } } diff --git a/vripper-core/src/main/kotlin/me/vripper/tables/PostTable.kt b/vripper-core/src/main/kotlin/me/vripper/tables/PostTable.kt index 5d1c5bf..25c6eb9 100644 --- a/vripper-core/src/main/kotlin/me/vripper/tables/PostTable.kt +++ b/vripper-core/src/main/kotlin/me/vripper/tables/PostTable.kt @@ -8,6 +8,7 @@ object PostTable : LongIdTable(name = "POST", columnName = "ID") { val done = integer("DONE") val hosts = varchar("HOSTS", 255) val outputPath = varchar("OUTPUT_PATH", 260) + val folderName = varchar("FOLDER_NAME", 260) val postId = long("POST_ID") val status = varchar("STATUS", 15) val threadId = long("THREAD_ID") diff --git a/vripper-core/src/main/kotlin/me/vripper/utilities/PathUtils.kt b/vripper-core/src/main/kotlin/me/vripper/utilities/PathUtils.kt index a812cc2..ef51ecf 100644 --- a/vripper-core/src/main/kotlin/me/vripper/utilities/PathUtils.kt +++ b/vripper-core/src/main/kotlin/me/vripper/utilities/PathUtils.kt @@ -1,7 +1,13 @@ package me.vripper.utilities +import me.vripper.exception.RenameException import me.vripper.model.Settings +import java.io.IOException +import java.nio.file.Files import java.nio.file.Path +import java.nio.file.StandardCopyOption +import kotlin.io.path.Path + object PathUtils { private val log by me.vripper.delegate.LoggerDelegate() @@ -9,7 +15,7 @@ object PathUtils { fun calculateDownloadPath( - forum: String, threadTitle: String, postTitle: String, postId: Long, settings: Settings + forum: String, threadTitle: String, settings: Settings ): Path { var downloadDirectory = if (settings.downloadSettings.forumSubDirectory) Path.of( settings.downloadSettings.downloadPath, sanitize(forum) @@ -18,14 +24,29 @@ object PathUtils { ) downloadDirectory = if (settings.downloadSettings.threadSubLocation) downloadDirectory.resolve(threadTitle) else downloadDirectory - downloadDirectory = downloadDirectory.resolve( - if (settings.downloadSettings.appendPostId) "${sanitize(postTitle)}_${postId}" else sanitize( - postTitle - ) - ) return downloadDirectory } + @Throws(RenameException::class) + fun rename(downloadDirectory: String, oldFolder: String, newFolder: String) { + val currentDownloadDirectory = Path(downloadDirectory, oldFolder) + val newDownloadDirectory = Path(downloadDirectory, sanitize(newFolder)) + try { + Files.move( + currentDownloadDirectory, + newDownloadDirectory, + StandardCopyOption.ATOMIC_MOVE + ) + } catch (e: IOException) { + throw RenameException( + String.format( + "Failed to move files from %s to %s", currentDownloadDirectory, newDownloadDirectory + ), + e + ) + } + } + /** * Will sanitize the image name and remove extension * diff --git a/vripper-core/src/main/resources/db.changelog-master.xml b/vripper-core/src/main/resources/db.changelog-master.xml index fbd6b60..36fcdda 100644 --- a/vripper-core/src/main/resources/db.changelog-master.xml +++ b/vripper-core/src/main/resources/db.changelog-master.xml @@ -145,4 +145,9 @@ + + + + + diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/controller/PostController.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/controller/PostController.kt index 9874e9a..873c7ef 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/controller/PostController.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/controller/PostController.kt @@ -2,7 +2,6 @@ package me.vripper.gui.controller import kotlinx.coroutines.* import me.vripper.entities.Image -import me.vripper.entities.Post import me.vripper.gui.model.PostModel import me.vripper.services.AppEndpointService import me.vripper.services.DataTransaction @@ -58,25 +57,26 @@ class PostController : Controller() { } fun findAllPosts(): Deferred> { - return coroutineScope.async { dataTransaction.findAllPosts().map(::mapper) } + return coroutineScope.async { dataTransaction.findAllPosts().map { it.id }.map(::mapper) } } - fun mapper(it: Post): PostModel { - val updated = dataTransaction.findPostById(it.id).orElseThrow() + fun mapper(id: Long): PostModel { + val post = dataTransaction.findPostById(id).orElseThrow() return PostModel( - updated.postId, - updated.postTitle, - progress(updated.total, updated.done), - updated.status.name, - updated.url, - updated.done, - updated.total, - updated.hosts.joinToString(separator = ", "), - updated.addedOn.format(dateTimeFormatter), - updated.rank + 1, - updated.downloadDirectory, - progressCount(updated.total, updated.done, updated.downloaded), - dataTransaction.findImagesByPostId(updated.postId).map(Image::thumbUrl).take(4) + post.postId, + post.postTitle, + progress(post.total, post.done), + post.status.name, + post.url, + post.done, + post.total, + post.hosts.joinToString(separator = ", "), + post.addedOn.format(dateTimeFormatter), + post.rank + 1, + post.getDownloadFolder(), + post.folderName, + progressCount(post.total, post.done, post.downloaded), + dataTransaction.findImagesByPostId(post.postId).map(Image::thumbUrl).take(4) ) } @@ -87,4 +87,8 @@ class PostController : Controller() { fun progress(total: Int, done: Int): Double { return if (done == 0 && total == 0) 0.0 else (done.toDouble() / total) } + + fun rename(postId: Long, value: String) { + appEndpointService.rename(postId, value) + } } \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostModel.kt index 9622c2f..f77f974 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostModel.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostModel.kt @@ -19,6 +19,7 @@ class PostModel( addedOn: String, order: Int, path: String, + folderName: String, progressCount: String, previewList: List ) { @@ -55,6 +56,9 @@ class PostModel( val pathProperty = SimpleStringProperty(path) var path: String by pathProperty + val folderNameProperty = SimpleStringProperty(folderName) + var folderName: String by folderNameProperty + val progressCountProperty = SimpleStringProperty(progressCount) var progressCount: String by progressCountProperty diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/DownloadActionsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/DownloadActionsView.kt index 667c458..a1f3220 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/DownloadActionsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/DownloadActionsView.kt @@ -98,6 +98,25 @@ class DownloadActionsView : View() { postsTableView.stopSelected() } } + button("Rename") { + setPrefSize(32.0, 32.0) + imageview("edit.png") { + fitWidth = 32.0 + fitHeight = 32.0 + } + addClass(Styles.actionBarButton) + contentDisplay = ContentDisplay.GRAPHIC_ONLY + tooltip("Rename selected [Ctrl+R]") + shortcut(KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN)) + enableWhen( + postsTableView.tableView.selectionModel.selectedItems.sizeProperty.greaterThan( + 0 + ) + ) + action { + postsTableView.renameSelected() + } + } button("Delete") { setPrefSize(32.0, 32.0) imageview("trash.png") { diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/PostsTableView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/PostsTableView.kt index 3dfc316..fd4ea8f 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/PostsTableView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/PostsTableView.kt @@ -21,6 +21,7 @@ import me.vripper.gui.clipboard.ClipboardService import me.vripper.gui.controller.PostController import me.vripper.gui.model.PostModel import me.vripper.gui.view.* +import me.vripper.gui.view.popup.RenameView import tornadofx.* class PostsTableView : View() { @@ -57,7 +58,7 @@ class PostsTableView : View() { } eventBus.events.ofType(PostCreateEvent::class.java).subscribe { postEvents -> - val add = postEvents.posts.map { postController.mapper(it) } + val add = postEvents.posts.map { postController.mapper(it.id) } runLater { tableView.items.addAll(add) } @@ -77,6 +78,8 @@ class PostsTableView : View() { postModel.progress = postController.progress( post.total, post.done ) + postModel.path = post.getDownloadFolder() + postModel.folderName = post.folderName } } } @@ -121,6 +124,16 @@ class PostsTableView : View() { } } + val renameItem = MenuItem("Rename").apply { + setOnAction { + rename(tableRow.item) + } + graphic = ImageView("edit.png").apply { + fitWidth = 18.0 + fitHeight = 18.0 + } + } + val deleteItem = MenuItem("Delete").apply { setOnAction { deleteSelected() @@ -163,7 +176,7 @@ class PostsTableView : View() { val contextMenu = ContextMenu() contextMenu.items.addAll( - startItem, stopItem, deleteItem, SeparatorMenuItem(), detailsItem, locationItem, urlItem + startItem, stopItem, renameItem, deleteItem, SeparatorMenuItem(), detailsItem, locationItem, urlItem ) tableRow.contextMenuProperty() .bind(tableRow.emptyProperty().map { empty -> if (empty) null else contextMenu }) @@ -284,6 +297,20 @@ class PostsTableView : View() { } } + private fun rename(post: PostModel) { + find(mapOf(RenameView::postId to post.postId, RenameView::name to post.folderName)).openModal() + ?.apply { + minWidth = 300.0 + } + } + + fun renameSelected() { + val selectedItem = tableView.selectionModel.selectedItem + if (selectedItem != null) { + rename(selectedItem) + } + } + fun deleteSelected() { val postIdList = tableView.selectionModel.selectedItems.map { it.postId } confirm( diff --git a/vripper-web-ui/src/app/app.component.html b/vripper-web-ui/src/app/app.component.html index 48c1e6b..f5bb2b9 100644 --- a/vripper-web-ui/src/app/app.component.html +++ b/vripper-web-ui/src/app/app.component.html @@ -9,6 +9,7 @@ (startSelected)="onStartSelected()" (stopSelected)="onStopSelected()" (deleteSelected)="onDeleteSelected()" + (renameSelected)='onRenameSelected()' (clearDownload)="onClearDownloads()" (clearLogs)="onClearLogs()" (clearThreads)="onClearThreads()"> @@ -24,7 +25,8 @@ diff --git a/vripper-web-ui/src/app/app.component.ts b/vripper-web-ui/src/app/app.component.ts index 50d8476..a7d6beb 100644 --- a/vripper-web-ui/src/app/app.component.ts +++ b/vripper-web-ui/src/app/app.component.ts @@ -1,4 +1,4 @@ -import { Component, computed, signal } from '@angular/core'; +import { Component, computed, signal, WritableSignal } from '@angular/core'; import { ToolbarComponent } from './toolbar/toolbar.component'; import { CommonModule, NgIf } from '@angular/common'; import { MatTabsModule } from '@angular/material/tabs'; @@ -20,9 +20,14 @@ import { ConfirmComponent, ConfirmDialogData, } from './confirm/confirm.component'; -import { Subject } from 'rxjs'; +import { EMPTY, mergeMap, Subject } from 'rxjs'; import { RxStompState } from '@stomp/rx-stomp'; import { StatusBarComponent } from './status-bar/status-bar.component'; +import { + RenameDialogComponent, + RenameDialogData, + RenameDialogResult, +} from './rename-dialog/rename-dialog.component'; @Component({ selector: 'app-root', @@ -49,6 +54,7 @@ export class AppComponent { logCount = signal(0); tabIndex = signal(0); + selectedPost: WritableSignal = signal(null); selectedPosts = signal([] as Post[]); noPostSelected = computed(() => this.selectedPosts().length === 0); loading = computed( @@ -71,6 +77,10 @@ export class AppComponent { this.selectedPosts.set(selectedPosts); }; + onPostSelectionChange = (selectedPost: Post) => { + this.selectedPost.set(selectedPost); + }; + onStartSelected = () => { if (this.selectedPosts().length > 0) { this.applicationEndpoint.startPosts(this.selectedPosts()).subscribe(); @@ -122,6 +132,39 @@ export class AppComponent { }); }; + onRenameSelected = () => { + if (this.selectedPost() == null) { + return; + } + const post = this.selectedPost(); + if (post?.postId == null || post?.folderName == null) { + return; + } + const dialog: MatDialogRef = + this.dialog.open< + RenameDialogComponent, + RenameDialogData, + RenameDialogResult + >(RenameDialogComponent, { + data: { + postId: post.postId, + name: post.folderName, + }, + }); + dialog + .afterClosed() + .pipe( + mergeMap(result => { + if (result) { + return this.applicationEndpoint.renamePost(result); + } else { + return EMPTY; + } + }) + ) + .subscribe(); + }; + onClearDownloads = () => { const confirmDialog: MatDialogRef = this.dialog.open(ConfirmComponent, { diff --git a/vripper-web-ui/src/app/domain/post-row.model.ts b/vripper-web-ui/src/app/domain/post-row.model.ts index 9fc3229..bf9735c 100644 --- a/vripper-web-ui/src/app/domain/post-row.model.ts +++ b/vripper-web-ui/src/app/domain/post-row.model.ts @@ -6,6 +6,7 @@ export class PostRow extends Post { public statusIcon: WritableSignal; public progress: WritableSignal; public total2: WritableSignal; + public path: WritableSignal; constructor( postId: number, @@ -18,6 +19,8 @@ export class PostRow extends Post { addedOn: string, rank: number, downloadDirectory: string, + folderName: string, + downloadFolder: string, downloaded: number ) { super( @@ -31,10 +34,13 @@ export class PostRow extends Post { addedOn, rank, downloadDirectory, + folderName, + downloadFolder, downloaded ); this.statusIcon = signal(statusIcon(status)); this.progress = signal(progress(done, total)); this.total2 = signal(totalFormatter(done, total, downloaded)); + this.path = signal(downloadFolder); } } diff --git a/vripper-web-ui/src/app/domain/post.model.ts b/vripper-web-ui/src/app/domain/post.model.ts index a55e749..d49ac6d 100644 --- a/vripper-web-ui/src/app/domain/post.model.ts +++ b/vripper-web-ui/src/app/domain/post.model.ts @@ -10,6 +10,8 @@ export class Post { public addedOn: string, public rank: number, public downloadDirectory: string, + public folderName: string, + public downloadFolder: string, public downloaded: number ) {} } diff --git a/vripper-web-ui/src/app/download-table/download-table.component.html b/vripper-web-ui/src/app/download-table/download-table.component.html index be60ed9..39a79b6 100644 --- a/vripper-web-ui/src/app/download-table/download-table.component.html +++ b/vripper-web-ui/src/app/download-table/download-table.component.html @@ -50,10 +50,10 @@ Path - {{ element.downloadDirectory }} + {{ element.path() }} diff --git a/vripper-web-ui/src/app/download-table/download-table.component.ts b/vripper-web-ui/src/app/download-table/download-table.component.ts index 515dd0f..6bc2eaf 100644 --- a/vripper-web-ui/src/app/download-table/download-table.component.ts +++ b/vripper-web-ui/src/app/download-table/download-table.component.ts @@ -8,7 +8,14 @@ import { } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Post } from '../domain/post.model'; -import { BehaviorSubject, Observable, Subscription, take } from 'rxjs'; +import { + BehaviorSubject, + EMPTY, + mergeMap, + Observable, + Subscription, + take, +} from 'rxjs'; import { ApplicationEndpointService } from '../services/application-endpoint.service'; import { Overlay, @@ -41,6 +48,11 @@ import { ConfirmDialogData, } from '../confirm/confirm.component'; import { PostRow } from '../domain/post-row.model'; +import { + RenameDialogComponent, + RenameDialogData, + RenameDialogResult, +} from '../rename-dialog/rename-dialog.component'; @Component({ selector: 'app-download-table', @@ -67,7 +79,9 @@ export class DownloadTableComponent { rowCountChange = new EventEmitter(); @Output() - selectedChange = new EventEmitter(); + selectedPostsChange = new EventEmitter(); + @Output() + selectedPostChange = new EventEmitter(); displayedColumns: string[] = [ 'title', @@ -100,9 +114,10 @@ export class DownloadTableComponent { this.dataSource._dataStream.subscribe(v => this.rowCountChange.emit(v.length) ); - this.selection.changed.subscribe(() => - this.selectedChange.emit(this.selection.selected) - ); + this.selection.changed.subscribe(selectionChange => { + this.selectedPostChange.emit(selectionChange.added[0]); + this.selectedPostsChange.emit(this.selection.selected); + }); this.breakpointObserver .observe([Breakpoints.XSmall, Breakpoints.Small, Breakpoints.Medium]) .subscribe(result => { @@ -214,6 +229,29 @@ export class DownloadTableComponent { ref.instance.onPostStop = () => this.applicationEndpoint.stopPosts(this.selection.selected).subscribe(); + ref.instance.onPostRename = () => { + const dialog: MatDialogRef = + this.dialog.open< + RenameDialogComponent, + RenameDialogData, + RenameDialogResult + >(RenameDialogComponent, { + data: { postId: row.postId, name: row.folderName }, + }); + dialog + .afterClosed() + .pipe( + mergeMap(result => { + if (result) { + return this.applicationEndpoint.renamePost(result); + } else { + return EMPTY; + } + }) + ) + .subscribe(); + }; + ref.instance.onPostDelete = () => { const dialog: MatDialogRef = this.dialog.open( @@ -271,6 +309,8 @@ class PostDataSource extends DataSource { e.addedOn, e.rank, e.downloadDirectory, + e.folderName, + e.downloadFolder, e.downloaded ) ), @@ -299,6 +339,7 @@ class PostDataSource extends DataSource { rowNode.statusIcon.set(statusIcon(v.status)); rowNode.progress.set(progress(v.done, v.total)); rowNode.total2.set(totalFormatter(v.done, v.total, v.downloaded)); + rowNode.path.set(v.downloadFolder); } }); }) diff --git a/vripper-web-ui/src/app/post-contextmenu/post-contextmenu.component.html b/vripper-web-ui/src/app/post-contextmenu/post-contextmenu.component.html index d716116..e0e2273 100644 --- a/vripper-web-ui/src/app/post-contextmenu/post-contextmenu.component.html +++ b/vripper-web-ui/src/app/post-contextmenu/post-contextmenu.component.html @@ -22,6 +22,10 @@ pause
Stop
+ + edit +
Rename
+
delete
Remove
diff --git a/vripper-web-ui/src/app/post-contextmenu/post-contextmenu.component.ts b/vripper-web-ui/src/app/post-contextmenu/post-contextmenu.component.ts index 4b52e82..9edff95 100644 --- a/vripper-web-ui/src/app/post-contextmenu/post-contextmenu.component.ts +++ b/vripper-web-ui/src/app/post-contextmenu/post-contextmenu.component.ts @@ -46,10 +46,8 @@ export class PostContextmenuComponent { }; onPostStart!: () => void; - onPostStop!: () => void; - + onPostRename!: () => void; onPostDelete!: () => void; - close!: () => void; } diff --git a/vripper-web-ui/src/app/services/application-endpoint.service.ts b/vripper-web-ui/src/app/services/application-endpoint.service.ts index bd9c9ca..bd4dd59 100644 --- a/vripper-web-ui/src/app/services/application-endpoint.service.ts +++ b/vripper-web-ui/src/app/services/application-endpoint.service.ts @@ -219,6 +219,8 @@ export class ApplicationEndpointService { element.addedOn, element.rank + 1, element.downloadDirectory, + element.folderName, + element.downloadFolder, element.downloaded ); }); @@ -240,6 +242,8 @@ export class ApplicationEndpointService { element.addedOn, element.rank + 1, element.downloadDirectory, + element.folderName, + element.downloadFolder, element.downloaded ); }); @@ -370,4 +374,8 @@ export class ApplicationEndpointService { clearThreads() { return this.httpClient.get(this.baseUrl + '/api/grab/clear'); } + + renamePost(data: { postId: number; name: string }) { + return this.httpClient.post(this.baseUrl + '/api/post/rename', data); + } } diff --git a/vripper-web-ui/src/app/toolbar/toolbar.component.html b/vripper-web-ui/src/app/toolbar/toolbar.component.html index d666c19..d51b98c 100644 --- a/vripper-web-ui/src/app/toolbar/toolbar.component.html +++ b/vripper-web-ui/src/app/toolbar/toolbar.component.html @@ -43,6 +43,13 @@ pause +