Skip to content

Commit

Permalink
chore: minor code refactoring with renaming functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AnurosePrakash committed Jul 3, 2023
1 parent dbb1441 commit cd4bcf5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"
mat-raised-button
color="primary"
[disabled]="data.contractAgreement?.statusText == 'Inactive'"
[disabled]="!data.contractAgreement?.canTransfer"
(click)="onTransferClick()">
Transfer
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ import {Policy} from '../../../core/services/api/legacy-managent-api-client';
import {AssetProperties} from '../../../core/services/asset-properties';
import {Asset} from '../../../core/services/models/asset';
import {BrokerDataOffer} from '../../../routes/broker-ui/catalog-page/catalog-page/mapping/broker-data-offer';
import {ContractAgreementCardMapped} from '../../../routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped';
import {
ContractAgreementCardMapped
} from '../../../routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped';
import {JsonDialogComponent} from '../../json-dialog/json-dialog/json-dialog.component';
import {JsonDialogData} from '../../json-dialog/json-dialog/json-dialog.data';
import {PropertyGridGroup} from '../../property-grid/property-grid-group/property-grid-group';
import {PropertyGridField} from '../../property-grid/property-grid/property-grid-field';
import {PropertyGridFieldService} from '../../property-grid/property-grid/property-grid-field.service';
import {formatDateAgo} from '../../ui-elements/ago/formatDateAgo';


@Injectable()
export class AssetPropertyGridGroupBuilder {
constructor(
private matDialog: MatDialog,
private activeFeatureSet: ActiveFeatureSet,
private propertyGridUtils: PropertyGridFieldService,
) {}
) {
}

buildAssetPropertiesGroup(
asset: Asset,
Expand Down Expand Up @@ -236,8 +240,7 @@ export class AssetPropertyGridGroupBuilder {
}

buildContractAgreementGroup(contractAgreement: ContractAgreementCardMapped) {
let properties: PropertyGridField[] = [];
properties = [
let properties: PropertyGridField[] = [
{
icon: 'category',
label: 'Signed',
Expand Down Expand Up @@ -288,6 +291,7 @@ export class AssetPropertyGridGroupBuilder {
),
},
];

if (contractAgreement.isConsumingLimitsEnforced) {
properties.push({
icon: 'info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
<!-- Property Icon -->
<mat-icon
style="flex-shrink: 0; margin-top: 6px"
matTooltip="{{ prop.tooltip }}"
[matTooltip]="prop.tooltip!"
[attr.title]="prop.labelTitle"
>{{ prop.icon }}</mat-icon
>
<div class="flex flex-col">
<!-- Property Label -->
<div
class="uppercase text-slate text-sm break-all"
matTooltip="{{ prop.tooltip }}"
[matTooltip]="prop.tooltip!"
[attr.title]="prop.labelTitle">
{{ prop.label }}
</div>
Expand Down Expand Up @@ -46,11 +46,11 @@
<!-- Property Value (Text) with tooltip -->
<span
*ngIf="!(prop.url || prop.onclick)"
matTooltip="{{ prop.tooltip }}"
[matTooltip]="prop.tooltip!"
[ngClass]="prop.additionalClasses"
>{{ prop.text }}
<mat-icon *ngIf="prop.tooltip" class="mat-icon-[10px]"
>info
>{{prop.icon}}
</mat-icon></span
>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class ContractAgreementCardMappedService {
isConsumingLimitsEnforced: false,
statusText: '',
statusTooltipText: '',
canTransfer: true,
searchTargets: [
contractAgreement.contractAgreementId,
contractAgreement.counterPartyId,
Expand All @@ -47,7 +48,7 @@ export class ContractAgreementCardMappedService {
return search(cards, searchText, (card) => card.searchTargets);
}

setStatus(
withEnforcedLimits(
maxConsumingContracts: number,
agreements: ContractAgreementCardMapped[],
): ContractAgreementCardMapped[] {
Expand All @@ -59,6 +60,7 @@ export class ContractAgreementCardMappedService {
index,
maxConsumingContracts,
),
canTransfer: index < maxConsumingContracts,
}));
}

Expand All @@ -67,11 +69,9 @@ export class ContractAgreementCardMappedService {
maxConsumingContracts: number,
): string {
if (index >= maxConsumingContracts) {
if (maxConsumingContracts == 1) {
return `This connector is configured with a limit of ${maxConsumingContracts} active consuming contract agreement, causing contract agreement to get disabled if new ones are negotiated.`;
} else {
return `This connector is configured with a limit of ${maxConsumingContracts} active consuming contract agreements, causing contract agreements to get disabled if new ones are negotiated.`;
}
return `This connector is licensed for a maximum number of ${maxConsumingContracts} consuming contract${
maxConsumingContracts == 1 ? '' : 's'
}. When negotiating new contracts, older contracts will be deactivated.`;
} else {
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export type ContractAgreementCardMapped = Omit<
isConsumingLimitsEnforced: boolean;
statusText: string;
statusTooltipText: string;
canTransfer: boolean;
searchTargets: (string | null)[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {ContractAgreementCardMapped} from '../contract-agreement-cards/contract-
import {ContractAgreementCardMappedService} from '../contract-agreement-cards/contract-agreement-card-mapped.service';
import {ContractAgreementPageData} from './contract-agreement-page.data';


@Injectable({providedIn: 'root'})
export class ContractAgreementPageService {
constructor(
Expand Down Expand Up @@ -80,7 +81,7 @@ export class ContractAgreementPageService {
connectorLimits.maxActiveConsumingContractAgreements >= 0;
if (isConsumingLimitsEnforced) {
consumingContractAgreements =
this.contractAgreementCardMappedService.setStatus(
this.contractAgreementCardMappedService.withEnforcedLimits(
connectorLimits?.maxActiveConsumingContractAgreements!,
consumingContractAgreements,
);
Expand Down

0 comments on commit cd4bcf5

Please sign in to comment.