Skip to content

Commit

Permalink
Restore filepicker #362
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Feb 13, 2024
1 parent d8f4668 commit ec1dcd3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 42 deletions.
50 changes: 25 additions & 25 deletions src/Client/Pages/FilePicker/FilePickerView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,31 @@ let sortButton icon msg =
let fileSortElements (model:Messages.Model) dispatch =
Bulma.field.div [
Bulma.buttons [
Bulma.button.a [
prop.title "Copy to Clipboard"
prop.onClick(fun e ->
CustomComponents.ResponsiveFA.triggerResponsiveReturnEle "clipboard_filepicker"
let txt = model.FilePickerState.FileNames |> List.map snd |> String.concat System.Environment.NewLine
let textArea = Browser.Dom.document.createElement "textarea"
textArea?value <- txt
textArea?style?top <- "0"
textArea?style?left <- "0"
textArea?style?position <- "fixed"

Browser.Dom.document.body.appendChild textArea |> ignore

textArea.focus()
// Can't belive this actually worked
textArea?select()

let t = Browser.Dom.document.execCommand("copy")
Browser.Dom.document.body.removeChild(textArea) |> ignore
()
)
prop.children [
CustomComponents.ResponsiveFA.responsiveReturnEle "clipboard_filepicker" "fa-regular fa-clipboard" "fa-solid fa-check"
]
]
//Bulma.button.a [
// prop.title "Copy to Clipboard"
// prop.onClick(fun e ->
// CustomComponents.ResponsiveFA.triggerResponsiveReturnEle "clipboard_filepicker"
// let txt = model.FilePickerState.FileNames |> List.map snd |> String.concat System.Environment.NewLine
// let textArea = Browser.Dom.document.createElement "textarea"
// textArea?value <- txt
// textArea?style?top <- "0"
// textArea?style?left <- "0"
// textArea?style?position <- "fixed"

// Browser.Dom.document.body.appendChild textArea |> ignore

// textArea.focus()
// // Can't belive this actually worked
// textArea?select()

// let t = Browser.Dom.document.execCommand("copy")
// Browser.Dom.document.body.removeChild(textArea) |> ignore
// ()
// )
// prop.children [
// CustomComponents.ResponsiveFA.responsiveReturnEle "clipboard_filepicker" "fa-solid fa-copy" "fa-solid fa-check"
// ]
//]

Bulma.buttons [
Bulma.buttons.hasAddons
Expand Down
22 changes: 10 additions & 12 deletions src/Client/SidebarComponents/ResponsiveFA.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,16 @@ let triggerResponsiveReturnEle id =
let responsiveReturnEle id (fa: string) (faToggled: string) =
let notTriggeredId = createNonTriggeredId id
let triggeredId = createTriggeredId id
div [Style [
Position PositionOptions.Relative
]] [
Bulma.icon [
Html.i [
prop.style [
style.position.absolute
style.top 0
style.left 0
style.display.block
style.custom("transition", "opacity 0.25s, transform 0.25s")
style.opacity 1
]
style.position.absolute
//style.top 0
//style.left 0
style.display.block
style.custom("transition", "opacity 0.25s, transform 0.25s")
style.opacity 1
]
prop.id notTriggeredId
prop.onTransitionEnd (fun e ->
Fable.Core.JS.setTimeout (fun () ->
Expand All @@ -89,8 +87,8 @@ let responsiveReturnEle id (fa: string) (faToggled: string) =
Html.i [
prop.style [
style.position.absolute
style.top 0
style.left 0
//style.top 0
//style.left 0
style.display.block
style.custom("transition", "opacity 0.25s, transform 0.25s")
style.opacity 0
Expand Down
1 change: 1 addition & 0 deletions src/Client/States/Spreadsheet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Model = {
type Msg =
// <--> UI <-->
| UpdateCell of (int*int) * CompositeCell
| UpdateCells of ((int*int) * CompositeCell) []
| UpdateHeader of columIndex: int * CompositeHeader
| UpdateActiveView of ActiveView
| UpdateSelectedCells of Set<int*int>
Expand Down
20 changes: 15 additions & 5 deletions src/Client/Update/InterfaceUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,23 @@ module Interface =
| _ -> failwith "not implemented"
| InsertFileNames fileNames ->
match host with
| Some Swatehost.Excel | Some Swatehost.ARCitect ->
| Some Swatehost.Excel ->
let cmd = OfficeInterop.InsertFileNames fileNames |> OfficeInteropMsg |> Cmd.ofMsg
model, cmd
//| Swatehost.Browser ->
// let arr = fileNames |> List.toArray |> Array.map (fun x -> TermTypes.TermMinimal.create x "")
// let cmd = Spreadsheet.InsertOntologyTerms arr |> SpreadsheetMsg |> Cmd.ofMsg
// model, cmd
| Some Swatehost.Browser | Some Swatehost.ARCitect ->
if model.SpreadsheetModel.SelectedCells.IsEmpty then
model, Cmd.ofMsg (DevMsg.GenericError (Cmd.none, exn("No cell(s) selected.")) |> DevMsg)
else
let columnIndex, rowIndex = model.SpreadsheetModel.SelectedCells.MinimumElement
let mutable rowIndex = rowIndex
let cells = [|
for name in fileNames do
let cell = ARCtrl.ISA.CompositeCell.createFreeText name
(columnIndex, rowIndex), cell
rowIndex <- rowIndex + 1
|]
let cmd = Spreadsheet.UpdateCells cells |> SpreadsheetMsg |> Cmd.ofMsg
model, cmd
| _ -> failwith "not implemented"
| RemoveBuildingBlock ->
match host with
Expand Down
5 changes: 5 additions & 0 deletions src/Client/Update/SpreadsheetUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ module Spreadsheet =
state.ActiveTable.UpdateCellAt(fst index,snd index, cell)
{state with ArcFile = state.ArcFile}
nextState, model, Cmd.none
| UpdateCells arr ->
let nextState =
state.ActiveTable.SetCellsAt arr
{state with ArcFile = state.ArcFile}
nextState, model, Cmd.none
| UpdateHeader (index, header) ->
let nextState =
state.ActiveTable.UpdateHeader(index, header)
Expand Down
16 changes: 16 additions & 0 deletions src/Shared/ARCtrl.Helper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ module ARCtrlHelper =
module Extensions =

open ARCtrl.Template
open ArcTableAux

type ArcTable with
member this.SetCellAt(columnIndex: int, rowIndex: int, cell: CompositeCell) =
SanityChecks.validateColumn <| CompositeColumn.create(this.Headers.[columnIndex],[|cell|])
Unchecked.setCellAt(columnIndex, rowIndex,cell) this.Values
Unchecked.fillMissingCells this.Headers this.Values

member this.SetCellsAt (cells: ((int*int)*CompositeCell) []) =
let columns = cells |> Array.groupBy (fun (index, cell) -> fst index)
for columnIndex, items in columns do
SanityChecks.validateColumn <| CompositeColumn.create(this.Headers.[columnIndex], items |> Array.map snd)
for index, cell in cells do
Unchecked.setCellAt(fst index, snd index, cell) this.Values
Unchecked.fillMissingCells this.Headers this.Values


type Template with
member this.FileName
Expand Down

0 comments on commit ec1dcd3

Please sign in to comment.