|
1 | 1 | // -------------------------------------------------------------------------------------------------------------------- |
2 | 2 | // <copyright file="ThingStatus.cs" company="Starion Group S.A."> |
3 | | -// Copyright (c) 2015-2020 Starion Group S.A. |
| 3 | +// Copyright (c) 2015-2025 Starion Group S.A. |
4 | 4 | // |
5 | 5 | // Author: Sam Gerené, Alex Vorobiev, Merlin Bieze, Naron Phou, Patxi Ozkoidi, Alexander van Delft, Mihail Militaru |
6 | 6 | // Nathanael Smiechowski, Kamil Wojnowski |
|
27 | 27 | namespace CDP4Composition.Mvvm |
28 | 28 | { |
29 | 29 | using System.Linq; |
| 30 | + |
30 | 31 | using CDP4Common.CommonData; |
31 | 32 |
|
| 33 | + using ReactiveUI; |
| 34 | + |
32 | 35 | /// <summary> |
33 | 36 | /// A class that gives information on the status of a <see cref="Thing"/> |
34 | 37 | /// </summary> |
35 | | - public class ThingStatus |
| 38 | + public class ThingStatus : ReactiveObject |
36 | 39 | { |
| 40 | + /// <summary> |
| 41 | + /// Backing field for <see cref="IsLocked"/> |
| 42 | + /// </summary> |
| 43 | + private bool isLocked = false; |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Backing field for <see cref="IsHidden"/> |
| 47 | + /// </summary> |
| 48 | + private bool isHidden = false; |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Backing field for <see cref="IsFavorite"/> |
| 52 | + /// </summary> |
| 53 | + private bool isFavorite = false; |
| 54 | + |
37 | 55 | /// <summary> |
38 | 56 | /// Initializes a new instace of the <see cref="ThingStatus"/> class |
39 | 57 | /// </summary> |
40 | 58 | /// <param name="thing">The <see cref="Thing"/></param> |
41 | | - public ThingStatus(Thing thing) |
| 59 | + private ThingStatus(Thing thing) |
42 | 60 | { |
43 | 61 | this.Thing = thing; |
44 | 62 | this.HasError = thing.ValidationErrors.Any(); |
45 | 63 | this.HasRelationship = thing.HasRelationship; |
46 | 64 | } |
47 | 65 |
|
| 66 | + /// <summary> |
| 67 | + /// Updates the status of the <see cref="ThingStatus"/> |
| 68 | + /// </summary> |
| 69 | + /// <param name="thing">The <see cref="Thing"/></param> |
| 70 | + public static ThingStatus CreateNewThingStatus(Thing thing) |
| 71 | + { |
| 72 | + return new ThingStatus(thing); |
| 73 | + } |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// Updates the status of the <see cref="ThingStatus"/> |
| 77 | + /// </summary> |
| 78 | + /// <param name="viewModel">The viewmodel where the ThingStatus should be present on</param> |
| 79 | + /// <param name="thing">The <see cref="Thing"/></param> |
| 80 | + public static void SetOrUpdateThingStatus(IHaveThingStatus viewModel, Thing thing) |
| 81 | + { |
| 82 | + if (viewModel.ThingStatus == null) |
| 83 | + { |
| 84 | + viewModel.ThingStatus = CreateNewThingStatus(thing); |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + viewModel.ThingStatus.Thing = thing; |
| 89 | + viewModel.ThingStatus.HasError = thing.ValidationErrors.Any(); |
| 90 | + viewModel.ThingStatus.HasRelationship = thing.HasRelationship; |
| 91 | + } |
| 92 | + } |
| 93 | + |
48 | 94 | /// <summary> |
49 | 95 | /// Gets the <see cref="Thing"/> |
50 | 96 | /// </summary> |
51 | | - public Thing Thing { get; } |
| 97 | + public Thing Thing { get; private set; } |
52 | 98 |
|
53 | 99 | /// <summary> |
54 | 100 | /// Asserts whether the <see cref="Thing"/> has errors |
55 | 101 | /// </summary> |
56 | | - public bool HasError { get; } |
| 102 | + public bool HasError { get; private set; } |
57 | 103 |
|
58 | 104 | /// <summary> |
59 | 105 | /// Gets a value indicating whether the thing has associated relationships |
60 | 106 | /// </summary> |
61 | | - public bool HasRelationship { get; } |
| 107 | + public bool HasRelationship { get; private set; } |
62 | 108 |
|
63 | 109 | /// <summary> |
64 | 110 | /// Gets or sets a value indicating whether the thing is marked as a user's favorite |
65 | 111 | /// </summary> |
66 | | - public bool IsFavorite { get; set; } = false; |
| 112 | + public bool IsFavorite |
| 113 | + { |
| 114 | + get => this.isFavorite; |
| 115 | + set => this.RaiseAndSetIfChanged(ref this.isFavorite, value); |
| 116 | + } |
67 | 117 |
|
68 | 118 | /// <summary> |
69 | 119 | /// Gets or sets a value indicating whether the thing is marked as locked |
70 | 120 | /// </summary> |
71 | | - public bool IsLocked { get; set; } = false; |
| 121 | + public bool IsLocked |
| 122 | + { |
| 123 | + get => this.isLocked; |
| 124 | + set => this.RaiseAndSetIfChanged(ref this.isLocked, value); |
| 125 | + } |
72 | 126 |
|
73 | 127 | /// <summary> |
74 | 128 | /// Gets or sets a value indicating whether the thing is marked as hidden |
75 | 129 | /// </summary> |
76 | | - public bool IsHidden { get; set; } = false; |
| 130 | + public bool IsHidden |
| 131 | + { |
| 132 | + get => this.isHidden; |
| 133 | + set => this.RaiseAndSetIfChanged(ref this.isHidden, value); |
| 134 | + } |
77 | 135 | } |
78 | 136 | } |
0 commit comments