-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
on settings save, return the new settings.
update the frontend to persist settings to the database. Using ScrutinyConfigService instead of TreoConfigService. Using snake case settings in frontend. Make sure we're using AppConfig type where possible.
- Loading branch information
Showing
16 changed files
with
259 additions
and
89 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
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
33 changes: 33 additions & 0 deletions
33
webapp/frontend/src/app/core/config/scrutiny-config.module.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,33 @@ | ||
import {ModuleWithProviders, NgModule} from '@angular/core'; | ||
import {ScrutinyConfigService} from 'app/core/config/scrutiny-config.service'; | ||
import {TREO_APP_CONFIG} from '@treo/services/config/config.constants'; | ||
|
||
@NgModule() | ||
export class ScrutinyConfigModule { | ||
/** | ||
* Constructor | ||
* | ||
* @param {ScrutinyConfigService} _scrutinyConfigService | ||
*/ | ||
constructor( | ||
private _scrutinyConfigService: ScrutinyConfigService | ||
) { | ||
} | ||
|
||
/** | ||
* forRoot method for setting user configuration | ||
* | ||
* @param config | ||
*/ | ||
static forRoot(config: any): ModuleWithProviders { | ||
return { | ||
ngModule: ScrutinyConfigModule, | ||
providers: [ | ||
{ | ||
provide: TREO_APP_CONFIG, | ||
useValue: config | ||
} | ||
] | ||
}; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
webapp/frontend/src/app/core/config/scrutiny-config.service.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,16 @@ | ||
import {TestBed} from '@angular/core/testing'; | ||
|
||
import {ScrutinyConfigService} from './scrutiny-config.service'; | ||
|
||
describe('ScrutinyConfigService', () => { | ||
let service: ScrutinyConfigService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(ScrutinyConfigService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
webapp/frontend/src/app/core/config/scrutiny-config.service.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,84 @@ | ||
import {Inject, Injectable} from '@angular/core'; | ||
import {HttpClient} from '@angular/common/http'; | ||
import {TREO_APP_CONFIG} from '@treo/services/config/config.constants'; | ||
import {BehaviorSubject, Observable} from 'rxjs'; | ||
import {getBasePath} from '../../app.routing'; | ||
import {map, tap} from 'rxjs/operators'; | ||
import {AppConfig} from './app.config'; | ||
import {merge} from 'lodash'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ScrutinyConfigService { | ||
// Private | ||
private _config: BehaviorSubject<AppConfig>; | ||
private _defaultConfig: AppConfig; | ||
|
||
constructor( | ||
private _httpClient: HttpClient, | ||
@Inject(TREO_APP_CONFIG) defaultConfig: AppConfig | ||
) { | ||
// Set the private defaults | ||
this._defaultConfig = defaultConfig | ||
this._config = new BehaviorSubject(null); | ||
} | ||
|
||
|
||
// ----------------------------------------------------------------------------------------------------- | ||
// @ Accessors | ||
// ----------------------------------------------------------------------------------------------------- | ||
|
||
/** | ||
* Setter & getter for config | ||
*/ | ||
set config(value: AppConfig) { | ||
// get the current config, merge the new values, and then submit. (setTheme only sets a single key, not the whole obj) | ||
const mergedSettings = merge({}, this._config.getValue(), value); | ||
|
||
console.log('saving settings...', mergedSettings) | ||
this._httpClient.post(getBasePath() + '/api/settings', mergedSettings).pipe( | ||
map((response: any) => { | ||
console.log('settings resp') | ||
return response.settings | ||
}), | ||
tap((settings: AppConfig) => { | ||
this._config.next(settings); | ||
return settings | ||
}) | ||
).subscribe(resp => { | ||
console.log('updated settings', resp) | ||
}) | ||
} | ||
|
||
get config$(): Observable<AppConfig> { | ||
if (this._config.getValue()) { | ||
console.log('using cached settings:', this._config.getValue()) | ||
return this._config.asObservable() | ||
} else { | ||
console.log('retrieving settings') | ||
return this._httpClient.get(getBasePath() + '/api/settings').pipe( | ||
map((response: any) => { | ||
return response.settings | ||
}), | ||
tap((settings: AppConfig) => { | ||
this._config.next(settings); | ||
return this._config.asObservable() | ||
}) | ||
); | ||
} | ||
|
||
} | ||
|
||
// ----------------------------------------------------------------------------------------------------- | ||
// @ Public methods | ||
// ----------------------------------------------------------------------------------------------------- | ||
|
||
/** | ||
* Resets the config to the default | ||
*/ | ||
reset(): void { | ||
// Set the config | ||
this.config = this._defaultConfig | ||
} | ||
} |
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
Oops, something went wrong.