Load config.json at runtime
This commit is contained in:
parent
01c0eb503f
commit
589c52f4cd
11 changed files with 71 additions and 39 deletions
|
|
@ -1,12 +1,11 @@
|
|||
import { CleanInsights, ConsentRequestUi } from 'clean-insights-sdk';
|
||||
import config from "../assets/config";
|
||||
|
||||
export default {
|
||||
install(Vue) {
|
||||
|
||||
class RequestUi extends ConsentRequestUi {
|
||||
showForCampaign(campaignId, campaign, complete) {
|
||||
const period = campaign.nextTotalMeasurementPeriod
|
||||
const period = campaign.nextTotalMeasurementPeriod
|
||||
if (!period) {
|
||||
return ''
|
||||
}
|
||||
|
|
@ -27,13 +26,16 @@ export default {
|
|||
}
|
||||
},
|
||||
created() {
|
||||
const analytics = config.analytics || {};
|
||||
if (analytics.enabled && analytics.config) {
|
||||
this.ci = new CleanInsights(analytics.config);
|
||||
this.$config.promise.then(function (config) {
|
||||
const analytics = config.analytics || {};
|
||||
if (analytics.enabled && analytics.config) {
|
||||
this.ci = new CleanInsights(analytics.config);
|
||||
|
||||
// Get name of first campaign in the config.
|
||||
this.campaignId = Object.keys(analytics.config.campaigns || { invalid: {} })[0];
|
||||
}
|
||||
// Get name of first campaign in the config.
|
||||
this.campaignId = Object.keys(analytics.config.campaigns || { invalid: {} })[0];
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
event(category, action) {
|
||||
|
|
|
|||
18
src/services/config.service.js
Normal file
18
src/services/config.service.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
export default {
|
||||
install(Vue) {
|
||||
var config = Vue.observable(require('@/assets/config.json'));
|
||||
const getRuntimeConfig = async () => {
|
||||
const runtimeConfig = await fetch('./config.json');
|
||||
return await runtimeConfig.json()
|
||||
}
|
||||
|
||||
config.promise = getRuntimeConfig();
|
||||
config.promise.then(function (json) {
|
||||
// Reactively use all the config values
|
||||
for (const key of Object.keys(json)) {
|
||||
Vue.set(config, key, json[key]);
|
||||
}
|
||||
});
|
||||
Vue.prototype.$config = config;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ import sdk from "matrix-js-sdk";
|
|||
import { TimelineWindow, EventTimeline } from "matrix-js-sdk";
|
||||
import util from "../plugins/utils";
|
||||
import User from "../models/user";
|
||||
import config from "../assets/config";
|
||||
|
||||
const LocalStorageCryptoStore = require("matrix-js-sdk/lib/crypto/store/localStorage-crypto-store")
|
||||
.LocalStorageCryptoStore;
|
||||
|
|
@ -120,7 +119,7 @@ export default {
|
|||
promiseLogin = tempMatrixClient
|
||||
.register(user, pass, null, {
|
||||
type: "m.login.dummy",
|
||||
initial_device_display_name: config.appName
|
||||
initial_device_display_name: this.$config.appName
|
||||
})
|
||||
.then((response) => {
|
||||
console.log("Response", response);
|
||||
|
|
@ -132,7 +131,7 @@ export default {
|
|||
return u;
|
||||
})
|
||||
} else {
|
||||
var data = { user: User.localPart(user.user_id), password: user.password, type: "m.login.password", initial_device_display_name: config.appName };
|
||||
var data = { user: User.localPart(user.user_id), password: user.password, type: "m.login.password", initial_device_display_name: this.$config.appName };
|
||||
if (user.device_id) {
|
||||
data.device_id = user.device_id;
|
||||
}
|
||||
|
|
@ -297,7 +296,7 @@ export default {
|
|||
if (this.ready) {
|
||||
return Promise.resolve(this.currentUser);
|
||||
}
|
||||
return this.$store.dispatch("login", this.currentUser || new User(config.defaultServer, "", "", true));
|
||||
return this.$store.dispatch("login", this.currentUser || new User(this.$config.defaultServer, "", "", true));
|
||||
},
|
||||
|
||||
addMatrixClientListeners(client) {
|
||||
|
|
@ -736,7 +735,7 @@ export default {
|
|||
return this.matrixClient;
|
||||
})
|
||||
} else {
|
||||
const tempMatrixClient = sdk.createClient(config.defaultServer);
|
||||
const tempMatrixClient = sdk.createClient(this.$config.defaultServer);
|
||||
var tempUserString = this.$store.state.tempuser;
|
||||
var tempUser = null;
|
||||
if (tempUserString) {
|
||||
|
|
@ -753,7 +752,7 @@ export default {
|
|||
clientPromise = tempMatrixClient
|
||||
.register(user, pass, null, {
|
||||
type: "m.login.dummy",
|
||||
initial_device_display_name: config.appName
|
||||
initial_device_display_name: this.$config.appName
|
||||
})
|
||||
.then((response) => {
|
||||
console.log("Response", response);
|
||||
|
|
@ -766,7 +765,7 @@ export default {
|
|||
|
||||
// Get an access token
|
||||
clientPromise = clientPromise.then(user => {
|
||||
var data = { user: User.localPart(user.user_id), password: user.password, type: "m.login.password", initial_device_display_name: config.appName };
|
||||
var data = { user: User.localPart(user.user_id), password: user.password, type: "m.login.password", initial_device_display_name: this.$config.appName };
|
||||
if (user.device_id) {
|
||||
data.device_id = user.device_id;
|
||||
}
|
||||
|
|
@ -779,7 +778,7 @@ export default {
|
|||
// Only used to get public room info from.
|
||||
clientPromise = clientPromise.then(user => {
|
||||
var opts = {
|
||||
baseUrl: config.defaultServer,
|
||||
baseUrl: this.$config.defaultServer,
|
||||
userId: user.user_id,
|
||||
accessToken: user.access_token,
|
||||
timelineSupport: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue