Adds in functionality to remove items from the saved searches - Thanks Dan Booth
Co-authored-by: Dan Booth <dan@diplo.co.uk> Co-authored-by: Warren Buckley <warren@umbraco.com>
This commit is contained in:
@@ -19,10 +19,15 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
IEnumerable<SavedLogSearch> GetSavedSearches();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new saved search to chosen datasource
|
||||
/// Adds a new saved search to chosen datasource and returns the updated searches
|
||||
/// </summary>
|
||||
IEnumerable<SavedLogSearch> AddSavedSearch(string name, string query);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a saved search to chosen datasource and returns the remaining searches
|
||||
/// </summary>
|
||||
IEnumerable<SavedLogSearch> DeleteSavedSearch(string name, string query);
|
||||
|
||||
/// <summary>
|
||||
/// A count of number of errors
|
||||
/// By counting Warnings with Exceptions, Errors & Fatal messages
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
{
|
||||
public class JsonLogViewer : LogViewerSourceBase
|
||||
{
|
||||
|
||||
private static readonly string SearchesConfigPath = IOHelper.MapPath("~/Config/logviewer.searches.config.js");
|
||||
|
||||
public override IEnumerable<LogEvent> GetAllLogs(DateTimeOffset startDate, DateTimeOffset endDate)
|
||||
{
|
||||
var logs = new List<LogEvent>();
|
||||
@@ -32,7 +33,7 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
var filesForCurrentDay = Directory.GetFiles(logDirectory, filesToFind);
|
||||
|
||||
//Foreach file we find - open it
|
||||
foreach(var filePath in filesForCurrentDay)
|
||||
foreach (var filePath in filesForCurrentDay)
|
||||
{
|
||||
//Open log file & add contents to the log collection
|
||||
//Which we then use LINQ to page over
|
||||
@@ -50,20 +51,18 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return logs;
|
||||
}
|
||||
|
||||
public override IEnumerable<SavedLogSearch> GetSavedSearches()
|
||||
{
|
||||
//Our default implementation
|
||||
//Open JSON file on disk and return serialize obj back
|
||||
var path = IOHelper.MapPath("~/Config/logviewer.searches.config.js");
|
||||
|
||||
//If file does not exist - lets create it with an empty array
|
||||
IOHelper.EnsureFileExists(path, "[]");
|
||||
IOHelper.EnsureFileExists(SearchesConfigPath, "[]");
|
||||
|
||||
var rawJson = File.ReadAllText(path);
|
||||
var rawJson = File.ReadAllText(SearchesConfigPath);
|
||||
return JsonConvert.DeserializeObject<IEnumerable<SavedLogSearch>>(rawJson);
|
||||
}
|
||||
|
||||
@@ -78,19 +77,33 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
//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, "[]");
|
||||
IOHelper.EnsureFileExists(SearchesConfigPath, "[]");
|
||||
|
||||
//Write it back down to file
|
||||
File.WriteAllText(path, rawJson);
|
||||
File.WriteAllText(SearchesConfigPath, 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;
|
||||
|
||||
}
|
||||
|
||||
public override IEnumerable<SavedLogSearch> DeleteSavedSearch(string name, string query)
|
||||
{
|
||||
//Get the existing items
|
||||
var searches = GetSavedSearches().ToList();
|
||||
|
||||
//Removes the search
|
||||
searches.RemoveAll(s => s.Name.Equals(name) && s.Query.Equals(query));
|
||||
|
||||
//Serilaize to JSON string
|
||||
var rawJson = JsonConvert.SerializeObject(searches, Formatting.Indented);
|
||||
|
||||
//Write it back down to file
|
||||
File.WriteAllText(SearchesConfigPath, rawJson);
|
||||
|
||||
//Return the updated object - so we can instantly reset the entire array from the API response
|
||||
return searches;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
|
||||
public abstract IEnumerable<SavedLogSearch> AddSavedSearch(string name, string query);
|
||||
|
||||
public abstract IEnumerable<SavedLogSearch> DeleteSavedSearch(string name, string query);
|
||||
|
||||
public int GetNumberOfErrors(DateTimeOffset startDate, DateTimeOffset endDate)
|
||||
{
|
||||
var logs = GetAllLogs(startDate, endDate);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//the factory object returned
|
||||
return {
|
||||
|
||||
getNumberOfErrors: function(){
|
||||
getNumberOfErrors: function () {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl(
|
||||
@@ -19,7 +19,7 @@
|
||||
'Failed to retrieve number of errors in logs');
|
||||
},
|
||||
|
||||
getLogLevelCounts: function(){
|
||||
getLogLevelCounts: function () {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl(
|
||||
@@ -28,7 +28,7 @@
|
||||
'Failed to retrieve log level counts');
|
||||
},
|
||||
|
||||
getMessageTemplates: function(){
|
||||
getMessageTemplates: function () {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl(
|
||||
@@ -37,7 +37,7 @@
|
||||
'Failed to retrieve log templates');
|
||||
},
|
||||
|
||||
getSavedSearches: function(){
|
||||
getSavedSearches: function () {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl(
|
||||
@@ -46,20 +46,25 @@
|
||||
'Failed to retrieve saved searches');
|
||||
},
|
||||
|
||||
postSavedSearch: function(name, query){
|
||||
postSavedSearch: function (name, query) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"logViewerApiBaseUrl",
|
||||
"PostSavedSearch"), {'name': name, 'query': query }),
|
||||
"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){
|
||||
deleteSavedSearch: function (name, query) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"logViewerApiBaseUrl",
|
||||
"DeleteSavedSearch"), { 'name': name, 'query': query }),
|
||||
'Failed to delete saved search');
|
||||
},
|
||||
|
||||
getLogs: function (options) {
|
||||
|
||||
var defaults = {
|
||||
pageSize: 100,
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
vm.findItem = findItem;
|
||||
vm.checkForSavedSearch = checkForSavedSearch;
|
||||
vm.addToSavedSearches = addToSavedSearches;
|
||||
vm.deleteSavedSearch = deleteSavedSearch;
|
||||
vm.back = back;
|
||||
|
||||
|
||||
@@ -272,9 +273,7 @@
|
||||
//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;
|
||||
|
||||
overlayService.close();
|
||||
});
|
||||
},
|
||||
@@ -284,7 +283,12 @@
|
||||
};
|
||||
|
||||
overlayService.open(overlay);
|
||||
}
|
||||
|
||||
function deleteSavedSearch(model) {
|
||||
logViewerResource.deleteSavedSearch(model.name, model.query).then(function (data) {
|
||||
vm.searches = data;
|
||||
});
|
||||
}
|
||||
|
||||
function back() {
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
<span class="umb-variant-switcher__name">{{search.name}}</span>
|
||||
<span>{{ search.query }}</span>
|
||||
</a>
|
||||
<a href=""><span><i class="icon icon-trash text-error" title="Delete this search" ng-click="vm.deleteSavedSearch(search)"></i></span></a>
|
||||
</umb-dropdown-item>
|
||||
</umb-dropdown>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Http;
|
||||
using Umbraco.Core.Logging.Viewer;
|
||||
@@ -27,7 +26,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
return _logViewer.GetNumberOfErrors(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public LogLevelCounts GetLogLevelCounts()
|
||||
{
|
||||
@@ -58,5 +57,11 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
return _logViewer.AddSavedSearch(item.Name, item.Query);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IEnumerable<SavedLogSearch> DeleteSavedSearch(SavedLogSearch item)
|
||||
{
|
||||
return _logViewer.DeleteSavedSearch(item.Name, item.Query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user