[longomatch] Remove dead links when editing subcategories



commit 03b4a24335b5cd52d5f656e9ab8c627119b3858c
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Apr 14 01:44:00 2015 +0200

    Remove dead links when editing subcategories

 LongoMatch.Core/Store/Templates/Dashboard.cs    |    6 ++++--
 LongoMatch.GUI/Gui/Component/DashboardWidget.cs |    6 ++++--
 Tests/Core/Store/Templates/TestDashboard.cs     |    9 ++++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/LongoMatch.Core/Store/Templates/Dashboard.cs b/LongoMatch.Core/Store/Templates/Dashboard.cs
index 5a8bbd6..6513725 100644
--- a/LongoMatch.Core/Store/Templates/Dashboard.cs
+++ b/LongoMatch.Core/Store/Templates/Dashboard.cs
@@ -266,10 +266,12 @@ namespace LongoMatch.Core.Store.Templates
                /// <param name="button">Dashboard button.</param>
                public void RemoveDeadLinks (AnalysisEventButton button)
                {
-
+                       /* Remove all links pointing to a tag that does not exists anymore */
                        foreach (DashboardButton b in List) {
                                b.ActionLinks.RemoveAll (l => l.DestinationButton == button &&
-                               l.DestinationTags.Intersect (button.AnalysisEventType.Tags).Any ());
+                               l.DestinationTags != null &&
+                               l.DestinationTags.Count > 0 &&
+                               !l.DestinationTags.Intersect (button.AnalysisEventType.Tags).Any ());
                        }
                }
 
diff --git a/LongoMatch.GUI/Gui/Component/DashboardWidget.cs b/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
index 2c68113..a0ce6f3 100644
--- a/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
@@ -464,13 +464,15 @@ namespace LongoMatch.Gui.Component
 
                void EditEventSubcategories (DashboardButton dashboardButton)
                {
-                       AnalysisEventType evt = (dashboardButton as AnalysisEventButton).AnalysisEventType;
+                       AnalysisEventButton button = (dashboardButton as AnalysisEventButton); 
+                       AnalysisEventType evt = button.AnalysisEventType;
                        EventTypeTagsEditor dialog = new EventTypeTagsEditor ();
                        dialog.EventType = evt;
                        dialog.Run ();
                        dialog.Destroy ();
-                       template.RemoveDeadLinks (dashboardButton);
+                       template.RemoveDeadLinks (button);
                        Edited = true;
+                       Refresh ();
                }
 
                void HandleResetField (object sender, EventArgs e)
diff --git a/Tests/Core/Store/Templates/TestDashboard.cs b/Tests/Core/Store/Templates/TestDashboard.cs
index 25a9e0b..0a6278d 100644
--- a/Tests/Core/Store/Templates/TestDashboard.cs
+++ b/Tests/Core/Store/Templates/TestDashboard.cs
@@ -104,7 +104,14 @@ namespace Tests.Core.Store.Templates
                        dashboard.RemoveDeadLinks (b2);
                        Assert.AreEqual (1, b1.ActionLinks.Count);
 
-                       b1.ActionLinks [0].DestinationTags = new List<Tag> { b1.AnalysisEventType.Tags [0] };
+                       b1.ActionLinks [0].DestinationTags = new List<Tag> { b2.AnalysisEventType.Tags [0] };
+                       dashboard.RemoveDeadLinks (b2);
+                       Assert.AreEqual (1, b1.ActionLinks.Count);
+
+                       b2.AnalysisEventType.Tags.Remove (b2.AnalysisEventType.Tags [1]);
+                       dashboard.RemoveDeadLinks (b2);
+                       Assert.AreEqual (1, b1.ActionLinks.Count);
+                       b2.AnalysisEventType.Tags.Remove (b2.AnalysisEventType.Tags [0]);
                        dashboard.RemoveDeadLinks (b2);
                        Assert.AreEqual (0, b1.ActionLinks.Count);
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]