Skip to content

Commit 722a6bb

Browse files
authored
Merge pull request #94 from umbraco/feature/aprimo-integration
Feature/aprimo integration
2 parents 197f264 + 9f6d325 commit 722a6bb

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/Umbraco.Cms.Integrations.DAM.Aprimo/Models/ViewModels/AprimoMediaWithCropsViewModel.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,35 @@ public class AprimoMediaWithCropsViewModel
1212
/// </summary>
1313
/// <param name="name"></param>
1414
/// <returns>Crop URL</returns>
15-
public string GetImageUrl(string name)
15+
public string GetCropUrl(string name)
1616
{
1717
var crop = Crops.FirstOrDefault(p => p.Name == name);
1818
if (crop != null)
1919
return crop.Url;
2020

2121
return string.Empty;
2222
}
23+
24+
/// <summary>
25+
/// Get image URL by size
26+
/// </summary>
27+
/// <param name="name"></param>
28+
/// <returns>Crop URL</returns>
29+
public string GetCropUrl(int? width, int? height)
30+
{
31+
if (!width.HasValue && !height.HasValue)
32+
throw new ArgumentException("Width and height cannot be both NULL.");
33+
34+
var crop = width.HasValue && height.HasValue
35+
? Crops.FirstOrDefault(p => p.ResizeWidth == width && p.ResizeHeight == height)
36+
: (width.HasValue
37+
? Crops.FirstOrDefault(p => p.ResizeWidth == width)
38+
: Crops.FirstOrDefault(p => p.ResizeHeight == height));
39+
if (crop != null)
40+
return crop.Url;
41+
42+
return string.Empty;
43+
}
2344
}
2445

2546
public class AprimoMediaItemViewModel

src/Umbraco.Cms.Integrations.DAM.Aprimo/readme.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Umbraco.Cms.Integrations.DAM.Aprimo
1+
# Umbraco.Cms.Integrations.DAM.Aprimo
22

33
This integration provides a custom media picker for digital assets managed in an Aprimo workspace. It can be used as a property editor for content with a value converter providing a strongly typed model for rendering, as well as a sample rendering component.
44

@@ -78,5 +78,26 @@ Properties available from the strongly-typed model:
7878
- Crops
7979
- Asset fields
8080

81+
### Working with Crops
82+
For the selected media asset you can retrieve the crops details using the `MediaWithCrops` object.
83+
84+
It contains the details of the original asset, the list of available crops and a method to retrieve the crop URL based on name and width/height.
85+
86+
For example:
87+
- get URL for crop item with the name _Social_: `@Model.MediaWithCrops.GetCropUrl("Social")`
88+
- get URL for crop item with height _1080_: `@Model.MediaWithCrops.GetCropUrl(null, 1080)`
89+
90+
### Working with fields
91+
The asset's fields are grouped in an object containing their label and a dictionary of values based on the available cultures for that asset.
92+
93+
For example:
94+
- get values for a field with label _Display Title_:
95+
```
96+
var displayTitle = @Model.Fields.FirstOrDefault(p => p.Label == "Display Title");
97+
var values = displayTitle != null
98+
? displayTitle.Values
99+
: default(Dictionary<string, string>());
100+
```
101+
81102
### Version history
82103
- 1.0.0 - Initial release

0 commit comments

Comments
 (0)