-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathHackathonMigrations.cs
More file actions
133 lines (118 loc) · 5.24 KB
/
Copy pathHackathonMigrations.cs
File metadata and controls
133 lines (118 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using OrchardCore.ContentFields.Fields;
using OrchardCore.ContentFields.Settings;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.Data.Migration;
using OrchardCore.Recipes.Services;
using OrchardCore.Title.Models;
using StatCan.OrchardCore.Extensions;
using System.Threading.Tasks;
namespace StatCan.OrchardCore.Hackathon
{
public class HackathonMigrations : DataMigration
{
private readonly IRecipeMigrator _recipeMigrator;
private readonly IContentDefinitionManager _contentDefinitionManager;
public HackathonMigrations(IRecipeMigrator recipeMigrator, IContentDefinitionManager contentDefinitionManager)
{
_recipeMigrator = recipeMigrator;
_contentDefinitionManager = contentDefinitionManager;
}
public async Task<int> CreateAsync()
{
CreateHackathonCustomSetings();
CreateUserProfiles();
CreateWidgets();
CreateChallenge();
CreateStudentDashboard();
await _recipeMigrator.ExecuteAsync("queries.recipe.json", this);
await _recipeMigrator.ExecuteAsync("roles.recipe.json", this);
return 1;
}
private void CreateHackathonCustomSetings()
{
_contentDefinitionManager.AlterPartDefinition("HackathonCustomSettings", part => part
.WithField("StartDate", f => f
.OfType(nameof(DateField))
.WithDisplayName("Start Date")
.WithPosition("0")
)
.WithField("EndDate", f => f
.OfType(nameof(DateField))
.WithDisplayName("End Date")
.WithPosition("1")
)
.WithNumericField("Capacity", "2", new NumericFieldSettings() { DefaultValue = "0", Hint = "The maximum number of participants. Set to 0 for unlimited" })
);
_contentDefinitionManager.AlterTypeDefinition("HackathonCustomSettings", type => type
.WithPart("HackathonCustomSettings", p => p.WithPosition("0"))
.Stereotype("CustomSettings"));
}
private void CreateUserProfiles()
{
_contentDefinitionManager.AlterPartDefinition("ParticipantProfile", part => part
.WithTextField("FirstName", "First Name", "0")
.WithTextField("LastName", "Last Name", "1")
.WithTextField("Email", "Contact Email", "Email", "2")
.WithField("Language", f => f
.OfType(nameof(TextField))
.WithDisplayName("Language")
.WithPosition("3")
.WithEditor("PredefinedList")
.WithSettings(new TextFieldPredefinedListEditorSettings()
{
Editor = 0,
DefaultValue = "en",
Options = new ListValueOption[] {
new ListValueOption(){Name = "English", Value = "en"},
new ListValueOption(){Name = "French", Value = "fr"},
new ListValueOption(){Name = "Billingual", Value = "both"}
}
})
)
);
_contentDefinitionManager.AlterTypeDefinition("ParticipantProfile", type => type
.WithPart("ParticipantProfile", p => p.WithPosition("0"))
.Stereotype("CustomUserSettings")
);
}
private void CreateWidgets()
{
_contentDefinitionManager.CreateBasicWidget("HackathonCalendar");
_contentDefinitionManager.CreateBasicWidget("ChallengeListWidget");
}
private void CreateChallenge()
{
_contentDefinitionManager.AlterPartDefinition("Challenge", p => p
.WithTextField("Name", "0")
.WithTextField("ShortDescription", "Short Description", "1")
);
_contentDefinitionManager.AlterTypeDefinition("Challenge", t => t.Creatable().Draftable().Listable().Securable()
.WithTitlePart("0", TitlePartOptions.GeneratedDisabled, "{{ContentItem.Content.Challenge.Name.Text}}")
.WithPart("Challenge", p => p.WithPosition("1"))
.WithMarkdownBody("2")
);
}
private void CreateStudentDashboard()
{
_contentDefinitionManager.AlterTypeDefinition("StudentDashboard", type => type
.DisplayedAs("StudentDashboard")
.Stereotype("Widget")
.WithPart("StudentDashboard", part => part
.WithPosition("0")
)
);
_contentDefinitionManager.AlterPartDefinition("StudentDashboard", part => part
.WithField("Hacker", field => field
.OfType("UserPickerField")
.WithDisplayName("Hacker")
.WithPosition("0")
.WithSettings(new UserPickerFieldSettings
{
DisplayedRoles = new[] { "Hacker" },
})
)
);
}
}
}