Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/26/18 16:33:53 (6 years ago)
Author:
jzenisek
Message:

#2839:

  • replaced use of TreeView with NoDoubleClickTreeView everywhere allegedly reasonable for Hive
  • updated genealogy computation for HiveAdminClient and corresponding views (ResourcesView & ProjectResourcesView)
Location:
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs

    r15819 r15922  
    7070    }
    7171
    72     private Dictionary<Guid, HashSet<Project>> projectAncestors;
    73     public Dictionary<Guid, HashSet<Project>> ProjectAncestors {
     72    //private Dictionary<Guid, HashSet<Project>> projectAncestors;
     73    //public Dictionary<Guid, HashSet<Project>> ProjectAncestors {
     74    //  get { return projectAncestors; }
     75    //}
     76
     77    //private Dictionary<Guid, HashSet<Project>> projectDescendants;
     78    //public Dictionary<Guid, HashSet<Project>> ProjectDescendants {
     79    //  get { return projectDescendants; }
     80    //}
     81
     82    //private Dictionary<Guid, HashSet<Resource>> resourceAncestors;
     83    //public Dictionary<Guid, HashSet<Resource>> ResourceAncestors {
     84    //  get { return resourceAncestors; }
     85    //}
     86
     87    //private Dictionary<Guid, HashSet<Resource>> resourceDescendants;
     88    //public Dictionary<Guid, HashSet<Resource>> ResourceDescendants {
     89    //  get { return resourceDescendants; }
     90    //}
     91
     92    private Dictionary<Guid, HashSet<Guid>> projectAncestors;
     93    public Dictionary<Guid, HashSet<Guid>> ProjectAncestors {
    7494      get { return projectAncestors; }
    7595    }
    7696
    77     private Dictionary<Guid, HashSet<Project>> projectDescendants;
    78     public Dictionary<Guid, HashSet<Project>> ProjectDescendants {
     97    private Dictionary<Guid, HashSet<Guid>> projectDescendants;
     98    public Dictionary<Guid, HashSet<Guid>> ProjectDescendants {
    7999      get { return projectDescendants; }
    80100    }
    81101
    82     private Dictionary<Guid, HashSet<Resource>> resourceAncestors;
    83     public Dictionary<Guid, HashSet<Resource>> ResourceAncestors {
     102    private Dictionary<Guid, HashSet<Guid>> resourceAncestors;
     103    public Dictionary<Guid, HashSet<Guid>> ResourceAncestors {
    84104      get { return resourceAncestors; }
    85105    }
    86106
    87     private Dictionary<Guid, HashSet<Resource>> resourceDescendants;
    88     public Dictionary<Guid, HashSet<Resource>> ResourceDescendants {
     107    private Dictionary<Guid, HashSet<Guid>> resourceDescendants;
     108    public Dictionary<Guid, HashSet<Guid>> ResourceDescendants {
    89109      get { return resourceDescendants; }
    90110    }
    91 
    92 
    93111    #endregion
    94112
     
    117135        projectResourceAssignments = new ItemList<AssignedProjectResource>();
    118136
    119         projectAncestors = new Dictionary<Guid, HashSet<Project>>();
    120         projectDescendants = new Dictionary<Guid, HashSet<Project>>();
    121         resourceAncestors = new Dictionary<Guid, HashSet<Resource>>();
    122         resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();
     137        //projectAncestors = new Dictionary<Guid, HashSet<Project>>();
     138        //projectDescendants = new Dictionary<Guid, HashSet<Project>>();
     139        //resourceAncestors = new Dictionary<Guid, HashSet<Resource>>();
     140        //resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();
     141        projectAncestors = new Dictionary<Guid, HashSet<Guid>>();
     142        projectDescendants = new Dictionary<Guid, HashSet<Guid>>();
     143        resourceAncestors = new Dictionary<Guid, HashSet<Guid>>();
     144        resourceDescendants = new Dictionary<Guid, HashSet<Guid>>();
    123145
    124146        HiveServiceLocator.Instance.CallHiveService(service => {
     
    132154        });
    133155
    134         UpdateResourceGenealogy(resources);
    135         UpdateProjectGenealogy(projects);
     156        UpdateResourceGenealogy();
     157        UpdateProjectGenealogy();
    136158      }
    137159      catch {
     
    143165    }
    144166
    145     public void UpdateResourceGenealogy(IItemList<Resource> resources) {
     167    //public void UpdateResourceGenealogy(IItemList<Resource> resources) {
     168    //  resourceAncestors.Clear();
     169    //  resourceDescendants.Clear();
     170
     171    //  foreach (var r in resources) {
     172    //    resourceAncestors.Add(r.Id, new HashSet<Resource>());
     173    //    resourceDescendants.Add(r.Id, new HashSet<Resource>());
     174    //  }
     175
     176    //  foreach (var r in resources) {
     177    //    var parentResourceId = r.ParentResourceId;
     178    //    while (parentResourceId != null) {
     179    //      var parent = resources.SingleOrDefault(x => x.Id == parentResourceId);
     180    //      if (parent != null) {
     181    //        resourceAncestors[r.Id].Add(parent);
     182    //        resourceDescendants[parent.Id].Add(r);
     183    //        parentResourceId = parent.ParentResourceId;
     184    //      } else {
     185    //        parentResourceId = null;
     186    //      }
     187    //    }
     188    //  }
     189    //}
     190
     191    //public void UpdateProjectGenealogy(IItemList<Project> projects) {
     192    //  projectAncestors.Clear();
     193    //  projectDescendants.Clear();
     194
     195    //  foreach (var p in projects) {
     196    //    projectAncestors.Add(p.Id, new HashSet<Project>());
     197    //    projectDescendants.Add(p.Id, new HashSet<Project>());
     198    //  }
     199
     200    //  foreach (var p in projects) {
     201    //    var parentProjectId = p.ParentProjectId;
     202    //    while (parentProjectId != null) {
     203    //      var parent = projects.SingleOrDefault(x => x.Id == parentProjectId);
     204    //      if (parent != null) {
     205    //        projectAncestors[p.Id].Add(parent);
     206    //        projectDescendants[parent.Id].Add(p);
     207    //        parentProjectId = parent.ParentProjectId;
     208    //      } else {
     209    //        parentProjectId = null;
     210    //      }
     211    //    }
     212    //  }
     213    //}
     214
     215    private void UpdateResourceGenealogy() {
    146216      resourceAncestors.Clear();
    147217      resourceDescendants.Clear();
    148218
    149       foreach (var r in resources) {
    150         resourceAncestors.Add(r.Id, new HashSet<Resource>());
    151         resourceDescendants.Add(r.Id, new HashSet<Resource>());
    152       }
    153 
    154       foreach (var r in resources) {
    155         var parentResourceId = r.ParentResourceId;
    156         while (parentResourceId != null) {
    157           var parent = resources.SingleOrDefault(x => x.Id == parentResourceId);
    158           if (parent != null) {
    159             resourceAncestors[r.Id].Add(parent);
    160             resourceDescendants[parent.Id].Add(r);
    161             parentResourceId = parent.ParentResourceId;
    162           } else {
    163             parentResourceId = null;
    164           }
    165         }
    166       }
    167     }
    168 
    169     public void UpdateProjectGenealogy(IItemList<Project> projects) {
     219      // fetch resource ancestor set
     220      HiveServiceLocator.Instance.CallHiveService(service => {
     221        var ra = service.GetResourceGenealogy();
     222        ra.Keys.ToList().ForEach(k => resourceAncestors.Add(k, new HashSet<Guid>()));
     223        resourceAncestors.Keys.ToList().ForEach(k => resourceAncestors[k].UnionWith(ra[k]));
     224      });
     225
     226      // build resource descendant set
     227      resourceAncestors.Keys.ToList().ForEach(k => resourceDescendants.Add(k, new HashSet<Guid>()));
     228      foreach (var ra in resourceAncestors) {
     229        foreach (var ancestor in ra.Value) {
     230          resourceDescendants[ancestor].Add(ra.Key);
     231        }
     232      }
     233    }
     234
     235    private void UpdateProjectGenealogy() {
    170236      projectAncestors.Clear();
    171237      projectDescendants.Clear();
    172238
    173       foreach (var p in projects) {
    174         projectAncestors.Add(p.Id, new HashSet<Project>());
    175         projectDescendants.Add(p.Id, new HashSet<Project>());
    176       }
    177 
    178       foreach (var p in projects) {
    179         var parentProjectId = p.ParentProjectId;
    180         while (parentProjectId != null) {
    181           var parent = projects.SingleOrDefault(x => x.Id == parentProjectId);
    182           if (parent != null) {
    183             projectAncestors[p.Id].Add(parent);
    184             projectDescendants[parent.Id].Add(p);
    185             parentProjectId = parent.ParentProjectId;
    186           } else {
    187             parentProjectId = null;
    188           }
    189         }
    190       }
    191     }
     239      // fetch project ancestor list
     240      HiveServiceLocator.Instance.CallHiveService(service => {
     241        var pa = service.GetProjectGenealogy();
     242        pa.Keys.ToList().ForEach(k => projectAncestors.Add(k, new HashSet<Guid>()));
     243        projectAncestors.Keys.ToList().ForEach(k => projectAncestors[k].UnionWith(pa[k]));
     244      });
     245
     246      // build project descendant list
     247      projectAncestors.Keys.ToList().ForEach(k => projectDescendants.Add(k, new HashSet<Guid>()));
     248      foreach (var pa in projectAncestors) {
     249        foreach (var ancestor in pa.Value) {
     250          projectDescendants[ancestor].Add(pa.Key);
     251        }
     252      }
     253    }
     254
    192255    #endregion
    193256
     
    268331
    269332    #region Helper
     333    public IEnumerable<Project> GetAvailableProjectAncestors(Guid id) {
     334      if (projectAncestors.ContainsKey(id)) return projects.Where(x => projectAncestors[id].Contains(x.Id));
     335      else return Enumerable.Empty<Project>();
     336    }
     337
     338    public IEnumerable<Project> GetAvailableProjectDescendants(Guid id) {
     339      if(projectDescendants.ContainsKey(id)) return projects.Where(x => projectDescendants[id].Contains(x.Id));
     340      else return Enumerable.Empty<Project>();
     341    }
     342
     343    public IEnumerable<Resource> GetAvailableResourceAncestors(Guid id) {
     344      if (resourceAncestors.ContainsKey(id)) return resources.Where(x => resourceAncestors[id].Contains(x.Id));
     345      else return Enumerable.Empty<Resource>();
     346    }
     347
     348    public IEnumerable<Resource> GetAvailableResourceDescendants(Guid id) {
     349      if (resourceDescendants.ContainsKey(id)) return resources.Where(x => resourceDescendants[id].Contains(x.Id));
     350      else return Enumerable.Empty<Resource>();
     351    }
     352
    270353    public bool CheckAccessToAdminAreaGranted() {
    271354      if(projects != null) {
     
    286369        return true;
    287370      } else if(resourceAncestors.ContainsKey(res.Id)) {
    288         return resourceAncestors[res.Id].Where(x => x.OwnerUserId == userId).Any();
     371        return GetAvailableResourceAncestors(res.Id).Where(x => x.OwnerUserId == userId).Any();
    289372      }
    290373
     
    298381        return true;
    299382      } else if (projectAncestors.ContainsKey(pro.Id)) {
    300         return projectAncestors[pro.Id].Where(x => x.OwnerUserId == userId).Any();
     383        return GetAvailableProjectAncestors(pro.Id).Where(x => x.OwnerUserId == userId).Any();
    301384      }
    302385
     
    308391
    309392      if(projectAncestors.ContainsKey(pro.Id)) {
    310         return projectAncestors[pro.Id].Where(x => x.OwnerUserId == userId).Any();
     393        return GetAvailableProjectAncestors(pro.Id).Where(x => x.OwnerUserId == userId).Any();
    311394      }
    312395
     
    327410      } else if(parent != null && projectDescendants.ContainsKey(child.Id)) {
    328411        // ... if the new parent is among the moved project's descendants
    329         changePossible = !projectDescendants[child.Id].Where(x => x.Id == parent.Id).Any();
     412        changePossible = !GetAvailableProjectDescendants(child.Id).Where(x => x.Id == parent.Id).Any();
    330413      }
    331414
     
    350433      } else if (parent != null && resourceDescendants.ContainsKey(child.Id)) {
    351434        // ... or if the new parent is among the moved resource's descendants
    352         changePossible = !resourceDescendants[child.Id].Where(x => x.Id == parent.Id).Any();
     435        changePossible = !GetAvailableResourceDescendants(child.Id).Where(x => x.Id == parent.Id).Any();
    353436      }
    354437
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r15913 r15922  
    239239    }
    240240
    241     public IEnumerable<Project> GetAvailableParentProjects(Guid id) {
    242       return projects.Where(x => projectAncestors[id].Contains(x.Id));
    243     }
    244 
    245     public IEnumerable<Project> GetAvailableChildProjects(Guid id) {
    246       return projects.Where(x => projectDescendants[id].Contains(x.Id));
    247     }
    248 
    249     public IEnumerable<Resource> GetAvailableParentResources(Guid id) {
    250       return resources.Where(x => resourceAncestors[id].Contains(x.Id));
    251     }
    252 
    253     public IEnumerable<Resource> GetAvailableChildResources(Guid id) {
    254       return resources.Where(x => resourceDescendants[id].Contains(x.Id));
    255     }
    256 
     241    public IEnumerable<Project> GetAvailableProjectAncestors(Guid id) {
     242      if (projectAncestors.ContainsKey(id)) return projects.Where(x => projectAncestors[id].Contains(x.Id));
     243      else return Enumerable.Empty<Project>();
     244    }
     245
     246    public IEnumerable<Project> GetAvailableProjectDescendants(Guid id) {
     247      if (projectDescendants.ContainsKey(id)) return projects.Where(x => projectDescendants[id].Contains(x.Id));
     248      else return Enumerable.Empty<Project>();
     249    }
     250
     251    public IEnumerable<Resource> GetAvailableResourceAncestors(Guid id) {
     252      if (resourceAncestors.ContainsKey(id)) return resources.Where(x => resourceAncestors[id].Contains(x.Id));
     253      else return Enumerable.Empty<Resource>();
     254    }
     255
     256    public IEnumerable<Resource> GetAvailableResourceDescendants(Guid id) {
     257      if (resourceDescendants.ContainsKey(id)) return resources.Where(x => resourceDescendants[id].Contains(x.Id));
     258      else return Enumerable.Empty<Resource>();
     259    }
    257260    #endregion
    258261
Note: See TracChangeset for help on using the changeset viewer.