fix: Add restart to settings & better disabled state (#493)

* fix: Add restart to settings & better disabled state

* fix: Correct function call and better handling

* fix: Add to network restart and form dirty check
This commit is contained in:
mrv777 2024-11-22 09:30:38 -06:00 committed by GitHub
parent 4100402990
commit c745cbb0e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 3 deletions

View File

@ -198,11 +198,15 @@
</div>
<div class="mt-2">
<button pButton [disabled]="form.invalid" (click)="updateSystem()"
<button pButton [disabled]="!form.dirty || form.invalid" (click)="updateSystem()"
class="btn btn-primary mr-2">Save</button>
<b style="line-height: 34px;">You must restart this device after saving for changes to take effect.</b>
</div>
<div class="mt-2">
<button pButton [disabled]="!savedChanges" (click)="restart()">Restart</button>
</div>
</form>
</ng-container>

View File

@ -19,7 +19,7 @@ export class EditComponent implements OnInit {
public firmwareUpdateProgress: number | null = null;
public websiteUpdateProgress: number | null = null;
public savedChanges: boolean = false;
public devToolsOpen: boolean = false;
public eASICModel = eASICModel;
public ASICModel!: eASICModel;
@ -205,9 +205,11 @@ export class EditComponent implements OnInit {
.subscribe({
next: () => {
this.toastr.success('Success!', 'Saved.');
this.savedChanges = true;
},
error: (err: HttpErrorResponse) => {
this.toastr.error('Error.', `Could not save. ${err.message}`);
this.savedChanges = false;
}
});
}
@ -232,4 +234,17 @@ export class EditComponent implements OnInit {
this.showFallbackStratumPassword = !this.showFallbackStratumPassword;
}
public restart() {
this.systemService.restart()
.pipe(this.loadingService.lockUIUntilComplete())
.subscribe({
next: () => {
this.toastr.success('Success!', 'Bitaxe restarted');
},
error: (err: HttpErrorResponse) => {
this.toastr.error('Error', `Could not restart. ${err.message}`);
}
});
}
}

View File

@ -26,9 +26,13 @@
</div>
<div class="mt-2">
<button pButton [disabled]="form.invalid" (click)="updateSystem()"
<button pButton [disabled]="!form.dirty || form.invalid" (click)="updateSystem()"
class="btn btn-primary mr-2">Save</button>
<b style="line-height: 34px;">You must restart this device after saving for changes to take effect.</b>
</div>
<div class="mt-2">
<button pButton [disabled]="!savedChanges" (click)="restart()">Restart</button>
</div>
</form>
</ng-container>

View File

@ -14,6 +14,7 @@ import { SystemService } from 'src/app/services/system.service';
export class NetworkEditComponent implements OnInit {
public form!: FormGroup;
public savedChanges: boolean = false;
@Input() uri = '';
@ -56,9 +57,11 @@ export class NetworkEditComponent implements OnInit {
.subscribe({
next: () => {
this.toastr.success('Success!', 'Saved.');
this.savedChanges = true;
},
error: (err: HttpErrorResponse) => {
this.toastr.error('Error.', `Could not save. ${err.message}`);
this.savedChanges = false;
}
});
}
@ -67,4 +70,17 @@ export class NetworkEditComponent implements OnInit {
toggleWifiPasswordVisibility() {
this.showWifiPassword = !this.showWifiPassword;
}
public restart() {
this.systemService.restart()
.pipe(this.loadingService.lockUIUntilComplete())
.subscribe({
next: () => {
this.toastr.success('Success!', 'Bitaxe restarted');
},
error: (err: HttpErrorResponse) => {
this.toastr.error('Error', `Could not restart. ${err.message}`);
}
});
}
}