Skip to content

Commit

Permalink
Merge pull request #34 from alexdresko/Integrate_HSPIBase.cs_and_thr_…
Browse files Browse the repository at this point in the history
…pagbuilder.cs_#3

Integrate hspi base.cs and thr pagbuilder.cs #3
  • Loading branch information
alexdresko committed Feb 28, 2017
2 parents 611f6c8 + 9ba52ef commit 351577e
Show file tree
Hide file tree
Showing 24 changed files with 1,487 additions and 6 deletions.
14 changes: 14 additions & 0 deletions HSPI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HSPIPluginA", "Templates\HS
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HSPIPluginA.Dev", "Templates\HSPIPluginA.Dev\HSPIPluginA.Dev.csproj", "{CAA3F9D3-4647-48DE-8BA7-32AC317B046D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HSPIPluginB.Dev", "Templates\HSPIPluginB.Dev\HSPIPluginB.Dev.csproj", "{8F609EDB-0CFF-4B67-A7ED-265331C90F91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HSPIPluginB", "Templates\HSPIPluginB\HSPIPluginB.csproj", "{B00BD583-D633-4CA1-B66C-EA78BC906023}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -40,6 +44,14 @@ Global
{CAA3F9D3-4647-48DE-8BA7-32AC317B046D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAA3F9D3-4647-48DE-8BA7-32AC317B046D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAA3F9D3-4647-48DE-8BA7-32AC317B046D}.Release|Any CPU.Build.0 = Release|Any CPU
{8F609EDB-0CFF-4B67-A7ED-265331C90F91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F609EDB-0CFF-4B67-A7ED-265331C90F91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F609EDB-0CFF-4B67-A7ED-265331C90F91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F609EDB-0CFF-4B67-A7ED-265331C90F91}.Release|Any CPU.Build.0 = Release|Any CPU
{B00BD583-D633-4CA1-B66C-EA78BC906023}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B00BD583-D633-4CA1-B66C-EA78BC906023}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B00BD583-D633-4CA1-B66C-EA78BC906023}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B00BD583-D633-4CA1-B66C-EA78BC906023}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -48,5 +60,7 @@ Global
{B2550542-2064-4520-B79F-9A3685D6A0CE} = {85A80E33-7B0C-4913-A709-F98A7F32829A}
{56725C85-3A26-4FA9-9CE4-CACDDEFF9603} = {85A80E33-7B0C-4913-A709-F98A7F32829A}
{CAA3F9D3-4647-48DE-8BA7-32AC317B046D} = {85A80E33-7B0C-4913-A709-F98A7F32829A}
{8F609EDB-0CFF-4B67-A7ED-265331C90F91} = {85A80E33-7B0C-4913-A709-F98A7F32829A}
{B00BD583-D633-4CA1-B66C-EA78BC906023} = {85A80E33-7B0C-4913-A709-F98A7F32829A}
EndGlobalSection
EndGlobal
329 changes: 329 additions & 0 deletions HSPI/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,329 @@
// Copyright (C) 2016 SRG Technology, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System.Collections.Specialized;
using Scheduler;

namespace HSPI
{
/// <summary>
/// This class adds some common support functions for creating the web pages used by HomeSeer plugins.
/// <para />
/// For each control there are three functions:
/// <list type="bullet">
/// <item>
/// <description><c>Build:</c> Used to initially create the control in the web page.</description>
/// </item>
/// <item>
/// <description><c>Update:</c> Used to modify the control in an existing web page.</description>
/// </item>
/// <item>
/// <description><c>Form:</c> Not normally call externally but could be useful in special circumstances.</description>
/// </item>
/// </list>
/// </summary>
/// <seealso cref="Scheduler.PageBuilderAndMenu.clsPageBuilder" />
public class PageBuilder : PageBuilderAndMenu.clsPageBuilder
{
/// <summary>
/// </summary>
/// <param name="pagename">The name used by HomeSeer when referencing this particular page.</param>
public PageBuilder(string pagename) : base(pagename)
{
}

/// <summary>
/// Build a button for a web page.
/// </summary>
/// <param name="text">The text on the button.</param>
/// <param name="name">The name used to create the references for the button.</param>
/// <param name="enabled">if set to <c>true</c> [enabled].</param>
/// <returns>The text to insert in the web page to create the button.</returns>
protected string BuildButton(string text, string name, bool enabled = true)
{
return "<div id='" + name + "_div'>" + FormButton(name, text, enabled: enabled) + "</div>";
}

/// <summary>
/// Update a button on a web page that was created with a DIV tag.
/// </summary>
/// <param name="text">The text on the button.</param>
/// <param name="name">The name used to create the references for the button.</param>
/// <param name="enabled">if set to <c>true</c> [enabled].</param>
protected void UpdateButton(string text, string name, bool enabled = true)
{
divToUpdate.Add(name + "_div", FormButton(name, text, enabled: enabled));
}

/// <summary>
/// Return the string required to create a web page button.
/// </summary>
protected string FormButton(string name, string label = "Submit", bool submitForm = true,
string imagePathNormal = "", string imagePathPressed = "", string toolTip = "",
bool enabled = true, string style = "")
{
var b = new clsJQuery.jqButton(name, label, PageName, submitForm)
{
id = "o" + name,
imagePathNormal = imagePathNormal
};
b.imagePathPressed = imagePathPressed == "" ? b.imagePathNormal : imagePathPressed;
b.toolTip = toolTip;
b.enabled = enabled;
b.style = style;

var button = b.Build();
button = button.Replace("</button>\r\n", "</button>").Trim();
return button;
}

/// <summary>
/// Build a label for a web page.
/// </summary>
/// <param name="msg">The text for the label.</param>
/// <param name="name">The name used to create the references for the label.</param>
/// <returns>The text to insert in the web page to create the label.</returns>
protected string BuildLabel(string name, string msg = "")
{
return "<div id='" + name + "_div'>" + FormLabel(name, msg) + "</div>";
}

/// <summary>
/// Update a label on a web page that was created with a DIV tag.
/// </summary>
/// <param name="msg">The text for the label.</param>
/// <param name="name">The name used to create the references for the label.</param>
protected void UpdateLabel(string name, string msg = "")
{
divToUpdate.Add(name + "_div", FormLabel(name, msg));
}

/// <summary>
/// Return the string required to create a web page label.
/// </summary>
protected string FormLabel(string name, string message = "", bool visible = true)
{
string content;
if (visible)
content = message + "<input id='" + name + "' Name='" + name + "' Type='hidden'>";
else
content = "<input id='" + name + "' Name='" + name + "' Type='hidden' value='" + message + "'>";
return content;
}

/// <summary>
/// Build a text entry box for a web page.
/// </summary>
/// <param name="text">The default text for the text box.</param>
/// <param name="name">The name used to create the references for the text box.</param>
/// <param name="allowEdit">if set to <c>true</c> allow the text to be edited.</param>
/// <returns>The text to insert in the web page to create the text box.</returns>
protected string BuildTextBox(string name, string text = "", bool allowEdit = true)
{
return "<div id='" + name + "_div'>" + HtmlTextBox(name, text, 20, allowEdit) + "</div>";
}

/// <summary>
/// Update a text box on a web page that was created with a DIV tag.
/// </summary>
/// <param name="text">The text for the text box.</param>
/// <param name="name">The name used to create the references for the text box.</param>
/// <param name="allowEdit">if set to <c>true</c> allow the text to be edited.</param>
protected void UpdateTextBox(string name, string text = "", bool allowEdit = true)
{
divToUpdate.Add(name + "_div", HtmlTextBox(name, text, 20, allowEdit));
}

/// <summary>
/// Return the string required to create a web page text box.
/// </summary>
protected string HtmlTextBox(string name, string defaultText, int size, bool allowEdit = true)
{
var style = "";
var sReadOnly = "";

if (!allowEdit)
{
style = "color:#F5F5F5; background-color:#C0C0C0;";
sReadOnly = "readonly='readonly'";
}

return "<input type='text' id='o" + name + "' style='" + style + "' size='" + size + "' name='" + name +
"' " + sReadOnly + " value='" + defaultText + "'>";
}

/// <summary>
/// Build a check box for a web page.
/// </summary>
/// <param name="name">The name used to create the references for the text box.</param>
/// <param name="Checked">if set to <c>true</c> [checked].</param>
/// <returns>The text to insert in the web page to create the check box.</returns>
protected string BuildCheckBox(string name, bool Checked = false)
{
return "<div id='" + name + "_div'>" + FormCheckBox(name, Checked) + "</div>";
}

/// <summary>
/// Update a check box on a web page that was created with a DIV tag.
/// </summary>
/// <param name="name">The name used to create the references for the text box.</param>
/// <param name="Checked">if set to <c>true</c> [checked].</param>
protected void UpdateCheckBox(string name, bool Checked = false)
{
divToUpdate.Add(name + "_div", FormCheckBox(name, Checked));
}

/// <summary>
/// Return the string required to create a web page check box.
/// </summary>
protected string FormCheckBox(string name, bool Checked = false, bool autoPostBack = true,
bool submitForm = true)
{
var cb = new clsJQuery.jqCheckBox(name, "", PageName, autoPostBack, submitForm)
{
id = "o" + name,
@checked = Checked
};
return cb.Build();
}

/// <summary>
/// Build a list box for a web page.
/// </summary>
/// <param name="name">The name used to create the references for the list box.</param>
/// <param name="options">Data value pairs used to populate the list box.</param>
/// <param name="selected">Index of the item to be selected.</param>
/// <param name="selectedValue">Name of the value to be selected.</param>
/// <param name="width">Width of the list box</param>
/// <param name="enabled">if set to <c>true</c> [enabled]. Doesn't seem to work.</param>
/// <returns>The text to insert in the web page to create the list box.</returns>
protected string BuildListBox(string name, ref NameValueCollection options, int selected = -1,
string selectedValue = "", int width = 150, bool enabled = true)
{
return "<div id='" + name + "_div'>" +
FormListBox(name, ref options, selected, selectedValue, width, enabled) + "</div>";
}

/// <summary>
/// Update a list box for a web page that was created with a DIV tag.
/// </summary>
/// <param name="name">The name used to create the references for the list box.</param>
/// <param name="options">Data value pairs used to populate the list box.</param>
/// <param name="selected">Index of the item to be selected.</param>
/// <param name="selectedValue">Name of the value to be selected.</param>
/// <param name="width">Width of the list box</param>
/// <param name="enabled">if set to <c>true</c> [enabled]. Doesn't seem to work.</param>
protected void UpdateListBox(string name, ref NameValueCollection options, int selected = -1,
string selectedValue = "", int width = 150, bool enabled = true)
{
divToUpdate.Add(name + "_div", FormListBox(name, ref options, selected, selectedValue, width, enabled));
}

/// <summary>
/// Return the string required to create a web page list box.
/// </summary>
protected string FormListBox(string name, ref NameValueCollection options, int selected = -1,
string selectedValue = "", int width = 150, bool enabled = true)
{
var lb = new clsJQuery.jqListBox(name, PageName);

lb.items.Clear();
lb.id = "o" + name;
lb.style = "width: " + width + "px;";
lb.enabled = enabled;

if (options != null)
{
for (var i = 0; i < options.Count; i++)
{
if (selected == -1 && selectedValue == options.GetKey(i))
selected = i;
lb.items.Add(options.GetKey(i));
}
if (selected >= 0)
lb.SelectedValue = options.GetKey(selected);
}

return lb.Build();
}

/// <summary>
/// Build a drop list for a web page.
/// </summary>
/// <param name="name">The name used to create the references for the list box.</param>
/// <param name="options">Data value pairs used to populate the list box.</param>
/// <param name="selected">Index of the item to be selected.</param>
/// <param name="selectedValue">Name of the value to be selected.</param>
/// <returns>The text to insert in the web page to create the drop list.</returns>
protected string BuildDropList(string name, ref NameValueCollection options, int selected = -1,
string selectedValue = "")
{
return "<div id='" + name + "_div'>" +
FormDropDown(name, ref options, selected, selectedValue: selectedValue) + "</div>";
}

/// <summary>
/// Update a drop list for a web page that was created with a DIV tag.
/// </summary>
/// <param name="name">The name used to create the references for the list box.</param>
/// <param name="options">Data value pairs used to populate the list box.</param>
/// <param name="selected">Index of the item to be selected.</param>
/// <param name="selectedValue">Name of the value to be selected.</param>
protected void UpdateDropList(string name, ref NameValueCollection options, int selected = -1,
string selectedValue = "")
{
divToUpdate.Add(name + "_div", FormDropDown(name, ref options, selected, selectedValue: selectedValue));
}

/// <summary>
/// Return the string required to create a web page drop list.
/// </summary>
protected string FormDropDown(string name, ref NameValueCollection options, int selected, int width = 150,
bool submitForm = true, bool addBlankRow = false,
bool autoPostback = true, string tooltip = "", bool enabled = true, string ddMsg = "",
string selectedValue = "")
{
var dd = new clsJQuery.jqDropList(name, PageName, submitForm)
{
selectedItemIndex = -1,
id = "o" + name,
autoPostBack = autoPostback,
toolTip = tooltip,
style = "width: " + width + "px;",
enabled = enabled
};


//Add a blank area to the top of the list
if (addBlankRow)
dd.AddItem(ddMsg, "", false);

if (options != null)
for (var i = 0; i < options.Count; i++)
{
var sel = i == selected || options.Get(i) == selectedValue;

dd.AddItem(options.GetKey(i), options.Get(i), sel);
}

return dd.Build();
}
}
}
2 changes: 1 addition & 1 deletion HSPI/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace HSPI
{
public class Connector
{
public static void Connect<TPlugin>(string[] args) where TPlugin : HSPIBase, new()
public static void Connect<TPlugin>(string[] args) where TPlugin : HspiBase, new()
{
var options = new Options();
if (Parser.Default.ParseArguments(args, options))
Expand Down
2 changes: 2 additions & 0 deletions HSPI/HSPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="HSPIBase2.cs" />
<Compile Include="HSPIBase.cs" />
<Compile Include="Options.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit 351577e

Please sign in to comment.