fix: update core and apply stricter tslint rules

This commit is contained in:
Michel Jonathan Schmitz
2019-07-10 12:38:29 +02:00
parent 03c317430a
commit 911492d064
67 changed files with 1291 additions and 507 deletions

View File

@@ -17,6 +17,9 @@ import {DataModule} from '../data/data.module';
import {StorageModule} from '../storage/storage.module';
import {ConfigProvider} from './config.provider';
/**
* TODO
*/
@NgModule({
imports: [
StorageModule,

View File

@@ -13,7 +13,7 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {TestBed} from '@angular/core/testing';
import {SCIndexResponse, SCThingOriginType, SCThingType} from '@openstapps/core';
import {SCIndexResponse, SCThingOriginType, SCThingType, SCSettingInputType} from '@openstapps/core';
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
import {StorageProvider} from '../storage/storage.provider';
import {ConfigProvider, STORAGE_KEY_CONFIG} from './config.provider';
@@ -207,10 +207,8 @@ const sampleIndexResponse: SCIndexResponse = {
settings: [
{
categories: ['credentials'],
input: {
defaultValue: '',
inputType: 'text',
},
defaultValue: '',
inputType: SCSettingInputType.Text,
name: 'username',
order: 0,
origin: {

View File

@@ -39,12 +39,25 @@ export const STORAGE_KEY_CONFIG = 'stapps.config';
*/
@Injectable()
export class ConfigProvider {
/**
* TODO
*/
client: Client;
/**
* TODO
*/
config: SCIndexResponse;
initialised: boolean = false;
logger: Logger = new Logger();
/**
* TODO
*/
initialised = false;
constructor(private storageProvider: StorageProvider, swHttpClient: StAppsWebHttpClient) {
/**
*
* @param storageProvider TODO
* @param swHttpClient TODO
*/
constructor(private readonly storageProvider: StorageProvider, swHttpClient: StAppsWebHttpClient) {
this.client = new Client(swHttpClient, environment.backend_url, environment.backend_version);
}
@@ -77,9 +90,8 @@ export class ConfigProvider {
}
if (typeof this.config.app[attribute] !== 'undefined') {
return this.config.app[attribute];
} else {
throw new ConfigValueNotAvailable(attribute);
}
throw new ConfigValueNotAvailable(attribute);
}
/**
@@ -96,10 +108,10 @@ export class ConfigProvider {
try {
this.config = await this.loadLocal();
this.initialised = true;
this.logger.log(`initialised configuration from storage: ${JSON.stringify(this.config)}`);
Logger.log(`initialised configuration from storage: ${JSON.stringify(this.config)}`);
if (this.config.backend.SCVersion !== environment.backend_version) {
loadError = new WrongConfigVersionInStorage(environment.backend_version, this.config.backend.SCVersion);
this.logger.warn(loadError);
Logger.warn(loadError);
}
} catch (error) {
loadError = error;
@@ -109,16 +121,18 @@ export class ConfigProvider {
const fetchedConfig: SCIndexResponse = await this.fetch();
await this.set(fetchedConfig);
this.initialised = true;
this.logger.log(`initialised configuration from remote: ${JSON.stringify(this.config)}`);
Logger.log(`initialised configuration from remote: ${JSON.stringify(this.config)}`);
} catch (error) {
fetchError = error;
}
// check for occurred errors and throw them
if (typeof loadError !== 'undefined' && typeof fetchError !== 'undefined') {
throw new ConfigInitError();
} else if (typeof loadError !== 'undefined') {
}
if (typeof loadError !== 'undefined') {
throw loadError;
} else if (typeof fetchError !== 'undefined') {
}
if (typeof fetchError !== 'undefined') {
throw fetchError;
}
}
@@ -132,7 +146,7 @@ export class ConfigProvider {
await this.storageProvider.init();
// get local configuration
if (await this.storageProvider.has(STORAGE_KEY_CONFIG)) {
return await this.storageProvider.get<SCIndexResponse>(STORAGE_KEY_CONFIG);
return this.storageProvider.get<SCIndexResponse>(STORAGE_KEY_CONFIG);
}
throw new SavedConfigNotAvailable();
}