Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/access-tab-processes
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Dec 5, 2024
2 parents 04bcdff + 08a20c5 commit 65668f5
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 105 deletions.
8 changes: 4 additions & 4 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn routes() -> Router {
)
.push(
// /api/dictionary
Router::with_path("dictionary")
Router::with_path("dictionary")
.push(
// /api/dictionary/browsers/
Router::with_path("browsers")
Expand All @@ -115,8 +115,8 @@ fn routes() -> Router {
)
)
.push(
// /api/dictionary/processes
Router::with_path("processes")
// /api/dictionary/processes
Router::with_path("processes")
.options(options_response)
.get(get_processes)
.push(
Expand Down Expand Up @@ -367,7 +367,7 @@ async fn get_windows<'a>(_req: &mut Request, _res: &mut Response) {
}
}
} else {
match windows(_language, _search_value, _dictionary_code).await {
match windows(_language, _search_value, _dictionary_code, _client_id, _role_id).await {
Ok(windows_list) => {
_res.render(Json(windows_list));
},
Expand Down
36 changes: 20 additions & 16 deletions src/models/browser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use salvo::prelude::*;
use serde_json::json;
use serde_json::{json, Value};
use std::{io::ErrorKind, io::Error};

use crate::{controller::opensearch::{find, get_by_id, IndexDocument}, models::get_index_name};
Expand Down Expand Up @@ -291,6 +291,18 @@ pub struct DependendField {
pub parent_name: Option<String>
}


pub fn parse_browser(value: Value) -> Browser {
let mut browser: Browser = serde_json::from_value(value).unwrap();

// sort fields by sequence
if let Some(ref mut fields) = browser.fields {
fields.sort_by_key(|field| field.sequence.clone().unwrap_or(0));
}
browser.to_owned()
}


pub async fn browser_from_id(_id: Option<String>, _language: Option<&String>, _dictionary_code: Option<&String>) -> Result<Browser, String> {
if _id.is_none() || _id.as_deref().map_or(false, |s| s.trim().is_empty()) {
return Err(
Expand All @@ -312,17 +324,12 @@ pub async fn browser_from_id(_id: Option<String>, _language: Option<&String>, _d
let _browser_document: &dyn IndexDocument = &_document;
match get_by_id(_browser_document).await {
Ok(value) => {
let mut browser: Browser = serde_json::from_value(value).unwrap();
log::info!("Finded Value: {:?}", browser.id);
let browser: Browser = parse_browser(value);
log::info!("Finded Browser {:?}: {:?}", browser.name, browser.id);

// sort fields by sequence
if let Some(ref mut fields) = browser.fields {
fields.sort_by_key(|field| field.sequence.clone().unwrap_or(0));
}

Ok(
browser
)
Ok(
browser
)
},
Err(error) => {
log::error!("{}", error);
Expand Down Expand Up @@ -354,11 +361,8 @@ pub async fn browsers(_language: Option<&String>, _search_value: Option<&String>
Ok(values) => {
let mut browsers_list: Vec<Browser> = vec![];
for value in values {
let mut browser: Browser = serde_json::from_value(value).unwrap();
// sort fields by sequence
if let Some(ref mut fields) = browser.fields {
fields.sort_by_key(|field| field.sequence.clone().unwrap_or(0));
}
let browser: Browser = parse_browser(value);

browsers_list.push(browser.to_owned());
}
Ok(BrowserListResponse {
Expand Down
14 changes: 10 additions & 4 deletions src/models/form.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use salvo::prelude::*;
use serde_json::json;
use serde_json::{json, Value};
use std::{io::ErrorKind, io::Error};

use crate::{controller::opensearch::{find, get_by_id, IndexDocument}, models::get_index_name};
Expand Down Expand Up @@ -132,6 +132,12 @@ impl IndexDocument for Form {
}
}


pub fn parse_form(value: Value) -> Form {
let form: Form = serde_json::from_value(value).unwrap();
form.to_owned()
}

pub async fn form_from_id(_id: Option<String>, _language: Option<&String>, _dictionary_code: Option<&String>) -> Result<Form, String> {
if _id.is_none() || _id.as_deref().map_or(false, |s| s.trim().is_empty()) {
return Err(
Expand All @@ -153,8 +159,8 @@ pub async fn form_from_id(_id: Option<String>, _language: Option<&String>, _dict
let _form_document: &dyn IndexDocument = &_document;
match get_by_id(_form_document).await {
Ok(value) => {
let form: Form = serde_json::from_value(value).unwrap();
log::info!("Finded Form Value: {:?}", form.id);
let form: Form = parse_form(value);
log::info!("Finded Form {:?} Value: {:?}", form.name, form.id);
// Ok(FormResponse {
// form: Some(form)
// })
Expand Down Expand Up @@ -192,7 +198,7 @@ pub async fn forms(_language: Option<&String>, _search_value: Option<&String>, _
Ok(values) => {
let mut forms_list: Vec<Form> = vec![];
for value in values {
let form: Form = serde_json::from_value(value).unwrap();
let form: Form = parse_form(value);
forms_list.push(form.to_owned());
}
Ok(FormsListResponse {
Expand Down
4 changes: 3 additions & 1 deletion src/models/menu_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct MenuTree {
pub uuid: Option<String>,
pub id: Option<String>,
pub internal_id: Option<i32>,
pub name: Option<String>,
pub node_id: Option<i32>,
pub parent_id: Option<i32>,
pub sequence: Option<i32>,
Expand All @@ -53,6 +54,7 @@ impl Default for MenuTree {
uuid: None,
id: None,
internal_id: None,
name: None,
node_id: None,
parent_id: None,
sequence: None,
Expand Down Expand Up @@ -153,7 +155,7 @@ pub async fn menu_tree_from_id(_id: Option<String>, _dictionary_code: Option<&St
log::info!("Finded Menu Tree Value: {:?}", menu.id);
// sort menu children nodes by sequence
if let Some(ref mut children) = menu.children {
children.sort_by_key(|child| child.sequence.clone().unwrap_or(0));
children.sort_by_key(|child: &MenuTree| child.sequence.clone().unwrap_or(0));
}
Ok(menu)
},
Expand Down
30 changes: 17 additions & 13 deletions src/models/process.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use salvo::prelude::*;
use serde_json::json;
use serde_json::{json, Value};
use std::{io::ErrorKind, io::Error};

use crate::{controller::opensearch::{find, get_by_id, IndexDocument}, models::get_index_name};
Expand Down Expand Up @@ -270,6 +270,18 @@ pub struct Workflow {
pub help: Option<String>,
}


pub fn parse_process(value: Value) -> Process {
let mut process: Process = serde_json::from_value(value).unwrap();

// sort process parameter list by sequence
if let Some(ref mut parameters) = process.parameters {
parameters.sort_by_key(|parameter: &ProcessParameters| parameter.sequence.clone().unwrap_or(0));
}
process.to_owned()
}


pub async fn process_from_id(_id: Option<String>, _language: Option<&String>, _dictionary_code: Option<&String>) -> Result<Process, String> {
if _id.is_none() || _id.as_deref().map_or(false, |s| s.trim().is_empty()) {
return Err(
Expand All @@ -291,13 +303,8 @@ pub async fn process_from_id(_id: Option<String>, _language: Option<&String>, _d
let _process_document: &dyn IndexDocument = &_document;
match get_by_id(_process_document).await {
Ok(value) => {
let mut process: Process = serde_json::from_value(value).unwrap();
log::info!("Finded Process Value: {:?}", process.id);

// sort process parameter by sequence
if let Some(ref mut parameters) = process.parameters {
parameters.sort_by_key(|parameter| parameter.sequence.clone().unwrap_or(0));
}
let process: Process = parse_process(value);
log::info!("Finded Process {:?} Value: {:?}", process.name, process.id);

Ok(
process
Expand Down Expand Up @@ -333,11 +340,8 @@ pub async fn processes(_language: Option<&String>, _search_value: Option<&String
Ok(values) => {
let mut processes_list: Vec<Process> = vec![];
for value in values {
let mut process: Process = serde_json::from_value(value).unwrap();
// sort process parameter by sequence
if let Some(ref mut parameters) = process.parameters {
parameters.sort_by_key(|parameter| parameter.sequence.clone().unwrap_or(0));
}
let process: Process = parse_process(value);

processes_list.push(process.to_owned());
}

Expand Down
Loading

0 comments on commit 65668f5

Please sign in to comment.