From 5ff61d2ce3a7805d226dc705c7ea83349eea8c05 Mon Sep 17 00:00:00 2001 From: patrick blume Date: Thu, 7 Nov 2024 16:13:05 +0100 Subject: [PATCH 1/2] Implement basic pathing for compositecolumndetails --- src/Client/OfficeInterop/OfficeInterop.fs | 26 ++++++++++++++++++----- src/Client/SidebarComponents/Navbar.fs | 18 ++++++++-------- src/Client/States/OfficeInteropState.fs | 1 + src/Client/States/SpreadsheetInterface.fs | 1 + src/Client/Update/InterfaceUpdate.fs | 17 +++++++++++++++ src/Client/Update/OfficeInteropUpdate.fs | 9 ++++++++ 6 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/Client/OfficeInterop/OfficeInterop.fs b/src/Client/OfficeInterop/OfficeInterop.fs index 22640c1e..d974cb0a 100644 --- a/src/Client/OfficeInterop/OfficeInterop.fs +++ b/src/Client/OfficeInterop/OfficeInterop.fs @@ -1050,7 +1050,7 @@ let tryGetSelectedTableIndex (table: Table) (context: RequestContext) = /// /// /// -let getSelectedBuildingBlock (table: Table) (context: RequestContext) = +let getSelectedCompositeColumn (table: Table) (context: RequestContext) = promise { let selectedRange = context.workbook.getSelectedRange().load(U2.Case2 (ResizeArray[|"columnIndex"|])) let headerRange = table.getHeaderRowRange() @@ -1154,7 +1154,7 @@ let getSelectedBuildingBlockCell (table: Table) (context: RequestContext) = /// let getArcMainColumn (excelTable: Table) (arcTable: ArcTable) (context: RequestContext) = promise { - let! selectedBlock = getSelectedBuildingBlock excelTable context + let! selectedBlock = getSelectedCompositeColumn excelTable context let protoHeaders = excelTable.getHeaderRowRange() let _ = protoHeaders.load(U2.Case2 (ResizeArray(["values"]))) @@ -1288,7 +1288,7 @@ let removeSelectedAnnotationBlock () = match excelTableRes with | Some excelTable -> - let! selectedBuildingBlock = getSelectedBuildingBlock excelTable context + let! selectedBuildingBlock = getSelectedCompositeColumn excelTable context // iterate DESCENDING to avoid index shift for i, _ in Seq.sortByDescending fst selectedBuildingBlock do @@ -1547,7 +1547,7 @@ let validateBuildingBlock (excelTable: Table, context: RequestContext) = let mutable errors:list = [] if isMainColumn then - let! selectedBuildingBlock = getSelectedBuildingBlock excelTable context + let! selectedBuildingBlock = getSelectedCompositeColumn excelTable context let targetIndex = fst (selectedBuildingBlock.Item (selectedBuildingBlock.Count - 1)) let! result = validateSelectedColumns(headerRange, bodyRowRange, int columnIndex, targetIndex, context) @@ -2111,7 +2111,7 @@ let fillSelectedWithOntologyAnnotation (ontologyAnnotation: OntologyAnnotation) if firstRow = 0. then 1. else firstRow - let! selectedBuildingBlock = getSelectedBuildingBlock excelTable context + let! selectedBuildingBlock = getSelectedCompositeColumn excelTable context let columnIndices = selectedBuildingBlock |> Array.ofSeq |> Array.map (fun (index, _) -> index) let columnHeaders = ARCtrl.Spreadsheet.ArcTable.helperColumnStrings |> Array.ofSeq @@ -2163,6 +2163,22 @@ let fillSelectedWithOntologyAnnotation (ontologyAnnotation: OntologyAnnotation) } ) +let getCompositeColumnDetails () = + Excel.run(fun context -> + promise { + let! excelTableRes = AnnotationTable.tryGetActive context + match excelTableRes with + | Some excelTable -> + + let selectedCompositeColumn = getSelectedCompositeColumn excelTable context + + + + return [InteropLogging.Msg.create InteropLogging.Info "Some Info"] + | None -> + return [InteropLogging.NoActiveTableMsg] + } + ) /// This function is used to insert file names into the selected range. let insertFileNamesFromFilePicker (fileNameList: string list) = diff --git a/src/Client/SidebarComponents/Navbar.fs b/src/Client/SidebarComponents/Navbar.fs index ea3ee4b7..2d323452 100644 --- a/src/Client/SidebarComponents/Navbar.fs +++ b/src/Client/SidebarComponents/Navbar.fs @@ -272,15 +272,15 @@ let private ShortCutIconList toggleMetdadataModal model (dispatch: Messages.Msg ], (fun _ -> SpreadsheetInterface.RemoveBuildingBlock |> InterfaceMsg |> dispatch) ) - //QuickAccessButton.create( - // "Get Building Block Information", - // [ - // Html.i [prop.className "fa-solid fa-question pr-1"] - // Html.span model.BuildingBlockDetailsState.CurrentRequestState.toStringMsg - // Html.i [prop.className "fa-solid fa-table-columns"] - // ], - // (fun _ -> SpreadsheetInterface.EditBuildingBlock |> InterfaceMsg |> dispatch) - //) + QuickAccessButton.create( + "Get Building Block Information", + [ + Html.i [prop.className "fa-solid fa-question pr-1"] + //Html.span model.BuildingBlockDetailsState.CurrentRequestState.toStringMsg + Html.i [prop.className "fa-solid fa-table-columns"] + ], + (fun _ -> SpreadsheetInterface.GetBuildingBlockDetails |> InterfaceMsg |> dispatch) + ) ] |> List.map (fun x -> x.toReactElement()) |> React.fragment diff --git a/src/Client/States/OfficeInteropState.fs b/src/Client/States/OfficeInteropState.fs index 1275bdf7..6fa2bffe 100644 --- a/src/Client/States/OfficeInteropState.fs +++ b/src/Client/States/OfficeInteropState.fs @@ -39,6 +39,7 @@ type Msg = | AddTemplate of ArcTable | JoinTable of ArcTable * options: TableJoinOptions option | RemoveBuildingBlock + | GetBuildingBlockDetails | UpdateUnitForCells | AutoFitTable of hideRefCols:bool // Term search functions diff --git a/src/Client/States/SpreadsheetInterface.fs b/src/Client/States/SpreadsheetInterface.fs index e9e385e7..ae0f0c26 100644 --- a/src/Client/States/SpreadsheetInterface.fs +++ b/src/Client/States/SpreadsheetInterface.fs @@ -22,6 +22,7 @@ type Msg = | UpdateArcFile of ArcFiles /// Inserts TermMinimal to selected fields of one column | InsertOntologyAnnotation of OntologyAnnotation +| GetBuildingBlockDetails | InsertFileNames of string list | ImportXlsx of byte [] | ImportJson of {|importState: SelectiveImportModalState; importedFile: ArcFiles|} diff --git a/src/Client/Update/InterfaceUpdate.fs b/src/Client/Update/InterfaceUpdate.fs index a7ffaf27..79141626 100644 --- a/src/Client/Update/InterfaceUpdate.fs +++ b/src/Client/Update/InterfaceUpdate.fs @@ -268,6 +268,23 @@ module Interface = Spreadsheet.DeleteColumn (distinct.[0]) |> SpreadsheetMsg |> Cmd.ofMsg model, cmd | _ -> failwith "not implemented" + | GetBuildingBlockDetails -> + match host with + | Some Swatehost.Excel -> + let cmd = OfficeInterop.GetBuildingBlockDetails |> OfficeInteropMsg |> Cmd.ofMsg + model, cmd + //| Some Swatehost.Browser | Some Swatehost.ARCitect -> + // if Set.isEmpty model.SpreadsheetModel.SelectedCells then failwith "No column selected" + // let selectedColumns, _ = model.SpreadsheetModel.SelectedCells |> Set.toArray |> Array.unzip + // let distinct = selectedColumns |> Array.distinct + // let cmd = + // if distinct.Length <> 1 then + // let msg = Failure("Please select one column only if you want to use `Remove Building Block`.") + // GenericError (Cmd.none,msg) |> DevMsg |> Cmd.ofMsg + // else + // Spreadsheet.DeleteColumn (distinct.[0]) |> SpreadsheetMsg |> Cmd.ofMsg + // model, cmd + | _ -> failwith "not implemented" | AddDataAnnotation data -> match host with | Some Swatehost.Excel -> diff --git a/src/Client/Update/OfficeInteropUpdate.fs b/src/Client/Update/OfficeInteropUpdate.fs index 0d30741e..0dead352 100644 --- a/src/Client/Update/OfficeInteropUpdate.fs +++ b/src/Client/Update/OfficeInteropUpdate.fs @@ -119,6 +119,15 @@ module OfficeInterop = (curry GenericError Cmd.none >> DevMsg) state, model, cmd + | GetBuildingBlockDetails -> + let cmd = + Cmd.OfPromise.either + OfficeInterop.Core.getCompositeColumnDetails + () + (curry GenericInteropLogs Cmd.none >> DevMsg) + (curry GenericError Cmd.none >> DevMsg) + state, model, cmd + | UpdateUnitForCells -> let cmd = Cmd.OfPromise.either From de1e6ba7d0772fdc53c1bbe02e780097a5052145 Mon Sep 17 00:00:00 2001 From: patrick blume Date: Fri, 8 Nov 2024 09:57:48 +0100 Subject: [PATCH 2/2] Get data from database --- src/Client/OfficeInterop/OfficeInterop.fs | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Client/OfficeInterop/OfficeInterop.fs b/src/Client/OfficeInterop/OfficeInterop.fs index d974cb0a..0d3cfbde 100644 --- a/src/Client/OfficeInterop/OfficeInterop.fs +++ b/src/Client/OfficeInterop/OfficeInterop.fs @@ -2170,9 +2170,36 @@ let getCompositeColumnDetails () = match excelTableRes with | Some excelTable -> - let selectedCompositeColumn = getSelectedCompositeColumn excelTable context + let! selectedCompositeColumn = getSelectedCompositeColumn excelTable context + let selectedRange = context.workbook.getSelectedRange() + let tableRange = excelTable.getRange() + let _ = + tableRange.load(U2.Case2 (ResizeArray[|"values";|])) |> ignore + selectedRange.load(U2.Case2 (ResizeArray[|"rowIndex";|])) + + do! context.sync().``then``(fun _ -> ()) + + let mainColumnIndex = fst (selectedCompositeColumn.Item 0) + let rowIndex = int selectedRange.rowIndex + + let values = + tableRange.values + |> Array.ofSeq + |> Array.map (fun item -> + item |> Array.ofSeq + |> Array.map (fun itemi -> + Option.map string itemi + |> Option.defaultValue "")) + + let value = values.[rowIndex].[mainColumnIndex] + + let! termsRes = searchTermsInDatabase [value] + let terms = + termsRes + |> Array.choose (fun term -> term) + let name = terms |> Array.map (fun item -> item.Name) return [InteropLogging.Msg.create InteropLogging.Info "Some Info"] | None ->