-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datapoints-graph): [MTM-52605] Configure alarms and events in Da…
…ta points graph 2.0 and display on chart (#29) Signed-off-by: Enio Sultan <92023325+eniosultan@users.noreply.github.com> Co-authored-by: Carlos Ceia <carlosceia@gmail.com> Co-authored-by: Enio Sultan <92023325+eniosultan@users.noreply.github.com> Co-authored-by: Enio Sultan <enio94.sutan@gmail.com> Co-authored-by: enio_sultan <ensu@softwareag.com>
- Loading branch information
1 parent
594d12f
commit 04813d1
Showing
61 changed files
with
8,553 additions
and
3,839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...arm-event-selector/alarm-event-attributes-form/alarm-event-attributes-form.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<div [formGroup]="formGroup"> | ||
<c8y-form-group> | ||
<label>{{ 'Label' | translate }}</label> | ||
<input | ||
class="form-control flex-grow" | ||
name="label" | ||
formControlName="label" | ||
[placeholder]=" | ||
'e.g. {{ example }}' | ||
| translate | ||
: { | ||
example: | ||
timelineType === 'ALARM' | ||
? 'Alarm unavailable' | ||
: 'Location update', | ||
} | ||
" | ||
/> | ||
</c8y-form-group> | ||
|
||
<div formGroupName="filters"> | ||
<c8y-form-group> | ||
<label>{{ 'Type' | translate }}</label> | ||
<input | ||
class="form-control flex-grow" | ||
name="type" | ||
formControlName="type" | ||
[placeholder]=" | ||
'e.g. {{ example }}' | ||
| translate | ||
: { | ||
example: | ||
timelineType === 'ALARM' | ||
? 'c8y_UnavailabilityAlarm' | ||
: 'c8y_LocationUpdate', | ||
} | ||
" | ||
/> | ||
</c8y-form-group> | ||
</div> | ||
</div> |
53 changes: 53 additions & 0 deletions
53
...-event-selector/alarm-event-attributes-form/alarm-event-attributes-form.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { CommonModule, FormsModule } from '@c8y/ngx-components'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { AlarmEventAttributesFormComponent } from './alarm-event-attributes-form.component'; | ||
|
||
describe('AlarmEventAttributesFormComponent', () => { | ||
let component: AlarmEventAttributesFormComponent; | ||
let fixture: ComponentFixture<AlarmEventAttributesFormComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [CommonModule.forRoot(), FormsModule, ReactiveFormsModule], | ||
declarations: [AlarmEventAttributesFormComponent], | ||
providers: [], | ||
}); | ||
await TestBed.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AlarmEventAttributesFormComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
describe('onInit', () => { | ||
it('should init form for event', () => { | ||
// given | ||
component.timelineType = 'EVENT'; | ||
// when | ||
fixture.detectChanges(); | ||
// then | ||
expect(component.formGroup.value).toEqual({ | ||
label: '', | ||
filters: { type: '' }, | ||
timelineType: '', | ||
}); | ||
}); | ||
|
||
it('should init form for alarm', () => { | ||
// given | ||
component.timelineType = 'ALARM'; | ||
// when | ||
fixture.detectChanges(); | ||
// then | ||
expect(component.formGroup.value).toEqual({ | ||
label: '', | ||
filters: { type: '' }, | ||
timelineType: '', | ||
}); | ||
}); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
...alarm-event-selector/alarm-event-attributes-form/alarm-event-attributes-form.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Component, forwardRef, Input, OnInit } from '@angular/core'; | ||
import { | ||
AbstractControl, | ||
ControlValueAccessor, | ||
FormBuilder, | ||
FormGroup, | ||
NG_VALIDATORS, | ||
NG_VALUE_ACCESSOR, | ||
ValidationErrors, | ||
Validator, | ||
Validators, | ||
} from '@angular/forms'; | ||
import { take } from 'rxjs/operators'; | ||
import { TimelineType } from '../alarm-event-selector.model'; | ||
|
||
@Component({ | ||
selector: 'c8y-alarm-event-attributes-form', | ||
templateUrl: './alarm-event-attributes-form.component.html', | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
useExisting: forwardRef(() => AlarmEventAttributesFormComponent), | ||
multi: true, | ||
}, | ||
{ | ||
provide: NG_VALIDATORS, | ||
useExisting: forwardRef(() => AlarmEventAttributesFormComponent), | ||
multi: true, | ||
}, | ||
], | ||
}) | ||
export class AlarmEventAttributesFormComponent | ||
implements ControlValueAccessor, Validator, OnInit | ||
{ | ||
@Input() timelineType: TimelineType; | ||
formGroup: FormGroup; | ||
|
||
constructor(private formBuilder: FormBuilder) {} | ||
|
||
ngOnInit() { | ||
this.formGroup = this.formBuilder.group({ | ||
label: ['', [Validators.required]], | ||
filters: this.formBuilder.group({ type: ['', [Validators.required]] }), | ||
timelineType: '', | ||
}); | ||
} | ||
|
||
validate(_control: AbstractControl): ValidationErrors { | ||
return this.formGroup?.valid ? null : { formInvalid: {} }; | ||
} | ||
|
||
writeValue(obj: any): void { | ||
this.formGroup.patchValue(obj); | ||
} | ||
|
||
registerOnChange(fn: any): void { | ||
this.formGroup.valueChanges.subscribe(fn); | ||
} | ||
|
||
registerOnTouched(fn: any): void { | ||
this.formGroup.valueChanges.pipe(take(1)).subscribe(fn); | ||
} | ||
|
||
setDisabledState(isDisabled: boolean): void { | ||
isDisabled ? this.formGroup.disable() : this.formGroup.enable(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...alarm-event-selector/alarm-event-selection-list/alarm-event-selection-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<div class="card-header separator sticky-top bg-inherit p-t-8"> | ||
<span class="card-title h4">{{ | ||
timelineTypeTexts.listTitle | translate | ||
}}</span> | ||
</div> | ||
|
||
<c8y-list-group | ||
class="flex-grow ff-scroll-fix cdk-droplist" | ||
cdkDropList | ||
(cdkDropListDropped)="drop($event)" | ||
[cdkDropListDisabled]="formArray.controls?.length < 2" | ||
> | ||
<div class="p-t-8" *ngIf="!formArray.controls?.length"> | ||
<c8y-ui-empty-state | ||
[icon]="timelineTypeTexts.emptyStateIcon" | ||
[title]="timelineTypeTexts.emptyStateTitle | translate" | ||
[subtitle]="timelineTypeTexts.emptyStateSubtitle | translate" | ||
[horizontal]="true" | ||
class="p-t-8" | ||
></c8y-ui-empty-state> | ||
</div> | ||
<div | ||
*ngFor="let itemForm of formArray.controls; let index = index" | ||
[formGroup]="itemForm" | ||
> | ||
<c8y-alarm-event-selector-list-item | ||
class="d-block" | ||
cdkDrag | ||
formControlName="details" | ||
[showAddRemoveButton]="false" | ||
[optionToRemove]="true" | ||
[showActiveToggle]="true" | ||
[timelineType]="timelineType" | ||
[allowItemEdit]="true" | ||
(removed)="onItemRemoved(index)" | ||
> | ||
<c8y-li-drag-handle | ||
cdkDragHandle | ||
title="{{ 'Click and drag to reorder' | translate }}" | ||
> | ||
<i c8yIcon="drag-reorder"></i> | ||
</c8y-li-drag-handle> | ||
</c8y-alarm-event-selector-list-item> | ||
</div> | ||
</c8y-list-group> | ||
|
||
<div class="card-footer bg-inherit separator-bottom"> | ||
<button | ||
[title]="timelineTypeTexts.addButtonLabel | translate" | ||
type="button" | ||
class="btn btn-default btn-sm" | ||
(click)="add()" | ||
> | ||
<i c8yIcon="plus-circle"></i> | ||
{{ timelineTypeTexts.addButtonLabel | translate }} | ||
</button> | ||
</div> |
59 changes: 59 additions & 0 deletions
59
...rm-event-selector/alarm-event-selection-list/alarm-event-selection-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { AlarmEventSelectionListComponent } from './alarm-event-selection-list.component'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { | ||
CommonModule, | ||
FormsModule, | ||
ListGroupModule, | ||
} from '@c8y/ngx-components'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { BsModalService } from 'ngx-bootstrap/modal'; | ||
import { WidgetConfigComponent } from '@c8y/ngx-components/context-dashboard'; | ||
import { DragDropModule } from '@angular/cdk/drag-drop'; | ||
|
||
describe('AlarmEventSelectionListComponent', () => { | ||
let component: AlarmEventSelectionListComponent; | ||
let fixture: ComponentFixture<AlarmEventSelectionListComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
CommonModule.forRoot(), | ||
FormsModule, | ||
ReactiveFormsModule, | ||
ListGroupModule, | ||
DragDropModule, | ||
], | ||
declarations: [AlarmEventSelectionListComponent], | ||
providers: [ | ||
BsModalService, | ||
{ | ||
provide: WidgetConfigComponent, | ||
useValue: { | ||
context: { id: 1, name: 'test device', c8y_IsDevice: true }, | ||
}, | ||
}, | ||
], | ||
}).compileComponents(); | ||
await TestBed.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AlarmEventSelectionListComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should set context asset', () => { | ||
// when | ||
fixture.detectChanges(); | ||
// then | ||
expect(component.config).toEqual({ | ||
contextAsset: { | ||
id: 1, | ||
name: 'test device', | ||
c8y_IsDevice: true, | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.