10 changed files with 365 additions and 9 deletions
@ -0,0 +1,32 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2022 The Thingsboard Authors |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
|
|||
--> |
|||
<section class="tb-widget-settings" [formGroup]="navigationCardWidgetSettingsForm" fxLayout="column"> |
|||
<mat-form-field fxFlex class="mat-block"> |
|||
<mat-label translate>widgets.navigation.title</mat-label> |
|||
<input required matInput formControlName="name"> |
|||
</mat-form-field> |
|||
<tb-material-icon-select fxFlex |
|||
iconClearButton |
|||
required |
|||
formControlName="icon"> |
|||
</tb-material-icon-select> |
|||
<mat-form-field fxFlex class="mat-block"> |
|||
<mat-label translate>widgets.navigation.navigation-path</mat-label> |
|||
<input required matInput formControlName="path"> |
|||
</mat-form-field> |
|||
</section> |
|||
@ -0,0 +1,56 @@ |
|||
///
|
|||
/// Copyright © 2016-2022 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { Component } from '@angular/core'; |
|||
import { WidgetSettings, WidgetSettingsComponent } from '@shared/models/widget.models'; |
|||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-navigation-card-widget-settings', |
|||
templateUrl: './navigation-card-widget-settings.component.html', |
|||
styleUrls: ['./../widget-settings.scss'] |
|||
}) |
|||
export class NavigationCardWidgetSettingsComponent extends WidgetSettingsComponent { |
|||
|
|||
navigationCardWidgetSettingsForm: FormGroup; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
private fb: FormBuilder) { |
|||
super(store); |
|||
} |
|||
|
|||
protected settingsForm(): FormGroup { |
|||
return this.navigationCardWidgetSettingsForm; |
|||
} |
|||
|
|||
protected defaultSettings(): WidgetSettings { |
|||
return { |
|||
name: '{i18n:device.devices}', |
|||
icon: 'devices_other', |
|||
path: '/devices' |
|||
}; |
|||
} |
|||
|
|||
protected onSettingsSet(settings: WidgetSettings) { |
|||
this.navigationCardWidgetSettingsForm = this.fb.group({ |
|||
name: [settings.name, [Validators.required]], |
|||
icon: [settings.icon, [Validators.required]], |
|||
path: [settings.path, [Validators.required]] |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2022 The Thingsboard Authors |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
|
|||
--> |
|||
<section class="tb-widget-settings" [formGroup]="navigationCardsWidgetSettingsForm" fxLayout="column"> |
|||
<section style="margin-bottom: 16px;"> |
|||
<div class="mat-caption" style="margin: -8px 0 8px;" translate>widgets.navigation.filter-type</div> |
|||
<mat-radio-group formControlName="filterType" fxLayoutGap="16px"> |
|||
<mat-radio-button [value]="'all'">{{ 'widgets.navigation.filter-type-all' | translate }}</mat-radio-button> |
|||
<mat-radio-button [value]="'include'">{{ 'widgets.navigation.filter-type-include' | translate }}</mat-radio-button> |
|||
<mat-radio-button [value]="'exclude'">{{ 'widgets.navigation.filter-type-exclude' | translate }}</mat-radio-button> |
|||
</mat-radio-group> |
|||
</section> |
|||
<mat-form-field [fxShow]="navigationCardsWidgetSettingsForm.get('filterType').value !== 'all'" fxFlex class="mat-block" floatLabel="always"> |
|||
<mat-label translate>widgets.navigation.items</mat-label> |
|||
<mat-chip-list #filterItemsChipList> |
|||
<mat-chip *ngFor="let filterItem of navigationCardsWidgetSettingsForm.get('filter').value" |
|||
[removable]="true" (removed)="onFilterItemRemoved(filterItem)"> |
|||
{{ filterItem }} |
|||
<mat-icon matChipRemove>cancel</mat-icon> |
|||
</mat-chip> |
|||
<input matInput type="text" placeholder="{{ 'widgets.navigation.enter-urls-to-filter' | translate }}" |
|||
style="max-width: 200px;" |
|||
#filterItemInput |
|||
(focusin)="onFilterItemInputFocus()" |
|||
matAutocompleteOrigin |
|||
#origin="matAutocompleteOrigin" |
|||
(input)="filterItemInputChange.next(filterItemInput.value)" |
|||
[matAutocompleteConnectedTo]="origin" |
|||
[matAutocomplete]="filterItemAutocomplete" |
|||
[matChipInputFor]="filterItemsChipList" |
|||
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" |
|||
(matChipInputTokenEnd)="addFilterItemFromChipInput($event)"> |
|||
</mat-chip-list> |
|||
<mat-autocomplete #filterItemAutocomplete="matAutocomplete" |
|||
class="tb-autocomplete" |
|||
(optionSelected)="filterItemSelected($event)"> |
|||
<mat-option *ngFor="let filterItem of filteredFilterItems | async" [value]="filterItem"> |
|||
<span [innerHTML]="filterItem | highlight:filterItemSearchText"></span> |
|||
</mat-option> |
|||
</mat-autocomplete> |
|||
</mat-form-field> |
|||
</section> |
|||
@ -0,0 +1,156 @@ |
|||
///
|
|||
/// Copyright © 2016-2022 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { Component, ElementRef, ViewChild } from '@angular/core'; |
|||
import { WidgetSettings, WidgetSettingsComponent } from '@shared/models/widget.models'; |
|||
import { FormBuilder, FormGroup } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { MatChipInputEvent, MatChipList } from '@angular/material/chips'; |
|||
import { MatAutocomplete, MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; |
|||
import { COMMA, ENTER, SEMICOLON } from '@angular/cdk/keycodes'; |
|||
import { Observable, of, Subject } from 'rxjs'; |
|||
import { map, mergeMap, share, startWith } from 'rxjs/operators'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-navigation-cards-widget-settings', |
|||
templateUrl: './navigation-cards-widget-settings.component.html', |
|||
styleUrls: ['./../widget-settings.scss'] |
|||
}) |
|||
export class NavigationCardsWidgetSettingsComponent extends WidgetSettingsComponent { |
|||
|
|||
@ViewChild('filterItemsChipList') filterItemsChipList: MatChipList; |
|||
@ViewChild('filterItemAutocomplete') filterItemAutocomplete: MatAutocomplete; |
|||
@ViewChild('filterItemInput') filterItemInput: ElementRef<HTMLInputElement>; |
|||
|
|||
filterItems: Array<string> = ['/devices', '/assets', '/deviceProfiles']; |
|||
|
|||
separatorKeysCodes = [ENTER, COMMA, SEMICOLON]; |
|||
|
|||
navigationCardsWidgetSettingsForm: FormGroup; |
|||
|
|||
filteredFilterItems: Observable<Array<string>>; |
|||
|
|||
filterItemSearchText = ''; |
|||
|
|||
filterItemInputChange = new Subject<string>(); |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
private fb: FormBuilder) { |
|||
super(store); |
|||
this.filteredFilterItems = this.filterItemInputChange |
|||
.pipe( |
|||
startWith(''), |
|||
map((value) => value ? value : ''), |
|||
mergeMap(name => this.fetchFilterItems(name) ), |
|||
share() |
|||
); |
|||
} |
|||
|
|||
protected settingsForm(): FormGroup { |
|||
return this.navigationCardsWidgetSettingsForm; |
|||
} |
|||
|
|||
protected defaultSettings(): WidgetSettings { |
|||
return { |
|||
filterType: 'all', |
|||
filter: [] |
|||
}; |
|||
} |
|||
|
|||
protected onSettingsSet(settings: WidgetSettings) { |
|||
this.navigationCardsWidgetSettingsForm = this.fb.group({ |
|||
filterType: [settings.filterType, []], |
|||
filter: [settings.filter, []] |
|||
}); |
|||
} |
|||
|
|||
protected validatorTriggers(): string[] { |
|||
return ['filterType']; |
|||
} |
|||
|
|||
protected updateValidators(emitEvent: boolean) { |
|||
const filterType: string = this.navigationCardsWidgetSettingsForm.get('filterType').value; |
|||
if (filterType === 'all') { |
|||
this.navigationCardsWidgetSettingsForm.get('filter').disable(); |
|||
} else { |
|||
this.navigationCardsWidgetSettingsForm.get('filter').enable(); |
|||
} |
|||
this.navigationCardsWidgetSettingsForm.get('filter').updateValueAndValidity({emitEvent}); |
|||
} |
|||
|
|||
private fetchFilterItems(searchText?: string): Observable<Array<string>> { |
|||
this.filterItemSearchText = searchText; |
|||
let result = [...this.filterItems]; |
|||
if (this.filterItemSearchText && this.filterItemSearchText.length) { |
|||
result.unshift(this.filterItemSearchText); |
|||
result = result.filter(item => item.includes(this.filterItemSearchText)); |
|||
} |
|||
return of(result); |
|||
} |
|||
|
|||
private addFilterItem(filterItem: string): boolean { |
|||
if (filterItem) { |
|||
const filterItems: string[] = this.navigationCardsWidgetSettingsForm.get('filter').value; |
|||
const index = filterItems.indexOf(filterItem); |
|||
if (index === -1) { |
|||
filterItems.push(filterItem); |
|||
this.navigationCardsWidgetSettingsForm.get('filter').setValue(filterItems); |
|||
this.navigationCardsWidgetSettingsForm.get('filter').markAsDirty(); |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
onFilterItemRemoved(filterItem: string): void { |
|||
const filterItems: string[] = this.navigationCardsWidgetSettingsForm.get('filter').value; |
|||
const index = filterItems.indexOf(filterItem); |
|||
if (index > -1) { |
|||
filterItems.splice(index, 1); |
|||
this.navigationCardsWidgetSettingsForm.get('filter').setValue(filterItems); |
|||
this.navigationCardsWidgetSettingsForm.get('filter').markAsDirty(); |
|||
} |
|||
} |
|||
|
|||
onFilterItemInputFocus() { |
|||
this.filterItemInputChange.next(this.filterItemInput.nativeElement.value); |
|||
} |
|||
|
|||
addFilterItemFromChipInput(event: MatChipInputEvent): void { |
|||
const value = event.value; |
|||
if ((value || '').trim()) { |
|||
const filterItem = value.trim(); |
|||
if (this.addFilterItem(filterItem)) { |
|||
this.clearFilterItemInput(''); |
|||
} |
|||
} |
|||
} |
|||
|
|||
filterItemSelected(event: MatAutocompleteSelectedEvent): void { |
|||
this.addFilterItem(event.option.value); |
|||
this.clearFilterItemInput(''); |
|||
} |
|||
|
|||
clearFilterItemInput(value: string = '') { |
|||
this.filterItemInput.nativeElement.value = value; |
|||
this.filterItemInputChange.next(null); |
|||
setTimeout(() => { |
|||
this.filterItemInput.nativeElement.blur(); |
|||
this.filterItemInput.nativeElement.focus(); |
|||
}, 0); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue