config_history_view.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var filters = require('views/common/filter_view');
  20. var sort = require('views/common/sort_view');
  21. App.MainConfigHistoryView = App.TableView.extend(App.TableServerViewMixin, {
  22. templateName: require('templates/main/dashboard/config_history'),
  23. controllerBinding: 'App.router.mainConfigHistoryController',
  24. /**
  25. * @type {boolean}
  26. * @default false
  27. */
  28. filteringComplete: false,
  29. isInitialRendering: true,
  30. /**
  31. * return filtered number of all content number information displayed on the page footer bar
  32. * @returns {String}
  33. */
  34. filteredContentInfo: Em.computed.i18nFormat('tableView.filters.filteredConfigVersionInfo', 'filteredCount', 'totalCount'),
  35. willInsertElement: function () {
  36. var
  37. controllerName = this.get('controller.name'),
  38. savedSortConditions = App.db.getSortingStatuses(controllerName) || [];
  39. if (savedSortConditions.everyProperty('status', 'sorting')) {
  40. savedSortConditions.push({
  41. name: "createTime",
  42. status: "sorting_desc"
  43. });
  44. App.db.setSortingStatuses(controllerName, savedSortConditions);
  45. }
  46. if (!this.get('controller.showFilterConditionsFirstLoad')) {
  47. this.clearFilterConditionsFromLocalStorage();
  48. }
  49. this._super();
  50. },
  51. didInsertElement: function () {
  52. this.addObserver('startIndex', this, 'updatePagination');
  53. this.addObserver('displayLength', this, 'updatePagination');
  54. this.set('isInitialRendering', true);
  55. this.refresh();
  56. this.set('controller.isPolling', true);
  57. this.get('controller').doPolling();
  58. },
  59. /**
  60. * stop polling after leaving config history page
  61. */
  62. willDestroyElement: function () {
  63. this.set('controller.isPolling', false);
  64. clearTimeout(this.get('controller.timeoutRef'));
  65. },
  66. updateFilter: function (iColumn, value, type) {
  67. if (!this.get('isInitialRendering')) {
  68. this._super(iColumn, value, type);
  69. }
  70. },
  71. sortView: sort.serverWrapperView,
  72. versionSort: sort.fieldView.extend({
  73. column: 1,
  74. name: 'serviceVersion',
  75. displayName: Em.I18n.t('dashboard.configHistory.table.version.title'),
  76. classNames: ['first']
  77. }),
  78. configGroupSort: sort.fieldView.extend({
  79. column: 2,
  80. name: 'configGroup',
  81. displayName: Em.I18n.t('dashboard.configHistory.table.configGroup.title')
  82. }),
  83. modifiedSort: sort.fieldView.extend({
  84. column: 3,
  85. name: 'createTime',
  86. displayName: Em.I18n.t('dashboard.configHistory.table.created.title')
  87. }),
  88. authorSort: sort.fieldView.extend({
  89. column: 4,
  90. name: 'author',
  91. displayName: Em.I18n.t('common.author')
  92. }),
  93. notesSort: sort.fieldView.extend({
  94. column: 5,
  95. name: 'notes',
  96. displayName: Em.I18n.t('common.notes')
  97. }),
  98. serviceFilterView: filters.createSelectView({
  99. column: 1,
  100. fieldType: 'filter-input-width',
  101. content: function () {
  102. return [
  103. {
  104. value: '',
  105. label: Em.I18n.t('common.all')
  106. }
  107. ].concat(App.StackService.find().map(function (service) {
  108. return {
  109. value: service.get('serviceName'),
  110. label: service.get('displayName')
  111. }
  112. }));
  113. }.property('App.router.clusterController.isLoaded'),
  114. onChangeValue: function () {
  115. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'select');
  116. }
  117. }),
  118. configGroupFilterView: filters.createSelectView({
  119. column: 2,
  120. fieldType: 'filter-input-width',
  121. content: function () {
  122. var groupName = App.ServiceConfigVersion.find().mapProperty('groupName').uniq();
  123. if (groupName.indexOf(null) > -1) {
  124. groupName.splice(groupName.indexOf(null), 1);
  125. }
  126. return [
  127. {
  128. value: '',
  129. label: Em.I18n.t('common.all')
  130. }
  131. ].concat(groupName.map(function (item) {
  132. return {
  133. value: item,
  134. label: item
  135. }
  136. }));
  137. }.property('parentView.isInitialRendering'),
  138. onChangeValue: function () {
  139. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'select');
  140. }
  141. }),
  142. modifiedFilterView: filters.createSelectView({
  143. column: 3,
  144. appliedEmptyValue: ["", ""],
  145. fieldType: 'filter-input-width,modified-filter',
  146. emptyValue: 'Any',
  147. contentBinding: "controller.modifiedFilter.content",
  148. onChangeValue: function () {
  149. this.set("controller.modifiedFilter.optionValue", this.get('selected'));
  150. this.get('parentView').updateFilter(this.get('column'), [this.get('controller.modifiedFilter.actualValues.startTime'), this.get('controller.modifiedFilter.actualValues.endTime')], 'range');
  151. }
  152. }),
  153. authorFilterView: filters.createTextView({
  154. column: 4,
  155. fieldType: 'filter-input-width',
  156. onChangeValue: function () {
  157. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'string');
  158. }
  159. }),
  160. notesFilterView: filters.createTextView({
  161. column: 5,
  162. fieldType: 'filter-input-width',
  163. onChangeValue: function () {
  164. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'string');
  165. }
  166. }),
  167. ConfigVersionView: Em.View.extend({
  168. tagName: 'tr',
  169. showLessNotes: true,
  170. toggleShowLessStatus: function () {
  171. this.toggleProperty('showLessNotes');
  172. },
  173. didInsertElement: function () {
  174. App.tooltip(this.$("[rel='Tooltip']"), {html: false});
  175. },
  176. // Define if show plain text label or link
  177. isServiceLinkDisabled: function () {
  178. return this.get('content.serviceName') === 'KERBEROS' && !App.Service.find().someProperty('serviceName', 'KERBEROS');
  179. }.property('content.serviceName')
  180. }),
  181. /**
  182. * refresh table content
  183. */
  184. refresh: function () {
  185. var self = this;
  186. this.set('filteringComplete', false);
  187. this.get('controller').load().done(function () {
  188. self.refreshDone.apply(self);
  189. });
  190. },
  191. /**
  192. * Clear all filter values, update filter conditions in the localStorage and update table data with API-request
  193. *
  194. * @method clearFilters
  195. * @override
  196. */
  197. clearFilters: function () {
  198. this._super();
  199. this.saveAllFilterConditions();
  200. this.refresh();
  201. },
  202. /**
  203. * callback executed after refresh call done
  204. * @method refreshDone
  205. */
  206. refreshDone: function () {
  207. this.set('isInitialRendering', false);
  208. this.set('filteringComplete', true);
  209. this.propertyDidChange('pageContent');
  210. this.set('controller.resetStartIndex', false);
  211. App.loadTimer.finish('Config History Page');
  212. },
  213. /**
  214. * associations between host property and column index
  215. * @type {Array}
  216. */
  217. colPropAssoc: function () {
  218. return this.get('controller.colPropAssoc');
  219. }.property('controller.colPropAssoc'),
  220. filter: Em.K
  221. });