@@ -854,10 +854,8 class Issue < ActiveRecord::Base | |||||
854 | end |
|
854 | end | |
855 |
|
855 | |||
856 | # Returns all the other issues that depend on the issue |
|
856 | # Returns all the other issues that depend on the issue | |
|
857 | # The algorithm is a modified breadth first search (bfs) | |||
857 | def all_dependent_issues(except=[]) |
|
858 | def all_dependent_issues(except=[]) | |
858 |
|
||||
859 | # The algorithm as a modified bread first search (bfs) |
|
|||
860 |
|
||||
861 | # The found dependencies |
|
859 | # The found dependencies | |
862 | dependencies = [] |
|
860 | dependencies = [] | |
863 |
|
861 | |||
@@ -879,77 +877,77 class Issue < ActiveRecord::Base | |||||
879 | eALL_PROCESSED = 5 # The issue and all its children, its parent and its related issues have been |
|
877 | eALL_PROCESSED = 5 # The issue and all its children, its parent and its related issues have been | |
880 | # added as dependent issues. It needs no further processing. |
|
878 | # added as dependent issues. It needs no further processing. | |
881 |
|
879 | |||
882 |
issue |
|
880 | issue_status = Hash.new(eNOT_DISCOVERED) | |
883 |
|
881 | |||
884 | # The queue |
|
882 | # The queue | |
885 | queue = [] |
|
883 | queue = [] | |
886 |
|
884 | |||
887 | # Initialize the bfs, add start node (self) to the queue |
|
885 | # Initialize the bfs, add start node (self) to the queue | |
888 | queue << self |
|
886 | queue << self | |
889 |
issue |
|
887 | issue_status[self] = ePROCESS_ALL | |
890 |
|
888 | |||
891 | while (!queue.empty?) do |
|
889 | while (!queue.empty?) do | |
892 |
|
890 | |||
893 |
current |
|
891 | current_issue = queue.shift | |
894 |
current |
|
892 | current_issue_status = issue_status[current_issue] | |
895 |
|
893 | |||
896 |
dependencies << current |
|
894 | dependencies << current_issue | |
897 |
|
895 | |||
898 | # Add parent to queue, if not already in it. |
|
896 | # Add parent to queue, if not already in it. | |
899 |
parent = current |
|
897 | parent = current_issue.parent | |
900 |
parentStatus = issue |
|
898 | parentStatus = issue_status[parent] | |
901 |
|
899 | |||
902 | if parent && (parentStatus == eNOT_DISCOVERED) && !except.include?(parent) then |
|
900 | if parent && (parentStatus == eNOT_DISCOVERED) && !except.include?(parent) then | |
903 |
|
901 | |||
904 | queue << parent |
|
902 | queue << parent | |
905 |
issue |
|
903 | issue_status[parent] = ePROCESS_RELATIONS_ONLY | |
906 |
|
904 | |||
907 | end |
|
905 | end | |
908 |
|
906 | |||
909 | # Add children to queue, but only if they are not already in it and |
|
907 | # Add children to queue, but only if they are not already in it and | |
910 | # the children of the current node need to be processed. |
|
908 | # the children of the current node need to be processed. | |
911 |
if current |
|
909 | if current_issue.children && (current_issue_status == ePROCESS_CHILDREN_ONLY || current_issue_status == ePROCESS_ALL) then | |
912 |
|
910 | |||
913 |
current |
|
911 | current_issue.children.each do |child| | |
914 |
|
912 | |||
915 |
if (issue |
|
913 | if (issue_status[child] == eNOT_DISCOVERED) && !except.include?(child) | |
916 | queue << child |
|
914 | queue << child | |
917 |
issue |
|
915 | issue_status[child] = ePROCESS_ALL | |
918 |
|
916 | |||
919 |
elsif (issue |
|
917 | elsif (issue_status[child] == eRELATIONS_PROCESSED) && !except.include?(child) | |
920 | queue << child |
|
918 | queue << child | |
921 |
issue |
|
919 | issue_status[child] = ePROCESS_CHILDREN_ONLY | |
922 |
|
920 | |||
923 |
elsif (issue |
|
921 | elsif (issue_status[child] == ePROCESS_RELATIONS_ONLY) && !except.include?(child) | |
924 | queue << child |
|
922 | queue << child | |
925 |
issue |
|
923 | issue_status[child] = ePROCESS_ALL | |
926 | end |
|
924 | end | |
927 | end |
|
925 | end | |
928 | end |
|
926 | end | |
929 |
|
927 | |||
930 | # Add related issues to the queue, if they are not already in it. |
|
928 | # Add related issues to the queue, if they are not already in it. | |
931 |
current |
|
929 | current_issue.relations_from.map(&:issue_to).each do |relatedIssue| | |
932 |
|
930 | |||
933 |
if (issue |
|
931 | if (issue_status[relatedIssue] == eNOT_DISCOVERED) && !except.include?(relatedIssue) then | |
934 | queue << relatedIssue |
|
932 | queue << relatedIssue | |
935 |
issue |
|
933 | issue_status[relatedIssue] = ePROCESS_ALL | |
936 |
|
934 | |||
937 |
elsif (issue |
|
935 | elsif (issue_status[relatedIssue] == eRELATIONS_PROCESSED) && !except.include?(relatedIssue) then | |
938 | queue << relatedIssue |
|
936 | queue << relatedIssue | |
939 |
issue |
|
937 | issue_status[relatedIssue] = ePROCESS_CHILDREN_ONLY | |
940 |
|
938 | |||
941 |
elsif (issue |
|
939 | elsif (issue_status[relatedIssue] == ePROCESS_RELATIONS_ONLY) && !except.include?(relatedIssue) then | |
942 | queue << relatedIssue |
|
940 | queue << relatedIssue | |
943 |
issue |
|
941 | issue_status[relatedIssue] = ePROCESS_ALL | |
944 | end |
|
942 | end | |
945 | end |
|
943 | end | |
946 |
|
944 | |||
947 | # Set new status for current issue |
|
945 | # Set new status for current issue | |
948 |
if (current |
|
946 | if (current_issue_status == ePROCESS_ALL) || (current_issue_status == ePROCESS_CHILDREN_ONLY) then | |
949 |
issue |
|
947 | issue_status[current_issue] = eALL_PROCESSED | |
950 |
|
948 | |||
951 |
elsif (current |
|
949 | elsif (current_issue_status == ePROCESS_RELATIONS_ONLY) then | |
952 |
issue |
|
950 | issue_status[current_issue] = eRELATIONS_PROCESSED | |
953 | end |
|
951 | end | |
954 |
|
952 | |||
955 | end # while |
|
953 | end # while |
General Comments 0
You need to be logged in to leave comments.
Login now