Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/620#discussion_r122794993
--- Diff:
metron-interface/metron-alerts/src/app/service/save-search.service.ts ---
@@ -0,0 +1,191 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import {Injectable, Inject, } from '@angular/core';
+import {Observable} from 'rxjs/Rx';
+import {Http} from '@angular/http';
+import {Subject} from 'rxjs/Subject';
+
+import {IAppConfig} from '../app.config.interface';
+import {APP_CONFIG} from '../app.config';
+import {ALERTS_SAVED_SEARCH, ALERTS_RECENT_SEARCH, NUM_SAVED_SEARCH} from
'../utils/constants';
+import {QueryBuilder} from '../model/query-builder';
+import {SaveSearch} from '../model/save-search';
+import {ColumnMetadata} from '../model/column-metadata';
+
+@Injectable()
+export class SaveSearchService {
+
+ queryBuilder: QueryBuilder;
+ tableColumns: ColumnMetadata[];
+
+ private loadSavedSearch = new Subject<SaveSearch>();
+ loadSavedSearch$ = this.loadSavedSearch.asObservable();
+ defaultHeaders = {'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'};
+
+ constructor(private http: Http, @Inject(APP_CONFIG) private config:
IAppConfig) {
+ }
+
+ deleteRecentSearch(saveSearch: SaveSearch): Observable<{}> {
+ return Observable.create(observer => {
+ let recentSearches: SaveSearch[] = [];
+ try {
+ recentSearches =
JSON.parse(localStorage.getItem(ALERTS_RECENT_SEARCH));
+ recentSearches = recentSearches.filter(search => search.name !==
saveSearch.name);
+ } catch (e) {}
+
+ localStorage.setItem(ALERTS_RECENT_SEARCH,
JSON.stringify(recentSearches));
+
+ observer.next({});
+ observer.complete();
+
+ });
+ }
+
+ deleteSavedSearch(saveSearch: SaveSearch): Observable<{}> {
+ return Observable.create(observer => {
+ let savedSearches: SaveSearch[] = [];
+ try {
+ savedSearches =
JSON.parse(localStorage.getItem(ALERTS_SAVED_SEARCH));
--- End diff --
This appears to be hard-coded to use local storage, can we make an
indirection layer to handle CRUD operations around saved searches? We likely
will want that to be something other than local storage going forward, right?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---