Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Kiryakov <[email protected]>
  • Loading branch information
Stepan-Kirjakov committed Jan 30, 2025
1 parent 44b18cc commit 151239b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export class ImportEntityDialog {
this.setResult({
type: 'file',
data: arrayBuffer,
label: result
formula: result
});
}, (e) => {
this.loading = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,15 @@
placeholder="Not selected"
panelStyleClass="guardian-dropdown-panel">
<ng-template pTemplate="selectedItem">
<div *ngIf="currentPolicy && currentPolicy.instanceTopicId" class="guardian-dropdown-selected">
<div *ngIf="currentPolicy" class="guardian-dropdown-selected">
<span class="guardian-dropdown-label">Policy</span>
<span class="guardian-dropdown-item">{{ currentPolicy.name }}</span>
</div>
</ng-template>
<ng-template let-policy pTemplate="item">
<div *ngIf="policy.instanceTopicId" class="guardian-dropdown-item">
<div class="guardian-dropdown-item">
<span>{{policy.name}}</span>
<span class="dropdown-policy-version">({{policy.version}})</span>
</div>
<div *ngIf="!policy.instanceTopicId" class="guardian-dropdown-item">
<span></span>
<span *ngIf="policy.version" class="dropdown-policy-version">({{policy.version}})</span>
</div>
</ng-template>
</p-dropdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export class NewFormulaDialog {
this.title = this.config.data?.title || '';
this.action = this.config.data?.action || '';
this.policies = this.config.data?.policies || [];
this.policies = this.policies.filter((p) => p.instanceTopicId);
this.policies = this.policies.filter((p) => p.topicId);

const formula = this.config.data?.formula;
const instanceTopicId = this.config.data?.policy?.instanceTopicId;
this.policy = this.policies.find((p) => p.instanceTopicId === instanceTopicId) || null;
const id = this.config.data?.policy?.id;
this.policy = this.policies.find((p) => p.id === id) || null;
if (formula) {
this.readonly = true;
this.dataForm.setValue({
Expand Down Expand Up @@ -71,7 +72,8 @@ export class NewFormulaDialog {
name,
description,
policyId: policy?.id,
instanceTopicId: policy?.instanceTopicId,
policyTopicId: policy?.topicId,
policyInstanceTopicId: policy?.instanceTopicId,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
placeholder="Select Policy"
panelStyleClass="guardian-dropdown-panel">
<ng-template pTemplate="selectedItem">
<div *ngIf="currentPolicy && currentPolicy.instanceTopicId" class="guardian-dropdown-selected">
<div *ngIf="currentPolicy" class="guardian-dropdown-selected">
<span class="guardian-dropdown-label">Policy</span>
<span class="guardian-dropdown-item">{{ currentPolicy.name }}</span>
</div>
<div *ngIf="!currentPolicy || !currentPolicy.instanceTopicId" class="guardian-dropdown-selected">
<div *ngIf="!currentPolicy" class="guardian-dropdown-selected">
<span class="guardian-dropdown-label">Policy</span>
<span class="guardian-dropdown-item">All</span>
</div>
</ng-template>
<ng-template let-policy pTemplate="item">
<div *ngIf="policy.instanceTopicId" class="guardian-dropdown-item">
<div *ngIf="policy" class="guardian-dropdown-item">
<span>{{policy.name}}</span>
<span class="dropdown-policy-version">({{policy.version}})</span>
</div>
<div *ngIf="!policy.instanceTopicId" class="guardian-dropdown-item">
<div *ngIf="!policy" class="guardian-dropdown-item">
<span>All</span>
</div>
</ng-template>
Expand Down
23 changes: 13 additions & 10 deletions frontend/src/app/modules/formulas/formulas/formulas.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,20 @@ export class FormulasComponent implements OnInit {
this.user = new UserPermissions(profile);
this.owner = this.user.did;
this.allPolicies = policies || [];
// this.allPolicies = this.allPolicies.filter((p) => p.status === PolicyType.PUBLISH);
this.allPolicies.unshift({
name: 'All',
instanceTopicId: null
id: null
});
this.allPolicies.forEach((p: any) => p.label = p.name);

const topic = this.route.snapshot.queryParams['topic'];
this.currentPolicy =
this.allPolicies.find((p) => p.instanceTopicId === topic) ||
this.allPolicies[0];
const policy = this.route.snapshot.queryParams['policy'];
if(policy) {
this.currentPolicy = this.allPolicies.find((p) => p.id === policy);
}

if(!this.currentPolicy) {
this.currentPolicy = this.allPolicies[0];
}

if (this.isConfirmed) {
this.loadData();
Expand All @@ -170,8 +173,8 @@ export class FormulasComponent implements OnInit {

private loadData() {
const filters: any = {};
if (this.currentPolicy?.instanceTopicId) {
filters.policyInstanceTopicId = this.currentPolicy?.instanceTopicId;
if (this.currentPolicy?.id) {
filters.policyId = this.currentPolicy?.id;
}
this.loading = true;
this.formulasService
Expand Down Expand Up @@ -217,8 +220,8 @@ export class FormulasComponent implements OnInit {
this.currentPolicy = this.allPolicies[0];
}
this.pageIndex = 0;
const topic = this.currentPolicy?.instanceTopicId || 'all'
this.router.navigate(['/formulas'], { queryParams: { topic } });
const policy = this.currentPolicy?.id || 'all'
this.router.navigate(['/formulas'], { queryParams: { policy } });
this.loadData();
}

Expand Down
6 changes: 3 additions & 3 deletions guardian-service/src/api/formulas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function formulasAPI(logger: PinoLogger): Promise<void> {
return new MessageError('Invalid parameters.');
}
const { filters, owner } = msg;
const { policyInstanceTopicId, pageIndex, pageSize } = filters;
const { policyId, pageIndex, pageSize } = filters;

const otherOptions: any = {};
const _pageSize = parseInt(pageSize, 10);
Expand Down Expand Up @@ -104,8 +104,8 @@ export async function formulasAPI(logger: PinoLogger): Promise<void> {
const query: any = {
owner: owner.owner
};
if (policyInstanceTopicId) {
query.policyInstanceTopicId = policyInstanceTopicId;
if (policyId) {
query.policyId = policyId;
}
const [items, count] = await DatabaseServer.getFormulasAndCount(query, otherOptions);
return new MessageResponse({ items, count });
Expand Down
2 changes: 1 addition & 1 deletion guardian-service/src/policy-engine/policy-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ export class PolicyEngine extends NatsService {

const name = newFormula.name;
num++;
notifier.info(`Schema ${num} (${name || '-'}) published`);
notifier.info(`Formula ${num} (${name || '-'}) published`);
}

if (skipped) {
Expand Down

0 comments on commit 151239b

Please sign in to comment.