From d8dacc1799bc45ad052685d12d5d56630d2bf829 Mon Sep 17 00:00:00 2001 From: MelsHyrule Date: Wed, 26 Oct 2022 17:04:18 -0400 Subject: [PATCH] Cleaned up --- .../application_controller/timelines.rb | 6 -- .../timelines/options.rb | 17 ---- .../components/timeline-options/helper.js | 2 + .../timeline-options/timeline-options.jsx | 74 ++------------- app/javascript/oldjs/controllers/index.js | 1 - .../timeline/timeline_options_controller.js | 89 ------------------- app/javascript/oldjs/miq_timeline.js | 3 +- app/views/layouts/_timeline.html.haml | 1 - app/views/layouts/_tl_show.html.haml | 11 +-- 9 files changed, 11 insertions(+), 193 deletions(-) delete mode 100644 app/javascript/oldjs/controllers/timeline/timeline_options_controller.js diff --git a/app/controllers/application_controller/timelines.rb b/app/controllers/application_controller/timelines.rb index e6069e4c23b4..e227e78fcc5e 100644 --- a/app/controllers/application_controller/timelines.rb +++ b/app/controllers/application_controller/timelines.rb @@ -3,15 +3,10 @@ module ApplicationController::Timelines # Process changes to timeline selection def tl_chooser - require 'byebug' - # byebug @record = identify_tl_or_perf_record @tl_record = @record # Use related server vm record tl_build_timeline @tl_options.date.update_from_params(params) - p "mels geting params" - p params - ## #"timeline", "tl_categories"=>["Configuration/Reconfiguration", "Console Activity", "Creation/Addition", "Deletion/Removal", "Devices", "Firmware", "General Activity", "Import/Export", "Login", "Migration/Vmotion", "Network", "Power Activity", "Security", "Snapshot Activity", "Status", "Storage", "Update"], "tl_timerange"=>"months", "tl_timepivot"=>"centered", "tl_result"=>"success", "tl_range_count"=>"2", "tl_date"=>"Sun Oct 02 2022 00:00:00 GMT-0400 (Eastern Daylight Time)", "tl_levels"=>["critical", "detail", "warning"], "tl_typ"=>"Daily", "tl_days"=>"60", "miq_date"=>"11/01/2022", "controller"=>"host", "action"=>"tl_chooser", "id"=>"9"} permitted: false> if @tl_options.management_events? @tl_options.management.update_from_params(params) @@ -182,7 +177,6 @@ def tl_gen_timeline_data(refresh = nil) else @report.extras[:browser_name] = browser_info(:name) @tl_json = @report.to_timeline - # # START of TIMELINE TIMEZONE Code session[:tl_position] = @report.extras[:tl_position] # session[:tl_position] = format_timezone(@report.extras[:tl_position],Time.zone,"tl") diff --git a/app/controllers/application_controller/timelines/options.rb b/app/controllers/application_controller/timelines/options.rb index 4f0a6b2ff248..55dcbcd002a3 100644 --- a/app/controllers/application_controller/timelines/options.rb +++ b/app/controllers/application_controller/timelines/options.rb @@ -33,20 +33,9 @@ def update_start_end(sdate, edate) def update_from_params(params) self.levels = params[:tl_levels]&.map(&:to_sym) || group_levels self.categories = {} - require 'byebug' - p "mels v1" params.fetch(:tl_categories, []).each do |category_display_name| - # category_display_name.to_sym next if category_display_name == "Other" group_data = event_groups[events[category_display_name]] - - if group_data === nil - p "mels inside the group data nil check" - p category_display_name # in the "Other" case - p events[category_display_name] # this and the below are nil - p event_groups[events[category_display_name]] - end - category = { :display_name => category_display_name, :include_set => [], @@ -54,12 +43,7 @@ def update_from_params(params) :regexes => [] } - # byebug - group_levels.each do |lvl| - p "mels hyrule group_data[lvl]" - p group_data # there is a case wehre group data turns up nil - p lvl next unless group_data[lvl] strings, regexes = group_data[lvl].partition { |typ| typ.kind_of?(String) } @@ -72,7 +56,6 @@ def update_from_params(params) end next if category[:include_set].empty? && category[:regexes].empty? - # category_display_name.to_sym categories[events[category_display_name]] = category end end diff --git a/app/javascript/components/timeline-options/helper.js b/app/javascript/components/timeline-options/helper.js index c60499bcfc45..37792967b79b 100644 --- a/app/javascript/components/timeline-options/helper.js +++ b/app/javascript/components/timeline-options/helper.js @@ -1,3 +1,5 @@ +// File can be safely deleted but ill leave it here for now, for good luck + export const tempData = { // 1 week "tl_show": "timeline", "tl_categories": [ diff --git a/app/javascript/components/timeline-options/timeline-options.jsx b/app/javascript/components/timeline-options/timeline-options.jsx index b782cce4f614..ae61038c914a 100644 --- a/app/javascript/components/timeline-options/timeline-options.jsx +++ b/app/javascript/components/timeline-options/timeline-options.jsx @@ -1,49 +1,9 @@ import React, { useState, useEffect } from 'react'; import MiqFormRenderer from '@@ddf'; import createSchemaSimple from './timeline-options-simple.schema'; -import miqRedirectBack from '../../helpers/miq-redirect-back'; import mapper from '../../forms/mappers/componentMapper'; -import { tableData, buildUr, tempData } from './helper'; -import MiqDataTable from '../miq-data-table'; -import NoRecordsFound from '../no-records-found'; -// const tempData1 = { // 1 week -// "tl_show": "timeline", -// "tl_categories": [ -// "Configuration/Reconfiguration", -// "Console Activity", -// "Creation/Addition", -// "Deletion/Removal", -// "Devices", -// "Firmware", -// "General Activity", -// "Import/Export", -// "Login", -// "Migration/Vmotion", -// "Network", -// "Power Activity", -// "Security", -// "Snapshot Activity", -// "Status", -// "Storage", -// "Update" -// ], -// "tl_timerange": "weeks", -// "tl_timepivot": "ending", -// "tl_result": "success", // set by thing not actually ever updated -// "tl_range_count": 1, -// "tl_date": "2022-10-18T04:00:00.000Z", //chosen date -// "tl_levels": [ -// "critical", -// "detail", -// "warning" -// ], -// "tl_typ": "Daily", -// "tl_days": 7, -// "miq_date": "10/18/2022" -// } - -const TimelineOptions = ({ url, recordId }) => { +const TimelineOptions = ({ url }) => { const [{ isLoading, timelineEvents, managementGroupNames, managementGroupLevels, policyGroupNames, policyGroupLevels, tableContent, }, setState] = useState({ @@ -82,7 +42,7 @@ const TimelineOptions = ({ url, recordId }) => { policyGroupLevels.push({ label: value, value: key }); }); - // TODO: is there a way to make the above more elegant/shorter + // TODO: is there a way to make the above more elegant/shorter? setState((state) => ({ ...state, isLoading: false, @@ -101,18 +61,14 @@ const TimelineOptions = ({ url, recordId }) => { let show = values.timelineEvents === 'EmsEvent' ? "timeline" : "policy_timeline" let categories = values.timelineEvents === 'EmsEvent' ? values.managementGroupNames : values.policyGroupNames let result = values.timelineEvents === 'EmsEvent' ? values.managementGroupLevels : values.policyGroupLevels - - // detemining what we need by looking at /app/controllers/application_controller/timelines/options.rb - let vmData = { // 1 week - "tl_show": show, // i think its "timeline" or "policy_timeline" - "tl_categories": categories, // we're gonna test passing in the lable not the id for now + let vmData = { + "tl_show": show, + "tl_categories": categories, "tl_levels": result, - "tl_result": "success", // set by thing not actually ever updated i think, also defaults to success + "tl_result": "success", } - window.ManageIQ.calendar.calDateFrom = values.startDate window.ManageIQ.calendar.calDateTo = values.endDate - window.miqJqueryRequest(url, {beforeSend: true, data: vmData}); }; @@ -123,22 +79,6 @@ const TimelineOptions = ({ url, recordId }) => { })); }; - const exitPage = () => { - miqSparkleOn(); - const returnURL = '/vm_infra/explorer/'; - const message = sprintf(__('Returned to previous page')); - // miqRedirectBack(message, 'warning', returnURL); // esot explota fix it - }; - - const miqTableContent = tableContent.rows.length > 0 ? ( - {}} - mode="db-list" - /> - ) : ; - return !isLoading && ( <> { timelineEvents, managementGroupNames, managementGroupLevels, policyGroupNames, policyGroupLevels, )} onSubmit={onSubmit} - // onCancel={exitPage} onReset={onReset} canReset /> - {/* <>{miqTableContent} */} ); }; diff --git a/app/javascript/oldjs/controllers/index.js b/app/javascript/oldjs/controllers/index.js index 73df93173079..196cd26008dd 100644 --- a/app/javascript/oldjs/controllers/index.js +++ b/app/javascript/oldjs/controllers/index.js @@ -18,6 +18,5 @@ require('./ops/pglogical_replication_form_controller.js'); require('./playbook-reusable-code-mixin.js'); require('./reconfigure/reconfigure_form_controller.js'); require('./schedule/schedule_form_controller.js'); -require('./timeline/timeline_options_controller.js'); // delete later require('./tree_view_controller.js'); require('./vm_cloud/vm_cloud_live_migrate_form_controller.js'); diff --git a/app/javascript/oldjs/controllers/timeline/timeline_options_controller.js b/app/javascript/oldjs/controllers/timeline/timeline_options_controller.js deleted file mode 100644 index eebbae843127..000000000000 --- a/app/javascript/oldjs/controllers/timeline/timeline_options_controller.js +++ /dev/null @@ -1,89 +0,0 @@ -ManageIQ.angular.app.controller('timelineOptionsController', ['miqService', 'url', 'categories', '$scope', function(miqService, url, categories, $scope) { - var vm = this; - var init = function() { - vm.reportModel = { - tl_show: 'timeline', - tl_categories: ['Power Activity'], - tl_timerange: 'weeks', - tl_timepivot: 'ending', - tl_result: 'success', - tl_range_count: 1, - tl_date: new Date(ManageIQ.calendar.calDateTo), - }; - - vm.afterGet = true; - vm.dateOptions = { - autoclose: true, - todayHighlight: true, - orientation: 'bottom', - }; - ManageIQ.angular.scope = $scope; - vm.availableCategories = categories; - }; - - vm.clearLevelsIfNotSelected = function() { - if (vm.reportModel.tl_categories.length === 0) { - vm.reportModel.tl_levels = undefined; - } - }; - - vm.eventTypeUpdated = function() { - vm.reportModel.tl_categories = []; - }; - - vm.countDecrement = function() { - if (vm.reportModel.tl_range_count > 1) { - vm.reportModel.tl_range_count--; - } - }; - - vm.countIncrement = function() { - vm.reportModel.tl_range_count++; - }; - - vm.applyButtonClicked = function() { - if (vm.reportModel.tl_categories.length === 0) { - return; - } - - // process selections - if (vm.reportModel.tl_timerange === 'days') { - vm.reportModel.tl_typ = 'Hourly'; - vm.reportModel.tl_days = vm.reportModel.tl_range_count; - } else { - vm.reportModel.tl_typ = 'Daily'; - if (vm.reportModel.tl_timerange === 'weeks') { - vm.reportModel.tl_days = vm.reportModel.tl_range_count * 7; - } else { - vm.reportModel.tl_days = vm.reportModel.tl_range_count * 30; - } - } - - var selectedDay = moment(vm.reportModel.tl_date); - var startDay = selectedDay.clone(); - var endDay = selectedDay.clone(); - - if (vm.reportModel.tl_timepivot === 'starting') { - endDay.add(vm.reportModel.tl_days, 'days').toDate(); - vm.reportModel.miq_date = endDay.format('MM/DD/YYYY'); - } else if (vm.reportModel.tl_timepivot === 'centered') { - var enddays = Math.ceil(vm.reportModel.tl_days / 2); - startDay.subtract(enddays, 'days').toDate(); - endDay.add(enddays, 'days').toDate(); - vm.reportModel.miq_date = endDay.format('MM/DD/YYYY'); - } else if (vm.reportModel.tl_timepivot === 'ending') { - startDay.subtract(vm.reportModel.tl_days, 'days'); - vm.reportModel.miq_date = endDay.format('MM/DD/YYYY'); - } - ManageIQ.calendar.calDateFrom = startDay.toDate(); - ManageIQ.calendar.calDateTo = endDay.toDate(); - miqService.sparkleOn(); - - console.log(vm.reportModel) - console.log(miqService.serializeModel(vm.reportModel)) - // temp restores we need to delte this later tho - miqService.miqAsyncAjaxButton(url, miqService.serializeModel(vm.reportModel)); - }; - - init(); -}]); diff --git a/app/javascript/oldjs/miq_timeline.js b/app/javascript/oldjs/miq_timeline.js index 6bf87f500c7b..30c5c66e48f2 100644 --- a/app/javascript/oldjs/miq_timeline.js +++ b/app/javascript/oldjs/miq_timeline.js @@ -171,6 +171,7 @@ }; })(ManageIQ); +// TODO: Convert this file to React window.miqInitTimeline = function(json) { if (!json) { return; @@ -180,8 +181,6 @@ window.miqInitTimeline = function(json) { var start; var end; - // i think this says if we dont set these values we default to today (or whatever the global variable has been previously set to) - // but im not seeing that behavior, i honeslty cant tell how the dates are set here but we can leave that for last if (!ManageIQ.calendar.calDateFrom || !ManageIQ.calendar.calDateTo) { end = new Date(); start = new Date(end - 24 * 60 * 60 * 1000 * 7); diff --git a/app/views/layouts/_timeline.html.haml b/app/views/layouts/_timeline.html.haml index 720e8e54f260..3ad33f541fa3 100644 --- a/app/views/layouts/_timeline.html.haml +++ b/app/views/layouts/_timeline.html.haml @@ -1,4 +1,3 @@ - tl_json ||= nil -- p "here we render the table and the timeline" :javascript miqInitTimeline('#{j_str tl_json}'); diff --git a/app/views/layouts/_tl_show.html.haml b/app/views/layouts/_tl_show.html.haml index 6ddeb12b29f1..18e82fd97b56 100644 --- a/app/views/layouts/_tl_show.html.haml +++ b/app/views/layouts/_tl_show.html.haml @@ -1,15 +1,8 @@ --# Create from/to date JS vars to limit calendar selection range -- url = url_for_only_path(:action => 'tl_chooser', :id => @record.id) -= react 'TimelineOptions', {:url => url, :recordId => @record.id} - -:javascript - ManageIQ.calendar.calDateFrom = new Date(#{@tl_options.date.start}); - ManageIQ.calendar.calDateTo = new Date(#{@tl_options.date.end}); - %h1 = @title = render :partial => "layouts/flash_msg" -= render :partial => "layouts/tl_options" +- url = url_for_only_path(:action => 'tl_chooser', :id => @record.id) += react 'TimelineOptions', {:url => url} = render :partial => 'layouts/tl_detail' = _("* Dates/Times on this page are based on time zone: %{time_zone}.") % {:time_zone => session[:user_tz]}