Skip to content

Commit

Permalink
Merge branch 'release/v3.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
sachatrauwaen committed Dec 4, 2017
2 parents 83b72a2 + a54f1e9 commit 174384f
Show file tree
Hide file tree
Showing 51 changed files with 1,997 additions and 617 deletions.
7 changes: 6 additions & 1 deletion OpenContent/AlpacaFormBuilder.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
ContactForm = true;
}
if (getData.key == "") {
Indexable = true;
}
BootstrapForm = <%= AlpacaContext.Bootstrap ? "true" : "false"%>;
BootstrapHorizontal = <%= AlpacaContext.Horizontal ? "true" : "false"%>;
Expand Down Expand Up @@ -113,7 +117,8 @@
var schema = getSchema(data);
var options = getOptions(data);
var view = getView(data);
var postData = JSON.stringify({ 'data': data, 'schema': schema, 'options': options, 'view': view, 'key': $("#<%=ddlForms.ClientID %>").val() });
var index = getIndex(data);
var postData = JSON.stringify({ 'data': data, 'schema': schema, 'options': options, 'view': view, 'index': index, 'key': $("#<%=ddlForms.ClientID %>").val() });
var action = "UpdateBuilder";
$.ajax({
type: "POST",
Expand Down
6 changes: 6 additions & 0 deletions OpenContent/App_LocalResources/EditGlobalSettings.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,10 @@
<data name="lFastHandlebars.Text" xml:space="preserve">
<value>Fast Handlebars. Case sensitive variables ! (Beta)</value>
</data>
<data name="lSaveXml.Text" xml:space="preserve">
<value>Save Xml</value>
</data>
<data name="cmdUpgradeXml.Text" xml:space="preserve">
<value>Generate Xml</value>
</data>
</root>
3 changes: 3 additions & 0 deletions OpenContent/App_LocalResources/View.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,7 @@
&lt;br&gt;
&lt;/p&gt;</value>
</data>
<data name="Notifications.Action" xml:space="preserve">
<value>Notifications</value>
</data>
</root>
3 changes: 2 additions & 1 deletion OpenContent/BuildScripts/ModuleDeploy.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
<DeployInclude Include="**\*.resx" Exclude="packages\**" />
<DeployInclude Include="**\*.aspx" Exclude="packages\**" />
<DeployInclude Include="**\*.js" Exclude="packages\**;**\_*.js" />
<DeployInclude Include="**\formsettings-*.json" Exclude="packages\**" />
<DeployInclude Include="**\*-schema.json" Exclude="packages\**" />
<DeployInclude Include="**\*-options.json" Exclude="packages\**" />
<DeployInclude Include="**\images\**" Exclude="packages\**;**\*.cs" />
<DeployInclude Include="**\web.config" Exclude="packages\**" />
<DeployInclude Include="**\css\**" Exclude="packages\**" />
Expand Down
3 changes: 2 additions & 1 deletion OpenContent/BuildScripts/ModulePackage.targets
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<InstallInclude Include="**\*.resx" Exclude="packages\**" />
<InstallInclude Include="**\*.aspx" Exclude="packages\**" />
<InstallInclude Include="**\*.js" Exclude="packages\**;**\_*.js" />
<InstallInclude Include="**\formsettings-*.json" Exclude="packages\**" />
<InstallInclude Include="**\*-schema.json" Exclude="packages\**" />
<InstallInclude Include="**\*-options.json" Exclude="packages\**" />
<InstallInclude Include="**\*.txt" Exclude="**\obj\**;**\_ReSharper*\**;packages\**;**\.git\**;" />
<InstallInclude Include="**\images\**" Exclude="packages\**;**\*.cs" />
<InstallInclude Include="**\web.config" Exclude="packages\**" />
Expand Down
2 changes: 1 addition & 1 deletion OpenContent/Components/Alpaca/AlpacaEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private void RegisterFields(bool bootstrap)
ClientResourceManager.RegisterStyleSheet(Page, "~/DesktopModules/OpenContent/js/fontIconPicker/themes/grey-theme/jquery.fonticonpicker.grey.min.css", FileOrder.Css.DefaultPriority);
ClientResourceManager.RegisterStyleSheet(Page, "~/DesktopModules/OpenContent/css/glyphicons/glyphicons.css", FileOrder.Css.DefaultPriority + 1);
}
if (allFields || fieldTypes.Contains("summernote"))
if (allFields || fieldTypes.Contains("summernote") || fieldTypes.Contains("mlsummernote"))
{
ClientResourceManager.RegisterScript(Page, "~/DesktopModules/OpenContent/js/summernote/summernote.min.js", FileOrder.Js.DefaultPriority, "DnnPageHeaderProvider");
ClientResourceManager.RegisterStyleSheet(Page, "~/DesktopModules/OpenContent/js/summernote/summernote.css", FileOrder.Css.DefaultPriority);
Expand Down
23 changes: 19 additions & 4 deletions OpenContent/Components/Alpaca/FormBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ private static void GetFields(SchemaConfig newSchemaFilter, OptionsConfig newOpt
Title = propTitle + " : until x days in the future"
});
fieldLst.Add(propKey);
newProp.Properties.Add("UseTime", new SchemaConfig()
{
Type = "boolean",
Title = propTitle + " Concider time"
});

/*
var newField = new OptionsConfig();
newOptionsFilter.Fields.Add(propKey, newField);
Expand Down Expand Up @@ -271,7 +277,7 @@ private JObject Build(string key, string currentCultureCode, bool schema, bool o
}
public FieldConfig BuildIndex(string key)
{
string prefix = (string.IsNullOrEmpty(key) || key == "Items") ? "" : key + "-";
string prefix = (string.IsNullOrEmpty(key) || key == "Items") ? "" : key + "-";
string cacheKey = _templateUri.UrlFolder + prefix + "index.json";
FieldConfig newConfig = (FieldConfig)DataCache.GetCache(cacheKey);
if (newConfig == null)
Expand Down Expand Up @@ -422,12 +428,21 @@ public FieldConfig BuildIndex(string key)
Index = true,
Sort = true
};
newConfig.Fields.Add(prop.Key, newField);
newConfig.Fields.Add(prop.Key, newField);
}

//else if (optType == "file" || optType == "file2")
//{
// var newField = new FieldConfig()
// {
// IndexType = "file",
// Index = true,
// Sort = false
// };
// newConfig.Fields.Add(prop.Key, newField);
//}
}
//var json = JObject.FromObject(newConfig);
//File.WriteAllText(templateUri.PhysicalFullDirectory + "\\test.json", json.ToString());
//File.WriteAllText(_templateUri.PhysicalFullDirectory + "\\test.json", json.ToString());

var schemaFile = new FileUri(_templateUri.UrlFolder, prefix + "schema.json");
var optionsFile = new FileUri(_templateUri.UrlFolder, prefix + "options.json");
Expand Down
13 changes: 11 additions & 2 deletions OpenContent/Components/Alpaca/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,25 @@ private QueryBuilder BuildFilter(JObject query, bool addWorkflowFilter, int user
{
var startDate = DateTime.MinValue;
var endDate = DateTime.MaxValue;
var useTime = false;
try
{
startDate = DateTime.Today.AddDays(-(long)startDays.Value);
useTime = (bool)(valObj["UseTime"] as JValue).Value;
}
catch (Exception)
{
}
DateTime currentDateTime = useTime ? DateTime.Now : DateTime.Today;
try
{
endDate = DateTime.Today.AddDays((long)endDays.Value);
startDate = currentDateTime.AddDays(-(long)startDays.Value);
}
catch (Exception)
{
}
try
{
endDate = currentDateTime.AddDays((long)endDays.Value);
}
catch (Exception)
{
Expand Down
4 changes: 3 additions & 1 deletion OpenContent/Components/Datasource/IDataIndex.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using DotNetNuke.Services.FileSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,5 +9,6 @@ namespace Satrabel.OpenContent.Components.Datasource
public interface IDataIndex
{
void Reindex(DataSourceContext context);

}
}
52 changes: 34 additions & 18 deletions OpenContent/Components/Datasource/OpenContentDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class OpenContentDataSource : IDataSource, IDataIndex
#region Queries
public virtual bool Any(DataSourceContext context)
{
OpenContentController ctrl = new OpenContentController();
OpenContentController ctrl = new OpenContentController(context.PortalId);
return ctrl.GetFirstContent(GetModuleId(context)) != null;
}
public virtual JArray GetVersions(DataSourceContext context, IDataItem item)
Expand Down Expand Up @@ -110,7 +110,7 @@ private DateTime getVersionDate(OpenContentVersion version)

public virtual IDataItem Get(DataSourceContext context, string id)
{
OpenContentController ctrl = new OpenContentController();
OpenContentController ctrl = new OpenContentController(context.PortalId);
OpenContentInfo content = null;

if (!string.IsNullOrEmpty(id) && id != "-1")
Expand Down Expand Up @@ -188,7 +188,7 @@ public virtual IDataItem GetData(DataSourceContext context, string scope, string

public virtual IDataItems GetAll(DataSourceContext context)
{
OpenContentController ctrl = new OpenContentController();
OpenContentController ctrl = new OpenContentController(context.PortalId);

var dataList = ctrl.GetContents(GetModuleId(context), context.Collection)
.OrderBy(i => i.CreatedOnDate)
Expand Down Expand Up @@ -217,7 +217,7 @@ public virtual IDataItems GetAll(DataSourceContext context, Select selectQuery)
else
{
SelectQueryDefinition def = BuildQuery(context, selectQuery);
OpenContentController ctrl = new OpenContentController();
OpenContentController ctrl = new OpenContentController(context.PortalId);
SearchResults docs = LuceneController.Instance.Search(OpenContentInfo.GetScope(GetModuleId(context), context.Collection), def.Filter, def.Query, def.Sort, def.PageSize, def.PageIndex);
int total = docs.TotalResults;
var dataList = new List<IDataItem>();
Expand Down Expand Up @@ -283,7 +283,7 @@ public virtual JObject GetDataAlpaca(DataSourceContext context, bool schema, boo

public virtual void Add(DataSourceContext context, JToken data)
{
OpenContentController ctrl = new OpenContentController();
OpenContentController ctrl = new OpenContentController(context.PortalId);
var content = new OpenContentInfo()
{
ModuleId = GetModuleId(context),
Expand All @@ -304,10 +304,11 @@ public virtual void Add(DataSourceContext context, JToken data)
LuceneController.Instance.Add(content, indexConfig);
LuceneController.Instance.Store.Commit();
}
Notify(context, data, "add");
}
public virtual void Update(DataSourceContext context, IDataItem item, JToken data)
{
OpenContentController ctrl = new OpenContentController();
OpenContentController ctrl = new OpenContentController(context.PortalId);
var content = (OpenContentInfo)item.Item;
content.Title = data["Title"]?.ToString() ?? "";
content.Json = data.ToString();
Expand All @@ -322,10 +323,25 @@ public virtual void Update(DataSourceContext context, IDataItem item, JToken dat
LuceneController.Instance.Store.Commit();
}
ClearUrlRewriterCache(context);
Notify(context, data, "update");
}

private static void Notify(DataSourceContext context, JToken data, string action)
{
if (context.Options?["Notifications"] is JArray)
{
var notifData = new JObject();
notifData["form"] = data.DeepClone();
notifData["form"]["action"] = action;
notifData["formSettings"] = new JObject();
notifData["formSettings"] = context.Options;
FormUtils.FormSubmit(notifData);
}
}

public virtual void Delete(DataSourceContext context, IDataItem item)
{
OpenContentController ctrl = new OpenContentController();
OpenContentController ctrl = new OpenContentController(context.PortalId);
var content = (OpenContentInfo)item.Item;
ctrl.DeleteContent(content);
if (context.Index)
Expand All @@ -334,6 +350,7 @@ public virtual void Delete(DataSourceContext context, IDataItem item)
LuceneController.Instance.Store.Commit();
}
ClearUrlRewriterCache(context);
Notify(context, content.JsonAsJToken, "delete");
}

/// <summary>
Expand All @@ -349,13 +366,13 @@ public virtual JToken Action(DataSourceContext context, string action, IDataItem
{
if (action == "FormSubmit")
{
OpenContentController ctrl = new OpenContentController();
var indexConfig = OpenContentUtils.GetIndexConfig(new FolderUri(context.TemplateFolder), "Submissions");
OpenContentController ctrl = new OpenContentController(context.PortalId);
//var indexConfig = OpenContentUtils.GetIndexConfig(new FolderUri(context.TemplateFolder), "Submissions");
var content = new OpenContentInfo()
{
ModuleId = GetModuleId(context),
Collection = "Submissions",
Title = "Form",
Title = item.Data["Title"] == null ? "Form" : item.Data["Title"].ToString(),
Json = data["form"].ToString(),
CreatedByUserId = context.UserId,
CreatedOnDate = DateTime.Now,
Expand All @@ -365,13 +382,12 @@ public virtual JToken Action(DataSourceContext context, string action, IDataItem
ctrl.AddContent(content);

//Index the content item
if (context.Index)
{
LuceneController.Instance.Add(content, indexConfig);
LuceneController.Instance.Store.Commit();
}

return FormUtils.FormSubmit(data as JObject);
//if (context.Index)
//{
// LuceneController.Instance.Add(content, indexConfig);
// LuceneController.Instance.Store.Commit();
//}
return FormUtils.FormSubmit(data as JObject, item.Data.DeepClone() as JObject);
}
return null;
}
Expand Down Expand Up @@ -423,7 +439,7 @@ public void Reindex(DataSourceContext context)
{
string scope = OpenContentInfo.GetScope(context.ModuleId, context.Collection);
var indexConfig = OpenContentUtils.GetIndexConfig(new FolderUri(context.TemplateFolder), context.Collection); //todo index is being build from schema & options. But they should be provided by the provider, not directly from the files
OpenContentController occ = new OpenContentController();
OpenContentController occ = new OpenContentController(context.PortalId);
LuceneController.Instance.ReIndexModuleData(occ.GetContents(context.ModuleId, context.Collection), indexConfig, scope);
}

Expand Down
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();
OpenContentController ctrl = new OpenContentController(PortalSettings.Current.PortalId);
var items = ctrl.GetContents(moduleId);
xml += "<opencontent>";
foreach (var item in items)
Expand Down
65 changes: 65 additions & 0 deletions OpenContent/Components/FileIndexer/FileIndexerManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using DotNetNuke.Collections.Internal;
using DotNetNuke.Framework.Reflections;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Satrabel.OpenContent.Components.FileIndexer
{
public class FileIndexerManager
{

private static readonly ILogAdapter Logger = AppConfig.Instance.LogAdapter.GetLogAdapter(typeof(FileIndexerManager));
private static NaiveLockingList<IFileIndexer> _fileIndexers;

public static void RegisterFileIndexers()
{
_fileIndexers = new NaiveLockingList<IFileIndexer>();

foreach (IFileIndexer fi in GetFileIndexers())
{
_fileIndexers.Add(fi);
}
}

private static IEnumerable<IFileIndexer> GetFileIndexers()
{
var typeLocator = new TypeLocator();
IEnumerable<Type> types = typeLocator.GetAllMatchingTypes(IsValidDataSourceProvider);

foreach (Type filterType in types)
{
IFileIndexer filter;
try
{
filter = Activator.CreateInstance(filterType) as IFileIndexer;
}
catch (Exception e)
{
Logger.Error($"Unable to create {filterType.FullName} while GetFileIndexers. {e.Message}");
filter = null;
}

if (filter != null)
{
yield return filter;
}
}
}

private static bool IsValidDataSourceProvider(Type t)
{
return t != null && t.IsClass && !t.IsAbstract && t.IsVisible && typeof(IFileIndexer).IsAssignableFrom(t);
}

public static IFileIndexer GetFileIndexer(string file)
{
if (string.IsNullOrEmpty(file))
return null;

var fileIndexer = _fileIndexers.SingleOrDefault(ds => ds.CanIndex(file));
return fileIndexer;
}
}

}
17 changes: 17 additions & 0 deletions OpenContent/Components/FileIndexer/IFileIndexer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Satrabel.OpenContent.Components.FileIndexer
{
public interface IFileIndexer
{
// return true if this fileindexer can handle this kind of file (based on the file extension)
bool CanIndex(string file);

//return a text representation of the content of the file for indexing
string GetContent(string file);
}
}
Loading

0 comments on commit 174384f

Please sign in to comment.