Skip to content

Commit

Permalink
fsprojects#126: Added tests back and starting to implement synchroniz…
Browse files Browse the repository at this point in the history
…ation between backend and front-end
  • Loading branch information
Peter Rosconi committed Jan 16, 2019
1 parent 6eea8aa commit 1ccb15d
Show file tree
Hide file tree
Showing 18 changed files with 270 additions and 35 deletions.
12 changes: 12 additions & 0 deletions IfSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{3C993D34
ProjectSection(SolutionItems) = preProject
build.cmd = build.cmd
build.fsx = build.fsx
paket.dependencies = paket.dependencies
paket.lock = paket.lock
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ipython-profile", "ipython-profile", "{F5A3E866-86FB-44AD-9ED1-DB65D6EB0058}"
Expand Down Expand Up @@ -40,6 +42,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "IfSharp", "src\IfSharp\IfSh
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "IfSharp.Widgets", "src\IfSharp.Widgets\IfSharp.Widgets.fsproj", "{264A3F75-98C9-4B30-BA57-C54C16087C87}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "IfSharp.Kernel.Tests", "tests\IfSharp.Kernel.Tests\IfSharp.Kernel.Tests.fsproj", "{52627028-50B5-427F-BDDB-9DEADB72E7D6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +76,14 @@ Global
{264A3F75-98C9-4B30-BA57-C54C16087C87}.Release|Any CPU.Build.0 = Release|Any CPU
{264A3F75-98C9-4B30-BA57-C54C16087C87}.Release|x64.ActiveCfg = Release|x64
{264A3F75-98C9-4B30-BA57-C54C16087C87}.Release|x64.Build.0 = Release|x64
{52627028-50B5-427F-BDDB-9DEADB72E7D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52627028-50B5-427F-BDDB-9DEADB72E7D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52627028-50B5-427F-BDDB-9DEADB72E7D6}.Debug|x64.ActiveCfg = Debug|x64
{52627028-50B5-427F-BDDB-9DEADB72E7D6}.Debug|x64.Build.0 = Debug|x64
{52627028-50B5-427F-BDDB-9DEADB72E7D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52627028-50B5-427F-BDDB-9DEADB72E7D6}.Release|Any CPU.Build.0 = Release|Any CPU
{52627028-50B5-427F-BDDB-9DEADB72E7D6}.Release|x64.ActiveCfg = Release|x64
{52627028-50B5-427F-BDDB-9DEADB72E7D6}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ nuget Newtonsoft.Json ~> 10.0.3
nuget FAKE >= 4.58.6
nuget xunit 2.1
nuget xunit.runner.console 2.1
nuget xunit.runner.visualstudio
nuget Paket.Core ~> 5.194.0
nuget Trinet.Core.IO.Ntfs
nuget PropertyChanged.Fody

#https://github.com/dotnet/corefx/issues/19914
# nuget System.Net.Http 4.3.1
4 changes: 4 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ NUGET
FSharp.Core (>= 4.0.1.7-alpha)
NETStandard.Library (>= 1.6)
FAKE (5.8.4)
Fody (3.3.5)
FSharp.Compiler.Service (25.0.1)
FSharp.Core (>= 4.1.18)
System.Collections.Immutable (>= 1.5)
Expand All @@ -27,6 +28,8 @@ NUGET
FSharp.Core (> 4.3)
Mono.Cecil (>= 0.10.0-beta6)
Newtonsoft.Json
PropertyChanged.Fody (2.6)
Fody (>= 3.3.2)
System.Collections.Immutable (1.5)
System.Reflection.Metadata (1.6)
System.Collections.Immutable (>= 1.5)
Expand All @@ -45,3 +48,4 @@ NUGET
xunit.extensibility.execution (2.1)
xunit.extensibility.core (2.1)
xunit.runner.console (2.1)
xunit.runner.visualstudio (2.4.1)
5 changes: 4 additions & 1 deletion src/IfSharp.Kernel/Kernel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,7 @@ type IfSharpKernel(connectionInformation : ConnectionInformation) =

//Async.Start (async { doHeartbeat() } )
Async.Start (async { doShell() } )
Async.Start (async { doControl() } )
Async.Start (async { doControl() } )

/// Sends an update
member __.SendWidgetUpdate w = sendWidget w
3 changes: 3 additions & 0 deletions src/IfSharp.Kernel/Printers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type IWidget =
type IWidgetCollection =
abstract member GetChildren : unit -> IWidget[]

type IKernel =
abstract member SendWidgetUpdate : IWidget -> unit

type WidgetDataDTO =
{
buffer_paths: string[]
Expand Down
3 changes: 0 additions & 3 deletions src/IfSharp.Widgets/Color.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace IfSharp.Widgets

open IfSharp.Kernel
open Newtonsoft.Json

type ColorPicker() =
inherit DOMWidget(modelName = "ColorPickerModel", viewName = "ColorPickerView")
member val value = "" with get,set // Color('black', help="The color value.").tag(sync=True)
Expand Down
4 changes: 4 additions & 0 deletions src/IfSharp.Widgets/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>
54 changes: 54 additions & 0 deletions src/IfSharp.Widgets/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
14 changes: 14 additions & 0 deletions src/IfSharp.Widgets/IfSharp.Widgets.fsproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\PropertyChanged.Fody\build\PropertyChanged.Fody.props" Condition="Exists('..\..\packages\PropertyChanged.Fody\build\PropertyChanged.Fody.props')" Label="Paket" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -82,6 +83,7 @@
<Compile Include="Date.fs" />
<Compile Include="SelectionContainer.fs" />
<None Include="paket.references" />
<Content Include="FodyWeavers.xml" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Compiler.Interactive.Settings">
Expand Down Expand Up @@ -122,4 +124,16 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.7.2'">
<ItemGroup>
<Reference Include="PropertyChanged">
<HintPath>..\..\packages\PropertyChanged.Fody\lib\net452\PropertyChanged.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="..\..\packages\Fody\build\Fody.targets" Condition="Exists('..\..\packages\Fody\build\Fody.targets')" Label="Paket" />
</Project>
32 changes: 25 additions & 7 deletions src/IfSharp.Widgets/Widgets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Internals =
)

open Internals
open System.ComponentModel

/// A serializer that only supports writing instances of IWidget such that the notebook
/// can link the values together in the UI
Expand Down Expand Up @@ -115,6 +116,7 @@ type ButtonStyleSerializer() =
type Widget(modelName: string, viewName: string, ?modelModule, ?modelModuleVersion, ?viewModule, ?viewModuleVersion) as this =

let domClasses = ResizeArray<_>()
let ev = new Event<_,_>()
let key = WidgetManager.Register(this)

member val comm_id = key
Expand All @@ -134,6 +136,12 @@ type Widget(modelName: string, viewName: string, ?modelModule, ?modelModuleVersi

member __.RemoveClass(className) = domClasses.Remove className

member this.SendUpdate() =
App.Kernel |> Option.iter (fun k -> k.SendWidgetUpdate this)

[<JsonIgnore>]
member __.PropertyChanged = ev.Publish

interface IWidget with

member __.Key = key
Expand All @@ -145,6 +153,11 @@ type Widget(modelName: string, viewName: string, ?modelModule, ?modelModuleVersi
|> Seq.cast<IWidget>
|> Seq.toArray

interface INotifyPropertyChanged with

[<CLIEvent>]
member __.PropertyChanged = ev.Publish

/// The WidgetManager contains an in-memory dictionary of all instances of Widget that
/// have been creates in order to keep track of UI element in the notebook
and WidgetManager() =
Expand Down Expand Up @@ -257,13 +270,20 @@ type DOMWidget(modelName, viewName, ?modelModule, ?modelModuleVersion, ?viewModu
[<JsonConverter(typeof<WidgetSerializer>)>]
member val style = DescriptionStyle() with get, set

type ValueWidget<'t>(modelName, viewName) =
inherit DOMWidget(modelName, viewName)
member val value : 't = Unchecked.defaultof<'t> with get,set

member this.OnvalueChanged() =
stdout.WriteLine("OnvalueChanged")
this.SendUpdate()

type Html(?value) =
inherit DOMWidget(modelName = "HTMLModel", viewName = "HTMLView")
member val value = defaultArg value "" with get,set

type IntSlider() =
inherit DOMWidget(modelName = "IntSliderModel", viewName = "IntSliderView")
member val value = 7 with get,set
inherit ValueWidget<int>(modelName = "IntSliderModel", viewName = "IntSliderView")
member val min = 0 with get,set
member val max = 10 with get,set
member val step = 1 with get,set
Expand All @@ -283,8 +303,7 @@ type IntSlider() =
// indent : {True,False}
// indent the control to align with other controls with a description. The style.description_width attribute controls this width for consistence with other controls.
type Checkbox() =
inherit DOMWidget(modelName = "CheckboxModel", viewName = "CheckboxView")
member val value = false with get,set // Bool(False, help="Bool value").tag(sync=True)
inherit ValueWidget<bool>(modelName = "CheckboxModel", viewName = "CheckboxView")
member val disabled = false with get,set // Bool(False, help="Enable or disable user changes.").tag(sync=True)
member val indent = false with get,set // Bool(True, help="Indent the control to align with other controls with a description.").tag(sync=True)

Expand All @@ -300,7 +319,7 @@ type Checkbox() =
/// icon: str
/// font-awesome icon name
type ToggleButton() =
inherit DOMWidget(modelName = "ToggleButtonModel", viewName = "ToggleButtonView")
inherit ValueWidget<bool>(modelName = "ToggleButtonModel", viewName = "ToggleButtonView")

member val value = false with get,set
member val tooltip = "" with get,set
Expand All @@ -315,7 +334,6 @@ type ToggleButton() =
// value: {True,False}
// value of the Valid widget
type Valid() =
inherit DOMWidget(modelName = "ValidModel", viewName = "ValidView")
member val value = false with get,set // Bool(False, help="Bool value").tag(sync=True)
inherit ValueWidget<bool>(modelName = "ValidModel", viewName = "ValidView")
member val disabled = false with get,set // Bool(False, help="Enable or disable user changes.").tag(sync=True)
member val readout = "" with get,set // Unicode('Invalid', help="Message displayed when the value is False").tag(sync=True)
3 changes: 2 additions & 1 deletion src/IfSharp.Widgets/paket.references
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FSharp.Core
Newtonsoft.JSON
Newtonsoft.JSON
PropertyChanged.Fody
6 changes: 5 additions & 1 deletion src/IfSharp/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
Expand Down Expand Up @@ -67,6 +66,11 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="PropertyChanged" publicKeyToken="ee3ee20bcf148ddd" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
Expand Down
11 changes: 0 additions & 11 deletions tests/IfSharp.Kernel.Tests/ExampleTest.fs

This file was deleted.

33 changes: 27 additions & 6 deletions tests/IfSharp.Kernel.Tests/IfSharp.Kernel.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<RootNamespace>IfSharp.Kernel.Tests</RootNamespace>
<AssemblyName>IfSharp.Kernel.Tests</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.1.0</TargetFSharpCoreVersion>
<Name>IfSharp.Kernel.Tests</Name>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
Expand Down Expand Up @@ -73,6 +73,14 @@
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.7.2'">
<PropertyGroup>
<__paket__xunit_runner_visualstudio_props>net20\xunit.runner.visualstudio</__paket__xunit_runner_visualstudio_props>
</PropertyGroup>
</When>
</Choose>
<Import Project="..\..\packages\xunit.runner.visualstudio\build\$(__paket__xunit_runner_visualstudio_props).props" Condition="Exists('..\..\packages\xunit.runner.visualstudio\build\$(__paket__xunit_runner_visualstudio_props).props')" Label="Paket" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.7.2'">
<PropertyGroup>
Expand All @@ -87,26 +95,28 @@
<Target Name="AfterBuild">
</Target>
-->
<Import Project="..\..\.paket\paket.targets" />
<ItemGroup>
<Compile Include="ExampleTest.fs" />
<None Include="Scratch.fsx" />
<Content Include="paket.references" />
<Content Include="app.config" />
<Compile Include="WidgetTests.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\IfSharp.Kernel\IfSharp.Kernel.fsproj">
<Name>IfSharp.Kernel</Name>
<Project>{2fe619b3-4756-4285-b31f-232607f62d78}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\src\IfSharp.Widgets\IfSharp.Widgets.fsproj">
<Name>IfSharp.Widgets</Name>
<Project>{264a3f75-98c9-4b30-ba57-c54c16087c87}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<Import Project="..\..\.paket\paket.targets" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.7.2'">
<ItemGroup>
Expand Down Expand Up @@ -174,6 +184,17 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.7.2'">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.7.2'">
<ItemGroup>
Expand Down
Loading

0 comments on commit 1ccb15d

Please sign in to comment.