1414// </copyright>
1515//
1616using System ;
17+ using System . Collections . Generic ;
1718using System . ComponentModel ;
18- using Rock . Model ;
19- using System . Web . UI ;
20- using Rock . Web . Cache ;
21- using Rock . Data ;
2219using System . Linq ;
23- using System . Collections . Generic ;
24- using Rock ;
20+ using System . Web . UI ;
2521using Avalanche ;
22+ using Avalanche . Attribute ;
2623using Avalanche . Models ;
24+ using Rock ;
2725using Rock . Attribute ;
28- using Avalanche . Attribute ;
29- using Newtonsoft . Json ;
26+ using Rock . Data ;
27+ using Rock . Model ;
28+ using Rock . Web . Cache ;
3029
3130namespace RockWeb . Plugins . Avalanche
3231{
@@ -40,6 +39,7 @@ namespace RockWeb.Plugins.Avalanche
4039 [ DefinedValueField ( AvalancheUtilities . MobileListViewComponent , "Component" , "Different components will display your list in different ways." ) ]
4140 [ CodeEditorField ( "Lava" , "Lava to display list items." , Rock . Web . UI . Controls . CodeEditorMode . Lava , defaultValue : defaultLava ) ]
4241 [ BooleanField ( "Only Show If Leader" , "Should groups be hidden from all users except leaders?" , true ) ]
42+ [ MarkdownField ( "No Groups Markdown" , "Markdown to show if no groups can be found." , defaultValue : "We are sorry, we could not find any groups." ) ]
4343 public partial class GroupListBlock : AvalancheBlock
4444 {
4545 public const string defaultLava = @"[
@@ -78,21 +78,37 @@ protected override void OnLoad( EventArgs e )
7878
7979 public override MobileBlock GetMobile ( string parameter )
8080 {
81+ var groups = GetGroups ( ) ;
82+
83+ CustomAttributes [ "Content" ] = AvalancheUtilities . ProcessLava (
84+ GetAttributeValue ( "NoGroupsMarkdown" ) ,
85+ CurrentPerson ,
86+ parameter ,
87+ GetAttributeValue ( "EnabledLavaCommands" ) ) ;
88+
89+ if ( ! groups . Any ( ) )
90+ {
91+ return new MobileBlock ( )
92+ {
93+ BlockType = "Avalanche.Blocks.MarkdownDetail" ,
94+ Attributes = CustomAttributes
95+ } ;
96+ }
97+
8198 AvalancheUtilities . SetActionItems ( GetAttributeValue ( "ActionItem" ) ,
8299 CustomAttributes ,
83100 CurrentPerson , AvalancheUtilities . GetMergeFields ( CurrentPerson ) ,
84101 GetAttributeValue ( "EnabledLavaCommands" ) ,
85102 parameter ) ;
86103
87104 var valueGuid = GetAttributeValue ( "Component" ) ;
88- var value = DefinedValueCache . Read ( valueGuid ) ;
105+ var value = DefinedValueCache . Get ( valueGuid ) ;
89106 if ( value != null )
90107 {
91108 CustomAttributes [ "Component" ] = value . GetAttributeValue ( "ComponentType" ) ;
92109 }
93110
94111 CustomAttributes [ "InitialRequest" ] = parameter ; //Request for pull to refresh
95- var groups = GetGroups ( ) ;
96112 Dictionary < string , object > mergeObjects = new Dictionary < string , object >
97113 {
98114 { "Groups" , groups }
@@ -103,7 +119,7 @@ public override MobileBlock GetMobile( string parameter )
103119 parameter ,
104120 GetAttributeValue ( "EnabledLavaCommands" ) ,
105121 mergeObjects ) ;
106- content = content . Replace ( "\\ " , "\\ \\ " ) ;
122+ content = content . Replace ( "\\ " , "\\ \\ " ) ;
107123 CustomAttributes [ "Content" ] = content ;
108124
109125 return new MobileBlock ( )
@@ -113,7 +129,7 @@ public override MobileBlock GetMobile( string parameter )
113129 } ;
114130 }
115131
116- public override MobileBlockResponse HandleRequest ( string request , Dictionary < string , string > Body )
132+ public override MobileBlockResponse HandleRequest ( string request , Dictionary < string , string > body )
117133 {
118134 var groups = GetGroups ( ) ;
119135 Dictionary < string , object > mergeObjects = new Dictionary < string , object >
@@ -161,9 +177,9 @@ private List<Group> GetGroups()
161177
162178 var qry = groupService . Queryable ( )
163179 . Where ( g => ids . Contains ( g . Id ) )
164- . SelectMany ( g => g . Groups )
180+ . SelectMany ( g => g . Groups . Where ( g2 => g2 . IsActive ) )
165181 . Join (
166- groupMemberService . Queryable ( ) ,
182+ groupMemberService . Queryable ( ) . Where ( gm => gm . GroupMemberStatus == GroupMemberStatus . Active ) ,
167183 g => g . Id ,
168184 m => m . GroupId ,
169185 ( g , m ) => new { Group = g , Member = m } ) ;
0 commit comments