From ae04aa51261e614d0c422f03d646e1a76d664501 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Tue, 9 Mar 2021 10:21:39 +0100 Subject: [PATCH 1/2] Stabilize protocol insert against bugs :bug: --- src/Client/OfficeInterop/HelperFunctions.fs | 132 +++++++++++-------- src/Client/OfficeInterop/OfficeInterop.fs | 133 +++++++++----------- 2 files changed, 140 insertions(+), 125 deletions(-) diff --git a/src/Client/OfficeInterop/HelperFunctions.fs b/src/Client/OfficeInterop/HelperFunctions.fs index 6e06ab48..0765624f 100644 --- a/src/Client/OfficeInterop/HelperFunctions.fs +++ b/src/Client/OfficeInterop/HelperFunctions.fs @@ -129,70 +129,102 @@ let findNewIdForUnit (allColHeaders:string []) (format:string option) (unitAcces int loopingCheck 1 -let createUnitColumns (allColHeaders:string []) (annotationTable:Table) newBaseColIndex rowCount (format:string option) (unitAccessionOpt:string option) = +let createUnitColumns (annotationTableName:string) newBaseColIndex rowCount (format:string option) (unitAccessionOpt:string option) = let col = createEmptyMatrixForTables 1 rowCount "" if format.IsSome then + Excel.run(fun context -> + let sheet = context.workbook.worksheets.getActiveWorksheet() + let annotationTable = sheet.tables.getItem(annotationTableName) + let annoHeaderRange = annotationTable.getHeaderRowRange() + let _ = annoHeaderRange.load(U2.Case2 (ResizeArray[|"values";"columnIndex"; "columnCount"; "rowIndex"|])) - let newUnitId = findNewIdForUnit allColHeaders format unitAccessionOpt - - /// create unit main column - let createdUnitCol1 = - annotationTable.columns.add( - index = newBaseColIndex+3., - values = U4.Case1 col, - name = sprintf "Unit %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) - ) + context.sync().``then``(fun e -> + printfn "1" + let headerVals = annoHeaderRange.values.[0] |> Array.ofSeq + + let allColHeaders = + headerVals + |> Array.choose id + |> Array.map string + + printfn "2" + let newUnitId = findNewIdForUnit allColHeaders format unitAccessionOpt + + /// create unit main column + let createdUnitCol1 = + annotationTable.columns.add( + index = newBaseColIndex+3., + values = U4.Case1 col, + name = sprintf "Unit %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) + ) - /// create unit TSR - let createdUnitCol2 = - annotationTable.columns.add( - index = newBaseColIndex+4., - values = U4.Case1 col, - name = sprintf "Term Source REF %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) - ) + /// create unit TSR + let createdUnitCol2 = + annotationTable.columns.add( + index = newBaseColIndex+4., + values = U4.Case1 col, + name = sprintf "Term Source REF %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) + ) - /// create unit TAN - let createdUnitCol3 = - annotationTable.columns.add( - index = newBaseColIndex+5., - values = U4.Case1 col, - name = sprintf "Term Accession Number %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) + /// create unit TAN + let createdUnitCol3 = + annotationTable.columns.add( + index = newBaseColIndex+5., + values = U4.Case1 col, + name = sprintf "Term Accession Number %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) + ) + printfn "3" + Some ( + sprintf " Added specified unit: %s" (format.Value), + sprintf "0.00 \"%s\"" (format.Value) + ) ) - - Some ( - sprintf " Added specified unit: %s" (format.Value), - sprintf "0.00 \"%s\"" (format.Value) ) + else - None + promise {return None} -let updateUnitColumns (allColHeaders:string []) (annoHeaderRange:Excel.Range) newBaseColIndex (format:string option) (unitAccessionOpt:string option) = +let updateUnitColumns (annotationTableName:string) newBaseColIndex (format:string option) (unitAccessionOpt:string option) = let col v= createValueMatrix 1 1 v if format.IsSome then + Excel.run(fun context -> + let sheet = context.workbook.worksheets.getActiveWorksheet() + let annotationTable = sheet.tables.getItem(annotationTableName) + let annoHeaderRange = annotationTable.getHeaderRowRange() + let _ = annoHeaderRange.load(U2.Case2 (ResizeArray[|"values";"columnIndex"; "columnCount"; "rowIndex"|])) - let newUnitId = findNewIdForUnit allColHeaders format unitAccessionOpt - - /// create unit main column - let updateUnitCol1 = - annoHeaderRange.getColumn(newBaseColIndex+3.) - |> fun c1 -> c1.values <- sprintf "Unit %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) |> col - - /// create unit TSR - let createdUnitCol2 = - annoHeaderRange.getColumn(newBaseColIndex+4.) - |> fun c2 -> c2.values <- sprintf "Term Source REF %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) |> col - - /// create unit TAN - let createdUnitCol3 = - annoHeaderRange.getColumn(newBaseColIndex+5.) - |> fun c3 -> c3.values <- sprintf "Term Accession Number %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) |> col - - Some ( - sprintf " Added specified unit: %s" (format.Value), - sprintf "0.00 \"%s\"" (format.Value) + context.sync().``then``(fun e -> + let headerVals = annoHeaderRange.values.[0] |> Array.ofSeq + + let allColHeaders = + headerVals + |> Array.choose id + |> Array.map string + let newUnitId = findNewIdForUnit allColHeaders format unitAccessionOpt + + /// create unit main column + let updateUnitCol1 = + annoHeaderRange.getColumn(newBaseColIndex+3.) + |> fun c1 -> c1.values <- sprintf "Unit %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) |> col + + /// create unit TSR + let createdUnitCol2 = + annoHeaderRange.getColumn(newBaseColIndex+4.) + |> fun c2 -> c2.values <- sprintf "Term Source REF %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) |> col + + /// create unit TAN + let createdUnitCol3 = + annoHeaderRange.getColumn(newBaseColIndex+5.) + |> fun c3 -> c3.values <- sprintf "Term Accession Number %s" (unitColAttributes format.Value unitAccessionOpt newUnitId) |> col + + Some ( + sprintf " Added specified unit: %s" (format.Value), + sprintf "0.00 \"%s\"" (format.Value) + ) + ) ) else - None + promise {return None} /// Swaps 'Rows with column values' to 'Columns with row values'. let viewRowsByColumns (rows:ResizeArray>) = diff --git a/src/Client/OfficeInterop/OfficeInterop.fs b/src/Client/OfficeInterop/OfficeInterop.fs index 31ac697a..93a768b6 100644 --- a/src/Client/OfficeInterop/OfficeInterop.fs +++ b/src/Client/OfficeInterop/OfficeInterop.fs @@ -376,6 +376,7 @@ let getTableRepresentation() = /// This function is used to add a new building block to the active annotationTable. let addAnnotationBlock (buildingBlockInfo:MinimalBuildingBlock) = + printfn "Start with building block %A" buildingBlockInfo.MainColumnName /// The following cols are currently always singles (cannot have TSR, TAN, unit cols). For easier refactoring these names are saved in OfficeInterop.Types. let isSingleCol = match buildingBlockInfo.MainColumnName with @@ -413,10 +414,10 @@ let addAnnotationBlock (buildingBlockInfo:MinimalBuildingBlock) = promise { - let! annotationTable = getActiveAnnotationTableName() + let! annotationTableName = getActiveAnnotationTableName() let sheet = context.workbook.worksheets.getActiveWorksheet() - let annotationTable = sheet.tables.getItem(annotationTable) + let annotationTable = sheet.tables.getItem(annotationTableName) // Ref. 2 @@ -428,8 +429,6 @@ let addAnnotationBlock (buildingBlockInfo:MinimalBuildingBlock) = let range = context.workbook.getSelectedRange() let _ = range.load(U2.Case1 "columnIndex") - // Ref. 1 - let r = context.runtime.load(U2.Case1 "enableEvents") let! newBaseColIndex,headerVals = context.sync().``then``(fun e -> // Ref. 3 @@ -456,10 +455,9 @@ let addAnnotationBlock (buildingBlockInfo:MinimalBuildingBlock) = newBaseColIndex', headerVals ) - let! res = context.sync().``then``( fun _ -> - - r.enableEvents <- false + let rowCount = tableRange.rowCount |> int + let! mainColName = context.sync().``then``( fun _ -> let allColHeaders = headerVals @@ -495,8 +493,6 @@ let addAnnotationBlock (buildingBlockInfo:MinimalBuildingBlock) = // The new id, which does not exist yet with the column name let newId = findNewIdForName() - let rowCount = tableRange.rowCount |> int - //create an empty column to insert let col value = createEmptyMatrixForTables 1 rowCount value @@ -539,49 +535,48 @@ let addAnnotationBlock (buildingBlockInfo:MinimalBuildingBlock) = createdCol3() |] + /// return main col names, unit column format and a message. The first two params are used in a follow up message (executing 'changeTableColumnFormat') + mainColName buildingBlockInfo.MainColumnName newId + ) + printfn "Start with unit for building block %A" buildingBlockInfo.MainColumnName + let! createUnitColsIfNeeded = /// if format.isSome then we need to also add unit columns in the following scheme: /// Unit [UnitTermName] (#id; #h; #u) | Term Source REF [UnitTermName] (#id; #h; #u) | Term Accession Number [UnitTermName] (#id; #h; #u) let createUnitColsIfNeeded = - OfficeInterop.HelperFunctions.createUnitColumns allColHeaders annotationTable newBaseColIndex rowCount buildingBlockInfo.UnitName buildingBlockInfo.UnitTermAccession + OfficeInterop.HelperFunctions.createUnitColumns annotationTableName newBaseColIndex rowCount buildingBlockInfo.UnitName buildingBlockInfo.UnitTermAccession - /// If unit block was added then return some msg information - let unitColCreationMsg = if createUnitColsIfNeeded.IsSome then fst createUnitColsIfNeeded.Value else "" - let unitColFormat = if createUnitColsIfNeeded.IsSome then snd createUnitColsIfNeeded.Value else "0.00" + createUnitColsIfNeeded - r.enableEvents <- true - /// return main col names, unit column format and a message. The first two params are used in a follow up message (executing 'changeTableColumnFormat') - mainColName buildingBlockInfo.MainColumnName newId, unitColFormat, sprintf "%s column was added. %s" buildingBlockInfo.MainColumnName unitColCreationMsg - ) + /// If unit block was added then return some msg information + let unitColCreationMsg = if createUnitColsIfNeeded.IsSome then fst createUnitColsIfNeeded.Value else "" + let unitColFormat = if createUnitColsIfNeeded.IsSome then snd createUnitColsIfNeeded.Value else "0.00" + + printfn "Done with building block %A" buildingBlockInfo.MainColumnName + return mainColName, unitColFormat, sprintf "%s column was added. %s" mainColName unitColCreationMsg - return res } ) +open Fable + let addAnnotationBlocksAsProtocol (buildingBlockInfoList:MinimalBuildingBlock list, protocol:Xml.GroupTypes.Protocol) = - - let addBuildingBlock buildingBlockInfo = - promise { - let! res = addAnnotationBlock(buildingBlockInfo) - return [res] + + let chainBuildingBlocks (buildingBlockInfoList:MinimalBuildingBlock list) = + let state bb = promise { + let! baseAsync = bb |> addAnnotationBlock + return [baseAsync] } - let chainBuildingBlocks buildingBlockInfoList = - let promiseList = buildingBlockInfoList |> List.map (fun x -> addBuildingBlock x) - - let emptyPromise = promise {return []} - - let rec chain ind (promiseList:JS.Promise<(string*string*string) list> list ) resultPromise = - if ind >= promiseList.Length then - resultPromise - elif ind = 0 then - let currentPromise = promiseList |> List.item ind - chain 1 promiseList currentPromise - else - let currentPromise = promiseList |> List.item ind - let nextPromise = - Promise.PromiseBuilder().Merge(currentPromise,resultPromise, (fun x y -> x@y)) - chain (ind+1) promiseList nextPromise - - chain 0 promiseList emptyPromise + buildingBlockInfoList.Tail + |> List.fold (fun (previousPromise:JS.Promise<(string*string*string) list>) nextID -> + promise { + let! prev,nextPromise = + previousPromise.``then``(fun e -> + e,state nextID + ) + let! next = nextPromise + return next@prev + } + ) (state buildingBlockInfoList.Head) let infoProm = @@ -629,8 +624,12 @@ let addAnnotationBlocksAsProtocol (buildingBlockInfoList:MinimalBuildingBlock li x.MainColumnName, "0.00", "" ) + printfn "start creating all building blocks" + let! chainProm = chainBuildingBlocks onlyNonExistingBuildingBlocks + printfn "done creating all building blocks" + let updateProtocol = {protocol with AnnotationTable = AnnotationTable.create annotationTable activeSheet.name} return (chainProm@alreadyExistingBlocks,updateProtocol) @@ -1520,7 +1519,6 @@ let writeTableValidationToXml(tableValidation:ValidationTypes.TableValidation,cu let addTableValidationToExisting (tableValidation:ValidationTypes.TableValidation, colNames: string list) = Excel.run(fun context -> - printfn "START ADDING TABLEVALIDATION" let getBaseName (colHeader:string) = let parsedHeader = parseColHeader colHeader let ont = if parsedHeader.Ontology.IsSome then sprintf " [%s]" parsedHeader.Ontology.Value.Name else "" @@ -1531,8 +1529,6 @@ let addTableValidationToExisting (tableValidation:ValidationTypes.TableValidatio getBaseName x, x ) |> Map.ofList - printfn "%A" newColNameMap - printfn "%A" tableValidation //failwith (sprintf "%A" tableValidation) let updateColumnValidationColNames = @@ -1636,41 +1632,28 @@ let addUnitToExistingBuildingBlock (format:string option,unitAccessionOpt:string let! selectedBuildingBlock = BuildingBlockTypes.findSelectedBuildingBlock selectedRange annoHeaderRange annoBodyRange context - let! res = context.sync().``then``( fun _ -> + if selectedBuildingBlock.TAN.IsNone || selectedBuildingBlock.TSR.IsNone then + failwith ( + sprintf + "Swate can only add a unit to columns of the type: %s, %s, %s." + OfficeInterop.Types.ColumnCoreNames.Shown.Parameter + OfficeInterop.Types.ColumnCoreNames.Shown.Characteristics + OfficeInterop.Types.ColumnCoreNames.Shown.Factor + ) - if selectedBuildingBlock.TAN.IsNone || selectedBuildingBlock.TSR.IsNone then - failwith ( - sprintf - "Swate can only add a unit to columns of the type: %s, %s, %s." - OfficeInterop.Types.ColumnCoreNames.Shown.Parameter - OfficeInterop.Types.ColumnCoreNames.Shown.Characteristics - OfficeInterop.Types.ColumnCoreNames.Shown.Factor - ) - - // This is necessary to skip over hidden cols - /// Get an array of the headers - let headerVals = annoHeaderRange.values.[0] |> Array.ofSeq - - let allColHeaders = - headerVals - |> Array.choose id - |> Array.map string - - let unitColumnResult = - if selectedBuildingBlock.Unit.IsSome then - updateUnitColumns allColHeaders annoHeaderRange (float selectedBuildingBlock.MainColumn.Index) format unitAccessionOpt - else - createUnitColumns allColHeaders table (float selectedBuildingBlock.MainColumn.Index) (int tableRange.rowCount) format unitAccessionOpt + let! unitColumnResult = + if selectedBuildingBlock.Unit.IsSome then + updateUnitColumns annotationTable (float selectedBuildingBlock.MainColumn.Index) format unitAccessionOpt + else + createUnitColumns annotationTable (float selectedBuildingBlock.MainColumn.Index) (int tableRange.rowCount) format unitAccessionOpt - let maincolName = selectedBuildingBlock.MainColumn.Header.Value.Header + let maincolName = selectedBuildingBlock.MainColumn.Header.Value.Header - /// If unit block was added then return some msg information - //let unitColCreationMsg = if unitColumnResult.IsSome then fst unitColumnResult.Value else "" - let unitColFormat = if unitColumnResult.IsSome then snd unitColumnResult.Value else "0.00" + /// If unit block was added then return some msg information + //let unitColCreationMsg = if unitColumnResult.IsSome then fst unitColumnResult.Value else "" + let unitColFormat = if unitColumnResult.IsSome then snd unitColumnResult.Value else "0.00" - maincolName, unitColFormat //, unitColCreationMsg - ) - return res + return maincolName, unitColFormat } ) From c687822bf7c6028e556f29b7e2dd054914eba635 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Tue, 9 Mar 2021 10:22:40 +0100 Subject: [PATCH 2/2] Update RELEASE_NOTES.md --- .assets/assets/manifest.xml | 2 +- RELEASE_NOTES.md | 6 ++++++ manifest.xml | 2 +- src/Server/Version.fs | 8 ++++---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.assets/assets/manifest.xml b/.assets/assets/manifest.xml index 1e1663ec..1e23b53a 100644 --- a/.assets/assets/manifest.xml +++ b/.assets/assets/manifest.xml @@ -1,7 +1,7 @@  5d6f5462-3401-48ec-9406-d12882e9ad83 - 0.4.1 + 0.4.2 Computational Systems Biology en-US diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 6d006142..66280be6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,9 @@ +### 0.4.2+ae04aa5 (Released 2021-3-9) +* Additions: + * latest commit #ae04aa5 +* Bugfixes: + * [[#ae04aa5](https://github.com/nfdi4plants/Swate/commit/ae04aa51261e614d0c422f03d646e1a76d664501)] Stabilize protocol insert against bugs :bug: + ### 0.4.1+d75743c (Released 2021-3-8) * Additions: * latest commit #d75743c diff --git a/manifest.xml b/manifest.xml index 2437fe5f..d389911e 100644 --- a/manifest.xml +++ b/manifest.xml @@ -1,7 +1,7 @@  5d6f5462-3401-48ec-9406-d12882e9ad83 - 0.4.1 + 0.4.2 Computational Systems Biology en-US diff --git a/src/Server/Version.fs b/src/Server/Version.fs index 00b42ad2..8949972f 100644 --- a/src/Server/Version.fs +++ b/src/Server/Version.fs @@ -3,11 +3,11 @@ namespace System open System.Reflection [] -[] -[] +[] +[] do () module internal AssemblyVersionInformation = let [] AssemblyTitle = "SWATE" - let [] AssemblyVersion = "0.4.1" - let [] AssemblyMetadata_ReleaseDate = "08/03/2021" + let [] AssemblyVersion = "0.4.2" + let [] AssemblyMetadata_ReleaseDate = "09/03/2021"