refactoring theming support

feature/appm-store/pbac
megala21 7 years ago
parent 5614914efa
commit 8f3d11fa0e

@ -31,7 +31,7 @@ import {
PlatformCreate, PlatformCreate,
PlatformListing PlatformListing
} from './components'; } from './components';
import Theme from './themes/theme'; import Theme from './theme';
const history = createHistory({basename: '/publisher'}); const history = createHistory({basename: '/publisher'});
@ -40,8 +40,8 @@ const history = createHistory({basename: '/publisher'});
*Loading the theme files based on the the user-preference. *Loading the theme files based on the the user-preference.
*/ */
let muiTheme = null; let muiTheme = null;
let selected = Theme.selectedTheme; let selected = Theme.currentTheme;
if (Theme.currentTheme === "default") { if (Theme.currentThemeType === "default") {
let defaultTheme = require("material-ui/styles/baseThemes/" + selected); let defaultTheme = require("material-ui/styles/baseThemes/" + selected);
muiTheme = getMuiTheme(defaultTheme.default); muiTheme = getMuiTheme(defaultTheme.default);
} else { } else {

@ -24,7 +24,6 @@ import {Step1, Step2, Step3} from './CreateSteps';
import RaisedButton from 'material-ui/RaisedButton'; import RaisedButton from 'material-ui/RaisedButton';
import {Card, CardActions, CardTitle} from 'material-ui/Card'; import {Card, CardActions, CardTitle} from 'material-ui/Card';
import {Step, StepLabel, Stepper,} from 'material-ui/Stepper'; import {Step, StepLabel, Stepper,} from 'material-ui/Stepper';
import Theme from '../../themes/theme';
/** /**
* The App Create Component. * The App Create Component.
@ -52,16 +51,17 @@ class ApplicationCreate extends Component {
} }
componentWillMount() { componentWillMount() {
let selected = Theme.selectedTheme; //Using the particular style specific to user selected theme.
if (Theme.currentTheme === "default") { const theme = require("../../theme").default;
require("../../themes/default/application-create.css"); const selected =
} else { (theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const applicationCreateCss = "application-create.css";
try { try {
require("../../themes/" + selected + "/application-create.css"); require("../../" + theme.themeFolder + "/" + selected + "/" + applicationCreateCss);
} catch (ex){ } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../themes/default/application-create.css"); require("../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + applicationCreateCss);
}
} }
} }

@ -21,7 +21,6 @@ import {withRouter} from 'react-router-dom';
import TextField from 'material-ui/TextField'; import TextField from 'material-ui/TextField';
import DataTable from '../UIComponents/DataTable'; import DataTable from '../UIComponents/DataTable';
import {Card, CardActions, CardTitle} from 'material-ui/Card'; import {Card, CardActions, CardTitle} from 'material-ui/Card';
import Theme from '../../themes/theme';
/** /**
* The App Create Component. * The App Create Component.
@ -114,16 +113,17 @@ class ApplicationListing extends Component {
//Fetch all the applications from backend and create application objects. //Fetch all the applications from backend and create application objects.
this.setState({data: this.data}); this.setState({data: this.data});
let selected = Theme.selectedTheme; //Using the particular style specific to user selected theme.
if (Theme.currentTheme === "default") { const theme = require("../../theme").default;
require("../../themes/default/application-listing.css"); const selected =
} else { (theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const applicationListingCss = "application-listing.css";
try { try {
require("../../themes/" + selected + "/application-listing.css"); require("../../" + theme.themeFolder + "/" + selected + "/" + applicationListingCss);
} catch (ex) { } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../themes/default/application-listing.css"); require("../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + applicationListingCss);
}
} }
} }

@ -22,9 +22,6 @@ import MenuItem from 'material-ui/MenuItem';
import TextField from 'material-ui/TextField'; import TextField from 'material-ui/TextField';
import SelectField from 'material-ui/SelectField'; import SelectField from 'material-ui/SelectField';
import RaisedButton from 'material-ui/RaisedButton'; import RaisedButton from 'material-ui/RaisedButton';
import Theme from '../../../themes/theme';
/** /**
* The first step of the application creation wizard. * The first step of the application creation wizard.
@ -54,16 +51,17 @@ class Step1 extends Component {
} }
componentWillMount() { componentWillMount() {
let selected = Theme.selectedTheme; //Using the particular style specific to user selected theme.
if (Theme.currentTheme === "default") { const theme = require("../../../theme").default;
require("../../../themes/default/application-create-step1.css"); const selected =
} else { (theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const applicationCreationStepCss = "application-create-step1.css";
try { try {
require("../../../themes/" + selected + "/application-create-step1.css"); require("../../../" + theme.themeFolder + "/" + selected + "/" + applicationCreationStepCss);
} catch (ex){ } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../../themes/default/application-create-step1.css"); require("../../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + applicationCreationStepCss);
}
} }
//Get the list of available platforms and set to the state. //Get the list of available platforms and set to the state.
} }

@ -28,7 +28,6 @@ import SelectField from 'material-ui/SelectField';
import RaisedButton from 'material-ui/RaisedButton'; import RaisedButton from 'material-ui/RaisedButton';
import Clear from 'material-ui/svg-icons/content/clear'; import Clear from 'material-ui/svg-icons/content/clear';
import {GridList, GridTile} from 'material-ui/GridList'; import {GridList, GridTile} from 'material-ui/GridList';
import Theme from '../../../themes/theme';
/** /**
* The Second step of application create wizard. * The Second step of application create wizard.
@ -70,16 +69,17 @@ class Step2 extends Component {
} }
componentWillMount() { componentWillMount() {
let selected = Theme.selectedTheme; //Using the particular style specific to user selected theme.
if (Theme.currentTheme === "default") { const theme = require("../../../theme").default;
require("../../../themes/default/application-create-step2.css"); const selected =
} else { (theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const applicationCreationStepCss = "application-create-step2.css";
try { try {
require("../../../themes/" + selected + "/application-create-step2.css"); require("../../../" + theme.themeFolder + "/" + selected + "/" + applicationCreationStepCss);
} catch (ex){ } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../../themes/default/application-create-step2.css"); require("../../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + applicationCreationStepCss);
}
} }
} }

@ -24,7 +24,6 @@ import TextField from 'material-ui/TextField';
import FlatButton from 'material-ui/FlatButton'; import FlatButton from 'material-ui/FlatButton';
import SelectField from 'material-ui/SelectField'; import SelectField from 'material-ui/SelectField';
import RaisedButton from 'material-ui/RaisedButton'; import RaisedButton from 'material-ui/RaisedButton';
import Theme from '../../../themes/theme';
/** /**
* The Third step of application create wizard. {Application Release Step} * The Third step of application create wizard. {Application Release Step}
@ -59,16 +58,17 @@ class Step3 extends Component {
} }
componentWillMount() { componentWillMount() {
let selected = Theme.selectedTheme; //Using the particular style specific to user selected theme.
if (Theme.currentTheme === "default") { const theme = require("../../../theme").default;
require("../../../themes/default/application-create-step3.css"); const selected =
} else { (theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const applicationCreationStepCss = "application-create-step1.css";
try { try {
require("../../../themes/" + selected + "/application-create-step3.css"); require("../../../" + theme.themeFolder + "/" + selected + "/" + applicationCreationStepCss);
} catch (ex){ } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../../themes/default/application-create-step3.css"); require("../../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + applicationCreationStepCss);
}
} }
} }

@ -31,7 +31,6 @@ import Dashboard from 'material-ui/svg-icons/action/dashboard';
import DevicesOther from 'material-ui/svg-icons/hardware/devices-other'; import DevicesOther from 'material-ui/svg-icons/hardware/devices-other';
import NotificationsIcon from 'material-ui/svg-icons/social/notifications'; import NotificationsIcon from 'material-ui/svg-icons/social/notifications';
import ActionAccountCircle from 'material-ui/svg-icons/action/account-circle'; import ActionAccountCircle from 'material-ui/svg-icons/action/account-circle';
import Theme from '../../themes/theme';
/** /**
@ -51,16 +50,17 @@ class BaseLayout extends Component {
} }
componentWillMount() { componentWillMount() {
let selected = Theme.selectedTheme; //Using the particular style specific to user selected theme.
if (Theme.currentTheme === "default") { const theme = require("../../theme").default;
require("../../themes/default/basic-layout.css"); const selected =
} else { (theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const basicLayoutCss = "basic-layout.css";
try { try {
require("../../themes/" + selected + "/basic-layout.css"); require("../../" + theme.themeFolder + "/" + selected + "/" + basicLayoutCss);
} catch (ex){ } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../themes/default/basic-layout.css"); require("../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + basicLayoutCss);
}
} }
} }

@ -31,7 +31,6 @@ import {GridList, GridTile} from 'material-ui/GridList';
import Close from 'material-ui/svg-icons/navigation/close'; import Close from 'material-ui/svg-icons/navigation/close';
import {Card, CardActions, CardTitle} from 'material-ui/Card'; import {Card, CardActions, CardTitle} from 'material-ui/Card';
import AddCircleOutline from 'material-ui/svg-icons/content/add-circle-outline'; import AddCircleOutline from 'material-ui/svg-icons/content/add-circle-outline';
import Theme from '../../themes/theme';
/** /**
* Platform Create component. * Platform Create component.
@ -66,16 +65,17 @@ class PlatformCreate extends Component {
} }
componentWillMount() { componentWillMount() {
let selected = Theme.selectedTheme; //Using the particular style specific to user selected theme.
if (Theme.currentTheme === "default") { const theme = require("../../theme").default;
require("../../themes/default/platform-create.css"); const selected =
} else { (theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const platformCreateCss = "platform-create.css";
try { try {
require("../../themes/" + selected + "/platform-create.css"); require("../../" + theme.themeFolder + "/" + selected + "/" + platformCreateCss);
} catch (ex) { } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../themes/default/platform-create.css"); require("../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + platformCreateCss);
}
} }
} }

@ -21,7 +21,6 @@ import {withRouter} from 'react-router-dom';
import TextField from 'material-ui/TextField'; import TextField from 'material-ui/TextField';
import DataTable from '../UIComponents/DataTable'; import DataTable from '../UIComponents/DataTable';
import {Card, CardActions, CardTitle} from 'material-ui/Card'; import {Card, CardActions, CardTitle} from 'material-ui/Card';
import Theme from '../../themes/theme';
/** /**
* The App Create Component. * The App Create Component.
@ -41,16 +40,17 @@ class PlatformListing extends Component {
} }
componentWillMount() { componentWillMount() {
let selected = Theme.selectedTheme; //Using the particular style specific to user selected theme.
if (Theme.currentTheme === "default") { const theme = require("../../theme").default;
require("../../themes/default/platform-listing.css"); const selected =
} else { (theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const platformListingCss = "platform-listing.css";
try { try {
require("../../themes/" + selected + "/platform-listing.css"); require("../../" + theme.themeFolder + "/" + selected + "/" + platformListingCss);
} catch (ex) { } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../themes/default/platform-listing.css"); require("../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + platformListingCss);
}
} }
//Fetch all the applications from backend and create application objects. //Fetch all the applications from backend and create application objects.
} }

@ -22,7 +22,6 @@ import DataTableRow from './DataTableRow';
import DataTableHeader from './DataTableHeader'; import DataTableHeader from './DataTableHeader';
import RaisedButton from 'material-ui/RaisedButton'; import RaisedButton from 'material-ui/RaisedButton';
import {Table, TableBody, TableHeader, TableRow} from 'material-ui/Table'; import {Table, TableBody, TableHeader, TableRow} from 'material-ui/Table';
import Theme from '../../themes/theme';
/** /**
* The Custom Table Component. * The Custom Table Component.
@ -62,16 +61,18 @@ class DataTable extends Component {
componentWillMount() { componentWillMount() {
this.setState({data: this.props.data, headers: this.props.headers}); this.setState({data: this.props.data, headers: this.props.headers});
let selected = Theme.selectedTheme;
if (Theme.currentTheme === "default") { //Using the particular style specific to user selected theme.
require("../../themes/default/data-table.css"); const theme = require("../../theme").default;
} else { const selected =
(theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const dataTableCss = "data-table.css";
try { try {
require("../../themes/" + selected + "/data-table.css"); require("../../" + theme.themeFolder + "/" + selected + "/" + dataTableCss);
} catch (ex) { } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../themes/default/data-table.css"); require("../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + dataTableCss);
}
} }
} }

@ -20,7 +20,6 @@ import PropTypes from 'prop-types';
import React, {Component} from 'react'; import React, {Component} from 'react';
import FlatButton from 'material-ui/FlatButton'; import FlatButton from 'material-ui/FlatButton';
import {TableHeaderColumn} from 'material-ui/Table'; import {TableHeaderColumn} from 'material-ui/Table';
import Theme from '../../themes/theme';
/** /**
* Data Table header component. * Data Table header component.
@ -33,16 +32,17 @@ class DataTableHeader extends Component {
} }
componentWillMount() { componentWillMount() {
let selected = Theme.selectedTheme; //Using the particular style specific to user selected theme.
if (Theme.currentTheme === "default") { const theme = require("../../theme").default;
require("../../themes/default/data-table.css"); const selected =
} else { (theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const dataTableCss = "data-table.css";
try { try {
require("../../themes/" + selected + "/data-table.css"); require("../../" + theme.themeFolder + "/" + selected + "/" + dataTableCss);
} catch (ex) { } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../themes/default/data-table.css"); require("../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + dataTableCss);
}
} }
} }

@ -19,7 +19,6 @@
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React, {Component} from 'react'; import React, {Component} from 'react';
import {TableRow, TableRowColumn} from 'material-ui/Table'; import {TableRow, TableRowColumn} from 'material-ui/Table';
import Theme from '../../themes/theme';
/** /**
* Data table row component. * Data table row component.
@ -36,16 +35,18 @@ class DataTableRow extends Component {
componentWillMount() { componentWillMount() {
this.setState({dataItem: this.props.dataItem}); this.setState({dataItem: this.props.dataItem});
let selected = Theme.selectedTheme;
if (Theme.currentTheme === "default") { //Using the particular style specific to user selected theme.
require("../../themes/default/data-table.css"); const theme = require("../../theme").default;
} else { const selected =
(theme.currentThemeType === theme.defaultThemeType) ? theme.defaultThemeType : theme.currentTheme;
const dataTableCss = "data-table.css";
try { try {
require("../../themes/" + selected + "/data-table.css"); require("../../" + theme.themeFolder + "/" + selected + "/" + dataTableCss);
} catch (ex) { } catch (ex){
// If the particular customized file does not exist, use the default one. // If the particular customized file does not exist, use the default one.
require("../../themes/default/data-table.css"); require("../../" + theme.themeFolder + "/" + theme.defaultThemeType + "/" + dataTableCss);
}
} }
} }

@ -22,12 +22,14 @@
*/ */
class Theme { class Theme {
constructor() { constructor() {
const theme = require("../config.json").theme; const theme = require("./config.json").theme;
this.currentTheme = theme.type; this.currentThemeType = theme.type;
if (this.currentTheme === "default") { this.defaultThemeType = "default";
this.selectedTheme = theme.value; this.themeFolder = "themes";
if (this.currentThemeType === this.defaultThemeType) {
this.currentTheme = theme.value;
} else { } else {
this.selectedTheme = theme.value; this.currentTheme = theme.value;
} }
} }
} }
Loading…
Cancel
Save