Skip to content

Commit

Permalink
Fix theming.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Dec 4, 2018
1 parent cfea0b7 commit 6ef567d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/UniversalDashboard/Controllers/DashboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using UniversalDashboard.Interfaces;
using System.Reflection;

namespace UniversalDashboard.Controllers
{
Expand Down Expand Up @@ -60,14 +61,20 @@ public Page Index(string page)
return _dashboard.Pages.FirstOrDefault(m => m.Name?.Replace("-", " ").Equals(page?.Replace("-", " "), StringComparison.OrdinalIgnoreCase) == true);
}

[Authorize]
[Route("theme")]
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
public IActionResult Theme()
{
var materializeCss = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "styles", "materialize.min.css");
var siteCss = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "styles", "site.css");

var css = System.IO.File.ReadAllText(materializeCss);
css += System.IO.File.ReadAllText(siteCss);
css += _dashboard?.Themes?.FirstOrDefault()?.RenderedContent;

return new ContentResult()
{
Content = _dashboard?.Themes?.FirstOrDefault()?.RenderedContent,
Content = css,
ContentType = "text/css",
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/UniversalDashboard/Services/ThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void TranslateHashtable(Hashtable hashtable, StringBuilder stringBuilder

var setting = value as string;
if (setting != null) {
stringBuilder.AppendLine("\t" + identifier + " : " + setting + " !important;");
stringBuilder.AppendLine("\t" + identifier + " : " + setting + ";");
continue;
}

Expand Down
16 changes: 16 additions & 0 deletions src/UniversalDashboard/Styles/materialize.min.css

Large diffs are not rendered by default.

File renamed without changes.
8 changes: 8 additions & 0 deletions src/UniversalDashboard/UniversalDashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
</ItemGroup>

<ItemGroup>
<None Update="Styles\site.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
<None Update="Styles\materialize.min.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
<None Update="Themes\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
Expand Down
12 changes: 8 additions & 4 deletions src/client/src/app/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ import React from 'react';
import {render} from 'react-dom';
import $ from "jquery";
import Materialize from "materialize-css";
import("materialize-css/dist/css/materialize.min.css" /* webpackChunkName: "materialize-css" */)
import 'whatwg-fetch';
import Promise from 'promise-polyfill';
import thunk from 'redux-thunk';

import('./styles/site.css' /* webpackChunkName: "ud-site-css" */);
import { UniversalDashboardService } from './services/universal-dashboard-service.jsx';
import ConnectedApp from './App';

import { Provider } from 'react-redux'
import { createStore, applyMiddleware } from 'redux'
import app from './reducers'
import {getApiPath} from 'config';

// To add to window
if (!window.Promise) {
Expand All @@ -25,4 +22,11 @@ window.UniversalDashboard = UniversalDashboardService;

const store = createStore(app, applyMiddleware(thunk));

var styles = document.createElement('link');
styles.rel = 'stylesheet';
styles.type = 'text/css';
styles.media = 'screen';
styles.href = getApiPath() + "/api/internal/dashboard/theme";
document.getElementsByTagName('head')[0].appendChild(styles);

render(<Provider store={store}><ConnectedApp/></Provider>, document.getElementById('app'));
2 changes: 0 additions & 2 deletions src/client/src/app/ud-dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ export default class UdDashboard extends React.Component {
}

loadData() {
this.loadStylesheet(getApiPath() + "/api/internal/dashboard/theme");

fetchGet("/api/internal/dashboard", function(json) {

var dashboard = json.dashboard;
Expand Down

0 comments on commit 6ef567d

Please sign in to comment.