From 828965b9023585a1da82404fe2ca4c5f99169ee1 Mon Sep 17 00:00:00 2001 From: perploug Date: Tue, 24 Sep 2013 12:15:15 +0200 Subject: [PATCH 1/4] umb photo folder directive --- .../html/umbphotofolder.directive.js | 147 ++++++++++++++++++ .../directives/html/umb-photo-folder.html | 8 + .../common/services/umb-image-helper.spec.js | 8 +- 3 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/common/directives/html/umbphotofolder.directive.js create mode 100644 src/Umbraco.Web.UI.Client/src/views/directives/html/umb-photo-folder.html diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/html/umbphotofolder.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/html/umbphotofolder.directive.js new file mode 100644 index 0000000000..50bbca7574 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/directives/html/umbphotofolder.directive.js @@ -0,0 +1,147 @@ +/** +* @ngdoc directive +* @name umbraco.directives.directive:umbPhotoFolder +* @restrict E +**/ +angular.module("umbraco.directives.html") +.directive('umbPhotoFolder', function ($compile, $log, $timeout, imageHelper) { + + return { + restrict: 'E', + replace: true, + require: '?ngModel', + terminate: true, + templateUrl: 'views/directives/html/umb-photo-folder.html', + link: function(scope, element, attrs, ngModel) { + + element.ready(function(){ + var wat = 1; + + }); + + ngModel.$render = function() { + + if(ngModel.$modelValue){ + + $timeout(function(){ + + var photos = ngModel.$modelValue; + var rows = []; + + scope.baseline = element.attr('baseline') | 0; + scope.minWidth = element.attr('minwidth') | 420; + scope.minHeight = element.attr('minheight') | 200; + scope.border = element.attr('border') | 5; + + scope.lastWidth = Math.max(element.width(), scope.minWidth); + + // get row width - this is fixed. + var w = scope.lastWidth; + + + // initial height - effectively the maximum height +/- 10%; + var h = Math.max(scope.minHeight,Math.floor(w / 5)); + + + // store relative widths of all images (scaled to match estimate height above) + var ws = []; + $.each(photos, function(key, val) { + val.width_n = $.grep(val.properties, function(val, index) {return (val.alias === "umbracoWidth");})[0].value; + val.height_n = $.grep(val.properties, function(val, index) {return (val.alias === "umbracoHeight");})[0].value; + val.url_n = imageHelper.getThumbnail({ imageModel: val, scope: scope }); + + var wt = parseInt(val.width_n, 10); + var ht = parseInt(val.height_n, 10); + + if( ht !== h ) { + wt = Math.floor(wt * (h / ht)); + } + + ws.push(wt); + }); + + + var rowNum = 0; + var limit = photos.length; + + while(scope.baseline < limit) + { + rowNum++; + // number of images appearing in this row + var c = 0; + // total width of images in this row - including margins + var tw = 0; + + // calculate width of images and number of images to view in this row. + while( (tw * 1.1 < w) && (scope.baseline + c < limit)) + { + tw += ws[scope.baseline + c++] + scope.border * 2; + } + + // Ratio of actual width of row to total width of images to be used. + var r = w / tw; + // image number being processed + var i = 0; + // reset total width to be total width of processed images + tw = 0; + + // new height is not original height * ratio + var ht = Math.floor(h * r); + + var row = {}; + row.photos = []; + row.style = {}; + row.style = {"height": ht + scope.border * 2, "width": scope.lastWidth}; + rows.push(row); + + while( i < c ) + { + var photo = photos[scope.baseline + i]; + // Calculate new width based on ratio + var wt = Math.floor(ws[scope.baseline + i] * r); + // add to total width with margins + tw += wt + scope.border * 2; + + // Create image, set src, width, height and margin + var purl = photo.url_n; + photo.style = {"width": wt, "height": ht, "margin": scope.border+"px", "cursor": "pointer"}; + row.photos.push(photo); + i++; + } + + // set row height to actual height + margins + scope.baseline += c; + + // if total width is slightly smaller than + // actual div width then add 1 to each + // photo width till they match + i = 0; + while( tw < w ) + { + row.photos[i].style.width++; + i = (i + 1) % c; + tw++; + } + + // if total width is slightly bigger than + // actual div width then subtract 1 from each + // photo width till they match + i = 0; + while( tw > w ) + { + row.photos[i].style.width--; + i = (i + 1) % c; + tw--; + } + } + + //populate the scope + scope.rows = rows; + + }, 500); //end timeout + } //end if modelValue + + }; //end $render + } + }; +}); diff --git a/src/Umbraco.Web.UI.Client/src/views/directives/html/umb-photo-folder.html b/src/Umbraco.Web.UI.Client/src/views/directives/html/umb-photo-folder.html new file mode 100644 index 0000000000..0e4131f3ad --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/directives/html/umb-photo-folder.html @@ -0,0 +1,8 @@ +
+
+ +
+
\ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/test/unit/common/services/umb-image-helper.spec.js b/src/Umbraco.Web.UI.Client/test/unit/common/services/umb-image-helper.spec.js index 1fc20de3f2..886ebbd0c9 100644 --- a/src/Umbraco.Web.UI.Client/test/unit/common/services/umb-image-helper.spec.js +++ b/src/Umbraco.Web.UI.Client/test/unit/common/services/umb-image-helper.spec.js @@ -1,4 +1,4 @@ -describe('icon helper tests', function () { +describe('image helper tests', function () { var umbImageHelper; beforeEach(module('umbraco.services')); @@ -29,9 +29,9 @@ describe('icon helper tests', function () { var image2 = "a-png.png"; var image3 = "thisisagif.blah.gif"; - expect(umbImageHelper.getThumbnailFromPath(image1)).toBe("a-jpeg_thumb.jpg"); - expect(umbImageHelper.getThumbnailFromPath(image2)).toBe("a-png_thumb.jpg"); - expect(umbImageHelper.getThumbnailFromPath(image3)).toBe("thisisagif.blah_thumb.jpg"); + expect(umbImageHelper.getThumbnailFromPath(image1)).toBe("a-jpeg_big-thumb.jpg"); + expect(umbImageHelper.getThumbnailFromPath(image2)).toBe("a-png_big-thumb.jpg"); + expect(umbImageHelper.getThumbnailFromPath(image3)).toBe("thisisagif.blah_big-thumb.jpg"); }); }); From e9f69e39abeb9e7daecc6210965bd7e37320d0c8 Mon Sep 17 00:00:00 2001 From: perploug Date: Tue, 24 Sep 2013 14:47:06 +0200 Subject: [PATCH 2/4] Adds folder icons to the photo folder directive --- .../html/umbphotofolder.directive.js | 49 ++++++++++++------- .../src/less/property-editors.less | 44 +++++++++++++++-- .../common/dialogs/mediapicker.controller.js | 16 ++++++ .../src/views/common/dialogs/mediapicker.html | 9 ++++ .../directives/html/umb-photo-folder.html | 28 +++++++++-- .../folderbrowser/folderbrowser.controller.js | 2 +- .../mediapicker/mediapicker.html | 2 +- 7 files changed, 122 insertions(+), 28 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/html/umbphotofolder.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/html/umbphotofolder.directive.js index 50bbca7574..814db432d0 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/html/umbphotofolder.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/html/umbphotofolder.directive.js @@ -28,11 +28,11 @@ angular.module("umbraco.directives.html") var photos = ngModel.$modelValue; var rows = []; - scope.baseline = element.attr('baseline') | 0; - scope.minWidth = element.attr('minwidth') | 420; - scope.minHeight = element.attr('minheight') | 200; - scope.border = element.attr('border') | 5; - + scope.baseline = element.attr('baseline') ? parseInt(element.attr('baseline'),10) : 0; + scope.minWidth = element.attr('min-width') ? parseInt(element.attr('min-width'),10) : 420; + scope.minHeight = element.attr('min-height') ? parseInt(element.attr('min-height'),10) : 200; + scope.border = element.attr('border') ? parseInt(element.attr('border'),10) : 5; + scope.clickHandler = scope.$eval(element.attr('on-click')); scope.lastWidth = Math.max(element.width(), scope.minWidth); // get row width - this is fixed. @@ -46,24 +46,30 @@ angular.module("umbraco.directives.html") // store relative widths of all images (scaled to match estimate height above) var ws = []; $.each(photos, function(key, val) { - val.width_n = $.grep(val.properties, function(val, index) {return (val.alias === "umbracoWidth");})[0].value; - val.height_n = $.grep(val.properties, function(val, index) {return (val.alias === "umbracoHeight");})[0].value; - val.url_n = imageHelper.getThumbnail({ imageModel: val, scope: scope }); - - var wt = parseInt(val.width_n, 10); - var ht = parseInt(val.height_n, 10); - - if( ht !== h ) { - wt = Math.floor(wt * (h / ht)); - } - - ws.push(wt); + + val.width_n = $.grep(val.properties, function(val, index) {return (val.alias === "umbracoWidth");})[0]; + val.height_n = $.grep(val.properties, function(val, index) {return (val.alias === "umbracoHeight");})[0]; + + //val.url_n = imageHelper.getThumbnail({ imageModel: val, scope: scope }); + + if(val.width_n && val.height_n){ + var wt = parseInt(val.width_n.value, 10); + var ht = parseInt(val.height_n.value, 10); + + if( ht !== h ) { + wt = Math.floor(wt * (h / ht)); + } + + ws.push(wt); + }else{ + //if its files or folders, we make them square + ws.push(scope.minHeight); + } }); var rowNum = 0; var limit = photos.length; - while(scope.baseline < limit) { rowNum++; @@ -103,7 +109,12 @@ angular.module("umbraco.directives.html") tw += wt + scope.border * 2; // Create image, set src, width, height and margin - var purl = photo.url_n; + //var purl = photo.url_n; + photo.thumbnail = imageHelper.getThumbnail({ imageModel: photo, scope: scope }); + if(!photo.thumbnail){ + photo.thumbnail = "none"; + } + photo.style = {"width": wt, "height": ht, "margin": scope.border+"px", "cursor": "pointer"}; row.photos.push(photo); i++; diff --git a/src/Umbraco.Web.UI.Client/src/less/property-editors.less b/src/Umbraco.Web.UI.Client/src/less/property-editors.less index 756560931a..7206b272bb 100644 --- a/src/Umbraco.Web.UI.Client/src/less/property-editors.less +++ b/src/Umbraco.Web.UI.Client/src/less/property-editors.less @@ -32,14 +32,52 @@ ul.color-picker li a { border:none; } + // // Media picker // -------------------------------------------------- .umb-mediapicker .add-link{ display: inline-block; - height: 100px; - width: 100px; + height: 120px; + width: 120px; + text-align: center; + color: @grayLight; + border: 2px @grayLight dashed !important; + line-height: 120px; +} + + +// +// folder-browser +// -------------------------------------------------- +.umb-folderbrowser .add-link{ + display: inline-block; + height: 120px; + width: 120px; text-align: center; border: 1px @grayLight dashed; - line-height: 100px + line-height: 120px } + +// +// Photo folder styling +// -------------------------------------------------- + +.umb-photo-folder .umb-non-thumbnail{ + text-align: center; + color: @gray; + font-size: 12px; +} + +.umb-photo-folder .umb-non-thumbnail i{ + color: @grayLight; + font-size: 60px; + line-height: 80px; + display: block +} + + +.umb-photo-folder .selected img{ + opacity:0.5; +} + diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/mediapicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/mediapicker.controller.js index a813f76d67..8c02df4bbd 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/mediapicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/mediapicker.controller.js @@ -55,6 +55,22 @@ angular.module("umbraco") $scope.gotoFolder($scope.options.formData.currentFolder); }); + $scope.clickHandler = function(image, ev){ + if (image.contentTypeAlias.toLowerCase() == 'folder') { + $scope.options.formData.currentFolder = image.id; + $scope.gotoFolder(image.id); + }else if (image.contentTypeAlias.toLowerCase() == 'image') { + eventsService.publish("Umbraco.Dialogs.MediaPickerController.Select", image).then(function(image){ + if(dialogOptions && dialogOptions.multipicker){ + $scope.select(image); + image.cssclass = ($scope.dialogData.selection.indexOf(image) > -1) ? "selected" : ""; + }else{ + $scope.submit(image); + } + }); + } + }; + $scope.selectMediaItem = function(image) { if (image.contentTypeAlias.toLowerCase() == 'folder') { $scope.options.formData.currentFolder = image.id; diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/mediapicker.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/mediapicker.html index 68660a25ee..cb433fbaed 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/mediapicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/mediapicker.html @@ -57,6 +57,14 @@ data-file-upload="options" data-file-upload-progress="" data-ng-class="{'fileupl
+ + +