feat: add support for runtime server url changes (#1271)
Fixes: #786 Fixes: #1229
This commit is contained in:
@@ -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.
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import { ErrorDialogComponent } from './error-dialog/error-dialog.component';
|
||||
import { NotificationsTrayComponent } from './notifications-tray/notifications-tray.component';
|
||||
import { SearchToolComponent } from './search-tool/search-tool.component';
|
||||
import { KeyboardShortcutsDialogComponent } from './keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.component';
|
||||
import { ServerSelectorComponent } from './server-selector/server-selector.component';
|
||||
|
||||
/** Custom Modules */
|
||||
import { IconsModule } from './icons.module';
|
||||
@@ -53,12 +54,14 @@ import { MaterialModule } from './material.module';
|
||||
KeyboardShortcutsDialogComponent,
|
||||
ErrorDialogComponent,
|
||||
NotificationsTrayComponent,
|
||||
SearchToolComponent
|
||||
SearchToolComponent,
|
||||
ServerSelectorComponent
|
||||
],
|
||||
exports: [
|
||||
FileUploadComponent,
|
||||
FooterComponent,
|
||||
LanguageSelectorComponent,
|
||||
ServerSelectorComponent,
|
||||
ThemePickerComponent,
|
||||
NotificationsTrayComponent,
|
||||
SearchToolComponent,
|
||||
|
||||
Reference in New Issue
Block a user