Adding the server config to be read and used.

feature/appm-store/pbac
sinthuja 7 years ago
parent b15e532983
commit f1aa4b69ba

@ -2,5 +2,10 @@
"theme": {
"type": "default",
"value": "lightBaseTheme"
},
"config": {
"hostname": "localhost",
"httpsPort": "9443",
"apiPort": "8243"
}
}

@ -0,0 +1,49 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
import axios from 'axios';
import Constants from './constants';
class Configuration {
constructor() {
this.serverConfig = {};
this.hostConstants = {
baseURL: window.location.origin,
appContext: window.location.pathname.split("/")[1]
};
}
loadConfiguration(callback) {
let thisObject = this;
axios.get(thisObject.hostConstants.baseURL + '/' + thisObject.hostConstants.appContext + "/config.json").
then(function (response) {
console.log('server config was read successfully! ');
thisObject.serverConfig = response.data.config;
Constants.load();
callback();
}).catch(function (error) {
console.log('unable to load the config file!' + error);
});
}
}
export default (new Configuration());

@ -15,41 +15,47 @@
* specific language governing permissions and limitations
* under the License.
*/
import Configuration from './configuration';
'use strict';
//TODO: Replace the server address with response from auth endpoint and remove hardcoded ids etc.
export default class Constants {
class Constants {
static scopes = 'perm:application:get perm:application:create perm:application:update perm:application-mgt:login' +
constructor() {
this.scopes = 'perm:application:get perm:application:create perm:application:update perm:application-mgt:login' +
' perm:application:delete perm:platform:add perm:platform:remove perm:roles:view perm:devices:view';
this.appManagerEndpoints = {};
this.platformManagerEndpoints = {};
this.userConstants = {};
this.defaultLocale = "en";
static appManagerEndpoints = {
GET_ALL_APPS: 'https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/',
CREATE_APP: 'https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/',
UPLOAD_IMAGE_ARTIFACTS: 'https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/upload-image-artifacts/', //+appId
GET_IMAGE_ARTIFACTS: "https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/image-artifacts/"
}
load() {
let apiBaseUrl = 'https://' + Configuration.serverConfig.hostname + ':' + Configuration.serverConfig.apiPort;
let httpBaseUrl = 'https://' + Configuration.serverConfig.hostname + ':' + Configuration.serverConfig.httpsPort;
this.appManagerEndpoints = {
GET_ALL_APPS: apiBaseUrl + '/api/application-mgt/v1.0/applications/1.0.0/',
CREATE_APP: apiBaseUrl + '/api/application-mgt/v1.0/applications/1.0.0/',
UPLOAD_IMAGE_ARTIFACTS: apiBaseUrl + '/api/application-mgt/v1.0/applications/1.0.0/upload-image-artifacts/', //+appId
GET_IMAGE_ARTIFACTS: apiBaseUrl + '/api/application-mgt/v1.0/applications/1.0.0/image-artifacts/'
};
static platformManagerEndpoints = {
CREATE_PLATFORM: 'https://localhost:8243/api/application-mgt/v1.0/platforms/1.0.0',
GET_ENABLED_PLATFORMS: 'https://localhost:8243/api/application-mgt/v1.0/platforms/1.0.0?status=ENABLED',
GET_PLATFORM: 'https://localhost:8243/api/application-mgt/v1.0/platforms/1.0.0/'
this.platformManagerEndpoints = {
CREATE_PLATFORM: apiBaseUrl + '/api/application-mgt/v1.0/platforms/1.0.0',
GET_ENABLED_PLATFORMS: apiBaseUrl + '/api/application-mgt/v1.0/platforms/1.0.0?status=ENABLED',
GET_PLATFORM: apiBaseUrl + '/api/application-mgt/v1.0/platforms/1.0.0/'
};
static userConstants = {
LOGIN_URL:"https://localhost:9443/auth/application-mgt/v1.0/auth/login",
LOGOUT_URL: "https://localhost:9443/auth/application-mgt/v1.0/auth/logout",
this.userConstants = {
LOGIN_URL: httpBaseUrl + '/auth/application-mgt/v1.0/auth/login',
LOGOUT_URL: httpBaseUrl + '/auth/application-mgt/v1.0/auth/logout',
REFRESH_TOKEN_URL: "",
WSO2_USER: 'wso2_user',
PARTIAL_TOKEN: 'WSO2_IOT_TOKEN'
};
static hostConstants = {
baseURL : window.location.origin,
appContext : window.location.pathname.split("/")[1]
}
static defaultLocale = "en";
}
export default(new Constants);

@ -57,46 +57,6 @@ class ApplicationListing extends Component {
};
}
headers = [
{
data_id: "image",
data_type: "image",
sortable: false,
label: ""
},
{
data_id: "applicationName",
data_type: "string",
sortable: true,
label: "Application Name",
sort: this.sortData
},
{
data_id: "platform",
data_type: "image_array",
sortable: false,
label: "Platform"
},
{
data_id: "category",
data_type: "string",
sortable: false,
label: "Category"
},
{
data_id: "status",
data_type: "string",
sortable: false,
label: "Status"
},
{
data_id: "edit",
data_type: "button",
sortable: false,
label: ""
}
];
applications = [
{

@ -24,27 +24,29 @@ import registerServiceWorker from './registerServiceWorker';
import {IntlProvider, addLocaleData, defineMessages} from 'react-intl';
import Axios from 'axios';
import Constants from './common/constants';
import Configuration from './common/configuration';
const possibleLocale = navigator.language.split("-")[0];
let loadLocaleFile = Axios.create({
baseURL: Constants.hostConstants.baseURL + "/" + Constants.hostConstants.appContext + "/locales/"
function loadStore() {
const possibleLocale = navigator.language.split("-")[0];
let loadLocaleFile = Axios.create({
baseURL: Configuration.hostConstants.baseURL + "/" + Configuration.hostConstants.appContext + "/locales/"
+ possibleLocale + ".json"
}).get();
}).get();
/**
/**
* This is the base js file of the app. All the content will be rendered in the root element.
* */
loadLocaleFile.then(response => {
loadLocaleFile.then(response => {
const messages = defineMessages(response.data);
addLocaleData(require('react-intl/locale-data/' + possibleLocale));
ReactDOM.render(<IntlProvider locale={possibleLocale}
messages={messages}><Publisher/></IntlProvider>, document.getElementById('root'));
registerServiceWorker();
}).catch(error => {
addLocaleData(require('react-intl/locale-data/' + Constants.defaultLocale));
}).catch(error => {
addLocaleData(require('react-intl/locale-data/en'));
let defaultLocale = axios.create({
baseURL: Constants.hostConstants.baseURL + "/" + Constants.hostConstants.appContext + "/locales"
baseURL: Configuration.hostConstants.baseURL + "/" + Configuration.hostConstants.appContext + "/locales"
+ Constants.defaultLocale + ".json"
}).get();
defaultLocale.then(response => {
@ -54,4 +56,8 @@ loadLocaleFile.then(response => {
registerServiceWorker();
}).catch(error => {
});
});
});
}
Configuration.loadConfiguration(loadStore);

@ -21,7 +21,6 @@ import axios from 'axios';
import Constants from './constants';
//TODO: Replace the server address with response from auth endpoint and remove hardcoded ids etc.
class Configuration {
constructor() {
@ -34,7 +33,9 @@ class Configuration {
loadConfiguration(callback) {
let thisObject = this;
axios.get(thisObject.hostConstants.baseURL + '/' + thisObject.hostConstants.appContext + "/config.json").then(function (response) {
axios.get(thisObject.hostConstants.baseURL + '/' + thisObject.hostConstants.appContext + "/config.json").
then(function (response) {
console.log('successfully loaded the configuration!');
thisObject.serverConfig = response.data.config;
Constants.load();
callback();

Loading…
Cancel
Save