Skip to content

Commit 6e35f81

Browse files
authored
Merge pull request #34 from umbraco/feature/hubspot-login-directive
acoumb
2 parents 108e350 + fd232e0 commit 6e35f81

File tree

7 files changed

+64
-12
lines changed

7 files changed

+64
-12
lines changed

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/formpicker.controller.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
vm.searchTerm = "";
1111
vm.error = "";
1212
vm.isValid = true;
13+
vm.isConnected = false;
1314

1415
// check configuration
1516
checkConfiguration(loadForms);
@@ -65,6 +66,7 @@
6566
if (vm.status.useOAuth === true) {
6667
// use OAuth
6768
umbracoCmsIntegrationsCrmHubspotResource.validateAccessToken().then(function (response) {
69+
6870
if (response.isExpired === true || response.isValid === false) {
6971
vm.loading = false;
7072
notificationsService.warning("HubSpot API", "Unable to connect to HubSpot. Please review the settings of the form picker property's data type.");
@@ -77,7 +79,8 @@
7779

7880
if (data.isValid === false || data.isExpired === true) {
7981
notificationsService.error("HubSpot API", "Unable to retrieve the list of forms from HubSpot. Please review the settings of the form picker property's data type.");
80-
}
82+
} else
83+
vm.isConnected = true;
8184
});
8285
});
8386
} else {
@@ -89,9 +92,20 @@
8992

9093
if (data.isValid === false || data.isExpired === true) {
9194
notificationsService.error("HubSpot API", "Invalid API key");
92-
}
95+
} else
96+
vm.isConnected = true;
9397
});
9498

9599
}
96100
}
101+
102+
$scope.connected = function () {
103+
vm.isConnected = true;
104+
loadForms();
105+
};
106+
107+
$scope.revoked = function () {
108+
vm.isConnected = false;
109+
vm.hubspotFormsList = [];
110+
};
97111
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
angular.module("umbraco.directives")
2+
.directive("hubspotAuthorization", function () {
3+
return {
4+
restrict: "E",
5+
scope: {
6+
"connected": "&onConnected",
7+
"revoked": "&onRevoked"
8+
},
9+
templateUrl: "/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/views/settings.html"
10+
}
11+
});

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/settings.controller.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
}
3030

3131
if (response.isValid !== true) {
32-
notificationsService.warning("HubSpot Configuration",
33-
"Invalid setup. Please review the API/OAuth settings.");
32+
// if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window.
33+
// if directive runs from data type, the notifications are displayed
34+
if (typeof $scope.connected === "undefined")
35+
notificationsService.warning("HubSpot Configuration",
36+
"Invalid setup. Please review the API/OAuth settings.");
3437
}
3538
});
3639

@@ -46,7 +49,12 @@
4649
vm.onRevokeToken = function() {
4750
umbracoCmsIntegrationsCrmHubspotResource.revokeAccessToken().then(function (response) {
4851
vm.oauthSetup.isConnected = false;
49-
notificationsService.success("HubSpot Configuration", "OAuth connection revoked.");
52+
53+
if(typeof $scope.connected === "undefined")
54+
notificationsService.success("HubSpot Configuration", "OAuth connection revoked.");
55+
56+
if (typeof $scope.revoked === "function")
57+
$scope.revoked();
5058
});
5159
}
5260

@@ -56,11 +64,17 @@
5664

5765
umbracoCmsIntegrationsCrmHubspotResource.getAccessToken(event.data.code).then(function (response) {
5866
if (response.startsWith("Error:")) {
59-
notificationsService.error("HubSpot Configuration", response);
67+
if (typeof $scope.connected === "undefined")
68+
notificationsService.error("HubSpot Configuration", response);
6069
} else {
6170
vm.oauthSetup.isConnected = true;
6271
vm.status.description = umbracoCmsIntegrationsCrmHubspotService.configDescription.OAuthConnected;
63-
notificationsService.success("HubSpot Configuration", "OAuth connected.");
72+
73+
if (typeof $scope.connected === "undefined")
74+
notificationsService.success("HubSpot Configuration", "OAuth connected.");
75+
76+
if (typeof $scope.connected === "function")
77+
$scope.connected();
6478
}
6579
});
6680

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/package.manifest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/formpicker.controller.js",
44
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/settings.controller.js",
55
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/hubspot.resource.js",
6-
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/hubspot.service.js"
6+
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/hubspot.service.js",
7+
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/hubspotauthorization.directive.js"
78
],
89
"css": [
910
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/css/styles.css"

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/views/formpickereditor.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<umb-box>
55
<umb-box-header title="{{ model.title }}" description="{{ model.subtitle }}"></umb-box-header>
66
<umb-box-content>
7-
<div class="hsOverlayGroup">
7+
<div class="hsOverlayGroup" ng-if="vm.isConnected">
88
<div class="form-search">
99
<i class="icon-search"></i>
1010
<input type="text" class="-full-width-input" ng-model="vm.searchTerm" placeholder="Type to search..." umb-auto-focus="" aria-invalid="false">
1111
</div>
1212
</div>
13-
<div class="hsOverlayGroup">
13+
<div class="hsOverlayGroup" ng-if="vm.isConnected">
1414
<ul class="hsFormsList">
1515
<li ng-repeat="form in vm.hubspotFormsList | orderBy:'name' | filter:vm.searchTerm" ng-click="model.pickForm(form)" class="ng-scope" role="button" tabindex="0">
1616
<a href="" ng-attr-title="form.name">
@@ -23,6 +23,14 @@
2323
</div>
2424
</umb-box-content>
2525
</umb-box>
26+
<umb-box>
27+
<umb-box-header title="HubSpot API" description="Please connect to HubSpot."></umb-box-header>
28+
<umb-box-content>
29+
<div class="hsOverlayGroup">
30+
<hubspot-authorization on-connected="connected()" on-revoked="revoked()"></hubspot-authorization>
31+
</div>
32+
</umb-box-content>
33+
</umb-box>
2634
</umb-editor-container>
2735

2836
<umb-editor-footer>

src/Umbraco.Cms.Integrations.Crm.Hubspot/Umbraco.Cms.Integrations.Crm.Hubspot.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageIconUrl></PackageIconUrl>
1111
<PackageProjectUrl>https://github.com/umbraco/Umbraco.Cms.Integrations</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/umbraco/Umbraco.Cms.Integrations</RepositoryUrl>
13-
<Version>1.0.2</Version>
13+
<Version>1.1.2</Version>
1414
<Authors>Umbraco HQ</Authors>
1515
<Company>Umbraco</Company>
1616
</PropertyGroup>
@@ -43,6 +43,10 @@
4343
</Content>
4444
</ItemGroup>
4545

46+
<ItemGroup>
47+
<None Remove="App_Plugins\UmbracoCms.Integrations\Crm\Hubspot\js\hubspotauthorization.directive.js" />
48+
</ItemGroup>
49+
4650
<Target Name="RemoveLuceneAnalyzer" BeforeTargets="CoreCompile">
4751
<ItemGroup>
4852
<Analyzer Remove="@(Analyzer)" Condition="%(FileName) == 'Lucene.Net.CodeAnalysis.CSharp'" />

src/Umbraco.Cms.Integrations.Crm.Hubspot/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<info>
44
<package>
55
<name>Umbraco.Cms.Integrations.Crm.Hubspot</name>
6-
<version>1.0.2</version>
6+
<version>1.1.2</version>
77
<iconUrl></iconUrl>
88
<licence url="https://opensource.org/licenses/MIT">MIT</licence>
99
<url>https://github.com/umbraco/Umbraco.Cms.Integrations</url>

0 commit comments

Comments
 (0)