iguazio.dashboard-controls 0.37.10 → 0.37.12-patch2

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.10",
3
+ "version": "v0.37.12-patch2",
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": {
@@ -17,15 +17,20 @@
17
17
  transclude: true
18
18
  });
19
19
 
20
- function IgzElementLoadingStatusController($element, $scope, $state, $timeout, $i18next, i18next, lodash) {
20
+ function IgzElementLoadingStatusController($element, $scope, $state, $i18next, i18next, lodash) {
21
21
  var ctrl = this;
22
- var defaultHeight = 0;
23
22
  var lng = i18next.language;
24
23
 
25
- ctrl.isShowSpinner = true;
26
24
  ctrl.isShowContent = false;
27
25
  ctrl.isShowError = false;
26
+ ctrl.isShowSpinner = true;
28
27
 
28
+ ctrl.deregisterHideError = null;
29
+ ctrl.deregisterHideSpinner = null;
30
+ ctrl.deregisterShowError = null;
31
+ ctrl.deregisterShowSpinner = null;
32
+
33
+ ctrl.$onDestroy = onDestroy;
29
34
  ctrl.$onInit = onInit;
30
35
  ctrl.$onChanges = onChanges;
31
36
 
@@ -36,21 +41,25 @@
36
41
  // Hook methods
37
42
  //
38
43
 
44
+ /**
45
+ * Destructor method
46
+ */
47
+ function onDestroy() {
48
+ deregisterBroadcasts();
49
+ }
50
+
39
51
  /**
40
52
  * Initialization method
41
53
  */
42
54
  function onInit() {
43
- $scope.$on('element-loading-status_show-spinner_' + ctrl.name, showSpinner);
44
- $scope.$on('element-loading-status_hide-spinner_' + ctrl.name, hideSpinner);
45
-
46
- $scope.$on('element-loading-status_show-error_' + ctrl.name, showError);
47
- $scope.$on('element-loading-status_hide-error_' + ctrl.name, hideError);
55
+ registerBroadcasts();
48
56
  }
49
57
 
50
58
  /**
51
59
  * Changes method
60
+ * @param {Object} changes
52
61
  */
53
- function onChanges() {
62
+ function onChanges(changes) {
54
63
  lodash.defaults(ctrl, {
55
64
  loadingStatusSize: 'default',
56
65
  refresh: false,
@@ -66,7 +75,10 @@
66
75
  });
67
76
  }
68
77
 
69
- defaultHeight = ctrl.loadingStatusSize === 'small' ? 20 : 40;
78
+ if (changes && changes.name && changes.name.currentValue !== changes.name.previousValue) {
79
+ deregisterBroadcasts();
80
+ registerBroadcasts();
81
+ }
70
82
  }
71
83
 
72
84
  //
@@ -98,12 +110,20 @@
98
110
  //
99
111
 
100
112
  /**
101
- * Show given loading spinner
113
+ * Deregister broadcasts
102
114
  */
103
- 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() {
104
126
  ctrl.isShowError = false;
105
- ctrl.isShowContent = false;
106
- ctrl.isShowSpinner = true;
107
127
  }
108
128
 
109
129
  /**
@@ -114,6 +134,16 @@
114
134
  ctrl.isShowContent = true;
115
135
  }
116
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
+
117
147
  /**
118
148
  * Show given loading error
119
149
  */
@@ -123,10 +153,12 @@
123
153
  }
124
154
 
125
155
  /**
126
- * Hide given loading error
156
+ * Show given loading spinner
127
157
  */
128
- function hideError() {
158
+ function showSpinner() {
129
159
  ctrl.isShowError = false;
160
+ ctrl.isShowContent = false;
161
+ ctrl.isShowSpinner = true;
130
162
  }
131
163
  }
132
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
 
@@ -341,7 +341,7 @@
341
341
  $scope.$on('info-page-pane_toggled', updateChart);
342
342
  $scope.$on('resize-size-cells', updateChart);
343
343
 
344
- timeout = $timeout(updateChart);
344
+ updateChart();
345
345
  }
346
346
 
347
347
  /**
@@ -43,7 +43,11 @@
43
43
  $timeout(initColumnsWidths);
44
44
  $timeout(initElements);
45
45
 
46
- angular.element($window).on('resize', reloadColumns);
46
+ angular.element($window).on('resize', function () {
47
+ $timeout(function () {
48
+ reloadColumns()
49
+ }, 200)
50
+ });
47
51
  $scope.$on('reload-columns', reloadColumns);
48
52
  $scope.$on('resizable-table-column_reset-data', resetData);
49
53
  $scope.$on('$destroy', onDestroy);
@@ -243,7 +247,7 @@
243
247
  columnWidth: ctrl.columnHeadWidth + 'px',
244
248
  nextColumnWidth: ctrl.nextBlockWidth + 'px'
245
249
  });
246
- }, 200);
250
+ });
247
251
  }
248
252
  }
249
253
 
@@ -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;