Skip to content

Commit

Permalink
Updated gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvanras committed Mar 20, 2019
1 parent 86a3458 commit c684af4
Show file tree
Hide file tree
Showing 154 changed files with 114,931 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Expand Up @@ -5,6 +5,4 @@ App_Plugins/obj

Apparare.ManifestJson/Apparare.ManifestJson.csproj.user

packages

Apparare.ManifestJson
packages
255 changes: 255 additions & 0 deletions Apparare.ManifestJson/Apparare.ManifestJson.csproj

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions Apparare.ManifestJson/ApparareManifestJsonComponent.cs
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Core.Models.Membership;

namespace Umbraco.Web.UI
{
public class ApparareManifestJsonComponent : IUserComposer
{
public void Compose(Composition composition)
{
composition.ContentApps().Append<ApparareManifestJson>();
}
}

public class ApparareManifestJson : IContentAppFactory
{
public ContentApp GetContentAppFor(object source, IEnumerable<IReadOnlyUserGroup> userGroups)
{
if (userGroups.Any(x => x.Alias.ToLowerInvariant() == "admin") == false)
return null;

var apparareManifestJson = new ContentApp
{
Alias = "apparareManifestJson",
Name = "Manifest",
Icon = "icon-diploma-alt",
View = "/App_Plugins/ApparareManifestJson/appararemanifestjson.html",
Weight = 0
};
return apparareManifestJson;
}
}
}
147 changes: 147 additions & 0 deletions Apparare.ManifestJson/Controllers/BackofficeApiController.cs
@@ -0,0 +1,147 @@
using ApparareManifestJson.Models;
using ApparareManifestJson.Models.Rdbms;
using NPoco;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Umbraco.Core.Scoping;
using Umbraco.Web.Editors;
using Umbraco.Web.Mvc;
using Umbraco.Core.Persistence;
using System.Collections;
using System.IO;
using System.Xml;
using ApparareManifestJson.Models.Custom;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace ApparareManifestJson.Controllers
{
[PluginController("ApparareManifestJson")]
public class BackofficeApiController : UmbracoAuthorizedJsonController
{
private readonly IScopeProvider _scopeProvider;

public BackofficeApiController(IScopeProvider scopeProvider)
{
_scopeProvider = scopeProvider;
}

[HttpGet]
public IHttpActionResult GetDbData(int nodeId)
{
ManifestJsonDto dbResult = GetManifestDbData(nodeId);

if (dbResult != null)
{
return Ok(dbResult);
}

return BadRequest(string.Format("Failed to get database data for NodeId: {0}", nodeId));
}

[HttpPost]
public IHttpActionResult CreateDbData(ManifestJsonDto manifest)
{
ManifestJsonDto dbResult = GetManifestDbData(manifest.NodeId);
ManifestHttpResponse mResponse = new ManifestHttpResponse();
var changed = false;

using (var scope = _scopeProvider.CreateScope())
{
if (dbResult != null)
{
if (manifest.Name != dbResult.Name)
{
dbResult.Name = manifest.Name;
changed = true;
}

if (manifest.ShortName != dbResult.ShortName)
{
dbResult.ShortName = manifest.ShortName;
changed = true;
}

if (manifest.Description != dbResult.Description)
{
dbResult.Description = manifest.Description;
changed = true;
}

if (manifest.BackgroundColor != dbResult.BackgroundColor)
{
dbResult.BackgroundColor = manifest.BackgroundColor;
changed = true;
}

if (manifest.ThemeColor != dbResult.ThemeColor)
{
dbResult.ThemeColor = manifest.ThemeColor;
changed = true;
}

if (changed)
{
dbResult.Version = (Convert.ToDecimal(dbResult.Version) + 0.1m).ToString();
scope.Database.Update(dbResult);
scope.Complete();

mResponse.status = "data_updated";
mResponse.result = dbResult;

return Ok(mResponse);
}

mResponse.status = "data_unchanged";
mResponse.result = dbResult;

return Ok(mResponse);
}
else
{
dbResult = new ManifestJsonDto();
dbResult.NodeId = manifest.NodeId;
dbResult.Version = "0.1";

if (manifest.Name != dbResult.Name)
dbResult.Name = manifest.Name;
if (manifest.ShortName != dbResult.ShortName)
dbResult.ShortName = manifest.ShortName;
if (manifest.Description != dbResult.Description)
dbResult.Description = manifest.Description;
if (manifest.BackgroundColor != dbResult.BackgroundColor)
dbResult.BackgroundColor = manifest.BackgroundColor;
if (manifest.ThemeColor != dbResult.ThemeColor)
dbResult.ThemeColor = manifest.ThemeColor;

scope.Database.Insert<ManifestJsonDto>(dbResult);
scope.Complete();

mResponse.status = "data_created";
mResponse.result = dbResult;

return Ok(mResponse);
}
}
}

public ManifestJsonDto GetManifestDbData(int m)
{
ManifestJsonDto result;

using (var scope = _scopeProvider.CreateScope())
{
result = scope.Database.Query<ManifestJsonDto>().Where(x => x.NodeId == m).FirstOrDefault();

scope.Complete();
}

return result;
}
}
}
51 changes: 51 additions & 0 deletions Apparare.ManifestJson/Handlers/HttpHandlers/ManifestJsonHandler.cs
@@ -0,0 +1,51 @@
using ApparareManifestJson.Controllers;
using ApparareManifestJson.Models.Rdbms;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Xml.Linq;
using Umbraco.Core.Scoping;
using Umbraco.Web;
using Umbraco.Core;
using ApparareManifestJson.Models.Custom;
using Umbraco.Core.Composing;

namespace ApparareManifestJson.Handlers.HttpHandlers
{
public class ManifestJsonHandler : IHttpHandler
{
public bool IsReusable => false;

public void ProcessRequest(HttpContext context)
{
ManifestRoot manifest = new ManifestRoot();

using (var scope = Current.ScopeProvider.CreateScope())
{
var result = scope.Database.Query<ManifestJsonDto>().Where(x => x.NodeId == 1053).FirstOrDefault();

scope.Complete();

manifest.name = result.Name;
manifest.short_name = result.ShortName;
manifest.description = result.Description;
manifest.theme_color = result.ThemeColor;
manifest.background_color = result.BackgroundColor;
manifest.version = result.Version;

string manifestJson = JToken.Parse(JsonConvert.SerializeObject(manifest)).ToString(Formatting.Indented);

context.Response.ContentType = "application/json";
if (manifestJson != null)
{
context.Response.Write(manifestJson);
}
}
}
}
}
15 changes: 15 additions & 0 deletions Apparare.ManifestJson/Models/Custom/ManifestHttpResponse.cs
@@ -0,0 +1,15 @@
using ApparareManifestJson.Models.Rdbms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ApparareManifestJson.Models.Custom
{
public class ManifestHttpResponse
{
public string status { get; set; }
public ManifestJsonDto result { get; set; }
}
}
15 changes: 15 additions & 0 deletions Apparare.ManifestJson/Models/Custom/ManifestIcon.cs
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ApparareManifestJson.Models.Custom
{
public class ManifestIcon
{
public string src { get; set; }
public string sizes { get; set; }
public string type { get; set; }
}
}
22 changes: 22 additions & 0 deletions Apparare.ManifestJson/Models/Custom/ManifestRoot.cs
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ApparareManifestJson.Models.Custom
{
public class ManifestRoot
{
public string name { get; set; }
public string short_name { get; set; }
public string description { get; set; }
public int manifest_version => 2;
public string version { get; set; }
public List<ManifestIcon> icons { get; set; }
public string theme_color { get; set; }
public string background_color { get; set; }
public string display => "standalone";
public string start_url => ".";
}
}
41 changes: 41 additions & 0 deletions Apparare.ManifestJson/Models/Rdbms/ManifestJsonDto.cs
@@ -0,0 +1,41 @@
using NPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Persistence.DatabaseAnnotations;

namespace ApparareManifestJson.Models.Rdbms
{
[TableName("ApparareManifestJson_Domains")]
[PrimaryKey("id")]
[ExplicitColumns]
public class ManifestJsonDto
{
[Column("Id")]
[PrimaryKeyColumn()]
public int Id { get; set; }

[Column("NodeId")]
public int NodeId { get; set; }

[Column("Version")]
public string Version { get; set; }

[Column("Name")]
public string Name { get; set; }

[Column("ShortName")]
public string ShortName { get; set; }

[Column("Description")]
public string Description { get; set; }

[Column("ThemeColor")]
public string ThemeColor { get; set; }

[Column("BackgroundColor")]
public string BackgroundColor { get; set; }
}
}
36 changes: 36 additions & 0 deletions Apparare.ManifestJson/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ApparareManifestJson")]
[assembly: AssemblyDescription("A Content App for Umbraco 8 that generates a managable manifest.json file for all the root nodes")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ApparareManifestJson")]
[assembly: AssemblyCopyright("Copyright © Koen van Ras 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("659d5de7-b3bf-4c47-8f54-297c2182bccb")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit c684af4

Please sign in to comment.