Skip to content

Commit

Permalink
Merge pull request #5 from squzy/feat/dashboard-2
Browse files Browse the repository at this point in the history
feat(incidnet): add rule resolver
  • Loading branch information
PxyUp committed Jul 8, 2020
2 parents b14c92f + f7dc9fc commit 869e933
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
<mat-card>
<ng-container *ngIf="currentIncident$ | async as incident; else loading">
<mat-card-header>
<mat-card-title>{{ 'MODULES.INCIDENTS.PAGE.TITLE' | translate }} #{{ incident.id }}</mat-card-title>
<mat-card-title>{{ 'MODULES.INCIDENTS.PAGE.TITLE' | translate }} # {{ incident.id }}</mat-card-title>
</mat-card-header>
<mat-card-content>
<div class="info">
<p>
<strong>{{ 'MODULES.INCIDENTS.PAGE.STATUS' | translate }}</strong>
: {{ 'ENUMS.INCIDENTS.STATUS.' + (incident.status || 0) | translate}}
</p>
<p>
<strong>{{ 'MODULES.INCIDENTS.PAGE.RULE_ID' | translate }}</strong>
: {{ incident.rule_id
}}
<button
(click)="goToRulePage(incident.rule_id)"
mat-icon-button
matTooltipPosition="right"
matTooltip="View config"
>
<mat-icon>link</mat-icon>
</button>
</p>
<ng-container *ngIf="currentRule$ | async as rule">
<p>
<strong>{{ 'MODULES.INCIDENTS.PAGE.RULE_ID' | translate }}</strong>
: {{ rule.id
}}
<button
(click)="goToRulePage(rule.owner_type, rule.owner_id)"
mat-icon-button
matTooltipPosition="right"
matTooltip="View config"
>
<mat-icon>link</mat-icon>
</button>
</p>
<p>
<strong>{{ 'MODULES.INCIDENTS.PAGE.RULE_NAME' | translate }}</strong>
: {{ rule.name }}
</p>
<p>
<strong>{{ 'MODULES.INCIDENTS.PAGE.RULE' | translate }}</strong>:
</p>
<pre>{{ rule.rule }}</pre>
<p>
<strong>{{ 'MODULES.INCIDENTS.PAGE.RULE_STATUS' | translate }}</strong>
: {{ 'ENUMS.RULES.STATUS.' + rule.status | translate }}
</p>
</ng-container>
</div>
<div class="history">
<p *ngFor="let item of incident.histories">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ $padding: 40px;
}
}
}
pre {
word-break: break-word;
white-space: pre-wrap;
}
}
}
.spinner-container {
Expand Down
37 changes: 19 additions & 18 deletions src/app/modules/incidents/components/incident/incident.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, ChangeDetectionStrategy, OnDestroy } from '@angular/core';
import { map, takeUntil, switchMap, startWith } from 'rxjs/operators';
import { map, takeUntil, switchMap, startWith, share, refCount, shareReplay } from 'rxjs/operators';
import { ActivatedRoute, Router } from '@angular/router';
import { IncidentService } from '../../services/incident.service';
import { Subject, combineLatest } from 'rxjs';
Expand All @@ -25,6 +25,12 @@ export class IncidentComponent implements OnDestroy {

currentIncident$ = combineLatest(this.currentId$, this.refresh$.pipe(startWith(null))).pipe(
switchMap(([id, _]) => this.incidentService.getById(id)),
shareReplay(),
takeUntil(this.destoryed$),
);

currentRule$ = this.currentIncident$.pipe(
switchMap((incident) => this.rulesService.getById(incident.rule_id)),
takeUntil(this.destoryed$),
);

Expand Down Expand Up @@ -56,23 +62,18 @@ export class IncidentComponent implements OnDestroy {
});
}

goToRulePage(ruleId: string) {
this.rulesService
.getById(ruleId)
.pipe(takeUntil(this.destoryed$))
.subscribe((rule) => {
switch (rule.owner_type) {
case OwnerType.INCIDENT_OWNER_TYPE_AGENT:
this.router.navigate(['agents', rule.owner_id]);
break;
case OwnerType.INCIDENT_OWNER_TYPE_SCHEDULER:
this.router.navigate(['checkers', rule.owner_id]);
break;
case OwnerType.INCIDENT_OWNER_TYPE_APPLICATION:
this.router.navigate(['applications', rule.owner_id]);
break;
}
});
goToRulePage(ownerType: OwnerType, ownerId: string) {
switch (ownerType) {
case OwnerType.INCIDENT_OWNER_TYPE_AGENT:
this.router.navigate(['agents', ownerId]);
break;
case OwnerType.INCIDENT_OWNER_TYPE_SCHEDULER:
this.router.navigate(['checkers', ownerId]);
break;
case OwnerType.INCIDENT_OWNER_TYPE_APPLICATION:
this.router.navigate(['applications', ownerId]);
break;
}
}
toDate(time: Time) {
return timeToDate(time);
Expand Down
5 changes: 4 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@
"RULE_ID": "Rule Id",
"TIME_HISTORY_ITEM": "Timestamp",
"BTN_STUDY": "Study incident",
"BTN_CLOSE": "Close incident"
"BTN_CLOSE": "Close incident",
"RULE_NAME": "Rule name",
"RULE": "Rule",
"RULE_STATUS": "Rule status"
},
"LIST": {
"TABLE_TITLE": "Table of incidents",
Expand Down
5 changes: 4 additions & 1 deletion src/assets/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@
"RULE_ID": "Идентификатор правила",
"STATUS": "Стутус",
"TIME_HISTORY_ITEM": "Время",
"TITLE": "Инцидент"
"TITLE": "Инцидент",
"RULE_NAME": "Имя правила",
"RULE": "Правило",
"RULE_STATUS": "Стутус правила"
}
},
"CHECKERS": {
Expand Down

0 comments on commit 869e933

Please sign in to comment.