Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboards #14

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Package.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project>
<PropertyGroup>
<VersionPrefix>4.0.0</VersionPrefix>
<VersionPrefix>4.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>

<Authors>Dmitry Andriyanov &lt;[email protected]&gt;</Authors>
<Authors>Dmitry Andriyanov &lt;[email protected]&gt;</Authors>
<NeutralLanguage>en-US</NeutralLanguage>
<Copyright>Thinking-Home.RU © 2017</Copyright>

<PackageTags>thinking-home;core</PackageTags>
<PackageProjectUrl>https://github.com/thinking-home/system</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/thinking-home/system/blob/master/LICENSE</PackageLicenseUrl>
<PackageTags>thinking-home;core</PackageTags>
<PackageProjectUrl>https://github.com/thinking-home/system</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/thinking-home/system/blob/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/thinking-home/system.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
1 change: 1 addition & 0 deletions ThinkingHome.Console/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
- [x] обрубать слэши команд telegram + валидировать (?)
- [x] обновить клиентские библиотеки

- [ ] сделать валидацию URL для языковых ресурсов
- [ ] написать тесты на BaseRegistry.ForEach, ToObjectRegistry, ToObjectSetRegistry и Find*
- [ ] сделать отдельное кэширование переводов на сервере и клиенте
- [ ] вынести интерфейсы сценариев в отдельный плагин
Expand Down
3 changes: 3 additions & 0 deletions ThinkingHome.Console/ThinkingHome.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<ProjectReference Include="..\ThinkingHome.Plugins.Scripts\ThinkingHome.Plugins.Scripts.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.Scripts.WebApi\ThinkingHome.Plugins.Scripts.WebApi.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.Scripts.WebUi\ThinkingHome.Plugins.Scripts.WebUi.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.UniUi.Settings.WebApi\ThinkingHome.Plugins.UniUi.Settings.WebApi.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.UniUi.Settings.WebUi\ThinkingHome.Plugins.UniUi.Settings.WebUi.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.UniUi\ThinkingHome.Plugins.UniUi.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.WebServer\ThinkingHome.Plugins.WebServer.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.WebServer.UrlValidation\ThinkingHome.Plugins.WebServer.UrlValidation.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.WebUi\ThinkingHome.Plugins.WebUi.csproj" />
Expand Down
3 changes: 3 additions & 0 deletions ThinkingHome.Console/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"ThinkingHome.Plugins.TelegramBot",
"ThinkingHome.Plugins.Timer",
"ThinkingHome.Plugins.Tmp",
"ThinkingHome.Plugins.UniUi",
"ThinkingHome.Plugins.UniUi.Settings.WebApi",
"ThinkingHome.Plugins.UniUi.Settings.WebUi",
"ThinkingHome.Plugins.WebServer",
"ThinkingHome.Plugins.WebServer.UrlValidation",
"ThinkingHome.Plugins.WebUi",
Expand Down
8 changes: 0 additions & 8 deletions ThinkingHome.Core.Plugins/Utils/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ namespace ThinkingHome.Core.Plugins.Utils
{
public static class Extensions
{
/// <summary>
/// Сериализация в JSON
/// </summary>
public static string ToJson(this object obj, string defaultValue = "")
{
return obj == null ? defaultValue : JsonConvert.SerializeObject(obj);
}

#region parse

public static int? ParseInt(this string stringValue)
Expand Down
39 changes: 39 additions & 0 deletions ThinkingHome.Core.Plugins/Utils/JSON.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Newtonsoft.Json;

namespace ThinkingHome.Core.Plugins.Utils
{
public static class JSON
{
/// <summary>
/// Десериализация
/// </summary>
public static T Parse<T>(string json)
{
return JsonConvert.DeserializeObject<T>(json);
}

/// <summary>
/// Десериализация
/// </summary>
public static dynamic Parse(string json)
{
return JsonConvert.DeserializeObject(json);
}

/// <summary>
/// Сериализация в JSON
/// </summary>
public static string Stringify(object obj, string defaultValue = "")
{
return obj == null ? defaultValue : JsonConvert.SerializeObject(obj);
}

/// <summary>
/// Сериализация в JSON
/// </summary>
public static string ToJson(this object obj, string defaultValue = "")
{
return Stringify(obj, defaultValue);
}
}
}
12 changes: 7 additions & 5 deletions ThinkingHome.Plugins.Cron.WebUi/Resources/editor.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@
</label>
<input id="908b0027-3b51-42df-b173-2b1dd554b53d" name="eventAlias" class="form-control"/>
</div>
<div class="form-check">
<label class="form-check-label">
<input name="enabled" type="checkbox" class="form-check-input" />
{{lang 'Enabled'}}
</label>
<div class="form-group">
<div class="form-check">
<label class="form-check-label">
<input name="enabled" type="checkbox" class="form-check-input" />
{{lang 'Enabled'}}
</label>
</div>
</div>
<p>
<a href="#" class="btn btn-primary js-btn-save">{{lang 'Save'}}</a>&nbsp;
Expand Down
48 changes: 24 additions & 24 deletions ThinkingHome.Plugins.Cron/Model/CronTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ namespace ThinkingHome.Plugins.Cron.Model
{
public class CronTask
{
public Guid Id { get; set; }
public Guid Id { get; set; }

public string Name { get; set; }
public string Name { get; set; }

public string EventAlias { get; set; }
public string EventAlias { get; set; }

public int? Month { get; set; }

public int? Day { get; set; }

public int? Hour { get; set; }
public int? Month { get; set; }

public int? Minute { get; set; }
public int? Day { get; set; }

public bool Enabled { get; set; }
public int? Hour { get; set; }

public static string GetValueMask(int? value)
{
return value.HasValue ? value.Value.ToString() : "*";
}
public int? Minute { get; set; }

public string GetPattern()
{
return string.Format(
"{0} {1} {2} {3} *",
GetValueMask(Minute),
GetValueMask(Hour),
GetValueMask(Day),
GetValueMask(Month));
}
public bool Enabled { get; set; }

public static string GetValueMask(int? value)
{
return value.HasValue ? value.Value.ToString() : "*";
}

public string GetPattern()
{
return string.Format(
"{0} {1} {2} {3} *",
GetValueMask(Minute),
GetValueMask(Hour),
GetValueMask(Day),
GetValueMask(Month));
}
}
}
}
34 changes: 17 additions & 17 deletions ThinkingHome.Plugins.Cron/Model/Migrations/Migration01.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

namespace ThinkingHome.Plugins.Cron.Model.Migrations
{
[Migration(1)]
public class Migration01 : Migration
{
public override void Apply()
{
Database.AddTable("Cron_Task",
new Column("Id", DbType.Guid, ColumnProperty.PrimaryKey),
[Migration(1)]
public class Migration01 : Migration
{
public override void Apply()
{
Database.AddTable("Cron_Task",
new Column("Id", DbType.Guid, ColumnProperty.PrimaryKey),
new Column("Name", DbType.String.WithSize(int.MaxValue), ColumnProperty.NotNull),
new Column("EventAlias", DbType.String.WithSize(int.MaxValue)),
new Column("Month", DbType.Int32),
new Column("Month", DbType.Int32),
new Column("Day", DbType.Int32),
new Column("Hour", DbType.Int32),
new Column("Minute", DbType.Int32),
new Column("Minute", DbType.Int32),
new Column("Enabled", DbType.Boolean, ColumnProperty.NotNull)
);
}
);
}

public override void Revert()
{
Database.RemoveTable("Cron_Task");
}
}
}
public override void Revert()
{
Database.RemoveTable("Cron_Task");
}
}
}
50 changes: 24 additions & 26 deletions ThinkingHome.Plugins.Mail/MailPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
using ThinkingHome.Plugins.Scripts;
using ThinkingHome.Plugins.Scripts.Attributes;

namespace ThinkingHome.Plugins.Mail
{
public class MailPlugin : PluginBase
namespace ThinkingHome.Plugins.Mail
{
public class MailPlugin : PluginBase
{
#region options

private string FromName => Configuration.GetValue<string>("fromName");
private string FromMail => Configuration.GetValue<string>("fromMail");
private string SmtpHost => Configuration.GetValue<string>("smtpHost");
private string FromName => Configuration.GetValue<string>("fromName");
private string FromMail => Configuration.GetValue<string>("fromMail");
private string SmtpHost => Configuration.GetValue<string>("smtpHost");
private int SmtpPort => Configuration.GetValue<int>("smtpPort");
private bool UseSSL => Configuration.GetValue<bool>("useSSL");
private bool DisableCertificateValidation => Configuration.GetValue<bool>("disableCertificateValidation");

private string AuthLogin => Configuration.GetSection("auth").GetValue<string>("login");
private string AuthPassword => Configuration.GetSection("auth").GetValue<string>("password");
private string AuthPassword => Configuration.GetSection("auth").GetValue<string>("password");
private bool UseAuth => !string.IsNullOrEmpty(AuthLogin) && !string.IsNullOrEmpty(AuthPassword);

#endregion
Expand All @@ -28,7 +28,6 @@ public class MailPlugin : PluginBase

private void SendMailInternal(MimeMessage message)
{

using (var client = new SmtpClient())
{
if (DisableCertificateValidation)
Expand All @@ -51,7 +50,6 @@ private void SendMailInternal(MimeMessage message)

private MimeMessage CreateMessage(string email, string subject)
{

var message = new MimeMessage();

message.From.Add(new MailboxAddress(FromName, FromMail));
Expand All @@ -66,29 +64,29 @@ private MimeMessage CreateMessage(string email, string subject)
[ScriptCommand("sendMail")]
public void SendMail(string email, string subject, string body)
{
var message = CreateMessage(email, subject);
var message = CreateMessage(email, subject);

message.Body = new TextPart("plain") { Text = body };
message.Body = new TextPart("plain") {Text = body};

SendMailInternal(message);
SendMailInternal(message);
}

[ScriptCommand("sendMailWithAttachment")]
public void SendMail(string email, string subject, string body, string fileName, Buffer fileContent)
{
[ScriptCommand("sendMailWithAttachment")]
public void SendMail(string email, string subject, string body, string fileName, Buffer fileContent)
{
SendMail(email, subject, body, fileName, fileContent.GetBytes());
}
}

public void SendMail(string email, string subject, string body, string fileName, byte[] fileContent)
{
var message = CreateMessage(email, subject);
public void SendMail(string email, string subject, string body, string fileName, byte[] fileContent)
{
var message = CreateMessage(email, subject);

var builder = new BodyBuilder { TextBody = body };
builder.Attachments.Add(fileName, fileContent);
var builder = new BodyBuilder {TextBody = body};
builder.Attachments.Add(fileName, fileContent);

message.Body = builder.ToMessageBody();
message.Body = builder.ToMessageBody();

SendMailInternal(message);
}
}
}
SendMailInternal(message);
}
}
}
45 changes: 45 additions & 0 deletions ThinkingHome.Plugins.Tmp/SearchFormWidgetDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Linq;
using Microsoft.EntityFrameworkCore;
using ThinkingHome.Plugins.UniUi.Model;
using ThinkingHome.Plugins.UniUi.Widgets;

namespace ThinkingHome.Plugins.Tmp
{
public class SearchFormWidgetDefinition : WidgetDefinition
{
public override string DisplayName => "Tmp search form";

public override object GetWidgetData(Widget widget, WidgetParameter[] parameters, DbContext session)
{
var alias = widget.TypeAlias;
var engine = parameters.Single(p => p.Name == "engine").ValueString;
var count = parameters.Single(p => p.Name == "count").ValueInt;
var suggest = new[] {"cat", "dog", "pig", "fish"};

return new { alias, engine, count, suggest };
}

public override WidgetParameterMetaData[] GetWidgetMetaData(DbContext session)
{
var paramEngine = new WidgetParameterMetaData
{
DisplayName = "Search engine",
Name = "engine",
Type = WidgetParameterType.Int32,
Items = new[] {
new WidgetSelectItem(1, "Yandex"),
new WidgetSelectItem(2, "Google")
}
};

var paramCount = new WidgetParameterMetaData
{
DisplayName = "Search result count",
Name = "count",
Type = WidgetParameterType.Int32
};

return new[] { paramEngine, paramCount };
}
}
}
1 change: 1 addition & 0 deletions ThinkingHome.Plugins.Tmp/ThinkingHome.Plugins.Tmp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ProjectReference Include="../ThinkingHome.Plugins.Mqtt/ThinkingHome.Plugins.Mqtt.csproj" />
<ProjectReference Include="../ThinkingHome.Plugins.Cron/ThinkingHome.Plugins.Cron.csproj" />
<ProjectReference Include="../ThinkingHome.Plugins.TelegramBot\ThinkingHome.Plugins.TelegramBot.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.UniUi\ThinkingHome.Plugins.UniUi.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
Expand Down
8 changes: 8 additions & 0 deletions ThinkingHome.Plugins.Tmp/TmpPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using ThinkingHome.Plugins.Mail;
using ThinkingHome.Plugins.Mqtt;
using ThinkingHome.Plugins.TelegramBot;
using ThinkingHome.Plugins.UniUi;
using ThinkingHome.Plugins.WebServer;
using ThinkingHome.Plugins.WebServer.Messages;
using ThinkingHome.Plugins.WebUi.Attributes;
Expand Down Expand Up @@ -68,6 +69,13 @@ public override void StopPlugin()
Logger.LogDebug($"stop tmp plugin {Guid.NewGuid()}");
}

[DefineWidgets]
public void DefineWidgetsDelegate(IWidgetDefinitionSet definitions)
{
definitions.Add<SearchFormWidgetDefinition>("search-form-1");
definitions.Add<SearchFormWidgetDefinition>("search-form-2");
definitions.Add<SearchFormWidgetDefinition>("search-form-3");
}

[MqttMessageHandler]
public void HandleMqttMessage(string topic, byte[] payload)
Expand Down
Loading