Skip to content

Commit

Permalink
#15, #18 : Add Building block insert and unit cell formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed May 27, 2020
1 parent b8a23ff commit 3256ba0
Show file tree
Hide file tree
Showing 20 changed files with 273 additions and 45 deletions.
7 changes: 6 additions & 1 deletion SAFEOfficeAddInn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.config\dotnet-tools.json = .config\dotnet-tools.json
global.json = global.json
manifest.xml = manifest.xml
manifestGeneration.fsx = manifestGeneration.fsx
package.json = package.json
paket.dependencies = paket.dependencies
paket.lock = paket.lock
Expand Down Expand Up @@ -55,6 +54,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "generators", "generators",
docsrc\generators\staticfile.fsx = docsrc\generators\staticfile.fsx
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{494903F3-B40F-4C45-BAF6-C89D8DD002C6}"
ProjectSection(SolutionItems) = preProject
tools\manifestGenerator.fsx = tools\manifestGenerator.fsx
tools\testDbSetup.fsx = tools\testDbSetup.fsx
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
22 changes: 21 additions & 1 deletion build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,39 @@ Target.create "CreateDevCerts" (fun _ ->
)


Target.create "Bundle" (fun _ ->
let serverDir = Path.combine deployDir "Server"
let clientDir = Path.combine deployDir "Client"
let publicDir = Path.combine clientDir "public"
let publishArgs = sprintf "publish -c Release -o \"%s\"" serverDir
runDotNet publishArgs serverPath

Shell.copyDir publicDir clientDeployPath FileFilter.allFiles
)

Target.create "Setup" ignore

open Fake.Core.TargetOperators

"Clean"
==> "InstallClient"
==> "Build"


"Clean"
==> "InstallClient"
==> "Run"

"Clean"
==> "InstallClient"
==> "Build"
==> "Bundle"

"Clean"
==> "InstallClient"
==> "OfficeDebug"

"InstallOfficeAddinTooling"
==> "CreateDevCerts"
==> "Setup"

Target.runOrDefaultWithArguments "Build"
3 changes: 3 additions & 0 deletions src/Client/Client.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ let view (model : Model) (dispatch : Msg -> unit) =
str "Footer content"
]

| Routing.Page.Home ->
div [] [str "soos"]

| _ ->
div [ Style [MinHeight "100vh"; BackgroundColor model.SiteStyleState.ColorMode.BodyBackground; Color model.SiteStyleState.ColorMode.Text;]
] [
Expand Down
1 change: 1 addition & 0 deletions src/Client/Client.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<Compile Include="Update.fs" />
<Compile Include="CustomComponents\Footer.fs" />
<Compile Include="CustomComponents\Button.fs" />
<Compile Include="CustomComponents\AnnotationTableMissingWarning.fs" />
<Compile Include="CustomComponents\Navbar.fs" />
<Compile Include="CustomComponents\Loading.fs" />
<Compile Include="CustomComponents\AutocompleteDropdown.fs" />
Expand Down
28 changes: 28 additions & 0 deletions src/Client/CustomComponents/AnnotationTableMissingWarning.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module CustomComponents.AnnotationTableMissingWarning

open Fable.React
open Fable.React.Props
open Fulma
open Fulma.Extensions.Wikiki
open ExcelColors
open Model
open Messages

let annotationTableMissingWarningComponent (model:Model) (dispatch: Msg-> unit) =
Notification.notification [
Notification.Color IsWarning
Notification.Props [

]
] [
Notification.delete [] []
Heading.h5 [] [str "Warning: No Annotation table found in worksheet"]
Text.p [] [
str "Your worksheet seems to contain no annotation table. You can create one by pressing the button below"
]
Button.buttonComponent
model.SiteStyleState.ColorMode
true
"create annoation table"
(fun _ -> model.SiteStyleState.IsDarkMode |> CreateAnnotationTable |> ExcelInterop |> dispatch)
]
8 changes: 4 additions & 4 deletions src/Client/CustomComponents/AutocompleteDropdown.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ let autocompleteDropdownComponent (model:Model) (dispatch: Msg -> unit) (isVisib
BorderColor model.SiteStyleState.ColorMode.ControlForeground
]]
] [
Table.table [Table.IsFullWidth] (
Table.table [Table.IsFullWidth] [
if isLoading then
[
tbody [] [
tr [] [
td [Style [TextAlign TextAlignOptions.Center]] [
Loading.loadingComponent
Expand All @@ -35,8 +35,8 @@ let autocompleteDropdownComponent (model:Model) (dispatch: Msg -> unit) (isVisib
]
]
else
suggestions
)
tbody [] suggestions
]


]
Expand Down
5 changes: 4 additions & 1 deletion src/Client/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ type ExcelInteropMsg =
| InSync of string
| TryExcel
| FillSelection of string
| AddColumn of string
| AddColumn of colname:string * formatString:string
| FormatColumn of colname:string * formatString:string
| CreateAnnotationTable of bool
| AnnotationtableCreated of string
| AnnotationTableExists of bool

type SimpleTermSearchMsg =
| SearchTermTextChange of string
Expand Down
64 changes: 45 additions & 19 deletions src/Client/OfficeInterop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ let createEmptyMatrixForTables (colCount:int) (rowCount:int) value =
|] :> IList<U3<bool,string,float>>
|] :> IList<IList<U3<bool,string,float>>>


let createValueMatrix (colCount:int) (rowCount:int) value =
ResizeArray([
for outer in 0 .. rowCount-1 do
let tmp = Array.zeroCreate colCount |> Seq.map (fun _ -> Some (value |> box))
ResizeArray(tmp)
])

let createAnnotationTable (isDark:bool) =
Excel.run(fun context ->
let tableRange = context.workbook.getSelectedRange()
Expand All @@ -62,31 +70,28 @@ let createAnnotationTable (isDark:bool) =

annotationTable.style <- style

if tableRange.columnCount < 2. then // only one column there, so add data col to end.

let dataCol = createEmptyMatrixForTables 1 (int tableRange.rowCount) ""

(annotationTable.columns.getItemAt 0.).name <- "Sample Name"
annotationTable.columns.add(-1.,U4.Case1 dataCol, "Data File Name") |> ignore

sheet.getUsedRange().format.autofitColumns()
sheet.getUsedRange().format.autofitRows()

sprintf "Annotation Table created in [%s] with dimensions %.0f + 1 mandatory c x (%.0f + 1h)r" tableRange.address tableRange.columnCount (tableRange.rowCount - 1.)
else
(annotationTable.columns.getItemAt 0.).name <- "Source Name"

(annotationTable.columns.getItemAt 0.).name <- "Sample Name"
(annotationTable.columns.getItemAt (tableRange.columnCount - 1.)).name <- "Data File Name"
sheet.getUsedRange().format.autofitColumns()
sheet.getUsedRange().format.autofitRows()

sheet.getUsedRange().format.autofitColumns()
sheet.getUsedRange().format.autofitRows()
sprintf "Annotation Table created in [%s] with dimensions %.0f c x (%.0f + 1h)r" tableRange.address tableRange.columnCount (tableRange.rowCount - 1.)

sprintf "Annotation Table created in [%s] with dimensions %.0fc x (%.0f + 1h)r. Adapted style to %s" tableRange.address tableRange.columnCount (tableRange.rowCount - 1.) style

)
//.catch (fun e -> e |> unbox<System.Exception> |> fun x -> x.Message)
)

let checkIfAnnotationTableIsPresent () =
Excel.run(fun context ->
let tableRange = context.workbook.getSelectedRange()
let sheet = context.workbook.worksheets.getActiveWorksheet()
//delete table with the same name if present because there can only be one chosen one <3
let table = sheet.tables.getItemOrNullObject("annotationTable")
context.sync()
.``then``( fun _ ->
not table.isNullObject
)
)


let addAnnotationColumn (colName:string) =
Expand All @@ -100,17 +105,38 @@ let addAnnotationColumn (colName:string) =
context.sync().``then``( fun _ ->
let colCount = tableRange.columnCount
let rowCount = tableRange.rowCount |> int
//create an empty column to insert
let testCol = createEmptyMatrixForTables 1 rowCount ""

let _ =
annotationTable.columns.add(
colCount - 1., //last column should always be the predefined results column
colCount,
values = U4.Case1 testCol, name=colName
)
sprintf "%s column was added." colName
)
)

let changeTableColumnFormat (colName:string) (format:string) =
Excel.run(fun context ->
let sheet = context.workbook.worksheets.getActiveWorksheet()
let annotationTable = sheet.tables.getItem("annotationTable")

let colRange = (annotationTable.columns.getItem (U2.Case2 colName)).getDataBodyRange()
colRange.load(U2.Case2 (ResizeArray(["columnCount";"rowCount"]))) |> ignore

context.sync().``then``( fun _ ->
let rowCount = colRange.rowCount |> int
//create an empty column to insert
let formats = createValueMatrix 1 rowCount format

colRange.numberFormat <- formats

sprintf "format of %s was changed to %s" colName format
)
)


let fillValue (v:string) =
Excel.run(fun context ->
let range = context.workbook.getSelectedRange()
Expand Down
8 changes: 8 additions & 0 deletions src/Client/Routing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ type Page =
| Page.ActivityLog -> "/#ActivityLog"
| Page.NotFound -> "/#NotFound"

static member toString = function
| Page.Home -> ""
| Page.TermSearch -> "TermSearch"
| Page.AddBuildingBlock -> "AddBuildingBlock"
| Page.FilePicker -> "FilePicker"
| Page.ActivityLog -> "ActivityLog"
| Page.NotFound -> "NotFound"

/// The URL is turned into a Result.
let pageParser : Parser<Page -> Page,_> =
oneOf [
Expand Down
49 changes: 41 additions & 8 deletions src/Client/Update.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,26 @@ let handleExcelInteropMsg (excelInteropMsg: ExcelInteropMsg) (currentState:Excel

| SyncContext passthroughMessage ->
currentState,
Cmd.OfPromise.either
OfficeInterop.syncContext
passthroughMessage
(fun _ -> ExcelInterop (InSync passthroughMessage))
(GenericError >> Dev)
Cmd.batch [
Cmd.OfPromise.either
OfficeInterop.checkIfAnnotationTableIsPresent
()
(AnnotationTableExists >> ExcelInterop)
(GenericError >> Dev)
Cmd.OfPromise.either
OfficeInterop.syncContext
passthroughMessage
(fun _ -> ExcelInterop (InSync passthroughMessage))
(GenericError >> Dev)
]

| AnnotationTableExists exists ->
let nextState = {
currentState with
HasAnnotationTable = exists
}

nextState,Cmd.none

| InSync passthroughMessage ->
currentState,
Expand All @@ -81,11 +96,20 @@ let handleExcelInteropMsg (excelInteropMsg: ExcelInteropMsg) (currentState:Excel
(SyncContext >> ExcelInterop)
(GenericError >> Dev)

| AddColumn columnValue ->
| AddColumn (colName,format) ->
currentState,

Cmd.OfPromise.either
OfficeInterop.addAnnotationColumn
columnValue
colName
(fun _ -> (colName,format) |> FormatColumn |> ExcelInterop)
(GenericError >> Dev)

| FormatColumn (colName,format) ->
currentState,
Cmd.OfPromise.either
(OfficeInterop.changeTableColumnFormat colName)
format
(SyncContext >> ExcelInterop)
(GenericError >> Dev)

Expand All @@ -94,9 +118,18 @@ let handleExcelInteropMsg (excelInteropMsg: ExcelInteropMsg) (currentState:Excel
Cmd.OfPromise.either
OfficeInterop.createAnnotationTable
isDark
(SyncContext >> ExcelInterop)
(AnnotationtableCreated >> ExcelInterop)
(GenericError >> Dev)

| AnnotationtableCreated range ->
let nextState = {
currentState with
HasAnnotationTable = true
}

nextState,Cmd.ofMsg(range |> SyncContext |> ExcelInterop)


let handleSimpleTermSearchMsg (simpleTermSearchMsg: SimpleTermSearchMsg) (currentState:SimpleTermSearchState) : SimpleTermSearchState * Cmd<Msg> =
match simpleTermSearchMsg with
| SearchTermTextChange newTerm ->
Expand Down
12 changes: 8 additions & 4 deletions src/Client/Views/ActivityLogView.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ActivityLogView

open Fulma
open Fable.React
open Model

//TO-DO: Save log as tab seperated file
Expand All @@ -9,7 +10,10 @@ let activityLogComponent (model:Model) =
Table.table [
Table.IsFullWidth
Table.Props [ExcelColors.colorBackground model.SiteStyleState.ColorMode]
] (
model.DevState.Log
|> List.map LogItem.toTableRow
)
] [
tbody [] (
model.DevState.Log
|> List.map LogItem.toTableRow
)
]

10 changes: 9 additions & 1 deletion src/Client/Views/AddBuildingBlockView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,15 @@ let addBuildingBlockComponent (model:Model) (dispatch:Msg -> unit) =
Button.Props [Disabled true]
Button.IsFullWidth
//TODO: add fill support via Excel interop here
//Button.OnClick (fun _ -> model.TermSearchState.Simple.TermSearchText |> FillSelection |> ExcelInterop |> dispatch)
Button.OnClick (
let format =
match model.AddBuildingBlockState.UnitTerm with
| Some unit ->
sprintf "0.00 \"%s\"" unit.Name
| _ -> "0.00"
let colName = model.AddBuildingBlockState.CurrentBuildingBlock |> AnnotationBuildingBlock.toAnnotationTableHeader
fun _ -> (colName,format) |> AddColumn |> ExcelInterop |> dispatch
)

] [
str "Insert this annotation building block"
Expand Down

0 comments on commit 3256ba0

Please sign in to comment.