Skip to content

Commit

Permalink
Tauri feature parity + fix blurry editor in WebView + Offline monaco
Browse files Browse the repository at this point in the history
  • Loading branch information
aarkue committed Aug 18, 2024
1 parent d9bfbe1 commit f07fd4b
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 64 deletions.
52 changes: 51 additions & 1 deletion backend/shared/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use process_mining::{ocel::ocel_struct::OCELType, OCEL};
use preprocessing::linked_ocel::IndexLinkedOCEL;
use process_mining::{
ocel::ocel_struct::{OCELEvent, OCELObject, OCELType},
OCEL,
};
use serde::{Deserialize, Serialize};

pub mod ocel_qualifiers {
Expand Down Expand Up @@ -37,3 +41,49 @@ impl From<&OCEL> for OCELInfo {
}
}
}

#[derive(Debug, Serialize, Deserialize)]
pub enum IndexOrID {
#[serde(rename = "id")]
ID(String),
#[serde(rename = "index")]
Index(usize),
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ObjectWithIndex {
pub object: OCELObject,
pub index: usize,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EventWithIndex {
pub event: OCELEvent,
pub index: usize,
}

pub fn get_event_info(ocel: &IndexLinkedOCEL, req: IndexOrID) -> Option<EventWithIndex> {
let ev_with_index = match req {
IndexOrID::ID(id) => ocel
.ev_by_id(&id)
.cloned()
.and_then(|ev| ocel.index_of_ev(&id).map(|ev_index| (ev, ev_index.0))),
IndexOrID::Index(index) => ocel.ocel.events.get(index).cloned().map(|ev| (ev, index)),
};
ev_with_index.map(|(event, index)| EventWithIndex { event, index })
}



pub fn get_object_info(ocel: &IndexLinkedOCEL, req: IndexOrID) -> Option<ObjectWithIndex> {
let ob_with_index = match req {
IndexOrID::ID(id) => ocel
.ob_by_id(&id)
.cloned()
.and_then(|ob| ocel.index_of_ob(&id).map(|ob_index| (ob, ob_index.0))),
IndexOrID::Index(index) => ocel.ocel.objects.get(index).cloned().map(|ev| (ev, index)),
};
ob_with_index.map(|(object, index)| ObjectWithIndex { object, index })
}
2 changes: 0 additions & 2 deletions backend/shared/src/preprocessing/linked_ocel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ pub fn link_ocel_info(ocel: OCEL) -> IndexLinkedOCEL {
}
}
}
println!("{:?}", types_rel_counts);
let avg_rels_of_type_per_type = types_rel_counts
.into_iter()
.map(|(t, count)| {
Expand All @@ -429,7 +428,6 @@ pub fn link_ocel_info(ocel: OCEL) -> IndexLinkedOCEL {
(t, count as f32 / n as f32)
})
.collect();
println!("{:?}", avg_rels_of_type_per_type);
println!("Linking OCEL took {:?}", now.elapsed());
IndexLinkedOCEL {
events_of_type,
Expand Down
68 changes: 17 additions & 51 deletions backend/web-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{
Json, Router,
};
use itertools::Itertools;
use serde::{Deserialize, Serialize};


use std::{
collections::{HashMap, HashSet},
Expand All @@ -20,12 +20,13 @@ use ocedeclare_shared::{
auto_discover_constraints_with_options, AutoDiscoverConstraintsRequest,
AutoDiscoverConstraintsResponse,
},
get_event_info, get_object_info,
ocel_graph::{get_ocel_graph, OCELGraph, OCELGraphOptions},
ocel_qualifiers::qualifiers::{
get_qualifiers_for_event_types, QualifierAndObjectType, QualifiersForEventType,
},
preprocessing::{linked_ocel::IndexLinkedOCEL, preprocess::link_ocel_info},
OCELInfo,
EventWithIndex, IndexOrID, OCELInfo, ObjectWithIndex,
};
use process_mining::{
event_log::ocel::ocel_struct::OCEL,
Expand Down Expand Up @@ -85,9 +86,10 @@ async fn main() {
"/ocel/discover-constraints",
post(auto_discover_constraints_handler),
)
.route("/ocel/event/:event_id", get(get_event_info))
.route("/ocel/get-event", post(get_event))
.route("/ocel/get-object", post(get_object))
.route("/ocel/event/:event_id", get(get_event_info_req))
.route("/ocel/object/:object_id", get(get_object_info_req))
.route("/ocel/get-event", post(get_event_req))
.route("/ocel/get-object", post(get_object_req))
.with_state(state)
.route("/", get(|| async { "Hello, Aaron!" }))
.layer(cors);
Expand Down Expand Up @@ -208,70 +210,34 @@ pub async fn auto_discover_constraints_handler<'a>(
}))
}

pub async fn get_event_info<'a>(
pub async fn get_event_info_req<'a>(
state: State<AppState>,
Path(event_id): Path<String>,
) -> Json<Option<OCELEvent>> {
println!("{:?}", event_id);
Json(with_ocel_from_state(&state, |ocel| ocel.ev_by_id(&event_id).cloned()).unwrap_or_default())
}

#[derive(Debug, Serialize, Deserialize)]
enum IndexOrID {
#[serde(rename = "id")]
ID(String),
#[serde(rename = "index")]
Index(usize),
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct ObjectWithIndex {
object: OCELObject,
index: usize,
pub async fn get_object_info_req<'a>(
state: State<AppState>,
Path(object_id): Path<String>,
) -> Json<Option<OCELObject>> {
Json(with_ocel_from_state(&state, |ocel| ocel.ob_by_id(&object_id).cloned()).unwrap_or_default())
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct EventWithIndex {
event: OCELEvent,
index: usize,
}

async fn get_event<'a>(
async fn get_event_req<'a>(
state: State<AppState>,
Json(req): Json<IndexOrID>,
) -> Json<Option<EventWithIndex>> {
let res = with_ocel_from_state(&state, |ocel| {
let ev_with_index = match req {
IndexOrID::ID(id) => ocel
.ev_by_id(&id)
.cloned()
.and_then(|ev| ocel.index_of_ev(&id).map(|ev_index| (ev, ev_index.0))),
IndexOrID::Index(index) => ocel.ocel.events.get(index).cloned().map(|ev| (ev, index)),
};
ev_with_index.map(|(event, index)| EventWithIndex { event, index })
})
.flatten();
let res = with_ocel_from_state(&state, |ocel| get_event_info(ocel, req)).flatten();

Json(res)
}

async fn get_object<'a>(
async fn get_object_req<'a>(
state: State<AppState>,
Json(req): Json<IndexOrID>,
) -> Json<Option<ObjectWithIndex>> {
let res = with_ocel_from_state(&state, |ocel| {
let ev_with_index = match req {
IndexOrID::ID(id) => ocel
.ob_by_id(&id)
.cloned()
.and_then(|ob| ocel.index_of_ob(&id).map(|ob_index| (ob, ob_index.0))),
IndexOrID::Index(index) => ocel.ocel.objects.get(index).cloned().map(|ev| (ev, index)),
};
ev_with_index.map(|(object, index)| ObjectWithIndex { object, index })
})
.flatten();
let res = with_ocel_from_state(&state, |ocel| get_object_info(ocel, req)).flatten();

Json(res)
}
5 changes: 3 additions & 2 deletions frontend/src/components/CELEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/* eslint-disable no-template-curly-in-string */
import { VisualEditorContext } from "@/routes/visual-editor/helper/VisualEditorContext";
import type { Variable } from "@/types/generated/Variable";
import { useMonaco, Editor } from "@monaco-editor/react";
import { useMonaco, Editor, loader } from "@monaco-editor/react";
import { useContext, useEffect, useMemo } from "react";

import * as monaco from "monaco-editor";
loader.config({ monaco });
export default function CELEditor({
cel,
onChange,
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@
top: unset !important;
transform: unset !important;
}


.react-flow {
will-change: contents;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0) scale(1, 1);
}
3 changes: 1 addition & 2 deletions frontend/src/routes/visual-editor/VisualEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ export default function VisualEditor(props: VisualEditorProps) {
"#758406",
],
} as const;

return (
<VisualEditorContext.Provider
value={{
Expand Down Expand Up @@ -654,7 +653,7 @@ export default function VisualEditor(props: VisualEditorProps) {
},
}}
>
<ReactFlow
<ReactFlow className="react-flow"
onInit={(flow) => {
initialized.current = true;
if (initialized.current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,13 +819,13 @@ export function FilterOrConstraintDisplay<
);
case "AdvancedCEL":
return (
<div className="flex items-center font-normal text-sm w-full">
<div className="flex items-center text-xs w-full bg-white/50 text-slate-800 border border-slate-600/10 text-[0.5rem] px-0.5 rounded-sm ">
{/* CEL */}
<PiCodeFill className="inline mr-1 pr-1 ml-0.5 border-r" size={24} />
<pre
className="bg-white/50 font-semibold text-slate-800 border border-slate-600/10 text-[0.5rem] px-0.5 rounded-sm overflow-ellipsis overflow-hidden"
className="text-[0.5rem] overflow-ellipsis overflow-hidden break-all whitespace-normal leading-tight font-semibold"
title={value.cel}
>
<PiCodeFill className="inline mr-0.5" size={12} />
{value.cel}
</pre>
</div>
Expand Down
29 changes: 26 additions & 3 deletions tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ use ocedeclare_shared::{
auto_discover_constraints_with_options, AutoDiscoverConstraintsRequest,
AutoDiscoverConstraintsResponse,
},
get_event_info, get_object_info,
ocel_graph::{get_ocel_graph, OCELGraph, OCELGraphOptions},
ocel_qualifiers::qualifiers::{get_qualifiers_for_event_types, QualifiersForEventType},
preprocessing::linked_ocel::{link_ocel_info, IndexLinkedOCEL},
OCELInfo,
EventWithIndex, IndexOrID, OCELInfo, ObjectWithIndex,
};
use process_mining::{import_ocel_json_from_path, import_ocel_xml_file};
use tauri::State;
Expand Down Expand Up @@ -69,7 +70,11 @@ fn check_with_box_tree(
state: State<OCELStore>,
) -> Result<EvaluateBoxTreeResult, String> {
match state.lock().unwrap().as_ref() {
Some(ocel) => Ok(evaluate_box_tree(req.tree, &ocel,req.measure_performance.unwrap_or(false))),
Some(ocel) => Ok(evaluate_box_tree(
req.tree,
&ocel,
req.measure_performance.unwrap_or(false),
)),
None => Err("No OCEL loaded".to_string()),
}
}
Expand All @@ -96,6 +101,22 @@ fn ocel_graph(options: OCELGraphOptions, state: State<OCELStore>) -> Result<OCEL
}
}

#[tauri::command(async)]
fn get_event(req: IndexOrID, state: State<OCELStore>) -> Option<EventWithIndex> {
match state.lock().unwrap().as_ref() {
Some(ocel) => get_event_info(ocel, req),
None => None,
}
}

#[tauri::command(async)]
fn get_object(req: IndexOrID, state: State<OCELStore>) -> Option<ObjectWithIndex> {
match state.lock().unwrap().as_ref() {
Some(ocel) => get_object_info(ocel, req),
None => None,
}
}

fn main() {
tauri::Builder::default()
.manage(OCELStore::new(None))
Expand All @@ -106,7 +127,9 @@ fn main() {
get_object_qualifiers,
check_with_box_tree,
auto_discover_constraints,
ocel_graph
ocel_graph,
get_event,
get_object
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
6 changes: 6 additions & 0 deletions tauri/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const tauriBackend: BackendProvider = {
"ocel/graph": async (options) => {
return await invoke("ocel_graph", { options });
},
"ocel/get-event": async (req) => {
return await invoke("get_event", {req})
},
"ocel/get-object": async (req) => {
return await invoke("get_object", {req})
}
};

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down

0 comments on commit f07fd4b

Please sign in to comment.