Skip to content

Commit

Permalink
-Added a new dashboard theme called MixERP.
Browse files Browse the repository at this point in the history
-Update documentation of overrides.
  • Loading branch information
binodnp committed Jan 1, 2016
1 parent bac54f4 commit 8fcd9e6
Show file tree
Hide file tree
Showing 81 changed files with 11,539 additions and 573 deletions.
Binary file added designs/logo-inverted.psd
Binary file not shown.
28 changes: 20 additions & 8 deletions docs/developer/overrides.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
# Overrides

Frapid searches for overridden views on the instance directory and loads them if found.
Frapid searches for overridden views on the theme and instance directories and loads them if found:

For example: the view:
For:

`~/Areas/Frapid.Account/Views/SignUp/Index.cshtml`
* **Domain Name**: fizbuzz.com
* **Area Name** : Frapid.Account
* **Controller Name** : SignUp
* **Action Name** : Index
* **Current Theme** : frapid

When you request the view:

```cs
var view = View(GetRazorView<AreaRegistration>("SignUp/Index.cshtml"));
```

would be overridden by:
it will be searched on the current theme directory (~/Catalogs/fizzbuzz_com/Areas/Frapid.WebsiteBuilder/Themes/frapid/):

`~/Catalogs/foo_com/Areas/Frapid.Account/Views/SignUp/Index.cshtml`
`~/Catalogs/fizzbuzz_com/Areas/Frapid.WebsiteBuilder/Themes/frapid/Areas/Frapid.Account/Views/SignUp/Index.cshtml`

for foo.com and
if not found then

`~/Catalogs/bar_com/Areas/Frapid.Account/Views/SignUp/Index.cshtml`
`~/Catalogs/fizzbuzz_com/Areas/Frapid.Account/Views/SignUp/Index.cshtml`

for bar.com.
if not found then

`~/Areas/Frapid.Account/Views/SignUp/Index.cshtml`

[Back to Developer Documentation](README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
using Frapid.Areas;
using Frapid.Configuration;
using Frapid.TokenManager;
using Frapid.WebsiteBuilder.Controllers;

namespace Frapid.Account.Controllers
{
public class BaseAuthenticationController : FrapidController
public class BaseAuthenticationController : WebsiteBuilderController
{
protected ActionResult OnAuthenticated(LoginResult result, SignInInfo model = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
scrudFactory.keys = [
{
property: "RegistrationOfficeId",
url: '/api/config/office/display-fields',
url: '/api/core/office/display-fields',
data: null,
valueField: "Key",
textField: "Value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
scrudFactory.keys = [
{
property: "OfficeId",
url: '/api/config/office/display-fields',
url: '/api/core/office/display-fields',
data: null,
valueField: "Key",
textField: "Value"
Expand Down
10 changes: 5 additions & 5 deletions src/Frapid.Web/Areas/Frapid.Config/Views/Office/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
scrudFactory.title = "Offices";
scrudFactory.viewAPI = "/api/config/office";
scrudFactory.viewTableName = "config.offices";
scrudFactory.viewAPI = "/api/core/office";
scrudFactory.viewTableName = "core.offices";
scrudFactory.formAPI = "/api/config/office";
scrudFactory.formTableName = "config.offices";
scrudFactory.formAPI = "/api/core/office";
scrudFactory.formTableName = "core.offices";
scrudFactory.disabledOnEdit = ["AuthorId"];
scrudFactory.excludedColumns = ["AuditUserId", "AuditTs"];
Expand All @@ -37,7 +37,7 @@
scrudFactory.keys = [
{
property: "ParentOfficeId",
url: '/api/config/office/display-fields',
url: '/api/core/office/display-fields',
data: null,
valueField: "Key",
textField: "Value"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
SELECT * FROM core.create_app('Frapid.Config', 'Config', '1.0', 'MixERP Inc.', 'December 1, 2015', 'orange configure', '/dashboard/config/offices', null);

SELECT * FROM core.create_menu('Frapid.Config', 'Office', '/dashboard/config/offices', 'building outline', '');
SELECT * FROM core.create_menu('Frapid.Config', 'Offices', '/dashboard/config/offices', 'building outline', '');
SELECT * FROM core.create_menu('Frapid.Config', 'Flags', '/dashboard/config/flags', 'flag', '');
SELECT * FROM core.create_menu('Frapid.Config', 'SMTP', '/dashboard/config/smtp', 'at', '');
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SELECT * FROM auth.create_app_menu_policy
'User',
core.get_office_id_by_office_name('Default'),
'Frapid.Config',
'{Office, Flags}'::text[]
'{Offices, Flags}'::text[]
);

SELECT * FROM auth.create_app_menu_policy
Expand Down
43 changes: 43 additions & 0 deletions src/Frapid.Web/Areas/Frapid.Dashboard/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Globalization;
using System.Web.Hosting;
using Frapid.ApplicationState.Cache;
using Frapid.Configuration;
using static System.String;

namespace Frapid.Dashboard
{
public class Configuration
{
private const string Path = "~/Catalogs/{0}/Areas/Frapid.Dashboard/";
private const string ConfigFile = "Dashboard.config";
private const string DefaultThemeKey = "DefaultTheme";

public static string GetCurrentThemePath()
{
string catalog = AppUsers.GetCatalog();
string path = Path + "Themes/{1}/";
string theme = GetDefaultTheme();

return Format(CultureInfo.InvariantCulture, path, catalog, theme);
}

public static string GetDashboardPath()
{
string catalog = AppUsers.GetCatalog();
string path = HostingEnvironment.MapPath(Format(CultureInfo.InvariantCulture, Path, catalog));

return path != null && !System.IO.Directory.Exists(path) ? Empty : path;
}

public static string GetDefaultTheme()
{
return Get(DefaultThemeKey);
}

public static string Get(string key)
{
string path = GetDashboardPath() + "/" + ConfigFile;
return ConfigurationManager.ReadConfigurationValue(path, key);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System.Web.Mvc;
using System.Collections.Generic;
using System.IO;
using System.Web.Hosting;
using System.Web.Mvc;
using Frapid.Areas;
using Frapid.Configuration;
using Frapid.Dashboard.DAL;

namespace Frapid.Dashboard.Controllers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,45 @@
using System.IO;
using System.Web.Hosting;
using System.Web.Mvc;
using Frapid.ApplicationState.Cache;
using Frapid.Areas;
using Frapid.Configuration;

namespace Frapid.Dashboard.Controllers
{
public class DashboardController : FrapidController
{
private static readonly string BasePath = "~/Areas/Frapid.Dashboard/Views";
private static readonly string LandingPage = BasePath + "/Default/LandingPage.cshtml";
private static readonly string LayoutByConvention = "~/Catalogs/{0}/Areas/Frapid.Dashboard/Views/Layouts/";
private static readonly string FallbackLayout = "~/Areas/Frapid.Dashboard/Views/Layouts/";
private static readonly string LayoutFile = "Dashboard.cshtml";
private static readonly string LandingPage = "~/Areas/Frapid.Dashboard/Views/Default/LandingPage.cshtml";

public DashboardController()
{
ViewBag.ViewPath = GetViewPath();
ViewBag.LayoutPath = GetLayoutPath();
ViewBag.LayoutFile = LayoutFile;
ViewBag.LayoutPath = this.GetLayoutPath();
ViewBag.LayoutFile = this.GetLayoutFile();
}

private string GetLayoutFile()
{
string theme = Configuration.GetDefaultTheme();
return ThemeConfiguration.GetLayout(theme);
}

private string GetLayoutPath()
{
string layout = Configuration.GetCurrentThemePath();
string layoutDirectory = HostingEnvironment.MapPath(layout);

if (layoutDirectory != null && Directory.Exists(layoutDirectory))
{
return layout;
}

return null;
}

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!filterContext.HttpContext.Request.IsAjaxRequest())
{
ViewBag.Layout = GetLayoutPath() + LayoutFile;
ViewBag.Layout = GetLayoutPath() + this.GetLayoutFile();
}
}

Expand All @@ -35,25 +49,53 @@ protected ViewResultBase FrapidView(string path, object model = null)
return View(this.HttpContext.Request.IsAjaxRequest() ? path : LandingPage, model);
}

protected string GetViewPath(string view = "")
protected string GetRazorView(string areaName, string path)
{
return BasePath + view;
}
string catalog = DbConvention.GetCatalog();
string theme = Configuration.GetDefaultTheme();

protected string GetLayoutPath()
{
string layout = LayoutByConvention;
string catalog = AppUsers.GetCatalog();
layout = string.Format(CultureInfo.InvariantCulture, layout, catalog);

string layoutDirectory = HostingEnvironment.MapPath(layout);
string overridePath = "~/Catalogs/{0}/Areas/Frapid.Dashboard/Themes/{1}/Areas/{2}/Views/" + path;
overridePath = string.Format(CultureInfo.InvariantCulture, overridePath, catalog, theme, areaName);

if (layoutDirectory != null && Directory.Exists(layoutDirectory))
if (System.IO.File.Exists(HostingEnvironment.MapPath(overridePath)))
{
return layout;
return overridePath;
}


overridePath = "~/Catalogs/{0}/Areas/{1}/Themes/{2}/Views/" + path;
overridePath = string.Format(CultureInfo.InvariantCulture, overridePath, catalog, areaName, theme);

if (System.IO.File.Exists(HostingEnvironment.MapPath(overridePath)))
{
return overridePath;
}

return FallbackLayout;
string defaultPath = "~/Areas/{0}/Views/{1}";
defaultPath = string.Format(CultureInfo.InvariantCulture, defaultPath, areaName, path);

return defaultPath;
}

protected string GetRazorView(string areaName, string controllerName, string actionName)
{
string path = controllerName.ToLower() + "/" + actionName.ToLower() + ".cshtml";
return this.GetRazorView(areaName, path);
}

protected string GetRazorView<T>(string path) where T : FrapidAreaRegistration, new()
{
FrapidAreaRegistration registration = new T();
return this.GetRazorView(registration.AreaName, path);
}

protected string GetRazorView<T>(string controllerName, string actionName)
where T : FrapidAreaRegistration, new()
{
FrapidAreaRegistration registration = new T();
string path = controllerName.ToLower() + "/" + actionName.ToLower() + ".cshtml";
return this.GetRazorView(registration.AreaName, path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ public ActionResult Index()
[RestrictAnonymous]
public ActionResult GetMeta()
{
var curent = AppUsers.GetCurrent();

return Json(new ViewModels.Dashboard
{
Culture = CultureManager.GetCurrent().Name,
Language = CultureManager.GetCurrent().TwoLetterISOLanguageName,
JqueryUIi18NPath = "/Scripts/jquery-ui/i18n/",
Today = DateTime.Now.ToShortDateString(),
Now = DateTime.Now.ToString(CultureManager.GetCurrent()),
UserId = AppUsers.GetCurrent().UserId,
User = AppUsers.GetCurrent().Email,
Office = AppUsers.GetCurrent().Office,
MetaView = AppUsers.GetCurrent(),
UserId = curent.UserId,
User = curent.Email,
Office = curent.Office,
MetaView = curent,
ShortDateFormat = CultureManager.GetShortDateFormat(),
LongDateFormat = CultureManager.GetLongDateFormat(),
ThousandSeparator = CultureManager.GetThousandSeparator(),
Expand All @@ -42,12 +44,5 @@ public ActionResult GetMeta()
DatepickerNumberOfMonths = "[2, 3]"
}, JsonRequestBehavior.AllowGet);
}

[Route("dashboard/apps")]
[RestrictAnonymous]
public ActionResult GetApps()
{
return View(GetRazorView<AreaRegistration>("Default/Apps.cshtml"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.EnterpriseServices;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using Frapid.Configuration;

namespace Frapid.Dashboard.Controllers
{
public class MyTemplateController : Controller
{
[Route("dashboard/my/template/{*resource}")]
public ActionResult Get(string resource = "")
{
string configFile =
HostingEnvironment.MapPath($"~/Catalogs/{DbConvention.GetCatalog()}/Configs/Frapid.config");

if (!System.IO.File.Exists(configFile))
{
return this.HttpNotFound();
}

var allowed = ConfigurationManager.ReadConfigurationValue(configFile, "MyAllowedResources").Split(',');

if (string.IsNullOrWhiteSpace(resource) || allowed.Count().Equals(0))
{
return this.HttpNotFound();
}

string directory = HostingEnvironment.MapPath(Configuration.GetCurrentThemePath());

if (directory == null)
{
return this.HttpNotFound();
}

string path = Path.Combine(directory, resource);

if (!System.IO.File.Exists(path))
{
return this.HttpNotFound();
}

string extension = Path.GetExtension(path);

if (!allowed.Contains(extension))
{
return this.HttpNotFound();
}

string mimeType = this.GetMimeType(path);
return this.File(path, mimeType);
}

private string GetMimeType(string fileName)
{
return MimeMapping.GetMimeMapping(fileName);
}
}
}
Loading

0 comments on commit 8fcd9e6

Please sign in to comment.