Skip to content

Commit

Permalink
V1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
vnbaaij committed Nov 24, 2014
1 parent c875c6b commit be35bd0
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Package.build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
****************************************
-->
<PropertyGroup>
<PackageVersion>1.2.0</PackageVersion>
<PackageVersion>1.3.0</PackageVersion>
<ProjectName>Our.Umbraco.FilePicker</ProjectName>
<BuildConfig>Release</BuildConfig>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions Package.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<umbPackage>
<info>
<package>
<name>File Picker</name>
<version>1.2.0</version>
<version>1.3.0</version>
<license url="http://opensource.org/licenses/MIT">The MIT License (MIT)</license>
<url>http://our.umbraco.org/projects/backoffice-extensions/file-picker</url>
<url>http://our.umbraco.org/projects/collaboration/filepicker</url>
<requirements>
<major>7</major>
<minor>0</minor>
Expand Down
Binary file removed Package/File_Picker_1.2.0.zip
Binary file not shown.
Binary file added Package/File_Picker_1.3.0.zip
Binary file not shown.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# File Picker

A File Picker property editor for Umbraco 7

After installing the package you can add a new datatype with the property editor 'File Picker'. You must select the folder from which a file can be selected. Optionally you can also supply a comma separated list of file extensions (i.e. 'png,jpg') to filter the files to choose from.

When the datatype is configured you can add it to your document types

##Version history

Version 1.2: first officially released version

Version 1.3: Bugfixing release closing issues #2, #3 and #5
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function filePickerController($scope, dialogService) {


$scope.openPicker = function () {
dialogService.open({
template: "/App_Plugins/FilePicker/filepickerdialog.html",
Expand Down Expand Up @@ -34,16 +36,29 @@ function folderPickerController($scope, dialogService) {
};
angular.module("umbraco").controller("Our.Umbraco.FolderPickerController", folderPickerController);

function fpDialogController($scope, dialogService) {
function filePickerDialogController($scope, dialogService) {

$scope.dialogEventHandler = $({});
$scope.dialogEventHandler.bind("treeNodeSelect", nodeSelectHandler);

function nodeSelectHandler(ev, args) {
args.event.preventDefault();
args.event.stopPropagation();
if (args.node.icon !== "icon-folder")
$scope.submit(args.node.id);
};
};
angular.module("umbraco").controller("Our.Umbraco.FilePickerDialogController", filePickerDialogController);

function folderPickerDialogController($scope, dialogService) {

$scope.dialogEventHandler = $({});
$scope.dialogEventHandler.bind("treeNodeSelect", nodeSelectHandler);

function nodeSelectHandler(ev, args) {
args.event.preventDefault();
args.event.stopPropagation();
$scope.submit(args.node.id);
};
};
angular.module("umbraco").controller("Our.Umbraco.FPDialogController", fpDialogController);
angular.module("umbraco").controller("Our.Umbraco.FolderPickerDialogController", folderPickerDialogController);
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<div class="umb-panel" ng-controller="Our.Umbraco.FPDialogController">
<div class="umb-panel" ng-controller="Our.Umbraco.FilePickerDialogController">
<div class="umb-panel-body no-header">
<umb-tree section="dummy"
treealias="fileTree"
eventhandler="dialogEventHandler"
hideoptions="true"
hideheader="true"
isdialog="true"
customtreeparams="startfolder={{dialogData.folder}}&amp;filter={{dialogData.filter}}&amp;files=true" />
customtreeparams="startfolder={{dialogData.folder}}&amp;filter={{dialogData.filefilter}}&amp;files=true"
/>
</div>
<div class="umb-panel-footer">
<div class="umb-el-wrap umb-panel-buttons">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<div class="umb-panel" ng-controller="Our.Umbraco.FPDialogController">
<div class="umb-panel" ng-controller="Our.Umbraco.FolderPickerDialogController">
<div class="umb-panel-body no-header">
<umb-tree section="dummy"
treealias="fileTree"
eventhandler="dialogEventHandler"
hideoptions="true"
hideheader="true"
isdialog="true" />
isdialog="true"
customtreeparams="filter=" />
</div>
<div class="umb-panel-footer">
<div class="umb-el-wrap umb-panel-buttons">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
{
label: "Filter",
description: "Comma separated list of extensions to filter the files to select from (i.e. '.png,.jpg')",
description: "Comma separated list of extensions to filter the files to select from (i.e. 'png, jpg'), no wildcard, no dot",
key: "filter",
view: "textstring"
}
Expand All @@ -31,5 +31,5 @@
],
javascript: [
'~/App_Plugins/FilePicker/filepicker.controller.js'
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ namespace Our.Umbraco.FilePicker.Controllers
[PluginController("FilePicker")]
public class FilePickerApiController : UmbracoAuthorizedJsonController
{
public IEnumerable<DirectoryInfo> GetFolders(string folder, string filter = "*")
public IEnumerable<DirectoryInfo> GetFolders(string folder, string[] filter)
{
var path = IOHelper.MapPath("~/" + folder.TrimStart('~', '/'));
return new DirectoryInfo(path).GetDirectories(filter);

IEnumerable<DirectoryInfo> dirs = new DirectoryInfo(path).EnumerateDirectories();
if (filter != null && filter[0] != ".")
return dirs.Where(d => d.EnumerateFiles().Where(f => filter.Contains(f.Extension, StringComparer.OrdinalIgnoreCase)).Any());

return new DirectoryInfo(path).GetDirectories();
}

public IEnumerable<FileInfo> GetFiles(string folder, string[] filter )
{
var path = IOHelper.MapPath("~/" + folder.TrimStart('~', '/'));
DirectoryInfo dir = new DirectoryInfo(path);
IEnumerable < FileInfo > files = dir.EnumerateFiles();
IEnumerable <FileInfo> files = dir.EnumerateFiles();

if (filter != null)
if (filter != null && filter[0] != ".")
return files.Where(f => filter.Contains(f.Extension, StringComparer.OrdinalIgnoreCase));

return new DirectoryInfo(path).GetFiles();
Expand Down
36 changes: 21 additions & 15 deletions Src/Our.Umbraco.FilePicker/Controllers/FolderTreeController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using System.Net.Http.Formatting;
using Umbraco.Core.IO;
using Umbraco.Core;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.Mvc;
using Umbraco.Web.Trees;
Expand All @@ -13,27 +14,34 @@ public class FolderTreeController : TreeController
{
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
if (!string.IsNullOrWhiteSpace(queryStrings.Get("files")))
return AddFiles(queryStrings);
if (!string.IsNullOrWhiteSpace(queryStrings.Get("startfolder")))
{
string folder = id == "-1" ? queryStrings.Get("startfolder") : id;
folder = folder.EnsureStartsWith("/");
TreeNodeCollection tempTree = AddFolders(folder, queryStrings);
tempTree.AddRange(AddFiles(folder, queryStrings));
return tempTree;
}

return AddFolders(id == "-1" ? "" : id, queryStrings);
}

private TreeNodeCollection AddFiles(FormDataCollection queryStrings)
private TreeNodeCollection AddFiles(string folder, FormDataCollection queryStrings)
{
var pickerApiController = new FilePickerApiController();
var str = queryStrings.Get("startfolder");
//var str = queryStrings.Get("startfolder");

if (string.IsNullOrWhiteSpace(str))
if (string.IsNullOrWhiteSpace(folder))
return null;

var filter = queryStrings.Get("filter").Split(',');

var filter = queryStrings.Get("filter").Split(',').Select(a=>a.Trim().EnsureStartsWith(".")).ToArray();

var path = IOHelper.MapPath(str);
var path = IOHelper.MapPath(folder);
var rootPath = IOHelper.MapPath(queryStrings.Get("startfolder"));
var treeNodeCollection = new TreeNodeCollection();
treeNodeCollection.AddRange(pickerApiController.GetFiles(str, filter)
.Select(file => CreateTreeNode(file.FullName.Replace(path, "").Replace("\\", "/"),
treeNodeCollection.AddRange(pickerApiController.GetFiles(folder, filter)
.Select(file => CreateTreeNode(file.FullName.Replace(rootPath, "").Replace("\\", "/"),
path, queryStrings, file.Name, "icon-document", false)));

return treeNodeCollection;
Expand All @@ -43,15 +51,13 @@ private TreeNodeCollection AddFolders(string parent, FormDataCollection queryStr
{
var pickerApiController = new FilePickerApiController();

var filter = queryStrings.Get("filter");
if (string.IsNullOrWhiteSpace(filter))
filter = "*";
var filter = queryStrings.Get("filter").Split(',').Select(a => a.Trim().EnsureStartsWith(".")).ToArray();

var treeNodeCollection = new TreeNodeCollection();
treeNodeCollection.AddRange(pickerApiController.GetFolders(parent, filter)
treeNodeCollection.AddRange(pickerApiController.GetFolders(parent,filter)
.Select(dir => CreateTreeNode(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"),
"~/" + parent, queryStrings, dir.Name,
"icon-folder", dir.EnumerateDirectories().Any())));
"icon-folder", pickerApiController.GetFiles(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"), filter).Any())));

return treeNodeCollection;
}
Expand Down
4 changes: 4 additions & 0 deletions Src/Our.Umbraco.FilePicker/Our.Umbraco.FilePicker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
4 changes: 2 additions & 2 deletions Src/Our.Umbraco.FilePicker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
[assembly: ComVisible(false)]
[assembly: Guid("35B141D2-D002-4CDA-AAD3-85808977C850")]

[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]

0 comments on commit be35bd0

Please sign in to comment.