Skip to content

Commit

Permalink
feat(datapoints-graph): alarm selector list item component
Browse files Browse the repository at this point in the history
Alarm selector list item component added

n/a
  • Loading branch information
jdre-c8y committed Apr 24, 2024
1 parent 2d919e3 commit ac3bad0
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,14 @@
*ngFor="let alarmForm of formArray.controls; let index = index"
[formGroup]="alarmForm"
>
<!-- <c8y-datapoint-selector-list-item-->
<!-- class="d-block"-->
<!-- [defaultFormOptions]="defaultFormOptions"-->
<!-- [activeToggleDisabled]="maxActiveCountReached"-->
<!-- [showActiveToggle]="true"-->
<!-- [showAddRemoveButton]="false"-->
<!-- [showOptions]="true"-->
<!-- [editable]="true"-->
<!-- [colorPickerDisabled]="false"-->
<!-- [actions]="actions"-->
<!-- [optionToRemove]="true"-->
<!-- [datapointLibraryEntries]="datapointLibraryEntries"-->
<!-- [hasUnlinkTemplateOption]="true"-->
<!-- formControlName="details"-->
<!-- (removed)="onItemRemoved(index)"-->
<!-- cdkDrag-->
<!-- >-->
<!-- <c8y-li-drag-handle-->
<!-- cdkDragHandle-->
<!-- title="{{ 'Click and drag to reorder' | translate }}"-->
<!-- >-->
<!-- <i c8yIcon="drag-reorder"></i>-->
<!-- </c8y-li-drag-handle>-->
<!-- </c8y-datapoint-selector-list-item>-->
<c8y-alarm-selector-list-item class="d-block" cdkDrag>
<c8y-li-drag-handle
cdkDragHandle
title="{{ 'Click and drag to reorder' | translate }}"
>
<i c8yIcon="drag-reorder"></i>
</c8y-li-drag-handle>
</c8y-alarm-selector-list-item>
</div>
</c8y-list-group>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<c8y-li
class="c8y-list__item__collapse--container-small"
[formGroup]="formGroup"
#li
>
<c8y-li-drag-handle
><ng-content select="c8y-li-drag-handle"></ng-content
></c8y-li-drag-handle>
<c8y-li-checkbox
class="a-s-center p-r-0"
[displayAsSwitch]="true"
formControlName="__active"
(click)="$event.stopPropagation()"
></c8y-li-checkbox>

<!-- <div class="d-flex a-i-center p-l-16">-->
<!-- <div class="c8y-list__item__colorpicker p-t-0 p-b-0 p-l-0" [title]="'Change color' | translate">-->
<!-- <div class="c8y-colorpicker">-->
<!-- <input-->
<!-- type="color"-->
<!-- [attr.aria-label]="'Color' | translate"-->
<!-- formControlName="color"-->
<!-- (click)="$event.stopPropagation()"-->
<!-- />-->
<!-- <span [style.background-color]="formGroup.value.color"></span>-->
<!-- </div>-->
<!-- </div>-->
<!-- <button-->
<!-- class="btn-clean data-point-label text-truncate"-->
<!-- type="button"-->
<!-- [attr.aria-expanded]="!li.collapsed"-->
<!-- (click)="li.collapsed = !li.collapsed"-->
<!-- >-->
<!-- <span class="text-truncate" [title]="formGroup.value.details?.label">-->
<!-- <c8y-highlight-->
<!-- [text]="formGroup.value.details?.label"-->
<!-- [pattern]="highlightText"-->
<!-- [shouldTrimPattern]="true"-->
<!-- ></c8y-highlight>-->
<!-- </span>-->
<!-- <small class="text-truncate text-muted icon-flex" *ngIf="formGroup.value.__target">-->
<!-- <i c8yIcon="exchange"></i>-->
<!-- <span class="text-truncate">{{ formGroup.value.__target.name }}</span>-->
<!-- </small>-->
<!-- </button>-->

<!-- <button-->
<!-- class="btn btn-dot btn-dot&#45;&#45;danger m-l-auto"-->
<!-- type="button"-->
<!-- [attr.aria-label]="'Invalid' | translate"-->
<!-- [popover]="'Some entries are invalid. Check the input fields with red borders.' | translate"-->
<!-- triggers="focus"-->
<!-- placement="right"-->
<!-- container="body"-->
<!-- *ngIf="!(isValid$ | async)"-->
<!-- >-->
<!-- <i c8yIcon="warning"></i>-->
<!-- </button>-->
<!-- <div class="m-l-auto a-s-center p-r-4" *ngIf="showAddRemoveButton">-->
<!-- <button-->
<!-- class="btn btn-dot btn-dot&#45;&#45;danger"-->
<!-- type="button"-->
<!-- [attr.aria-label]="'Remove' | translate"-->
<!-- [tooltip]="'Remove from selected data points' | translate"-->
<!-- [delay]="500"-->
<!-- (click)="addOrRemoveItem()"-->
<!-- *ngIf="isSelected"-->
<!-- [attr.data-cy]="'datapoint-selector-list-item&#45;&#45;remove-datapoint-button'"-->
<!-- >-->
<!-- <i class="icon-20" c8yIcon="minus-circle"></i>-->
<!-- </button>-->
<!-- <button-->
<!-- class="btn btn-dot text-primary"-->
<!-- type="button"-->
<!-- [attr.aria-label]="'Add to selected data points' | translate"-->
<!-- [tooltip]="'Add to selected data points' | translate"-->
<!-- [delay]="500"-->
<!-- (click)="addOrRemoveItem()"-->
<!-- *ngIf="!isSelected"-->
<!-- [attr.data-cy]="'datapoint-selector-list-item&#45;&#45;add-datapoint-button'"-->
<!-- >-->
<!-- <i class="text-primary icon-20" c8yIcon="plus-circle"></i>-->
<!-- </button>-->
<!-- </div>-->
<!-- </div>-->

<!-- <c8y-li-action-->
<!-- *ngIf="optionToRemove"-->
<!-- [icon]="'minus-circle'"-->
<!-- [label]="'Remove from list' | translate"-->
<!-- (click)="remove()"-->
<!-- ></c8y-li-action>-->
<!-- <c8y-li-action-->
<!-- *ngFor="let action of actions"-->
<!-- [icon]="action.icon"-->
<!-- [label]="action.label"-->
<!-- (click)="action.callback(formGroup.value)"-->
<!-- ></c8y-li-action>-->
<!-- <c8y-li-collapse>-->
<!-- <div class="data-point-details">-->
<!-- <ul class="list-unstyled small m-b-16">-->
<!-- <li class="p-t-4 p-b-4 d-flex separator-top-bottom">-->
<!-- <label class="small m-b-0 m-r-8 a-s-start text-muted" translate>Fragment</label>-->
<!-- <span class="m-l-auto">-->
<!-- <c8y-highlight-->
<!-- [text]="formGroup.value.fragment"-->
<!-- [pattern]="highlightText"-->
<!-- [shouldTrimPattern]="true"-->
<!-- ></c8y-highlight>-->
<!-- </span>-->
<!-- </li>-->
<!-- <li class="p-t-4 p-b-4 d-flex separator-bottom">-->
<!-- <label class="small m-b-0 m-r-8 a-s-start text-muted" translate>Series</label>-->
<!-- <span class="m-l-auto">-->
<!-- <c8y-highlight-->
<!-- [text]="formGroup.value.series"-->
<!-- [pattern]="highlightText"-->
<!-- [shouldTrimPattern]="true"-->
<!-- ></c8y-highlight>-->
<!-- </span>-->
<!-- </li>-->
<!-- </ul>-->
<!-- <div-->
<!-- class="form-group"-->
<!-- *ngIf="datapointLibraryEntries && datapointLibraryEntries | async as libraryEntries"-->
<!-- >-->
<!-- <label class="d-inline-block" translate>Data point template</label>-->
<!-- <button-->
<!-- class="btn-help btn-help&#45;&#45;sm"-->
<!-- type="button"-->
<!-- [attr.aria-label]="'Help' | translate"-->
<!-- [popover]="datapointHintPopoverTemplate"-->
<!-- (click)="$event.stopPropagation()"-->
<!-- triggers="focus"-->
<!-- placement="top"-->
<!-- container="body"-->
<!-- ></button>-->

<!-- <ng-template #datapointHintPopoverTemplate>-->
<!-- {{-->
<!-- 'Using a data point template sets color, label, unit and ranges. Removing the template allows you to set the values manually.'-->
<!-- | translate-->
<!-- }}-->
<!-- </ng-template>-->
<!-- <div class="d-flex">-->
<!-- <c8y-typeahead-->
<!-- class="flex-grow"-->
<!-- [placeholder]="'No template' | translate"-->
<!-- [ngModel]="formGroup.value.__template ? formGroup.value.details : undefined"-->
<!-- [ngModelOptions]="{ standalone: true }"-->
<!-- (onSearch)="setPipe($event)"-->
<!-- [displayProperty]="'label'"-->
<!-- [hideNew]="true"-->
<!-- *ngIf="datapointLibraryEntries"-->
<!-- [disabled]="isSelected && disableTypeaheadIfSelected"-->
<!-- >-->
<!-- <c8y-li-->
<!-- class="p-l-8 p-r-8 c8y-list__item&#45;&#45;link interact"-->
<!-- *c8yFor="-->
<!-- let item of datapointLibraryEntries;-->
<!-- loadMore: 'auto';-->
<!-- pipe: filterPipe;-->
<!-- notFound: notFoundTemplate-->
<!-- "-->
<!-- (click)="dataPointTemplateSelected(item)"-->
<!-- [active]="formGroup.value.__template === item.id"-->
<!-- [attr.role]="'menuitem'"-->
<!-- >-->
<!-- <c8y-highlight [text]="item.c8y_Kpi?.label" [pattern]="pattern"></c8y-highlight>-->
<!-- <c8y-li-icon icon="circle" [style.color]="item.c8y_Kpi?.color"></c8y-li-icon>-->
<!-- </c8y-li>-->
<!-- <ng-template #notFoundTemplate>-->
<!-- <c8y-li class="bg-level-2 p-8" *ngIf="pattern.length > 0">-->
<!-- <span>No match found.</span>-->
<!-- </c8y-li>-->
<!-- </ng-template>-->
<!-- </c8y-typeahead>-->
<!-- <button-->
<!-- class="btn btn-info btn-xs btn-icon a-s-center m-l-8"-->
<!-- type="button"-->
<!-- [attr.aria-label]="'Info' | translate"-->
<!-- [popover]="datapointOverviewPopoverTemplate"-->
<!-- placement="left"-->
<!-- triggers="focus"-->
<!-- container="body"-->
<!-- *ngIf="formGroup.value.__template"-->
<!-- >-->
<!-- <i class="text-info" c8yIcon="info"></i>-->
<!-- </button>-->
<!-- <button-->
<!-- class="btn btn-danger btn-xs btn-icon a-s-center m-l-8"-->
<!-- type="button"-->
<!-- tooltip="{{ 'Unlink data point template' | translate }}"-->
<!-- [attr.aria-label]="'Unlink data point template' | translate"-->
<!-- triggers="mouseenter"-->
<!-- [delay]="500"-->
<!-- *ngIf="formGroup.value.__template && hasUnlinkTemplateOption"-->
<!-- (click)="unlinkDatapointTemplate()"-->
<!-- >-->
<!-- <i c8yIcon="unlink"></i>-->
<!-- </button>-->
<!-- </div>-->
<!-- </div>-->
<!-- <ng-template #datapointOverviewPopoverTemplate>-->
<!-- <c8y-datapoint-template-popover-->
<!-- [datapoint]="formGroup.value.details"-->
<!-- ></c8y-datapoint-template-popover>-->
<!-- </ng-template>-->
<!-- <c8y-datapoint-attributes-form-->
<!-- *ngIf="defaultFormOptions"-->
<!-- [showTarget]="defaultFormOptions.showTarget"-->
<!-- [showRange]="defaultFormOptions.showRange"-->
<!-- [showYellowRange]="defaultFormOptions.showYellowRange"-->
<!-- [showRedRange]="defaultFormOptions.showRedRange"-->
<!-- [showChart]="defaultFormOptions.showChart"-->
<!-- [showFormIfTemplateWasSelected]="defaultFormOptions.showFormIfTemplateWasSelected"-->
<!-- formControlName="details"-->
<!-- ></c8y-datapoint-attributes-form>-->
<!-- </div>-->
<!-- </c8y-li-collapse>-->
</c8y-li>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component, forwardRef } from '@angular/core';
import { FormGroup, NG_VALIDATORS, NG_VALUE_ACCESSOR } from '@angular/forms';

@Component({
selector: 'c8y-alarm-selector-list-item',
templateUrl: './alarm-selector-list-item.component.html',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => AlarmSelectorListItemComponent),
multi: true,
},
{
provide: NG_VALIDATORS,
useExisting: forwardRef(() => AlarmSelectorListItemComponent),
multi: true,
},
],
})
export class AlarmSelectorListItemComponent {
formGroup: FormGroup;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export type AlarmSelectorModalOptions = {
contextAsset: IIdentified;
};

export type AlarmDetails = {
timelineType: 'ALARM';
export type AlarmOrEvent = {
timelineType: TimelineType;
color: string;
__active: boolean;
label: string;
Expand All @@ -16,3 +16,11 @@ export type AlarmDetails = {
};
__target: IIdentified;
};

export type AlarmDetails = AlarmOrEvent & {
timelineType: 'ALARM';
};

export type EventDetails = AlarmOrEvent & {
timelineType: 'EVENT';
};
3 changes: 2 additions & 1 deletion src/datapoints-graph/alarm-selector/alarm-selector.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { NgModule } from '@angular/core';
import { DragDropModule } from '@angular/cdk/drag-drop';
import { AlarmSelectionListComponent } from './alarm-selection-list/alarm-selection-list.component';
import { CoreModule } from '@c8y/ngx-components';
import { AlarmSelectorListItemComponent } from './alarm-selector-list-item/alarm-selector-list-item.component';

@NgModule({
imports: [CoreModule, DragDropModule],
declarations: [AlarmSelectionListComponent],
declarations: [AlarmSelectionListComponent, AlarmSelectorListItemComponent],
exports: [AlarmSelectionListComponent],
providers: [],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@
name="datapoints"
></c8y-datapoint-selection-list>

<c8y-alarm-selection-list></c8y-alarm-selection-list>
<c8y-alarm-selection-list
formControlName="alarms"
name="alarms"
class="bg-inherit"
></c8y-alarm-selection-list>
</form>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class DatapointsGraphWidgetConfigComponent
private initForm(): void {
this.formGroup = this.formBuilder.group({
datapoints: [[], [Validators.required, Validators.minLength(1)]],
alarms: [[]],
displayDateSelection: [false, []],
displayAggregationSelection: [false, []],
widgetInstanceGlobalTimeContext: [false, []],
Expand All @@ -157,6 +158,11 @@ export class DatapointsGraphWidgetConfigComponent
});
this.form.form.addControl('config', this.formGroup);
this.formGroup.patchValue(this.config);
this.formGroup.controls.alarms.setValue(
this.config?.alarmsEventsConfigs?.filter(
(ae) => ae.timelineType === 'ALARM'
)
);
}

private initDateSelection(): void {
Expand Down
5 changes: 3 additions & 2 deletions src/datapoints-graph/model/datapoints-graph-widget.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
CHART_RENDER_TYPES,
KPIDetails,
} from '@c8y/ngx-components/datapoint-selector';
import { DateTimeContext } from '@c8y/ngx-components';
import { gettext } from '@c8y/ngx-components';
import { DateTimeContext, gettext } from '@c8y/ngx-components';
import { aggregationType, IMeasurement, ISeries } from '@c8y/client';
import type {
BarSeriesOption,
LineSeriesOption,
ScatterSeriesOption,
} from 'echarts';
import { AlarmOrEvent } from '../alarm-selector/alarm-selector-modal/alarm-selector-modal.model';

export type DatapointsGraphKPIDetails = KPIDetails & {
lineType?: DatapointLineType;
Expand All @@ -20,6 +20,7 @@ export type DatapointsGraphKPIDetails = KPIDetails & {

export type DatapointsGraphWidgetConfig = {
datapoints: DatapointsGraphKPIDetails[];
alarmsEventsConfigs: AlarmOrEvent[];
date?: DateTimeContext;
displayDateSelection?: boolean;
displayAggregationSelection?: boolean;
Expand Down

0 comments on commit ac3bad0

Please sign in to comment.