Skip to content

Commit

Permalink
little code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanueltouzery committed Dec 23, 2020
1 parent 376b04b commit d591192
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 71 deletions.
5 changes: 2 additions & 3 deletions projectpad/src/widgets/server_poi_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,8 @@ impl Widget for ServerPoiContents {
}
Msg::ServerLinkSelected(srv_l) => {
self.model.cur_server_id = Some(srv_l.linked_server_id);
self.model.scroll_to_item_request = srv_l
.linked_group_name
.map(|gn| ScrollTarget::GroupName(gn));
self.model.scroll_to_item_request =
srv_l.linked_group_name.map(ScrollTarget::GroupName);
self.fetch_items();
}
Msg::GotItems(items) => {
Expand Down
135 changes: 67 additions & 68 deletions projectpad/src/widgets/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,76 +405,10 @@ impl Widget for Win {
.emit(SearchViewMsg::FilterChanged(Some(search_text)));
}
Msg::DisplayItem(di) => {
let (project, project_item, server_item) = *di;
self.project_list
.emit(ProjectListMsg::ProjectSelectedFromElsewhere(project.id));
let env = match &project_item {
Some(ProjectItem::Server(s)) => Some(s.environment),
Some(ProjectItem::ServerLink(s)) => Some(s.environment),
Some(ProjectItem::ProjectNote(n)) if n.has_prod => {
Some(EnvironmentType::EnvProd)
}
Some(ProjectItem::ProjectNote(n)) if n.has_uat => Some(EnvironmentType::EnvUat),
Some(ProjectItem::ProjectNote(n)) if n.has_stage => {
Some(EnvironmentType::EnvStage)
}
Some(ProjectItem::ProjectNote(n)) if n.has_dev => {
Some(EnvironmentType::EnvDevelopment)
}
_ => None,
};
if let Some(e) = env {
self.project_summary.emit(
ProjectSummaryMsg::ProjectEnvironmentSelectedFromElsewhere((
project.clone(),
e,
)),
);
} else {
self.project_summary
.emit(ProjectSummaryMsg::ProjectActivated(project.clone()));
}
self.project_items_list.emit(
ProjectItemsListMsg::ProjectItemSelectedFromElsewhere((
project,
env,
project_item,
)),
);
if let Some(sitem) = server_item {
self.project_poi_contents
.stream()
.emit(ProjectPoiContentsMsg::ScrollToServerItem(sitem));
}
self.model
.relm
.stream()
.emit(Msg::SearchActiveChanged(false));
self.model
.titlebar
.stream()
.emit(WinTitleBarMsg::SearchActiveChanged(false));
self.display_item(di);
}
Msg::RequestDisplayItem(server_item) => {
let s = self.model.display_item_sender.clone();
self.model
.db_sender
.send(SqlFunc::new(move |sql_conn| {
use projectpadsql::schema::project::dsl as prj;
use projectpadsql::schema::server::dsl as srv;
let (server, project) = srv::server
.inner_join(prj::project)
.filter(srv::id.eq(server_item.server_id()))
.first::<(Server, Project)>(sql_conn)
.unwrap();
s.send((
project,
Some(ProjectItem::Server(server)),
Some(server_item.clone()),
))
.unwrap();
}))
.unwrap();
self.request_display_item(server_item);
}
Msg::KeyPress(e) => {
self.handle_keypress(e);
Expand Down Expand Up @@ -568,6 +502,71 @@ impl Widget for Win {
}
}

fn request_display_item(&self, server_item: ServerItem) {
let s = self.model.display_item_sender.clone();
self.model
.db_sender
.send(SqlFunc::new(move |sql_conn| {
use projectpadsql::schema::project::dsl as prj;
use projectpadsql::schema::server::dsl as srv;
let (server, project) = srv::server
.inner_join(prj::project)
.filter(srv::id.eq(server_item.server_id()))
.first::<(Server, Project)>(sql_conn)
.unwrap();
s.send((
project,
Some(ProjectItem::Server(server)),
Some(server_item.clone()),
))
.unwrap();
}))
.unwrap();
}

fn display_item(&self, di: Box<DisplayItemParams>) {
let (project, project_item, server_item) = *di;
self.project_list
.emit(ProjectListMsg::ProjectSelectedFromElsewhere(project.id));
let env = match &project_item {
Some(ProjectItem::Server(s)) => Some(s.environment),
Some(ProjectItem::ServerLink(s)) => Some(s.environment),
Some(ProjectItem::ProjectNote(n)) if n.has_prod => Some(EnvironmentType::EnvProd),
Some(ProjectItem::ProjectNote(n)) if n.has_uat => Some(EnvironmentType::EnvUat),
Some(ProjectItem::ProjectNote(n)) if n.has_stage => Some(EnvironmentType::EnvStage),
Some(ProjectItem::ProjectNote(n)) if n.has_dev => Some(EnvironmentType::EnvDevelopment),
_ => None,
};
if let Some(e) = env {
self.project_summary
.emit(ProjectSummaryMsg::ProjectEnvironmentSelectedFromElsewhere(
(project.clone(), e),
));
} else {
self.project_summary
.emit(ProjectSummaryMsg::ProjectActivated(project.clone()));
}
self.project_items_list
.emit(ProjectItemsListMsg::ProjectItemSelectedFromElsewhere((
project,
env,
project_item,
)));
if let Some(sitem) = server_item {
self.project_poi_contents
.stream()
.emit(ProjectPoiContentsMsg::ScrollToServerItem(sitem));
}
self.model
.relm
.stream()
.emit(Msg::SearchActiveChanged(false));
self.model
.titlebar
.stream()
.emit(WinTitleBarMsg::SearchActiveChanged(false));
}

fn load_style(&self) -> Result<(), Box<dyn std::error::Error>> {
let screen = self.window.get_screen().unwrap();
let css = gtk::CssProvider::new();
Expand Down

0 comments on commit d591192

Please sign in to comment.