diff --git a/src/Client/OfficeInterop/ExcelHelper.fs b/src/Client/OfficeInterop/ExcelHelper.fs index 35941181..cec25dee 100644 --- a/src/Client/OfficeInterop/ExcelHelper.fs +++ b/src/Client/OfficeInterop/ExcelHelper.fs @@ -133,6 +133,20 @@ let getSelectedRangeAdress (context: RequestContext) = return range.address } +let getTableValues (tableRange: Range) = + tableRange.values + |> Array.ofSeq + |> Array.map (fun row -> + row + |> Array.ofSeq + |> Array.map (fun column -> + column + |> Option.map string + |> Option.defaultValue "" + |> (fun s -> s.TrimEnd()) + ) + ) + [] module Table = diff --git a/src/Client/OfficeInterop/OfficeInterop.fs b/src/Client/OfficeInterop/OfficeInterop.fs index 17e1776c..0cb4c0f8 100644 --- a/src/Client/OfficeInterop/OfficeInterop.fs +++ b/src/Client/OfficeInterop/OfficeInterop.fs @@ -849,42 +849,6 @@ module UpdateHandler = let _ = table.rows.load(propertyNames = U2.Case2 (ResizeArray[|"count"|])) - //let! table, logging = context.sync().``then``(fun _ -> - - // //logic to compare size of previous table and current table and adapt size of inMemory table - // if prevTableOutput.IsSome then - // //Skip header because it is newly generated for inMemory table - // let newColValues = - // prevTableOutput.Value.[1..] - // |> Array.map (fun cell -> - // [|cell|] - // |> Array.map (box >> Some) - // |> ResizeArray - // ) |> ResizeArray - - // let rowCount0 = int table.rows.count - // let diff = rowCount0 - newColValues.Count - - // if diff > 0 then // table larger than values -> Delete rows to reduce excel table size to previous table size - // table.rows?deleteRowsAt(newColValues.Count, diff) - // elif diff < 0 then // more values than table -> Add rows to increase excel table size to previous table size - // let absolute = (-1) * diff - // let nextvalues = createMatrixForTables 1 absolute "" - // table.rows.add(-1, U4.Case1 nextvalues) |> ignore - - // let body = (table.columns.getItemAt 0.).getDataBodyRange() - // body.values <- newColValues - - // // Fit widths and heights of cols and rows to value size. (In this case the new column headers). - // activeSheet.getUsedRange().format.autofitColumns() - // activeSheet.getUsedRange().format.autofitRows() - - // r.enableEvents <- true - - // // Return info message - - // table, logging - //) let logging = InteropLogging.Msg.create InteropLogging.Info (sprintf "Annotation Table created in [%s] with dimensions 2c x (%.0f + 1h)r." newTableRange.address (newTableRange.rowCount - 1.)) return (table, logging) @@ -983,7 +947,8 @@ module UpdateHandler = if adaptedStartIndex > float (originTable.ColumnCount) then originTable.ColumnCount else int adaptedStartIndex + 1 - let rec loop (originTable: ArcTable) (tablesToAdd: ArcTable []) (selectedColumns: bool[][]) (options: TableJoinOptions option) i = + //Loop over all tables to be added and add them to the origin table + let rec loop (originTable: ArcTable) (tablesToAdd: ArcTable []) (selectedColumns: bool[] []) (options: TableJoinOptions option) i = let tableToAdd = tablesToAdd.[i] let refinedTableToAdd = prepareTemplateInMemory originTable tableToAdd selectedColumns.[i] @@ -1015,8 +980,9 @@ module UpdateHandler = type Main = /// - /// Get metadata of active table + /// Get metadata of active table. /// + /// static member getTableMetaData (?context0) = excelRunWith context0 <| fun context -> promise { @@ -1052,8 +1018,9 @@ type Main = } /// - /// Delete the annotation block of the selected column in excel + /// Delete the annotation block of the selected column in excel. /// + /// static member removeSelectedAnnotationBlock (?context0) = excelRunWith context0 <| fun context -> promise { @@ -1081,6 +1048,8 @@ type Main = /// /// Reads all excel information and returns ArcFiles object, with metadata and tables. /// + /// + /// static member tryParseToArcFile (?getTables, ?context0) = let getTables = defaultArg getTables true excelRunWith context0 <| fun context -> @@ -1478,14 +1447,7 @@ type Main = let rowIndex = int selectedRange.rowIndex if rowIndex > 0 then - let values = - tableRange.values - |> Array.ofSeq - |> Array.map (fun item -> - item |> Array.ofSeq - |> Array.map (fun itemi -> - Option.map string itemi - |> Option.defaultValue "")) + let values = getTableValues tableRange let value = values.[rowIndex].[mainColumnIndex] @@ -1812,19 +1774,7 @@ type Main = do! context.sync() - let tableValues = - tableRange.values - |> Array.ofSeq - |> Array.map (fun row -> - row - |> Array.ofSeq - |> Array.map (fun column -> - column - |> Option.map string - |> Option.defaultValue "" - |> (fun s -> s.TrimEnd()) - ) - ) + let tableValues = getTableValues tableRange let tableHeaders = tableValues.[0] diff --git a/src/Client/Pages/ProtocolTemplates/SelectiveTemplateFromDB.fs b/src/Client/Pages/ProtocolTemplates/SelectiveTemplateFromDB.fs index 1821c8f2..e11a8be7 100644 --- a/src/Client/Pages/ProtocolTemplates/SelectiveTemplateFromDB.fs +++ b/src/Client/Pages/ProtocolTemplates/SelectiveTemplateFromDB.fs @@ -34,11 +34,15 @@ type SelectiveTemplateFromDB = /// /// /// - static member ToProtocolSearchElement(model: Model) setProtocolSearch dispatch = + static member ToProtocolSearchElement (model: Model, setProtocolSearch, importTypeState, setImportTypeState, dispatch) = Daisy.button.button [ prop.onClick(fun _ -> setProtocolSearch true - UpdateModel model |> dispatch) + if model.ProtocolState.TemplatesSelected.Length > 0 then + Protocol.RemoveSelectedProtocols |> ProtocolMsg |> dispatch + {importTypeState with SelectedColumns = Array.empty} |> setImportTypeState + else + UpdateModel model |> dispatch) button.primary button.block prop.text "Browse database" @@ -53,7 +57,7 @@ type SelectiveTemplateFromDB = /// /// /// - static member DisplaySelectedProtocolElements(selectedTemplate: Template option, templateIndex, selectionInformation: SelectiveImportModalState, setSelectedColumns: SelectiveImportModalState -> unit, dispatch, ?hasIcon: bool) = + static member DisplaySelectedProtocolElements(selectedTemplate: Template option, templateIndex, selectedInformation, setSelectedInformation, dispatch, ?hasIcon: bool) = let hasIcon = defaultArg hasIcon true Html.div [ prop.style [style.overflowX.auto; style.marginBottom (length.rem 1)] @@ -63,7 +67,7 @@ type SelectiveTemplateFromDB = Html.i [prop.className "fa-solid fa-cog"] Html.span $"Template: {selectedTemplate.Value.Name}" if selectedTemplate.IsSome then - SelectiveImportModal.TableWithImportColumnCheckboxes(selectedTemplate.Value.Table, templateIndex, selectionInformation, setSelectedColumns) + SelectiveImportModal.TableWithImportColumnCheckboxes(selectedTemplate.Value.Table, templateIndex, selectedInformation, setSelectedInformation) ] ] @@ -76,7 +80,7 @@ type SelectiveTemplateFromDB = /// /// /// - static member AddFromDBToTableButton name (model: Model) selectionInformation importType setImportType useTemplateName protocolSearchState setProtocolSearch dispatch = + static member AddFromDBToTableButton(name, model: Model, selectionInformation, importType, setImportType, useTemplateName, protocolSearchState, setProtocolSearch, dispatch) = let addTemplate (model: Model, selectedColumns) = let template = if model.ProtocolState.TemplatesSelected.Length = 0 then @@ -109,7 +113,7 @@ type SelectiveTemplateFromDB = /// /// /// - static member AddTemplatesFromDBToTableButton name (model: Model) importType setImportType protocolSearchState setProtocolSearch dispatch = + static member AddTemplatesFromDBToTableButton(name, model: Model, importType, setImportType, protocolSearchState, setProtocolSearch, dispatch) = let addTemplates (model: Model, selectedColumns) = let templates = model.ProtocolState.TemplatesSelected if templates.Length = 0 then @@ -152,7 +156,7 @@ type SelectiveTemplateFromDB = {importTypeState with ImportTables = importTypeState.ImportTables |> List.filter (fun it -> it.Index <> i)} |> setImportTypeState React.fragment [ Html.div [ - SelectiveTemplateFromDB.ToProtocolSearchElement model setProtocolSearch dispatch + SelectiveTemplateFromDB.ToProtocolSearchElement(model, setProtocolSearch, importTypeState, setImportTypeState, dispatch) ] if model.ProtocolState.TemplatesSelected.Length > 0 then SelectiveImportModal.RadioPluginsBox( @@ -182,14 +186,17 @@ type SelectiveTemplateFromDB = SelectiveTemplateFromDB.DisplaySelectedProtocolElements(Some template, 0, importTypeState, setImportTypeState, dispatch, false)) ] Html.div [ - SelectiveTemplateFromDB.AddFromDBToTableButton "Add template" model importTypeState importTypeState setImportTypeState importTypeState.TemplateName protocolSearchState setProtocolSearch dispatch + SelectiveTemplateFromDB.AddFromDBToTableButton( + "Add template", model, importTypeState, importTypeState, setImportTypeState, importTypeState.TemplateName, protocolSearchState, setProtocolSearch, dispatch) ] else if model.ProtocolState.TemplatesSelected.Length > 1 then let templates = model.ProtocolState.TemplatesSelected for templateIndex in 0..templates.Length-1 do let template = templates.[templateIndex] - SelectiveImportModal.TableImport(templateIndex, template.Table, importTypeState, addTableImport, rmvTableImport, importTypeState, setImportTypeState, template.Name) + SelectiveImportModal.TableImport( + templateIndex, template.Table, importTypeState, addTableImport, rmvTableImport, importTypeState, setImportTypeState, template.Name) Html.div [ - SelectiveTemplateFromDB.AddTemplatesFromDBToTableButton "Add templates" model importTypeState setImportTypeState protocolSearchState setProtocolSearch dispatch + SelectiveTemplateFromDB.AddTemplatesFromDBToTableButton( + "Add templates", model, importTypeState, setImportTypeState, protocolSearchState, setProtocolSearch, dispatch) ] ]