Making the store to read the server backend configurations from config file.

feature/appm-store/pbac
sinthuja 7 years ago
parent 6374b5d9c1
commit b61bb7afe2

@ -46,6 +46,7 @@
"mocha": "^3.4.1",
"mock-local-storage": "^1.0.2",
"node-sass": "^4.5.3",
"react-intl": "^2.4.0",
"sass-loader": "^6.0.6",
"style-loader": "^0.18.1",
"webpack": "^2.7.0"

@ -0,0 +1,41 @@
{
"Title" : "Title",
"Description" : "Description",
"Category" : "Category",
"Visibility" : "Visibility",
"Devices" : "Devices",
"Roles" : "Roles",
"Groups" : "Groups",
"Tags" : "Tags",
"Platform" : "Platform",
"Platforms" : "Platfomrs",
"No.Platform" : "No Platforms",
"Screenshots" : "Screenshots",
"Icon" : "Icon",
"Banner" : "Banner",
"Create.Application" : "Create Application",
"Back" : "Back",
"Cancel" : "Cancel",
"Finish" : "Finish",
"Continue" : "Continue",
"Application.Name" : "Application Name",
"General" : "General",
"App.Releases" : "Application Releases",
"Package.Manager" : "Package Manager",
"Save" : "Save",
"Create.Release" : "Create Release",
"Release" : "Release",
"New.Release.For" : "New Release for",
"Upload.Package.File" : "Upload Package File",
"Upload" : "Upload",
"Select.from.package.library" : "Select from package library",
"Release.Name" : "Release Name",
"Release.Notes" : "Release Notes",
"Send.for.Review" : "Send for Review",
"Production.Releases" : "Production Releases",
"Beta.Releases" : "Beta Releases",
"Alpha.Releases" : "Alpha Releases",
"Version" : "Version",
"Status" : "Status",
"App.Publisher" : "Application Publisher"
}

@ -0,0 +1,48 @@
/*
* 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';
//TODO: Replace the server address with response from auth endpoint and remove hardcoded ids etc.
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 + "/config.json").then(function (response) {
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,31 +15,35 @@
* specific language governing permissions and limitations
* under the License.
*/
import Configuration from './configuration';
import axios from 'axios';
'use strict';
//TODO: Replace the server address with response from auth endpoint and remove hardcoded ids etc.
class Constants {
constructor() {
this.contentTypeHeaderName = 'Content-Type';
this.contentType = 'application/json';
this.https = 'https://';
console.log('server config called');
this.serverConfig = {};
this.getServerConfig();
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";
}
load() {
let apiBaseUrl = 'https://' + Configuration.serverConfig.hostname + ':' + Configuration.serverConfig.apiPort;
let httpBaseUrl = 'https://' + Configuration.serverConfig.hostname + ':' + Configuration.serverConfig.httpsPort;
this.appManagerEndpoints = {
GET_ALL_APPS: this.https + this.serverConfig.hostname + ':' + this.serverConfig.httpsPort + '/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/"
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/'
};
//TODO: remove the platform manager endpoints
this.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',
@ -47,22 +51,13 @@ class Constants {
};
this.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",
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'
};
}
getServerConfig(callback) {
let baseURL = window.location.origin;
let appContext = window.location.pathname.split("/")[1];
let configFileName = 'config.json';
return axios.get(baseURL + "/" + configFileName);
}
}
export default (new Constants);
export default(new Constants);

@ -21,6 +21,7 @@ import {withRouter} from 'react-router-dom';
import {Button, Col, Row, Table} from 'reactstrap';
import Drawer from '../UIComponents/Drawer/Drawer';
import ApplicationView from './View/ApplicationView';
import Configuration from '../../common/configuration';
import Constants from '../../common/constants';
/**
@ -55,7 +56,6 @@ class ApplicationListing extends Component {
src: "http://dl1.cbsistatic.com/i/r/2016/08/08/0e67e43a-5a45-41ab-b81d-acfba8708044/resize/736x552/0c0ee669677b5060a0fa1bfb0c7873b4/android-logo-promo-470.png"
}]
};
console.log(Constants.appManagerEndpoints.GET_ALL_APPS);
}
headers = [

@ -21,9 +21,43 @@ import Store from './App';
import ReactDOM from 'react-dom';
import 'bootstrap/dist/css/bootstrap.css';
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';
function loadStore() {
const possibleLocale = navigator.language.split("-")[0];
//TODO: baseURL: Configuration.hostConstants.baseURL + "/" + Configuration.hostConstants.appContext + "/locales/"
let loadLocaleFile = Axios.create({
baseURL: Configuration.hostConstants.baseURL + "/locales/"
+ possibleLocale + ".json"
}).get();
/**
* This is the base js file of the app. All the content will be rendered in the root element.
* */
loadLocaleFile.then(response => {
const messages = defineMessages(response.data);
addLocaleData(require('react-intl/locale-data/' + possibleLocale));
ReactDOM.render(<IntlProvider locale={possibleLocale}
messages={messages}><Store/></IntlProvider>, document.getElementById('root'));
registerServiceWorker();
}).catch(error => {
addLocaleData(require('react-intl/locale-data/en'));
let defaultLocale = Axios.create({
baseURL: Configuration.hostConstants.baseURL + "/" + "locales/" + Constants.defaultLocale + ".json"
}).get();
defaultLocale.then(response => {
const messages = defineMessages(response.data);
ReactDOM.render(<IntlProvider locale={possibleLocale}
messages={messages}><Store/></IntlProvider>, document.getElementById('root'));
registerServiceWorker();
}).catch(error => {
});
});
}
Configuration.loadConfiguration(loadStore);
/**
* This is the base js file of the app. All the content will be rendered in the root element.
* */
ReactDOM.render(<Store/>, document.getElementById('root'));
registerServiceWorker();

Loading…
Cancel
Save