Skip to content

Commit 2700fe6

Browse files
committed
2 parents 9249037 + 147af35 commit 2700fe6

File tree

8 files changed

+72
-12
lines changed

8 files changed

+72
-12
lines changed

src/Umbraco.Cms.Integrations.Crm.ActiveCampaign.Core/ActiveCampaignComposer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using Microsoft.Extensions.DependencyInjection;
22

3-
using System;
4-
53
using Umbraco.Cms.Core.Composing;
64
using Umbraco.Cms.Core.DependencyInjection;
75
using Umbraco.Cms.Integrations.Crm.ActiveCampaign.Core.Configuration;
@@ -19,7 +17,7 @@ public void Compose(IUmbracoBuilder builder)
1917
.AddHttpClient(Constants.FormsHttpClient, client =>
2018
{
2119
client.BaseAddress = new Uri(
22-
$"{builder.Config.GetSection(Constants.SettingsPath)[nameof(ActiveCampaignSettings.BaseUrl)]}/api/3/forms");
20+
$"{builder.Config.GetSection(Constants.SettingsPath)[nameof(ActiveCampaignSettings.BaseUrl)]}");
2321
client.DefaultRequestHeaders
2422
.Add("Api-Token", builder.Config.GetSection(Constants.SettingsPath)[nameof(ActiveCampaignSettings.ApiKey)]);
2523
});

src/Umbraco.Cms.Integrations.Crm.ActiveCampaign.Core/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class Constants
99

1010
public const string FormsHttpClient = "FormsClient";
1111

12+
public const int DefaultPageSize = 10;
13+
1214
public class Resources
1315
{
1416
public const string AuthorizationFailed = "ActiveCampaign authorization failed.";

src/Umbraco.Cms.Integrations.Crm.ActiveCampaign.Core/Controllers/FormsController.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class FormsController : UmbracoAuthorizedApiController
2121

2222
private readonly IHttpClientFactory _httpClientFactory;
2323

24+
private const string ApiPath = "/api/3/forms";
25+
2426
public FormsController(IOptions<ActiveCampaignSettings> options, IHttpClientFactory httpClientFactory)
2527
{
2628
_settings = options.Value;
@@ -32,11 +34,20 @@ public FormsController(IOptions<ActiveCampaignSettings> options, IHttpClientFact
3234
public IActionResult CheckApiAccess() => new JsonResult(new ApiAccessDto(_settings.BaseUrl, _settings.ApiKey));
3335

3436
[HttpGet]
35-
public async Task<IActionResult> GetForms()
37+
public async Task<IActionResult> GetForms(int page = 1)
3638
{
3739
var client = _httpClientFactory.CreateClient(Constants.FormsHttpClient);
3840

39-
var response = await client.SendAsync(new HttpRequestMessage { Method = HttpMethod.Get });
41+
var requestUriString = page == 1
42+
? $"{client.BaseAddress}{ApiPath}&limit={Constants.DefaultPageSize}"
43+
: $"{client.BaseAddress}{ApiPath}&limit={Constants.DefaultPageSize}&offset={(page - 1) * Constants.DefaultPageSize}";
44+
45+
var requestMessage = new HttpRequestMessage {
46+
RequestUri = new Uri(requestUriString),
47+
Method = HttpMethod.Get
48+
};
49+
50+
var response = await client.SendAsync(requestMessage);
4051

4152
var content = await response.Content.ReadAsStringAsync();
4253

@@ -61,7 +72,7 @@ public async Task<IActionResult> GetForm(string id)
6172
new HttpRequestMessage
6273
{
6374
Method = HttpMethod.Get,
64-
RequestUri = new Uri(client.BaseAddress + "/" + id)
75+
RequestUri = new Uri($"{client.BaseAddress}{ApiPath}/{id}")
6576
});
6677

6778
var content = await response.Content.ReadAsStringAsync();
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using System.Collections.Generic;
2-
using System.Text.Json.Serialization;
1+
using System.Text.Json.Serialization;
32

43
namespace Umbraco.Cms.Integrations.Crm.ActiveCampaign.Core.Models.Dtos
54
{
65
public class FormCollectionResponseDto : BaseResponseDto
76
{
87
[JsonPropertyName("forms")]
98
public List<FormDto> Form { get; set; }
9+
10+
[JsonPropertyName("meta")]
11+
public MetaDto Meta { get; set; }
1012
}
1113
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Umbraco.Cms.Integrations.Crm.ActiveCampaign.Core.Models.Dtos
4+
{
5+
public class MetaDto
6+
{
7+
[JsonPropertyName("total")]
8+
public string Total { get; set; }
9+
10+
[JsonPropertyName("totalPages")]
11+
public int TotalPages => int.TryParse(Total, out var total) ? total / Constants.DefaultPageSize : 0;
12+
}
13+
}

src/Umbraco.Cms.Integrations.Crm.ActiveCampaign/App_Plugins/UmbracoCms.Integrations/Crm/ActiveCampaign/js/activecampaign.resource.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
$http.get(`${apiEndpoint}/CheckApiAccess`),
1010
"Failed");
1111
},
12-
getForms: function () {
12+
getForms: function (page) {
1313
return umbRequestHelper.resourcePromise(
14-
$http.get(`${apiEndpoint}/GetForms`),
14+
$http.get(`${apiEndpoint}/GetForms?page=${page}`),
1515
"Failed");
1616
},
1717
getForm: function (id) {

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
vm.status = "";
1111

12+
// pagination
13+
vm.pagination = {
14+
pageNumber: 1,
15+
totalPages: 1
16+
};
17+
vm.nextPage = goToPage;
18+
vm.prevPage = goToPage;
19+
vm.changePage = goToPage;
20+
vm.goToPage = goToPage;
21+
1222
umbracoCmsIntegrationsCrmActiveCampaignResource.checkApiAccess().then(function (response) {
1323
vm.isApiConfigurationValid = response.isApiConfigurationValid;
1424
if (response.isApiConfigurationValid) {
@@ -69,12 +79,16 @@
6979
});
7080
}
7181

72-
function loadForms() {
82+
function loadForms(page) {
7383
vm.loading = true;
74-
umbracoCmsIntegrationsCrmActiveCampaignResource.getForms().then(function (response) {
84+
umbracoCmsIntegrationsCrmActiveCampaignResource.getForms(page).then(function (response) {
85+
7586
vm.formsList = [];
7687

7788
if (response.forms != null) {
89+
90+
vm.pagination.totalPages = response.meta.totalPages;
91+
7892
response.forms.forEach(item => {
7993
vm.formsList.push({
8094
id: item.id,
@@ -87,6 +101,11 @@
87101
vm.loading = false;
88102
});
89103
}
104+
105+
// pagination events
106+
function goToPage(page) {
107+
loadForms(page);
108+
}
90109
}
91110

92111
angular.module("umbraco")

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424
</a>
2525
</li>
2626
</ul>
27+
<!-- If list is empty, then display -->
28+
<umb-empty-state ng-if="!vm.formsList"
29+
position="center">
30+
<localize key="content_listViewNoItems">There are no forms in the list.</localize>
31+
</umb-empty-state>
32+
<!-- Pagination -->
33+
<div class="flex justify-center" ng-show="!vm.loading">
34+
<umb-pagination page-number="vm.pagination.pageNumber"
35+
total-pages="vm.pagination.totalPages"
36+
on-next="vm.nextPage"
37+
on-prev="vm.prevPage"
38+
on-change="vm.changePage"
39+
on-go-to-page="vm.goToPage">
40+
</umb-pagination>
41+
</div>
2742
</div>
2843

2944
<div ng-if="vm.status" class="alert alert-warning">

0 commit comments

Comments
 (0)