config_history_view.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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: function () {
  35. return this.t('tableView.filters.filteredConfigVersionInfo').format(this.get('filteredCount'), this.get('totalCount'));
  36. }.property('filteredCount', 'totalCount'),
  37. didInsertElement: function () {
  38. this.addObserver('startIndex', this, 'updatePagination');
  39. this.addObserver('displayLength', this, 'updatePagination');
  40. this.set('isInitialRendering', true);
  41. this.refresh();
  42. this.set('controller.isPolling', true);
  43. this.get('controller').doPolling();
  44. },
  45. /**
  46. * stop polling after leaving config history page
  47. */
  48. willDestroyElement: function () {
  49. this.set('controller.isPolling', false);
  50. clearTimeout(this.get('controller.timeoutRef'));
  51. },
  52. updateFilter: function (iColumn, value, type) {
  53. if (!this.get('isInitialRendering')) {
  54. this._super(iColumn, value, type);
  55. }
  56. },
  57. sortView: sort.serverWrapperView,
  58. versionSort: sort.fieldView.extend({
  59. column: 1,
  60. name: 'serviceVersion',
  61. displayName: Em.I18n.t('dashboard.configHistory.table.version.title'),
  62. classNames: ['first']
  63. }),
  64. configGroupSort: sort.fieldView.extend({
  65. column: 2,
  66. name: 'configGroup',
  67. displayName: Em.I18n.t('dashboard.configHistory.table.configGroup.title')
  68. }),
  69. modifiedSort: sort.fieldView.extend({
  70. column: 3,
  71. name: 'createTime',
  72. status: 'sorting_desc',
  73. displayName: Em.I18n.t('dashboard.configHistory.table.created.title')
  74. }),
  75. authorSort: sort.fieldView.extend({
  76. column: 4,
  77. name: 'author',
  78. displayName: Em.I18n.t('common.author')
  79. }),
  80. notesSort: sort.fieldView.extend({
  81. column: 5,
  82. name: 'notes',
  83. displayName: Em.I18n.t('common.notes')
  84. }),
  85. serviceFilterView: filters.createSelectView({
  86. column: 1,
  87. fieldType: 'filter-input-width',
  88. content: function () {
  89. return [
  90. {
  91. value: '',
  92. label: Em.I18n.t('common.all')
  93. }
  94. ].concat(App.Service.find().map(function (service) {
  95. return {
  96. value: service.get('serviceName'),
  97. label: service.get('displayName')
  98. }
  99. }));
  100. }.property('App.router.clusterController.isLoaded'),
  101. onChangeValue: function () {
  102. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'select');
  103. }
  104. }),
  105. configGroupFilterView: filters.createSelectView({
  106. column: 2,
  107. fieldType: 'filter-input-width',
  108. content: function () {
  109. var groupName = App.ServiceConfigVersion.find().mapProperty('groupName').uniq();
  110. if (groupName.indexOf(null) > -1) {
  111. groupName.splice(groupName.indexOf(null), 1);
  112. }
  113. return [
  114. {
  115. value: '',
  116. label: Em.I18n.t('common.all')
  117. }
  118. ].concat(groupName.map(function (item) {
  119. return {
  120. value: item,
  121. label: item
  122. }
  123. }));
  124. }.property('App.router.mainConfigHistoryController.content'),
  125. onChangeValue: function () {
  126. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'select');
  127. }
  128. }),
  129. modifiedFilterView: filters.createSelectView({
  130. column: 3,
  131. appliedEmptyValue: ["", ""],
  132. fieldType: 'filter-input-width,modified-filter',
  133. triggeredOnSameValue: [
  134. {
  135. values: ['Custom', 'Custom2'],
  136. displayAs: 'Custom'
  137. }
  138. ],
  139. emptyValue: 'Any',
  140. valueBinding: "controller.modifiedFilter.optionValue",
  141. selectedBinding: "controller.modifiedFilter.optionValue",
  142. contentBinding: "controller.modifiedFilter.content",
  143. onTimeChange: function () {
  144. this.get('parentView').updateFilter(this.get('column'), [this.get('controller.modifiedFilter.actualValues.startTime'), this.get('controller.modifiedFilter.actualValues.endTime')], 'range');
  145. }.observes('controller.modifiedFilter.actualValues')
  146. }),
  147. authorFilterView: filters.createTextView({
  148. column: 4,
  149. fieldType: 'filter-input-width',
  150. onChangeValue: function () {
  151. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'string');
  152. }
  153. }),
  154. notesFilterView: filters.createTextView({
  155. column: 5,
  156. fieldType: 'filter-input-width',
  157. onChangeValue: function () {
  158. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'string');
  159. }
  160. }),
  161. ConfigVersionView: Em.View.extend({
  162. tagName: 'tr',
  163. showLessNotes: true,
  164. toggleShowLessStatus: function () {
  165. this.toggleProperty('showLessNotes');
  166. },
  167. didInsertElement: function () {
  168. App.tooltip(this.$("[rel='Tooltip']"));
  169. }
  170. }),
  171. /**
  172. * refresh table content
  173. */
  174. refresh: function () {
  175. var self = this;
  176. this.set('filteringComplete', false);
  177. this.get('controller').load().done(this.refreshDone);
  178. },
  179. /**
  180. * callback executed after refresh call done
  181. * @method refreshDone
  182. */
  183. refreshDone: function () {
  184. this.set('isInitialRendering', false);
  185. this.set('filteringComplete', true);
  186. this.propertyDidChange('pageContent');
  187. this.set('controller.resetStartIndex', false);
  188. },
  189. /**
  190. * associations between host property and column index
  191. * @type {Array}
  192. */
  193. colPropAssoc: function () {
  194. return this.get('controller.colPropAssoc');
  195. }.property('controller.colPropAssoc')
  196. });