From 004560ca3d14deada42ef4a77323422e4c9c0327 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Sun, 5 Mar 2023 13:47:52 +0200 Subject: [PATCH] reformat code --- rustfmt.toml | 1 + src/app.rs | 43 +++-- src/components/generator_picker.rs | 161 ++++++++++------- src/components/mod.rs | 2 +- src/components/sql_column_info.rs | 79 ++++---- src/generate_sql.rs | 219 ++++++++++++----------- src/magicdraw_parser/ddl_parser.rs | 82 ++++++--- src/magicdraw_parser/mod.rs | 148 +++++++++------ src/magicdraw_parser/sql_types_parser.rs | 100 ++++++++--- src/magicdraw_parser/uml_model_parser.rs | 199 ++++++++++++-------- src/magicdraw_parser/utils.rs | 99 ++++++---- src/main.rs | 2 +- 12 files changed, 686 insertions(+), 449 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..218e203 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +hard_tabs = true diff --git a/src/app.rs b/src/app.rs index 082140a..031236b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,18 +1,18 @@ -use std::cell::RefCell; -use std::io::Cursor; -use std::collections::{HashMap, self}; -use std::rc::Rc; -use gloo::console::{console_dbg, console}; +use gloo::console::{console, console_dbg}; use gloo::file::callbacks::FileReader; use gloo::file::File; use gloo::storage::{LocalStorage, Storage}; +use std::cell::RefCell; +use std::collections::{self, HashMap}; +use std::io::Cursor; +use std::rc::Rc; use web_sys::{DragEvent, Event, FileList, HtmlInputElement, MouseEvent}; use yew::html::TargetCast; use yew::{html, Callback, Component, Context, Html}; -use crate::generate_sql::{SQLValueGuess, generate_table_guessess, generate_fake_entries}; -use crate::magicdraw_parser::{parse_project, SQLTableCollection, SQLTable}; use crate::components::sql_column_info::SQLTableColumnInfo; +use crate::generate_sql::{generate_fake_entries, generate_table_guessess, SQLValueGuess}; +use crate::magicdraw_parser::{parse_project, SQLTable, SQLTableCollection}; const COLLECTION_STORE_KEY: &str = "current_collection"; const DEFAULT_ROWS_PER_TABLE: u32 = 20; @@ -37,7 +37,7 @@ pub struct App { currently_shown_table: usize, all_good_confirmed: bool, generated_sql: Option, - rows_per_table: u32 + rows_per_table: u32, } impl Component for App { @@ -63,7 +63,7 @@ impl Component for App { all_good_confirmed: true, // TODO: make this false, by default generated_sql: None, current_guessess, - rows_per_table: DEFAULT_ROWS_PER_TABLE + rows_per_table: DEFAULT_ROWS_PER_TABLE, } } @@ -93,16 +93,13 @@ impl Component for App { gloo::file::callbacks::read_as_bytes(&file, move |res| { // TODO: show error message - link.send_message(Msg::Loaded( - file_name, - res.expect("failed to read file"), - )) + link.send_message(Msg::Loaded(file_name, res.expect("failed to read file"))) }) }; self.active_readers.insert(file_name, task); true - }, + } Msg::Noop => false, Msg::UpdateCurrentProject(collection) => { if let Some(collection) = collection { @@ -115,38 +112,40 @@ impl Component for App { let guess = generate_table_guessess(table); self.current_guessess.push(Rc::new(RefCell::new(guess))); } - self.current_collection = Some(collection.tables.into_iter().map(Rc::new).collect()); + self.current_collection = + Some(collection.tables.into_iter().map(Rc::new).collect()); } else { LocalStorage::delete(COLLECTION_STORE_KEY); self.current_collection = None } true - }, + } Msg::ShowNextTable => { if let Some(collection) = &self.current_collection { - self.currently_shown_table = (self.currently_shown_table + 1).min(collection.len()-1); + self.currently_shown_table = + (self.currently_shown_table + 1).min(collection.len() - 1); return true; } false - }, + } Msg::ShowPrevTable => { if self.currently_shown_table > 0 { self.currently_shown_table = self.currently_shown_table - 1; return true; } false - }, + } Msg::AllGoodConfirmation => { self.all_good_confirmed = true; true - }, + } Msg::UpdateGenarator(column, generator) => { let mut guessess = self.current_guessess[self.currently_shown_table].borrow_mut(); let entry = guessess.get_mut(&column).unwrap(); *entry = generator; true - }, + } Msg::GenerateSQL => { let tables = self.current_collection.as_ref().unwrap(); let guessess = self.current_guessess.iter().map(|v| v.borrow()).collect(); @@ -157,7 +156,7 @@ impl Component for App { self.generated_sql = None } true - }, + } Msg::UpdateRowsPerTable(rows_per_table) => { self.rows_per_table = rows_per_table; false diff --git a/src/components/generator_picker.rs b/src/components/generator_picker.rs index 1e64f7f..0a2340d 100644 --- a/src/components/generator_picker.rs +++ b/src/components/generator_picker.rs @@ -1,16 +1,17 @@ use std::{collections::HashMap, str::FromStr}; -use yew::{Html, html, Callback, TargetCast, AttrValue}; use web_sys::{Event, HtmlInputElement}; +use yew::{html, AttrValue, Callback, Html, TargetCast}; -use crate::{generate_sql::{SQLValueGuess, SQLStringValueGuess, SQLBoolValueGuess, SQLTimeValueGuess, SQLIntValueGuess}, magicdraw_parser::{SQLColumn, SQLCheckConstraint}}; +use crate::{ + generate_sql::{ + SQLBoolValueGuess, SQLIntValueGuess, SQLStringValueGuess, SQLTimeValueGuess, SQLValueGuess, + }, + magicdraw_parser::{SQLCheckConstraint, SQLColumn}, +}; -fn show_dropdown_picker( - selected: &str, - options: &[AttrValue], - onchange: Callback -) -> Html { - html!{ +fn show_dropdown_picker(selected: &str, options: &[AttrValue], onchange: Callback) -> Html { + html! {