/// /// Copyright © 2016-2019 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, OnInit } from '@angular/core'; import { select, Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { EntityComponent } from '@shared/components/entity/entity.component'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { User } from '@shared/models/user.model'; import { selectAuth, selectUserDetails } from '@core/auth/auth.selectors'; import { map } from 'rxjs/operators'; import { Authority } from '@shared/models/authority.enum'; import {DeviceInfo} from '@shared/models/device.models'; import {EntityType} from '@shared/models/entity-type.models'; import {NULL_UUID} from '@shared/models/id/has-uuid'; @Component({ selector: 'tb-device', templateUrl: './device.component.html', styleUrls: ['./device.component.scss'] }) export class DeviceComponent extends EntityComponent { entityType = EntityType; deviceScope: 'tenant' | 'customer' | 'customer_user'; constructor(protected store: Store, public fb: FormBuilder) { super(store); } ngOnInit() { this.deviceScope = this.entitiesTableConfig.componentsData.deviceScope; super.ngOnInit(); } hideDelete() { if (this.entitiesTableConfig) { return !this.entitiesTableConfig.deleteEnabled(this.entity); } else { return false; } } isAssignedToCustomer(entity: DeviceInfo): boolean { return entity && entity.customerId && entity.customerId.id !== NULL_UUID; } buildForm(entity: DeviceInfo): FormGroup { return this.fb.group( { name: [entity ? entity.name : '', [Validators.required]], type: [entity ? entity.type : null, [Validators.required]], label: [entity ? entity.label : ''], additionalInfo: this.fb.group( { gateway: [entity && entity.additionalInfo ? entity.additionalInfo.gateway : false], description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''], } ) } ); } updateForm(entity: DeviceInfo) { this.entityForm.patchValue({name: entity.name}); this.entityForm.patchValue({type: entity.type}); this.entityForm.patchValue({label: entity.label}); this.entityForm.patchValue({additionalInfo: {gateway: entity.additionalInfo ? entity.additionalInfo.gateway : false}}); this.entityForm.patchValue({additionalInfo: {description: entity.additionalInfo ? entity.additionalInfo.description : ''}}); } }