refactor so-mon-ui code
[so.git] / so-monitoring / so-monitoring-ui / src / main / frontend / src / app / model / searchData.model.ts
index 4552590..a948eb7 100644 (file)
-import { ToastrNotificationService } from "../toastr-notification-service.service";\r
-\r
-/**\r
-============LICENSE_START=======================================================\r
- Copyright (C) 2018 Ericsson. All rights reserved.\r
-================================================================================\r
-Licensed under the Apache License, Version 2.0 (the "License");\r
-you may not use this file except in compliance with the License.\r
-You may obtain a copy of the License at\r
-\r
-    http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-Unless required by applicable law or agreed to in writing, software\r
-distributed under the License is distributed on an "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-See the License for the specific language governing permissions and\r
- limitations under the License.\r
-\r
-SPDX-License-Identifier: Apache-2.0\r
-============LICENSE_END=========================================================\r
-\r
-@authors: ronan.kenny@ericsson.com, waqas.ikram@ericsson.com\r
-*/\r
-\r
-import { Observable, throwError, of } from 'rxjs';\r
-import { SearchRequest } from "./SearchRequest.model";\r
-export class SearchData {\r
-\r
-  public selectedValueSII = "EQ";\r
-  public selectedValueRI = "EQ";\r
-  public selectedValueSN = "EQ";\r
-  public selectedValueSTATUS = "ALL";\r
-\r
-  private now = Date.now();\r
-  // Minus 1 hour from current time for start date\r
-  public startDate = new Date(this.now - (1 * 60 * 60 * 1000));\r
-  public selectedStartHour = this.getNumberAsString(this.startDate.getHours());\r
-  public selectedStartMinute = this.getNumberAsString(this.startDate.getMinutes());\r
-\r
-  public endDate = new Date(this.now);\r
-  public selectedEndHour = this.getNumberAsString(this.endDate.getHours());\r
-  public selectedEndMinute = this.getNumberAsString(this.endDate.getMinutes());\r
-\r
-\r
-  public serviceInstanceId: string;\r
-  public requestId: string;\r
-  public serviceInstanceName: string;\r
-\r
-  private startTimeInMilliseconds: number;\r
-  private endTimeInMilliseconds: number;\r
-\r
-  constructor() {\r
-  }\r
-\r
-  public getSearchRequest(): Observable<SearchRequest> {\r
-    var searchFields = {};\r
-    if ((!this.startDate || this.startDate === null) || (!this.endDate || this.endDate === null)) {\r
-      console.error("Found either start time or end time null or undefined");\r
-      return throwError("Found end or start date empty, Please enter start and end date");\r
-    }\r
-\r
-    this.startDate.setHours(parseInt(this.selectedStartHour));\r
-    this.startDate.setMinutes(parseInt(this.selectedStartMinute));\r
-\r
-    this.endDate.setHours(parseInt(this.selectedEndHour));\r
-    this.endDate.setMinutes(parseInt(this.selectedEndMinute));\r
-\r
-    this.startTimeInMilliseconds = this.startDate.getTime();\r
-    this.endTimeInMilliseconds = this.endDate.getTime();\r
-\r
-    if (this.startTimeInMilliseconds > this.endTimeInMilliseconds) {\r
-      console.error("End time: " + this.endDate + " can not be greater then start time: " + this.startDate);\r
-      return throwError("End time: " + this.endDate + " can not be greater then start time: " + this.startDate);\r
-    }\r
-\r
-\r
-    if (!this.isEmpty(this.selectedValueSII) && !this.isEmpty(this.serviceInstanceId)) {\r
-      searchFields["serviceInstanceId"] = [this.selectedValueSII, this.serviceInstanceId]\r
-    }\r
-    if (!this.isEmpty(this.selectedValueRI) && !this.isEmpty(this.requestId)) {\r
-      searchFields["requestId"] = [this.selectedValueRI, this.requestId]\r
-    }\r
-    if (!this.isEmpty(this.selectedValueSN) && !this.isEmpty(this.serviceInstanceName)) {\r
-      searchFields["serviceInstanceName"] = [this.selectedValueSN, this.serviceInstanceName]\r
-    }\r
-\r
-    if (!this.isEmpty(this.selectedValueSTATUS) && this.selectedValueSTATUS !== "ALL") {\r
-      searchFields["requestStatus"] = ["EQ", this.selectedValueSTATUS]\r
-    }\r
-\r
-    return of(new SearchRequest(searchFields, this.startTimeInMilliseconds, this.endTimeInMilliseconds));\r
-  }\r
-\r
-  private isEmpty(str) {\r
-    return (!str || 0 === str.length);\r
-  }\r
-\r
-  private getNumberAsString(num: number) {\r
-    if (num <= 9) {\r
-      return "0" + num;\r
-    }\r
-    return "" + num;\r
-  }\r
-\r
-}\r
+import { ToastrNotificationService } from "../toastr-notification-service.service";
+
+/**
+============LICENSE_START=======================================================
+ Copyright (C) 2018 Ericsson. All rights reserved.
+================================================================================
+Licensed 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.
+
+SPDX-License-Identifier: Apache-2.0
+============LICENSE_END=========================================================
+
+@authors: ronan.kenny@ericsson.com, waqas.ikram@ericsson.com
+*/
+
+import { Observable, throwError, of } from 'rxjs';
+import { SearchRequest } from "./SearchRequest.model";
+import { Input } from "@angular/core";
+
+export class SearchData {
+
+  @Input() selectedValueSII = "EQ";
+  @Input() selectedValueRI = "EQ";
+  @Input() selectedValueSN = "EQ";
+  @Input() selectedValueSTATUS = "ALL";
+
+  private now = Date.now();
+  // Minus 1 hour from current time for start date
+  @Input() startDate = new Date(this.now - (1 * 60 * 60 * 1000));
+  @Input() selectedStartHour = this.getNumberAsString(this.startDate.getHours());
+  @Input() selectedStartMinute = this.getNumberAsString(this.startDate.getMinutes());
+
+  @Input() endDate = new Date(this.now);
+  @Input() selectedEndHour = this.getNumberAsString(this.endDate.getHours());
+  @Input() selectedEndMinute = this.getNumberAsString(this.endDate.getMinutes());
+
+
+  @Input() serviceInstanceId: string;
+  @Input() requestId: string;
+  @Input() serviceInstanceName: string;
+
+  private startTimeInMilliseconds: number;
+  private endTimeInMilliseconds: number;
+
+  constructor() {
+  }
+
+  public getSearchRequest(): Observable<SearchRequest> {
+    var searchFields = {};
+    if ((!this.startDate || this.startDate === null) || (!this.endDate || this.endDate === null)) {
+      console.error("Found either start time or end time null or undefined");
+      return throwError("Found end or start date empty, Please enter start and end date");
+    }
+
+    this.startDate.setHours(parseInt(this.selectedStartHour));
+    this.startDate.setMinutes(parseInt(this.selectedStartMinute));
+
+    this.endDate.setHours(parseInt(this.selectedEndHour));
+    this.endDate.setMinutes(parseInt(this.selectedEndMinute));
+
+    this.startTimeInMilliseconds = this.startDate.getTime();
+    this.endTimeInMilliseconds = this.endDate.getTime();
+
+    if (this.startTimeInMilliseconds > this.endTimeInMilliseconds) {
+      console.error("End time: " + this.endDate + " can not be greater then start time: " + this.startDate);
+      return throwError("End time: " + this.endDate + " can not be greater then start time: " + this.startDate);
+    }
+
+
+    if (!this.isEmpty(this.selectedValueSII) && !this.isEmpty(this.serviceInstanceId)) {
+      searchFields["serviceInstanceId"] = [this.selectedValueSII, this.serviceInstanceId]
+    }
+    if (!this.isEmpty(this.selectedValueRI) && !this.isEmpty(this.requestId)) {
+      searchFields["requestId"] = [this.selectedValueRI, this.requestId]
+    }
+    if (!this.isEmpty(this.selectedValueSN) && !this.isEmpty(this.serviceInstanceName)) {
+      searchFields["serviceInstanceName"] = [this.selectedValueSN, this.serviceInstanceName]
+    }
+
+    if (!this.isEmpty(this.selectedValueSTATUS) && this.selectedValueSTATUS !== "ALL") {
+      searchFields["requestStatus"] = ["EQ", this.selectedValueSTATUS]
+    }
+
+    return of(new SearchRequest(searchFields, this.startTimeInMilliseconds, this.endTimeInMilliseconds));
+  }
+
+  private isEmpty(str) {
+    return (!str || 0 === str.length);
+  }
+
+  private getNumberAsString(num: number) {
+    if (num <= 9) {
+      return "0" + num;
+    }
+    return "" + num;
+  }
+
+}