CHANGE: focus on name input
This commit is contained in:
@@ -2,18 +2,18 @@
|
||||
<form class="grid grid-cols-2 gap-4" (submit)="$event.preventDefault();generatorService.createEntity()" >
|
||||
<div class="property" *ngIf="hasProperty('name')">
|
||||
<p>Name</p>
|
||||
<input required placeholder="entity name" type="text" name="entity_name" [ngModel]="entity_name" (ngModelChange)="entity_name = $event"/>
|
||||
<input tabindex="0" #nameinput autocomplete="name" placeholder="entity name" type="text" name="entity_name" [ngModel]="entity_name" (ngModelChange)="entity_name = $event"/>
|
||||
</div>
|
||||
<div class="property" *ngIf="hasProperty('uniq_id')">
|
||||
<p>Uniqe ID</p>
|
||||
<div class="flex-row flex gap-2">
|
||||
<input type="text" name="entity_uniq_id" [ngModel]="entity_uniq_id" (ngModelChange)="entity_uniq_id = $event"/>
|
||||
<button class="randomButton" >
|
||||
<!-- <button tabindex="-1" class="randomButton" type="button">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-dice-3" viewBox="0 0 16 16">
|
||||
<path d="M13 1a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2zM3 0a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h10a3 3 0 0 0 3-3V3a3 3 0 0 0-3-3z"/>
|
||||
<path d="M5.5 4a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m8 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m-4-4a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0"/>
|
||||
</svg>
|
||||
</button>
|
||||
</button> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="property" *ngIf="hasProperty('cmd_t')">
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { Component, Input, ViewChild } from '@angular/core';
|
||||
import { DeviceClass, MQTTEntity } from '../_models/mqtt_base';
|
||||
import { EntityService } from '../_services/entity.service';
|
||||
import { GeneratorService } from '../_services/generator.service';
|
||||
|
||||
@Component({
|
||||
@@ -9,17 +8,18 @@ import { GeneratorService } from '../_services/generator.service';
|
||||
styleUrl: './entity-data.component.css',
|
||||
})
|
||||
export class EntityDataComponent {
|
||||
@Input() entity_type: number = 0;
|
||||
@Input() entity_type: number = 1;
|
||||
@Input() basemodel!: MQTTEntity;
|
||||
@Input() created: boolean = false;
|
||||
constructor(
|
||||
private entityService: EntityService,
|
||||
public generatorService: GeneratorService
|
||||
) {
|
||||
@ViewChild('nameinput') nameinput!: any;
|
||||
constructor(public generatorService: GeneratorService) {
|
||||
if (generatorService.selected_entity) {
|
||||
this.basemodel = generatorService.selected_entity;
|
||||
}
|
||||
}
|
||||
ngAfterViewInit() {
|
||||
if (!this.created) this.nameinput.nativeElement.focus();
|
||||
}
|
||||
|
||||
_entity_name: string = '';
|
||||
_entity_uniq_id: string = '';
|
||||
|
||||
@@ -49,23 +49,23 @@ export class EntityComponent {
|
||||
}
|
||||
|
||||
update(model: keyof this = 'stat_t', event: Event | boolean = false): void {
|
||||
if (this.generatorService.auto_topic == 2) {
|
||||
this.stat_t = this.updateTopic('stat');
|
||||
this.entity_cmd_t = this.updateTopic('cmd');
|
||||
this.entity_bri_cmd_t = this.updateTopic('bri_cmd');
|
||||
return;
|
||||
}
|
||||
if (event instanceof Event)
|
||||
var value = (event.target as HTMLInputElement).value;
|
||||
else return;
|
||||
if (this.generatorService.auto_topic == 1) {
|
||||
this.sync_topcis(model, value);
|
||||
} else {
|
||||
if (!this.hasOwnProperty(model)) return;
|
||||
if (typeof this[model] === 'string') {
|
||||
this[model] = value as (typeof this)[keyof this];
|
||||
}
|
||||
}
|
||||
// if (this.generatorService.auto_topic == 2) {
|
||||
// this.stat_t = this.updateTopic('stat');
|
||||
// this.entity_cmd_t = this.updateTopic('cmd');
|
||||
// this.entity_bri_cmd_t = this.updateTopic('bri_cmd');
|
||||
// return;
|
||||
// }
|
||||
// if (event instanceof Event)
|
||||
// var value = (event.target as HTMLInputElement).value;
|
||||
// else return;
|
||||
// if (this.generatorService.auto_topic == 1) {
|
||||
// this.sync_topcis(model, value);
|
||||
// } else {
|
||||
// if (!this.hasOwnProperty(model)) return;
|
||||
// if (typeof this[model] === 'string') {
|
||||
// this[model] = value as (typeof this)[keyof this];
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
sync_topcis(model: keyof this, value: string) {
|
||||
@@ -74,7 +74,7 @@ export class EntityComponent {
|
||||
let missing = new_list.filter((item) => old_list.indexOf(item) < 0);
|
||||
|
||||
if (old_list.filter((item) => new_list.indexOf(item) < 0).length > 1)
|
||||
return (this.generatorService.auto_topic = 0);
|
||||
return (this.generatorService.auto_topic = false);
|
||||
if (missing.length == 0) return; //(this.generatorService.auto_topic = 2);
|
||||
if (new_list.indexOf(missing[0]) == new_list.length - 1) {
|
||||
this[model] = value as (typeof this)[keyof this];
|
||||
@@ -114,38 +114,38 @@ export class EntityComponent {
|
||||
return topic_str;
|
||||
}
|
||||
|
||||
select_type(event: unknown) {
|
||||
let ent_type = entity_types[event as keyof typeof entity_types];
|
||||
let ent_class = ent_type[1];
|
||||
if (typeof ent_class === 'function' && event != 0) {
|
||||
this.basemodel = new ent_class();
|
||||
this.generatorService.selected_entity = this.basemodel;
|
||||
if (this.generatorService.has_property('dev_cla')) {
|
||||
this.entity_dev_cla = this.basemodel.getProperty('dev_cla');
|
||||
}
|
||||
} else this.generatorService.selected_entity = null;
|
||||
this.entity_type = event as number;
|
||||
this.update();
|
||||
}
|
||||
select_type(event: unknown) {}
|
||||
// let ent_type = entity_types[event as keyof typeof entity_types];
|
||||
// let ent_class = ent_type[1];
|
||||
// if (typeof ent_class === 'function' && event != 0) {
|
||||
// this.basemodel = new ent_class();
|
||||
// this.generatorService.selected_entity = this.basemodel;
|
||||
// // if (this.generatorService.has_property('dev_cla')) {
|
||||
// // this.entity_dev_cla = this.basemodel.;
|
||||
// // }
|
||||
// } else this.generatorService.selected_entity = null;
|
||||
// this.entity_type = event as number;
|
||||
// this.update();
|
||||
// }
|
||||
|
||||
lock_auto_topic() {
|
||||
this.generatorService.auto_topic = 1;
|
||||
// this.generatorService.auto_topic = 1;
|
||||
}
|
||||
|
||||
create_entity() {
|
||||
this.basemodel?.setProperty('stat_t', this.stat_t);
|
||||
this.basemodel?.setProperty('name', this.entity_name);
|
||||
this.basemodel?.setProperty('cmd_t', this.entity_cmd_t);
|
||||
this.basemodel?.setProperty('bri_cmd_t', this.entity_bri_cmd_t);
|
||||
this.basemodel?.setProperty('pl_off', this.entity_pl_off);
|
||||
this.basemodel?.setProperty('pl_on', this.entity_pl_on);
|
||||
this.basemodel?.setProperty('unit_of_meas', this.entity_unit_of_meas);
|
||||
this.basemodel?.setProperty('val_tpl', this.entity_val_tpl);
|
||||
this.basemodel?.setProperty('dev_cla', this.entity_dev_cla);
|
||||
this._discoveryTopic = this.discoveryTopic;
|
||||
this.showDiscovery = true;
|
||||
return;
|
||||
}
|
||||
create_entity() {}
|
||||
// this.basemodel?.setProperty('stat_t', this.stat_t);
|
||||
// this.basemodel?.setProperty('name', this.entity_name);
|
||||
// this.basemodel?.setProperty('cmd_t', this.entity_cmd_t);
|
||||
// this.basemodel?.setProperty('bri_cmd_t', this.entity_bri_cmd_t);
|
||||
// this.basemodel?.setProperty('pl_off', this.entity_pl_off);
|
||||
// this.basemodel?.setProperty('pl_on', this.entity_pl_on);
|
||||
// this.basemodel?.setProperty('unit_of_meas', this.entity_unit_of_meas);
|
||||
// this.basemodel?.setProperty('val_tpl', this.entity_val_tpl);
|
||||
// this.basemodel?.setProperty('dev_cla', this.entity_dev_cla);
|
||||
// this._discoveryTopic = this.discoveryTopic;
|
||||
// this.showDiscovery = true;
|
||||
// return;
|
||||
// }
|
||||
|
||||
get discoveryString() {
|
||||
return this.basemodel?.toJSON();
|
||||
|
||||
Reference in New Issue
Block a user