fix: sort path ignore case (#264)
This commit is contained in:
parent
6510ae8be9
commit
60df3b473c
2 changed files with 42 additions and 26 deletions
|
@ -316,13 +316,13 @@ function renderPathsTableHead() {
|
|||
<tr>
|
||||
${headerItems.map(item => {
|
||||
let svg = `<svg width="12" height="12" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M11.5 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L11 2.707V14.5a.5.5 0 0 0 .5.5zm-7-14a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L4 13.293V1.5a.5.5 0 0 1 .5-.5z"/></svg>`;
|
||||
let order = "asc";
|
||||
let order = "desc";
|
||||
if (PARAMS.sort === item.name) {
|
||||
if (PARAMS.order === "asc") {
|
||||
order = "desc";
|
||||
svg = `<svg width="12" height="12" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z"/></svg>`
|
||||
} else {
|
||||
if (PARAMS.order === "desc") {
|
||||
order = "asc";
|
||||
svg = `<svg width="12" height="12" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/></svg>`
|
||||
} else {
|
||||
svg = `<svg width="12" height="12" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z"/></svg>`
|
||||
}
|
||||
}
|
||||
const qs = new URLSearchParams({ ...PARAMS, order, sort: item.name }).toString();
|
||||
|
|
|
@ -952,28 +952,11 @@ impl Server {
|
|||
) -> Result<()> {
|
||||
if let Some(sort) = query_params.get("sort") {
|
||||
if sort == "name" {
|
||||
paths.sort_by(|v1, v2| match v1.path_type.cmp(&v2.path_type) {
|
||||
Ordering::Equal => {
|
||||
alphanumeric_sort::compare_str(v1.name.clone(), v2.name.clone())
|
||||
}
|
||||
v => v,
|
||||
})
|
||||
paths.sort_by(|v1, v2| v1.sort_by_name(v2))
|
||||
} else if sort == "mtime" {
|
||||
paths.sort_by(|v1, v2| match v1.path_type.cmp(&v2.path_type) {
|
||||
Ordering::Equal => v1.mtime.cmp(&v2.mtime),
|
||||
v => v,
|
||||
})
|
||||
paths.sort_by(|v1, v2| v1.sort_by_mtime(v2))
|
||||
} else if sort == "size" {
|
||||
paths.sort_by(|v1, v2| match v1.path_type.cmp(&v2.path_type) {
|
||||
Ordering::Equal => {
|
||||
if v1.is_dir() {
|
||||
alphanumeric_sort::compare_str(v1.name.clone(), v2.name.clone())
|
||||
} else {
|
||||
v1.size.unwrap_or(0).cmp(&v2.size.unwrap_or(0))
|
||||
}
|
||||
}
|
||||
v => v,
|
||||
})
|
||||
paths.sort_by(|v1, v2| v1.sort_by_size(v2))
|
||||
}
|
||||
if query_params
|
||||
.get("order")
|
||||
|
@ -983,7 +966,7 @@ impl Server {
|
|||
paths.reverse()
|
||||
}
|
||||
} else {
|
||||
paths.sort_unstable();
|
||||
paths.sort_by(|v1, v2| v1.sort_by_name(v2))
|
||||
}
|
||||
if query_params.contains_key("simple") {
|
||||
let output = paths
|
||||
|
@ -1286,9 +1269,42 @@ impl PathItem {
|
|||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn base_name(&self) -> &str {
|
||||
self.name.split('/').last().unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn sort_by_name(&self, other: &Self) -> Ordering {
|
||||
match self.path_type.cmp(&other.path_type) {
|
||||
Ordering::Equal => {
|
||||
alphanumeric_sort::compare_str(self.name.to_lowercase(), other.name.to_lowercase())
|
||||
}
|
||||
v => v,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sort_by_mtime(&self, other: &Self) -> Ordering {
|
||||
match self.path_type.cmp(&other.path_type) {
|
||||
Ordering::Equal => self.mtime.cmp(&other.mtime),
|
||||
v => v,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sort_by_size(&self, other: &Self) -> Ordering {
|
||||
match self.path_type.cmp(&other.path_type) {
|
||||
Ordering::Equal => {
|
||||
if self.is_dir() {
|
||||
alphanumeric_sort::compare_str(
|
||||
self.name.to_lowercase(),
|
||||
other.name.to_lowercase(),
|
||||
)
|
||||
} else {
|
||||
self.size.unwrap_or(0).cmp(&other.size.unwrap_or(0))
|
||||
}
|
||||
}
|
||||
v => v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Eq, PartialEq)]
|
||||
|
|
Loading…
Reference in a new issue