Skip to content

Commit

Permalink
使用新架构优化应用导航页
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Oct 18, 2023
1 parent 56f17e0 commit 96a14d7
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 54 deletions.
14 changes: 14 additions & 0 deletions Stardust.Web/Areas/Configs/Controllers/AppConfigController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using NewLife.Cube;
using NewLife.Cube.ViewModels;
using NewLife.Log;
using NewLife.Remoting;
using NewLife.Web;
Expand Down Expand Up @@ -117,6 +118,19 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)
//PageSetting.EnableAdd = false;
}

protected override FieldCollection OnGetFields(ViewKinds kind, Object model)
{
var fields = base.OnGetFields(kind, model);

if (kind == ViewKinds.List)
{
var appId = GetRequest("appId").ToInt(-1);
if (appId > 0) fields.RemoveField("AppName", "Category");
}

return fields;
}

protected override IEnumerable<AppConfig> Search(Pager p)
{
var id = p["id"].ToInt(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static ConfigDataController()
{
ListFields.AddDataField("Value", null, "Scope");
ListFields.AddDataField("NewValue", null, "NewStatus");
//ListFields.RemoveField("Remark");
ListFields.RemoveField("Remark");
ListFields.RemoveField("CreateIP", "UpdateIP");

AddFormFields.RemoveCreateField();
Expand Down
13 changes: 13 additions & 0 deletions Stardust.Web/Areas/Deployment/Controllers/AppDeployController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)
//PageSetting.EnableAdd = false;
}

protected override FieldCollection OnGetFields(ViewKinds kind, Object model)
{
var fields = base.OnGetFields(kind, model);

if (kind == ViewKinds.List)
{
var appId = GetRequest("appId").ToInt(-1);
if (appId > 0) fields.RemoveField("AppName", "Category");
}

return fields;
}

protected override IEnumerable<AppDeploy> Search(Pager p)
{
var id = p["id"].ToInt(-1);
Expand Down
15 changes: 14 additions & 1 deletion Stardust.Web/Areas/Monitors/Controllers/AppTracerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,20 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)
PageSetting.EnableNavbar = false;
}

PageSetting.EnableAdd = false;
//PageSetting.EnableAdd = false;
}

protected override FieldCollection OnGetFields(ViewKinds kind, Object model)
{
var fields = base.OnGetFields(kind, model);

if (kind == ViewKinds.List)
{
var appId = GetRequest("appId").ToInt(-1);
if (appId > 0) fields.RemoveField("AppName", "Category");
}

return fields;
}

protected override IEnumerable<AppTracer> Search(Pager p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override FieldCollection OnGetFields(ViewKinds kind, Object model)
if (nodeId > 0) fields.RemoveField("NodeName");

var appId = GetRequest("appId").ToInt(-1);
if (appId > 0) fields.RemoveField("AppName");
if (appId > 0) fields.RemoveField("AppName", "Category", "Name");
}

return fields;
Expand Down
125 changes: 74 additions & 51 deletions Stardust.Web/Views/Shared/_App_Nav.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
@{
var path = Context.Request.Path + "";

var flag = false;
var appId = Context.Request.Query["appId"].ToInt(0);
if (appId == 0 && path.EqualIgnoreCase("/Registry/App", "/Registry/App/Detail", "/Registry/App/Edit"))
{
appId = Context.Request.Query["Id"].ToInt(0);
flag = true;
}
if (appId == 0 && path.EqualIgnoreCase("/Configs/AppConfig", "/Configs/AppConfig/Detail", "/Configs/AppConfig/Edit"))
{
Expand Down Expand Up @@ -43,66 +45,87 @@
var entity = AppTracer.FindByID(appId);
if (entity != null && entity.AppId > 0) appId = entity.AppId;
}

var start = Context.Request.Query["dtStart"].ToDateTime();
var end = Context.Request.Query["dtEnd"].ToDateTime();
if (end.Year < 2000) end = Context.Request.Query["dtEnd2"].ToDateTime().AddSeconds(1);

var dic = new Dictionary<String, Object>();
dic["实例"] = "/Registry/AppOnline?appId=" + appId;
dic["历史"] = "/Registry/AppHistory?appId=" + appId;
dic["命令"] = "/Registry/AppCommand?appId=" + appId;
dic["性能"] = "/Registry/AppMeter?appId=" + appId;
dic["注册中心"] = "/Registry/AppService?appId=" + appId;
dic["服务消费"] = "/Registry/AppConsume?appId=" + appId;

var configs = AppConfig.FindAllByAppId(appId);
dic["配置中心"] = "/Configs/AppConfig?appId=" + appId;
if (configs.Count == 1)
{
dic["配置管理"] = "/Configs/ConfigData?appId=" + configs[0].Id;
}

var deploys = AppDeploy.FindAllByAppId(appId);
dic["发布中心"] = "/Deployment/AppDeploy?appId=" + appId;
if (deploys.Count == 1)
{
dic["版本上传"] = "/Deployment/AppDeployVersion?appId=" + deploys[0].Id;
dic["发布节点"] = "/Deployment/AppDeployNode?appId=" + deploys[0].Id;
}

var monitors = AppTracer.FindAllByAppId(appId);
dic["监控中心"] = "/Monitors/AppTracer?appId=" + appId;
if (monitors.Count == 1)
{
dic["监控大屏"] = "/Monitors/AppDayStat?appId=" + monitors[0].ID;
}

// var dic2 = new Dictionary<String, Object>();
// dic2["报警事件"] = "/Safety/AlarmEvent?appId=" + appId;
// dic2["ADAS"] = "/Safety/ADASAlarm?appId=" + appId;
// dic2["DSM"] = "/Safety/DSMAlarm?appId=" + appId;
// dic2["BSD"] = "/Safety/BSDAlarm?appId=" + appId;
// dic["报警"] = dic2;
}
@if (appId > 0)
{
var app = App.FindById(appId);
var config = AppConfig.FindAllByAppId(appId).FirstOrDefault();
var deploy = AppDeploy.FindAllByAppId(appId).FirstOrDefault();
var monitor = AppTracer.FindAllByAppId(appId).FirstOrDefault();

<div class="navbar-collapse collapse" style="text-align:center">
<div class="navbar-collapse collapse text-center">
<ul class="nav nav-pills" style="margin-bottom: 10px; display: inline-block;float: none;">
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Registry/App/Detail","/Registry/App/Edit")?"active":"")">
<li role="presentation" class="@(flag?"active":"")">
<a href="/Registry/App/Edit?Id=@appId">应用:@(app?.ToString() ?? "信息")</a>
</li>
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Registry/AppOnline")?"active":"")">
<a href="/Registry/AppOnline?appId=@appId">实例</a>
</li>
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Registry/AppHistory")?"active":"")">
<a href="/Registry/AppHistory?appId=@appId">历史</a>
</li>
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Registry/AppCommand")?"active":"")">
<a href="/Registry/AppCommand?appId=@appId">命令</a>
</li>
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Registry/AppMeter")?"active":"")">
<a href="/Registry/AppMeter?appId=@appId">性能</a>
</li>
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Registry/AppService")?"active":"")">
<a href="/Registry/AppService?appId=@appId">注册中心</a>
</li>
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Registry/AppConsume")?"active":"")">
<a href="/Registry/AppConsume?appId=@appId">服务消费</a>
</li>
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Configs/AppConfig")?"active":"")">
<a href="/Configs/AppConfig?appId=@appId">配置中心</a>
</li>
@if (config != null)
{
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Configs/ConfigData")?"active":"")">
<a href="/Configs/[email protected]">配置管理</a>
</li>
}
<li role="presentation" class="@(path.EqualIgnoreCase("/Deployment/AppDeploy")?"active":"")">
<a href="/Deployment/AppDeploy?appId=@appId">发布中心</a>
</li>
@if (deploy != null)
{
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Deployment/AppDeployVersion")?"active":"")">
<a href="/Deployment/[email protected]">版本上传</a>
</li>
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Deployment/AppDeployNode")?"active":"")">
<a href="/Deployment/[email protected]&enable=1">发布节点</a>
</li>
}
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Monitors/AppTracer")?"active":"")">
<a href="/Monitors/AppTracer?appId=@appId">监控中心</a>
</li>
@if (monitor != null)
@foreach (var item in dic)
{
<li role="presentation" class="@(path.StartsWithIgnoreCase("/Monitors/AppDayStat")?"active":"")">
<a href="/Monitors/[email protected]">监控大屏</a>
</li>
if (item.Value is IDictionary<String, Object> childs)
{
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">@item.Key <span class="caret"></span></a>
<ul class="dropdown-menu">
@foreach (var elm in childs)
{
var url = elm.Value + "";
var v = url.Substring(null, "?");
if (start.Year > 2000) url += "&dtStart=" + start.ToFullString();
if (end.Year > 2000) url += "&dtEnd=" + end.ToFullString();
<li role="presentation" class="@(path.EqualIgnoreCase(v)?"active":"")">
<a href="@url">@elm.Key</a>
</li>
}
</ul>
</li>
}
else
{
var url = item.Value + "";
var v = url.Substring(null, "?");
if (start.Year > 2000) url += "&dtStart=" + start.ToFullString();
if (end.Year > 2000) url += "&dtEnd=" + end.ToFullString();
<li role="presentation" class="@(path.EqualIgnoreCase(v)?"active":"")">
<a href="@url">@item.Key</a>
</li>
}
}
</ul>
</div>
Expand Down

0 comments on commit 96a14d7

Please sign in to comment.