dynamicsmobile
Version:
Allows development of off-line mobile and web business apps over the Dynamics Mobile platform. More info on https://www.dynamicsmobile.com
124 lines (123 loc) • 5.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigurationService = void 0;
const tslib_1 = require("tslib");
const application_context_service_1 = require("./application-context-service");
const dms_platform_bridge_factory_1 = require("../platform/dms-platform-bridge-factory");
const injectable_1 = require("../ioc/injectable");
/*
* Provides methods for persisting of key-value pairs for a longer period
* May be used to store simple data, which must survive longer, but still not vital or sensitive for the
* system operations.
* DO NOT it to store sensitive data like passwords, api-keys , etc
*/
let ConfigurationService = exports.ConfigurationService = class ConfigurationService {
constructor(dms) {
this.dms = dms;
this.settings = {};
}
synchronize() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return;
});
}
retreiveSettings() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
this.settings = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("retreiveSettings", undefined);
if (!this.settings)
this.settings = {};
}
catch (err) {
if (!this.settings)
this.settings = {};
}
});
}
saveSettings() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("saveAllSettings", this.settings);
});
}
/**
* Returns the value of a setting by given name
* @param settingName - string , name of the setting
* @returns string or null
*
*/
getSetting(settingName) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return this.settings[settingName.toUpperCase()];
});
}
/**
* persists given value under given name
* the value can be retreived back by using method getSetting
* @param settingName - string , name of the setting
* @param value - string value to be persisted
* @returns string or null
*
*/
setSetting(settingName, value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (settingName.indexOf('$TSK_') >= 0)
throw new Error('$TSK_ literal is not allowed in settingName');
var _value = (value ? (value.replace(/'/g, '').replace(/"/, '')) : undefined);
this.settings[settingName.toUpperCase()] = (_value ? _value.toString() : undefined);
yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("setSetting", { settingName: settingName, value: (_value ? _value.toString() : undefined) });
yield this.saveSettings();
});
}
/**
* Used internally and must not be used directly from user code
* The method is used internally by the navigation related Returns current navigation state
*/
getNavigationState() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var s = yield this.getSetting("$dmscurrentnavstate");
if (s && typeof s == "string")
return JSON.parse(window.atob(s));
else
return { LastTaskId: null, LastStepId: null };
});
}
/**
* Used internally and must not be used directly from user code
* The method is used internally by the navigation related Returns current navigation state
*/
setNavigationState(state) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var stateString = window.btoa(JSON.stringify(state));
yield this.setSetting("$dmscurrentnavstate", stateString);
});
}
getAllSettings() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var settingsNotAllowedInUserInterface = ["$DMSCURRENTNAVSTATE", "COMPANY", "DMSAPIKEY"];
var me = this;
var settingsAsArray = [];
var keys = Object.getOwnPropertyNames(this.settings);
keys.forEach(key => {
if (key.indexOf('$') < 0 && key.indexOf('$TSK_') < 0 && settingsNotAllowedInUserInterface.indexOf(key) < 0)
settingsAsArray.push({ key: key, value: me.settings[key] });
});
return settingsAsArray;
});
}
getAllowedTasks() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var settingsAsArray = [];
var keys = Object.getOwnPropertyNames(this.settings);
keys.forEach(key => {
if (key.indexOf('$TSK_') >= 0)
settingsAsArray.push({ id: key.substr(5), allowed: true });
});
return settingsAsArray;
});
}
};
exports.ConfigurationService = ConfigurationService = tslib_1.__decorate([
(0, injectable_1.Injectable)({ singleton: true }),
tslib_1.__metadata("design:paramtypes", [application_context_service_1.DmsApplicationService])
], ConfigurationService);
//# sourceMappingURL=configuration-service.js.map