Skip to content

Commit add85bf

Browse files
committed
wip
1 parent efe690f commit add85bf

File tree

4 files changed

+369
-4
lines changed

4 files changed

+369
-4
lines changed

formulas/Helpers.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
using ToSic.Razor.Blade;
44
public class Helpers : Custom.Hybrid.Code14 {
55
public dynamic GetFormulas(string contentType, string fieldName) {
6-
var contentItem = AsList(App.Data[contentType]).FirstOrDefault();
7-
var contentItemType = AsEntity(contentItem).Type;
8-
var fieldType = AsList(contentItemType.Attributes as object).Where(a => a.Name == fieldName).FirstOrDefault();
6+
var contentItemType = App.AppState.GetContentType(contentType);
7+
var fieldType = contentItemType.Attributes
8+
.Where(a => a.Name == fieldName)
9+
.FirstOrDefault();
910

1011
var attributeMd = AsList(fieldType.Metadata.OfType("@All") as object).FirstOrDefault();
1112
return AsList(attributeMd.Formulas as object);

formulas/_110 Values.cshtml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
@inherits Custom.Hybrid.Razor14
2+
@using ToSic.Razor.Blade;
3+
<hide>
4+
@Html.Partial("_header.cshtml")
5+
@{
6+
var hlp = CreateInstance("../shared/Helpers.cs");
7+
var viewMd = AsDynamic((CmsContext.View.Metadata.OfType(hlp.TutViewMetadataType) as IEnumerable<dynamic>).FirstOrDefault());
8+
var fancybox = CreateInstance("../shared/Fancybox.cs");
9+
Edit.Enabled = true;
10+
Kit.Page.Activate("2sxc.JsCore", "2sxc.JsCms", "2sxc.Toolbars");
11+
}
12+
</hide>
13+
14+
<div class="row">
15+
<div class="col-md-7">
16+
<h2>Formulas affecting Values</h2>
17+
<p>We'll show you examples where formulas can be applied to set the Value in many ways. </p>
18+
</div>
19+
@Html.Partial("../shared/_DefaultInfoSection.cshtml")
20+
</div>
21+
22+
@* Fill If Empty *@
23+
@Html.Partial("_PartFormulas.cshtml", new {
24+
Title = "Set the Value if it's empty",
25+
Instructions = "This formula sets the value of a field if it's empty. As long as it's not empty, the user can type anything he/she wants. ",
26+
ContentType = "FormulasIfEmpty",
27+
FieldName = "Title",
28+
Size = 100
29+
})
30+
31+
@* Combine Values of Fields *@
32+
@Html.Partial("_PartFormulas.cshtml", new {
33+
Title = "Generate a Field Combining Others",
34+
Instructions = "This formula combines the values of 3 fields into a URL Slug. ",
35+
ContentType = "FormulasCombineValues",
36+
FieldName = "UrlKey",
37+
Size = 100
38+
})
39+
40+
@Html.Partial("_PartFormulas.cshtml", new {
41+
Title = "Single Field visibility",
42+
Instructions = "This formula determines the visibility of the Description field. It only becomes visible when the Title field isn't empty.",
43+
ContentType = "FormulasBasic",
44+
FieldName = "Description"
45+
})
46+
47+
@Html.Partial("_PartFormulas.cshtml", new {
48+
Title = "Group visibility",
49+
Instructions = "This formula determines the visibility of the Advanced settings group. The group becomes visible, when the Advanced toggle is active.",
50+
ContentType = "FormulasVisibleGroup",
51+
FieldName = "AdvancedSettings"
52+
})
53+
54+
@Html.Partial("_PartFormulas.cshtml", new {
55+
Title = "Required fields",
56+
Instructions = "This formula determines wether the Name field is required. It becomes required if the age isn't specified.",
57+
ContentType = "FormulasRequired",
58+
FieldName = "Name"
59+
})
60+
61+
@Html.Partial("_PartFormulas.cshtml", new {
62+
Title = "Disabled fields",
63+
Instructions = "This formula determines wether the ApiKeyV2 field is disabled. It becomes disabled if the UseNewFeatures field is true.",
64+
ContentType = "FormulasDisabled",
65+
FieldName = "ApiKeyV2"
66+
})
67+
68+
@Html.Partial("_PartFormulas.cshtml", new {
69+
Title = "Group Name - Text summary",
70+
Instructions = "This formula changes the Name of the PersonGroup field. The name becomes \"Person - Profile complete\" if all group fields are filled out and \"Person - Profile incomplete\" if not.",
71+
ContentType = "FormulasTextSummary",
72+
FieldName = "PersonGroup"
73+
})
74+
75+
@Html.Partial("_PartFormulas.cshtml", new {
76+
Title = "Group Name - Emoji summary",
77+
Instructions = "This formula changes the Name of the ProductGroup field. The name becomes \"Product ✅\" if all group fields are filled out and \"Product ✏️\" if not.",
78+
ContentType = "FormulasEmojiSummary",
79+
FieldName = "ProductGroup",
80+
Size = 150
81+
})
82+
83+
@Html.Partial("_PartFormulas.cshtml", new {
84+
Title = "Helptext",
85+
Instructions = "This formula adds a help text based on the ProductCode Field text. If the ProductCode field contains \"n0t0k\" the helptext \"This product code is deprecated. Please request a new product code. \" is added, or if it contains spaces the helptext \"Please remove all spaces from your product code.\" is added.",
86+
ContentType = "FormulasHelpText",
87+
FieldName = "ProductCode",
88+
More = "prefill:ProductCode=n0t0k code",
89+
Size = 175
90+
})
91+
92+
93+
@* Run Code Once only *@
94+
@Html.Partial("_PartFormulas.cshtml", new {
95+
Title = "Run Code Only when Form Opens",
96+
Instructions = "This formula determines the initial open/closed state - in this case randomly. "
97+
+ "Normally it would do this based on how complete data in that section is or based on other criterias. "
98+
+ "This is often used to improve initial state of a form based on how much data is already filled in. ",
99+
ContentType = "FormulasRunAtStart",
100+
FieldName = "GroupRandomlyOpen",
101+
Size = 200
102+
})
103+
104+
@* Change Dropdown Values *@
105+
@Html.Partial("_PartFormulas.cshtml", new {
106+
Title = "Change dropdown options: Country to Offices",
107+
Instructions = "This formula changes the values in the second dropdown based on the country picked first. ",
108+
ContentType = "FormulasDropdown",
109+
FieldName = "Office",
110+
Size = 160
111+
})
112+
113+
@* Change Dropdown Values #2 *@
114+
@Html.Partial("_PartFormulas.cshtml", new {
115+
Title = "Change dropdown options: Limited or More Options",
116+
Instructions = "This formula changes the values in the second dropdown if the user wants more options. ",
117+
ContentType = "FormulasDropdownDirections",
118+
FieldName = "Options",
119+
Size = 160
120+
})
121+
122+
@* Date Examples #1 *@
123+
@Html.Partial("_PartFormulas.cshtml", new {
124+
Title = "Date - Prefill but leave editable",
125+
Instructions = "This formula sets the initial value to the current date (if the field is empty). You can try it by deleting the value, once you leave the field it's updated again. ",
126+
ContentType = "FormulasDates",
127+
FieldName = "RightNow",
128+
Size = 125
129+
})
130+
131+
@* Date Examples #2 *@
132+
@Html.Partial("_PartFormulas.cshtml", new {
133+
Title = "Date - Calculate value",
134+
Instructions = "This formula sets the third field to the current date/time + an offset the user can choose in a dropdown. "
135+
+ "Note that since we do some calculations, we must make sure the result is time-zone cleaned. ",
136+
ContentType = "FormulasDates",
137+
FieldName = "PublishWhen",
138+
Size = 125
139+
})

formulas/_115 Settings.cshtml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
@inherits Custom.Hybrid.Razor14
2+
@using ToSic.Razor.Blade;
3+
<hide>
4+
@Html.Partial("_header.cshtml")
5+
@{
6+
var hlp = CreateInstance("../shared/Helpers.cs");
7+
var viewMd = AsDynamic((CmsContext.View.Metadata.OfType(hlp.TutViewMetadataType) as IEnumerable<dynamic>).FirstOrDefault());
8+
var fancybox = CreateInstance("../shared/Fancybox.cs");
9+
Edit.Enabled = true;
10+
Kit.Page.Activate("2sxc.JsCore", "2sxc.JsCms", "2sxc.Toolbars");
11+
}
12+
</hide>
13+
14+
<div class="row">
15+
<div class="col-md-7">
16+
<h2>Formulas affecting Field Settigns</h2>
17+
<p>We'll show you examples where formulas can be applied to change visibility, required, and more.</p>
18+
<p>In this tutorial you'll learn how to:</p>
19+
<ul>
20+
<li>
21+
Change field and group visibility
22+
</li>
23+
<li>
24+
Make fields required
25+
</li>
26+
<li>
27+
Make fields disabled
28+
</li>
29+
<li>
30+
Make group summaries in titles
31+
</li>
32+
<li>
33+
Add help text
34+
</li>
35+
</ul>
36+
<br>
37+
</div>
38+
@Html.Partial("../shared/_DefaultInfoSection.cshtml")
39+
</div>
40+
41+
@* Fill If Empty *@
42+
@Html.Partial("_PartFormulas.cshtml", new {
43+
Title = "Set the Value if it's empty",
44+
Instructions = "This formula sets the value of a field if it's empty. As long as it's not empty, the user can type anything he/she wants. ",
45+
ContentType = "FormulasIfEmpty",
46+
FieldName = "Title",
47+
Size = 100
48+
})
49+
50+
@* Combine Values of Fields *@
51+
@Html.Partial("_PartFormulas.cshtml", new {
52+
Title = "Generate a Field Combining Others",
53+
Instructions = "This formula combines the values of 3 fields into a URL Slug. ",
54+
ContentType = "FormulasCombineValues",
55+
FieldName = "UrlKey",
56+
Size = 100
57+
})
58+
59+
@Html.Partial("_PartFormulas.cshtml", new {
60+
Title = "Single Field visibility",
61+
Instructions = "This formula determines the visibility of the Description field. It only becomes visible when the Title field isn't empty.",
62+
ContentType = "FormulasBasic",
63+
FieldName = "Description"
64+
})
65+
66+
@Html.Partial("_PartFormulas.cshtml", new {
67+
Title = "Group visibility",
68+
Instructions = "This formula determines the visibility of the Advanced settings group. The group becomes visible, when the Advanced toggle is active.",
69+
ContentType = "FormulasVisibleGroup",
70+
FieldName = "AdvancedSettings"
71+
})
72+
73+
@Html.Partial("_PartFormulas.cshtml", new {
74+
Title = "Required fields",
75+
Instructions = "This formula determines wether the Name field is required. It becomes required if the age isn't specified.",
76+
ContentType = "FormulasRequired",
77+
FieldName = "Name"
78+
})
79+
80+
@Html.Partial("_PartFormulas.cshtml", new {
81+
Title = "Disabled fields",
82+
Instructions = "This formula determines wether the ApiKeyV2 field is disabled. It becomes disabled if the UseNewFeatures field is true.",
83+
ContentType = "FormulasDisabled",
84+
FieldName = "ApiKeyV2"
85+
})
86+
87+
@Html.Partial("_PartFormulas.cshtml", new {
88+
Title = "Group Name - Text summary",
89+
Instructions = "This formula changes the Name of the PersonGroup field. The name becomes \"Person - Profile complete\" if all group fields are filled out and \"Person - Profile incomplete\" if not.",
90+
ContentType = "FormulasTextSummary",
91+
FieldName = "PersonGroup"
92+
})
93+
94+
@Html.Partial("_PartFormulas.cshtml", new {
95+
Title = "Group Name - Emoji summary",
96+
Instructions = "This formula changes the Name of the ProductGroup field. The name becomes \"Product ✅\" if all group fields are filled out and \"Product ✏️\" if not.",
97+
ContentType = "FormulasEmojiSummary",
98+
FieldName = "ProductGroup",
99+
Size = 150
100+
})
101+
102+
@Html.Partial("_PartFormulas.cshtml", new {
103+
Title = "Helptext",
104+
Instructions = "This formula adds a help text based on the ProductCode Field text. If the ProductCode field contains \"n0t0k\" the helptext \"This product code is deprecated. Please request a new product code. \" is added, or if it contains spaces the helptext \"Please remove all spaces from your product code.\" is added.",
105+
ContentType = "FormulasHelpText",
106+
FieldName = "ProductCode",
107+
More = "prefill:ProductCode=n0t0k code",
108+
Size = 175
109+
})
110+
111+
112+
@* Run Code Once only *@
113+
@Html.Partial("_PartFormulas.cshtml", new {
114+
Title = "Run Code Only when Form Opens",
115+
Instructions = "This formula determines the initial open/closed state - in this case randomly. "
116+
+ "Normally it would do this based on how complete data in that section is or based on other criterias. "
117+
+ "This is often used to improve initial state of a form based on how much data is already filled in. ",
118+
ContentType = "FormulasRunAtStart",
119+
FieldName = "GroupRandomlyOpen",
120+
Size = 200
121+
})
122+
123+
@* Change Dropdown Values *@
124+
@Html.Partial("_PartFormulas.cshtml", new {
125+
Title = "Change dropdown options: Country to Offices",
126+
Instructions = "This formula changes the values in the second dropdown based on the country picked first. ",
127+
ContentType = "FormulasDropdown",
128+
FieldName = "Office",
129+
Size = 160
130+
})
131+
132+
@* Change Dropdown Values #2 *@
133+
@Html.Partial("_PartFormulas.cshtml", new {
134+
Title = "Change dropdown options: Limited or More Options",
135+
Instructions = "This formula changes the values in the second dropdown if the user wants more options. ",
136+
ContentType = "FormulasDropdownDirections",
137+
FieldName = "Options",
138+
Size = 160
139+
})
140+
141+
@* Date Examples #1 *@
142+
@Html.Partial("_PartFormulas.cshtml", new {
143+
Title = "Date - Prefill but leave editable",
144+
Instructions = "This formula sets the initial value to the current date (if the field is empty). You can try it by deleting the value, once you leave the field it's updated again. ",
145+
ContentType = "FormulasDates",
146+
FieldName = "RightNow",
147+
Size = 125
148+
})
149+
150+
@* Date Examples #2 *@
151+
@Html.Partial("_PartFormulas.cshtml", new {
152+
Title = "Date - Calculate value",
153+
Instructions = "This formula sets the third field to the current date/time + an offset the user can choose in a dropdown. "
154+
+ "Note that since we do some calculations, we must make sure the result is time-zone cleaned. ",
155+
ContentType = "FormulasDates",
156+
FieldName = "PublishWhen",
157+
Size = 125
158+
})

0 commit comments

Comments
 (0)