-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6287143
commit 2344cde
Showing
8 changed files
with
384 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...s/timescale-rules-create-edit-template/timescale-rules-create-edit-template.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2023 InfAI (CC SES) | ||
* | ||
* 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. | ||
*/ | ||
|
||
.mat-mdc-dialog-content { | ||
padding-top: 8px; | ||
} |
127 changes: 127 additions & 0 deletions
127
.../timescale-rules-create-edit-template/timescale-rules-create-edit-template.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<!-- | ||
~ | ||
~ Copyright 2023 InfAI (CC SES) | ||
~ | ||
~ 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. | ||
~ | ||
--> | ||
<h2 mat-dialog-title>Timescale Rule</h2> | ||
|
||
<mat-dialog-content> | ||
|
||
|
||
<form [formGroup]="form" fxLayout="column"> | ||
<div> | ||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>ID</mat-label> | ||
<input matInput formControlName="id"> | ||
</mat-form-field> | ||
</div> | ||
|
||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>Template</mat-label> | ||
<senergy-select-search [options]="templates" formControlName="template" useOptionViewProperty="name" | ||
useOptionValueProperty="name" [required]="true"></senergy-select-search> | ||
</mat-form-field> | ||
|
||
<div> | ||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>Description</mat-label> | ||
<input matInput formControlName="description" required> | ||
</mat-form-field> | ||
</div> | ||
|
||
<div> | ||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>Target</mat-label> | ||
<mat-select formControlName="target" placeholder="Target" required> | ||
<mat-option [value]="'device'"> | ||
Devices | ||
</mat-option> | ||
<mat-option [value]="'export'"> | ||
Exports | ||
</mat-option> | ||
</mat-select> | ||
</mat-form-field> | ||
</div> | ||
|
||
<div> | ||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>Users</mat-label> | ||
<senergy-select-search [options]="users" [multiple]="true" formControlName="users" | ||
useOptionViewProperty="username" | ||
useOptionValueProperty="id"></senergy-select-search> | ||
</mat-form-field> | ||
</div> | ||
|
||
<div> | ||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>Roles</mat-label> | ||
<senergy-select-search [options]="roles" [multiple]="true" | ||
formControlName="roles"></senergy-select-search> | ||
</mat-form-field> | ||
</div> | ||
|
||
<div *ngIf="rule?.errors !== null && rule?.errors !== undefined && (rule?.errors?.length || 0) > 0"> | ||
<mat-form-field color="accent" appearance="outline" fxFill disabled=""> | ||
<mat-label>Errors</mat-label> | ||
<textarea matInput [value]="(rule?.errors || []).join('\n')" cdkTextareaAutosize cdkAutosizeMinRows="1" | ||
disabled></textarea> | ||
</mat-form-field> | ||
</div> | ||
|
||
<mat-expansion-panel> | ||
<mat-expansion-panel-header> | ||
<mat-panel-title fxFlex>Details</mat-panel-title> | ||
</mat-expansion-panel-header> | ||
<ng-template matExpansionPanelContent> | ||
|
||
<div> | ||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>Group</mat-label> | ||
<input matInput formControlName="group" required> | ||
</mat-form-field> | ||
</div> | ||
|
||
<div> | ||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>Priority</mat-label> | ||
<input matInput formControlName="priority" required type="number"> | ||
</mat-form-field> | ||
</div> | ||
|
||
<div> | ||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>Command Template</mat-label> | ||
<textarea matInput formControlName="command_template" required cdkTextareaAutosize | ||
cdkAutosizeMinRows="5"></textarea> | ||
</mat-form-field> | ||
</div> | ||
|
||
<div> | ||
<mat-form-field color="accent" appearance="outline" fxFill> | ||
<mat-label>Delete Template</mat-label> | ||
<textarea matInput formControlName="delete_template" cdkTextareaAutosize | ||
cdkAutosizeMinRows="1"></textarea> | ||
</mat-form-field> | ||
</div> | ||
</ng-template> | ||
</mat-expansion-panel> | ||
</form> | ||
</mat-dialog-content> | ||
|
||
|
||
<mat-dialog-actions fxLayoutAlign="end center"> | ||
<button mat-raised-button color="primary" (click)="close()">Cancel</button> | ||
<button mat-raised-button color="accent" (click)="save()" [disabled]="form.invalid" *ngIf="editable">Save</button> | ||
</mat-dialog-actions> |
111 changes: 111 additions & 0 deletions
111
...es/timescale-rules-create-edit-template/timescale-rules-create-edit-template.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2023 InfAI (CC SES) | ||
* | ||
* 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, Inject} from '@angular/core'; | ||
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; | ||
import {TimescaleRuleModel, TimescaleRuleTemplateModel} from '../shared/timescale-rule.model'; | ||
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; | ||
import {TimescaleRulesService} from '../shared/timescale-rules.service'; | ||
|
||
@Component({ | ||
selector: 'senergy-timescale-rules-create-edit-template', | ||
templateUrl: './timescale-rules-create-edit-template.component.html', | ||
styleUrls: ['./timescale-rules-create-edit-template.component.css'] | ||
}) | ||
export class TimescaleRulesCreateEditTemplateComponent { | ||
|
||
rule?: TimescaleRuleModel; | ||
editable = false; | ||
roles: string[] = []; | ||
users: any[] = []; | ||
form: FormGroup = this.fb.group({ | ||
id: {value: '', disabled: true}, | ||
description: [{value: '', disabled: true}, Validators.required], | ||
priority: [{value: 0, disabled: true}, Validators.required], | ||
group: [{value: '', disabled: true}, Validators.required], | ||
target: ['', Validators.required], | ||
users: [], | ||
roles: [], | ||
command_template: [{value: '', disabled: true}, Validators.required], | ||
delete_template: {value: '', disabled: true}, | ||
errors: {value: null, disabled: true}, | ||
template: ['', Validators.required], | ||
}); | ||
create = false; | ||
templates: TimescaleRuleTemplateModel[] = []; | ||
|
||
constructor( | ||
private dialogRef: MatDialogRef<TimescaleRulesCreateEditTemplateComponent>, | ||
private fb: FormBuilder, | ||
@Inject(MAT_DIALOG_DATA) data: { | ||
rule?: TimescaleRuleModel; | ||
editable: boolean; | ||
roles: string[]; | ||
users: any[]; | ||
templates: TimescaleRuleTemplateModel[]; | ||
}, | ||
private timescaleRuleService: TimescaleRulesService, | ||
) { | ||
this.rule = data.rule; | ||
this.roles = data.roles; | ||
this.users = data.users; | ||
this.editable = data.editable; | ||
this.templates = data.templates; | ||
if (this.rule !== undefined) { | ||
this.form.patchValue(this.rule); | ||
} | ||
if (!this.editable) { | ||
this.form.disable(); | ||
} | ||
this.create = data.rule === undefined; | ||
this.form.get('template')?.valueChanges.subscribe(name => { | ||
const template = this.templates.find(t => t.name === name); | ||
if (template === undefined) { | ||
return; | ||
} | ||
this.form.patchValue({ | ||
description: template.description, | ||
priority: template.priority, | ||
group: template.group, | ||
command_template: template.command_template, | ||
delete_template: template.delete_template, | ||
}); | ||
}); | ||
} | ||
|
||
save() { | ||
this.rule = this.form.getRawValue() as TimescaleRuleModel; | ||
this.rule.errors = undefined; | ||
this.rule.completed_run = false; | ||
if (this.create) { | ||
this.timescaleRuleService.createRuleFromTemplate(this.rule).subscribe(rule => { | ||
if (rule !== null) { | ||
this.dialogRef.close(rule); | ||
} | ||
}); | ||
} else { | ||
this.timescaleRuleService.updateRuleFromTemplate(this.rule).subscribe(t => { | ||
if (t) { | ||
this.dialogRef.close(this.rule); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
close() { | ||
this.dialogRef.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.