iguazio.dashboard-controls 0.37.11 → 0.37.12-patch3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iguazio.dashboard-controls",
3
- "version": "0.37.11",
3
+ "version": "0.37.12-patch3",
4
4
  "main": "dist/js/iguazio.dashboard-controls.js",
5
5
  "description": "Collection of resources (such as CSS styles, fonts and images) and AngularJs 1.x components and services to share among different Iguazio repos.",
6
6
  "repository": {
@@ -21,10 +21,16 @@
21
21
  var ctrl = this;
22
22
  var lng = i18next.language;
23
23
 
24
- ctrl.isShowSpinner = true;
25
24
  ctrl.isShowContent = false;
26
25
  ctrl.isShowError = false;
26
+ ctrl.isShowSpinner = true;
27
27
 
28
+ ctrl.deregisterHideError = null;
29
+ ctrl.deregisterHideSpinner = null;
30
+ ctrl.deregisterShowError = null;
31
+ ctrl.deregisterShowSpinner = null;
32
+
33
+ ctrl.$onDestroy = onDestroy;
28
34
  ctrl.$onInit = onInit;
29
35
  ctrl.$onChanges = onChanges;
30
36
 
@@ -35,21 +41,25 @@
35
41
  // Hook methods
36
42
  //
37
43
 
44
+ /**
45
+ * Destructor method
46
+ */
47
+ function onDestroy() {
48
+ deregisterBroadcasts();
49
+ }
50
+
38
51
  /**
39
52
  * Initialization method
40
53
  */
41
54
  function onInit() {
42
- $scope.$on('element-loading-status_show-spinner_' + ctrl.name, showSpinner);
43
- $scope.$on('element-loading-status_hide-spinner_' + ctrl.name, hideSpinner);
44
-
45
- $scope.$on('element-loading-status_show-error_' + ctrl.name, showError);
46
- $scope.$on('element-loading-status_hide-error_' + ctrl.name, hideError);
55
+ registerBroadcasts();
47
56
  }
48
57
 
49
58
  /**
50
59
  * Changes method
60
+ * @param {Object} changes
51
61
  */
52
- function onChanges() {
62
+ function onChanges(changes) {
53
63
  lodash.defaults(ctrl, {
54
64
  loadingStatusSize: 'default',
55
65
  refresh: false,
@@ -64,6 +74,11 @@
64
74
  refresh: true
65
75
  });
66
76
  }
77
+
78
+ if (changes && changes.name && changes.name.currentValue !== changes.name.previousValue) {
79
+ deregisterBroadcasts();
80
+ registerBroadcasts();
81
+ }
67
82
  }
68
83
 
69
84
  //
@@ -95,12 +110,20 @@
95
110
  //
96
111
 
97
112
  /**
98
- * Show given loading spinner
113
+ * Deregister broadcasts
99
114
  */
100
- function showSpinner() {
115
+ function deregisterBroadcasts() {
116
+ ctrl.deregisterHideError();
117
+ ctrl.deregisterHideSpinner();
118
+ ctrl.deregisterShowError();
119
+ ctrl.deregisterShowSpinner();
120
+ }
121
+
122
+ /**
123
+ * Hide given loading error
124
+ */
125
+ function hideError() {
101
126
  ctrl.isShowError = false;
102
- ctrl.isShowContent = false;
103
- ctrl.isShowSpinner = true;
104
127
  }
105
128
 
106
129
  /**
@@ -111,6 +134,16 @@
111
134
  ctrl.isShowContent = true;
112
135
  }
113
136
 
137
+ /**
138
+ * Register broadcasts
139
+ */
140
+ function registerBroadcasts() {
141
+ ctrl.deregisterHideError = $scope.$on('element-loading-status_hide-error_' + ctrl.name, hideError);
142
+ ctrl.deregisterHideSpinner = $scope.$on('element-loading-status_hide-spinner_' + ctrl.name, hideSpinner);
143
+ ctrl.deregisterShowError = $scope.$on('element-loading-status_show-error_' + ctrl.name, showError);
144
+ ctrl.deregisterShowSpinner = $scope.$on('element-loading-status_show-spinner_' + ctrl.name, showSpinner);
145
+ }
146
+
114
147
  /**
115
148
  * Show given loading error
116
149
  */
@@ -120,10 +153,12 @@
120
153
  }
121
154
 
122
155
  /**
123
- * Hide given loading error
156
+ * Show given loading spinner
124
157
  */
125
- function hideError() {
158
+ function showSpinner() {
126
159
  ctrl.isShowError = false;
160
+ ctrl.isShowContent = false;
161
+ ctrl.isShowSpinner = true;
127
162
  }
128
163
  }
129
164
  }());
@@ -4,8 +4,8 @@
4
4
  .controller('PaginationController', PaginationController);
5
5
 
6
6
  /*eslint no-shadow: 0*/
7
- function PaginationController($i18next, $injector , $location, $rootScope, $stateParams, $timeout,
8
- i18next, lodash, ActionCheckboxAllService, PaginationService,
7
+ function PaginationController($i18next, $injector , $location, $q, $rootScope, $stateParams, $timeout,
8
+ i18next, lodash, ActionCheckboxAllService, GeneralDataService, PaginationService,
9
9
  entitiesType, onChangePageCallback, dataServiceName, vm, emptyOnPageChange) {
10
10
 
11
11
  // entityId - id of nested entity
@@ -34,6 +34,7 @@
34
34
  * (e.g. filter, include, sort, etc.).
35
35
  */
36
36
  function changePage(pageNumber, perPage, additionalParams) {
37
+ var previousData = angular.copy(vm[entitiesType]);
37
38
  var pageAdditionalParams = lodash.cloneDeep(additionalParams);
38
39
  selectedItemId = lodash.defaultTo($stateParams.selectedItemId, $location.search().id);
39
40
  selectedItemId = isNumeric(selectedItemId) ? lodash.toInteger(selectedItemId) : selectedItemId;
@@ -122,17 +123,24 @@
122
123
  vm.isSplashShowed.value = false;
123
124
  })
124
125
  .catch(function (error) {
125
- var errorMessages = {
126
- '400': $i18next.t('common:ERROR_MSG.PAGINATION.400', { lng: lng }),
127
- '403': $i18next.t('common:ERROR_MSG.PAGINATION.403', { lng: lng }),
128
- '500': $i18next.t('common:ERROR_MSG.ERROR_ON_SERVER_SIDE', { lng: lng }),
129
- 'default': $i18next.t('common:ERROR_MSG.UNKNOWN_ERROR', { lng: lng })
130
- };
131
- var message = lodash.get(errorMessages, String(error.status), errorMessages.default);
132
-
133
- $rootScope.$broadcast('splash-screen_show-error', {
134
- alertText: message + ' ' + $i18next.t('common:ERROR_MSG.YOU_CAN_TRY_TO_REFRESH_PAGE', { lng: lng })
135
- });
126
+ if (GeneralDataService.isDisconnectionError(error.status)) {
127
+ vm[entitiesType] = previousData;
128
+ vm.isSplashShowed.value = false;
129
+
130
+ return $q.reject(error)
131
+ } else {
132
+ var errorMessages = {
133
+ '400': $i18next.t('common:ERROR_MSG.PAGINATION.400', { lng: lng }),
134
+ '403': $i18next.t('common:ERROR_MSG.PAGINATION.403', { lng: lng }),
135
+ '500': $i18next.t('common:ERROR_MSG.ERROR_ON_SERVER_SIDE', { lng: lng }),
136
+ 'default': $i18next.t('common:ERROR_MSG.UNKNOWN_ERROR', { lng: lng })
137
+ };
138
+ var message = lodash.get(errorMessages, String(error.status), errorMessages.default);
139
+
140
+ $rootScope.$broadcast('splash-screen_show-error', {
141
+ alertText: message + ' ' + $i18next.t('common:ERROR_MSG.YOU_CAN_TRY_TO_REFRESH_PAGE', { lng: lng })
142
+ });
143
+ }
136
144
  });
137
145
  }
138
146
 
@@ -10,6 +10,7 @@
10
10
  return {
11
11
  fetchAllPages: fetchAllPages,
12
12
  getErrorMessage: getErrorMessage,
13
+ isDisconnectionError: isDisconnectionError,
13
14
  poll: poll,
14
15
  pruneObject: pruneObject,
15
16
  trackDeletion: trackDeletion
@@ -144,6 +145,15 @@
144
145
  return lodash.defaultTo(result, messages.default);
145
146
  }
146
147
 
148
+ /**
149
+ * Checks if the error status is equal '-1'. It means, that server is unreachable.
150
+ * @param {number} errorStatus - Error status code.
151
+ * @returns {Boolean} if true - server is unreachable
152
+ */
153
+ function isDisconnectionError(errorStatus) {
154
+ return errorStatus === -1;
155
+ }
156
+
147
157
  /**
148
158
  * Polls by calling `pollMethod` and then invoking `isDone` method with `pollMethod`'s result. Stops polling
149
159
  * when `isDone` returned `true`. Keeps on polling as long as `isDone` returns `false`.
@@ -0,0 +1,91 @@
1
+ (function () {
2
+ 'use strict';
3
+
4
+ angular.module('iguazio.dashboard-controls')
5
+ .factory('ServerStatusService', ServerStatusService);
6
+
7
+ function ServerStatusService($http, $q, $i18next, i18next, lodash, ConfigService, DialogsService) {
8
+ var dialogPromise = null;
9
+ var errors = [];
10
+
11
+ return {
12
+ resolveInterceptor: resolveInterceptor,
13
+ rejectInterceptor: rejectInterceptor
14
+ };
15
+
16
+ //
17
+ // Public methods
18
+ //
19
+
20
+ /**
21
+ * Removes error from errors list if server becomes reachable
22
+ * @param {Object} response - backend response object
23
+ * @returns {Promise} returns promise
24
+ */
25
+ function resolveInterceptor(response) {
26
+ if (response && response.status && response.status !== -1) {
27
+ if (errors.length > 0) {
28
+ errors = errors.filter(function (err) {
29
+ return err.method !== response.config.method && err.url !== response.config.url;
30
+ });
31
+ }
32
+
33
+ return $q.resolve(response);
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Adds request to errors list if it`s failed and pops a modal if server isn`t reachable more than 60sec
39
+ * @param {Object} rejectionResponse - backend response object
40
+ * @returns {Promise} returns promise
41
+ */
42
+ function rejectInterceptor(rejectionResponse) {
43
+ const currentError = {
44
+ method: rejectionResponse.config.method,
45
+ url: rejectionResponse.config.url
46
+ };
47
+
48
+ if (rejectionResponse.status === -1 && rejectionResponse.xhrStatus === 'error') {
49
+ const existingFailedResponse = errors.find(function (err) {
50
+ return err.method === rejectionResponse.config.method && err.url === rejectionResponse.config.url;
51
+ });
52
+
53
+ if (existingFailedResponse) {
54
+ const dateNow = new Date();
55
+ const timeFromFirstFailure = (dateNow.getTime() - existingFailedResponse.date.getTime());
56
+
57
+ if (timeFromFirstFailure >= 3000) {
58
+ return showAlert()
59
+ .then(function () {
60
+ location.reload();
61
+ });
62
+ }
63
+ } else {
64
+ currentError.date = new Date();
65
+ errors.push(currentError);
66
+ }
67
+ }
68
+
69
+ return $q.reject(rejectionResponse);
70
+ }
71
+
72
+ /**
73
+ * Pops a modal with an error message and makes sure there's only one open.
74
+ * When the modal is resolved, all pending flows that awaited it will continue.
75
+ * @returns {Promise} resolved when modal is closed ("Refresh" button is clicked)
76
+ */
77
+ function showAlert() {
78
+ var lng = i18next.language;
79
+
80
+ if (lodash.isNull(dialogPromise)) {
81
+ dialogPromise = DialogsService.oopsAlert($i18next.t('common:SERVER_UNREACHABLE_ALERT', {lng: lng}),
82
+ $i18next.t('common:REFRESH', {lng: lng}))
83
+ .then(function () {
84
+ dialogPromise = null;
85
+ });
86
+ }
87
+
88
+ return dialogPromise;
89
+ }
90
+ }
91
+ }());
@@ -22,8 +22,8 @@
22
22
 
23
23
  function FunctionsController($filter, $interval, $q, $rootScope, $scope, $state, $stateParams, $timeout,
24
24
  $transitions, $i18next, i18next, lodash, CommonTableService, ConfigService,
25
- DialogsService, ElementLoadingStatusService, FunctionsService, NuclioHeaderService,
26
- TableSizeService) {
25
+ DialogsService, ElementLoadingStatusService, FunctionsService, GeneralDataService,
26
+ NuclioHeaderService, TableSizeService) {
27
27
  var ctrl = this;
28
28
  var lng = i18next.language;
29
29
  var updatingFunctionsInterval = null;
@@ -344,9 +344,11 @@
344
344
  sortTable(true);
345
345
  })
346
346
  .catch(function (error) {
347
- var defaultMsg = $i18next.t('functions:ERROR_MSG.GET_FUNCTIONS', { lng: lng });
347
+ if (!GeneralDataService.isDisconnectionError(error.status)) {
348
+ var defaultMsg = $i18next.t('functions:ERROR_MSG.GET_FUNCTIONS', {lng: lng});
348
349
 
349
- return DialogsService.alert(lodash.get(error, 'data.error', defaultMsg));
350
+ return DialogsService.alert(lodash.get(error, 'data.error', defaultMsg));
351
+ }
350
352
  })
351
353
  .finally(function () {
352
354
  ctrl.isSplashShowed.value = false;
@@ -75,9 +75,6 @@
75
75
  if (lodash.has(changes, 'version')) {
76
76
  ctrl.annotations = lodash.chain(ctrl.version)
77
77
  .get('metadata.annotations', {})
78
- .omitBy(function (value, key) {
79
- return lodash.startsWith(key, 'nuclio.io/');
80
- })
81
78
  .map(function (value, key) {
82
79
  return {
83
80
  name: key,
@@ -165,10 +162,6 @@
165
162
  */
166
163
  function updateAnnotations() {
167
164
  var isFormValid = true;
168
- var annotations = lodash.get(ctrl.version, 'metadata.annotations', {});
169
- var nuclioAnnotations = lodash.pickBy(annotations, function (value, key) {
170
- return lodash.startsWith(key, 'nuclio.io/');
171
- });
172
165
  var newAnnotations = {};
173
166
 
174
167
  lodash.forEach(ctrl.annotations, function (annotation) {
@@ -188,8 +181,6 @@
188
181
  isDisabled: !isFormValid
189
182
  });
190
183
 
191
- lodash.merge(newAnnotations, nuclioAnnotations);
192
-
193
184
  lodash.set(ctrl.version, 'metadata.annotations', newAnnotations);
194
185
  ctrl.onChangeCallback();
195
186
  }
@@ -20,7 +20,7 @@
20
20
 
21
21
  function NclVersionController($i18next, $interval, $rootScope, $scope, $state, $stateParams, $transitions, $timeout,
22
22
  i18next, lodash, ngDialog, ConfigService, DialogsService, ExportService,
23
- FunctionsService, NuclioHeaderService, VersionHelperService) {
23
+ FunctionsService, GeneralDataService, NuclioHeaderService, VersionHelperService) {
24
24
  var ctrl = this;
25
25
  var deregisterFunction = null;
26
26
  var interval = null;
@@ -369,9 +369,12 @@
369
369
  setIngressHost();
370
370
  })
371
371
  .catch(function (error) {
372
- var defaultMsg = $i18next.t('functions:ERROR_MSG.GET_FUNCTION', { lng: lng });
372
+ if (!GeneralDataService.isDisconnectionError(error.status)) {
373
373
 
374
- DialogsService.alert(lodash.get(error, 'data.error', defaultMsg));
374
+ var defaultMsg = $i18next.t('functions:ERROR_MSG.GET_FUNCTION', {lng: lng});
375
+
376
+ DialogsService.alert(lodash.get(error, 'data.error', defaultMsg));
377
+ }
375
378
  })
376
379
  .finally(function () {
377
380
  ctrl.isSplashShowed.value = false;