Files
BeWoPlaner/BeWo/ViewModel/AiPromptbausteinFolderVM.cs

302 lines
7.2 KiB
C#
Raw Normal View History

2025-12-30 11:30:01 +01:00
using System;
2026-01-22 14:14:57 +01:00
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
2025-12-30 11:30:01 +01:00
using System.Windows;
using BeWo.ViewModel.ListViewModel;
using BS.Shared;
2025-12-30 12:35:43 +01:00
using BS.Shared.DataContracts.Compact;
2026-01-23 16:28:47 +01:00
using BS.Shared.DataContracts.Feature.AI;
2025-12-30 11:30:01 +01:00
namespace BeWo.ViewModel
{
public class AiPromptbausteinFolderVM : AbstractDCMapperVM<AiPromptbausteinFolderDC>
{
private string _Title;
private string _Description;
private long? _ParentFolderOid;
2025-12-30 12:35:43 +01:00
private CompactEmployeeDC _Creator;
private bool _IsPublic;
2025-12-30 11:30:01 +01:00
private int _Position;
private bool _IsExpanded;
2026-01-02 11:37:30 +01:00
private AiActionType _ActionType;
2025-12-30 11:30:01 +01:00
private AiPromptbausteinFolderListVM _SubFolders;
private AiPromptbausteinPromptListVM _SubPrompts;
private AiPromptbausteinRoutineListVM _SubRoutines;
2025-12-30 11:30:01 +01:00
public AiPromptbausteinFolderVM(AiPromptbausteinFolderDC dc) : base(dc, dc.Oid)
{
}
public string Title
{
get => _Title;
2026-01-02 11:37:30 +01:00
set
{
var success = SetProperty(ref _Title, value, nameof(Title), () => DataContract.Title);
if (!success)
return;
}
2025-12-30 11:30:01 +01:00
}
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);
}
2025-12-30 12:35:43 +01:00
public CompactEmployeeDC Creator
2025-12-30 11:30:01 +01:00
{
2025-12-30 12:35:43 +01:00
get => DataContract.Creator;
set => SetProperty(ref _Creator, value, nameof(Creator), () => DataContract.Creator);
2025-12-30 11:30:01 +01:00
}
2025-12-30 12:35:43 +01:00
public bool IsPublic
2025-12-30 11:30:01 +01:00
{
2025-12-30 12:35:43 +01:00
get => _IsPublic;
set => SetProperty(ref _IsPublic, value, nameof(IsPublic), () => DataContract.IsPublic);
2025-12-30 11:30:01 +01:00
}
public int Position
{
get => _Position;
set => SetProperty(ref _Position, value, nameof(Position), () => DataContract.Position);
}
public bool IsExpanded
{
get => _IsExpanded;
2026-01-12 16:53:47 +01:00
set => SetProperty(ref _IsExpanded, value, nameof(IsExpanded));
2025-12-30 11:30:01 +01:00
}
public AiActionType ActionType
{
get => _ActionType;
set => SetProperty(ref _ActionType, value, nameof(ActionType), () => DataContract.ActionType);
}
public AiPromptbausteinFolderListVM SubFolders
{
get => _SubFolders;
2026-05-12 11:47:04 +02:00
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));
};
}
2025-12-30 11:30:01 +01:00
}
public AiPromptbausteinPromptListVM SubPrompts
{
get => _SubPrompts;
2026-01-02 11:37:30 +01:00
set
{
var success = SetProperty(ref _SubPrompts, value, nameof(SubPrompts));
if (!success)
return;
2026-02-03 15:15:32 +01:00
_SubPrompts.VMList.ListChanged += (s, e) => {
FirePropertyChanged(nameof(TotalPromptCount));
FirePropertyChanged(nameof(AlleFolderItems));
if (e.ListChangedType == System.ComponentModel.ListChangedType.ItemChanged)
return;
2026-02-03 15:15:32 +01:00
FirePropertyChanged(nameof(Prompts));
};
2026-01-02 11:37:30 +01:00
}
2025-12-30 11:30:01 +01:00
}
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();
}
}
2026-01-22 14:14:57 +01:00
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;
}
}
2026-01-12 16:53:47 +01:00
public bool CanAddFolder
2026-01-02 11:37:30 +01:00
{
2026-01-12 16:53:47 +01:00
get => DataContract.CanAddFolder;
set => DataContract.CanAddFolder = value;
}
public bool CanAddPrompt
{
get => DataContract.CanAddPrompt;
set => DataContract.CanAddPrompt = value;
2025-12-30 14:43:25 +01:00
}
public bool CanAddRoutine
{
get => DataContract.CanAddRoutine;
set => DataContract.CanAddRoutine = value;
}
2025-12-30 14:43:25 +01:00
public bool CanEdit
{
2026-03-04 15:36:55 +01:00
get => DataContract.CanEdit && BeWoApp.HasLoggedOnUserRight(UserRightType.AiModulePromptbausteineEdit);
2025-12-30 14:43:25 +01:00
set => DataContract.CanEdit = value;
}
2026-01-12 16:53:47 +01:00
public bool IsNewFeature
{
get => DataContract.IsNewFeature;
}
public bool IsEnabled
{
get => !IsNewFeature;
}
2025-12-30 12:48:57 +01:00
public AiPromptbausteinFolderVM Parent { get; set; }
2026-01-16 13:33:59 +01:00
public FontWeight FontWeight => !IsNew && Parent is null ? FontWeights.SemiBold : FontWeights.Medium;
public bool HasSubFolders => SubFolders is object && SubFolders.Count > 0;
public int TotalPromptCount
2026-01-02 11:37:30 +01:00
{
get
{
var total = SubPrompts.Count;
foreach ( var folder in SubFolders.VMList)
2026-01-02 11:37:30 +01:00
{
total += folder.TotalPromptCount;
2026-01-02 11:37:30 +01:00
}
return total;
2026-01-02 11:37:30 +01:00
}
}
2025-12-30 11:30:01 +01:00
public int TotalRoutineCount
2026-01-27 16:58:04 +01:00
{
get
{
var total = SubRoutines.Count;
2026-01-27 16:58:04 +01:00
foreach (var folder in SubFolders.VMList)
2026-01-27 16:58:04 +01:00
{
total += folder.TotalRoutineCount;
2026-01-27 16:58:04 +01:00
}
return total;
}
}
2025-12-30 11:30:01 +01:00
protected override void InitByDataContract(AiPromptbausteinFolderDC pDataContract)
{
_Title = pDataContract.Title;
_Description = pDataContract.Description;
_ParentFolderOid = pDataContract.ParentFolderOid;
2025-12-30 12:35:43 +01:00
_Creator = pDataContract.Creator;
_IsPublic = pDataContract.IsPublic;
2025-12-30 11:30:01 +01:00
_Position = pDataContract.Position;
_IsExpanded = pDataContract.IsExpanded;
_ActionType = pDataContract.ActionType;
SubFolders = new AiPromptbausteinFolderListVM(pDataContract.SubFolders, this);
2026-02-03 15:15:32 +01:00
SubPrompts = new AiPromptbausteinPromptListVM(pDataContract.SubPrompts);
SubRoutines = new AiPromptbausteinRoutineListVM(pDataContract.SubRoutines);
2025-12-30 11:30:01 +01:00
}
protected override AiPromptbausteinFolderDC MapToDataContract(AiPromptbausteinFolderDC pDataContract, bool doCommit)
{
pDataContract.Title = _Title;
pDataContract.Description = _Description;
pDataContract.ParentFolderOid = _ParentFolderOid;
2025-12-30 12:35:43 +01:00
pDataContract.Creator = _Creator;
pDataContract.IsPublic = _IsPublic;
2025-12-30 11:30:01 +01:00
pDataContract.Position = _Position;
pDataContract.ActionType = _ActionType;
pDataContract.SubFolders = _SubFolders.CopyToDCList(doCommit);
pDataContract.SubPrompts = _SubPrompts.CopyToDCList(doCommit);
pDataContract.SubRoutines = _SubRoutines.CopyToDCList(doCommit);
2025-12-30 11:30:01 +01:00
return pDataContract;
}
2025-12-30 12:35:43 +01:00
public override void UpdateByDataContract(AiPromptbausteinFolderDC pDataContract)
{
2026-05-12 11:47:04 +02:00
DataContract = pDataContract;
2025-12-30 12:35:43 +01:00
Title = pDataContract.Title;
Description = pDataContract.Description;
IsPublic = pDataContract.IsPublic;
}
2025-12-30 11:30:01 +01:00
}
}