Former-commit-id: ac3c369a69d4398d17a7750dcaf954279fe5e7e5
TangShanKaiPing
wanggang 6 years ago
parent 0a7b8a2990
commit 181a760957

@ -1,6 +1,6 @@
@{var props = ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.HideSurroundingHtml && !pm.IsComplexType && !pm.IsCollectionType && pm.PropertyName != "Id").ToList();
foreach (var prop in props)
{
<td>@Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint)</td>
<td style="max-width:10em;">@Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint)</td>
}
}

@ -1,6 +1,6 @@
using Application.Domain.Entities;
namespace IoT.Shared.Application.Models
namespace Application.Models
{
public class DataDto
{

@ -1,4 +1,4 @@
namespace IoT.Shared.Application.Models
namespace Application.Models
{
public class DeviceDto
{

@ -1,31 +1,41 @@
using System.ComponentModel.DataAnnotations;
using Application.Domain.Entities;
using Infrastructure.Application;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace Application.Models
{
[Display(Name = "数据")]
public class EditDataModel : EditModel
{
[Display(Name = "类型")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public DeviceDataType Type { get; set; }
[Display(Name = "名称")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string Name { get; set; }
[Display(Name = "键")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
[ReadOnly(true)]
public string Key { get; set; }
[Display(Name = "值")]
public string Value { get; set; }
[Display(Name = "名称")]
public string Name { get; set; }
[Display(Name = "类型")]
public DeviceDataType Type { get; set; }
[Display(Name = "单位")]
public string Unit { get; set; }
[Display(Name = "描述")]
public string Description { get; set; }
[Display(Name = "时间戳")]
public long Timestamp { get; set; }
[Display(Name = "隐藏")]
public bool Hidden { get; set; }
[HiddenInput(DisplayValue = false)]
[ScaffoldColumn(true)]
public string DeviceNumber { get; set; }
}
}

@ -0,0 +1,24 @@
using Infrastructure.Application;
using System.ComponentModel.DataAnnotations;
namespace Application.Models
{
[Display(Name = "产品")]
public class EditProductModel : EditModel
{
[Display(Name = "产品名称")]
public string Name { get; set; }
[Display(Name = "产品型号")]
public string Number { get; set; }
[Display(Name = "图标")]
public string Icon { get; set; }
[Display(Name = "ApiJson")]
public string ApiJson { get; set; }
[Display(Name = "产品分类")]
public string CategoryName { get; set; }
}
}

@ -1,4 +1,4 @@
namespace IoT.Shared.Application.Models
namespace Application.Models
{
public class Methods
{
@ -28,5 +28,11 @@
public const string DeleteDeviceRequest = nameof(DeleteDeviceRequest);
public const string DeleteDeviceResponse = nameof(DeleteDeviceResponse);
public const string EditDataRequest = nameof(EditDataRequest);
public const string EditDataResponse = nameof(EditDataResponse);
public const string DeleteDataRequest = nameof(DeleteDataRequest);
public const string DeleteDataResponse = nameof(DeleteDataResponse);
}
}

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace IoT.Shared.Application.Models
namespace Application.Models
{
public class NodeDto
{

@ -1,6 +1,6 @@
using Application.Domain.Entities;
namespace IoT.Shared.Application.Models
namespace Application.Models
{
public class ProductDto : Product
{

@ -1,7 +1,7 @@
using Application.Domain.Entities;
using Infrastructure.Data;
using Infrastructure.Extensions;
using IoT.Shared.Application.Models;
using Application.Models;
using IoT.Shared.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

@ -1,7 +1,7 @@
using Application.Domain.Entities;
using Infrastructure.Data;
using Infrastructure.Extensions;
using IoT.Shared.Application.Models;
using Application.Models;
using IoT.Shared.Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;

@ -12,7 +12,7 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.IO.Ports;
using IoT.Shared.Application.Models;
using Application.Models;
namespace IoT.Shared.DeviceServices.SerialPort
{

@ -1,5 +1,5 @@
using Infrastructure.Extensions;
using IoT.Shared.Application.Models;
using Application.Models;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Configuration;
using System;

@ -1,6 +1,6 @@
using Application.Domain.Entities;
using Infrastructure.Extensions;
using IoT.Shared.Application.Models;
using Application.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;

@ -2,7 +2,6 @@
using Application.Models;
using Infrastructure.Data;
using Infrastructure.Extensions;
using IoT.Shared.Application.Models;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@ -146,6 +145,37 @@ namespace IoT.Shared.Infrastructure
}
}
}
else if (method == Methods.EditDataRequest)
{
var model = message.FromJson<DataDto>();
using (var scope = this.applicationServices.CreateScope())
{
var dataRepo = scope.ServiceProvider.GetService<IRepository<Data>>();
var data = dataRepo.Table().FirstOrDefault(o => o.Key == model.Key);
if (data != null)
{
data.From(model);
dataRepo.SaveChanges();
var dataDto = data.To<DataDto>();
dataDto.DeviceNumber = model.DeviceNumber;
this.ClientToServer(Methods.EditDataResponse, dataDto.ToJson());
}
}
}
else if (method == Methods.DeleteDataRequest)
{
using (var scope = this.applicationServices.CreateScope())
{
var dataRepo = scope.ServiceProvider.GetService<IRepository<Data>>();
var data = dataRepo.Table().FirstOrDefault(o => o.Key == message);
if (data != null)
{
dataRepo.Delete(data);
dataRepo.SaveChanges();
this.ClientToServer(Methods.DeleteDataResponse, message);
}
}
}
}
public void SendNode(NodeDto node)

@ -1,12 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Application.Domain.Entities;
using Application.Models;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoTCenter.Services;
using IoTShared.Controllers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
namespace IoTCenter.Areas.Admin.Controllers
{
@ -15,10 +20,17 @@ namespace IoTCenter.Areas.Admin.Controllers
public class DataController : CrudController<Data, DataSearchModel, EditDataModel, EditDataModel>
{
private readonly AjaxController _ajax;
private readonly IHubContext<PageHub> _pageHubContext;
public DataController(IRepository<Data> repo, AjaxController ajax) : base(repo)
public DataController(IRepository<Data> repo, AjaxController ajax, IHubContext<PageHub> pageHubContext) : base(repo)
{
this._ajax = ajax;
this._pageHubContext = pageHubContext;
}
public override IQueryable<Data> Include(IQueryable<Data> query)
{
return query.Include(o => o.Device);
}
public override IQueryable<Data> Query(DataSearchModel model, IQueryable<Data> query)
@ -29,5 +41,41 @@ namespace IoTCenter.Areas.Admin.Controllers
.WhereIf(model.DeviceId.HasValue, o => o.DeviceId == model.DeviceId.Value)
.WhereIf(!string.IsNullOrEmpty(model.Keyword), o => o.Name.Contains(model.Keyword));
}
public override void ToModel(Data entity, EditDataModel model)
{
model.DeviceNumber = entity.Device.Number;
}
public override IActionResult Edit(EditDataModel model)
{
if (ModelState.IsValid)
{
var dataDto = model.To<DataDto>();
this._pageHubContext.Clients.Group(model.DeviceNumber).SendAsync(Methods.ServerToClient, Methods.EditDataRequest, dataDto.ToJson(), null);
return RedirectTo();
}
ModelState.AddModelError("", "服务器出现异常,请稍后重试");
return View(model);
}
public override IActionResult Delete(List<Guid> list)
{
foreach (var id in list)
{
try
{
var entity = this.repo.Table().Include(o => o.Device).FirstOrDefault(o => o.Id == id);
var number = entity.Device.Number;
this._pageHubContext.Clients.Group(number).SendAsync(Methods.ServerToClient, Methods.DeleteDataRequest, entity.Key, null);
}
catch (Exception ex)
{
ex.PrintStack();
return RedirectTo(message: ex.Message);
}
}
return RedirectTo();
}
}
}

@ -3,7 +3,6 @@ using Application.Models;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Application.Models;
using IoTCenter.Services;
using IoTShared.Controllers;
using Microsoft.AspNetCore.Authorization;

@ -4,7 +4,6 @@ using Infrastructure.Application;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Application.Models;
using IoTCenter.Services;
using IoTShared.Services;
using Microsoft.AspNetCore.Authorization;

@ -0,0 +1,40 @@
using System.Linq;
using Application.Domain.Entities;
using Application.Models;
using Infrastructure.Application;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoTCenter.Services;
using IoTShared.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
namespace IoTCenter.Areas.Admin.Controllers
{
[Authorize]
[Area(nameof(Admin))]
public class ProductController : CrudController<Product, PagedListModel<EditProductModel>, EditProductModel, EditProductModel>
{
public ProductController(IRepository<Product> repo) : base(repo)
{
}
public override IQueryable<Product> Include(IQueryable<Product> query)
{
return query.Include(o => o.Category);
}
public override void ToModel(Product entity, EditProductModel model)
{
model.CategoryName = entity.Category.Name;
}
public override void ToDisplayModel(Product entity, EditProductModel model)
{
this.ToModel(entity, model);
}
}
}

@ -5,7 +5,7 @@
<li class="treeview @GetClass("User","Role","Permission")">
<a href="javascript:;" class="dropdown-toggle">
<i class="fa fa-list"></i>
<span>权限管理</span>
<span>用户管理</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
@ -16,7 +16,7 @@
<li class="@GetClass("Permission")"><a href="@Url.Action("Index","Permission")"><i class="fa fa-circle-o"></i><span>权限管理</span></a></li>
</ul>
</li>
<li class="treeview @GetClass("Node","Device","Data","Api","Parameter","Sence","Command")">
<li class="treeview @GetClass("Category","Product","Node","Device","Data","Api","Parameter","Sence","Command")">
<a href="javascript:;" class="dropdown-toggle">
<i class="fa fa-list"></i>
<span>设备管理</span>
@ -25,13 +25,15 @@
</span>
</a>
<ul class="treeview-menu">
<li class="@GetClass("Category")"><a href="@Url.Action("Index","Category")"><i class="fa fa-circle-o"></i><span>分类管理</span></a></li>
<li class="@GetClass("Product")"><a href="@Url.Action("Index","Product")"><i class="fa fa-circle-o"></i><span>产品管理</span></a></li>
<li class="@GetClass("Node")"><a href="@Url.Action("Index","Node")"><i class="fa fa-circle-o"></i><span>节点管理</span></a></li>
<li class="@GetClass("Device")"><a href="@Url.Action("Index","Device")"><i class="fa fa-circle-o"></i><span>设备管理</span></a></li>
<li class="@GetClass("Data")"><a href="@Url.Action("Index","Data")"><i class="fa fa-circle-o"></i><span>数据管理</span></a></li>
<li class="@GetClass("Api")"><a href="@Url.Action("Index","Api")"><i class="fa fa-circle-o"></i><span>接口管理</span></a></li>
<li class="@GetClass("Parameter")"><a href="@Url.Action("Index","Parameter")"><i class="fa fa-circle-o"></i><span>参数管理</span></a></li>
<li class="@GetClass("Sence")"><a href="@Url.Action("Index","Sence")"><i class="fa fa-circle-o"></i><span>场景管理</span></a></li>
<li class="@GetClass("Command")"><a href="@Url.Action("Index","Command")"><i class="fa fa-circle-o"></i><span>命令管理</span></a></li>
<li class="@GetClass("Sence")"><a href="@Url.Action("Index","Sence")"><i class="fa fa-circle-o"></i><span>场景管理</span></a></li>
</ul>
</li>
</ul>

@ -3,7 +3,6 @@ using Application.Models;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Jwt;
using IoT.Shared.Application.Models;
using IoTCenter.Services;
using IoTShared.Services;
using Microsoft.AspNetCore.Authorization;

@ -1,7 +1,7 @@
using Application.Domain.Entities;
using Application.Models;
using Infrastructure.Data;
using Infrastructure.Extensions;
using IoT.Shared.Application.Models;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

@ -3,7 +3,6 @@ using Application.Models;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.SignalR;
using IoT.Shared.Application.Models;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

@ -350,7 +350,7 @@
<div class="item-inner">
<div class="item-title">{{device.DisplayName||device.Name}}</div>
<div class="item-after">
<span v-if="device.Name=='智能插座'" class="badge color-green" v-if="getData(device,'电量')">{{getData(device,"电量")}}</span>
<span class="badge color-green" v-if="getData(device,'电量')">{{getData(device,"电量")}}</span>
<span class="badge color-green">{{getData(device,"状态")}}</span>
</div>
</div>

Loading…
Cancel
Save