-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
383 additions
and
147 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
rust/perspective-viewer/src/rust/components/copy_dropdown.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (c) 2018, the Perspective Authors. | ||
// | ||
// This file is part of the Perspective library, distributed under the terms | ||
// of the Apache License 2.0. The full license can be found in the LICENSE | ||
// file. | ||
|
||
use super::containers::dropdown_menu::*; | ||
use crate::model::*; | ||
|
||
pub fn get_menu_items(has_render: bool) -> Vec<CopyDropDownMenuItem> { | ||
vec![ | ||
CopyDropDownMenuItem::OptGroup( | ||
"Current View", | ||
if has_render { | ||
vec![ExportMethod::Csv, ExportMethod::Json, ExportMethod::Png] | ||
} else { | ||
vec![ExportMethod::Csv, ExportMethod::Json] | ||
}, | ||
), | ||
CopyDropDownMenuItem::OptGroup( | ||
"All", | ||
vec![ExportMethod::CsvAll, ExportMethod::JsonAll], | ||
), | ||
CopyDropDownMenuItem::OptGroup("Config", vec![ExportMethod::JsonConfig]), | ||
] | ||
} | ||
|
||
pub type CopyDropDownMenu = DropDownMenu<ExportMethod>; | ||
pub type CopyDropDownMenuProps = DropDownMenuProps<ExportMethod>; | ||
pub type CopyDropDownMenuMsg = DropDownMenuMsg; | ||
pub type CopyDropDownMenuItem = DropDownMenuItem<ExportMethod>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
rust/perspective-viewer/src/rust/custom_elements/copy_dropdown.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (c) 2018, the Perspective Authors. | ||
// | ||
// This file is part of the Perspective library, distributed under the terms | ||
// of the Apache License 2.0. The full license can be found in the LICENSE | ||
// file. | ||
|
||
use crate::components::copy_dropdown::*; | ||
use crate::custom_elements::modal::*; | ||
use crate::model::*; | ||
use crate::renderer::Renderer; | ||
use crate::session::Session; | ||
use crate::utils::*; | ||
|
||
use js_intern::*; | ||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
use wasm_bindgen::prelude::*; | ||
use wasm_bindgen::JsCast; | ||
use wasm_bindgen_futures::spawn_local; | ||
use web_sys::*; | ||
use yew::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
#[derive(Clone)] | ||
pub struct CopyDropDownMenuElement { | ||
modal: ModalElement<CopyDropDownMenu>, | ||
target: Rc<RefCell<Option<HtmlElement>>>, | ||
} | ||
|
||
impl ResizableMessage for <CopyDropDownMenu as Component>::Message { | ||
fn resize(y: i32, x: i32, _: bool) -> Self { | ||
CopyDropDownMenuMsg::SetPos(y, x) | ||
} | ||
} | ||
|
||
impl CopyDropDownMenuElement { | ||
pub fn new(session: Session, renderer: Renderer) -> CopyDropDownMenuElement { | ||
let document = window().unwrap().document().unwrap(); | ||
let dropdown = document | ||
.create_element("perspective-copy-dropdown") | ||
.unwrap() | ||
.unchecked_into::<HtmlElement>(); | ||
|
||
let modal_rc: Rc<RefCell<Option<ModalElement<CopyDropDownMenu>>>> = | ||
Default::default(); | ||
|
||
let callback = Callback::from({ | ||
let modal_rc = modal_rc.clone(); | ||
let renderer = renderer.clone(); | ||
move |x: ExportMethod| { | ||
let js_task = (&session, &renderer).export_method_to_jsvalue(x); | ||
let copy_task = copy_to_clipboard(js_task, x.mimetype()); | ||
let modal = modal_rc.borrow().clone().unwrap(); | ||
spawn_local(async move { | ||
let result = copy_task.await; | ||
crate::js_log_maybe! { | ||
result?; | ||
modal.hide()?; | ||
} | ||
}) | ||
} | ||
}); | ||
|
||
let plugin = renderer.get_active_plugin().unwrap(); | ||
let has_render = js_sys::Reflect::has(&plugin, js_intern!("render")).unwrap(); | ||
let values = Rc::new(get_menu_items(has_render)); | ||
let props = CopyDropDownMenuProps { values, callback }; | ||
let modal = ModalElement::new(dropdown, props, true); | ||
*modal_rc.borrow_mut() = Some(modal.clone()); | ||
CopyDropDownMenuElement { | ||
modal, | ||
target: Default::default(), | ||
} | ||
} | ||
|
||
pub fn open(&self, target: HtmlElement) { | ||
self.modal.open(target, None); | ||
} | ||
|
||
pub fn hide(&self) -> Result<(), JsValue> { | ||
self.modal.hide() | ||
} | ||
|
||
pub fn connected_callback(&self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (c) 2018, the Perspective Authors. | ||
// | ||
// This file is part of the Perspective library, distributed under the terms | ||
// of the Apache License 2.0. The full license can be found in the LICENSE | ||
// file. | ||
|
||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(inline_js = "export const ClipboardItem = window.ClipboardItem")] | ||
extern "C" { | ||
pub type ClipboardItem; | ||
|
||
#[wasm_bindgen(constructor, js_class = "ClipboardItem")] | ||
pub fn new(files: &js_sys::Object) -> ClipboardItem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.