From 512bd24eed32ce9105d1f5634fcd829569950ff3 Mon Sep 17 00:00:00 2001 From: Melissa Alvarez Date: Wed, 12 Dec 2018 17:01:24 -0600 Subject: [PATCH] Remove old schedule_events dir --- .../settings/scheduled_events/_index.scss | 6 - .../__tests__/calendars_list_controller.js | 29 --- .../calendars_list/_calendars_list.scss | 20 --- .../calendars_list/_index.scss | 1 - .../calendars_list/buttons_enabled_checks.js | 60 ------- .../calendars_list/calendars_list.html | 136 -------------- .../calendars_list_controller.js | 170 ------------------ .../scheduled_events/calendars_list/index.js | 9 - .../components/events_list/_events_list.scss | 19 -- .../components/events_list/_index.scss | 1 - .../components/events_list/events_list.html | 131 -------------- .../events_list/events_list_directive.js | 107 ----------- .../components/events_list/index.js | 9 - .../import_events_modal_controller.js | 35 ---- .../_import_events_modal.scss | 13 -- .../import_events_modal/_index.scss | 1 - .../import_events_modal.html | 91 ---------- .../import_events_modal_controller.js | 164 ----------------- .../import_events_service.js | 31 ---- .../components/import_events_modal/index.js | 10 -- .../__tests__/new_event_modal_controller.js | 35 ---- .../components/new_event_modal/_index.scss | 1 - .../new_event_modal/_new_event_modal.scss | 60 ------- .../components/new_event_modal/index.js | 10 -- .../new_event_modal/new_event_modal.html | 129 ------------- .../new_event_modal_controller.js | 102 ----------- .../new_event_modal/new_event_service.js | 31 ---- .../components/utils/validate_calendar.js | 35 ---- .../public/settings/scheduled_events/index.js | 10 -- .../__tests__/create_calendar_controller.js | 36 ---- .../scheduled_events/new_calendar/_index.scss | 1 - .../new_calendar/_new_calendar.scss | 21 --- .../new_calendar/create_calendar.html | 102 ----------- .../create_calendar_controller.js | 166 ----------------- .../scheduled_events/new_calendar/index.js | 9 - 35 files changed, 1791 deletions(-) delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/_index.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/__tests__/calendars_list_controller.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/_calendars_list.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/_index.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/buttons_enabled_checks.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/calendars_list.html delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/calendars_list_controller.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/index.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/_events_list.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/_index.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/events_list.html delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/events_list_directive.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/index.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/__tests__/import_events_modal_controller.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/_import_events_modal.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/_index.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_modal.html delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_modal_controller.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_service.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/index.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/__tests__/new_event_modal_controller.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/_index.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/_new_event_modal.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/index.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_modal.html delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_modal_controller.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_service.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/components/utils/validate_calendar.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/index.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/__tests__/create_calendar_controller.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/_index.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/_new_calendar.scss delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/create_calendar.html delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/create_calendar_controller.js delete mode 100644 x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/index.js diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/_index.scss b/x-pack/plugins/ml/public/settings/scheduled_events/_index.scss deleted file mode 100644 index a5db98c4b1229..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/_index.scss +++ /dev/null @@ -1,6 +0,0 @@ -@import 'calendars_list/index'; -@import 'new_calendar/index'; - -@import 'components/events_list/index'; -@import 'components/import_events_modal/index'; -@import 'components/new_event_modal/index'; \ No newline at end of file diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/__tests__/calendars_list_controller.js b/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/__tests__/calendars_list_controller.js deleted file mode 100644 index 7e519be3ddaeb..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/__tests__/calendars_list_controller.js +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import ngMock from 'ng_mock'; -import expect from 'expect.js'; - -xdescribe('ML - Calendars List Controller', () => { - beforeEach(() => { - ngMock.module('kibana'); - }); - - it('Initialize Calendars List Controller', (done) => { - ngMock.inject(function ($rootScope, $controller) { - const scope = $rootScope.$new(); - - expect(() => { - $controller('MlCalendarsList', { $scope: scope }); - }).to.not.throwError(); - - expect(scope.permissions.canCreateCalendar).to.eql(false); - done(); - }); - }); -}); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/_calendars_list.scss b/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/_calendars_list.scss deleted file mode 100644 index 963c9d0e2cd54..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/_calendars_list.scss +++ /dev/null @@ -1,20 +0,0 @@ -ml-calendars-list{ - font-size: $euiFontSizeS; - - header { - margin: $euiSize 0; - } - .calendars-list-container { - width: 100%; - margin-right: auto; - margin-left: auto; - padding-left: $euiSize; - padding-right: $euiSize; - } - - .actions-col { - // SASSTODO: Proper calcs - width: 150px; - min-width: 150px; - } -} diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/_index.scss b/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/_index.scss deleted file mode 100644 index 98af83f633806..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import 'calendars_list'; \ No newline at end of file diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/buttons_enabled_checks.js b/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/buttons_enabled_checks.js deleted file mode 100644 index 2374441f6e4fb..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/buttons_enabled_checks.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import { createPermissionFailureMessage } from 'plugins/ml/privilege/check_privilege'; - -export function buttonsEnabledChecks(permissions, mlNodesAvailable) { - const NO_ML_NODES_ERROR = 'No ML nodes available'; - - function newButtonWrapperClass() { - return (permissions.canCreateCalendar && mlNodesAvailable) ? 'button-wrapper' : ['button-wrapper', 'disabled']; - } - - function newButtonWrapperTooltip() { - let tooltip = undefined; - if (permissions.canCreateCalendar === false) { - tooltip = createPermissionFailureMessage('canCreateCalendar'); - } else if (mlNodesAvailable === false) { - tooltip = NO_ML_NODES_ERROR; - } - return tooltip; - } - - function newButtonDisabled() { - return ( - (permissions.canCreateCalendar === false) || mlNodesAvailable === false - ); - } - - function deleteButtonWrapperClass() { - return (permissions.canDeleteCalendar && mlNodesAvailable) ? 'button-wrapper' : ['button-wrapper', 'disabled']; - } - - function deleteButtonWrapperTooltip() { - let tooltip = undefined; - if (permissions.canDeleteCalendar === false) { - tooltip = createPermissionFailureMessage('canDeleteCalendar'); - } else if (mlNodesAvailable === false) { - tooltip = NO_ML_NODES_ERROR; - } - return tooltip; - } - - function deleteButtonDisabled() { - return (permissions.canDeleteCalendar && mlNodesAvailable) === false; - } - - return { - newButtonWrapperClass, - newButtonWrapperTooltip, - newButtonDisabled, - deleteButtonWrapperClass, - deleteButtonWrapperTooltip, - deleteButtonDisabled, - }; -} diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/calendars_list.html b/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/calendars_list.html deleted file mode 100644 index fb678a1a6aac3..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/calendars_list.html +++ /dev/null @@ -1,136 +0,0 @@ - - - - -
-
-
-
-
-
- - -
- -
-
- -
-
- -
- - - - -
-
- - - - - - - - - - - - - - - - - - - - - -
- - ID - - - - Jobs - - - - Events - -
-
- - {{calendar.calendar_id}} - -
-
-
- - {{calendar.job_ids.join(', ')}} - -
-
-
- - {{calendar.events.length}} {{calendar.events.length === 1 ? 'event' : 'events'}} - -
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-
-
diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/calendars_list_controller.js b/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/calendars_list_controller.js deleted file mode 100644 index eff4f9843ab51..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/calendars_list_controller.js +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import _ from 'lodash'; - -import 'ui/pager_control'; -import 'ui/pager'; -import 'ui/sortable_column'; - -import uiRoutes from 'ui/routes'; -import { getCalendarManagementBreadcrumbs } from '../../breadcrumbs'; -import { checkFullLicense } from 'plugins/ml/license/check_license'; -import { checkGetJobsPrivilege, checkPermission } from 'plugins/ml/privilege/check_privilege'; -import { getMlNodeCount, mlNodesAvailable } from 'plugins/ml/ml_nodes_check/check_ml_nodes'; -import { buttonsEnabledChecks } from 'plugins/ml/settings/scheduled_events/calendars_list/buttons_enabled_checks'; -import { ml } from 'plugins/ml/services/ml_api_service'; -import { initPromise } from 'plugins/ml/util/promise'; - -import template from './calendars_list.html'; - -import { timefilter } from 'ui/timefilter'; - -uiRoutes - .when('/settings/calendars_list', { - template, - k7Breadcrumbs: getCalendarManagementBreadcrumbs, - resolve: { - CheckLicense: checkFullLicense, - privileges: checkGetJobsPrivilege, - mlNodeCount: getMlNodeCount, - initPromise: initPromise(true) - } - }); - -import { uiModules } from 'ui/modules'; -const module = uiModules.get('apps/ml', ['ui.bootstrap']); - -module.controller('MlCalendarsList', - function ( - $scope, - $filter, - $route, - $location, - pagerFactory, - mlConfirmModalService) { - - $scope.permissions = { - canCreateCalendar: checkPermission('canCreateCalendar'), - canDeleteCalendar: checkPermission('canDeleteCalendar'), - }; - - timefilter.disableTimeRangeSelector(); // remove time picker from top of page - timefilter.disableAutoRefreshSelector(); // remove time picker from top of page - const mlConfirm = mlConfirmModalService; - - let calendars = []; // Complete list of calendars received from the ML endpoint. - $scope.displayCalendars = []; // List of calendars being displayed after filtering and sorting. - $scope.buttonChecks = buttonsEnabledChecks($scope.permissions, mlNodesAvailable()); - - // Create a pager object to page through long lists of calendars. - const PAGE_SIZE = 20; - const limitTo = $filter('limitTo'); - $scope.pager = pagerFactory.create(0, PAGE_SIZE, 1); - - // Sort field labels, to identify column used for sorting the list. - const SORT_FIELD_LABELS = { - CALENDAR_ID: 'calendar_id', - JOB_IDS: 'job_ids', - EVENT_COUNT: 'event_count' - }; - $scope.SORT_FIELD_LABELS = SORT_FIELD_LABELS; - $scope.sortField = SORT_FIELD_LABELS.CALENDAR_ID; - $scope.sortReverse = false; - - $scope.onSortChange = function (field, reverse) { - $scope.sortField = field; - $scope.sortReverse = reverse; - }; - - // Listen for changes to the search text and build Regexp. - $scope.onQueryChange = function (query) { - if (query) { - $scope.filterRegexp = new RegExp(`(${query})`, 'gi'); - } else { - $scope.filterRegexp = undefined; - } - }; - - $scope.onPageNext = function () { - $scope.pager.nextPage(); - }; - - $scope.onPagePrevious = function () { - $scope.pager.previousPage(); - }; - - $scope.$watchMulti([ - 'sortField', - 'sortReverse', - 'filterRegexp', - 'pager.currentPage' - ], applyTableSettings); - - $scope.newCalendarClick = function () { - $location.path('settings/calendars_list/new_calendar'); - }; - - $scope.editCalendarClick = function (id) { - $location.path(`settings/calendars_list/edit_calendar/${id}`); - }; - - $scope.deleteCalendarClick = function (calendarId) { - mlConfirm.open({ - message: `Confirm deletion of ${calendarId}?`, - title: `Delete calendar` - }) - .then(() => { - ml.deleteCalendar({ calendarId }) - .then(loadCalendars) - .catch((error) => { - console.log(error); - }); - }) - .catch(() => {}); - }; - - function loadCalendars() { - ml.calendars() - .then((resp) => { - calendars = resp; - $scope.pager = pagerFactory.create(calendars.length, PAGE_SIZE, 1); - applyTableSettings(); - }); - } - - function applyTableSettings() { - // Applies the settings from the table controls (search filter and sorting). - let filteredCalendars = _.filter(calendars, (calendar) => { - // If search text has been entered, look for match in the calendar ID or job IDs. - return $scope.filterRegexp === undefined || - calendar.calendar_id.match($scope.filterRegexp) || - calendar.job_ids.join(' ').match($scope.filterRegexp); - }); - - filteredCalendars = _.sortBy(filteredCalendars, (calendar) => { - switch ($scope.sortField) { - case SORT_FIELD_LABELS.JOB_IDS: - return calendar.job_ids.join(); - case SORT_FIELD_LABELS.EVENT_COUNT: - return calendar.events.length; - case SORT_FIELD_LABELS.CALENDAR_ID: - default: - return calendar[$scope.sortField]; - } - }); - if ($scope.sortReverse === true) { - filteredCalendars = filteredCalendars.reverse(); - } - - $scope.displayCalendars = limitTo(filteredCalendars, $scope.pager.pageSize, $scope.pager.startIndex); - $scope.pager.setTotalItems(filteredCalendars.length); - } - - loadCalendars(); - }); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/index.js b/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/index.js deleted file mode 100644 index 6a6382516e06f..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/calendars_list/index.js +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import './calendars_list_controller'; diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/_events_list.scss b/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/_events_list.scss deleted file mode 100644 index b5d4b9056f1ec..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/_events_list.scss +++ /dev/null @@ -1,19 +0,0 @@ -.events-list { - .actions-col { - width: 90px; - min-width: 90px; - } - .asterisk { - color: $euiColorDanger; - font-weight: $euiFontWeightBold; - cursor: default; - } - - .footer-cell { - border-top: $euiBorderThin; - padding: $euiSizeS; - font-size: $euiFontSizeS; - font-style: italic; - text-align: right; - } -} diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/_index.scss b/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/_index.scss deleted file mode 100644 index d5d95b9d63ccc..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import 'events_list'; \ No newline at end of file diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/events_list.html b/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/events_list.html deleted file mode 100644 index b7cd05240e660..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/events_list.html +++ /dev/null @@ -1,131 +0,0 @@ -
-
-
- -
- - - -
- -
- - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - Description - - - - Start - - - - End - -
-
- - {{event.description}} - - * -
-
-
- - {{formatTime(event.start_time)}} - -
-
-
- - {{formatTime(event.end_time)}} - -
-
-
-
- -
-
-
- - -
-
diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/events_list_directive.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/events_list_directive.js deleted file mode 100644 index ac38a944bfa69..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/events_list_directive.js +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import 'plugins/ml/settings/scheduled_events/components/new_event_modal'; -import 'plugins/ml/settings/scheduled_events/components/import_events_modal'; - -import template from './events_list.html'; -import moment from 'moment'; - -import { uiModules } from 'ui/modules'; -const module = uiModules.get('apps/ml'); - -module.directive('mlEventsList', function ( - $filter, - pagerFactory, - mlNewEventService, - mlImportEventsService, - config) { - return { - restrict: 'AE', - replace: true, - transclude: true, - template, - scope: { - events: '=', - showControls: '=', - lockControls: '=', - asteriskText: '=' - }, - controller: function ($scope) { - - $scope.pageOfEvents = []; // Current page of events displayed in the list. - $scope.dateFormatTz = config.get('dateFormat:tz'); - - const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'; - const PAGE_SIZE = 20; - - // Create objects for sorting and paging through the events. - const orderBy = $filter('orderBy'); - const limitTo = $filter('limitTo'); - $scope.pager = pagerFactory.create($scope.events.length, PAGE_SIZE, 1); - $scope.sortField = 'description'; - $scope.sortReverse = false; - - $scope.onSortChange = function (field, reverse) { - $scope.sortField = field; - $scope.sortReverse = reverse; - }; - - $scope.onPageNext = function () { - $scope.pager.nextPage(); - }; - - $scope.onPagePrevious = function () { - $scope.pager.previousPage(); - }; - - $scope.$watchMulti([ - 'events', - 'sortField', - 'sortReverse', - 'pager.currentPage' - ], applyTableSettings); - - $scope.clickNewEvent = function () { - mlNewEventService.openNewEventWindow() - .then((event) => { - $scope.events.push(event); - applyTableSettings(); - }) - .catch(() => {}); - }; - - $scope.formatTime = function (timeMs) { - const time = moment(timeMs); - return time.format(TIME_FORMAT); - }; - - $scope.deleteEvent = function (eventToDelete) { - $scope.events.splice($scope.events.indexOf(eventToDelete), 1); - applyTableSettings(); - }; - - $scope.clickImportEvents = function () { - mlImportEventsService.openImportEventsWindow() - .then((events) => { - $scope.events.push(...events); - applyTableSettings(); - }) - .catch(() => {}); - }; - - function applyTableSettings() { - // Apply sorting and paging to the complete list of events. - const pageOfEvents = orderBy($scope.events, $scope.sortField, $scope.sortReverse); - $scope.pageOfEvents = limitTo(pageOfEvents, $scope.pager.pageSize, $scope.pager.startIndex); - $scope.pager.setTotalItems($scope.events.length); - } - - } - }; -}); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/index.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/index.js deleted file mode 100644 index f6bfb42f65aed..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/events_list/index.js +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import './events_list_directive'; diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/__tests__/import_events_modal_controller.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/__tests__/import_events_modal_controller.js deleted file mode 100644 index 7984eb93e0801..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/__tests__/import_events_modal_controller.js +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import ngMock from 'ng_mock'; -import expect from 'expect.js'; - -const mockModalInstance = { close: function () { }, dismiss: function () { } }; - -xdescribe('ML - Import Events Modal Controller', () => { - beforeEach(() => { - ngMock.module('kibana'); - }); - - it('Initialize Import Events Modal Controller', (done) => { - ngMock.inject(function ($rootScope, $controller) { - const scope = $rootScope.$new(); - - expect(() => { - $controller('MlImportEventsModal', { - $scope: scope, - $modalInstance: mockModalInstance, - params: {} - }); - }).to.not.throwError(); - - expect(scope.loadingLock).to.be(false); - done(); - }); - }); -}); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/_import_events_modal.scss b/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/_import_events_modal.scss deleted file mode 100644 index c827578661e60..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/_import_events_modal.scss +++ /dev/null @@ -1,13 +0,0 @@ -.import-events-modal { - font-size: $euiFontSizeS; - padding: $euiSizeL; - cursor: auto; - - .no-shadow { - box-shadow: none; - } - - .recurring-warning { - color: $euiColorDanger; - } -} diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/_index.scss b/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/_index.scss deleted file mode 100644 index b7a72ef464dda..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import 'import_events_modal'; \ No newline at end of file diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_modal.html b/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_modal.html deleted file mode 100644 index ee06dafca9f30..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_modal.html +++ /dev/null @@ -1,91 +0,0 @@ -
- -

Import events

-
- -
- Import events from an ICS file -
-
- -
- -
- -
- -
- Events to import: {{newEvents.length}} -
- -
-
- {{errorMessage}} -
-
- -
- -
- -
- - - -
- -
- *{{RECURRING_WARNING}} -
-
- -
- -
-
-
- -
- -
- - - - -
diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_modal_controller.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_modal_controller.js deleted file mode 100644 index c4c63149a4c65..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_modal_controller.js +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -const icalendar = require('icalendar'); -import $ from 'jquery'; -import moment from 'moment'; - -import 'plugins/ml/settings/scheduled_events/components/events_list'; - -import { uiModules } from 'ui/modules'; -const module = uiModules.get('apps/ml'); - -module.controller('MlImportEventsModal', function ( - $scope, - $timeout, - $modalInstance) { - - $scope.loadingLock = false; - $scope.allNewEvents = []; - $scope.newEvents = []; - $scope.fileLoaded = false; - $scope.file = undefined; - $scope.includePastEvents = false; - $scope.showRecurringWarning = false; - $scope.RECURRING_WARNING = 'Recurring events not supported. Only the first event will be imported.'; - - $timeout(() => { - $('.modal-dialog').width(750); - }, 0); - - const MAX_FILE_SIZE_MB = 100; - // called when a file is selected using the file browser - $scope.fileNameChanged = function (event) { - $scope.$apply(() => { - if (event.target.files.length) { - reset(); - $scope.file = event.target.files[0]; - if ($scope.file.size <= (MAX_FILE_SIZE_MB * 1000000)) { - readFile($scope.file) - .then((resp) => { - try { - $scope.allNewEvents = parseICSFile(resp.data); - $scope.createEventsList(); - $scope.fileLoaded = true; - $scope.loadingLock = false; - } catch (error) { - $scope.error = true; - $scope.errorMessage = 'Could not parse ICS file'; - } - }) - .catch((error) => { - console.error(error); - $scope.loadingLock = false; - }); - } else { - $scope.fileLoaded = false; - $scope.loadingLock = false; - } - } - }); - }; - - function readFile(file) { - return new Promise((resolve, reject) => { - $scope.loadingLock = true; - - if (file && file.size) { - const reader = new FileReader(); - reader.readAsText(file); - - reader.onload = (() => { - return () => { - $scope.loadingLock = false; - const data = reader.result; - if (data === '') { - reject(); - } else { - resolve({ data }); - } - }; - })(file); - } else { - reject(); - } - }); - } - - function reset() { - $scope.file = undefined; - $scope.fileLoaded = false; - $scope.loadingLock = false; - $scope.newEvents = []; - $scope.error = false; - $scope.errorMessage = ''; - } - - function parseICSFile(data) { - const cal = icalendar.parse_calendar(data); - return createEvents(cal); - } - - function createEvents(ical) { - const events = ical.events(); - const mlEvents = []; - - events.forEach((e) => { - if (e.element === 'VEVENT') { - const description = e.properties.SUMMARY; - const start = e.properties.DTSTART; - const end = e.properties.DTEND; - const recurring = (e.properties.RRULE !== undefined); - - if (description && start && end && description.length && start.length && end.length) { - mlEvents.push({ - description: description[0].value, - start_time: start[0].value.valueOf(), - end_time: end[0].value.valueOf(), - asterisk: recurring - }); - } - } - }); - return mlEvents; - } - - // populate the newEvents list - // filtering out past events if the checkbox is ticked - $scope.createEventsList = function () { - if ($scope.includePastEvents) { - $scope.newEvents = [...$scope.allNewEvents]; - } else { - const now = moment().valueOf(); - $scope.newEvents = $scope.allNewEvents.filter(e => e.start_time > now); - } - - $scope.showRecurringWarning = ($scope.newEvents.find(e => e.asterisk) !== undefined); - }; - - $scope.save = function () { - $modalInstance.close($scope.newEvents); - reset(); - }; - - $scope.cancel = function () { - $modalInstance.dismiss('cancel'); - }; -}).directive('mlFileInputOnChange', function () { - return { - restrict: 'A', - link: function (scope, element, attrs) { - const onChangeHandler = scope.$eval(attrs.mlFileInputOnChange); - element.on('change', onChangeHandler); - element.on('$destroy', () => { - element.off(); - }); - - } - }; -}); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_service.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_service.js deleted file mode 100644 index 58c49c66ce160..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/import_events_service.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import template from './import_events_modal.html'; - -import { uiModules } from 'ui/modules'; -const module = uiModules.get('apps/ml'); - -module.service('mlImportEventsService', function ($modal) { - - this.openImportEventsWindow = function () { - return new Promise((resolve, reject) => { - const modal = $modal.open({ - template, - controller: 'MlImportEventsModal', - backdrop: 'static', - keyboard: false - }); - - modal.result - .then(resolve) - .catch(reject); - }); - }; - -}); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/index.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/index.js deleted file mode 100644 index e0cb4cf7a574b..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/import_events_modal/index.js +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import './import_events_service'; -import './import_events_modal_controller'; diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/__tests__/new_event_modal_controller.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/__tests__/new_event_modal_controller.js deleted file mode 100644 index a6f29dc0939d8..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/__tests__/new_event_modal_controller.js +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import ngMock from 'ng_mock'; -import expect from 'expect.js'; - -const mockModalInstance = { close: function () { }, dismiss: function () { } }; - -xdescribe('ML - New Event Modal Controller', () => { - beforeEach(() => { - ngMock.module('kibana'); - }); - - it('Initialize New Event Modal Controller', (done) => { - ngMock.inject(function ($rootScope, $controller) { - const scope = $rootScope.$new(); - - expect(() => { - $controller('MlNewEventModal', { - $scope: scope, - $modalInstance: mockModalInstance, - params: {} - }); - }).to.not.throwError(); - - expect(scope.event.description).to.be(''); - done(); - }); - }); -}); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/_index.scss b/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/_index.scss deleted file mode 100644 index a9f6e72195d72..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import 'new_event_modal'; \ No newline at end of file diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/_new_event_modal.scss b/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/_new_event_modal.scss deleted file mode 100644 index 71f770c3e89df..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/_new_event_modal.scss +++ /dev/null @@ -1,60 +0,0 @@ -.new-event-modal { - font-size: $euiFontSizeS; - padding: $euiSizeL; - cursor: auto; - - .date_container { - width: 200px; - display: inline-block; - } - - .ml-new-event-contents { - margin-top: $euiSizeXS; - - .main-container { - display: flex; - .tabs-container { - // SASSTODO: Proper selectors - ul { - padding: 0px; - li { - a { - border-radius: $euiSizeXS 0px 0px $euiSizeXS; - white-space: nowrap; - } - } - } - } - - .calendar-container { - border: 2px solid $euiColorPrimary; - flex-grow: 1; - border-radius: $euiBorderRadius; - - // SASSTODO: Proper calcs - .calendar { - width: 235px; - margin: 20px; - float: left; - .calendar-input-container { - margin-right: -33px; - } - .partition { - border-right: 1px solid $euiColorPrimary; - position: absolute; - height: 275px; - left: 270px; - top: 0px; - } - .partition-large { - height: 325px; - } - } - } - .top-tab-selected { - border-radius: 0 $euiSizeXS $euiSizeXS $euiSizeXS; - - } - } - } -} diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/index.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/index.js deleted file mode 100644 index 9bda4b44c1189..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/index.js +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import './new_event_service'; -import './new_event_modal_controller'; diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_modal.html b/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_modal.html deleted file mode 100644 index 4cae3ab705be7..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_modal.html +++ /dev/null @@ -1,129 +0,0 @@ -
- -

Create new event

-
- -
- -
- - -
-
- -
- -
- - -
- -
-
-
- - - -
-
-
- - - -
-
-
- -
-
-
-
- - -
- - -
-
-
- -
- -
- - -
-
-
-
-
- -
- -
- -
- - - - -
diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_modal_controller.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_modal_controller.js deleted file mode 100644 index 6213f32ba71e2..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_modal_controller.js +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import moment from 'moment'; -import $ from 'jquery'; - -import { uiModules } from 'ui/modules'; -const module = uiModules.get('apps/ml'); - -module.controller('MlNewEventModal', function ( - $scope, - $modalInstance, - $timeout) { - - const RANGE_TYPE = { - SINGLE_DAY: '0', - DAY_RANGE: '1', - TIME_RANGE: '2', - }; - $scope.RANGE_TYPE = RANGE_TYPE; - const MODAL_WIDTH_SMALL = 425; - const MODAL_WIDTH_LARGE = 700; - - $scope.event = { - description: '', - start: '', - end: '' - }; - - $scope.ui = { - saveEnabled() { - return ($scope.ui.description !== '' && $scope.ui.description !== undefined); - }, - description: '', - rangeType: RANGE_TYPE.SINGLE_DAY, - timepicker: { - start: moment().startOf('day'), - end: moment().startOf('day').add(1, 'days') - }, - setRangeType(i, event) { - if (event && event.preventDefault) { - event.preventDefault(); - } - - $scope.ui.rangeType = i; - let width = MODAL_WIDTH_SMALL; - if (i === RANGE_TYPE.SINGLE_DAY) { - width = MODAL_WIDTH_SMALL; - } else if (i === RANGE_TYPE.DAY_RANGE || i === RANGE_TYPE.TIME_RANGE) { - width = MODAL_WIDTH_LARGE; - } - $('.modal-dialog').width(width); - } - }; - - - $timeout(() => { - $scope.ui.setRangeType('0'); - $('.ml-new-event-contents #id').focus(); - }, 0); - - function extractForm() { - let start = null; - let end = null; - - const startMoment = moment($scope.ui.timepicker.start); - if ($scope.ui.rangeType === RANGE_TYPE.SINGLE_DAY) { - const endMoment = moment($scope.ui.timepicker.start); - start = startMoment.startOf('day'); - end = endMoment.startOf('day').add(1, 'days'); - } - else if ($scope.ui.rangeType === RANGE_TYPE.DAY_RANGE) { - const endMoment = moment($scope.ui.timepicker.end); - start = startMoment.startOf('day'); - end = endMoment.startOf('day').add(1, 'days'); - } - else if ($scope.ui.rangeType === RANGE_TYPE.TIME_RANGE) { - start = startMoment; - end = moment($scope.ui.timepicker.end); - } - - return{ - description: $scope.ui.description, - start_time: start.valueOf(), - end_time: end.valueOf() - }; - } - - $scope.save = function () { - const event = extractForm(); - $modalInstance.close(event); - }; - - $scope.cancel = function () { - $modalInstance.dismiss('cancel'); - }; -}); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_service.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_service.js deleted file mode 100644 index 3101fe2314a7d..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/new_event_modal/new_event_service.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import template from './new_event_modal.html'; - -import { uiModules } from 'ui/modules'; -const module = uiModules.get('apps/ml'); - -module.service('mlNewEventService', function ($modal) { - - this.openNewEventWindow = function () { - return new Promise((resolve, reject) => { - const modal = $modal.open({ - template, - controller: 'MlNewEventModal', - backdrop: 'static', - keyboard: false - }); - - modal.result - .then(resolve) - .catch(reject); - }); - }; - -}); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/components/utils/validate_calendar.js b/x-pack/plugins/ml/public/settings/scheduled_events/components/utils/validate_calendar.js deleted file mode 100644 index 79557b746ad1f..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/components/utils/validate_calendar.js +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -// Calendar ID requires the same format as a Job ID, therefore isJobIdValid can be used - -import { isJobIdValid } from 'plugins/ml/../common/util/job_utils'; -import _ from 'lodash'; - -export function validateCalendarId(calendarId, checks) { - let valid = true; - - _.each(checks, item => item.valid = true); - - if (calendarId === '' || calendarId === undefined) { - checks.calendarId.valid = false; - } else if (isJobIdValid(calendarId) === false) { - checks.calendarId.valid = false; - let msg = 'Calendar ID can contain lowercase alphanumeric (a-z and 0-9), hyphens or underscores; '; - msg += 'must start and end with an alphanumeric character'; - checks.calendarId.message = msg; - } - - _.each(checks, (item) => { - if (item.valid === false) { - valid = false; - } - }); - - return valid; -} diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/index.js b/x-pack/plugins/ml/public/settings/scheduled_events/index.js deleted file mode 100644 index 7e44dce158ff1..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/index.js +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import './calendars_list'; -import './new_calendar'; diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/__tests__/create_calendar_controller.js b/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/__tests__/create_calendar_controller.js deleted file mode 100644 index 829354a2927e7..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/__tests__/create_calendar_controller.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import ngMock from 'ng_mock'; -import expect from 'expect.js'; - -xdescribe('ML - Create Calendar Controller', () => { - beforeEach(() => { - ngMock.module('kibana'); - }); - - it('Initialize Create Calendar Controller', (done) => { - ngMock.inject(function ($rootScope, $controller) { - const scope = $rootScope.$new(); - - expect(() => { - $controller('MlCreateCalendar', { - $route: { - current: { - params: {} - } - }, - $scope: scope - }); - }).to.not.throwError(); - - expect(scope.isNewCalendar).to.eql(true); - done(); - }); - }); -}); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/_index.scss b/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/_index.scss deleted file mode 100644 index dc8fbb6efc0f5..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import 'new_calendar'; \ No newline at end of file diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/_new_calendar.scss b/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/_new_calendar.scss deleted file mode 100644 index fc393ce56ce75..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/_new_calendar.scss +++ /dev/null @@ -1,21 +0,0 @@ -ml-new-calendar{ - font-size: $euiFontSizeS; - - // SASSTODO: Proper selector - h3 { - margin-top: 0px; - } - - .new-calendar-container { - width: 100%; - margin-right: auto; - margin-left: auto; - padding-left: $euiSize; - padding-right: $euiSize; - - .validation-error { - color: $euiColorDanger; - font-size: $euiFontSizeXS; - } - } -} diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/create_calendar.html b/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/create_calendar.html deleted file mode 100644 index 369bb94289cbc..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/create_calendar.html +++ /dev/null @@ -1,102 +0,0 @@ - - - -
-
-

{{pageTitle}}

-
-
-
-
- - -
-
-
-
- -
-
- - -
-
- {{ ( validation.checks.calendarId.message || "Enter a name for the calendar" ) }} -
-
-
- - -
-
- - - -
-
- - - -
- -
-
- - -
- -
- -
- diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/create_calendar_controller.js b/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/create_calendar_controller.js deleted file mode 100644 index 7a6e363aa1909..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/create_calendar_controller.js +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import $ from 'jquery'; -import _ from 'lodash'; - -import 'plugins/ml/components/item_select'; -import 'plugins/ml/settings/scheduled_events/components/events_list'; - -import { validateCalendarId } from 'plugins/ml/settings/scheduled_events/components/utils/validate_calendar'; - -import uiRoutes from 'ui/routes'; -import { getCreateCalendarBreadcrumbs, getEditCalendarBreadcrumbs } from '../../breadcrumbs'; -import { checkFullLicense } from 'plugins/ml/license/check_license'; -import { checkGetJobsPrivilege } from 'plugins/ml/privilege/check_privilege'; -import { checkMlNodesAvailable } from 'plugins/ml/ml_nodes_check/check_ml_nodes'; -import { mlJobService } from 'plugins/ml/services/job_service'; -import { mlCalendarService } from 'plugins/ml/services/calendar_service'; -import { mlMessageBarService } from 'plugins/ml/components/messagebar/messagebar_service'; -import { initPromise } from 'plugins/ml/util/promise'; -import { ml } from 'plugins/ml/services/ml_api_service'; - -import template from './create_calendar.html'; - -uiRoutes - .when('/settings/calendars_list/new_calendar', { - template, - k7Breadcrumbs: getCreateCalendarBreadcrumbs, - resolve: { - CheckLicense: checkFullLicense, - privileges: checkGetJobsPrivilege, - checkMlNodesAvailable, - initPromise: initPromise(true) - } - }) - .when('/settings/calendars_list/edit_calendar/:calendarId', { - template, - k7Breadcrumbs: getEditCalendarBreadcrumbs, - resolve: { - CheckLicense: checkFullLicense, - privileges: checkGetJobsPrivilege, - checkMlNodesAvailable, - initPromise: initPromise(true) - } - }); - -import { uiModules } from 'ui/modules'; -const module = uiModules.get('apps/ml', ['ui.bootstrap']); - -module.controller('MlCreateCalendar', - function ( - $scope, - $route, - $location) { - const msgs = mlMessageBarService; - msgs.clear(); - - const calendarId = $route.current.params.calendarId; - $scope.isNewCalendar = (calendarId === undefined); - - $scope.pageTitle = $scope.isNewCalendar ? 'Create new calendar' : `Edit calendar ${calendarId}`; - - $scope.calendarId = calendarId || ''; - $scope.description = ''; - $scope.events = []; - $scope.jobIds = []; - $scope.allJobs = []; - $scope.groupIds = []; - $scope.allGroups = []; - $scope.updateJobsList = {}; - $scope.updateGroupsList = {}; - $scope.saveLock = false; - $scope.validation = { - checks: { - calendarId: { valid: true }, - } - }; - - mlJobService.loadJobs() - .then(() => { - const jobs = mlJobService.jobs; - $scope.allJobs = jobs.map(j => ({ id: j.job_id })); - $scope.allGroups = mlJobService.getJobGroups().map(g => ({ id: g.id })); - - mlCalendarService.loadCalendars(jobs) - .then((resp) => { - const calendars = resp.calendars; - const calGroups = mlCalendarService.getCalendarGroups(); - // append calendar groups to the list of all groups and deduplicate - $scope.allGroups.push(...calGroups); - $scope.allGroups = _.uniq($scope.allGroups, 'id'); - $scope.allGroups = _.sortBy($scope.allGroups, 'id'); - - calendars.forEach((calendar) => { - // if we're editing an existing calendar - if (calendarId !== undefined && calendarId === calendar.calendar_id) { - $scope.events = calendar.events || []; - $scope.description = calendar.description || ''; - - calendar.job_ids.forEach(id => { - if ($scope.allJobs.find((j) => j.id === id)) { - // if the job exists, add it to the job list - $scope.jobIds.push(id); - } else if ($scope.allGroups.find((g) => g.id === id)) { - // otherwise, it could be a group, - // if it exists as a group, add it to the group list - $scope.groupIds.push(id); - } - }); - } - }); - - $scope.updateJobsList.update($scope.jobIds); - $scope.updateGroupsList.update($scope.groupIds); - }); - $('.new-calendar-container #id').focus(); - }); - - $scope.save = function () { - msgs.clear(); - // Just pass the three event properties used by the endpoint, ignoring UI-specific properties - // such as 'asterisk' which is used to flag recurring events from an ICS file import. - const events = $scope.events.map((event) => { - return { - description: event.description, - start_time: event.start_time, - end_time: event.end_time - }; - }); - - const calendar = { - calendarId: $scope.calendarId, - description: $scope.description, - events, - job_ids: [...$scope.jobIds, ...$scope.groupIds], - }; - - if (validateCalendarId(calendar.calendarId, $scope.validation.checks)) { - $scope.saveLock = true; - const saveFunc = $scope.isNewCalendar ? (c => ml.addCalendar(c)) : (c => ml.updateCalendar(c)); - saveFunc(calendar) - .then(() => { - $location.path('settings/calendars_list'); - $scope.saveLock = false; - }) - .catch((error) => { - msgs.error('Save calendar failed: ', error); - $scope.saveLock = false; - }); - } - }; - - $scope.cancel = function () { - $location.path('settings/calendars_list'); - }; - - $scope.saveEnabled = function () { - return ($scope.calendarId !== '' && $scope.calendarId !== undefined && $scope.saveLock === false); - }; - - }); diff --git a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/index.js b/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/index.js deleted file mode 100644 index 6dd769aa0aa23..0000000000000 --- a/x-pack/plugins/ml/public/settings/scheduled_events/new_calendar/index.js +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - - - -import './create_calendar_controller';