File

core/dashboard/widget-time-context.component.ts

Implements

OnInit OnDestroy AfterContentChecked

Metadata

Index

Properties
Methods
Inputs
Outputs

Inputs

canDecouple
Type : boolean
Default value : true

Indicates if the component can decouple or not.

Outputs

dateContextChange
Type : EventEmitter

Emits each change as an array of dates [from, to].

Methods

applyDatetimeContext
applyDatetimeContext()

Applies form value to global or local date context.

Returns : void
predefinedDateFromSelected
predefinedDateFromSelected(selectedDateFrom: PredefinedTimeSpan)
Parameters :
Name Type Optional
selectedDateFrom PredefinedTimeSpan No
Returns : void
reset
reset()

Resets form to initial value and update context.

Returns : void
toggleDecoupling
toggleDecoupling()

Toggles the coupling on or off.

Returns : void

Properties

currentPredefinedTimeSpan
Type : PredefinedTimeSpan
Default value : null
defaultDate
Type : DateTimeContext

The dates to set as default [from, to].

fields
Type : FormlyFieldConfig[]
form
Type : FormGroup
globalDate
Type : DateTimeContext

The global time context value.

isCoupled
Default value : true

Indicates if the time context is bound to the global scope.

localDate
Type : DateTimeContext

The current local date if decoupled.

model
Type : literal type
predefinedTimeSpanList
Type : PredefinedTimeSpan[]
<c8y-action-bar-item
  *ngIf="isCoupled"
  [groupId]="'timecontext'"
  [placement]="'left'"
  itemClass="navbar-form"
>
  <ng-container
    [ngTemplateOutlet]="dateTimePicker"
    [ngTemplateOutletContext]="{ date: globalDate }"
  ></ng-container>
</c8y-action-bar-item>

<ng-container
  *ngIf="!isCoupled"
  [ngTemplateOutlet]="dateTimePicker"
  [ngTemplateOutletContext]="{ date: localDate }"
></ng-container>

<ng-template #dateTimePicker let-date="date">
  <label>{{ 'Time range' | translate }}</label>
  <div class="dropdown m-r-4" dropdown #dropdown="bs-dropdown" container="body" [insideClick]="true">
    <button
      class="dropdown-toggle form-control l-h-1 d-flex a-i-center"
      dropdownToggle
      title="{{ date[0] | c8yDate: 'short' }} — {{ date[1] | c8yDate: 'short' }}"
    >
      <span>{{ date[0] | c8yDate: 'shortDate' }} — {{ date[1] | c8yDate: 'shortDate' }}</span>
      <span class="caret m-r-8 m-l-4"></span>
    </button>

    <div *dropdownMenu class="dropdown-menu dropdown-menu--date-range">
      <div class="p-16">
        <formly-form [form]="form" [fields]="fields" [model]="model"></formly-form>
      </div>
      <div class="p-16 d-flex gap-8 separator-top">
        <button
          class="btn btn-default btn-sm flex-grow"
          (click)="reset(); dropdown.isOpen = false"
          title="{{ 'Reset' | translate }}"
          type="button"
          translate
        >
          Reset
        </button>

        <button
          class="btn btn-primary btn-sm flex-grow"
          (click)="applyDatetimeContext(); dropdown.isOpen = false"
          [disabled]="(form.pristine && form.untouched) || form.invalid"
          title="{{ 'Apply' | translate }}"
          type="button"
          translate
        >
          Apply
        </button>
      </div>
    </div>
  </div>

  <div class="c8y-select-wrapper">
    <select
      class="form-control"
      [ngModel]="currentPredefinedTimeSpan"
      (ngModelChange)="predefinedDateFromSelected($event)"
    >
      <option value="undefined" disabled="true">{{ 'Custom range' | translate }}</option>
      <option *ngFor="let dateFrom of predefinedTimeSpanList" [ngValue]="dateFrom">
        {{ dateFrom.title }}
      </option>
    </select>
    <span></span>
  </div>
</ng-template>

<c8y-dashboard-child-action *ngIf="canDecouple">
  <a href="" (click)="toggleDecoupling(); (false)">
    <i [c8yIcon]="isCoupled ? 'unlock' : 'lock'"></i>
    <span class="m-l-4">
      {{ isCoupled ? 'Decouple time context' : ('Couple time context' | translate) }}
    </span>
  </a>
</c8y-dashboard-child-action>

results matching ""

    No results matching ""