Chore: update media+mediahelper mocks
This commit is contained in:
@@ -60,7 +60,6 @@ angular.module('umbraco.mocks').
|
||||
active: true,
|
||||
properties: [
|
||||
{ alias: "list", label: "List", view: "listview", value: "", hideLabel: true, config:{entityType: "content"} },
|
||||
{ alias: "media", label: "Media picker", view: "mediapicker", value: "" ,config:{} }
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -70,8 +69,6 @@ angular.module('umbraco.mocks').
|
||||
{ alias: "valTest", label: "Validation test", view: "validationtest", value: "asdfasdf" },
|
||||
{ alias: "bodyText", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
|
||||
{ alias: "textarea", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
|
||||
{ alias: "map", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
|
||||
|
||||
{ alias: "media", label: "Media picker", view: "mediapicker", value: "1234,23242,23232,23231", config: {multiPicker: 1} }
|
||||
]
|
||||
},
|
||||
@@ -90,8 +87,6 @@ angular.module('umbraco.mocks').
|
||||
{ alias: "valTest4", label: "Validation test", view: "validationtest", value: "asdfasdf" },
|
||||
{ alias: "bodyText4", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
|
||||
{ alias: "textarea4", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
|
||||
{ alias: "map4", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
|
||||
|
||||
{ alias: "content4", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
|
||||
]
|
||||
},
|
||||
@@ -102,8 +97,6 @@ angular.module('umbraco.mocks').
|
||||
{ alias: "valTest5", label: "Validation test", view: "validationtest", value: "asdfasdf" },
|
||||
{ alias: "bodyText5", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
|
||||
{ alias: "textarea5", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
|
||||
{ alias: "map5", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
|
||||
|
||||
{ alias: "content5", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
|
||||
]
|
||||
},
|
||||
@@ -114,8 +107,6 @@ angular.module('umbraco.mocks').
|
||||
{ alias: "valTest6", label: "Validation test", view: "validationtest", value: "asdfasdf" },
|
||||
{ alias: "bodyText6", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
|
||||
{ alias: "textarea6", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
|
||||
{ alias: "map6", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
|
||||
|
||||
{ alias: "content6", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
|
||||
]
|
||||
},
|
||||
@@ -126,8 +117,6 @@ angular.module('umbraco.mocks').
|
||||
{ alias: "valTest7", label: "Validation test", view: "validationtest", value: "asdfasdf" },
|
||||
{ alias: "bodyText7", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
|
||||
{ alias: "textarea7", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
|
||||
{ alias: "map7", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
|
||||
|
||||
{ alias: "content7", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
|
||||
]
|
||||
},
|
||||
|
||||
@@ -61,8 +61,8 @@ angular.module('umbraco.mocks').
|
||||
return {
|
||||
register: function() {
|
||||
$httpBackend
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Media/GetById?'))
|
||||
.respond(returnNodebyId);
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Media/GetById?'))
|
||||
.respond(returnNodebyId);
|
||||
|
||||
$httpBackend
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Media/GetByIds?'))
|
||||
|
||||
@@ -1,20 +1,141 @@
|
||||
angular.module('umbraco.mocks').
|
||||
factory('imageHelperMocks', ['$httpBackend', 'mocksUtils', function ($httpBackend, mocksUtils) {
|
||||
'use strict';
|
||||
|
||||
function returnEntitybyIds(){
|
||||
return "hello.jpg";
|
||||
}
|
||||
/**
|
||||
* @ngdoc service
|
||||
* @name umbraco.mocks.mediaHelperService
|
||||
* @description A helper object used for dealing with media items
|
||||
**/
|
||||
function mediaHelper(umbRequestHelper) {
|
||||
return {
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.mediaHelper#getImagePropertyValue
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Returns the file path associated with the media property if there is one
|
||||
*
|
||||
* @param {object} options Options object
|
||||
* @param {object} options.mediaModel The media object to retrieve the image path from
|
||||
* @param {object} options.imageOnly Optional, if true then will only return a path if the media item is an image
|
||||
*/
|
||||
getMediaPropertyValue: function (options) {
|
||||
return "assets/img/mocks/image.jpg";
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.mediaHelper#getImagePropertyValue
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Returns the actual image path associated with the image property if there is one
|
||||
*
|
||||
* @param {object} options Options object
|
||||
* @param {object} options.imageModel The media object to retrieve the image path from
|
||||
*/
|
||||
getImagePropertyValue: function (options) {
|
||||
return "assets/img/mocks/image.jpg";
|
||||
},
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.mediaHelper#getThumbnail
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* formats the display model used to display the content to the model used to save the content
|
||||
*
|
||||
* @param {object} options Options object
|
||||
* @param {object} options.imageModel The media object to retrieve the image path from
|
||||
*/
|
||||
getThumbnail: function (options) {
|
||||
|
||||
if (!options || !options.imageModel) {
|
||||
throw "The options objet does not contain the required parameters: imageModel";
|
||||
}
|
||||
|
||||
return {
|
||||
register: function () {
|
||||
var imagePropVal = this.getImagePropertyValue(options);
|
||||
if (imagePropVal !== "") {
|
||||
return this.getThumbnailFromPath(imagePropVal);
|
||||
}
|
||||
return "";
|
||||
},
|
||||
|
||||
$httpBackend
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Images/GetBigThumbnail'))
|
||||
.respond(returnEntitybyIds);
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.mediaHelper#scaleToMaxSize
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Finds the corrct max width and max height, given maximum dimensions and keeping aspect ratios
|
||||
*
|
||||
* @param {number} maxSize Maximum width & height
|
||||
* @param {number} width Current width
|
||||
* @param {number} height Current height
|
||||
*/
|
||||
scaleToMaxSize: function (maxSize, width, height) {
|
||||
var retval = { width: width, height: height };
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
}]);
|
||||
var maxWidth = maxSize; // Max width for the image
|
||||
var maxHeight = maxSize; // Max height for the image
|
||||
var ratio = 0; // Used for aspect ratio
|
||||
|
||||
// Check if the current width is larger than the max
|
||||
if (width > maxWidth) {
|
||||
ratio = maxWidth / width; // get ratio for scaling image
|
||||
|
||||
retval.width = maxWidth;
|
||||
retval.height = height * ratio;
|
||||
|
||||
height = height * ratio; // Reset height to match scaled image
|
||||
width = width * ratio; // Reset width to match scaled image
|
||||
}
|
||||
|
||||
// Check if current height is larger than max
|
||||
if (height > maxHeight) {
|
||||
ratio = maxHeight / height; // get ratio for scaling image
|
||||
|
||||
retval.height = maxHeight;
|
||||
retval.width = width * ratio;
|
||||
width = width * ratio; // Reset width to match scaled image
|
||||
}
|
||||
|
||||
return retval;
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.mediaHelper#getThumbnailFromPath
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Returns the path to the thumbnail version of a given media library image path
|
||||
*
|
||||
* @param {string} imagePath Image path, ex: /media/1234/my-image.jpg
|
||||
*/
|
||||
getThumbnailFromPath: function (imagePath) {
|
||||
return "assets/img/mocks/big-thumb.jpg";
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.mediaHelper#detectIfImageByExtension
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Returns true/false, indicating if the given path has an allowed image extension
|
||||
*
|
||||
* @param {string} imagePath Image path, ex: /media/1234/my-image.jpg
|
||||
*/
|
||||
detectIfImageByExtension: function (imagePath) {
|
||||
var lowered = imagePath.toLowerCase();
|
||||
var ext = lowered.substr(lowered.lastIndexOf(".") + 1);
|
||||
return ("," + Umbraco.Sys.ServerVariables.umbracoSettings.imageFileTypes + ",").indexOf("," + ext + ",") !== -1;
|
||||
}
|
||||
};
|
||||
}
|
||||
angular.module('umbraco.mocks').factory('mediaHelper', mediaHelper);
|
||||
@@ -207,73 +207,4 @@ function mediaHelper(umbRequestHelper) {
|
||||
}
|
||||
};
|
||||
}
|
||||
angular.module('umbraco.services').factory('mediaHelper', mediaHelper);
|
||||
|
||||
/**
|
||||
* @ngdoc service
|
||||
* @name umbraco.services.imageHelper
|
||||
* @deprecated
|
||||
**/
|
||||
function imageHelper(umbRequestHelper, mediaHelper) {
|
||||
return {
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#getImagePropertyValue
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
getImagePropertyValue: function (options) {
|
||||
return mediaHelper.getImagePropertyValue(options);
|
||||
},
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#getThumbnail
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
getThumbnail: function (options) {
|
||||
return mediaHelper.getThumbnail(options);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#scaleToMaxSize
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
scaleToMaxSize: function (maxSize, width, height) {
|
||||
return mediaHelper.scaleToMaxSize(maxSize, width, height);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#getThumbnailFromPath
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
getThumbnailFromPath: function (imagePath) {
|
||||
return mediaHelper.getThumbnailFromPath(imagePath);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#detectIfImageByExtension
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
detectIfImageByExtension: function (imagePath) {
|
||||
return mediaHelper.detectIfImageByExtension(imagePath);
|
||||
}
|
||||
};
|
||||
}
|
||||
angular.module('umbraco.services').factory('imageHelper', imageHelper);
|
||||
angular.module('umbraco.services').factory('mediaHelper', mediaHelper);
|
||||
Reference in New Issue
Block a user