Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Merge changes from the release branch before release beta2.
Browse files Browse the repository at this point in the history
  • Loading branch information
tusmester committed Jul 10, 2017
1 parent 0bbfd8a commit 8619346
Show file tree
Hide file tree
Showing 12 changed files with 333 additions and 13 deletions.
38 changes: 38 additions & 0 deletions src/WebPages/Portlets/DialogFileUploadPortlet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using SenseNet.Portal.UI.PortletFramework;
using System.Web.UI.WebControls.WebParts;

namespace SenseNet.Portal.Portlets
{
public class DialogFileUploadPortlet : ContextBoundPortlet
{
private const string DialogFileUploadPortletClass = "DialogFileUploadPortlet";
private const string VIEWPATH = "/Root/System/SystemPlugins/Controls/DialogFileUpload.ascx";

[WebBrowsable(true), Personalizable(true)]
[LocalizedWebDisplayName(DialogFileUploadPortletClass, "Prop_AllowedContentTypes_DisplayName")]
[LocalizedWebDescription(DialogFileUploadPortletClass, "Prop_AllowedContentTypes_Description")]
[WebCategory("Dialog File Upload", 100)]
[WebOrder(100)]
public string AllowedContentTypes { get; set; }

public DialogFileUploadPortlet()
{
this.Name = "$DialogFileUploadPortlet:PortletDisplayName";
this.Description = "$DialogFileUploadPortlet:PortletDescription";
this.Category = new PortletCategory(PortletCategoryType.Application);
}

protected override void OnInit(EventArgs e)
{
var control = this.Page.LoadControl(VIEWPATH) as UI.Controls.DialogFileUpload;
if (control != null)
{
control.AllowedContentTypes = this.AllowedContentTypes;
this.Controls.Add(control);
}

base.OnInit(e);
}
}
}
2 changes: 1 addition & 1 deletion src/WebPages/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("7.0.0.0")]
[assembly: AssemblyFileVersion("7.0.0.0")]
[assembly: AssemblyInformationalVersion("7.0.0-beta1.1")]
[assembly: AssemblyInformationalVersion("7.0.0-beta2")]

[assembly: ComVisible(false)]
[assembly: Guid("7c7cd205-75ad-4c99-b745-9b1a6b724be9")]
Expand Down
203 changes: 203 additions & 0 deletions src/WebPages/UI/Controls/DialogFileUpload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using SenseNet.ContentRepository.Storage;
using SenseNet.ContentRepository;
using SenseNet.Portal.Virtualization;
using SenseNet.Portal.Handlers;
using System.Web;
using SenseNet.ContentRepository.Storage.Security;
using SenseNet.ContentRepository.Schema;

namespace SenseNet.Portal.UI.Controls
{
[Serializable]
internal class FileListElement
{
public string Path { get; set; }
public string FileName { get; set; }
}

public class DialogFileUpload : UserControl
{
// ==================================================================================== Properties
public string AllowedContentTypes { get; set; }


// ==================================================================================== Members
private List<FileListElement> _fileListElements;

private List<ContentType> AllowedContentTypesList => string.IsNullOrEmpty(AllowedContentTypes)
? null
: AllowedContentTypes
.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)
.Select(ContentType.GetByName).ToList();


// ==================================================================================== Controls
private FileUpload Upload
{
get
{
return this.FindControlRecursive("Upload") as FileUpload;
}
}
private Repeater UploadedFiles
{
get
{
return this.FindControlRecursive("UploadedFiles") as Repeater;
}
}
private PlaceHolder ErrorPlaceHolder
{
get
{
return this.FindControlRecursive("ErrorPlaceHolder") as PlaceHolder;
}
}
private Label ErrorLabel
{
get
{
return this.FindControlRecursive("ErrorLabel") as Label;
}
}


// ==================================================================================== Methods
protected override void LoadControlState(object savedState)
{
var state = (object[])savedState;
_fileListElements = state[0] as List<FileListElement>;
base.LoadControlState(state[1]);
}
protected override object SaveControlState()
{
return new[] {
_fileListElements,
base.SaveControlState()
};
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Page.RegisterRequiresControlState(this);
}
protected override void CreateChildControls()
{
ErrorPlaceHolder.Visible = false;

if (Upload.HasFile)
{
try
{
this.SaveFile();
}
catch (Exception ex)
{
ErrorLabel.Text = ex.Message;
ErrorPlaceHolder.Visible = true;
}
}

UploadedFiles.DataSource = _fileListElements;
UploadedFiles.ItemDataBound += new RepeaterItemEventHandler(UploadedFiles_ItemDataBound);
UploadedFiles.DataBind();
}
private void SaveFile()
{
// get target container
var container = PortalContext.Current.ContextNode as GenericContent;
var targetFolderName = HttpContext.Current.Request["TargetFolder"];
if (!string.IsNullOrEmpty(targetFolderName))
{
var containerPath = RepositoryPath.Combine(container?.Path, targetFolderName);
container = Node.LoadNode(containerPath) as GenericContent;

// create target container if does not exist
if (container == null)
{
using (new SystemAccount())
{
container = new Folder(PortalContext.Current.ContextNode)
{
Name = targetFolderName,
AllowedChildTypes = AllowedContentTypesList
};
container.Save();
}
}
}

var contentTypeName = UploadHelper.GetContentType(Upload.PostedFile.FileName, container?.Path) ?? typeof(File).Name;
if (container != null && container.GetAllowedChildTypeNames().Any(ctn => ctn == contentTypeName))
{
var binaryData = UploadHelper.CreateBinaryData(Upload.PostedFile);
var fileName = binaryData.FileName.ToString();

var content = ContentRepository.Content.CreateNew(contentTypeName, container, fileName);

// Uploaded files of different users go to the same folder.
// Avoid collision, do not overwrite each others' files.
content.ContentHandler.AllowIncrementalNaming = true;

content["Name"] = fileName;
content.Fields["Binary"].SetData(binaryData);
content.Save();

// display uploaded file in repeater
if (_fileListElements == null)
_fileListElements = new List<FileListElement>();

_fileListElements.Add(new FileListElement { FileName = content.Name, Path = content.Path });
}
else
{
ErrorLabel.Text = "This type cannot be uploaded!";
ErrorPlaceHolder.Visible = true;
}
}

private void UploadedFiles_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
var button = e.Item.FindControlRecursive("DeleteFile") as Button;
if (button != null)
button.Click += DeleteFileButton_Click;
}

private void DeleteFileButton_Click(object sender, EventArgs e)
{
var button = sender as Button;
var path = button?.CommandName ?? string.Empty;

var node = Node.LoadNode(path);
if (node == null)
{
ErrorLabel.Text = "Cannot find content!";
ErrorPlaceHolder.Visible = true;
return;
}

// check: was this file uploaded by me? if yes, delete. Otherwise don't allow delete.
if (node.CreatedById == User.Current.Id)
{
Node.ForceDelete(path);

_fileListElements = _fileListElements.Where(a => a.Path != path).ToList();
if (_fileListElements.Count == 0)
_fileListElements = null;

UploadedFiles.DataSource = _fileListElements;
UploadedFiles.DataBind();
}
else
{
ErrorLabel.Text = "This content cannot be deleted since it was created by another user!";
ErrorPlaceHolder.Visible = true;
}
}
}
}
11 changes: 5 additions & 6 deletions src/WebPages/WebPages.Install.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
<package >
<metadata>
<id>SenseNet.WebPages.Install</id>
<version>7.0.0-beta1.1</version>
<title>Install package for the UI layer for the sensenet ECM platform built using ASP.NET pages, webparts and controls.</title>
<version>7.0.0-beta2</version>
<title>sensenet ECM WebPages Install package</title>
<authors>kavics,aniko,laci,borsi,lajos,tusmester</authors>
<owners>Sense/Net</owners>
<licenseUrl>https://github.com/SenseNet/sn-webpages/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/SenseNet/sn-webpages</projectUrl>
<iconUrl>https://raw.githubusercontent.com/SenseNet/sn-resources/master/images/sn-icon/sensenet-icon-64.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>sensenet ECM WebPages Installer contains the install content for the UI layer built on well-known ASP.NET technologies like pages, webparts and ascx views. This package contains installation items and should be installed only in a single web project. All other projects should reference the SenseNet.WebPages dll-only package.</description>
<releaseNotes>Initial release.</releaseNotes>
<copyright>Copyright © Sense/Net Inc.</copyright>
<tags>sensenet ecm ecms</tags>
<dependencies>
<dependency id="SenseNet.Services.Install" version="7.0.0-beta2.1" />
<dependency id="SenseNet.WebPages" version="7.0.0-beta1.1" />
<dependency id="SenseNet.SnAdmin" version="1.4.2" />
<dependency id="SenseNet.Services.Install" version="7.0.0-beta3" />
<dependency id="SenseNet.WebPages" version="7.0.0-beta2" />
<dependency id="SenseNet.SnAdmin" version="1.4.3" />
</dependencies>
</metadata>
<files>
Expand Down
2 changes: 2 additions & 0 deletions src/WebPages/WebPages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
<Compile Include="Portlets\Controls\LoginView.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Portlets\DialogFileUploadPortlet.cs" />
<Compile Include="Portlets\FieldDeletePortlet.cs" />
<Compile Include="Portlets\FieldEditorPortlet.cs" />
<Compile Include="Portlets\FieldMoverPortlet.cs" />
Expand Down Expand Up @@ -387,6 +388,7 @@
<Compile Include="UI\Controls\DefaultButtons.cs" />
<Compile Include="UI\Controls\DefaultButtonsFactory.cs" />
<Compile Include="UI\Controls\DefaultButtonsFactoryBase.cs" />
<Compile Include="UI\Controls\DialogFileUpload.cs" />
<Compile Include="UI\Controls\DialogUpload.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
Expand Down
9 changes: 4 additions & 5 deletions src/WebPages/WebPages.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
<package >
<metadata>
<id>SenseNet.WebPages</id>
<version>7.0.0-beta1.1</version>
<title>UI layer for the sensenet ECM platform built using ASP.NET pages, webparts and controls.</title>
<version>7.0.0-beta2</version>
<title>sensenet ECM WebPages</title>
<authors>kavics,aniko,laci,borsi,lajos,tusmester</authors>
<owners>Sense/Net</owners>
<licenseUrl>https://github.com/SenseNet/sn-webpages/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/SenseNet/sn-webpages</projectUrl>
<iconUrl>https://raw.githubusercontent.com/SenseNet/sn-resources/master/images/sn-icon/sensenet-icon-64.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>sensenet ECM WebPages contains the UI layer built on well-known ASP.NET technologies like pages, webparts and ascx views.</description>
<releaseNotes>Initial release.</releaseNotes>
<description>sensenet ECM WebPages is the UI layer for the sensenet ECM platform built using ASP.NET pages, webparts and controls.</description>
<copyright>Copyright © Sense/Net Inc.</copyright>
<tags>sensenet ecm ecms</tags>
<dependencies>
<dependency id="SenseNet.Services" version="7.0.0-beta2" />
<dependency id="SenseNet.Services" version="7.0.0-beta3" />
<dependency id="SenseNet.Tools" version="2.1.1" />
</dependencies>
</metadata>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentMetaData>
<ContentType>Page</ContentType>
<ContentName>IFrameUpload</ContentName>
<Fields>
<PageTemplateNode>
<Path>/Root/Global/pagetemplates/sn-iframedialogupload.html</Path>
</PageTemplateNode>
<PersonalizationSettings attachment="IFrameUpload.PersonalizationSettings" />
<DisplayName><![CDATA[$Action,IFrameUpload]]></DisplayName>
<Icon><![CDATA[application]]></Icon>
</Fields>
<Permissions>
<Clear />
</Permissions>
</ContentMetaData>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% string snLang = SenseNet.Portal.Virtualization.PortalContext.Current?.Site?.Language ?? "en-us"; %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<%=snLang%>" xml:lang="<%=snLang%>">
<head>
<title><% = (SenseNet.Portal.Virtualization.PortalContext.Current.Workspace != null) ? SenseNet.ContentRepository.Content.Create(SenseNet.Portal.Virtualization.PortalContext.Current.Workspace).DisplayName : "Sense/Net" %></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="imagetoolbar" content="no" />
<sn:BaseTag ID="BaseTagControl1" runat="server" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
</head>

<body class="sn-body" style="min-width:0; background:0;">
<% string snLang = SenseNet.Portal.Virtualization.PortalContext.Current?.Site?.Language ?? "en-us"; %>

<sn:CssRequest CSSPath="$skin/styles/jqueryui/jquery-ui.css" ID="pageTemplateUIStyleReq" runat="server" />
<sn:CssRequest CSSPath="$skin/styles/jqueryui/jquery-ui-sntheme.css" ID="pageTemplateUIStyleReq2" runat="server" />
<sn:CssRequest CSSPath="$skin/styles/sn-layout.css" ID="snLayoutCss" runat="server" />
<sn:CssRequest CSSPath="$skin/styles/skin.css" ID="pageTemplateCssRequest1" runat="server" />

<div class="sn-layout-full ui-helper-clearfix" style="margin-top:20px;">
<snpe:DialogFileUploadPortlet ID="portlet" runat="server" AllowedContentTypes="Image" />
</div>

<!-- prc -->
<sn:ScriptRequest runat="server" Path="$skin/scripts/init.js" />
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentMetaData>
<ContentType>PageTemplate</ContentType>
<ContentName>sn-iframedialogupload.html</ContentName>
<Fields>
<Binary attachment="sn-iframedialogupload.html" />
<DisplayName>sn-iframedialogupload.html</DisplayName>
</Fields>
<Permissions>
<Clear />
</Permissions>
</ContentMetaData>
Loading

0 comments on commit 8619346

Please sign in to comment.