working breadcrumb
This commit is contained in:
parent
dbba11a416
commit
f9bc5b2e39
|
@ -17,6 +17,7 @@ use crate::gitutils::gitdir::GitDir;
|
||||||
use crate::gitutils::gitfile::GitFile;
|
use crate::gitutils::gitfile::GitFile;
|
||||||
use crate::gitutils::gitrepo::GitRepo;
|
use crate::gitutils::gitrepo::GitRepo;
|
||||||
use crate::ite::SuperIterator;
|
use crate::ite::SuperIterator;
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
name : String,
|
name : String,
|
||||||
|
@ -44,6 +45,7 @@ where for <'a> &'a TS : IntoIterator<Item = &'a Entry>,
|
||||||
{
|
{
|
||||||
repo : Repository,
|
repo : Repository,
|
||||||
browse : TS,
|
browse : TS,
|
||||||
|
root_query : GitWebQ,
|
||||||
breadcrumb: BREADCRUMB,
|
breadcrumb: BREADCRUMB,
|
||||||
user_opt : Option<User>,
|
user_opt : Option<User>,
|
||||||
revisions_nbr : u32,
|
revisions_nbr : u32,
|
||||||
|
@ -53,13 +55,50 @@ where for <'a> &'a TS : IntoIterator<Item = &'a Entry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Clone, Deserialize)]
|
||||||
pub struct GitWebQ {
|
pub struct GitWebQ {
|
||||||
commit: Option<String>,
|
commit: Option<String>,
|
||||||
path: Option<String>,
|
path: Option<String>,
|
||||||
branch: Option<String>,
|
branch: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GitWebQ {
|
||||||
|
fn clone_with_commit(&self, commit : Option<String>) -> GitWebQ {
|
||||||
|
let mut res = self.clone();
|
||||||
|
res.commit = commit;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
fn clone_with_path(&self, path : Option<String>) -> GitWebQ {
|
||||||
|
let mut res = self.clone();
|
||||||
|
res.path = path;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
fn clone_with_branch(&self, branch : Option<String>) -> GitWebQ {
|
||||||
|
let mut res = self.clone();
|
||||||
|
res.branch = branch;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for GitWebQ{
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "?{}{}{}",
|
||||||
|
match &self.commit {
|
||||||
|
None => {"".to_string()}
|
||||||
|
Some(c) => {format!("commit={}", c)}
|
||||||
|
},
|
||||||
|
match &self.path {
|
||||||
|
None => {"".to_string()}
|
||||||
|
Some(p) => {format!("&path={}", p)}
|
||||||
|
},
|
||||||
|
match &self.branch {
|
||||||
|
None => {"".to_string()}
|
||||||
|
Some(b) => {format!("&branch={}", b)}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//#[get("/git/{owner}/{repo}.git")]
|
//#[get("/git/{owner}/{repo}.git")]
|
||||||
pub async fn git_main<T : AuthValidator>(
|
pub async fn git_main<T : AuthValidator>(
|
||||||
web::Path((ownername, reponame)): web::Path<(String, String)>,
|
web::Path((ownername, reponame)): web::Path<(String, String)>,
|
||||||
|
@ -71,32 +110,34 @@ pub async fn git_main<T : AuthValidator>(
|
||||||
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
|
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
|
||||||
// let authtorization = auth.ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
|
// let authtorization = auth.ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
|
||||||
//let authorization = auth.and_then(|cred| validator.check_basic(&cred)).ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
|
//let authorization = auth.and_then(|cred| validator.check_basic(&cred)).ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
|
||||||
let web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) = query;
|
let web::Query(query_struct) = query;
|
||||||
let rootname = match pathopt {
|
// let GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt} = query_struct;
|
||||||
|
let rootname = match &query_struct.path {
|
||||||
None => {"".to_string()}
|
None => {"".to_string()}
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
if s.starts_with("/") {
|
if s.starts_with("/") {
|
||||||
(&s[1..]).to_string()
|
(&s[1..]).to_string()
|
||||||
} else {
|
} else {
|
||||||
s
|
s.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let commit = match commitnameopt {
|
let commit = match &query_struct.commit {
|
||||||
None => {match branchopt {
|
None => {match &query_struct.branch {
|
||||||
None => {GitRef::Head}
|
None => {GitRef::Head}
|
||||||
Some(s) => {GitRef::Branch(s)}
|
Some(s) => {GitRef::Branch(s.clone())}
|
||||||
}}
|
}}
|
||||||
Some(s) => {GitRef::Commit(s)}
|
Some(s) => {GitRef::Commit(s.clone())}
|
||||||
};
|
};
|
||||||
let owner = Owner { name : ownername};
|
let owner = Owner { name : ownername};
|
||||||
let repo = Repository {name : reponame, owner};
|
let repo = Repository {name : reponame, owner};
|
||||||
// let user = User { name : "Hubert".to_string()};
|
// let user = User { name : "Hubert".to_string()};
|
||||||
let user = auth.map(|auth| User{name : auth.user_id().to_string()});
|
let user = auth.map(|auth| User{name : auth.user_id().to_string()});
|
||||||
// il faut ajouter le commit/branch dans la query
|
// il faut ajouter le commit/branch dans la query
|
||||||
let path = rootname.split("/").map_accum("/git/".to_string() + &repo.owner.name + "/" + &repo.name, |direname, b| {
|
let path = rootname.split("/").map_accum(query_struct.clone_with_path(Some("".to_string())), |direname, b| {
|
||||||
let href = b + "/" + direname;
|
let newpath = (&b.path).as_ref().map(|path| {path.clone() + "/" + direname});
|
||||||
((direname.to_string(), href.clone()), href)
|
let newb = b.clone_with_path(newpath);
|
||||||
|
((direname.to_string(), format!("{}", newb)), newb)
|
||||||
}).collect();
|
}).collect();
|
||||||
let gitrepo = GitRepo::new(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name).as_str())?;
|
let gitrepo = GitRepo::new(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name).as_str())?;
|
||||||
let root = gitrepo.get_tree(&commit, Path::new(rootname.as_str()))?;
|
let root = gitrepo.get_tree(&commit, Path::new(rootname.as_str()))?;
|
||||||
|
@ -117,6 +158,7 @@ pub async fn git_main<T : AuthValidator>(
|
||||||
Ok(GitMainTemplate {
|
Ok(GitMainTemplate {
|
||||||
repo,
|
repo,
|
||||||
browse : entries,
|
browse : entries,
|
||||||
|
root_query : query_struct.clone_with_path(None),
|
||||||
breadcrumb: path,
|
breadcrumb: path,
|
||||||
user_opt : user,
|
user_opt : user,
|
||||||
revisions_nbr : gitrepo.get_revisions_nbr(),
|
revisions_nbr : gitrepo.get_revisions_nbr(),
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
<div class="w3-cell-row">
|
<div class="w3-cell-row">
|
||||||
<div class="w3-cell">
|
<div class="w3-cell">
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
<li><a href="#">{{repo.name}}</a></li>
|
<li><a href="{{root_query}}">{{repo.name}}.git</a></li>
|
||||||
{% for (dir, prev) in breadcrumb %}
|
{% for (dir, prev) in breadcrumb %}
|
||||||
<li><a href="{{prev}}">{{dir}}</a></li>
|
<li><a href="{{prev}}">{{dir}}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in New Issue