Skip to content

Commit

Permalink
Merge branch 'hotfix/dnn92siteexport'
Browse files Browse the repository at this point in the history
  • Loading branch information
sachatrauwaen committed Oct 15, 2018
2 parents 092cd2b + 58231ba commit bdb407f
Show file tree
Hide file tree
Showing 17 changed files with 1,369 additions and 164 deletions.
2 changes: 1 addition & 1 deletion OpenContent/Components/FeatureController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FeatureController : ModuleSearchBase, IPortable, IUpgradeable, IMod
public string ExportModule(int moduleId)
{
string xml = "";
OpenContentController ctrl = new OpenContentController(PortalSettings.Current.PortalId);
OpenContentController ctrl = new OpenContentController();
var items = ctrl.GetContents(moduleId);
xml += "<opencontent>";
foreach (var item in items)
Expand Down
122 changes: 108 additions & 14 deletions OpenContent/Components/Handlebars/HandlebarsEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Collections;
using DotNetNuke.Entities.Portals;
using Satrabel.OpenContent.Components.Logging;
using Newtonsoft.Json.Linq;

namespace Satrabel.OpenContent.Components.Handlebars
{
Expand All @@ -39,9 +40,12 @@ public void Compile(string source)
RegisterArrayIndexHelper(hbs);
RegisterArrayTranslateHelper(hbs);
RegisterIfAndHelper(hbs);
RegisterIfOrHelper(hbs);
RegisterConvertHtmlToTextHelper(hbs);
RegisterConvertToJsonHelper(hbs);
RegisterTruncateWordsHelper(hbs);
RegisterReplaceHelper(hbs);
RegisterReplaceNewlineHelper(hbs);
_template = hbs.Compile(source);
}
catch (Exception ex)
Expand Down Expand Up @@ -108,11 +112,14 @@ private void RegisterHelpers(IHandlebars hbs)
RegisterArrayTranslateHelper(hbs);
RegisterArrayLookupHelper(hbs);
RegisterIfAndHelper(hbs);
RegisterIfOrHelper(hbs);
RegisterIfInHelper(hbs);
RegisterEachPublishedHelper(hbs);
RegisterConvertHtmlToTextHelper(hbs);
RegisterConvertToJsonHelper(hbs);
RegisterTruncateWordsHelper(hbs);
RegisterReplaceHelper(hbs);
RegisterReplaceNewlineHelper(hbs);
}

private void RegisterTruncateWordsHelper(HandlebarsDotNet.IHandlebars hbs)
Expand All @@ -137,6 +144,39 @@ private void RegisterTruncateWordsHelper(HandlebarsDotNet.IHandlebars hbs)
}
});
}
private void RegisterReplaceHelper(HandlebarsDotNet.IHandlebars hbs)
{
hbs.RegisterHelper("replace", (writer, context, parameters) =>
{
try
{
string text = parameters[0].ToString();
string oldString = parameters[1].ToString().Replace("\\n", "\n");
text = text.Replace(oldString, parameters[2].ToString());
HandlebarsDotNet.HandlebarsExtensions.WriteSafeString(writer, text);
}
catch (Exception)
{
HandlebarsDotNet.HandlebarsExtensions.WriteSafeString(writer, "");
}
});
}
private void RegisterReplaceNewlineHelper(HandlebarsDotNet.IHandlebars hbs)
{
hbs.RegisterHelper("replacenewline", (writer, context, parameters) =>
{
try
{
string text = parameters[0].ToString();
text = text.Replace("\n", parameters[1].ToString());
HandlebarsDotNet.HandlebarsExtensions.WriteSafeString(writer, text);
}
catch (Exception)
{
HandlebarsDotNet.HandlebarsExtensions.WriteSafeString(writer, "");
}
});
}
public string Execute(Page page, FileUri sourceFileUri, object model)
{
try
Expand Down Expand Up @@ -165,7 +205,7 @@ public string Execute(Page page, TemplateFiles files, string templateVirtualFold
string source = File.ReadAllText(sourceFileUri.PhysicalFilePath);
string sourceFolder = sourceFileUri.UrlFolder;
var hbs = HandlebarsDotNet.Handlebars.Create();

RegisterHelpers(hbs);
RegisterScriptHelper(hbs);
RegisterHandlebarsHelper(hbs);
Expand Down Expand Up @@ -292,7 +332,7 @@ private void RegisterEqualHelper(HandlebarsDotNet.IHandlebars hbs)
}
});
hbs.RegisterHelper("equaldate", (writer, options, context, arguments) =>
{
{
try
{
DateTime datetime1 = DateTime.Parse(arguments[0].ToString(), null, System.Globalization.DateTimeStyles.RoundtripKind);
Expand Down Expand Up @@ -490,7 +530,7 @@ private void RegisterImageUrlHelper(HandlebarsDotNet.IHandlebars hbs)
writer.WriteSafeString(imageUrl);
}
});

}

/// <summary>
Expand Down Expand Up @@ -651,21 +691,47 @@ private void RegisterFormatNumberHelper(HandlebarsDotNet.IHandlebars hbs)
{
try
{
decimal? number = parameters[0] as decimal?;
string format = parameters[1].ToString();
string provider = parameters[2].ToString();

IFormatProvider formatprovider = null;
if (provider.ToLower() == "invariant")
decimal number;
if (parameters[0] is decimal?)
{
number = (parameters[0] as decimal?).Value;
}
else if (parameters[0] is decimal)
{
formatprovider = CultureInfo.InvariantCulture;
number = (decimal)parameters[0];
}
else if (!string.IsNullOrWhiteSpace(provider))
else
{
formatprovider = CultureInfo.CreateSpecificCulture(provider);
number = decimal.Parse(parameters[0].ToString());
}

string res = number.Value.ToString(format, formatprovider);
string res = "";
string format = "0.00";

if (parameters.Count() > 1)
{
format = parameters[1].ToString();
}
if (parameters.Count() > 2 && !string.IsNullOrWhiteSpace(parameters[2].ToString()))
{
string provider = parameters[2].ToString();
IFormatProvider formatprovider = null;
if (provider.ToLower() == "invariant")
{
formatprovider = CultureInfo.InvariantCulture;
}
else
{
formatprovider = CultureInfo.CreateSpecificCulture(provider);
}
res = number.ToString(format, formatprovider);
}
else
{
res = number.ToString(format);
}
//string provider = parameters[2].ToString();
//string res = number.Value.ToString(format, formatprovider);
HandlebarsDotNet.HandlebarsExtensions.WriteSafeString(writer, res);
}
catch (Exception)
Expand Down Expand Up @@ -814,6 +880,26 @@ private void RegisterIfAndHelper(IHandlebars hbs)
}
});
}

private void RegisterIfOrHelper(IHandlebars hbs)
{
hbs.RegisterHelper("ifor", (writer, options, context, arguments) =>
{
bool res = false;
foreach (var arg in arguments)
{
res = res || HandlebarsUtils.IsTruthyOrNonEmpty(arg);
}
if (res)
{
options.Template(writer, (object)context);
}
else
{
options.Inverse(writer, (object)context);
}
});
}
private void RegisterIfInHelper(IHandlebars hbs)
{
hbs.RegisterHelper("ifin", (writer, options, context, arguments) =>
Expand Down Expand Up @@ -858,7 +944,15 @@ private void RegisterConvertToJsonHelper(HandlebarsDotNet.IHandlebars hbs)
{
try
{
var res = System.Web.Helpers.Json.Encode(parameters[0]);
string res;
if (parameters[0] is JToken)
{
res = ((JToken)parameters[0]).ToString();
}
else
{
res = System.Web.Helpers.Json.Encode(parameters[0]);
}
HandlebarsDotNet.HandlebarsExtensions.WriteSafeString(writer, res);
}
catch (Exception)
Expand Down
5 changes: 1 addition & 4 deletions OpenContent/Components/OpenContentAPIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,8 @@ public HttpResponseMessage LookupData(LookupDataRequestDTO req)
}
if (json is JArray)
{
if (LocaleController.Instance.GetLocales(PortalSettings.PortalId).Count > 1)
{
JsonUtils.SimplifyJson(json, DnnLanguageUtils.GetCurrentCultureCode());
}
AddLookupItems(req.valueField, req.textField, req.childrenField, res, json as JArray);
JsonUtils.SimplifyJson(json, DnnLanguageUtils.GetCurrentCultureCode());
}
}
return Request.CreateResponse(HttpStatusCode.OK, res);
Expand Down
13 changes: 3 additions & 10 deletions OpenContent/Components/Render/ModelFactoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,13 @@ protected void ExtendModel(JObject model, bool onlyData, bool onlyMainData)
foreach (var dataItem in dataItems.Items)
{
var json = dataItem.Data;

if (json != null && LocaleController.Instance.GetLocales(_portalId).Count > 1)
{
JsonUtils.SimplifyJson(json, GetCurrentCultureCode());
}
if (json is JObject)
{
JObject context = new JObject();
json["Context"] = context;
context["Id"] = dataItem.Id;
EnhanceSelect2(json as JObject);
JsonUtils.SimplifyJson(json, GetCurrentCultureCode());
}
colDataJson.Add(json);
}
Expand All @@ -243,10 +239,7 @@ protected void ExtendModel(JObject model, bool onlyData, bool onlyMainData)
try
{
var jsonSettings = JToken.Parse(_settingsJson);
if (LocaleController.Instance.GetLocales(_portalId).Count > 1)
{
JsonUtils.SimplifyJson(jsonSettings, GetCurrentCultureCode());
}
JsonUtils.SimplifyJson(jsonSettings, GetCurrentCultureCode());
model["Settings"] = jsonSettings;
}
catch (Exception ex)
Expand Down Expand Up @@ -304,7 +297,7 @@ private JObject GetAdditionalData()
var json = dataItem?.Data;
if (json != null)
{
if (LocaleController.Instance.GetLocales(_portalId).Count > 1)
//if (LocaleController.Instance.GetLocales(_portalId).Count > 1)
{
JsonUtils.SimplifyJson(json, GetCurrentCultureCode());
}
Expand Down
15 changes: 4 additions & 11 deletions OpenContent/Components/Render/ModelFactoryMultiple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,12 @@ public IEnumerable<Dictionary<string, object>> GetModelAsDictionaryList()
{
foreach (var item in _dataList)
{
var model = item.Data as JObject;
var model = item.Data.DeepClone() as JObject;
JObject context = new JObject();
model["Context"] = context;
context["Id"] = item.Id;
if (LocaleController.Instance.GetLocales(_portalId).Count > 1)
{
JsonUtils.SimplifyJson(model, GetCurrentCultureCode());
}
context["Id"] = item.Id;
EnhanceSelect2(model);
JsonUtils.SimplifyJson(model, GetCurrentCultureCode());
yield return JsonUtils.JsonToDictionary(model.ToString());
}
}
Expand Down Expand Up @@ -91,14 +88,10 @@ public override JToken GetModelAsJson(bool onlyData = false, bool onlyMainData =
JObject context = new JObject();
dyn["Context"] = context;
context["Id"] = item.Id;
if (LocaleController.Instance.GetLocales(_portalId).Count > 1)
{
JsonUtils.SimplifyJson(dyn, GetCurrentCultureCode());
}
EnhanceSelect2(dyn);
JsonUtils.SimplifyJson(dyn, GetCurrentCultureCode());
EnhanceUser(dyn, item.CreatedByUserId);
EnhanceImages(dyn, itemsModel);

if (onlyData)
{
RemoveNoData(itemsModel);
Expand Down
5 changes: 1 addition & 4 deletions OpenContent/Components/Render/ModelFactorySingle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ public ModelFactorySingle(IDataItem data, OpenContentModuleInfo module, PortalSe
public override JToken GetModelAsJson(bool onlyData = false, bool onlyMainData = false)
{
var model = _dataJson as JObject;
if (LocaleController.Instance.GetLocales(_portalId).Count > 1)
{
JsonUtils.SimplifyJson(model, GetCurrentCultureCode());
}
var enhancedModel = new JObject();
ExtendSchemaOptions(enhancedModel, onlyData || onlyMainData);
ExtendModel(enhancedModel, onlyData, onlyMainData);
ExtendModelSingle(enhancedModel);
EnhanceSelect2(model);
JsonUtils.Merge(model, enhancedModel);
JsonUtils.SimplifyJson(model, GetCurrentCultureCode());
return model;
}

Expand Down
20 changes: 19 additions & 1 deletion OpenContent/Components/Rest/RestQueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,28 @@ public static Select MergeQuery(FieldConfig config, Select select, RestSelect re
{
if (rule.Value != null)
{
RuleValue val;
if(rule.Value.Type == Newtonsoft.Json.Linq.JTokenType.Boolean)
{
val = new BooleanRuleValue((bool)rule.Value.Value);
}
else if (rule.Value.Type == Newtonsoft.Json.Linq.JTokenType.Integer)
{
val = new IntegerRuleValue((int)rule.Value.Value);
}
else if (rule.Value.Type == Newtonsoft.Json.Linq.JTokenType.Float)
{
val = new FloatRuleValue((float)rule.Value.Value);
}
else
{
val = new StringRuleValue(rule.Value.ToString());
}

query.AddRule(FieldConfigUtils.CreateFilterRule(config, cultureCode,
rule.Field,
rule.FieldOperator,
new StringRuleValue(rule.Value.ToString())
val
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion OpenContent/Components/Rest/V2/RestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public HttpResponseMessage Get(string entity, int pageIndex, int pageSize, strin
item["id"] = item["Context"]["Id"];
JsonUtils.IdJson(item);
}
res[entity] = model[collection];
res[entity] = model["Items"];
res["meta"]["total"] = dsItems.Total;
return Request.CreateResponse(HttpStatusCode.OK, res);
}
Expand Down
5 changes: 3 additions & 2 deletions OpenContent/EditFormSettings.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ protected override void OnInit(EventArgs e)
hlCancel.NavigateUrl = Globals.NavigateURL();
cmdSave.NavigateUrl = Globals.NavigateURL();
OpenContentSettings settings = this.OpenContentSettings();
AlpacaEngine alpaca = new AlpacaEngine(Page, ModuleContext.PortalId, "~/DeskTopModules/OpenContent", "formsettings");
AlpacaEngine alpaca = new AlpacaEngine(Page, ModuleContext.PortalId, "DeskTopModules/OpenContent", "formsettings");
//AlpacaEngine alpaca = new AlpacaEngine(Page, ModuleContext, "", "");
alpaca.RegisterAll();
alpaca.RegisterAll(true, true);
string itemId = null;
AlpacaContext = new AlpacaContext(PortalId, ModuleId, itemId, ScopeWrapper.ClientID, hlCancel.ClientID, cmdSave.ClientID, null, null, null);
AlpacaContext.Bootstrap = true;
}

public AlpacaContext AlpacaContext { get; private set; }
Expand Down
1 change: 1 addition & 0 deletions OpenContent/OpenContent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@
<Content Include="alpaca\css\img\Dn_16X16_Standard.png" />
<Content Include="alpaca\css\img\Up_16X16_Standard.png" />
<Content Include="alpaca\js\fields\dnn\AccordionField.js" />
<Content Include="alpaca\js\fields\dnn\CheckboxField.js" />
<Content Include="alpaca\js\fields\dnn\dnnfields.js" />
<Content Include="alpaca\js\fields\dnn\dnnfields.min.js">
<DependentUpon>dnnfields.js</DependentUpon>
Expand Down
2 changes: 1 addition & 1 deletion OpenContent/OpenContent.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="OpenContent" type="Module" version="03.05.04">
<package name="OpenContent" type="Module" version="03.06.00">
<friendlyName>OpenContent</friendlyName>
<description>OpenContent module by Satrabel.be</description>
<iconFile>~/DesktopModules/OpenContent/Images/icon_extensions.png</iconFile>
Expand Down
Loading

0 comments on commit bdb407f

Please sign in to comment.