[UI.Client]

新增RolePermissionTrueFalseMapper对象。
Role编辑界面的Content权限编辑表格中的权限用Yes、No代替NONE、Read、Read&Write,使语义更加准确。
优化RoleViewModel.cs代码格式。
优化RolePermissionMapper.cs代码格式。
This commit is contained in:
SL 2023-09-02 23:46:13 +08:00
parent 035c2655ae
commit 8ae5186ee0
6 changed files with 235 additions and 145 deletions

View File

@ -0,0 +1,9 @@
using MECF.Framework.UI.Client.ClientBase;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles;
public class PermissionType
{
public MenuPermissionEnum EnumPermission { get; set; }
public string StringPermission { get; set; }
}

View File

@ -1,61 +1,55 @@
using System.Collections.ObjectModel;
using Aitex.Core.Util;
using MECF.Framework.UI.Client.ClientBase;
using OpenSEMI.ClientBase;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
public class RolePermissionMapper
public class RolePermissionMapper : Singleton<RolePermissionMapper>
{
private RolePermissionMapper()
#region Constructors
public RolePermissionMapper()
{
_DicPermission.Add(new PermissionType()
PermissionDictionary.Add(new PermissionType()
{ EnumPermission = MenuPermissionEnum.MP_NONE,
StringPermission = "NONE"
});
_DicPermission.Add(new PermissionType()
PermissionDictionary.Add(new PermissionType()
{
EnumPermission = MenuPermissionEnum.MP_READ,
StringPermission = "Read"
});
_DicPermission.Add(new PermissionType()
PermissionDictionary.Add(new PermissionType()
{
EnumPermission = MenuPermissionEnum.MP_READ_WRITE,
StringPermission = "Read & Write"
});
}
private static RolePermissionMapper _Instance = null;
public static RolePermissionMapper Instance
#endregion
#region Properties
public ObservableCollection<PermissionType> PermissionDictionary { get; } = new();
#endregion
#region Methods
public int ToInt(MenuPermissionEnum enumPermission)
{
get
return (int)enumPermission;
}
public string ToString(MenuPermissionEnum enumPermission)
{
foreach (var pd in PermissionDictionary)
{
if (_Instance == null)
{
_Instance = new RolePermissionMapper();
}
return _Instance;
}
}
private ObservableCollection<PermissionType> _DicPermission = new ObservableCollection<PermissionType>();
public ObservableCollection<PermissionType> PermissionDictionary
{
get { return _DicPermission; }
}
public int ToInt(MenuPermissionEnum enumPermistion)
{
return (int)enumPermistion;
}
public string ToString(MenuPermissionEnum enumPermistion)
{
foreach (PermissionType pd in _DicPermission)
{
if (pd.EnumPermission == enumPermistion)
if (pd.EnumPermission == enumPermission)
{
return pd.StringPermission;
}
@ -63,11 +57,8 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
return "";
}
}
public class PermissionType
{
public MenuPermissionEnum EnumPermission{get;set;}
public string StringPermission { get; set; }
#endregion
}
}

View File

@ -0,0 +1,63 @@
using System.Collections.ObjectModel;
using Aitex.Core.Util;
using MECF.Framework.UI.Client.ClientBase;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
public class RolePermissionTrueFalseMapper : Singleton<RolePermissionTrueFalseMapper>
{
#region Constructors
public RolePermissionTrueFalseMapper()
{
PermissionDictionary.Add(new PermissionType()
{ EnumPermission = MenuPermissionEnum.MP_NONE,
StringPermission = "No"
});
PermissionDictionary.Add(new PermissionType()
{
EnumPermission = MenuPermissionEnum.MP_READ_WRITE,
StringPermission = "Yes"
});
}
#endregion
#region Properties
public ObservableCollection<PermissionType> PermissionDictionary { get; } = new();
#endregion
#region Methods
public int ToInt(MenuPermissionEnum enumPermission)
{
return (int)enumPermission;
}
public string ToString(MenuPermissionEnum enumPermission)
{
foreach (var pd in PermissionDictionary)
{
if (pd.EnumPermission == enumPermission)
{
return pd.StringPermission;
}
}
return "";
}
#endregion
}
}

View File

@ -471,7 +471,7 @@
x:Name="combPermission"
Width="140"
DisplayMemberPath="StringPermission"
ItemsSource="{Binding DataContext.PermissionDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
ItemsSource="{Binding DataContext.PermissionTrueFalseDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
SelectedIndex="{Binding DisplayIndexPermission}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
@ -501,28 +501,28 @@
<Button
Width="80"
Height="25"
Command="{Binding btnAddRoleCommand}"
Command="{Binding BtnAddRoleCommand}"
Content="Create"
Style="{StaticResource ViewEnabledBtn}" />
<Button
Width="80"
Height="25"
Margin="10,0,0,0"
Command="{Binding btnDeleteRoleCommand}"
Command="{Binding BtnDeleteRoleCommand}"
Content="Delete"
Style="{StaticResource ViewEnabledBtn}" />
<Button
Width="80"
Height="25"
Margin="10,0,0,0"
Command="{Binding btnCloneRoleCommand}"
Command="{Binding BtnCloneRoleCommand}"
Content="Clone"
Style="{StaticResource ViewEnabledBtn}" />
<Button
Width="80"
Height="25"
Margin="10,0,0,0"
Command="{Binding btnSaveCommand}"
Command="{Binding BtnSaveCommand}"
Content="Save"
Style="{StaticResource EditEnabledBtn}" />
<Button

View File

@ -14,28 +14,67 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
public class RoleViewModel : BaseModel
{
public bool IsPermission { get => this.Permission == 3; }
#region Variables
private bool _IsEnabledRoleName = false;
public bool IsEnabledRoleName
{
get { return _IsEnabledRoleName; }
set { _IsEnabledRoleName = value; NotifyOfPropertyChange("IsEnabledRoleName"); }
}
private bool _isEnabledRoleName;
private RoleItem _treeSelectedRole;
private CtrlMode _controlMode = CtrlMode.VIEW;
#endregion
#region Constructors
public RoleViewModel()
{
this.DisplayName = "Role";
DisplayName = "Role";
}
#endregion
protected override void OnInitialize()
#region Properties
/// <summary>
/// 返回当前视图是否具有访问权限
/// </summary>
public bool IsPermission => Permission == 3;
public bool IsEnabledRoleName
{
base.OnInitialize();
get => _isEnabledRoleName;
set { _isEnabledRoleName = value; NotifyOfPropertyChange("IsEnabledRoleName"); }
}
public static RoleManager RoleManager => RoleManager.Instance;
public ObservableCollection<PermissionType> PermissionDictionary => RolePermissionMapper.Instance.PermissionDictionary;
public ObservableCollection<PermissionType> PermissionTrueFalseDictionary => RolePermissionTrueFalseMapper.Instance.PermissionDictionary;
public ObservableCollection<RoleItem> RoleList { get; } = new();
public RoleItem TreeSelectedRole
{
get => _treeSelectedRole;
set
{
_treeSelectedRole = value;
NotifyOfPropertyChange("TreeSelectedRole");
}
}
public CtrlMode ControlMode
{
get => _controlMode;
set { _controlMode = value; NotifyOfPropertyChange(); }
}
#endregion
#region Methods
protected override void OnActivate()
{
_RolesList.Clear();
_TreeSelectedRole = null;
RoleList.Clear();
_treeSelectedRole = null;
RoleManager.Initialize();
LoadRoleList();
@ -60,10 +99,10 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
public void OnRoleChanged()
{
string[] RoleNameList = { "管理员", "设备工程师", "工艺工程师", "操作员" };
string _RoleName = RoleNameList.Contains(TreeSelectedRole.DisplayRoleName) ? TreeSelectedRole.DisplayRoleName : "";
var roleNameList = new[] { "管理员", "设备工程师", "工艺工程师", "操作员" };
var roleName = roleNameList.Contains(TreeSelectedRole.DisplayRoleName) ? TreeSelectedRole.DisplayRoleName : "";
IsEnabledRoleName = true;
if (!string.IsNullOrEmpty(_RoleName))
if (!string.IsNullOrEmpty(roleName))
IsEnabledRoleName = false;
if (ControlMode == CtrlMode.EDIT)
@ -75,16 +114,16 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
}
//check role to set the mode from view to edit
if (_TreeSelectedRole != null && _TreeSelectedRole.IsRoleChanged())
if (_treeSelectedRole != null && _treeSelectedRole.IsRoleChanged())
ControlMode = CtrlMode.EDIT;
}
public bool OnAutoLogoutTimeChecked(object sender)
{
ControlMode = CtrlMode.EDIT;
return ((CheckBox)(sender)).IsChecked.Value;
}
private bool SaveChanged()
{
if (String.IsNullOrWhiteSpace(TreeSelectedRole.DisplayRoleName))
@ -100,22 +139,22 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
return false;
}
foreach (MenuInfo menu in TreeSelectedRole.MenuCollection)
foreach (var menu in TreeSelectedRole.MenuCollection)
{
menu.IndexPermission = menu.DisplayIndexPermission + 1;
}
foreach (RecipeInfo recipe in TreeSelectedRole.RecipeCollection)
foreach (var recipe in TreeSelectedRole.RecipeCollection)
{
recipe.IndexPermission = recipe.DisplayIndexPermission + 1;
}
foreach (StepInfo step in TreeSelectedRole.RecipeStepCollection)
foreach (var step in TreeSelectedRole.RecipeStepCollection)
{
step.IndexPermission = step.DisplayIndexPermission + 1;
}
foreach (ContentInfo content in TreeSelectedRole.ContentCollection)
foreach (var content in TreeSelectedRole.ContentCollection)
{
content.IndexPermission = content.DisplayIndexPermission + 1;
}
@ -137,8 +176,8 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
}
return true;
}
private Boolean IsRoleExists(RoleItem role)
private bool IsRoleExists(RoleItem role)
{
if (RoleList == null || RoleList.Count == 0)
return false;
@ -149,48 +188,50 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
return true;
}
private void LoadRoleList()
{
_RolesList.Clear();
List<RoleItem> roles = RoleManager.GetAllRoles();
RoleList.Clear();
var roles = RoleManager.GetAllRoles();
if (roles == null || roles.Count == 0)
return;
foreach (RoleItem r in roles)
foreach (var r in roles)
{
RoleItem treeRole = RoleManager.CloneRole(r);
var treeRole = RoleManager.CloneRole(r);
if (treeRole != null)
{
_RolesList.Add(treeRole);
RoleList.Add(treeRole);
}
}
TreeSelectedRole = _RolesList.FirstOrDefault();
TreeSelectedRole = RoleList.FirstOrDefault();
TreeSelectedRole.IsSelected = true;
ControlMode = CtrlMode.VIEW;
}
private void OnRoleTreeSelectedChanged(EventCommandParameter<object, RoutedEventArgs> arg)
{
RoleItem roleItem = arg.CustomParameter as RoleItem;
var roleItem = arg.CustomParameter as RoleItem;
if (roleItem == null)
return;
TreeSelectedRole = roleItem;
}
private void OnBtnAddRoleCommand(Object arg)
{
RoleItem newRole = RoleManager.CreateRole();
var newRole = RoleManager.CreateRole();
if (newRole != null)
{
_RolesList.Add(newRole);
RoleList.Add(newRole);
TreeSelectedRole = newRole;
TreeSelectedRole.IsSelected = true;
}
ControlMode = CtrlMode.EDIT;
}
private void OnBtnDeleteRoleCommand(Object arg)
{
List<string> lstRoleCanNotDelete = new List<string>() { "管理员", "设备工程师", "工艺工程师", "操作员" };
var lstRoleCanNotDelete = new List<string>() { "管理员", "设备工程师", "工艺工程师", "操作员" };
if (TreeSelectedRole == null) return;
if (lstRoleCanNotDelete.Contains(TreeSelectedRole.DisplayRoleName))
@ -211,7 +252,7 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
}
if(TreeSelectedRole.RoleId == "0" || TreeSelectedRole.RoleId == "1" ||
TreeSelectedRole.RoleId == "2" || TreeSelectedRole.RoleId == "3")
TreeSelectedRole.RoleId == "2" || TreeSelectedRole.RoleId == "3")
{
DialogBox.ShowWarning("Can not delete a fixed role");
return;
@ -219,11 +260,11 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
try
{
int index = _RolesList.IndexOf(TreeSelectedRole);
_RolesList.Remove(TreeSelectedRole);
var index = RoleList.IndexOf(TreeSelectedRole);
RoleList.Remove(TreeSelectedRole);
RoleManager.DeleteRole(TreeSelectedRole.RoleId);
index = index > 1 ? index - 1 : 0;
TreeSelectedRole = _RolesList == null ? null : _RolesList[index];
TreeSelectedRole = RoleList == null ? null : RoleList[index];
TreeSelectedRole.IsSelected = true;
DialogBox.ShowInfo("Operated successfully.");
}
@ -233,21 +274,23 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
DialogBox.ShowInfo("Operation failed.");
}
}
private void OnBtnCloneRoleCommand(Object arg)
{
if (_TreeSelectedRole != null)
if (_treeSelectedRole != null)
{
RoleItem newRole = RoleManager.CreateRole(_TreeSelectedRole);
var newRole = RoleManager.CreateRole(_treeSelectedRole);
if (newRole != null)
{
newRole.DisplayRoleName = newRole.RoleName = "Copy of " + newRole.DisplayRoleName;
_RolesList.Add(newRole);
RoleList.Add(newRole);
TreeSelectedRole = newRole;
TreeSelectedRole.IsSelected = true;
ControlMode = CtrlMode.EDIT;
}
}
}
private void OnBtnSaveCommand(Object arg)
{
try
@ -266,112 +309,94 @@ namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
DialogBox.ShowInfo("Operation failed.");
}
}
private void OnBtnCancelRoleCommand(Object arg)
{
LoadRoleList();
ControlMode = CtrlMode.VIEW;
}
#endregion
#region commands
private ICommand _RoleTreeSelectChangedCmd;
private ICommand _roleTreeSelectChangedCmd;
public ICommand RoleTreeSelectChangedCommand
{
get
{
if (this._RoleTreeSelectChangedCmd == null)
this._RoleTreeSelectChangedCmd = new BaseCommand<EventCommandParameter<object, RoutedEventArgs>>((EventCommandParameter<object, RoutedEventArgs> arg) => this.OnRoleTreeSelectedChanged(arg));
return this._RoleTreeSelectChangedCmd;
if (_roleTreeSelectChangedCmd == null)
_roleTreeSelectChangedCmd = new BaseCommand<EventCommandParameter<object, RoutedEventArgs>>((EventCommandParameter<object, RoutedEventArgs> arg) => OnRoleTreeSelectedChanged(arg));
return _roleTreeSelectChangedCmd;
}
}
private ICommand _BtnSaveCommand;
public ICommand btnSaveCommand
private ICommand _btnSaveCommand;
public ICommand BtnSaveCommand
{
get
{
if (this._BtnSaveCommand == null)
this._BtnSaveCommand = new BaseCommand<Object>((Object arg) => this.OnBtnSaveCommand(arg));
return this._BtnSaveCommand;
if (_btnSaveCommand == null)
_btnSaveCommand = new BaseCommand<Object>((Object arg) => OnBtnSaveCommand(arg));
return _btnSaveCommand;
}
}
private ICommand _BtnAddRoleCommand;
public ICommand btnAddRoleCommand
private ICommand _btnAddRoleCommand;
public ICommand BtnAddRoleCommand
{
get
{
if (this._BtnAddRoleCommand == null)
this._BtnAddRoleCommand = new BaseCommand<Object>((Object arg) => this.OnBtnAddRoleCommand(arg));
return this._BtnAddRoleCommand;
if (_btnAddRoleCommand == null)
_btnAddRoleCommand = new BaseCommand<Object>((Object arg) => OnBtnAddRoleCommand(arg));
return _btnAddRoleCommand;
}
}
private ICommand _BtnDeleteRoleCommand;
public ICommand btnDeleteRoleCommand
private ICommand _btnDeleteRoleCommand;
public ICommand BtnDeleteRoleCommand
{
get
{
if (this._BtnDeleteRoleCommand == null)
this._BtnDeleteRoleCommand = new BaseCommand<Object>((Object arg) => this.OnBtnDeleteRoleCommand(arg));
return this._BtnDeleteRoleCommand;
if (_btnDeleteRoleCommand == null)
_btnDeleteRoleCommand = new BaseCommand<Object>((Object arg) => OnBtnDeleteRoleCommand(arg));
return _btnDeleteRoleCommand;
}
}
private ICommand _BtnCloneRoleCommand;
public ICommand btnCloneRoleCommand
private ICommand _btnCloneRoleCommand;
public ICommand BtnCloneRoleCommand
{
get
{
if (this._BtnCloneRoleCommand == null)
this._BtnCloneRoleCommand = new BaseCommand<Object>((Object arg) => this.OnBtnCloneRoleCommand(arg));
return this._BtnCloneRoleCommand;
if (_btnCloneRoleCommand == null)
_btnCloneRoleCommand = new BaseCommand<Object>((Object arg) => OnBtnCloneRoleCommand(arg));
return _btnCloneRoleCommand;
}
}
private ICommand _BtnCancelRoleCommand;
private ICommand _btnCancelRoleCommand;
public ICommand BtnCancelRoleCommand
{
get
{
if (this._BtnCancelRoleCommand == null)
this._BtnCancelRoleCommand = new BaseCommand<Object>((Object arg) => this.OnBtnCancelRoleCommand(arg));
return this._BtnCancelRoleCommand;
if (_btnCancelRoleCommand == null)
_btnCancelRoleCommand = new BaseCommand<Object>((Object arg) => OnBtnCancelRoleCommand(arg));
return _btnCancelRoleCommand;
}
}
#endregion
public RoleManager RoleManager
{
get { return RoleManager.Instance; }
}
public ObservableCollection<PermissionType> PermissionDictionary
{
get { return RolePermissionMapper.Instance.PermissionDictionary; }
}
private ObservableCollection<RoleItem> _RolesList = new ObservableCollection<RoleItem>();
public ObservableCollection<RoleItem> RoleList
{
get { return _RolesList; }
}
private RoleItem _TreeSelectedRole = null;
public RoleItem TreeSelectedRole
{
get { return _TreeSelectedRole; }
set
{
_TreeSelectedRole = value;
this.NotifyOfPropertyChange("TreeSelectedRole");
}
}
private CtrlMode _ControlMode = CtrlMode.VIEW;
public CtrlMode ControlMode
{
get { return _ControlMode; }
set { _ControlMode = value; NotifyOfPropertyChange("ControlMode"); }
}
}
}

View File

@ -206,7 +206,9 @@
<Compile Include="CenterViews\Configs\Roles\ContentInfo.cs" />
<Compile Include="CenterViews\Configs\Roles\MenuInfo.cs" />
<Compile Include="CenterViews\Configs\Roles\PermissionException.cs" />
<Compile Include="CenterViews\Configs\Roles\PermissionType.cs" />
<Compile Include="CenterViews\Configs\Roles\RecipeInfo.cs" />
<Compile Include="CenterViews\Configs\Roles\RolePermissionTrueFalseMapper.cs" />
<Compile Include="CenterViews\Configs\Roles\StepInfo.cs" />
<Compile Include="CenterViews\Configs\SignalTowerConfig\RadioCheckBox.xaml.cs">
<DependentUpon>RadioCheckBox.xaml</DependentUpon>