forked from Ruderverein-Donau-Linz/rowt
		
	allow sorting of user
This commit is contained in:
		@@ -591,18 +591,27 @@ WHERE lower(name)=?
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn all(db: &SqlitePool) -> Vec<Self> {
 | 
			
		||||
        sqlx::query_as!(
 | 
			
		||||
            Self,
 | 
			
		||||
            "
 | 
			
		||||
SELECT id, name, pw, deleted, last_access, dob, weight, sex, member_since_date, birthdate, mail, nickname, notes, phone, address, family_id, user_token
 | 
			
		||||
FROM user
 | 
			
		||||
WHERE deleted = 0
 | 
			
		||||
ORDER BY last_access DESC
 | 
			
		||||
        Self::all_with_order(db, "last_access", true).await
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn all_with_order(db: &SqlitePool, sort: &str, asc: bool) -> Vec<Self> {
 | 
			
		||||
        let mut query = format!(
 | 
			
		||||
        "
 | 
			
		||||
        )
 | 
			
		||||
        .fetch_all(db)
 | 
			
		||||
        .await
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        SELECT id, name, pw, deleted, last_access, dob, weight, sex, member_since_date, birthdate, mail, nickname, notes, phone, address, family_id, user_token
 | 
			
		||||
        FROM user
 | 
			
		||||
        WHERE deleted = 0
 | 
			
		||||
        ORDER BY {}
 | 
			
		||||
        ",
 | 
			
		||||
        sort
 | 
			
		||||
    );
 | 
			
		||||
        if !asc {
 | 
			
		||||
            query.push_str(" DESC");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        sqlx::query_as::<_, User>(&query)
 | 
			
		||||
            .fetch_all(db)
 | 
			
		||||
            .await
 | 
			
		||||
            .unwrap()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn all_with_role(db: &SqlitePool, role: &Role) -> Vec<Self> {
 | 
			
		||||
 
 | 
			
		||||
@@ -43,13 +43,17 @@ impl<'r> FromRequest<'r> for Referer {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[get("/user")]
 | 
			
		||||
#[get("/user?<sort>&<asc>")]
 | 
			
		||||
async fn index(
 | 
			
		||||
    db: &State<SqlitePool>,
 | 
			
		||||
    user: VorstandUser,
 | 
			
		||||
    flash: Option<FlashMessage<'_>>,
 | 
			
		||||
    sort: Option<String>,
 | 
			
		||||
    asc: bool,
 | 
			
		||||
) -> Template {
 | 
			
		||||
    let user_futures: Vec<_> = User::all(db)
 | 
			
		||||
    let sort_column = sort.unwrap_or_else(|| "last_access".to_string());
 | 
			
		||||
 | 
			
		||||
    let user_futures: Vec<_> = User::all_with_order(db, &sort_column, asc)
 | 
			
		||||
        .await
 | 
			
		||||
        .into_iter()
 | 
			
		||||
        .map(|u| async move { UserWithRolesAndMembershipPdf::from_user(db, u).await })
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user