Skip to content

Commit 03792cb

Browse files
Added type converters for defined value and campus
1 parent 95f0abd commit 03792cb

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

Plugin/Avalanche.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
</Compile>
8585
<Compile Include="Controls\ActionItem.cs" />
8686
<Compile Include="Field\Converters\AddressFieldTypeConverter.cs" />
87+
<Compile Include="Field\Converters\CampusFieldTypeConverter.cs" />
88+
<Compile Include="Field\Converters\DefinedValueTypeConverter.cs" />
8789
<Compile Include="Field\Converters\FieldTypeConverter.cs" />
8890
<Compile Include="Field\Converters\MemoFieldTypeConverter.cs" />
8991
<Compile Include="Field\Converters\SelectMultiFieldTypeConverter.cs" />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// <copyright>
2+
// Copyright Southeast Christian Church
3+
4+
//
5+
// Licensed under the Southeast Christian Church License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// A copy of the License shoud be included with this file.
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// </copyright>
15+
//
16+
using System.Linq;
17+
using Avalanche.Attribute;
18+
using Avalanche.Models;
19+
using Rock;
20+
using Rock.Field;
21+
using Rock.Field.Types;
22+
using Rock.Web.Cache;
23+
24+
namespace Avalanche.Field.Converters
25+
{
26+
[ConvertForFieldType( typeof( CampusFieldType ) )]
27+
28+
public class CampusFieldTypeConverter : FieldTypeConverter
29+
{
30+
public override FormElementItem Convert( IFieldType fieldType, AttributeCache attribute )
31+
{
32+
var element = new FormElementItem()
33+
{
34+
Type = FormElementType.Picker,
35+
Keyboard = Keyboard.Text,
36+
Options = CampusCache.All().ToDictionary( c => c.Name, c => c.Guid.ToString() )
37+
};
38+
39+
return element;
40+
}
41+
}
42+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// <copyright>
2+
// Copyright Southeast Christian Church
3+
4+
//
5+
// Licensed under the Southeast Christian Church License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// A copy of the License shoud be included with this file.
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// </copyright>
15+
//
16+
using System.Linq;
17+
using Avalanche.Attribute;
18+
using Avalanche.Models;
19+
using Rock;
20+
using Rock.Field;
21+
using Rock.Field.Types;
22+
using Rock.Web.Cache;
23+
24+
namespace Avalanche.Field.Converters
25+
{
26+
[ConvertForFieldType( typeof( DefinedValueFieldType ) )]
27+
28+
public class DefinedValueTypeConverter : FieldTypeConverter
29+
{
30+
public override FormElementItem Convert( IFieldType fieldType, AttributeCache attribute )
31+
{
32+
33+
string INCLUDE_INACTIVE_KEY = "includeInactive";
34+
35+
36+
37+
38+
var element = new FormElementItem()
39+
{
40+
Type = FormElementType.Picker,
41+
Keyboard = Keyboard.Text,
42+
};
43+
44+
var definedTypeValue = attribute.QualifierValues.GetValueOrNull( "definedtype" );
45+
var definedType = DefinedTypeCache.Get( definedTypeValue.AsInteger() );
46+
if ( definedType != null )
47+
{
48+
var values = definedType.DefinedValues;
49+
if ( !attribute.QualifierValues.GetValueOrNull( "includeInactive" ).AsBoolean() )
50+
{
51+
values = values.Where( a => a.IsActive ).ToList();
52+
}
53+
54+
if ( definedTypeValue != null )
55+
{
56+
element.Options = values.ToDictionary( dv => dv.Value, dv => dv.Guid.ToString() );
57+
}
58+
59+
var allowmultiple = attribute.QualifierValues.GetValueOrNull( "allowmultiple" );
60+
if ( allowmultiple != null && allowmultiple.AsBoolean() == true )
61+
{
62+
element.Type = FormElementType.CheckboxList;
63+
}
64+
}
65+
66+
67+
return element;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)