added help component, improved prediction with model templates
This commit is contained in:
65
src/app/model-templates/model-templates.component.html
Normal file
65
src/app/model-templates/model-templates.component.html
Normal file
@ -0,0 +1,65 @@
|
||||
<h2>Models</h2>
|
||||
|
||||
<rb-icon-button icon="add" mode="primary" (click)="newModel = !newModel" class="space-below">New model</rb-icon-button>
|
||||
|
||||
<form *ngIf="newModel" #modelForm="ngForm">
|
||||
<rb-form-input name="group" label="group" appValidate="string" required [(ngModel)]="modelGroup" #groupInput="ngModel"
|
||||
[rbFormInputAutocomplete]="autocomplete.bind(this, groups)"
|
||||
[rbDebounceTime]="0" [rbInitialOpen]="true">
|
||||
<ng-template rbFormValidationMessage="failure">{{groupInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
<rb-form-input name="name" label="name" appValidate="string" required [(ngModel)]="model.name" #nameInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{nameInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
<rb-form-input name="label" label="label" appValidate="string" [(ngModel)]="model.label" #labelInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{labelInput.errors.failure}}</ng-template>
|
||||
</rb-form-input>
|
||||
<rb-form-input name="url" label="URL" appValidate="url" required [(ngModel)]="model.url" #urlInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{urlInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
|
||||
<rb-icon-button icon="save" mode="primary" type="submit" [disabled]="!modelForm.form.valid" (click)="saveModel()">
|
||||
Save model
|
||||
</rb-icon-button>
|
||||
</form>
|
||||
|
||||
<rb-table class="space-above">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Label</th>
|
||||
<th>URL</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<ng-container *ngFor="let group of d.arr.modelGroups">
|
||||
<tr><th>{{group.group}}</th><th></th><th></th><th></th><th></th></tr>
|
||||
<tr *ngFor="let modelItem of group.models">
|
||||
<td>{{modelItem.name}}</td>
|
||||
<td>{{modelItem.label}}</td>
|
||||
<td>{{modelItem.url}}</td>
|
||||
<td>
|
||||
<span class="rb-ic rb-ic-edit clickable"
|
||||
(click)="modelGroup = group.group;
|
||||
oldModelGroup = group.group;
|
||||
oldModelName = modelItem.name;
|
||||
model = modelItem;
|
||||
newModel = true;">
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="rb-ic rb-ic-delete clickable"
|
||||
(click)="deleteModel(group.group, modelItem.name, modalDeleteConfirm)"></span>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-container>
|
||||
</rb-table>
|
||||
|
||||
<ng-template #modalDeleteConfirm>
|
||||
<rb-alert alertTitle="Are you sure?" type="danger" okBtnLabel="Delete model" cancelBtnLabel="Cancel">
|
||||
Do you really want to delete this model?
|
||||
</rb-alert>
|
||||
</ng-template>
|
25
src/app/model-templates/model-templates.component.spec.ts
Normal file
25
src/app/model-templates/model-templates.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ModelTemplatesComponent } from './model-templates.component';
|
||||
|
||||
describe('ModelTemplatesComponent', () => {
|
||||
let component: ModelTemplatesComponent;
|
||||
let fixture: ComponentFixture<ModelTemplatesComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ModelTemplatesComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ModelTemplatesComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
74
src/app/model-templates/model-templates.component.ts
Normal file
74
src/app/model-templates/model-templates.component.ts
Normal file
@ -0,0 +1,74 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {DataService} from '../services/data.service';
|
||||
import {ModelItemModel} from '../models/model-item.model';
|
||||
import {ApiService} from '../services/api.service';
|
||||
import {AutocompleteService} from '../services/autocomplete.service';
|
||||
import {ModalService} from '@inst-iot/bosch-angular-ui-components';
|
||||
|
||||
@Component({
|
||||
selector: 'app-model-templates',
|
||||
templateUrl: './model-templates.component.html',
|
||||
styleUrls: ['./model-templates.component.scss']
|
||||
})
|
||||
export class ModelTemplatesComponent implements OnInit {
|
||||
|
||||
newModel = false;
|
||||
modelGroup = '';
|
||||
oldModelGroup = '';
|
||||
oldModelName = '';
|
||||
model = new ModelItemModel().models[0];
|
||||
groups = [];
|
||||
|
||||
constructor(
|
||||
private api: ApiService,
|
||||
public autocomplete: AutocompleteService,
|
||||
public d: DataService,
|
||||
private modal: ModalService
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadGroups();
|
||||
}
|
||||
|
||||
loadGroups() {
|
||||
delete this.d.arr.modelGroups;
|
||||
this.d.load('modelGroups', () => {
|
||||
this.groups = this.d.arr.modelGroups.map(e => e.group);
|
||||
});
|
||||
}
|
||||
|
||||
saveModel() {
|
||||
if (this.modelGroup !== this.oldModelGroup) { // group was changed, delete model in old group
|
||||
this.deleteModel(this.oldModelGroup, this.oldModelName);
|
||||
}
|
||||
this.api.post('/model/' + this.modelGroup, this.model, () => {
|
||||
this.newModel = false;
|
||||
this.loadGroups();
|
||||
this.modelGroup = '';
|
||||
this.oldModelGroup = '';
|
||||
this.oldModelName = '';
|
||||
this.model = new ModelItemModel().models[0];
|
||||
this.groups = this.d.arr.modelGroups.map(e => e.group);
|
||||
});
|
||||
}
|
||||
|
||||
deleteModel(group, name, modal = null) {
|
||||
new Promise(resolve => {
|
||||
if (modal) {
|
||||
this.modal.open(modal).then(result => {
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
else {
|
||||
resolve(true);
|
||||
}
|
||||
}).then(res => {
|
||||
if (res) {
|
||||
this.api.delete(`/model/${group}/${name}`, () => {
|
||||
this.loadGroups();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user