Skip to content

Commit

Permalink
Merge pull request #624 from nfdi4plants/Feature_Swate_EnableManualSe…
Browse files Browse the repository at this point in the history
…ttingsForAutosave

Implement manual autosave control
  • Loading branch information
Freymaurer authored Feb 12, 2025
2 parents e740ab6 + 80d4854 commit 530343b
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 127 deletions.
3 changes: 2 additions & 1 deletion src/Client/Client.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Compile Include="ARCtrl.Helper.fs" />
<Compile Include="Types.fs" />
<Compile Include="Helper.fs" />
<Compile Include="LocalStorage\AutosaveConfig.fs" />
<Compile Include="LocalStorage\SwateSearchConfig.fs" />
<Compile Include="LocalStorage\Widgets.fs" />
<Compile Include="LocalStorage\Darkmode.fs" />
Expand Down Expand Up @@ -98,7 +99,7 @@
<Compile Include="Pages\FilePicker\FilePickerView.fs" />
<Compile Include="Pages\Info\PrivacyPolicy.fs" />
<Compile Include="Pages\Info\InfoView.fs" />
<Compile Include="Pages\ActivityLog\ActivityLogView.fs" />
<Compile Include="Pages\Settings\ActivityLogView.fs" />
<Compile Include="Pages\Settings\SearchConfig.fs" />
<Compile Include="Pages\Settings\SettingsView.fs" />
<Compile Include="Pages\JsonExporter\JsonExporter.fs" />
Expand Down
11 changes: 10 additions & 1 deletion src/Client/Init.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open LocalHistory
open Model
open Messages
open Update
open LocalStorage.AutosaveConfig

let initialModel =
{
Expand All @@ -28,4 +29,12 @@ let initialModel =
// defines the initial state and initial command (= side-effect) of the application
let init (pageOpt: Routing.Route option) : Model * Cmd<Msg> =
let model, cmd = urlUpdate pageOpt initialModel
model, cmd

let autosaveConfig = getAutosaveConfiguration()

let newModel =
if autosaveConfig.IsSome && autosaveConfig.Value <> model.PersistentStorageState.Autosave then
{model with Model.PersistentStorageState.Autosave = autosaveConfig.Value}
else model

newModel, cmd
20 changes: 20 additions & 0 deletions src/Client/LocalStorage/AutosaveConfig.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

module LocalStorage.AutosaveConfig

open Browser

let [<Literal>] AutosaveConfig_Key = "AutosaveConfig"

let getAutosaveConfiguration() =
try
WebStorage.localStorage.getItem(AutosaveConfig_Key)
|> (fun item -> bool.Parse(item))
|> Some
with
| _ ->
WebStorage.localStorage.removeItem(AutosaveConfig_Key)
printfn "Could not find %s" AutosaveConfig_Key
None

let setAutosaveConfiguration(autosaveConfig: bool) =
WebStorage.localStorage.setItem(AutosaveConfig_Key, autosaveConfig.ToString())
25 changes: 14 additions & 11 deletions src/Client/LocalStorage/Darkmode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open Fable.Core.JsInterop

[<RequireQualifiedAccess>]
module private Attribute =

let getDataTheme() =
let v = Browser.Dom.document.documentElement.getAttribute("data-theme")
if isNull v then
Expand All @@ -17,6 +18,7 @@ module private Attribute =

[<RequireQualifiedAccess>]
module private BrowserSetting =

let getDefault() =
let m : bool = Browser.Dom.window?matchMedia("(prefers-color-scheme: dark)")?matches
if m then Dark else Light
Expand All @@ -38,7 +40,7 @@ module private LocalStorage =
|> DataTheme.ofString
|> Some
with
|_ ->
| _ ->
WebStorage.localStorage.removeItem(DataTheme_Key)
printfn "Could not find %s" DataTheme_Key
None
Expand All @@ -48,10 +50,10 @@ type DataTheme =
| Light
static member ofString (str: string) =
match str.ToLower() with
| "dark" -> Dark
| "light" | _ -> Light
| "dark" -> Dark
| "light" | _ -> Light

static member SET(theme:DataTheme) =
static member SET(theme: DataTheme) =
Attribute.setDataTheme <| string theme
LocalStorage.write <| theme // This helps remember

Expand All @@ -61,23 +63,24 @@ type DataTheme =
// check data theme attribute
let dataTheme = Attribute.getDataTheme()
match localStorage, dataTheme with
| _, Some dt -> dt // this value actually decides the theme via styles.scss
| Some dt, _ -> dt // this value is set by website but does not reflect actual styling directly
| _, _ -> BrowserSetting.getDefault() // if all fails we check for the browser setting
| _, Some dt -> dt // this value actually decides the theme via styles.scss
| Some dt, _ -> dt // this value is set by website but does not reflect actual styling directly
| _, _ -> BrowserSetting.getDefault() // if all fails we check for the browser setting

[<RequireQualifiedAccess>]
type State = {
Theme: DataTheme
Theme: DataTheme
SetTheme: State -> unit
} with
static member init() =
{
Theme = DataTheme.Light
SetTheme = fun (state) -> failwith "This is not implemented and serves as placeholder"
Theme = DataTheme.Light
SetTheme = fun _ -> failwith "This is not implemented and serves as placeholder"
}

member this.Update() =
let dt = DataTheme.GET()
DataTheme.SET dt
{this with Theme = dt}

let themeContext = React.createContext(name="Theme", defaultValue=LocalStorage.Darkmode.State.init())
let themeContext = React.createContext(name="Theme", defaultValue=LocalStorage.Darkmode.State.init())
3 changes: 1 addition & 2 deletions src/Client/LocalStorage/SwateSearchConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module SwateDefaultSearch =
try
let v = Browser.WebStorage.localStorage.getItem(KEY)
match v.ToLower() with
| "true" | "1" -> true
| "true" | "1" -> true
| "false" | "0" -> false
| _ -> true
with
Expand All @@ -42,4 +42,3 @@ module TIBSearch =
let Set(v: string []) =
let s = Json.serialize v
Browser.WebStorage.localStorage.setItem(KEY, s)

6 changes: 3 additions & 3 deletions src/Client/MainComponents/Cells.fs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ type Cell =
onBlur=onBlur,
onKeyDown=onKeyDown,
classNames=(Swate.Components.TermSearchStyle(!^"h-[35px] !rounded-none w-full !border-0")),
disableDefaultSearch = model.PersistentStorageState.DisableSwateDefaultSearch,
disableDefaultAllChildrenSearch = model.PersistentStorageState.DisableSwateDefaultSearch,
disableDefaultParentSearch = model.PersistentStorageState.DisableSwateDefaultSearch,
disableDefaultSearch = model.PersistentStorageState.IsDisabledSwateDefaultSearch,
disableDefaultAllChildrenSearch = model.PersistentStorageState.IsDisabledSwateDefaultSearch,
disableDefaultParentSearch = model.PersistentStorageState.IsDisabledSwateDefaultSearch,
termSearchQueries = model.PersistentStorageState.TIBQueries.TermSearch,
parentSearchQueries = model.PersistentStorageState.TIBQueries.ParentSearch,
allChildrenSearchQueries = model.PersistentStorageState.TIBQueries.AllChildrenSearch
Expand Down
47 changes: 24 additions & 23 deletions src/Client/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ type DevMsg =

module PersistentStorage =
type Msg =
| UpdateAppVersion of string
| UpdateSwateDefaultSearch of bool
| AddTIBSearchCatalogue of string
| RemoveTIBSearchCatalogue of string
| SetTIBSearchCatalogues of Set<string>
| UpdateAppVersion of string
| UpdateSwateDefaultSearch of bool
| AddTIBSearchCatalogue of string
| RemoveTIBSearchCatalogue of string
| SetTIBSearchCatalogues of Set<string>
| UpdateAutosave of bool

module PageState =

type Msg =
| UpdateShowSidebar of bool
| UpdateMainPage of MainPage
| UpdateMainPage of MainPage
| UpdateSidebarPage of SidebarPage

module FilePicker =
Expand Down Expand Up @@ -105,25 +106,25 @@ module History =
| UpdateHistoryPosition of int

type Msg =
| UpdateModel of Model
| DevMsg of DevMsg
| TermSearchMsg of TermSearch.Msg
| AdvancedSearchMsg of AdvancedSearch.Msg
| OfficeInteropMsg of OfficeInterop.Msg
| PersistentStorageMsg of PersistentStorage.Msg
| FilePickerMsg of FilePicker.Msg
| BuildingBlockMsg of BuildingBlock.Msg
| ProtocolMsg of Protocol.Msg
| DataAnnotatorMsg of DataAnnotator.Msg
| SpreadsheetMsg of Spreadsheet.Msg
| UpdateModel of Model
| DevMsg of DevMsg
| TermSearchMsg of TermSearch.Msg
| AdvancedSearchMsg of AdvancedSearch.Msg
| OfficeInteropMsg of OfficeInterop.Msg
| PersistentStorageMsg of PersistentStorage.Msg
| FilePickerMsg of FilePicker.Msg
| BuildingBlockMsg of BuildingBlock.Msg
| ProtocolMsg of Protocol.Msg
| DataAnnotatorMsg of DataAnnotator.Msg
| SpreadsheetMsg of Spreadsheet.Msg
/// This is used to forward Msg to SpreadsheetMsg/OfficeInterop
| InterfaceMsg of SpreadsheetInterface.Msg
| PageStateMsg of PageState.Msg
| Batch of seq<Messages.Msg>
| HistoryMsg of History.Msg
| UpdateModal of Model.ModalState.ModalTypes option
| InterfaceMsg of SpreadsheetInterface.Msg
| PageStateMsg of PageState.Msg
| Batch of seq<Messages.Msg>
| HistoryMsg of History.Msg
| UpdateModal of Model.ModalState.ModalTypes option
/// Top level msg to test specific api interactions, only for dev.
| Run of (unit -> unit)
| Run of (unit -> unit)
| TestMyAPI
| TestMyPostAPI
| DoNothing
75 changes: 39 additions & 36 deletions src/Client/Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ type LogItem =
| Error of (System.DateTime*string)
| Warning of (System.DateTime*string)

static member ofInteropLogginMsg (msg:InteropLogging.Msg) =
static member ofInteropLogginMsg (msg: InteropLogging.Msg) =
match msg.LogIdentifier with
| InteropLogging.Info -> Info (System.DateTime.UtcNow,msg.MessageTxt)
| InteropLogging.Debug -> Debug(System.DateTime.UtcNow,msg.MessageTxt)
| InteropLogging.Error -> Error(System.DateTime.UtcNow,msg.MessageTxt)
| InteropLogging.Warning -> Warning(System.DateTime.UtcNow,msg.MessageTxt)
| InteropLogging.Info -> Info (System.DateTime.UtcNow,msg.MessageTxt)
| InteropLogging.Debug -> Debug(System.DateTime.UtcNow,msg.MessageTxt)
| InteropLogging.Error -> Error(System.DateTime.UtcNow,msg.MessageTxt)
| InteropLogging.Warning -> Warning(System.DateTime.UtcNow,msg.MessageTxt)

static member private DebugCell = Html.td [prop.className "bg-info text-info-content font-semibold"; prop.text "Debug"]
static member private InfoCell = Html.td [prop.className "bg-primary text-primary-content font-semibold"; prop.text "Info"]
static member private ErrorCell = Html.td [prop.className "bg-error text-error-content font-semibold"; prop.text "ERROR"]
static member private WarningCell = Html.td [prop.className "bg-warning text-warning-content font-semibold"; prop.text "Warning"]
static member private DebugCell = Html.td [prop.className "bg-info text-info-content font-semibold"; prop.text "Debug"]
static member private InfoCell = Html.td [prop.className "bg-primary text-primary-content font-semibold"; prop.text "Info"]
static member private ErrorCell = Html.td [prop.className "bg-error text-error-content font-semibold"; prop.text "ERROR"]
static member private WarningCell = Html.td [prop.className "bg-warning text-warning-content font-semibold"; prop.text "Warning"]

static member toTableRow = function
| Debug (t, m) ->
Expand Down Expand Up @@ -49,13 +49,13 @@ type LogItem =
Html.td m
]

static member ofStringNow (level:string) (message: string) =
static member ofStringNow (level: string) (message: string) =
match level with
| "Debug"| "debug" -> Debug(System.DateTime.UtcNow,message)
| "Info" | "info" -> Info (System.DateTime.UtcNow,message)
| "Error" | "error" -> Error(System.DateTime.UtcNow,message)
| "Debug"| "debug" -> Debug(System.DateTime.UtcNow,message)
| "Info" | "info" -> Info (System.DateTime.UtcNow,message)
| "Error" | "error" -> Error(System.DateTime.UtcNow,message)
| "Warning" | "warning" -> Warning(System.DateTime.UtcNow,message)
| others -> Error(System.DateTime.UtcNow,sprintf "Swate found an unexpected log identifier: %s" others)
| others -> Error(System.DateTime.UtcNow,sprintf "Swate found an unexpected log identifier: %s" others)

module TermSearch =

Expand All @@ -81,17 +81,18 @@ type DevState = {
}

type PersistentStorageState = {
AppVersion : string
Host : Swatehost option
SwateDefaultSearch : bool
TIBSearchCatalogues : Set<string>

AppVersion : string
Host : Swatehost option
SwateDefaultSearch : bool
TIBSearchCatalogues : Set<string>
Autosave : bool
} with
static member init () = {
Host = Some Swatehost.Browser
AppVersion = ""
SwateDefaultSearch = true
TIBSearchCatalogues = Set.empty
Host = Some Swatehost.Browser
AppVersion = ""
SwateDefaultSearch = true
TIBSearchCatalogues = Set.empty
Autosave = true
}

member this.TIBQueries =
Expand All @@ -115,7 +116,9 @@ type PersistentStorageState = {
yield (n, query)
]
|}
member this.DisableSwateDefaultSearch = not this.SwateDefaultSearch

member this.IsDisabledSwateDefaultSearch = not this.SwateDefaultSearch

type PageState = {
SidebarPage : Routing.SidebarPage
MainPage: Routing.MainPage
Expand All @@ -124,17 +127,19 @@ type PageState = {
static member init () =
{
SidebarPage = SidebarPage.BuildingBlock
MainPage = MainPage.Default
MainPage = MainPage.Default
ShowSideBar = false
}

member this.IsHome =
match this.MainPage with
| MainPage.Default -> true
| _ -> false
| MainPage.Default -> true
| _ -> false

module FilePicker =

type Model = {
FileNames : (int*string) list
FileNames : (int*string) list
} with
static member init () = {
FileNames = []
Expand Down Expand Up @@ -174,15 +179,12 @@ module BuildingBlock =
}

type Model = {

HeaderCellType : CompositeHeaderDiscriminate
HeaderArg : U2<OntologyAnnotation,IOType> option
BodyCellType : CompositeCellDiscriminate
BodyArg : U2<string, OntologyAnnotation> option

} with
static member init () = {

HeaderCellType = CompositeHeaderDiscriminate.Parameter
HeaderArg = None
BodyCellType = CompositeCellDiscriminate.Term
Expand Down Expand Up @@ -216,6 +218,7 @@ module Protocol =
| All
| OnlyCurated
| Community of string

member this.ToStringRdb() =
match this with
| All -> "All"
Expand All @@ -224,13 +227,13 @@ module Protocol =

static member fromString(str: string) =
match str with
| "All" -> All
| "DataPLANT official" -> OnlyCurated
| anyElse -> Community anyElse
| "All" -> All
| "DataPLANT official" -> OnlyCurated
| anyElse -> Community anyElse

static member CommunityFromOrganisation(org: ARCtrl.Organisation) =
match org with
| ARCtrl.Organisation.DataPLANT -> None
| ARCtrl.Organisation.DataPLANT -> None
| ARCtrl.Organisation.Other name -> Some <| Community name

/// This model is used for both protocol insert and protocol search
Expand Down Expand Up @@ -259,7 +262,7 @@ type RequestBuildingBlockInfoStates =
match this with
| Inactive -> ""
| RequestExcelInformation -> "Check Columns"
| RequestDataBaseInformation -> "Search Database "
| RequestDataBaseInformation -> "Search Database"

type Model = {
///PageState
Expand Down
Loading

0 comments on commit 530343b

Please sign in to comment.