Skip to content

Commit

Permalink
web-app setup: Fix error withlosing backend name in various pages
Browse files Browse the repository at this point in the history
A timing issue caused the backend name to sometimes be empty when the page was
being set up.
  • Loading branch information
bennettpeter committed Jun 1, 2023
1 parent 5108b8c commit 4af4024
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 86 deletions.
Expand Up @@ -14,6 +14,7 @@ export class BackendWakeupComponent implements OnInit, AfterViewInit {
@ViewChild("backendwakeup")
currentForm!: NgForm;

hostName = '';
successCount = 0;
errorCount = 0;
WOLbackendReconnectWaitTime = 0;
Expand All @@ -33,8 +34,18 @@ export class BackendWakeupComponent implements OnInit, AfterViewInit {
this.setupService.setCurrentForm(this.currentForm);
}

getBackendWake(){
const hostName = this.setupService.getHostName();
getBackendWake() {
this.mythService.GetHostName().subscribe({
next: data => {
this.hostName = data.String;
this.getSettings();
},
error: () => this.errorCount++
})

}

getSettings() {
this.mythService.GetSetting({ HostName: '_GLOBAL_', Key: "WOLbackendReconnectWaitTime", Default: "0" })
.subscribe({
next: data => this.WOLbackendReconnectWaitTime = Number(data.String),
Expand All @@ -50,19 +61,20 @@ export class BackendWakeupComponent implements OnInit, AfterViewInit {
next: data => this.WOLbackendCommand = data.String,
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "SleepCommand", Default: "" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "SleepCommand", Default: "" })
.subscribe({
next: data => this.SleepCommand = data.String,
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "WakeUpCommand", Default: "" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "WakeUpCommand", Default: "" })
.subscribe({
next: data => this.WakeUpCommand = data.String,
error: () => this.errorCount++
});

}


bewObserver = {
next: (x: any) => {
if (x.bool)
Expand All @@ -84,7 +96,6 @@ export class BackendWakeupComponent implements OnInit, AfterViewInit {
saveForm() {
this.successCount = 0;
this.errorCount = 0;
const hostName = this.setupService.getHostName();
this.mythService.PutSetting({
HostName: '_GLOBAL_', Key: "WOLbackendReconnectWaitTime",
Value: String(this.WOLbackendReconnectWaitTime)
Expand All @@ -98,11 +109,11 @@ export class BackendWakeupComponent implements OnInit, AfterViewInit {
Value: this.WOLbackendCommand
}).subscribe(this.bewObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "SleepCommand",
HostName: this.hostName, Key: "SleepCommand",
Value: this.SleepCommand
}).subscribe(this.bewObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "WakeUpCommand",
HostName: this.hostName, Key: "WakeUpCommand",
Value: this.WakeUpCommand
}).subscribe(this.bewObserver);
}
Expand Down
Expand Up @@ -25,7 +25,11 @@ export class HostAddressComponent implements OnInit, AfterViewInit {
private configService: ConfigService) {

this.m_HostAddressData = this.setupService.getHostAddressData();
configService.GetIPAddresses("All").subscribe(result => this.m_IPsAll = result.IPAddresses);
// Set this for 500 msgit log later to avoid messages that value changed after checked
// (pristine) and also avoid form being set as dirty.
setTimeout(() =>
configService.GetIPAddresses("All").subscribe(result => this.m_IPsAll = result.IPAddresses)
, 500)
configService.GetIPAddresses("IPv4").subscribe(result => this.m_IPsV4 = result.IPAddresses);
configService.GetIPAddresses("IPv6").subscribe(result => this.m_IPsV6 = result.IPAddresses);
}
Expand Down
Expand Up @@ -29,6 +29,7 @@ export class JobqueueBackendComponent implements OnInit, AfterViewInit {

successCount = 0;
errorCount = 0;
hostName = '';
JobQueueMaxSimultaneousJobs = 1;
JobQueueCheckFrequency = 60;
JobQueueWindowStart = new Date(0);
Expand Down Expand Up @@ -86,75 +87,84 @@ export class JobqueueBackendComponent implements OnInit, AfterViewInit {
this.errorCount = 0
this.setupService.parseTime(this.JobQueueWindowStart, "00:00");
this.setupService.parseTime(this.JobQueueWindowEnd, "23:59");
const hostName = this.setupService.getHostName();
this.mythService.GetHostName().subscribe({
next: data => {
this.hostName = data.String;
this.getSettings();
},
error: () => this.errorCount++
})

this.mythService.GetSetting({ HostName: hostName, Key: "JobQueueMaxSimultaneousJobs", Default: "1" })
}

getSettings() {
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobQueueMaxSimultaneousJobs", Default: "1" })
.subscribe({
next: data => this.JobQueueMaxSimultaneousJobs = Number(data.String),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobQueueCheckFrequency", Default: "60" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobQueueCheckFrequency", Default: "60" })
.subscribe({
next: data => this.JobQueueCheckFrequency = Number(data.String),
error: () => this.errorCount++
});
this.JobQueueWindowStartHT$ = this.mythService.GetSetting({
HostName: hostName, Key: "JobQueueWindowStart", Default: "00:00"
HostName: this.hostName, Key: "JobQueueWindowStart", Default: "00:00"
});
this.JobQueueWindowStartHT$
.subscribe({
next: data => this.setupService.parseTime(this.JobQueueWindowStart, data.String),
error: () => this.errorCount++
});
this.JobQueueWindowEndHT$ = this.mythService.GetSetting({
HostName: hostName, Key: "JobQueueWindowEnd", Default: "23:59"
HostName: this.hostName, Key: "JobQueueWindowEnd", Default: "23:59"
});
this.JobQueueWindowEndHT$
.subscribe({
next: data => this.setupService.parseTime(this.JobQueueWindowEnd, data.String),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobQueueCPU", Default: "0" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobQueueCPU", Default: "0" })
.subscribe({
next: data => this.JobQueueCPU = data.String,
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobAllowMetadata", Default: "1" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobAllowMetadata", Default: "1" })
.subscribe({
next: data => this.JobAllowMetadata = (data.String == '1'),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobAllowCommFlag", Default: "1" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobAllowCommFlag", Default: "1" })
.subscribe({
next: data => this.JobAllowCommFlag = (data.String == '1'),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobAllowTranscode", Default: "1" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobAllowTranscode", Default: "1" })
.subscribe({
next: data => this.JobAllowTranscode = (data.String == '1'),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobAllowPreview", Default: "1" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobAllowPreview", Default: "1" })
.subscribe({
next: data => this.JobAllowPreview = (data.String == '1'),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobAllowUserJob1", Default: "0" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobAllowUserJob1", Default: "0" })
.subscribe({
next: data => this.JobAllowUserJob1 = (data.String == '1'),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobAllowUserJob2", Default: "0" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobAllowUserJob2", Default: "0" })
.subscribe({
next: data => this.JobAllowUserJob2 = (data.String == '1'),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobAllowUserJob3", Default: "0" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobAllowUserJob3", Default: "0" })
.subscribe({
next: data => this.JobAllowUserJob3 = (data.String == '1'),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "JobAllowUserJob4", Default: "0" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "JobAllowUserJob4", Default: "0" })
.subscribe({
next: data => this.JobAllowUserJob4 = (data.String == '1'),
error: () => this.errorCount++
Expand Down Expand Up @@ -182,58 +192,57 @@ export class JobqueueBackendComponent implements OnInit, AfterViewInit {
saveForm() {
this.successCount = 0;
this.errorCount = 0;
const hostName = this.setupService.getHostName();

this.mythService.PutSetting({
HostName: hostName, Key: "JobQueueMaxSimultaneousJobs",
HostName: this.hostName, Key: "JobQueueMaxSimultaneousJobs",
Value: String(this.JobQueueMaxSimultaneousJobs)
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobQueueCheckFrequency",
HostName: this.hostName, Key: "JobQueueCheckFrequency",
Value: String(this.JobQueueCheckFrequency)
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobQueueWindowStart",
HostName: this.hostName, Key: "JobQueueWindowStart",
Value: this.setupService.formatTime(this.JobQueueWindowStart)
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobQueueWindowEnd",
HostName: this.hostName, Key: "JobQueueWindowEnd",
Value: this.setupService.formatTime(this.JobQueueWindowEnd)
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobQueueCPU",
HostName: this.hostName, Key: "JobQueueCPU",
Value: this.JobQueueCPU
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobAllowMetadata",
HostName: this.hostName, Key: "JobAllowMetadata",
Value: this.JobAllowMetadata ? "1" : "0"
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobAllowCommFlag",
HostName: this.hostName, Key: "JobAllowCommFlag",
Value: this.JobAllowCommFlag ? "1" : "0"
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobAllowTranscode",
HostName: this.hostName, Key: "JobAllowTranscode",
Value: this.JobAllowTranscode ? "1" : "0"
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobAllowPreview",
HostName: this.hostName, Key: "JobAllowPreview",
Value: this.JobAllowPreview ? "1" : "0"
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobAllowUserJob1",
HostName: this.hostName, Key: "JobAllowUserJob1",
Value: this.JobAllowUserJob1 ? "1" : "0"
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobAllowUserJob2",
HostName: this.hostName, Key: "JobAllowUserJob2",
Value: this.JobAllowUserJob2 ? "1" : "0"
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobAllowUserJob3",
HostName: this.hostName, Key: "JobAllowUserJob3",
Value: this.JobAllowUserJob3 ? "1" : "0"
}).subscribe(this.jqbObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "JobAllowUserJob4",
HostName: this.hostName, Key: "JobAllowUserJob4",
Value: this.JobAllowUserJob4 ? "1" : "0"
}).subscribe(this.jqbObserver);

Expand Down
Expand Up @@ -25,7 +25,7 @@ export class MiscSettingsComponent implements OnInit, AfterViewInit {
MiscStatusScript = "";
DisableAutomaticBackup = false;
DisableFirewireReset = false;

hostName = '';

soptions = [
{ name: 'settings.misc.sg_balfree', code: "BalancedFreeSpace" },
Expand All @@ -49,13 +49,17 @@ export class MiscSettingsComponent implements OnInit, AfterViewInit {
translate.get(this.soptions[3].name).subscribe(data => this.soptions[3].name = data);
translate.get(this.uoptions[0].name).subscribe(data => this.uoptions[0].name = data);
translate.get(this.uoptions[1].name).subscribe(data => this.uoptions[1].name = data);
this.getMiscellaneousData();
this.mythService.GetHostName().subscribe({
next: data => {
this.hostName = data.String;
this.getMiscellaneousData();
},
error: () => this.errorCount++
})
}

getMiscellaneousData() {

const hostName = this.setupService.getHostName();

this.mythService.GetSetting({ HostName: '_GLOBAL_', Key: "MasterBackendOverride", Default: "0" })
.subscribe({
next: data => this.MasterBackendOverride = (data.String == "1"),
Expand All @@ -66,7 +70,7 @@ export class MiscSettingsComponent implements OnInit, AfterViewInit {
next: data => this.DeletesFollowLinks = (data.String == "1"),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "TruncateDeletesSlowly", Default: "0" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "TruncateDeletesSlowly", Default: "0" })
.subscribe({
next: data => this.TruncateDeletesSlowly = (data.String == "1"),
error: () => this.errorCount++
Expand All @@ -86,7 +90,7 @@ export class MiscSettingsComponent implements OnInit, AfterViewInit {
next: data => this.UPNPWmpSource = data.String,
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "MiscStatusScript", Default: "" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "MiscStatusScript", Default: "" })
.subscribe({
next: data => this.MiscStatusScript = data.String,
error: () => this.errorCount++
Expand All @@ -96,7 +100,7 @@ export class MiscSettingsComponent implements OnInit, AfterViewInit {
next: data => this.DisableAutomaticBackup = (data.String == "1"),
error: () => this.errorCount++
});
this.mythService.GetSetting({ HostName: hostName, Key: "DisableFirewireReset", Default: "0" })
this.mythService.GetSetting({ HostName: this.hostName, Key: "DisableFirewireReset", Default: "0" })
.subscribe({
next: data => this.DisableFirewireReset = (data.String == "1"),
error: () => this.errorCount++
Expand Down Expand Up @@ -135,8 +139,6 @@ export class MiscSettingsComponent implements OnInit, AfterViewInit {
this.successCount = 0;
this.errorCount = 0;

const hostName = this.setupService.getHostName();

this.mythService.PutSetting({
HostName: '_GLOBAL_', Key: "MasterBackendOverride",
Value: this.MasterBackendOverride ? "1" : "0"
Expand All @@ -148,7 +150,7 @@ export class MiscSettingsComponent implements OnInit, AfterViewInit {
})
.subscribe(this.miscObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "TruncateDeletesSlowly",
HostName: this.hostName, Key: "TruncateDeletesSlowly",
Value: this.TruncateDeletesSlowly ? "1" : "0"
})
.subscribe(this.miscObserver);
Expand All @@ -168,7 +170,7 @@ export class MiscSettingsComponent implements OnInit, AfterViewInit {
})
.subscribe(this.miscObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "MiscStatusScript",
HostName: this.hostName, Key: "MiscStatusScript",
Value: this.MiscStatusScript
})
.subscribe(this.miscObserver);
Expand All @@ -178,7 +180,7 @@ export class MiscSettingsComponent implements OnInit, AfterViewInit {
})
.subscribe(this.miscObserver);
this.mythService.PutSetting({
HostName: hostName, Key: "DisableFirewireReset",
HostName: this.hostName, Key: "DisableFirewireReset",
Value: this.DisableFirewireReset ? "1" : "0"
})
.subscribe(this.miscObserver);
Expand Down

0 comments on commit 4af4024

Please sign in to comment.