Skip to content

Commit

Permalink
Add core functionality to File Picker (Issue #13).
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Dec 7, 2020
1 parent 2498c0b commit 6cb6ebf
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/Client/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type ExcelInteropMsg =
| FillHiddenColsRequest of activeAnnotationTable:TryFindAnnoTableResult
| FillHiddenColumns of tableName:string*InsertTerm []
| UpdateFillHiddenColsState of FillHiddenColsState
//
| InsertFileNames of activeAnnotationTable:TryFindAnnoTableResult*fileNameList:string list
// Development
| TryExcel
| TryExcel2
Expand Down
45 changes: 41 additions & 4 deletions src/Client/OfficeInterop/OfficeInterop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ open Fable.Core

let exampleExcelFunction () =
Excel.run(fun context ->

context.sync().
``then``(fun _ ->
sprintf "Current Event Handlers: %A" EventHandlerStates.adaptHiddenColsHandlerList
context.sync()
.``then``( fun _ ->
sprintf "Test output"
)
)

Expand Down Expand Up @@ -818,6 +818,43 @@ let getInsertTermsToFillHiddenCols (annotationTable') =
)
)

let insertFileNamesFromFilePicker (annotationTable, fileNameList:string list) =
Excel.run(fun context ->
let sheet = context.workbook.worksheets.getActiveWorksheet()
//let annotationTable = sheet.tables.getItem(annotationTable)
//let annoRange = annotationTable.getDataBodyRange()
//let _ = annoRange.load(U2.Case2 (ResizeArray(["address";"values";"columnIndex"; "columnCount"])))
let range = context.workbook.getSelectedRange()
let _ = range.load(U2.Case2 (ResizeArray(["address";"values";"columnIndex"; "columnCount"])))
//let nextColsRange = range.getColumnsAfter 2.
//let _ = nextColsRange.load(U2.Case2 (ResizeArray(["address";"values";"columnIndex";"columnCount"])))

let r = context.runtime.load(U2.Case1 "enableEvents")

//sync with proxy objects after loading values from excel
context.sync().``then``( fun _ ->
if range.columnCount > 1. then failwith "Cannot insert Terms in more than one column at a time."

r.enableEvents <- false

let newVals = ResizeArray([
for rowInd in 0 .. range.values.Count-1 do
let tmp =
range.values.[rowInd] |> Seq.map (
fun col ->
let fileName = if fileNameList.Length-1 < rowInd then None else List.item rowInd fileNameList |> box |> Some
fileName
)
ResizeArray(tmp)
])

range.values <- newVals
r.enableEvents <- true
//sprintf "%s filled with %s; ExtraCols: %s" range.address v nextColsRange.address
sprintf "%A, %A" range.values.Count newVals
)
)

let fillHiddenColsByInsertTerm (annotationTable,insertTerms:InsertTerm []) =
Excel.run(fun context ->

Expand Down
15 changes: 13 additions & 2 deletions src/Client/Update.fs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,20 @@ let handleExcelInteropMsg (excelInteropMsg: ExcelInteropMsg) (currentState:Excel
}
nextState, Cmd.none
//
| InsertFileNames (activeTableNameRes,fileNameList) ->
let nextState = currentState
let cmd name =
Cmd.OfPromise.either
OfficeInterop.insertFileNamesFromFilePicker
(name, fileNameList)
((fun x ->
("Debug",x) |> GenericLog) >> Dev
)
(GenericError >> Dev)
let cmd = matchActiveTableResToMsg activeTableNameRes cmd
nextState, cmd


| TryExcel ->
| TryExcel ->
let nextState = currentState
let cmd =
Cmd.OfPromise.either
Expand Down
3 changes: 2 additions & 1 deletion src/Client/Views/ActivityLogView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ let activityLogComponent (model:Model) dispatch =
//Button.button [
// Button.Color Color.IsInfo
// Button.IsFullWidth
// Button.OnClick (fun e -> TryExcel |> ExcelInterop |> dispatch )
// Button.OnClick (fun e ->
// (fun tableName -> TryExcel (tableName, model.FilePickerState.FileNames))|> PipeActiveAnnotationTable |> ExcelInterop |> dispatch )
// Button.Props [Style [MarginBottom "1rem"]]
//] [
// str "Try Excel"
Expand Down
18 changes: 9 additions & 9 deletions src/Client/Views/BaseView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ let baseViewComponent (model: Model) (dispatch: Msg -> unit) (bodyChildren: Reac
Content.Props [ExcelColors.colorControl model.SiteStyleState.ColorMode]
] [
yield! footerChildren
Button.button [
Button.OnClick (fun e ->
let e = Browser.Dom.document.getElementById("BlockNameSearch")
let content = e.innerHTML
e.innerHTML <- content
)
][
str "Test"
]
//Button.button [
// Button.OnClick (fun e ->
// let e = Browser.Dom.document.getElementById("BlockNameSearch")
// let content = e.innerHTML
// e.innerHTML <- content
// )
//][
// str "Test"
//]
]
]
]
Expand Down
17 changes: 17 additions & 0 deletions src/Client/Views/FilePickerView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,22 @@ let filePickerComponent (model:Model) (dispatch:Msg -> unit) =
Table.table [Table.IsFullWidth] [
tbody [] (createFileList model dispatch)
]
Button.button [
Button.IsFullWidth
if model.FilePickerState.FileNames |> List.isEmpty then
yield! [
Button.Disabled true
Button.IsActive false
Button.Color Color.IsDanger
]
else
Button.Color Color.IsSuccess
Button.OnClick (fun e ->
(fun tableName -> InsertFileNames (tableName, model.FilePickerState.FileNames)) |> PipeActiveAnnotationTable |> ExcelInterop |> dispatch
)

][
str "Insert File Names"
]

]

0 comments on commit 6cb6ebf

Please sign in to comment.