Skip to content

Commit

Permalink
Merge pull request #21 from BinChengZhao/feature/rich_logs_and_i18n
Browse files Browse the repository at this point in the history
Richer and more responsive data to optimize user experience.
  • Loading branch information
BinChengZhao authored Sep 12, 2021
2 parents 74903e3 + af745aa commit fae1556
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 20 deletions.
12 changes: 7 additions & 5 deletions delicate-scheduler/src/actions/operation_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn show_operation_log(
) -> HttpResponse {
if let Ok(conn) = pool.get() {
return HttpResponse::Ok().json(Into::<
UnifiedResponseMessages<PaginateData<model::OperationLog>>,
UnifiedResponseMessages<PaginateData<model::FrontEndOperationLog>>,
>::into(
web::block::<_, _, diesel::result::Error>(move || {
let query_builder = model::OperationLogQueryBuilder::query_all_columns();
Expand All @@ -30,9 +30,9 @@ async fn show_operation_log(
.query_filter(count_builder)
.get_result::<i64>(&conn)?;

let front_end_operation_log: Vec<model::OperationLog> =
operation_log.into_iter().collect();
Ok(PaginateData::<model::OperationLog>::default()
let front_end_operation_log: Vec<model::FrontEndOperationLog> =
operation_log.into_iter().map(|log| log.into()).collect();
Ok(PaginateData::<model::FrontEndOperationLog>::default()
.set_data_source(front_end_operation_log)
.set_page_size(per_page)
.set_total(count)
Expand All @@ -42,7 +42,9 @@ async fn show_operation_log(
));
}

HttpResponse::Ok().json(UnifiedResponseMessages::<PaginateData<model::OperationLog>>::error())
HttpResponse::Ok().json(UnifiedResponseMessages::<
PaginateData<model::FrontEndOperationLog>,
>::error())
}

#[post("/api/operation_log/detail")]
Expand Down
13 changes: 7 additions & 6 deletions delicate-scheduler/src/actions/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ async fn show_tasks(
.query_filter(count_builder)
.get_result::<i64>(&conn)?;

let mut front_end_task = tasks
.into_iter()
.map(|(_, t)| t)
.collect::<Vec<model::FrontEndTask>>();

front_end_task.sort_by(|a, b| a.id.cmp(&b.id));
Ok(PaginateData::<model::FrontEndTask>::default()
.set_data_source(
tasks
.into_iter()
.map(|(_, t)| t)
.collect::<Vec<model::FrontEndTask>>(),
)
.set_data_source(front_end_task)
.set_page_size(per_page)
.set_total(count)
.set_state_desc::<state::task::State>())
Expand Down
13 changes: 8 additions & 5 deletions delicate-scheduler/src/actions/user_login_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn show_user_login_log(
) -> HttpResponse {
if let Ok(conn) = pool.get() {
return HttpResponse::Ok().json(Into::<
UnifiedResponseMessages<PaginateData<model::UserLoginLog>>,
UnifiedResponseMessages<PaginateData<model::FrontEndUserLoginLog>>,
>::into(
web::block::<_, _, diesel::result::Error>(move || {
let query_builder = model::UserLoginLogQueryBuilder::query_all_columns();
Expand All @@ -29,9 +29,10 @@ async fn show_user_login_log(
.query_filter(count_builder)
.get_result::<i64>(&conn)?;

let front_end_user_login_log: Vec<model::UserLoginLog> =
user_login_log.into_iter().collect();
Ok(PaginateData::<model::UserLoginLog>::default()
let front_end_user_login_log: Vec<model::FrontEndUserLoginLog> =
user_login_log.into_iter().map(|log| log.into()).collect();

Ok(PaginateData::<model::FrontEndUserLoginLog>::default()
.set_data_source(front_end_user_login_log)
.set_page_size(per_page)
.set_total(count)
Expand All @@ -42,5 +43,7 @@ async fn show_user_login_log(
));
}

HttpResponse::Ok().json(UnifiedResponseMessages::<PaginateData<model::UserLoginLog>>::error())
HttpResponse::Ok().json(UnifiedResponseMessages::<
PaginateData<model::FrontEndUserLoginLog>,
>::error())
}
85 changes: 85 additions & 0 deletions delicate-scheduler/src/db/common/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ pub mod task {
NotEnabled = 1,
Enabled = 2,
Deleted = 3,
Unknown = 81,
}

impl From<i16> for State {
fn from(v: i16) -> State {
match v {
1 => State::NotEnabled,
2 => State::Enabled,
3 => State::Deleted,
_ => State::Unknown,
}
}
}
}

Expand Down Expand Up @@ -49,6 +61,17 @@ pub mod user {
pub enum State {
Health = 1,
Forbidden = 2,
Unknown = 81,
}

impl From<i16> for State {
fn from(v: i16) -> State {
match v {
1 => State::Health,
2 => State::Forbidden,
_ => State::Unknown,
}
}
}
}

Expand All @@ -60,6 +83,17 @@ pub mod user_auth {
pub enum State {
Health = 1,
Forbidden = 2,
Unknown = 81,
}

impl From<i16> for State {
fn from(v: i16) -> State {
match v {
1 => State::Health,
2 => State::Forbidden,
_ => State::Unknown,
}
}
}
}

Expand All @@ -72,6 +106,18 @@ pub mod executor_processor {
NotEnabled = 1,
Enabled = 2,
Abnormal = 3,
Unknown = 81,
}

impl From<i16> for State {
fn from(v: i16) -> State {
match v {
1 => State::NotEnabled,
2 => State::Enabled,
3 => State::Abnormal,
_ => State::Unknown,
}
}
}
}

Expand All @@ -83,6 +129,17 @@ pub mod executor_group {
pub enum State {
Health = 1,
Forbidden = 2,
Unknown = 81,
}

impl From<i16> for State {
fn from(v: i16) -> State {
match v {
1 => State::Health,
2 => State::Forbidden,
_ => State::Unknown,
}
}
}
}

Expand Down Expand Up @@ -122,6 +179,21 @@ pub mod user_login_log {
Ldap = 4,
OtherOAuth = 5,
Logout = 81,
Unknown = 88,
}

impl From<i16> for LoginType {
fn from(v: i16) -> LoginType {
match v {
1 => LoginType::Mobile,
2 => LoginType::Email,
3 => LoginType::UserName,
4 => LoginType::Ldap,
5 => LoginType::OtherOAuth,
81 => LoginType::Logout,
_ => LoginType::Unknown,
}
}
}

#[allow(dead_code)]
Expand All @@ -131,6 +203,19 @@ pub mod user_login_log {
LogoutSuccess = 2,
Loginfailure = 3,
Logoutfailure = 4,
Unknown = 81,
}

impl From<i16> for LoginCommand {
fn from(v: i16) -> LoginCommand {
match v {
1 => LoginCommand::LoginSuccess,
2 => LoginCommand::LogoutSuccess,
3 => LoginCommand::Loginfailure,
4 => LoginCommand::Logoutfailure,
_ => LoginCommand::Unknown,
}
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions delicate-scheduler/src/db/mysql/model/operation_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ pub struct OperationLog {
operation_time: NaiveDateTime,
}

#[derive(Debug, Clone, Serialize)]
pub struct FrontEndOperationLog {
id: u64,
name: String,
table_id: u64,
operation_type: i8,
operation_type_desc: &'static str,
user_id: u64,
user_name: String,
operation_time: NaiveDateTime,
}

impl From<OperationLog> for FrontEndOperationLog{
fn from(log: OperationLog) -> Self {
let OperationLog{id, name,table_id, operation_type, user_id, user_name, operation_time} = log;
let operation_type_desc = Into::<state::operation_log::OperationType>::into(operation_type as i16).into();

Self {
id, name,table_id, operation_type, operation_type_desc, user_id, user_name, operation_time
}
}
}

#[derive(Queryable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize)]
#[table_name = "operation_log_detail"]

Expand Down
5 changes: 4 additions & 1 deletion delicate-scheduler/src/db/mysql/model/task_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub struct TaskLog {
}

// The front-end int64 is not convenient to be compatible, and the server side helps to handle it.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize)]
pub struct FrontEndTaskLog {
id: FrontEndRecordId,
task_id: i64,
Expand All @@ -139,6 +139,7 @@ pub struct FrontEndTaskLog {
maximum_parallel_runnable_num: i16,
tag: String,
status: i16,
status_desc: &'static str,
created_time: NaiveDateTime,
updated_time: NaiveDateTime,
executor_processor_id: i64,
Expand Down Expand Up @@ -168,6 +169,7 @@ impl From<TaskLog> for FrontEndTaskLog {
} = log;

let id = FrontEndRecordId(id);
let status_desc = Into::<state::task_log::State>::into(status as i16).into();

FrontEndTaskLog {
id,
Expand All @@ -180,6 +182,7 @@ impl From<TaskLog> for FrontEndTaskLog {
maximum_parallel_runnable_num,
tag,
status,
status_desc,
created_time,
updated_time,
executor_processor_id,
Expand Down
34 changes: 34 additions & 0 deletions delicate-scheduler/src/db/mysql/model/user_login_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,43 @@ pub struct UserLoginLog {
lastip: String,
created_time: NaiveDateTime,
user_name: String,
}

#[derive(Debug, Clone, Serialize)]

pub struct FrontEndUserLoginLog {
id: i64,
user_id: u64,
login_type: u8,
login_type_desc: &'static str,
command: u8,
command_desc: &'static str,
lastip: String,
created_time: NaiveDateTime,
user_name: String,
}

impl From<UserLoginLog> for FrontEndUserLoginLog{
fn from(log: UserLoginLog) -> Self {
let UserLoginLog{id, user_id, login_type, command, lastip, created_time, user_name} = log;
let login_type_desc = Into::<state::user_login_log::LoginType>::into(login_type as i16).into();
let command_desc = Into::<state::user_login_log::LoginCommand>::into(command as i16).into();

FrontEndUserLoginLog {
id,
user_id,
login_type,
login_type_desc,
command,
command_desc,
lastip,
created_time,
user_name,
}
}
}


#[derive(Insertable, Debug, Default, Serialize, Deserialize)]
#[table_name = "user_login_log"]
pub struct NewUserLoginLog {
Expand Down
4 changes: 2 additions & 2 deletions delicate-web/src/pages/inLogs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class loginLogs extends PureComponent {
},
{
title: t`Login Type`,
dataIndex: 'login_type'
dataIndex: 'login_type_desc'
},
{
title: t`Login Status`,
dataIndex: 'command'
dataIndex: 'command_desc'
},
{
title: t`Last Ip`,
Expand Down
2 changes: 1 addition & 1 deletion delicate-web/src/pages/operateLogs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class operateLogs extends PureComponent {
},
{
title: t`Operate Type`,
dataIndex: 'operation_type'
dataIndex: 'operation_type_desc'
},
{
title: t`Table Id`,
Expand Down

0 comments on commit fae1556

Please sign in to comment.