Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of join templates workflow #598

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Client/OfficeInterop/ExcelHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)
)

[<AutoOpen>]
module Table =

Expand Down
70 changes: 10 additions & 60 deletions src/Client/OfficeInterop/OfficeInterop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -1015,8 +980,9 @@ module UpdateHandler =
type Main =

/// <summary>
/// Get metadata of active table
/// Get metadata of active table.
/// </summary>
/// <param name="context0"></param>
static member getTableMetaData (?context0) =
excelRunWith context0 <| fun context ->
promise {
Expand Down Expand Up @@ -1052,8 +1018,9 @@ type Main =
}

/// <summary>
/// Delete the annotation block of the selected column in excel
/// Delete the annotation block of the selected column in excel.
/// </summary>
/// <param name="context0"></param>
static member removeSelectedAnnotationBlock (?context0) =
excelRunWith context0 <| fun context ->
promise {
Expand Down Expand Up @@ -1081,6 +1048,8 @@ type Main =
/// <summary>
/// Reads all excel information and returns ArcFiles object, with metadata and tables.
/// </summary>
/// <param name="getTables"></param>
/// <param name="context0"></param>
static member tryParseToArcFile (?getTables, ?context0) =
let getTables = defaultArg getTables true
excelRunWith context0 <| fun context ->
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand Down
27 changes: 17 additions & 10 deletions src/Client/Pages/ProtocolTemplates/SelectiveTemplateFromDB.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ type SelectiveTemplateFromDB =
/// </summary>
/// <param name="model"></param>
/// <param name="dispatch"></param>
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"
Expand All @@ -53,7 +57,7 @@ type SelectiveTemplateFromDB =
/// <param name="setSelectedColumns"></param>
/// <param name="dispatch"></param>
/// <param name="hasIcon"></param>
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)]
Expand All @@ -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)
]
]

Expand All @@ -76,7 +80,7 @@ type SelectiveTemplateFromDB =
/// <param name="importType"></param>
/// <param name="useTemplateName"></param>
/// <param name="dispatch"></param>
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
Expand Down Expand Up @@ -109,7 +113,7 @@ type SelectiveTemplateFromDB =
/// <param name="model"></param>
/// <param name="importType"></param>
/// <param name="dispatch"></param>
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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
]
]
Loading