feat: add support for runtime server url changes (#1271)

Fixes: #786
Fixes: #1229
This commit is contained in:
Karan Takalkar
2020-11-19 12:03:12 +05:30
committed by GitHub
parent 5f90bc00bd
commit 8271eb00ac
14 changed files with 145 additions and 11 deletions
@@ -0,0 +1,8 @@
<mat-form-field id="server-selector">
<mat-label>Server</mat-label>
<mat-select [formControl]="serverSelector">
<mat-option *ngFor="let server of servers" [value]="server">
{{ server }}
</mat-option>
</mat-select>
</mat-form-field>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ServerSelectorComponent } from './server-selector.component';
describe('ServerSelectorComponent', () => {
let component: ServerSelectorComponent;
let fixture: ComponentFixture<ServerSelectorComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ServerSelectorComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ServerSelectorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,45 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
/** Custom Services */
import { SettingsService } from 'app/settings/settings.service';
/**
* Server Selector Component
*/
@Component({
selector: 'mifosx-server-selector',
templateUrl: './server-selector.component.html',
styleUrls: ['./server-selector.component.scss']
})
export class ServerSelectorComponent implements OnInit {
/** Server Settings. */
servers: string[];
/** Server Setting */
serverSelector = new FormControl('');
/**
* @param {SettingsService} settingsService Settings Service
*/
constructor(private settingsService: SettingsService) { }
ngOnInit(): void {
this.servers = this.settingsService.servers;
this.serverSelector.patchValue(this.settingsService.server);
this.buildDependencies();
}
/**
* Subscribe to value changes.
*/
buildDependencies() {
this.serverSelector.valueChanges.subscribe((url: string) => {
this.settingsService.setServer(url);
window.location.reload(); // refreshes the environment.ts.
});
}
}