Skip to content

Commit

Permalink
Add option to create pointer json template (Issue #129).
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Mar 4, 2021
1 parent 137cc54 commit 66fb577
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 43 deletions.
6 changes: 6 additions & 0 deletions src/Client/Client.fs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ let view (model : Model) (dispatch : Msg -> unit) =
] [
//Text.p [] [str ""]
]
| Routing.Route.SettingsDataStewards ->
BaseView.baseViewComponent model dispatch [
SettingsDataStewardView.settingsDataStewardViewComponent model dispatch
] [
//Text.p [] [str ""]
]

| Routing.Route.Info ->
BaseView.baseViewComponent model dispatch [
Expand Down
1 change: 1 addition & 0 deletions src/Client/Client.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="Views\ActivityLogView.fs" />
<Compile Include="Views\SettingsView.fs" />
<Compile Include="Views\SettingsXmlView.fs" />
<Compile Include="Views\SettingsDataStewardView.fs" />
<Compile Include="Views\NotFoundView.fs" />
<Compile Include="Client.fs" />
</ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions src/Client/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type ExcelInteropMsg =
| InsertFileNames of fileNameList:string list
// Show Details to selected BuildingBlock
| GetSelectedBuildingBlockSearchTerms
//
| CreatePointerJson
// Development
| TryExcel
| TryExcel2
Expand Down Expand Up @@ -202,6 +204,10 @@ type SettingXmlMsg =
| ReassignCustomXmlRequest of prevXml:OfficeInterop.Types.Xml.XmlTypes * newXml:OfficeInterop.Types.Xml.XmlTypes
| RemoveCustomXmlRequest of xml: OfficeInterop.Types.Xml.XmlTypes

type SettingDataStewardMsg =
// Client
| UpdatePointerJson of string option

type TopLevelMsg =
| CloseSuggestions

Expand All @@ -221,6 +227,7 @@ type Msg =
| ProtocolInsert of ProtocolInsertMsg
| BuildingBlockDetails of BuildingBlockDetailsMsg
| SettingXmlMsg of SettingXmlMsg
| SettingDataStewardMsg of SettingDataStewardMsg
| TopLevelMsg of TopLevelMsg
| UpdatePageState of Routing.Route option
| Batch of seq<Msg>
Expand Down
38 changes: 24 additions & 14 deletions src/Client/Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -457,51 +457,60 @@ type SettingsXmlState = {
ValidationXmls = [||]
}

type SettingsDataStewardState = {
PointerJson : string option
} with
static member init () = {
PointerJson = None
}

type Model = {

//PageState
///PageState
PageState : PageState

//Data that needs to be persistent once loaded
///Data that needs to be persistent once loaded
PersistentStorageState : PersistentStorageState

//Debouncing
///Debouncing
DebouncerState : Debouncer.State

//Error handling, Logging, etc.
///Error handling, Logging, etc.
DevState : DevState

//Site Meta Options (Styling etc)
///Site Meta Options (Styling etc)
SiteStyleState : SiteStyleState

//States regarding term search
///States regarding term search
TermSearchState : TermSearchState

AdvancedSearchState : AdvancedSearchState

//Use this in the future to model excel stuff like table data
///Use this in the future to model excel stuff like table data
ExcelState : ExcelState

//Use this to log Api calls and maybe handle them better
///Use this to log Api calls and maybe handle them better
ApiState : ApiState

//States regarding File picker functionality
///States regarding File picker functionality
FilePickerState : FilePickerState

ProtocolInsertState : ProtocolInsertState

//Insert annotation columns
///Insert annotation columns
AddBuildingBlockState : AddBuildingBlockState

//Create Validation scheme for Table
///Create Validation scheme for Table
ValidationState : ValidationState

//Used to show selected building block information
///Used to show selected building block information
BuildingBlockDetailsState : BuildingBlockDetailsState

//Used to manage all xml settings
SettingsXmlState : SettingsXmlState
///Used to manage all custom xml settings
SettingsXmlState : SettingsXmlState

///Used to manage functions specifically for data stewards
SettingsDataStewardState : SettingsDataStewardState
}

let initializeModel (pageOpt: Route option) = {
Expand All @@ -520,4 +529,5 @@ let initializeModel (pageOpt: Route option) = {
ProtocolInsertState = ProtocolInsertState .init ()
BuildingBlockDetailsState = BuildingBlockDetailsState .init ()
SettingsXmlState = SettingsXmlState .init ()
SettingsDataStewardState = SettingsDataStewardState .init ()
}
37 changes: 37 additions & 0 deletions src/Client/OfficeInterop/OfficeInterop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1781,4 +1781,41 @@ let updateAnnotationTableByXmlType(prevXmlType:XmlTypes, nextXmlType:XmlTypes) =

return (sprintf "Updated %s BY %s" prevXmlType.toStringRdb nextXmlType.toStringRdb)
}
)

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

let activeSheet = context.workbook.worksheets.getActiveWorksheet().load(propertyNames = U2.Case2 (ResizeArray[|"name"|]))

promise {
let! annotationTable = getActiveAnnotationTableName()
let workbook = context.workbook.load(U2.Case1 "name")

let! json = context.sync().``then``(fun e ->
[
"name" , Fable.SimpleJson.JString ""
"version" , Fable.SimpleJson.JString ""
"author" , Fable.SimpleJson.JString ""
"description" , Fable.SimpleJson.JString ""
"docslink" , Fable.SimpleJson.JString ""
"tags" , Fable.SimpleJson.JArray []
"Workbook" , Fable.SimpleJson.JString workbook.name
"Worksheet" , Fable.SimpleJson.JString activeSheet.name
"Table" , Fable.SimpleJson.JString annotationTable
]
|> List.map (fun x ->
[x]
|> Map.ofList
|> Fable.SimpleJson.JObject
|> Fable.SimpleJson.SimpleJson.toString
|> fun x -> " " + x.Replace("{","").Replace("}","")
)
|> String.concat (sprintf ",%s" System.Environment.NewLine)
|> fun jsonbody ->
sprintf "{%s%s%s}" System.Environment.NewLine jsonbody System.Environment.NewLine
)

return json
}
)
46 changes: 17 additions & 29 deletions src/Client/Routing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Route =
| ActivityLog
| Settings
| SettingsXml
| SettingsDataStewards
| NotFound

static member toRouteUrl (route:Route) =
Expand All @@ -32,24 +33,10 @@ type Route =
| Route.Info -> "/#Info"
| Route.ActivityLog -> "/#ActivityLog"
| Route.Settings -> "/#Settings"
| Route.SettingsXml -> "/#SettingsXml"
| Route.SettingsXml -> "/#Settings/Xml"
| Route.SettingsDataStewards-> "/#Settings/DataStewards"
| Route.NotFound -> "/#NotFound"

static member toString (route:Route) =
match route with
| Route.Home -> ""
| Route.AddBuildingBlock -> "AddBuildingBlock"
| Route.TermSearch -> "TermSearch"
| Route.Validation -> "Validation"
| Route.ProtocolInsert -> "ProtocolInsert"
| Route.ProtocolSearch -> "ProtocolSearch"
| Route.Info -> "Info"
| Route.FilePicker -> "FilePicker"
| Route.ActivityLog -> "ActivityLog"
| Route.Settings -> "Settings"
| Route.SettingsXml -> "SettingsXml"
| Route.NotFound -> "NotFound"

member this.toStringRdbl =
match this with
| Route.Home -> ""
Expand All @@ -63,9 +50,9 @@ type Route =
| Route.ActivityLog -> "Activity Log"
| Route.Settings -> "Settings"
| Route.SettingsXml -> "Xml Settings"
| Route.SettingsDataStewards-> "Settings for Data Stewards"
| Route.NotFound -> "NotFound"


static member toIcon (p: Route)=
let createElem icons name =
Fable.React.Standard.span [
Expand Down Expand Up @@ -99,18 +86,19 @@ module Routing =
/// The URL is turned into a Result.
let route : Parser<Route -> Route,_> =
oneOf [
map Route.Home (s "")
map Route.TermSearch (s "TermSearch")
map Route.AddBuildingBlock (s "AddBuildingBlock")
map Route.Validation (s "Validation")
map Route.FilePicker (s "FilePicker")
map Route.Info (s "Info")
map Route.ProtocolInsert (s "ProtocolInsert")
map Route.ProtocolSearch (s "ProtocolSearch")
map Route.ActivityLog (s "ActivityLog")
map Route.Settings (s "Settings")
map Route.SettingsXml (s "SettingsXml")
map Route.NotFound (s "NotFound")
map Route.Home (s "")
map Route.TermSearch (s "TermSearch")
map Route.AddBuildingBlock (s "AddBuildingBlock")
map Route.Validation (s "Validation")
map Route.FilePicker (s "FilePicker")
map Route.Info (s "Info")
map Route.ProtocolInsert (s "ProtocolInsert")
map Route.ProtocolSearch (s "ProtocolSearch")
map Route.ActivityLog (s "ActivityLog")
map Route.Settings (s "Settings")
map Route.SettingsXml (s "Settings" </> s "Xml")
map Route.SettingsDataStewards (s "Settings" </> s "DataStewards")
map Route.NotFound (s "NotFound")
]

//this would be the way to got if we would use push based routing, but i decided to use hash based routing. Ill leave this here for now as a note.
Expand Down
29 changes: 29 additions & 0 deletions src/Client/Update.fs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ let handleExcelInteropMsg (excelInteropMsg: ExcelInteropMsg) (currentState:Excel
)
let cmd2 = Cmd.ofMsg (UpdateCurrentRequestState RequestBuildingBlockInfoStates.RequestExcelInformation |> BuildingBlockDetails)
currentState, Cmd.batch [cmd;cmd2]
//
| CreatePointerJson ->
let cmd =
Cmd.OfPromise.either
OfficeInterop.createPointerJson
()
(fun x -> Some x |> UpdatePointerJson |> SettingDataStewardMsg)
(GenericError >> Dev)
currentState, cmd

/// DEV
| TryExcel ->
Expand Down Expand Up @@ -1665,6 +1674,16 @@ let handleSettingXmlMsg (msg:SettingXmlMsg) (currentState: SettingsXmlState) : S
(GenericError >> Dev)
currentState, cmd

let handleSettingDataStewardMsg (topLevelMsg:SettingDataStewardMsg) (currentState: SettingsDataStewardState) : SettingsDataStewardState * Cmd<Msg> =
match topLevelMsg with
// Client
| UpdatePointerJson nextPointerJson ->
let nextState = {
currentState with
PointerJson = nextPointerJson
}
nextState, Cmd.none

let handleTopLevelMsg (topLevelMsg:TopLevelMsg) (currentModel: Model) : Model * Cmd<Msg> =
match topLevelMsg with
// Client
Expand Down Expand Up @@ -1889,6 +1908,16 @@ let update (msg : Msg) (currentModel : Model) : Model * Cmd<Msg> =
}
nextModel, nextCmd

| SettingDataStewardMsg msg ->
let nextState, nextCmd =
currentModel.SettingsDataStewardState
|> handleSettingDataStewardMsg msg
let nextModel = {
currentModel with
SettingsDataStewardState = nextState
}
nextModel, nextCmd

| TopLevelMsg topLevelMsg ->
let nextModel, nextCmd =
handleTopLevelMsg topLevelMsg currentModel
Expand Down
Loading

0 comments on commit 66fb577

Please sign in to comment.