Skip to content

Commit ae87838

Browse files
committed
working on erabliereapi connector
1 parent af23afc commit ae87838

16 files changed

+520
-157
lines changed

CreateSelfSignedCert.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Write-Host "Generate a new self-signed certificate"
22
$cert = New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My -DnsName "localhost" -KeySpec KeyExchange
33

4+
if (!(Test-Path "C:\certs")) {
5+
New-Item -Path "C:\" -Name "certs" -ItemType "directory"
6+
}
7+
48
# Export the certificate as a PFX file
59
$certPath = "C:\certs\bc-erabliereapi-connector-certificate.pfx"
610
$certPassword = ConvertTo-SecureString -String "1234" -Force -AsPlainText

erabliereapi/EAPISetupPage.al

Lines changed: 0 additions & 73 deletions
This file was deleted.

erabliereapi/ErabliereList.al

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
page 50102 "Erabliere List"
22
{
3-
// Specify that this page will be a list page.
43
PageType = List;
5-
6-
// The page will be part of the "Lists" group of search results.
74
UsageCategory = Lists;
8-
9-
// The data of this page is taken from the "Reward" table.
105
SourceTable = Erablieres;
11-
12-
// The "CardPageId" is set to the Reward Card previously created.
13-
// This will allow users to open records from the list in the "Reward Card" page.
146
CardPageId = "Erabliere Card";
157

168
layout
@@ -47,46 +39,41 @@ page 50102 "Erabliere List"
4739
var
4840
ErablieresArray: JsonArray;
4941
ErabliereToken: JsonToken;
50-
ErabliereObj: JsonObject;
5142
ErabliereAPI: CodeUnit "ErabliereAPI";
5243
ErabliereRec: Record "Erablieres";
53-
propVal: JsonToken;
44+
propVal: Text;
5445
i: Integer;
5546
count: Integer;
56-
Dialog: Codeunit "DynDialog";
5747
begin
58-
ErablieresArray := ErabliereAPI.GetErabliere();
48+
ErablieresArray := ErabliereAPI.GetAdminErabliere();
5949
count := ErablieresArray.Count;
6050
Dialog.Open(count);
6151
for i := 0 to ErablieresArray.Count - 1 do begin
6252

6353
ErablieresArray.Get(i, ErabliereToken);
6454

65-
ErabliereObj := ErabliereToken.AsObject();
66-
67-
ErabliereObj.Get('id', propVal);
55+
propVal := Json.GetText(ErabliereToken, 'id');
6856

6957
// Si l'érable n'existe pas, on le crée
70-
if not ErabliereRec.Get(propVal.AsValue().AsText()) then begin
58+
if not ErabliereRec.Get(propVal) then begin
7159
ErabliereRec.Init();
7260

73-
ErabliereRec.Validate("Erabliere ID", propVal.AsValue().AsText());
61+
ErabliereRec.Validate("Erabliere ID", propVal);
7462

75-
ErabliereObj.Get('nom', propVal);
63+
propVal := Json.GetText(ErabliereToken, 'nom');
7664

77-
ErabliereRec.Validate("Description", propVal.AsValue().AsText());
65+
ErabliereRec.Validate("Description", propVal);
7866

7967
ErabliereRec.Insert();
8068

81-
Dialog.Update(i + 1, propVal.AsValue().AsText() + ' inséré');
69+
Dialog.Update(i + 1, propVal + ' inséré');
8270
end
8371
else begin
84-
ErabliereObj.Get('nom', propVal);
72+
propVal := Json.GetText(ErabliereToken, 'nom');
8573

86-
Dialog.Update(i + 1, propVal.AsValue().AsText() + ' existe déjà');
74+
Dialog.Update(i + 1, propVal + ' existe déjà');
8775
end;
8876
end;
89-
Dialog.Close();
9077
Dialog.PrettyMessage('Importation terminée');
9178
end;
9279
}
@@ -101,28 +88,29 @@ page 50102 "Erabliere List"
10188
var
10289
ErablieresArray: JsonArray;
10390
ErabliereToken: JsonToken;
104-
ErabliereObj: JsonObject;
10591
ErabliereAPI: CodeUnit "ErabliereAPI";
10692
ErabliereRec: Record "Erablieres";
107-
propVal: JsonToken;
93+
propVal: Text;
10894
i: Integer;
10995
count: Integer;
110-
DynDialog: Codeunit "DynDialog";
11196
begin
112-
ErablieresArray := ErabliereAPI.GetErabliere();
97+
ErablieresArray := ErabliereAPI.GetAdminErabliere();
11398
count := ErablieresArray.Count;
114-
DynDialog.Open(count);
99+
Dialog.Open(count);
115100
for i := 0 to count - 1 do begin
116-
Sleep(250);
101+
Sleep(125);
117102
ErablieresArray.Get(i, ErabliereToken);
118-
ErabliereToken.AsObject().Get('nom', propVal);
119-
DynDialog.Update(i + 1, propVal.AsValue().AsText());
103+
propVal := Json.GetText(ErabliereToken, 'nom');
104+
Dialog.Update(i + 1, propVal);
120105
end;
121-
Sleep(1250);
122-
DynDialog.Close();
123-
DynDialog.PrettyMessage('Prévisualisation terminée');
106+
Sleep(625);
107+
Dialog.PrettyMessage('Prévisualisation terminée');
124108
end;
125109
}
126110
}
127111
}
112+
113+
var
114+
Dialog: Codeunit "DynDialog";
115+
Json: Codeunit "Json";
128116
}

erabliereapi/ErablierePage.al

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
page 50101 "Erabliere Card"
22
{
3-
// The page will be of type "Card" and will render as a card.
43
PageType = Card;
5-
6-
// The page will be part of the "Tasks" group of search results.
74
UsageCategory = Tasks;
8-
9-
// The source table shows data from the "Reward" table.
105
SourceTable = Erablieres;
116

12-
// The layout describes the visual parts on the page.
137
layout
148
{
159
area(content)
@@ -18,10 +12,6 @@ page 50101 "Erabliere Card"
1812
{
1913
field("Erabliere Id"; Rec."Erabliere ID")
2014
{
21-
// ApplicationArea sets the application area that
22-
// applies to the page field and action controls.
23-
// Setting the property to All means that the control
24-
// will always appear in the user interface.
2515
ApplicationArea = All;
2616
}
2717

@@ -33,11 +23,13 @@ page 50101 "Erabliere Card"
3323
field("Duration"; Rec.Duration)
3424
{
3525
ApplicationArea = All;
26+
Editable = false;
3627
}
3728

3829
field("Duration Text"; Rec.DurationText)
3930
{
4031
ApplicationArea = All;
32+
ToolTip = 'A duration writen as text. Ex: PT1H30M';
4133
}
4234
}
4335
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
pageextension 50120 ContactPageExt extends "Contact List"
2+
{
3+
layout
4+
{
5+
// Add changes to page layout here
6+
}
7+
8+
actions
9+
{
10+
// Import contact from ErabliereAPI
11+
addafter("Export Contact")
12+
{
13+
action("Import from ErabliereAPI")
14+
{
15+
Promoted = true;
16+
PromotedCategory = Process;
17+
ApplicationArea = All;
18+
Caption = 'Import Contacts';
19+
ToolTip = 'Import contacts from ErabliereAPI';
20+
Image = Import;
21+
22+
trigger OnAction()
23+
var
24+
result: Boolean;
25+
begin
26+
result := ImportContactsFromErabliereAPI(True);
27+
28+
if result then begin
29+
result := ImportContactsFromErabliereAPI(False);
30+
end;
31+
end;
32+
}
33+
}
34+
}
35+
36+
procedure ImportContactsFromErabliereAPI(Preview: Boolean): Boolean
37+
var
38+
ErabliereAPI: CodeUnit "ErabliereAPI";
39+
ContactRec: Record "Contact";
40+
ContactsArray: JsonArray;
41+
ContactToken: JsonToken;
42+
uniqueName: Text;
43+
i: Integer;
44+
count: Integer;
45+
begin
46+
ContactsArray := ErabliereAPI.GetAdminContact();
47+
count := ContactsArray.Count;
48+
Dialog.Open(count);
49+
for i := 0 to count - 1 do begin
50+
ContactsArray.Get(i, ContactToken);
51+
uniqueName := Json.GetText(ContactToken, 'uniqueName');
52+
53+
if uniqueName.Contains('@') then begin
54+
ContactRec.SetFilter("ErabliereAPI Unique Name", uniqueName);
55+
56+
if ContactRec.FindFirst() then begin
57+
SynErabliereAPIContact(ContactRec, ContactToken);
58+
if not Preview then
59+
ContactRec.Modify(true);
60+
Dialog.Update(i + 1, StrSubstNo('Contact %1 was updated', uniqueName));
61+
end
62+
else begin
63+
ContactRec.Init();
64+
ContactRec.Type := ContactRec.Type::Person;
65+
SynErabliereAPIContact(ContactRec, ContactToken);
66+
ContactRec.CheckDuplicates();
67+
if not Preview then
68+
ContactRec.Insert(true);
69+
Dialog.Update(i + 1, StrSubstNo('Contact %1 was created', uniqueName));
70+
end;
71+
end
72+
else begin
73+
Dialog.Update(i + 1, StrSubstNo('Device %1 was not imported as a contact', uniqueName));
74+
end;
75+
end;
76+
if Preview then
77+
Dialog.PrettyConfirm('Do you confirm the import data?')
78+
else
79+
Dialog.PrettyMessage('Importation terminée');
80+
end;
81+
82+
procedure SynErabliereAPIContact(var ContactRec: Record "Contact"; var ContactToken: JsonToken)
83+
begin
84+
ContactRec.Validate(Name, Json.GetText(ContactToken, 'name'));
85+
ContactRec.Validate("ErabliereAPI Unique Name", Json.GetText(ContactToken, 'uniqueName'));
86+
ContactRec.Validate("E-Mail", Json.GetText(ContactToken, 'email'));
87+
ContactRec.Validate("E-Mail 2", Json.GetText(ContactToken, 'secondaryEmail'));
88+
ContactRec.Validate("ErabliereAPI Account Type", Json.GetText(ContactToken, 'accountType'));
89+
ContactRec.Validate("ErabliereAPI Stripe ID", Json.GetText(ContactToken, 'stripeId'));
90+
ContactRec.Validate("ErabliereAPI Ext. Account Url", Json.GetText(ContactToken, 'externalAccountUrl'));
91+
ContactRec.Validate("ErabliereAPI Creation Time", Json.GetDate(ContactToken, 'creationTime'));
92+
ContactRec.Validate("ErabliereAPI Last Update Time", Json.GetDate(ContactToken, 'lastAccessTime'));
93+
end;
94+
95+
var
96+
Dialog: Codeunit "DynDialog";
97+
Json: Codeunit "Json";
98+
}
File renamed without changes.

0 commit comments

Comments
 (0)