Skip to content

Commit a825d68

Browse files
authored
Merge pull request #87 from umbraco/feature/aprimo-integration
Feature/aprimo integration
2 parents 63b6c4e + 697fc64 commit a825d68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2199
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Integrations.DAM.Aprimo.Models.ViewModels.AprimoAssetViewModel>
2+
3+
<!-- Thumbnail -->
4+
<div class="aprimo-asset-row">
5+
@if (!string.IsNullOrEmpty(Model.Thumbnail))
6+
{
7+
<img class="thumbnail" src="@Model.Thumbnail" alt="@Model.Title" />
8+
}
9+
<div class="text">
10+
<h3>@Model.Title</h3>
11+
</div>
12+
</div>
13+
<!-- Crops -->
14+
@if (Model.MediaWithCrops != null)
15+
{
16+
<div class="aprimo-asset-row">
17+
<h3>Cropped images</h3>
18+
@if (Model.MediaWithCrops.Original != null)
19+
{
20+
<div class="column">
21+
<h3>@Model.MediaWithCrops.Original.Name</h3>
22+
@if (!string.IsNullOrEmpty(Model.MediaWithCrops.Original.Url))
23+
{
24+
<img src="@Model.MediaWithCrops.Original.Url" class="thumbnail" alt="@Model.MediaWithCrops.Original.Name" />
25+
}
26+
</div>
27+
}
28+
@if (Model.MediaWithCrops.Crops.Any())
29+
{
30+
@foreach (var cropItem in Model.MediaWithCrops.Crops)
31+
{
32+
<div class="column">
33+
@if (!string.IsNullOrEmpty(cropItem.Url))
34+
{
35+
<img src="@cropItem.Url" class="thumbnail" alt="@cropItem.Name" width="@cropItem.ResizeWidth" height="@cropItem.ResizeHeight" />
36+
}
37+
<h3>@cropItem.Name</h3>
38+
<p>
39+
@cropItem.Extension - @($"{cropItem.ResizeWidth} x {cropItem.ResizeHeight} px")
40+
</p>
41+
</div>
42+
}
43+
}
44+
</div>
45+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.aprimo-editor-container {
2+
margin: 20px;
3+
}
4+
5+
.aprimo-search {
6+
width: 70%;
7+
}
8+
9+
.aprimo-center {
10+
display: block;
11+
margin: auto;
12+
width: 50%;
13+
padding: 10px;
14+
}
15+
16+
.aprimo-label {
17+
font-size: 15px;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
angular.module("umbraco.resources").factory("umbracoCmsIntegrationsDamAprimoResource",
2+
function ($http, umbRequestHelper) {
3+
const apiEndpoint = "backoffice/UmbracoCmsIntegrationsDamAprimo/Assets";
4+
5+
return {
6+
checkApiConfiguration: function () {
7+
return umbRequestHelper.resourcePromise(
8+
$http.get(`${apiEndpoint}/CheckApiConfiguration`),
9+
"Failed to access resource");
10+
},
11+
getAuthorizationUrl: function () {
12+
return umbRequestHelper.resourcePromise(
13+
$http.get(`${apiEndpoint}/GetAuthorizationUrl`),
14+
"Failed to access resource");
15+
},
16+
getContentSelectorUrl: function () {
17+
return umbRequestHelper.resourcePromise(
18+
$http.get(`${apiEndpoint}/GetContentSelectorUrl`),
19+
"Failed to access resource");
20+
},
21+
getAccessToken: function (authorizationCode) {
22+
return umbRequestHelper.resourcePromise(
23+
$http.post(`${apiEndpoint}/GetAccessToken`, { code: authorizationCode }),
24+
"Failed to access resource");
25+
},
26+
refreshAccessToken: function () {
27+
return umbRequestHelper.resourcePromise(
28+
$http.post(`${apiEndpoint}/RefreshAccessToken`),
29+
"Failed");
30+
},
31+
getRecords: function (page, searchTerm) {
32+
return umbRequestHelper.resourcePromise(
33+
$http.get(`${apiEndpoint}/GetRecords?page=${page}&searchTerm=${searchTerm}`),
34+
"Failed to access resource");
35+
},
36+
getRecordDetails: function (id) {
37+
return umbRequestHelper.resourcePromise(
38+
$http.get(`${apiEndpoint}/GetRecordDetails?id=${id}`),
39+
"Failed to access resource");
40+
},
41+
revokeAccessToken: function () {
42+
return umbRequestHelper.resourcePromise(
43+
$http.delete(`${apiEndpoint}/RevokeAccessToken`),
44+
"Failed to access resource");
45+
}
46+
};
47+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function aprimoService() {
2+
return {
3+
browserIsSupported: function () {
4+
return !(window.navigator.userAgent.toLowerCase().indexOf("firefox") > -1
5+
|| window.navigator.userAgent.toLowerCase().indexOf("trident") > -1);
6+
}
7+
}
8+
}
9+
10+
angular.module("umbraco.services")
11+
.service("umbracoCmsIntegrationsDamAprimoService", aprimoService);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
angular.module("umbraco.directives")
2+
.directive("browserSupport", function () {
3+
return {
4+
restrict: "E",
5+
templateUrl: "/App_Plugins/UmbracoCms.Integrations/DAM/Aprimo/views/browser-support.html"
6+
}
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
function configurationController($scope, notificationsService, umbracoCmsIntegrationsDamAprimoService, umbracoCmsIntegrationsDamAprimoResource) {
2+
var vm = this;
3+
4+
vm.configuration = {};
5+
6+
vm.useContentSelector = false;
7+
8+
const useContentSelector = document.getElementById("useContentSelector");
9+
if ($scope.model.value != null && $scope.model.value.useContentSelector != null) {
10+
useContentSelector.checked = $scope.model.value.useContentSelector;
11+
vm.useContentSelector = $scope.model.value.useContentSelector;
12+
}
13+
14+
const btnConnect = document.getElementById("btnConnect");
15+
const btnRevoke = document.getElementById("btnRevoke");
16+
17+
checkApiConfiguration();
18+
19+
$scope.$on('formSubmitting', function (ev) {
20+
$scope.model.value = {
21+
useContentSelector: vm.useContentSelector
22+
};
23+
});
24+
25+
vm.onConnect = () => {
26+
window.addEventListener("message", handleAuthEvent, false);
27+
28+
umbracoCmsIntegrationsDamAprimoResource.getAuthorizationUrl().then(function (response) {
29+
window.open(response,
30+
"Aprimo Authorize", "width=900,height=700,modal=yes,alwaysRaised=yes");
31+
});
32+
};
33+
34+
vm.onRevoke = () => {
35+
window.removeEventListener("message", handleAuthEvent);
36+
umbracoCmsIntegrationsDamAprimoResource.revokeAccessToken().then(function () {
37+
vm.configuration.isAuthorized = false;
38+
vm.configuration.icon = "lock";
39+
vm.configuration.tag = "danger";
40+
vm.configuration.message = "Invalid access token.";
41+
42+
toggleDisabledState(
43+
vm.configuration.isAuthorized
44+
? btnRevoke : btnConnect,
45+
vm.configuration.isAuthorized
46+
? btnConnect : btnRevoke);
47+
48+
notificationsService.success("Aprimo", "Access token revoked.");
49+
});
50+
};
51+
52+
vm.onUseContentSelector = () => {
53+
vm.useContentSelector = useContentSelector.checked;
54+
}
55+
56+
function handleAuthEvent(event) {
57+
if (event.data.type === "aprimo:oauth:success") {
58+
notificationsService.success("Aprimo", "Connected.");
59+
checkApiConfiguration();
60+
} else if (event.data.type === "aprimo:oauth:error") {
61+
notificationsService.error("Aprimo", event.data.response);
62+
}
63+
}
64+
65+
function checkApiConfiguration() {
66+
umbracoCmsIntegrationsDamAprimoResource.checkApiConfiguration().then(function (response) {
67+
68+
vm.configuration = {
69+
isAuthorized: response.isAuthorized,
70+
icon: response.failure ? "lock" : "unlock",
71+
tag: response.failure ? "danger" : "positive",
72+
message: response.failure ? response.error : "Connected.",
73+
browserIsSupported: umbracoCmsIntegrationsDamAprimoService.browserIsSupported()
74+
};
75+
76+
toggleDisabledState(
77+
vm.configuration.isAuthorized
78+
? btnRevoke : btnConnect,
79+
vm.configuration.isAuthorized
80+
? btnConnect : btnRevoke);
81+
});
82+
}
83+
84+
function toggleDisabledState(activeCtrl, disabledCtrl) {
85+
activeCtrl.removeAttribute("disabled");
86+
disabledCtrl.setAttribute("disabled", "");
87+
}
88+
}
89+
90+
angular.module("umbraco")
91+
.controller("Umbraco.Cms.Integrations.DAM.Aprimo.ConfigurationController", configurationController)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
function mediaPickerController($scope, editorService, notificationsService, umbracoCmsIntegrationsDamAprimoService, umbracoCmsIntegrationsDamAprimoResource) {
2+
3+
var vm = this;
4+
5+
vm.selectedRecord = null;
6+
;
7+
vm.error = "";
8+
9+
umbracoCmsIntegrationsDamAprimoResource.checkApiConfiguration().then(function (response) {
10+
if (response.success) {
11+
if ($scope.model.value != null && $scope.model.value.length > 0) {
12+
umbracoCmsIntegrationsDamAprimoResource.getRecordDetails($scope.model.value).then(function (recordResponse) {
13+
if (recordResponse.success) {
14+
vm.selectedRecord = {
15+
title: recordResponse.data.title,
16+
extension: recordResponse.data.thumbnail.extension,
17+
uri: recordResponse.data.thumbnail.uri
18+
};
19+
} else
20+
notificationsService.error("Aprimo", recordResponse.error);
21+
});
22+
}
23+
} else {
24+
vm.error = response.error;
25+
}
26+
});
27+
28+
vm.selectRecord = () => {
29+
if ($scope.model.config.configuration.useContentSelector)
30+
openAprimoContentSelector();
31+
else
32+
openAprimoMediaPickerOverlay();
33+
}
34+
35+
vm.saveAsset = (id) => {
36+
$scope.model.value = id;
37+
38+
umbracoCmsIntegrationsDamAprimoResource.getRecordDetails(id).then(function (recordResponse) {
39+
if (recordResponse.success) {
40+
vm.selectedRecord = {
41+
title: recordResponse.data.title,
42+
extension: recordResponse.data.thumbnail.extension,
43+
uri: recordResponse.data.thumbnail.uri
44+
};
45+
} else
46+
notificationsService.error("Aprimo", recordResponse.error);
47+
});
48+
}
49+
50+
vm.removeAsset = () => {
51+
$scope.model.value = null;
52+
vm.selectedRecord = null;
53+
}
54+
55+
function openAprimoMediaPickerOverlay() {
56+
var options = {
57+
title: "Aprimo Content API",
58+
subtitle: "Please select an asset",
59+
configuration: $scope.model.config.configuration,
60+
view: "/App_Plugins/UmbracoCms.Integrations/DAM/Aprimo/views/mediapickereditor.html",
61+
size: "medium",
62+
save: function (id) {
63+
vm.saveAsset(id);
64+
65+
editorService.close();
66+
},
67+
close: function () {
68+
editorService.close();
69+
}
70+
};
71+
72+
editorService.open(options);
73+
};
74+
75+
function openAprimoContentSelector() {
76+
umbracoCmsIntegrationsDamAprimoResource.getContentSelectorUrl().then(function (response) {
77+
if (response.length > 0) {
78+
window.open(response,
79+
"Aprimo Content Selector",
80+
"width=900,height=700,modal=yes,alwaysRaised=yes");
81+
82+
window.addEventListener("message", function (event) {
83+
if (event.data.result !== 'cancel' && event.data.selection !== undefined) {
84+
vm.saveAsset(event.data.selection[0].id);
85+
}
86+
}, false);
87+
}
88+
else
89+
notificationsService.warning("Aprimo", "Could not retrieve content selector URL.");
90+
});
91+
}
92+
}
93+
94+
angular.module("umbraco")
95+
.controller("Umbraco.Cms.Integrations.DAM.Aprimo.MediaPickerController", mediaPickerController);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
function mediaPickerEditorController($scope, notificationsService,
2+
umbracoCmsIntegrationsDamAprimoService, umbracoCmsIntegrationsDamAprimoResource) {
3+
4+
var vm = this;
5+
6+
vm.loading = false;
7+
vm.data = {};
8+
vm.searchTerm = "";
9+
vm.browserIsSupported = umbracoCmsIntegrationsDamAprimoService.browserIsSupported();
10+
11+
vm.pagination = {
12+
pageNumber: 1,
13+
totalPages: 1
14+
};
15+
vm.nextPage = goToPage;
16+
vm.prevPage = goToPage;
17+
vm.changePage = goToPage;
18+
vm.goToPage = goToPage;
19+
20+
umbracoCmsIntegrationsDamAprimoResource.checkApiConfiguration().then(function (response) {
21+
if (response.success) {
22+
vm.loading = true;
23+
query(1);
24+
}
25+
else
26+
notificationsService.error("Aprimo", response.error);
27+
});
28+
29+
vm.search = () => {
30+
query(1);
31+
}
32+
33+
vm.clearSearch = () => {
34+
vm.searchTerm = "";
35+
query(1);
36+
}
37+
38+
vm.save = (id) => {
39+
$scope.model.save(id);
40+
}
41+
42+
function query(page) {
43+
vm.loading = true;
44+
umbracoCmsIntegrationsDamAprimoResource.getRecords(page, vm.searchTerm).then(function (recordsResponse) {
45+
if (recordsResponse.success) {
46+
vm.data = recordsResponse.data;
47+
48+
vm.pagination.pageNumber = vm.data.page;
49+
vm.pagination.totalPages = Math.ceil(vm.data.totalCount / vm.data.pageSize);
50+
}
51+
else {
52+
notificationsService.error("Aprimo", recordsResponse.error);
53+
}
54+
55+
vm.loading = false;
56+
});
57+
}
58+
59+
function goToPage(page) {
60+
query(page);
61+
}
62+
}
63+
64+
angular.module("umbraco")
65+
.controller("Umbraco.Cms.Integrations.DAM.Aprimo.MediaPickerEditorController", mediaPickerEditorController);

0 commit comments

Comments
 (0)