diff --git a/Log/Web/Assets/CSSWebflow.go b/Log/Web/Assets/CSSWebflow.go index 126bbc3..2346007 100644 --- a/Log/Web/Assets/CSSWebflow.go +++ b/Log/Web/Assets/CSSWebflow.go @@ -1153,7 +1153,7 @@ textarea.w-select { * Safari (on both iOS and OS X) does not handle viewport units (vh, vw) well. * For example percentage units do not work on descendants of elements that * have any dimensions expressed in viewport units. It also doesn’t handle them at - * all in `calc()`. + * all in calc(). */ /** * Wrapper around all lightbox elements @@ -1319,7 +1319,7 @@ textarea.w-select { overflow-y: hidden; } /* - * 1. We use content-box to avoid having to do `width: calc(10vh + 2vw)` + * 1. We use content-box to avoid having to do "width: calc(10vh + 2vw)" * which doesn’t work in Safari anyway. * 2. Chrome renders images pixelated when switching to GPU. Making sure * the parent is also rendered on the GPU (by setting translate3d for @@ -1664,4 +1664,4 @@ textarea.w-select { display: none; padding: 10px; background-color: #ffdede; -}` \ No newline at end of file +}` diff --git a/Log/Web/Assets/JSWebflow.go b/Log/Web/Assets/JSWebflow.go index 74cb725..a1b3b16 100644 --- a/Log/Web/Assets/JSWebflow.go +++ b/Log/Web/Assets/JSWebflow.go @@ -291,9 +291,9 @@ Webflow.init = function() { // Collection Functions // -------------------- - // The cornerstone, an `each` implementation, aka `forEach`. - // Handles objects with the built-in `forEach`, arrays, and raw objects. - // Delegates to **ECMAScript 5**'s native `forEach` if available. + // The cornerstone, an "each" implementation, aka "forEach". + // Handles objects with the built-in "forEach", arrays, and raw objects. + // Delegates to **ECMAScript 5**'s native "forEach" if available. var each = _.each = _.forEach = function(obj, iterator, context) { /* jshint shadow:true */ if (obj == null) return obj; @@ -313,7 +313,7 @@ Webflow.init = function() { }; // Return the results of applying the iterator to each element. - // Delegates to **ECMAScript 5**'s native `map` if available. + // Delegates to **ECMAScript 5**'s native "map" if available. _.map = _.collect = function(obj, iterator, context) { var results = []; if (obj == null) return results; @@ -324,7 +324,7 @@ Webflow.init = function() { return results; }; - // Return the first value which passes a truth test. Aliased as `detect`. + // Return the first value which passes a truth test. Aliased as "detect". _.find = _.detect = function(obj, predicate, context) { var result; any(obj, function(value, index, list) { @@ -337,8 +337,8 @@ Webflow.init = function() { }; // Return all the elements that pass a truth test. - // Delegates to **ECMAScript 5**'s native `filter` if available. - // Aliased as `select`. + // Delegates to **ECMAScript 5**'s native "filter" if available. + // Aliased as "select". _.filter = _.select = function(obj, predicate, context) { var results = []; if (obj == null) return results; @@ -350,8 +350,8 @@ Webflow.init = function() { }; // Determine if at least one element in the object matches a truth test. - // Delegates to **ECMAScript 5**'s native `some` if available. - // Aliased as `any`. + // Delegates to **ECMAScript 5**'s native "some" if available. + // Aliased as "any". var any = _.some = _.any = function(obj, predicate, context) { predicate || (predicate = _.identity); var result = false; @@ -363,8 +363,8 @@ Webflow.init = function() { return !!result; }; - // Determine if the array or object contains a given value (using `===`). - // Aliased as `include`. + // Determine if the array or object contains a given value (using "==="). + // Aliased as "include". _.contains = _.include = function(obj, target) { if (obj == null) return false; if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; @@ -407,7 +407,7 @@ Webflow.init = function() { // Returns a function, that, as long as it continues to be invoked, will not // be triggered. The function will be called after it stops being called for - // N milliseconds. If `immediate` is passed, trigger the function on the + // N milliseconds. If "immediate" is passed, trigger the function on the // leading edge, instead of the trailing. _.debounce = function(func, wait, immediate) { var timeout, args, context, timestamp, result; @@ -446,7 +446,7 @@ Webflow.init = function() { // ---------------- // Retrieve the names of an object's properties. - // Delegates to **ECMAScript 5**'s native `Object.keys` + // Delegates to **ECMAScript 5**'s native "Object.keys" _.keys = function(obj) { if (!_.isObject(obj)) return []; if (nativeKeys) return nativeKeys(obj); @@ -2446,12 +2446,12 @@ var lightbox = (function (window, document, $, tram, undefined) { * Creates the DOM structure required by the lightbox. */ lightbox.build = function () { - // In case `build` is called more than once. + // In case "build" is called more than once. lightbox.destroy(); $refs = { html: $(document.documentElement), - // Empty jQuery object can be used to build new ones using `.add`. + // Empty jQuery object can be used to build new ones using ".add". empty: $() }; @@ -2491,7 +2491,7 @@ var lightbox = (function (window, document, $, tram, undefined) { // IE loses focus to inner nodes without letting us know. .on('focusin', focusThis); - // The `tabindex` attribute is needed to enable non-input elements + // The "tabindex" attribute is needed to enable non-input elements // to receive keyboard events. $('body').append($refs.lightbox.prop('tabIndex', 0)); @@ -3771,4 +3771,4 @@ Webflow.define('branding', function($, _) { // Export module return api; }); -` \ No newline at end of file +` diff --git a/Log/Web/HandlerCommons.go b/Log/Web/HandlerCommons.go index deaca1e..255529f 100644 --- a/Log/Web/HandlerCommons.go +++ b/Log/Web/HandlerCommons.go @@ -2,8 +2,6 @@ package Web import ( "fmt" - "github.com/SommerEngineering/Ocean/Log" - LM "github.com/SommerEngineering/Ocean/Log/Meta" "github.com/SommerEngineering/Ocean/Log/Web/Assets" "github.com/SommerEngineering/Ocean/Shutdown" "net/http" diff --git a/Log/Web/HandlerLog.go b/Log/Web/HandlerLog.go new file mode 100644 index 0000000..352c86c --- /dev/null +++ b/Log/Web/HandlerLog.go @@ -0,0 +1,30 @@ +package Web + +import ( + "github.com/SommerEngineering/Ocean/Log" + LM "github.com/SommerEngineering/Ocean/Log/Meta" + "github.com/SommerEngineering/Ocean/Log/Web/Scheme" + "github.com/SommerEngineering/Ocean/MimeTypes" + "github.com/SommerEngineering/Ocean/Shutdown" + "net/http" +) + +func HandlerWebLog(response http.ResponseWriter, request *http.Request) { + + if Shutdown.IsDown() { + http.NotFound(response, request) + return + } + + data := Scheme.Viewer{} + data.Events = make([]Scheme.LogEvent, 3) + data.Events[0].AB = Scheme.A + data.Events[0].LogLevel = Scheme.LogINFO + data.Events[0].LogLine = `hello world` + data.Title = `Web Log Viewer` + + MimeTypes.Write2HTTP(response, MimeTypes.TypeWebHTML) + if executeError := templates.ExecuteTemplate(response, `WebLog`, data); executeError != nil { + Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameEXECUTE, `Was not able to execute the web log viewer template.`, executeError.Error()) + } +} diff --git a/Log/Web/Init.go b/Log/Web/Init.go new file mode 100644 index 0000000..f991931 --- /dev/null +++ b/Log/Web/Init.go @@ -0,0 +1,19 @@ +package Web + +import ( + "github.com/SommerEngineering/Ocean/Log" + LM "github.com/SommerEngineering/Ocean/Log/Meta" + WebTemp "github.com/SommerEngineering/Ocean/Log/Web/Templates" + "html/template" +) + +func init() { + + Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameINIT, `Init the web log.`) + defer Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameINIT, `Init the web log done.`) + + templates = template.New(`root`) + if _, err := templates.Parse(WebTemp.Viewer); err != nil { + Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactUnknown, LM.MessageNamePARSE, `Was not able to parse the template for the web log viewer.`, err.Error()) + } +} diff --git a/Log/Web/Scheme/Constants.go b/Log/Web/Scheme/Constants.go new file mode 100644 index 0000000..f12d6cb --- /dev/null +++ b/Log/Web/Scheme/Constants.go @@ -0,0 +1,12 @@ +package Scheme + +const ( + A string = `loga` + B string = `logb` + LogWARN = `logwarn` + LogDEBUG = `logdebug` + LogERROR = `logerror` + LogINFO = `loginfo` + LogTALKATIVE = `logtalkative` + LogSECURITY = `logsecurity` +) diff --git a/Log/Web/Templates/Viewer.go b/Log/Web/Templates/Viewer.go index b44e04a..9fe81ea 100644 --- a/Log/Web/Templates/Viewer.go +++ b/Log/Web/Templates/Viewer.go @@ -1,6 +1,7 @@ package Templates var Viewer string = ` +{{define "WebLog"}} @@ -122,4 +123,5 @@ var Viewer string = ` -` + +{{end}}` diff --git a/Log/Web/Variables.go b/Log/Web/Variables.go new file mode 100644 index 0000000..ef1f76e --- /dev/null +++ b/Log/Web/Variables.go @@ -0,0 +1,11 @@ +package Web + +import ( + LM "github.com/SommerEngineering/Ocean/Log/Meta" + "html/template" +) + +var ( + templates *template.Template = nil + senderName LM.Sender = `System::WebLog` +) diff --git a/System/InitHandlers.go b/System/InitHandlers.go index c9136cb..fa86bb4 100644 --- a/System/InitHandlers.go +++ b/System/InitHandlers.go @@ -32,7 +32,7 @@ func InitHandlers() { Handlers.AddAdminHandler(`/next/number`, NumGen.HandlerGetNext) Handlers.AddAdminHandler(`/ICCC`, ICCC.ICCCHandler) Handlers.AddAdminHandler(`/binaryAssets/`, BinaryAssets.HandlerBinaryAssets) - //Handlers.AddAdminHandler(`/log`) + Handlers.AddAdminHandler(`/log`, Web.HandlerWebLog) Handlers.AddAdminHandler(`/log/css/normalize.css`, Web.HandlerCSSNormalize) Handlers.AddAdminHandler(`/log/css/webflow.css`, Web.HandlerCSSWebflow) Handlers.AddAdminHandler(`/log/css/log.css`, Web.HandlerCSSLog) diff --git a/Templates/Init.go b/Templates/Init.go index 9d33324..25957bc 100644 --- a/Templates/Init.go +++ b/Templates/Init.go @@ -54,8 +54,11 @@ func init() { } templateData := string(contentData) - templates.Parse(templateData) - Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameEXECUTE, fmt.Sprintf(`The template '%s' was parsed.`, file.FileInfo().Name())) + if _, err := templates.Parse(templateData); err != nil { + Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityMiddle, LM.ImpactMiddle, LM.MessageNamePARSE, fmt.Sprintf(`The template '%s' cannot be parsed.`, file.FileInfo().Name()), err.Error()) + } else { + Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameEXECUTE, fmt.Sprintf(`The template '%s' was parsed.`, file.FileInfo().Name())) + } } else { Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameDATABASE, `Was not able to open a template.`, file.FileInfo().Name()) }