Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webapp setup: System Events settings
- Loading branch information
1 parent
6ab306d
commit c70edac
Showing
12 changed files
with
208 additions
and
8 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
2 changes: 1 addition & 1 deletion
2
.../backend/src/app/config/settings/input-connections/iconnection/iconnection.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
Empty file.
35 changes: 35 additions & 0 deletions
35
mythtv/html/backend/src/app/config/settings/system-events/system-events.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,35 @@ | ||
<form class="ml-3 mr-3" name="eventsform" #eventsform="ngForm"> | ||
|
||
<p-card class="m-5"> | ||
<ng-template pTemplate="title"> | ||
{{ 'settings.sysevents.title' | translate }} | ||
</ng-template> | ||
<ng-template pTemplate="subtitle"> | ||
</ng-template> | ||
<ng-template pTemplate="content"> | ||
<div class="grid"> | ||
<div class="mb-4 w-full" *ngFor="let event of events; index as ix; first as isFirst"> | ||
<div class="form-group field"> | ||
<label for="{{event.Key}}" class="block">{{ event.LocalizedName }}</label> | ||
<input pInputText id="{{event.Key}}" [(ngModel)]="event.Value" name="{{event.Key}}" | ||
class="mb-2 form-control w-full" /> | ||
</div> | ||
</div> | ||
</div> | ||
</ng-template> | ||
|
||
<ng-template pTemplate="footer"> | ||
<div class="grid nogutter"> | ||
<div class="col-12"> | ||
<p-message *ngIf="successCount > 0 && successCount == expectedCount && errorCount == 0 && !eventsform.dirty" | ||
severity="success" text="{{ 'common.savesuccess' | translate }}"></p-message> | ||
<p-message *ngIf="this.errorCount > 0" severity="error" | ||
text="{{ 'common.networkfail' | translate }}"></p-message> | ||
</div> | ||
<p-button class="col pr-1" label="{{'common.save' | translate}}" icon="pi pi-save" iconPos="left" | ||
(onClick)="saveForm(); eventsform.form.markAsPristine()" | ||
[disabled]="(!eventsform.dirty)"></p-button> | ||
</div> | ||
</ng-template> | ||
</p-card> | ||
</form> |
25 changes: 25 additions & 0 deletions
25
mythtv/html/backend/src/app/config/settings/system-events/system-events.component.spec.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,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { SystemEventsComponent } from './system-events.component'; | ||
|
||
describe('SystemEventsComponent', () => { | ||
let component: SystemEventsComponent; | ||
let fixture: ComponentFixture<SystemEventsComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ SystemEventsComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SystemEventsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
108 changes: 108 additions & 0 deletions
108
mythtv/html/backend/src/app/config/settings/system-events/system-events.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,108 @@ | ||
import { Component, HostListener, OnInit, ViewChild } from '@angular/core'; | ||
import { NgForm } from '@angular/forms'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { Observable, of } from 'rxjs'; | ||
import { ConfigService } from 'src/app/services/config.service'; | ||
import { SystemEvent, SystemEventList } from 'src/app/services/interfaces/config.interface'; | ||
import { MythService } from 'src/app/services/myth.service'; | ||
import { SetupService } from 'src/app/services/setup.service'; | ||
|
||
@Component({ | ||
selector: 'app-system-events', | ||
templateUrl: './system-events.component.html', | ||
styleUrls: ['./system-events.component.css'] | ||
}) | ||
|
||
export class SystemEventsComponent implements OnInit { | ||
|
||
@ViewChild("eventsform") currentForm!: NgForm; | ||
eventList!: SystemEventList; | ||
|
||
events: SystemEvent[] = []; | ||
|
||
successCount = 0; | ||
errorCount = 0; | ||
expectedCount = 0; | ||
|
||
warningText = 'settings.warning'; | ||
|
||
// See mythdb.cpp. This value is used to delete a setting | ||
kClearSettingValue = "<clear_setting_value>"; | ||
|
||
constructor(private configService: ConfigService, private translate: TranslateService, | ||
private setupService: SetupService, private mythService: MythService) { | ||
this.configService.GetSystemEvents().subscribe(data => { | ||
this.eventList = data; | ||
this.events = data.SystemEventList.SystemEvents; | ||
}); | ||
this.translate.get(this.warningText).subscribe(data => { | ||
this.warningText = data | ||
}); | ||
} | ||
|
||
ngOnInit(): void { | ||
} | ||
|
||
jqbObserver = { | ||
next: (x: any) => { | ||
if (x.bool) | ||
this.successCount++; | ||
else { | ||
this.errorCount++; | ||
if (this.currentForm) | ||
this.currentForm.form.markAsDirty(); | ||
} | ||
}, | ||
error: (err: any) => { | ||
console.error(err); | ||
this.errorCount++; | ||
if (this.currentForm) | ||
this.currentForm.form.markAsDirty(); | ||
}, | ||
}; | ||
|
||
saveForm() { | ||
this.successCount = 0; | ||
this.errorCount = 0; | ||
this.expectedCount = 0; | ||
const hostName = this.setupService.getHostName(); | ||
|
||
this.events.forEach(entry => { | ||
let value = entry.Value.trim(); | ||
if (value) | ||
// value = this.kClearSettingValue; | ||
this.mythService.PutSetting({ | ||
HostName: hostName, Key: entry.Key, | ||
Value: value | ||
}).subscribe(this.jqbObserver); | ||
else | ||
this.mythService.DeleteSetting({ | ||
HostName: hostName, Key: entry.Key | ||
}).subscribe(this.jqbObserver); | ||
this.expectedCount++; | ||
}); | ||
|
||
} | ||
|
||
confirm(message?: string): Observable<boolean> { | ||
const confirmation = window.confirm(message); | ||
return of(confirmation); | ||
}; | ||
|
||
canDeactivate(): Observable<boolean> | boolean { | ||
if (this.currentForm && this.currentForm.dirty) | ||
return this.confirm(this.warningText); | ||
return true; | ||
} | ||
|
||
@HostListener('window:beforeunload', ['$event']) | ||
onWindowClose(event: any): void { | ||
if (this.currentForm && this.currentForm.dirty) { | ||
event.preventDefault(); | ||
event.returnValue = false; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
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
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