diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/App.jsx b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/App.jsx
index 24dcb2848ae..4b55d0e77df 100644
--- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/App.jsx
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/App.jsx
@@ -18,6 +18,7 @@
import './App.scss';
import React, {Component} from 'react';
+import AuthHandler from './api/authHandler';
import createHistory from 'history/createBrowserHistory';
import {BrowserRouter as Router, Redirect, Route, Switch} from 'react-router-dom'
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
@@ -54,12 +55,19 @@ class Base extends Component {
constructor() {
super();
this.state = {
- user: "s"
+ user: null
+
}
}
componentWillMount() {
+ let user = AuthHandler.getUser();
+ if (user) {
+ if (!AuthHandler.isTokenExpired()) {
+ this.setState({user: user});
+ }
+ }
}
componentDidMount() {
@@ -67,7 +75,7 @@ class Base extends Component {
}
render() {
- if (this.state.user) {
+ if (this.state.user !== null) {
console.log("Have User.");
return (
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/AuthHandler.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/AuthHandler.js
deleted file mode 100644
index 62604f68a36..00000000000
--- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/AuthHandler.js
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- */
-'use strict';
-
-import Axios from 'axios';
-
-/**
- * Handles all tasks related to Authentication and Authorization.
- * Generate access tokens, verify the user has necessary permissions etc.
- * */
-class AuthHandler {
-
- /**
- * Generate client id and client secret to generate access tokens.
- * */
- login(userName, password) {
- Axios.post("https://localhost:9443/auth/application-mgt/v1.0/auth/tokens?userName=admin&password=admin").then()
- }
-
- isLoggedIn() {
-
- }
-
- getloggedInUser() {
-
- }
-
-
-
-}
\ No newline at end of file
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/Endpoints.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/Endpoints.js
deleted file mode 100644
index 0f6ab3bd140..00000000000
--- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/Endpoints.js
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.
- */
-'use strict';
-
-import Helper from './helpers/AppMgtApiHelpers';
-
-/**
- * Application related apis
- * */
-export default class Endpoint{
-
- /**
- * Api for create an application.
- * @param: applicationData: The application data object. This contains an object array of each step data from
- * application creation wizard.
- *
- * From that data array, the proper application object is created and send it to the api.
- * */
- static createApplication(applicationData) {
-
- console.log("In application create application", applicationData);
- Helper.buildApplication(applicationData);
-
- }
-
- /**
- * Method to handle application release process.
- * */
- static releaseApplication() {
-
- }
-
- /**
- * Edit created application.
- * @param applicationData: The modified application data.
- * */
- static editApplication(applicationData) {
-
- }
-
- /**
- * Get all the created applications for the user.
- * */
- static getApplications() {
-
- }
-
- /**
- * Get specific application.
- * @param appId : The application Id.
- * */
- static getApplication(appId) {
-
- }
-
- /**
- * Delete specified application.
- * @param appId: The id of the application which is to be deleted.
- * */
- static deleteApplication(appId) {
-
- }
-
-
- /**
- * Platform related apis
- * */
- /**
- * Create a new Platform
- * @param platformData: The platform data object.
- * */
- static createPlatform(platformData) {
- // /api/application-mgt/v1.0/platforms/1.0.0/
- // {
- // identifier: "${platform_identifier}",
- // name: "New Platform",
- // description : "New Platform"
- // }
- }
-
- /**
- * Get available platforms
- * */
- static getPlatforms() {
-
- }
-
- /**
- * Get the user specified platform
- * @param platformId: The identifier of the platform
- * */
- static getPlatform(platformId) {
-
- }
-
- /**
- * Delete specified platform
- * @param platformId: The id of the platform which is to be deleted.
- * */
- static deletePlatform(platformId) {
-
- }
-
-
-}
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/authHandler.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/authHandler.js
new file mode 100644
index 00000000000..e7f9e60fc0f
--- /dev/null
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/authHandler.js
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+'use strict';
+
+import Axios from 'axios';
+import User from './data/user';
+import Utils from './data/utils';
+import Constants from "../common/constants";
+
+/**
+ * Handles all tasks related to Authentication and Authorization.
+ * Generate access tokens, verify the user has necessary permissions etc.
+ * */
+class AuthHandler {
+
+ /**
+ * Sends a request to the auth handler endpoint (auth/application-mgt/v1.0/auth/login) and generate token pair.
+ * @param userName: The user name of the user.
+ * @param password: The user password.
+ * @return Object: The response object from the axios post.
+ * */
+ static login(userName, password) {
+ const headers = {"Content-type": "application/json"};
+ let login_promise = Axios.post("https://localhost:9443/auth/application-mgt/v1.0/auth/login?userName=admin&password=admin",
+ null, {headers: headers});
+
+ login_promise.then(response => {
+ console.log(response);
+ const userName = response.data.userName;
+ const validityPeriod = response.data.expires_in; // In seconds
+ const WSO2_IOT_TOKEN = response.data.access_token;
+ const refreshToken = response.data.refresh_token;
+ const clientId = response.data.application_info[0].consumerKey;
+ const clientSecret = response.data.application_info[0].consumerSecret;
+
+ const user = new User(userName, clientId, clientSecret, validityPeriod);
+ console.log(user);
+ user.setAuthToken(WSO2_IOT_TOKEN, validityPeriod);
+ AuthHandler.setUser(user);
+ }
+ );
+
+
+ return login_promise;
+ };
+
+ /**
+ * Persists the user object in browser's local storage.
+ * @param user: The user object.
+ * */
+ static setUser(user) {
+ if (!user instanceof User) {
+ throw "Invalid user object";
+ }
+ localStorage.setItem(Constants.userConstants.WSO2_USER, JSON.stringify(user.toJson()));
+ /* TODO: IMHO it's better to get this key (`wso2_user`) from configs */
+ }
+
+ /**
+ * Get the logged in user.
+ * @return User: The logged in user object.
+ * */
+ static getUser() {
+ const userData = localStorage.getItem(Constants.userConstants.WSO2_USER);
+ const partialToken = Utils.getCookie(Constants.userConstants.PARTIAL_TOKEN);
+
+ if (!(userData && partialToken)) {
+ return null;
+ }
+ return User.fromJson(JSON.parse(userData));
+ }
+
+ isLoggedIn() {
+
+ }
+
+ logout() {
+
+ }
+
+ /**
+ * Checks whether the access token is expired.
+ * @return boolean: True if expired. False otherwise.
+ * */
+ static isTokenExpired() {
+ const userData = AuthHandler.getUser().getAuthToken();
+ return (Date.now() - userData._createdTime) > userData._expires;
+ }
+}
+
+export default AuthHandler;
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/data/user.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/data/user.js
new file mode 100644
index 00000000000..c9363a82edb
--- /dev/null
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/data/user.js
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+"use strict";
+
+import Utils from './utils'
+import Constants from '../../common/constants';
+/**
+ * Represent an user logged in to the application, There will be allays one user per session and
+ * this user details will be persist in browser localstorage.
+ */
+export default class User {
+ constructor(name, clientId, clientSecret, validityPeriod) {
+ if (User._instance) {
+ return User._instance;
+ }
+
+ this._userName = name;
+ this._clientId = clientId;
+ this._clientSecret = clientSecret;
+ this._expires = validityPeriod;
+ this._createdTime = Date.now();
+ User._instance = this;
+ }
+
+ /**
+ * OAuth scopes which are available for use by this user
+ * @returns {Array} : An array of scopes
+ */
+ get scopes() {
+ return this._scopes;
+ }
+
+ /**
+ * Set OAuth scopes available to be used by this user
+ * @param {Array} newScopes : An array of scopes
+ */
+ set scopes(newScopes) {
+ Object.assign(this.scopes, newScopes);
+ }
+
+ /**
+ * Get the JS accessible access token fragment from cookie storage.
+ * @returns {String|null}
+ */
+ getAuthToken() {
+ return Utils.getCookie(Constants.userConstants.PARTIAL_TOKEN);
+ }
+
+ /**
+ * Store the JavaScript accessible access token segment in cookie storage
+ * @param {String} newToken : Part of the access token which needs when accessing REST API
+ * @param {Number} validityPeriod : Validity period of the cookie in seconds
+ */
+ setAuthToken(newToken, validityPeriod) {
+ Utils.delete_cookie(Constants.userConstants.PARTIAL_TOKEN);
+ Utils.setCookie(Constants.userConstants.PARTIAL_TOKEN, newToken, validityPeriod);
+ }
+
+ /**
+ *
+ * @param type
+ */
+ checkPermission(type) {
+ throw ("Not implemented!");
+ }
+
+ /**
+ * Provide user data in JSON structure.
+ * @returns {JSON} : JSON representation of the user object
+ */
+ toJson() {
+ return {
+ name: this._userName,
+ clientId: this._clientId,
+ clientSecret: this._clientSecret,
+ expires: this._expires
+ };
+ }
+
+ /**
+ * User utility method to create an user from JSON object.
+ * @param {JSON} userJson : Need to provide user information in JSON structure to create an user object
+ * @returns {User} : An instance of User(this) class.
+ */
+ static fromJson(userJson) {
+
+ const _user = new User(userJson.name);
+ _user._clientId = userJson.clientId;
+ _user._clientSecret = userJson.clientSecret;
+ _user._expires = userJson.expires;
+
+ console.log(_user);
+ return _user;
+ }
+}
+
+User._instance = null; // A private class variable to preserve the single instance of a swaggerClient
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/data/utils.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/data/utils.js
new file mode 100644
index 00000000000..28a654816eb
--- /dev/null
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/data/utils.js
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+
+/**
+ * Utility class for Publisher application
+ */
+class PublisherUtils {
+
+ /**
+ * TODO: Remove this method one the initial phase is done, This is used to continue the API class until the login page is create
+ * @returns {promise}
+ */
+ // static autoLogin() {
+ // let auth = new AuthManager();
+ // return auth.authenticateUser('admin', 'admin');
+ // }
+
+ /**
+ * Get JavaScript accessible cookies saved in browser, by giving the cooke name.
+ * @param {String} name : Name of the cookie which need to be retrived
+ * @returns {String|null} : If found a cookie with given name , return its value,Else null value is returned
+ */
+ static getCookie(name) {
+ let pairs = document.cookie.split(";");
+ let cookie = null;
+ for (let pair of pairs) {
+ pair = pair.split("=");
+ let cookie_name = pair[0].trim();
+ let value = encodeURIComponent(pair[1]);
+ if (cookie_name === name) {
+ cookie = value;
+ break;
+ }
+ }
+ return cookie;
+ }
+
+ /**
+ * Delete a browser cookie given its name
+ * @param {String} name : Name of the cookie which need to be deleted
+ */
+ static delete_cookie(name) {
+ document.cookie = name + '=; Path=' + "/" + '; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
+ }
+
+ /**
+ * Set a cookie with given name and value assigned to it. Cookies can be only set to the same origin,
+ * which the script is running
+ * @param {String} name : Name of the cookie which need to be set
+ * @param {String} value : Value of the cookie, expect it to be URLEncoded
+ * @param {number} validityPeriod : (Optional) Validity period of the cookie in seconds
+ * @param {String} path : Path which needs to set the given cookie
+ * @param {boolean} secured : secured parameter is set
+ */
+ static setCookie(name, value, validityPeriod, path = "/", secured = true) {
+ let expires = "";
+ const securedDirective = secured ? "; Secure" : "";
+ if (validityPeriod) {
+ const date = new Date();
+ date.setTime(date.getTime() + validityPeriod * 1000);
+ expires = "; expires=" + date.toUTCString();
+ }
+
+ document.cookie = name + "=" + value + expires + "; path=" + path + securedDirective + validityPeriod
+ }
+
+ /**
+ * Given an object returns whether the object is empty or not
+ * @param {Object} object : Any JSON object
+ * @returns {boolean}
+ */
+ static isEmptyObject(object) {
+ return Object.keys(object).length === 0 && object.constructor === Object
+ }
+
+
+}
+
+export default PublisherUtils;
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/endpoints.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/endpoints.js
new file mode 100644
index 00000000000..fd32fbed20f
--- /dev/null
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/endpoints.js
@@ -0,0 +1,183 @@
+/*
+ * 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.
+ */
+'use strict';
+
+import Axios from 'axios';
+import AuthHandler from './authHandler';
+import Constants from '../common/constants';
+import Helper from './helpers/appMgtApiHelpers';
+
+
+
+export default class Endpoint {
+
+ /* =================================================================
+ * Application related apis
+ * */
+
+ /**
+ * Api for create an application.
+ * @param: applicationData: The application data object. This contains an object array of each step data from
+ * application creation wizard.
+ *
+ * From applicationData, the proper application object will be created and send it to the api.
+ * */
+ static createApplication(applicationData) {
+
+ let app = Helper.buildApplication(applicationData).application;
+ let user = AuthHandler.getUser();
+ console.log(user.idToken);
+ const headers = {
+ "Authorization": 'Bearer ' + user.getAuthToken(),
+ "Content-Type": "application/json",
+ };
+
+ Axios.post(Constants.appManagerEndpoints.CREATE_APP, app, {headers: headers}).then(
+ function (response) {
+ console.log(response);
+ }
+ ).catch(function (err) {
+ console.log(err);
+ });
+
+ }
+
+ /**
+ * Method to handle application release process.
+ * */
+ static releaseApplication() {
+
+ }
+
+ /**
+ * Promote the current state of the application.
+ * @param appId: The uuid of the application which the state should be updated.
+ * */
+ static updateState(appId) {
+
+ }
+
+ /**
+ * Get the next possible state, which the application can be promoted to.
+ * @param appId: The application uuid.
+ */
+ static getNextState(appId) {
+
+ }
+
+ /**
+ * Edit created application.
+ * @param applicationData: The modified application data.
+ * */
+ static editApplication(applicationData) {
+
+ }
+
+ /**
+ * Get all the created applications for the user.
+ * @return Object: The response object from the axios post.
+ * */
+ static getApplications() {
+ let user = AuthHandler.getUser();
+ console.log("Get all applications", user.getAuthToken());
+ const headers = {
+ "Authorization": 'Bearer ' + user.getAuthToken(),
+ 'Accept': 'application/json',
+ "Content-Type": "application/json",
+ };
+
+ return Axios.get(Constants.appManagerEndpoints.GET_ALL_APPS, {headers: headers});
+ }
+
+ /**
+ * Get specific application.
+ * @param appId: The application Id.
+ * */
+ static getApplication(appId) {
+
+ }
+
+ /**
+ * Delete specified application.
+ * @param appId: The id of the application which is to be deleted.
+ * */
+ static deleteApplication(appId) {
+
+ }
+
+ /*
+ * End of Application management apis.
+ * =================================================================
+ * */
+
+ /*
+ * =================================================================
+ * Platform related apis
+ * */
+
+ /**
+ * Create a new Platform
+ * @param platformData: The platform data object.
+ * */
+ static createPlatform(platformData) {
+
+ const headers = {
+ "Authorization": 'Bearer ' + AuthHandler.getUser().getAuthToken(),
+ 'Accept': 'application/json',
+ "Content-Type": "application/json",
+ };
+
+ Axios.post(Constants.platformManagerEndpoints.CREATE_PLATFORM, platformData, {headers: headers}).then(
+ function (response) {
+ console.log(response);
+ }
+ ).catch(function (err) {
+ console.log(err);
+ });
+
+ }
+
+ /**
+ * Get available platforms
+ * */
+ static getPlatforms() {
+
+ }
+
+ /**
+ * Get the user specified platform
+ * @param platformId: The identifier of the platform
+ * */
+ static getPlatform(platformId) {
+
+ }
+
+ /**
+ * Delete specified platform
+ * @param platformId: The id of the platform which is to be deleted.
+ * */
+ static deletePlatform(platformId) {
+
+ }
+
+ /*
+ * End of Platform management apis.
+ * =================================================================
+ * */
+
+}
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/helpers/AppMgtApiHelpers.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/helpers/appMgtApiHelpers.js
similarity index 69%
rename from components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/helpers/AppMgtApiHelpers.js
rename to components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/helpers/appMgtApiHelpers.js
index c52d9ed6cde..00629cec4f9 100644
--- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/helpers/AppMgtApiHelpers.js
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/api/helpers/appMgtApiHelpers.js
@@ -26,24 +26,31 @@ export default class Helper {
/**
* Generate application object from form data passed.
* @param appData: Application data from the application creation form.
+ * @return {Object, Object}: The application object and the set of images related to the application.
* */
static buildApplication(appData) {
let application = {};
let images = {};
- for (var step in appData) {
+ for (let step in appData) {
let tmpData = appData[step].data.step;
- for (var prop in tmpData) {
+ for (let prop in tmpData) {
if (prop === 'banner' || prop === 'screenshots' || prop === 'icon') {
images[prop] = tmpData[prop];
+ } else if(prop === 'tags') {
+ let tags = [];
+ let tagsFromStep = tmpData[prop];
+ for (let tag in tagsFromStep) {
+ console.log(tag);
+ tags.push(tagsFromStep[tag].value);
+ }
+ application[prop] = tags;
} else {
application[prop] = tmpData[prop];
}
}
}
-
- console.log(application, images);
+ return {application, images};
}
-
-}
\ No newline at end of file
+}
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/common/constants.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/common/constants.js
index 405042531c5..cc38f4a9280 100644
--- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/common/constants.js
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/common/constants.js
@@ -16,16 +16,30 @@
* under the License.
*/
-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';
+export default class Constants {
-TOKEN_ENDPOINT = '/token';
-DYNAMIC_CLIENT_REGISTER_ENDPOINT = '/api-application-registration/register';
+ static 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';
+
+ static TOKEN_ENDPOINT = '/token';
+ static DYNAMIC_CLIENT_REGISTER_ENDPOINT = '/api-application-registration/register';
+
+ 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_IMAGES: '/api/application-mgt/v1.0/applications/1.0.0/upload-image-artifacts/', //+appId
+ };
+
+ static platformManagerEndpoints = {
+ CREATE_PLATFORM: 'https://localhost:8243/api/application-mgt/v1.0/platforms/1.0.0/'
+ }
+
+ static userConstants = {
+ WSO2_USER: 'wso2_user',
+ PARTIAL_TOKEN: 'WSO2_IOT_TOKEN'
+ }
+
+}
-appManagerEndpoints = {
- GET_ALL_APPS: '/api/application-mgt/v1.0/applications/1.0.0/',
- CREATE_APP: '/api/application-mgt/v1.0/applications/1.0.0/',
- UPLOAD_IMAGES: '/api/application-mgt/v1.0/applications/1.0.0/upload-image-artifacts/', //+appId
-};
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/ApplicationCreate.jsx b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/ApplicationCreate.jsx
index 2542eaa5f7a..c2c53d7e7d2 100644
--- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/ApplicationCreate.jsx
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/ApplicationCreate.jsx
@@ -18,7 +18,7 @@
import React, {Component} from 'react';
import Dialog from 'material-ui/Dialog';
-import Endpoint from '../../api/Endpoints';
+import Endpoint from '../../api/endpoints';
import {withRouter} from 'react-router-dom';
import FlatButton from 'material-ui/FlatButton';
import {Step1, Step2, Step3} from './CreateSteps';
@@ -67,7 +67,7 @@ class ApplicationCreate extends Component {
/**
* Handles next button click event.
* */
- handleNext = () => {
+ handleNext() {
console.log("Handle Next");
const {stepIndex} = this.state;
this.setState({
@@ -79,7 +79,7 @@ class ApplicationCreate extends Component {
/**
* Handles form submit.
* */
- handleSubmit = () => {
+ handleSubmit() {
console.log(this.state.stepData);
Endpoint.createApplication(this.state.stepData);
@@ -89,7 +89,7 @@ class ApplicationCreate extends Component {
* Handles cancel button click event.
* This will show a confirmation dialog to cancel the application creation process.
* */
- handleCancel = () => {
+ handleCancel() {
this.setState({isDialogOpen: true});
};
@@ -97,7 +97,7 @@ class ApplicationCreate extends Component {
* Handled [ < Prev ] button click.
* This clears the data in the current step and returns to the previous step.
* */
- handlePrev = () => {
+ handlePrev() {
const {stepIndex} = this.state;
if (stepIndex > 0) {
this.removeStepData();
@@ -108,7 +108,7 @@ class ApplicationCreate extends Component {
/**
* Saves form data in each step in to the state.
* */
- setStepData = (step, data) => {
+ setStepData(step, data) {
console.log(step, data, this.state.stepData);
let tmpStepData = this.state.stepData;
tmpStepData.push({step: step, data: data});
@@ -119,7 +119,7 @@ class ApplicationCreate extends Component {
/**
* Remove the last data point
* */
- removeStepData = () => {
+ removeStepData() {
let tempData = this.state.stepData;
tempData.pop();
this.setState({stepData: tempData});
@@ -129,7 +129,7 @@ class ApplicationCreate extends Component {
* Handles the Yes button in app creation cancellation dialog.
* Clears all the form data and reset the wizard.
* */
- handleYes = () => {
+ handleYes() {
this.setState({finished: false, stepIndex: 0, stepData: [], isDialogOpen: false});
};
@@ -137,7 +137,7 @@ class ApplicationCreate extends Component {
* Handles No button in app creation cancellation dialog.
* Returns to the same step.
* */
- handleNo = () => {
+ handleNo() {
this.setState({isDialogOpen: false});
};
@@ -153,21 +153,27 @@ class ApplicationCreate extends Component {
getStepContent(stepIndex) {
switch (stepIndex) {
case 0:
- return
;
+ return ;
case 1:
- return ;
+ return ;
case 2:
- return ;
+ return ;
default:
- return ;
+ return ;
}
}
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/ApplicationListing.jsx b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/ApplicationListing.jsx
index fcceb20ca5b..3d815bb74d7 100644
--- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/ApplicationListing.jsx
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/ApplicationListing.jsx
@@ -17,6 +17,7 @@
*/
import React, {Component} from 'react';
+import EndPoint from '../../api/endpoints';
import {withRouter} from 'react-router-dom';
import TextField from 'material-ui/TextField';
import DataTable from '../UIComponents/DataTable';
@@ -44,37 +45,37 @@ class ApplicationListing extends Component {
data = [
{
id: Math.random(),
- applicationName:"Cne",
- platform:'Android',
- category:"Public",
+ applicationName: "Cne",
+ platform: 'Android',
+ category: "Public",
status: "Created"
},
{
id: Math.random(),
- applicationName:"Gone",
- platform:'IOS',
- category:"Public",
+ applicationName: "Gone",
+ platform: 'IOS',
+ category: "Public",
status: "Created"
},
{
id: Math.random(),
- applicationName:"Ane",
- platform:'Android',
- category:"Public",
+ applicationName: "Ane",
+ platform: 'Android',
+ category: "Public",
status: "Created"
},
{
id: Math.random(),
- applicationName:"one",
- platform:'Android',
- category:"Public",
+ applicationName: "one",
+ platform: 'Android',
+ category: "Public",
status: "Created"
},
{
id: Math.random(),
- applicationName:"one",
- platform:'Android',
- category:"Public",
+ applicationName: "one",
+ platform: 'Android',
+ category: "Public",
status: "Created"
},
];
@@ -84,19 +85,21 @@ class ApplicationListing extends Component {
data_id: "image",
data_type: "image",
sortable: false,
- label: ""},
+ label: ""
+ },
{
data_id: "applicationName",
data_type: "string",
sortable: true,
label: "Application Name",
- sort: this._sortData.bind(this)
+ sort: this.sortData.bind(this)
},
{
data_id: "platform",
data_type: "image_array",
sortable: false,
- label: "Platform"},
+ label: "Platform"
+ },
{
data_id: "category",
data_type: "string",
@@ -125,36 +128,41 @@ class ApplicationListing extends Component {
Theme.removeThemingScripts(this.scriptId);
}
+ componentDidMount() {
+ let getApps = EndPoint.getApplications();
+ getApps.then(response => {
+ console.log(response);
+ })
+ }
/**
* Handles the search action.
* When typing in the search bar, this method will be invoked.
* */
- _searchApplications(event, word) {
+ searchApplications(event, word) {
let searchedData;
- if (word){
- searchedData = this.data.filter((dataItem) => {
- return dataItem.applicationName.includes(word);
- });
- } else {
- searchedData = this.data;
- }
+ if (word) {
+ searchedData = this.data.filter((dataItem) => {
+ return dataItem.applicationName.includes(word);
+ });
+ } else {
+ searchedData = this.data;
+ }
this.setState({data: searchedData}, console.log("Searched data ", this.state.data));
-
}
/**
* Handles sort data function and toggles the asc state.
* asc: true : sort in ascending order.
* */
- _sortData() {
+ sortData() {
let isAsc = this.state.asc;
- let datas = isAsc?this.data.sort(this._compare):this.data.reverse();
+ let datas = isAsc ? this.data.sort(this.compare) : this.data.reverse();
this.setState({data: datas, asc: !isAsc});
}
- _compare(a, b) {
+ compare(a, b) {
if (a.applicationName < b.applicationName)
return -1;
if (a.applicationName > b.applicationName)
@@ -162,8 +170,8 @@ class ApplicationListing extends Component {
return 0;
}
- _onRowClick(id) {
- this.props.history.push("apps/"+id);
+ onRowClick(id) {
+ this.props.history.push("apps/" + id);
}
render() {
@@ -171,18 +179,17 @@ class ApplicationListing extends Component {
+ onChange={this.searchApplications.bind(this)}/>
-
-
-
-
+
-
-
);
+
+ );
}
}
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/CreateSteps/Step1.jsx b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/CreateSteps/Step1.jsx
index f414a8c278c..ee1c2aaccf3 100644
--- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/CreateSteps/Step1.jsx
+++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/src/main/resources/publisher/src/components/Application/CreateSteps/Step1.jsx
@@ -39,11 +39,13 @@ import Theme from '../../../theme';
class Step1 extends Component {
constructor() {
super();
+ this.platforms = [{identifier: 1}, {identifier: 2}, {identifier: 3}];
+ this.stores = [{identifier: 5}, {identifier: 2}, {identifier: 3}];
this.state = {
finished: false,
stepIndex: 0,
store: 1,
- platform: 1,
+ platform: 0,
stepData: [],
title: "",
titleError: ""
@@ -65,17 +67,17 @@ class Step1 extends Component {
/**
* Invokes the handleNext function in Create component.
* */
- _handleNext = () => {
+ handleNext() {
this.props.handleNext();
};
/**
* Persist the current form data to the state.
* */
- _setStepData() {
- var step = {
+ setStepData() {
+ let step = {
store: this.state.store,
- platform: this.state.platform
+ platform: this.platforms[this.state.platform]
};
this.props.setData("step1", {step: step});
}
@@ -86,14 +88,14 @@ class Step1 extends Component {
* Sets the data to the state.
* Invokes the handleNext method of Create component.
* */
- _handleClick() {
- this._setStepData();
+ handleClick() {
+ this.setStepData();
}
/**
* Triggers when changing the Platform selection.
* */
- _onChangePlatform = (event, index, value) => {
+ onChangePlatform(event, index, value) {
console.log(value);
this.setState({platform: value});
};
@@ -101,17 +103,10 @@ class Step1 extends Component {
/**
* Triggers when changing the Store selection.
* */
- _onChangeStore = (event, index, value) => {
+ onChangeStore(event, index, value) {
this.setState({store: value});
};
- /**
- * Triggers when user types on Title text field.
- * */
- _onChangeTitle = (event, value) => {
- this.setState({title: value});
- };
-
render() {
return (
@@ -122,30 +117,30 @@ class Step1 extends Component {
floatingLabelText="Store Type*"
value={this.state.store}
floatingLabelFixed={true}
- onChange={this._onChangeStore.bind(this)}
+ onChange={this.onChangeStore.bind(this)}
>
-
-
-
+
+
+
+
-
-
-
+
+
+
-