Skip to content

Commit

Permalink
chore: Updated the contract agreement cards to view the activation st…
Browse files Browse the repository at this point in the history
…atus
  • Loading branch information
AnurosePrakash committed Jun 28, 2023
1 parent 696d9e6 commit 9f43728
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 60 deletions.
2 changes: 1 addition & 1 deletion fake-backend/json/connectorLimits.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"numActiveConsumingContractAgreements": 2,
"maxActiveConsumingContractAgreements": 10
"maxActiveConsumingContractAgreements": null
}
6 changes: 3 additions & 3 deletions fake-backend/json/contractAgreementPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"contractAgreementId": "my-own-asset-cd:f52a5d30-6356-4a55-a75a-3c45d7a88c3e",
"direction": "PROVIDING",
"counterPartyAddress": "http://edc2:11003/api/v1/ids/data",
"counterPartyAddress": "http://edc2:11003/api/v1/ids/data/blaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"counterPartyId": "urn:connector:example-connector",
"contractSigningDate": "2022-03-20T11:18:59.659Z",
"contractStartDate": "2022-03-20T11:18:59.659Z",
Expand Down Expand Up @@ -110,7 +110,7 @@
{
"contractAgreementId": "my-test-asset-cd:6ebbc301-9b1e-4cd7-9f17-97b5b7867531",
"direction": "CONSUMING",
"counterPartyAddress": "http://edc2:11003/api/v1/ids/data",
"counterPartyAddress": "http://edc2:11003/api/v1/ids/data/blaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"counterPartyId": "my-connector",
"contractSigningDate": "2022-03-25T11:18:59.659Z",
"contractStartDate": "2022-03-25T11:18:59.659Z",
Expand Down Expand Up @@ -181,7 +181,7 @@
{
"contractAgreementId": "my-test-asset-2-cd:6ebbc301-9b1e-4cd7-9f17-08b5b7867533",
"direction": "CONSUMING",
"counterPartyAddress": "http://edc2:11003/api/v1/ids/data",
"counterPartyAddress": "http://edc2:11003/api/v1/ids/data/blaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"counterPartyId": "my-connector",
"contractSigningDate": "2022-03-25T11:18:59.659Z",
"contractStartDate": "2022-03-25T11:18:59.659Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
<button
*ngIf="
data.type === 'contract-agreement' &&
data.contractAgreement?.direction === 'CONSUMING'
data.contractAgreement?.direction === 'CONSUMING' &&
data.contractAgreement?.isActivated
"
mat-raised-button
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ export class ContractAgreementCardMappedService {
*/
buildContractAgreementCardMapped(
contractAgreement: ContractAgreementCard,
consumedConnectorLimit: string,

): ContractAgreementCardMapped {
let asset = this.assetPropertyMapper.buildAssetFromProperties(
contractAgreement.asset.properties,
);

return {
...contractAgreement,
asset,
isInProgress: contractAgreement.transferProcesses.some(
(it) => it.state.simplifiedState === 'RUNNING',
),
consumedConnectorLimits:
contractAgreement.direction == 'CONSUMING' ? consumedConnectorLimit : null,
isActivated: true,
connectorMaxLimit: null,
searchTargets: [
contractAgreement.contractAgreementId,
contractAgreement.counterPartyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type ContractAgreementCardMapped = Omit<
> & {
asset: Asset;
isInProgress: boolean;
consumedConnectorLimits: string | null;
isActivated: boolean;
connectorMaxLimit: number | null;
searchTargets: (string | null)[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,62 @@
</div>
<div class="flex flex-row space-x-[10px] justify-between">
<!-- Counterparty Address -->
<div class="flex flex-col flex-grow">
<div class="text-slate text-sm uppercase tracking-wider">
Other Connector
</div>
<div class="flex flex-col">
<div class="text-slate text-sm uppercase">Other Connector</div>
<div>
<a
class="link"
class="link break-all"
target="_blank"
[attr.href]="card.counterPartyAddress"
>{{ card.counterPartyAddress }}</a
>
</div>
</div>
<div *ngIf="card.direction === 'CONSUMING'" class="flex flex-col">
<!-- Consuming Status -->
<div
*ngIf="
card.direction === 'CONSUMING' &&
('connector-limit-for-consuming-contract-agreements'
| isActiveFeature)
"
class="flex flex-col">
<div class="text-slate text-sm uppercase tracking-wider">
Consumed Limit
Consuming Status
</div>
<div
*ngIf="card.isActivated && !card.connectorMaxLimit"
class="text-right"
data-toggle="tooltip"
title="Unlimited transferring of the consuming contract agreements are allowed.">
{{ 'Activated' }}
</div>
<div
*ngIf="card.isActivated && card.connectorMaxLimit! > 1"
class="text-right"
data-toggle="tooltip"
title="Be aware that only transferring of the {{card.connectorMaxLimit}} newest consuming contract agreements are allowed.">
{{ 'Activated' }}
</div>
<div
*ngIf="!card.isActivated && card.connectorMaxLimit! > 1"
class="text-right"
data-toggle="tooltip"
title="Be aware that only transferring of the {{card.connectorMaxLimit}} newest consuming contract agreements are allowed.">
{{ 'Deactivated' }}
</div>
<div
*ngIf="card.isActivated && card.connectorMaxLimit === 1"
class="text-right"
data-toggle="tooltip"
title="Be aware that only transferring of the {{card.connectorMaxLimit}} newest consuming contract agreement is allowed.">
{{ 'Activated' }}
</div>
<div *ngIf="card.consumedConnectorLimits | json" class="flex flex-row flex-wrap">
{{card.consumedConnectorLimits}}
<div
*ngIf="!card.isActivated && card.connectorMaxLimit === 1"
class="text-right"
data-toggle="tooltip"
title="Be aware that only transferring of the {{card.connectorMaxLimit}} newest consuming contract agreement is allowed.">
{{ 'Deactivated' }}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Injectable} from '@angular/core';
import {Observable, combineLatest, concat, interval} from 'rxjs';
import {Observable, combineLatest, concat, interval, of} from 'rxjs';
import {filter, map, switchMap} from 'rxjs/operators';
import {
ConnectorLimits,
Expand All @@ -15,8 +15,6 @@ import {ContractAgreementPageData} from './contract-agreement-page.data';

@Injectable({providedIn: 'root'})
export class ContractAgreementPageService {
consumedConnectorLimitsData!: string;

constructor(
private edcApiService: EdcApiService,
private contractAgreementCardMappedService: ContractAgreementCardMappedService,
Expand Down Expand Up @@ -48,67 +46,58 @@ export class ContractAgreementPageService {
}

private fetchData(): Observable<Fetched<ContractAgreementPageData>> {
return this.edcApiService.getContractAgreementPage().pipe(
Fetched.wrap({failureMessage: 'Failed fetching contract definitions'}),
Fetched.map((contractAgreementPage) =>
this.buildContractAgreementPageData(contractAgreementPage),
return combineLatest([
this.edcApiService.getContractAgreementPage(),
this.fetchLimits(),
]).pipe(
map(([contractAgreementPage, connectorLimits]) =>
this.buildContractAgreementPageData(
contractAgreementPage,
connectorLimits,
),
),
);
}

private fetchConnectorLimitsData(): Observable<ConnectorLimits> {
return this.edcApiService.getEnterpriseEditionConnectorLimits().pipe(
Fetched.wrap({failureMessage: 'Failed fetching connector limits'}),
Fetched.map((connectorLimits) => connectorLimits),
Fetched.wrap({failureMessage: 'Failed fetching Contract Agreement Page'}),
);
}

private buildContractAgreementPageData(
contractAgreementPage: ContractAgreementPage,
connectorLimits: ConnectorLimits | null,
): ContractAgreementPageData {
if (this.activeFeatureSet.hasEnterPriseEditionFields() || true) {
this.fetchConnectorLimitsData().subscribe((data) =>
data.match({
ifOk: (value) => {
this.consumedConnectorLimitsData = 'test';
console.log('data is.......' + this.consumedConnectorLimitsData);
//value.numActiveConsumingContractAgreements.toString() +
//'/' +
//value.maxActiveConsumingContractAgreements!.toString()
},
ifError: (data) => console.log(data),
ifLoading: () => {
this.consumedConnectorLimitsData = 'Loading...';
},
}),
);
}
console.log('before map' + this.consumedConnectorLimitsData);
let contractAgreements = this.mapContractAgreements(
contractAgreementPage.contractAgreements,
this.consumedConnectorLimitsData!!,
);

let consumingContractAgreements = contractAgreements.filter(
(it) => it.direction === 'CONSUMING',
);

if (connectorLimits?.maxActiveConsumingContractAgreements != null) {
consumingContractAgreements.map(
(it) =>
{it.isActivated =
consumingContractAgreements.indexOf(it) <
connectorLimits?.maxActiveConsumingContractAgreements!;
it.connectorMaxLimit = connectorLimits?.maxActiveConsumingContractAgreements!;}
);
}

return {
contractAgreements,
consumingContractAgreements: contractAgreements.filter(
(it) => it.direction === 'CONSUMING',
),
consumingContractAgreements: consumingContractAgreements,
providingContractAgreements: contractAgreements.filter(
(it) => it.direction === 'PROVIDING',
),
numTotalContractAgreements:
contractAgreementPage.contractAgreements.length,
numTotalContractAgreements: contractAgreements.length,
};
}

private mapContractAgreements(
contractAgreements: ContractAgreementCard[],
consumedConnectorLimit: string,
): ContractAgreementCardMapped[] {
return contractAgreements.map((contractAgreement) =>
this.contractAgreementCardMappedService.buildContractAgreementCardMapped(
contractAgreement,
consumedConnectorLimit,
),
);
}
Expand Down Expand Up @@ -138,4 +127,11 @@ export class ContractAgreementPageService {
filter((it) => it.isReady),
);
}

private fetchLimits(): Observable<ConnectorLimits | null> {
if (this.activeFeatureSet.hasEnterPriseEditionFields()) {
return this.edcApiService.getEnterpriseEditionConnectorLimits();
}
return of(null);
}
}

0 comments on commit 9f43728

Please sign in to comment.