Skip to content

Commit ce9cfbf

Browse files
author
perploug
committed
Chore: update media+mediahelper mocks
1 parent 8024bde commit ce9cfbf

File tree

4 files changed

+144
-103
lines changed

4 files changed

+144
-103
lines changed

src/Umbraco.Web.UI.Client/src/common/mocks/resources/_utils.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ angular.module('umbraco.mocks').
6060
active: true,
6161
properties: [
6262
{ alias: "list", label: "List", view: "listview", value: "", hideLabel: true, config:{entityType: "content"} },
63-
{ alias: "media", label: "Media picker", view: "mediapicker", value: "" ,config:{} }
6463
]
6564
},
6665
{
@@ -70,8 +69,6 @@ angular.module('umbraco.mocks').
7069
{ alias: "valTest", label: "Validation test", view: "validationtest", value: "asdfasdf" },
7170
{ alias: "bodyText", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
7271
{ alias: "textarea", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
73-
{ alias: "map", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
74-
7572
{ alias: "media", label: "Media picker", view: "mediapicker", value: "1234,23242,23232,23231", config: {multiPicker: 1} }
7673
]
7774
},
@@ -90,8 +87,6 @@ angular.module('umbraco.mocks').
9087
{ alias: "valTest4", label: "Validation test", view: "validationtest", value: "asdfasdf" },
9188
{ alias: "bodyText4", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
9289
{ alias: "textarea4", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
93-
{ alias: "map4", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
94-
9590
{ alias: "content4", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
9691
]
9792
},
@@ -102,8 +97,6 @@ angular.module('umbraco.mocks').
10297
{ alias: "valTest5", label: "Validation test", view: "validationtest", value: "asdfasdf" },
10398
{ alias: "bodyText5", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
10499
{ alias: "textarea5", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
105-
{ alias: "map5", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
106-
107100
{ alias: "content5", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
108101
]
109102
},
@@ -114,8 +107,6 @@ angular.module('umbraco.mocks').
114107
{ alias: "valTest6", label: "Validation test", view: "validationtest", value: "asdfasdf" },
115108
{ alias: "bodyText6", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
116109
{ alias: "textarea6", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
117-
{ alias: "map6", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
118-
119110
{ alias: "content6", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
120111
]
121112
},
@@ -126,8 +117,6 @@ angular.module('umbraco.mocks').
126117
{ alias: "valTest7", label: "Validation test", view: "validationtest", value: "asdfasdf" },
127118
{ alias: "bodyText7", label: "Body Text", description: "Here you enter the primary article contents", view: "rte", value: "<p>askjdkasj lasjd</p>", config: {} },
128119
{ alias: "textarea7", label: "textarea", view: "textarea", value: "ajsdka sdjkds", config: { rows: 4 } },
129-
{ alias: "map7", label: "Map", view: "googlemaps", value: "37.4419,-122.1419", config: { mapType: "ROADMAP", zoom: 4 } },
130-
131120
{ alias: "content7", label: "Content picker", view: "contentpicker", value: "1234,23242,23232,23231" }
132121
]
133122
},

src/Umbraco.Web.UI.Client/src/common/mocks/resources/media.mocks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ angular.module('umbraco.mocks').
6161
return {
6262
register: function() {
6363
$httpBackend
64-
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Media/GetById?'))
65-
.respond(returnNodebyId);
64+
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Media/GetById?'))
65+
.respond(returnNodebyId);
6666

6767
$httpBackend
6868
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Media/GetByIds?'))
Lines changed: 141 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,141 @@
1-
angular.module('umbraco.mocks').
2-
factory('imageHelperMocks', ['$httpBackend', 'mocksUtils', function ($httpBackend, mocksUtils) {
3-
'use strict';
4-
5-
function returnEntitybyIds(){
6-
return "hello.jpg";
7-
}
8-
9-
10-
return {
11-
register: function () {
12-
13-
$httpBackend
14-
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Images/GetBigThumbnail'))
15-
.respond(returnEntitybyIds);
16-
17-
18-
}
19-
};
20-
}]);
1+
/**
2+
* @ngdoc service
3+
* @name umbraco.mocks.mediaHelperService
4+
* @description A helper object used for dealing with media items
5+
**/
6+
function mediaHelper(umbRequestHelper) {
7+
return {
8+
/**
9+
* @ngdoc function
10+
* @name umbraco.services.mediaHelper#getImagePropertyValue
11+
* @methodOf umbraco.services.mediaHelper
12+
* @function
13+
*
14+
* @description
15+
* Returns the file path associated with the media property if there is one
16+
*
17+
* @param {object} options Options object
18+
* @param {object} options.mediaModel The media object to retrieve the image path from
19+
* @param {object} options.imageOnly Optional, if true then will only return a path if the media item is an image
20+
*/
21+
getMediaPropertyValue: function (options) {
22+
return "assets/img/mocks/image.jpg";
23+
},
24+
25+
/**
26+
* @ngdoc function
27+
* @name umbraco.services.mediaHelper#getImagePropertyValue
28+
* @methodOf umbraco.services.mediaHelper
29+
* @function
30+
*
31+
* @description
32+
* Returns the actual image path associated with the image property if there is one
33+
*
34+
* @param {object} options Options object
35+
* @param {object} options.imageModel The media object to retrieve the image path from
36+
*/
37+
getImagePropertyValue: function (options) {
38+
return "assets/img/mocks/image.jpg";
39+
},
40+
/**
41+
* @ngdoc function
42+
* @name umbraco.services.mediaHelper#getThumbnail
43+
* @methodOf umbraco.services.mediaHelper
44+
* @function
45+
*
46+
* @description
47+
* formats the display model used to display the content to the model used to save the content
48+
*
49+
* @param {object} options Options object
50+
* @param {object} options.imageModel The media object to retrieve the image path from
51+
*/
52+
getThumbnail: function (options) {
53+
54+
if (!options || !options.imageModel) {
55+
throw "The options objet does not contain the required parameters: imageModel";
56+
}
57+
58+
var imagePropVal = this.getImagePropertyValue(options);
59+
if (imagePropVal !== "") {
60+
return this.getThumbnailFromPath(imagePropVal);
61+
}
62+
return "";
63+
},
64+
65+
/**
66+
* @ngdoc function
67+
* @name umbraco.services.mediaHelper#scaleToMaxSize
68+
* @methodOf umbraco.services.mediaHelper
69+
* @function
70+
*
71+
* @description
72+
* Finds the corrct max width and max height, given maximum dimensions and keeping aspect ratios
73+
*
74+
* @param {number} maxSize Maximum width & height
75+
* @param {number} width Current width
76+
* @param {number} height Current height
77+
*/
78+
scaleToMaxSize: function (maxSize, width, height) {
79+
var retval = { width: width, height: height };
80+
81+
var maxWidth = maxSize; // Max width for the image
82+
var maxHeight = maxSize; // Max height for the image
83+
var ratio = 0; // Used for aspect ratio
84+
85+
// Check if the current width is larger than the max
86+
if (width > maxWidth) {
87+
ratio = maxWidth / width; // get ratio for scaling image
88+
89+
retval.width = maxWidth;
90+
retval.height = height * ratio;
91+
92+
height = height * ratio; // Reset height to match scaled image
93+
width = width * ratio; // Reset width to match scaled image
94+
}
95+
96+
// Check if current height is larger than max
97+
if (height > maxHeight) {
98+
ratio = maxHeight / height; // get ratio for scaling image
99+
100+
retval.height = maxHeight;
101+
retval.width = width * ratio;
102+
width = width * ratio; // Reset width to match scaled image
103+
}
104+
105+
return retval;
106+
},
107+
108+
/**
109+
* @ngdoc function
110+
* @name umbraco.services.mediaHelper#getThumbnailFromPath
111+
* @methodOf umbraco.services.mediaHelper
112+
* @function
113+
*
114+
* @description
115+
* Returns the path to the thumbnail version of a given media library image path
116+
*
117+
* @param {string} imagePath Image path, ex: /media/1234/my-image.jpg
118+
*/
119+
getThumbnailFromPath: function (imagePath) {
120+
return "assets/img/mocks/big-thumb.jpg";
121+
},
122+
123+
/**
124+
* @ngdoc function
125+
* @name umbraco.services.mediaHelper#detectIfImageByExtension
126+
* @methodOf umbraco.services.mediaHelper
127+
* @function
128+
*
129+
* @description
130+
* Returns true/false, indicating if the given path has an allowed image extension
131+
*
132+
* @param {string} imagePath Image path, ex: /media/1234/my-image.jpg
133+
*/
134+
detectIfImageByExtension: function (imagePath) {
135+
var lowered = imagePath.toLowerCase();
136+
var ext = lowered.substr(lowered.lastIndexOf(".") + 1);
137+
return ("," + Umbraco.Sys.ServerVariables.umbracoSettings.imageFileTypes + ",").indexOf("," + ext + ",") !== -1;
138+
}
139+
};
140+
}
141+
angular.module('umbraco.mocks').factory('mediaHelper', mediaHelper);

src/Umbraco.Web.UI.Client/src/common/services/mediahelper.service.js

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -207,73 +207,4 @@ function mediaHelper(umbRequestHelper) {
207207
}
208208
};
209209
}
210-
angular.module('umbraco.services').factory('mediaHelper', mediaHelper);
211-
212-
/**
213-
* @ngdoc service
214-
* @name umbraco.services.imageHelper
215-
* @deprecated
216-
**/
217-
function imageHelper(umbRequestHelper, mediaHelper) {
218-
return {
219-
/**
220-
* @ngdoc function
221-
* @name umbraco.services.imageHelper#getImagePropertyValue
222-
* @methodOf umbraco.services.imageHelper
223-
* @function
224-
*
225-
* @deprecated
226-
*/
227-
getImagePropertyValue: function (options) {
228-
return mediaHelper.getImagePropertyValue(options);
229-
},
230-
/**
231-
* @ngdoc function
232-
* @name umbraco.services.imageHelper#getThumbnail
233-
* @methodOf umbraco.services.imageHelper
234-
* @function
235-
*
236-
* @deprecated
237-
*/
238-
getThumbnail: function (options) {
239-
return mediaHelper.getThumbnail(options);
240-
},
241-
242-
/**
243-
* @ngdoc function
244-
* @name umbraco.services.imageHelper#scaleToMaxSize
245-
* @methodOf umbraco.services.imageHelper
246-
* @function
247-
*
248-
* @deprecated
249-
*/
250-
scaleToMaxSize: function (maxSize, width, height) {
251-
return mediaHelper.scaleToMaxSize(maxSize, width, height);
252-
},
253-
254-
/**
255-
* @ngdoc function
256-
* @name umbraco.services.imageHelper#getThumbnailFromPath
257-
* @methodOf umbraco.services.imageHelper
258-
* @function
259-
*
260-
* @deprecated
261-
*/
262-
getThumbnailFromPath: function (imagePath) {
263-
return mediaHelper.getThumbnailFromPath(imagePath);
264-
},
265-
266-
/**
267-
* @ngdoc function
268-
* @name umbraco.services.imageHelper#detectIfImageByExtension
269-
* @methodOf umbraco.services.imageHelper
270-
* @function
271-
*
272-
* @deprecated
273-
*/
274-
detectIfImageByExtension: function (imagePath) {
275-
return mediaHelper.detectIfImageByExtension(imagePath);
276-
}
277-
};
278-
}
279-
angular.module('umbraco.services').factory('imageHelper', imageHelper);
210+
angular.module('umbraco.services').factory('mediaHelper', mediaHelper);

0 commit comments

Comments
 (0)