328 lines
8.0 KiB
C#
328 lines
8.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using BeWo.ViewModel.ListViewModel;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.DataContracts.Feature.AI;
|
|
|
|
namespace BeWo.ViewModel
|
|
{
|
|
public class AiPromptbausteinFolderVM : AbstractDCMapperVM<AiPromptbausteinFolderDC>
|
|
{
|
|
private string _Title;
|
|
private string _Description;
|
|
private long? _ParentFolderOid;
|
|
private CompactEmployeeDC _Creator;
|
|
private bool _IsPublic;
|
|
private int _Position;
|
|
private bool _IsExpanded;
|
|
private bool _IsSelected;
|
|
private AiActionType _ActionType;
|
|
private AiPromptbausteinFolderListVM _SubFolders;
|
|
private AiPromptbausteinPromptListVM _SubPrompts;
|
|
private AiPromptbausteinRoutineListVM _SubRoutines;
|
|
private bool _CanAddFolder;
|
|
private bool _CanAddPrompt;
|
|
private bool _CanAddRoutine;
|
|
private bool _CanEdit;
|
|
|
|
public AiPromptbausteinFolderVM(AiPromptbausteinFolderDC dc) : base(dc, dc.Oid)
|
|
{
|
|
|
|
}
|
|
|
|
public string Title
|
|
{
|
|
get => _Title;
|
|
set
|
|
{
|
|
var success = SetProperty(ref _Title, value, nameof(Title), () => DataContract.Title);
|
|
if (!success)
|
|
return;
|
|
}
|
|
}
|
|
|
|
public string Description
|
|
{
|
|
get => _Description;
|
|
set => SetProperty(ref _Description, value, nameof(Description), () => DataContract.Description);
|
|
}
|
|
|
|
public long? ParentFolderOid
|
|
{
|
|
get => _ParentFolderOid;
|
|
set => SetProperty(ref _ParentFolderOid, value, nameof(ParentFolderOid), () => DataContract.ParentFolderOid);
|
|
}
|
|
|
|
public CompactEmployeeDC Creator
|
|
{
|
|
get => _Creator;
|
|
set => SetProperty(ref _Creator, value, nameof(Creator), () => DataContract.Creator);
|
|
}
|
|
|
|
public bool IsPublic
|
|
{
|
|
get => _IsPublic;
|
|
set => SetProperty(ref _IsPublic, value, nameof(IsPublic), () => DataContract.IsPublic);
|
|
}
|
|
|
|
public int Position
|
|
{
|
|
get => _Position;
|
|
set => SetProperty(ref _Position, value, nameof(Position), () => DataContract.Position);
|
|
}
|
|
|
|
public bool IsExpanded
|
|
{
|
|
get => _IsExpanded;
|
|
set => SetProperty(ref _IsExpanded, value, nameof(IsExpanded));
|
|
}
|
|
|
|
public bool IsSelected
|
|
{
|
|
get => _IsSelected;
|
|
set => SetProperty(ref _IsSelected, value, nameof(IsSelected));
|
|
}
|
|
|
|
public AiActionType ActionType
|
|
{
|
|
get => _ActionType;
|
|
set => SetProperty(ref _ActionType, value, nameof(ActionType), () => DataContract.ActionType);
|
|
}
|
|
|
|
public bool CanAddFolder
|
|
{
|
|
get => _CanAddFolder;
|
|
set => SetProperty(ref _CanAddFolder, value, nameof(CanAddFolder));
|
|
}
|
|
public bool CanAddPrompt
|
|
{
|
|
get => _CanAddPrompt;
|
|
set => SetProperty(ref _CanAddPrompt, value, nameof(CanAddPrompt));
|
|
}
|
|
public bool CanAddRoutine
|
|
{
|
|
get => _CanAddRoutine;
|
|
set => SetProperty(ref _CanAddRoutine, value, nameof(CanAddRoutine));
|
|
}
|
|
public bool CanEdit
|
|
{
|
|
get => _CanEdit;
|
|
set => SetProperty(ref _CanEdit, value && BeWoApp.HasLoggedOnUserRight(UserRightType.AiModulePromptbausteineEdit), nameof(CanEdit));
|
|
}
|
|
|
|
public AiPromptbausteinFolderListVM SubFolders
|
|
{
|
|
get => _SubFolders;
|
|
set
|
|
{
|
|
var success = SetProperty(ref _SubFolders, value, nameof(SubFolders));
|
|
if (!success)
|
|
return;
|
|
|
|
_SubFolders.VMList.ListChanged += (s, e) => {
|
|
FirePropertyChanged(nameof(TotalPromptCount));
|
|
FirePropertyChanged(nameof(TotalRoutineCount));
|
|
FirePropertyChanged(nameof(AlleFolderItems));
|
|
|
|
if (e.ListChangedType == System.ComponentModel.ListChangedType.ItemChanged)
|
|
return;
|
|
|
|
FirePropertyChanged(nameof(Prompts));
|
|
FirePropertyChanged(nameof(Routines));
|
|
};
|
|
}
|
|
}
|
|
|
|
public AiPromptbausteinPromptListVM SubPrompts
|
|
{
|
|
get => _SubPrompts;
|
|
set
|
|
{
|
|
var success = SetProperty(ref _SubPrompts, value, nameof(SubPrompts));
|
|
if (!success)
|
|
return;
|
|
|
|
_SubPrompts.VMList.ListChanged += (s, e) => {
|
|
FirePropertyChanged(nameof(TotalPromptCount));
|
|
FirePropertyChanged(nameof(AlleFolderItems));
|
|
|
|
if (e.ListChangedType == System.ComponentModel.ListChangedType.ItemChanged)
|
|
return;
|
|
|
|
FirePropertyChanged(nameof(Prompts));
|
|
};
|
|
}
|
|
}
|
|
|
|
public AiPromptbausteinRoutineListVM SubRoutines
|
|
{
|
|
get => _SubRoutines;
|
|
set
|
|
{
|
|
var success = SetProperty(ref _SubRoutines, value, nameof(SubRoutines));
|
|
if (!success)
|
|
return;
|
|
|
|
_SubRoutines.VMList.ListChanged += (s, e) => {
|
|
FirePropertyChanged(nameof(TotalRoutineCount));
|
|
FirePropertyChanged(nameof(AlleFolderItems));
|
|
|
|
if (e.ListChangedType == System.ComponentModel.ListChangedType.ItemChanged)
|
|
return;
|
|
|
|
FirePropertyChanged(nameof(Routines));
|
|
};
|
|
}
|
|
}
|
|
|
|
public List<AbstractBaseVM> AlleFolderItems
|
|
{
|
|
get
|
|
{
|
|
var l1 = Prompts.Cast<AbstractBaseVM>();
|
|
var l2 = Routines.Cast<AbstractBaseVM>();
|
|
|
|
var l12 = l1.Union(l2);
|
|
|
|
return l12.ToList();
|
|
}
|
|
}
|
|
|
|
public List<AiPromptbausteinPromptVM> Prompts
|
|
{
|
|
get
|
|
{
|
|
var res = new List<AiPromptbausteinPromptVM>();
|
|
|
|
res.AddRange(SubPrompts.VMList);
|
|
|
|
foreach (var folder in SubFolders.VMList)
|
|
{
|
|
res.AddRange(folder.Prompts);
|
|
}
|
|
|
|
return res;
|
|
}
|
|
}
|
|
|
|
public List<AiPromptbausteinRoutineVM> Routines
|
|
{
|
|
get
|
|
{
|
|
var res = new List<AiPromptbausteinRoutineVM>();
|
|
|
|
res.AddRange(SubRoutines.VMList);
|
|
|
|
foreach (var folder in SubFolders.VMList)
|
|
{
|
|
res.AddRange(folder.Routines);
|
|
}
|
|
|
|
return res;
|
|
}
|
|
}
|
|
|
|
public bool IsNewFeature
|
|
{
|
|
get => DataContract.IsNewFeature;
|
|
}
|
|
public bool IsEnabled
|
|
{
|
|
get => !IsNewFeature;
|
|
}
|
|
|
|
public bool CanShareEdit
|
|
{
|
|
get => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModulePromptbausteinShare)
|
|
&& Creator?.EmployeeOid is long owner
|
|
&& owner == BeWoApp.CompactLoggedOnEmployee.EmployeeOid
|
|
&& CanEdit;
|
|
}
|
|
|
|
public AiPromptbausteinFolderVM Parent { get; set; }
|
|
|
|
public FontWeight FontWeight => !IsNew && Parent is null ? FontWeights.SemiBold : FontWeights.Medium;
|
|
public bool HasSubFolders => SubFolders is object && SubFolders.Count > 0;
|
|
|
|
public int TotalPromptCount
|
|
{
|
|
get
|
|
{
|
|
var total = SubPrompts.Count;
|
|
|
|
foreach ( var folder in SubFolders.VMList)
|
|
{
|
|
total += folder.TotalPromptCount;
|
|
}
|
|
|
|
return total;
|
|
}
|
|
}
|
|
|
|
public int TotalRoutineCount
|
|
{
|
|
get
|
|
{
|
|
var total = SubRoutines.Count;
|
|
|
|
foreach (var folder in SubFolders.VMList)
|
|
{
|
|
total += folder.TotalRoutineCount;
|
|
}
|
|
|
|
return total;
|
|
}
|
|
}
|
|
|
|
protected override void InitByDataContract(AiPromptbausteinFolderDC pDataContract)
|
|
{
|
|
_Title = pDataContract.Title;
|
|
_Description = pDataContract.Description;
|
|
_ParentFolderOid = pDataContract.ParentFolderOid;
|
|
_Creator = pDataContract.Creator;
|
|
_IsPublic = pDataContract.IsPublic;
|
|
_Position = pDataContract.Position;
|
|
_IsExpanded = pDataContract.IsExpanded;
|
|
_ActionType = pDataContract.ActionType;
|
|
_CanAddFolder = pDataContract.CanAddFolder;
|
|
_CanAddPrompt = pDataContract.CanAddPrompt;
|
|
_CanAddRoutine = pDataContract.CanAddRoutine;
|
|
_CanEdit = pDataContract.CanEdit;
|
|
SubFolders = new AiPromptbausteinFolderListVM(pDataContract.SubFolders, this);
|
|
SubPrompts = new AiPromptbausteinPromptListVM(pDataContract.SubPrompts);
|
|
SubRoutines = new AiPromptbausteinRoutineListVM(pDataContract.SubRoutines);
|
|
}
|
|
|
|
protected override AiPromptbausteinFolderDC MapToDataContract(AiPromptbausteinFolderDC pDataContract, bool doCommit)
|
|
{
|
|
pDataContract.Title = _Title;
|
|
pDataContract.Description = _Description;
|
|
pDataContract.ParentFolderOid = _ParentFolderOid;
|
|
pDataContract.Creator = _Creator;
|
|
pDataContract.IsPublic = _IsPublic;
|
|
pDataContract.Position = _Position;
|
|
pDataContract.ActionType = _ActionType;
|
|
pDataContract.SubFolders = _SubFolders.CopyToDCList(doCommit);
|
|
pDataContract.SubPrompts = _SubPrompts.CopyToDCList(doCommit);
|
|
pDataContract.SubRoutines = _SubRoutines.CopyToDCList(doCommit);
|
|
|
|
return pDataContract;
|
|
}
|
|
|
|
public override void UpdateByDataContract(AiPromptbausteinFolderDC pDataContract)
|
|
{
|
|
if(IsNew)
|
|
IsNew = false;
|
|
|
|
DataContract = pDataContract;
|
|
|
|
Title = pDataContract.Title;
|
|
Description = pDataContract.Description;
|
|
IsPublic = pDataContract.IsPublic;
|
|
}
|
|
}
|
|
} |