Skip to content

Commit 0db441c

Browse files
amateurforgerangrynode
authored andcommitted
fix: Proper/link display of category/folder in magnet list
1 parent 616e77a commit 0db441c

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ env_logger = "0.11.8"
3737
# Comment/uncomment below for development version
3838
# hightorrent_api = { path = "../hightorrent_api" }
3939
hightorrent_api = { git = "https://github.com/angrynode/hightorrent_api", branch = "feat-sea-orm", features = [ "sea_orm" ]}
40+
itertools = "0.14.0"
4041
# hightorrent_api = "0.2"
4142
log = "0.4.27"
4243
# SQLite ORM

src/routes/magnet.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use askama::Template;
22
use askama_web::WebTemplate;
33
use hightorrent_api::hightorrent::MagnetLink;
4+
use itertools::multizip;
45
use serde::{Deserialize, Serialize};
56
use snafu::prelude::*;
67

@@ -73,7 +74,11 @@ pub struct MagnetListTemplate {
7374
/// Global application state (errors/warnings)
7475
pub state: AppStateContext,
7576
/// Magnets stored in database
76-
pub magnets: Vec<(magnet::Model, content_folder::Model)>,
77+
pub magnets: Vec<(
78+
magnet::Model,
79+
category::Model,
80+
Option<content_folder::Model>,
81+
)>,
7782
}
7883

7984
pub async fn list(context: AppStateContext) -> Result<MagnetListTemplate, AppStateError> {
@@ -86,18 +91,20 @@ pub async fn list(context: AppStateContext) -> Result<MagnetListTemplate, AppSta
8691
.context(OtherSnafu)?;
8792

8893
// In the creation form we guarantee to set the content_folder so we can unwrap
89-
let content_folders: Vec<content_folder::Model> = magnets
94+
let content_folders: Vec<Option<content_folder::Model>> = magnets
9095
.load_one(content_folder::Entity, &context.state.database)
9196
.await
97+
.context(SqliteSnafu)?;
98+
99+
let categories: Vec<category::Model> = magnets
100+
.load_one(category::Entity, &context.state.database)
101+
.await
92102
.context(SqliteSnafu)?
93103
.into_iter()
94104
.map(|x| x.unwrap())
95105
.collect();
96106

97-
let magnets = magnets
98-
.into_iter()
99-
.zip(content_folders.into_iter())
100-
.collect();
107+
let magnets = multizip((magnets, categories, content_folders)).collect();
101108

102109
Ok(MagnetListTemplate {
103110
state: context,

templates/magnet/list.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ <h1>List of uploaded magnets not yet resolved</h1>
1515
<th>Actions</th>
1616
</tr>
1717
</thead>
18-
{% for (magnet, content_folder) in magnets %}
18+
{% for (magnet, category, content_folder) in magnets %}
1919
<tr>
2020
<td class="is-left" align="left"><a href="/magnet/{{ magnet.id }}">{{ magnet.name }}</a></td>
21-
<td><a href="/folders/{{ content_folder.category_id }}/{{ content_folder.id }}">{{ content_folder.path }}</a></td>
21+
{% if let Some(content_folder) = content_folder %}
22+
<td><a href="/folders/{{ category.name }}{{ content_folder.path }}">{{ category.name }}{{ content_folder.path }}</a></td>
23+
{% else %}
24+
<td><a href="/folders/{{ category.name }}">{{ category.name }}</a></td>
25+
{% endif %}
2226
<td>
2327
{% if magnet.resolved %}
2428
<!-- TODO: mettre le lien vers la page des d'import d'un torrent -->

0 commit comments

Comments
 (0)