diff --git a/src/Umbraco.Core/Logging/Viewer/ILogViewer.cs b/src/Umbraco.Core/Logging/Viewer/ILogViewer.cs index 16568bfef3..4ab3a9f6bd 100644 --- a/src/Umbraco.Core/Logging/Viewer/ILogViewer.cs +++ b/src/Umbraco.Core/Logging/Viewer/ILogViewer.cs @@ -18,6 +18,11 @@ namespace Umbraco.Core.Logging.Viewer /// IEnumerable GetSavedSearches(); + /// + /// Adds a new saved search to chosen datasource + /// + IEnumerable AddSavedSearch(string name, string query); + /// /// A count of number of errors /// By counting Warnings with Exceptions, Errors & Fatal messages diff --git a/src/Umbraco.Core/Logging/Viewer/JsonLogViewer.cs b/src/Umbraco.Core/Logging/Viewer/JsonLogViewer.cs index 60166669e1..1f0faf1d40 100644 --- a/src/Umbraco.Core/Logging/Viewer/JsonLogViewer.cs +++ b/src/Umbraco.Core/Logging/Viewer/JsonLogViewer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Newtonsoft.Json; using Serilog.Events; using Serilog.Formatting.Compact.Reader; @@ -65,5 +66,31 @@ namespace Umbraco.Core.Logging.Viewer var rawJson = File.ReadAllText(path); return JsonConvert.DeserializeObject>(rawJson); } + + public override IEnumerable AddSavedSearch(string name, string query) + { + //Get the existing items + var searches = GetSavedSearches().ToList(); + + //Add the new item to the bottom of the list + searches.Add(new SavedLogSearch { Name = name, Query = query }); + + //Serilaize to JSON string + var rawJson = JsonConvert.SerializeObject(searches, Formatting.Indented); + + //Open file & save contents + var path = IOHelper.MapPath("~/Config/logviewer.searches.config.js"); + + //If file does not exist - lets create it with an empty array + IOHelper.EnsureFileExists(path, "[]"); + + //Write it back down to file + File.WriteAllText(path, rawJson); + + //Return the updated object - so we can instantly reset the entire array from the API response + //As opposed to push a new item into the array + return searches; + + } } } diff --git a/src/Umbraco.Core/Logging/Viewer/LogViewerSourceBase.cs b/src/Umbraco.Core/Logging/Viewer/LogViewerSourceBase.cs index 3aee40dd10..07fee47fa1 100644 --- a/src/Umbraco.Core/Logging/Viewer/LogViewerSourceBase.cs +++ b/src/Umbraco.Core/Logging/Viewer/LogViewerSourceBase.cs @@ -14,6 +14,8 @@ namespace Umbraco.Core.Logging.Viewer public abstract IEnumerable GetSavedSearches(); + public abstract IEnumerable AddSavedSearch(string name, string query); + public int GetNumberOfErrors(DateTimeOffset startDate, DateTimeOffset endDate) { var logs = GetAllLogs(startDate, endDate); diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/logviewer.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/logviewer.resource.js index 4bc5cf42b4..1182901d6b 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/logviewer.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/logviewer.resource.js @@ -46,6 +46,19 @@ 'Failed to retrieve saved searches'); }, + postSavedSearch: function(name, query){ + return umbRequestHelper.resourcePromise( + $http.post( + umbRequestHelper.getApiUrl( + "logViewerApiBaseUrl", + "PostSavedSearch"), {'name': name, 'query': query }), + 'Failed to add new saved search'); + + return umbRequestHelper.resourcePromise( + $http.post(umbRequestHelper.getApiUrl("dataTypeApiBaseUrl", "PostSave"), saveModel), + "Failed to save data for data type id " + dataType.id); + }, + getLogs: function(options){ var defaults = { diff --git a/src/Umbraco.Web.UI.Client/src/views/logviewer/overview.controller.js b/src/Umbraco.Web.UI.Client/src/views/logviewer/overview.controller.js index 25ddbda16a..475ff48d9c 100644 --- a/src/Umbraco.Web.UI.Client/src/views/logviewer/overview.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/logviewer/overview.controller.js @@ -306,17 +306,14 @@ view: "logviewersearch", queryToSave: vm.logOptions.filterExpression, submit: function (model) { - overlayService.close(); - //Resource call with two params (name & query) //API that opens the JSON and adds it to the bottom + logViewerResource.postSavedSearch(model.queryName, model.queryToSave).then(function(data){ + console.log('search after add', data); + vm.searches = data; - //model.queryName - //model.queryToSave - - //Once OK from API - push it into existing vm.searches array - vm.searches.push({'name': model.queryName, 'query': model.queryToSave}); - + overlayService.close(); + }); }, close: function() { overlayService.close(); diff --git a/src/Umbraco.Web.UI/config/logviewer.searches.config.js b/src/Umbraco.Web.UI/config/logviewer.searches.config.js index 88f134edc1..cc5cd845ae 100644 --- a/src/Umbraco.Web.UI/config/logviewer.searches.config.js +++ b/src/Umbraco.Web.UI/config/logviewer.searches.config.js @@ -1,34 +1,34 @@ -[ - { - "name": "Find all logs where the Level is NOT Verbose and NOT Debug", - "query": "Not(@Level='Verbose') and Not(@Level='Debug')" - }, - { - "name": "Find all logs that has an exception property (Warning, Error & Critical with Exceptions)", - "query": "Has(@Exception)" - }, - { - "name": "Find all logs that have the property 'TimingDuration'", - "query": "Has(TimingDuration)" - }, - { - "name": "Find all logs that have the property 'TimingDuration' and the duration is greater than 1000ms", - "query": "Has(TimingDuration) and TimingDuration > 1000" - }, - { - "name": "Find all logs that are from the namespace 'Umbraco.Core'", - "query": "StartsWith(SourceContext, 'Umbraco.Core')" - }, - { - "name": "Find all logs that use a specific log message template", - "query": "@MessageTemplate = '[Timing {TimingId}] {EndMessage} ({TimingDuration}ms)'" - }, - { - "name": "Find logs where one of the items in the SortedComponentTypes property array is equal to", - "query": "SortedComponentTypes[?] = 'Umbraco.Web.Search.ExamineComponent'" - }, - { - "name": "Find logs where one of the items in the SortedComponentTypes property array contains", - "query": "Contains(SortedComponentTypes[?], 'DatabaseServer')" - } +[ + { + "name": "Find all logs where the Level is NOT Verbose and NOT Debug", + "query": "Not(@Level='Verbose') and Not(@Level='Debug')" + }, + { + "name": "Find all logs that has an exception property (Warning, Error & Critical with Exceptions)", + "query": "Has(@Exception)" + }, + { + "name": "Find all logs that have the property 'TimingDuration'", + "query": "Has(TimingDuration)" + }, + { + "name": "Find all logs that have the property 'TimingDuration' and the duration is greater than 1000ms", + "query": "Has(TimingDuration) and TimingDuration > 1000" + }, + { + "name": "Find all logs that are from the namespace 'Umbraco.Core'", + "query": "StartsWith(SourceContext, 'Umbraco.Core')" + }, + { + "name": "Find all logs that use a specific log message template", + "query": "@MessageTemplate = '[Timing {TimingId}] {EndMessage} ({TimingDuration}ms)'" + }, + { + "name": "Find logs where one of the items in the SortedComponentTypes property array is equal to", + "query": "SortedComponentTypes[?] = 'Umbraco.Web.Search.ExamineComponent'" + }, + { + "name": "Find logs where one of the items in the SortedComponentTypes property array contains", + "query": "Contains(SortedComponentTypes[?], 'DatabaseServer')" + } ]