config_history_view.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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({
  22. templateName: require('templates/main/dashboard/config_history'),
  23. controllerBinding: 'App.router.mainConfigHistoryController',
  24. filteringComplete: false,
  25. timeOut: null,
  26. content: function () {
  27. return this.get('controller.content');
  28. }.property('controller.content'),
  29. pageContent: function () {
  30. var content = this.get('filteredContent');
  31. if (content.length > ((this.get('endIndex') - this.get('startIndex')) + 1)) {
  32. content = content.slice(0, (this.get('endIndex') - this.get('startIndex')) + 1);
  33. }
  34. return content.sort(function (a, b) {
  35. return a.get('index') - b.get('index');
  36. });
  37. }.property('filteredContent'),
  38. filteredCount: function () {
  39. return this.get('controller.filteredCount');
  40. }.property('controller.filteredCount'),
  41. totalCount: function () {
  42. return this.get('controller.totalCount');
  43. }.property('controller.totalCount'),
  44. /**
  45. * return filtered number of all content number information displayed on the page footer bar
  46. * @returns {String}
  47. */
  48. filteredContentInfo: function () {
  49. return this.t('tableView.filters.filteredConfigVersionInfo').format(this.get('filteredCount'), this.get('totalCount'));
  50. }.property('filteredCount', 'totalCount'),
  51. /**
  52. * synchronize properties of view with controller to generate query parameters
  53. */
  54. updatePagination: function (key) {
  55. if (!Em.isNone(this.get('displayLength'))) {
  56. App.db.setDisplayLength(this.get('controller.name'), this.get('displayLength'));
  57. this.get('controller.paginationProps').findProperty('name', 'displayLength').value = this.get('displayLength');
  58. }
  59. if (!Em.isNone(this.get('startIndex'))) {
  60. App.db.setStartIndex(this.get('controller.name'), this.get('startIndex'));
  61. this.get('controller.paginationProps').findProperty('name', 'startIndex').value = this.get('startIndex');
  62. }
  63. if (key !== 'SKIP_REFRESH') {
  64. this.refresh();
  65. }
  66. },
  67. didInsertElement: function () {
  68. this.addObserver('startIndex', this, 'updatePagination');
  69. this.addObserver('displayLength', this, 'updatePagination');
  70. this.refresh();
  71. this.set('controller.isPolling', true);
  72. this.get('controller').doPolling();
  73. },
  74. /**
  75. * stop polling after leaving config history page
  76. */
  77. willDestroyElement: function () {
  78. this.set('controller.isPolling', false);
  79. clearTimeout(this.get('controller.timeoutRef'));
  80. },
  81. sortView: sort.serverWrapperView,
  82. versionSort: sort.fieldView.extend({
  83. column: 1,
  84. name: 'serviceVersion',
  85. displayName: Em.I18n.t('dashboard.configHistory.table.version.title'),
  86. classNames: ['first']
  87. }),
  88. configGroupSort: sort.fieldView.extend({
  89. column: 2,
  90. name: 'configGroup',
  91. displayName: Em.I18n.t('dashboard.configHistory.table.configGroup.title')
  92. }),
  93. modifiedSort: sort.fieldView.extend({
  94. column: 3,
  95. name: 'createTime',
  96. status: 'sorting_desc',
  97. displayName: Em.I18n.t('dashboard.configHistory.table.created.title')
  98. }),
  99. authorSort: sort.fieldView.extend({
  100. column: 4,
  101. name: 'author',
  102. displayName: Em.I18n.t('common.author')
  103. }),
  104. notesSort: sort.fieldView.extend({
  105. column: 5,
  106. name: 'notes',
  107. displayName: Em.I18n.t('common.notes')
  108. }),
  109. serviceFilterView: filters.createSelectView({
  110. column: 1,
  111. fieldType: 'filter-input-width',
  112. content: function () {
  113. return ['All'].concat(App.Service.find().mapProperty('serviceName'));
  114. }.property('App.router.clusterController.isLoaded'),
  115. onChangeValue: function () {
  116. this.get('parentView').updateFilter(this.get('column'), this.get('actualValue'), 'select');
  117. },
  118. emptyValue: Em.I18n.t('common.all')
  119. }),
  120. configGroupFilterView: filters.createSelectView({
  121. column: 2,
  122. fieldType: 'filter-input-width',
  123. content: function () {
  124. var groupName = App.ServiceConfigVersion.find().mapProperty('groupName').uniq();
  125. if (groupName.indexOf(null) > -1 ){
  126. groupName.splice(groupName.indexOf(null), 1);
  127. }
  128. return ['All'].concat(groupName);
  129. }.property('App.router.mainConfigHistoryController.content'),
  130. onChangeValue: function () {
  131. this.get('parentView').updateFilter(this.get('column'), this.get('actualValue'), 'select');
  132. },
  133. emptyValue: Em.I18n.t('common.all')
  134. }),
  135. modifiedFilterView: filters.createSelectView({
  136. column: 3,
  137. appliedEmptyValue: ["", ""],
  138. fieldType: 'filter-input-width,modified-filter',
  139. content: ['Any', 'Past 1 hour', 'Past 1 Day', 'Past 2 Days', 'Past 7 Days', 'Past 14 Days', 'Past 30 Days'],
  140. valueBinding: "controller.modifiedFilter.optionValue",
  141. startTimeBinding: "controller.modifiedFilter.actualValues.startTime",
  142. endTimeBinding: "controller.modifiedFilter.actualValues.endTime",
  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.startTime', 'controller.modifiedFilter.actualValues.endTime')
  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. updateFilter: function (iColumn, value, type) {
  162. var self = this;
  163. this.set('controller.resetStartIndex', false);
  164. this.saveFilterConditions(iColumn, value, type, false);
  165. if (!this.get('filteringComplete')) {
  166. clearTimeout(this.get('timeOut'));
  167. this.set('timeOut', setTimeout(function () {
  168. self.updateFilter(iColumn, value, type);
  169. }, this.get('filterWaitingTime')));
  170. } else {
  171. clearTimeout(this.get('timeOut'));
  172. this.set('controller.resetStartIndex', true);
  173. this.refresh();
  174. }
  175. },
  176. ConfigVersionView: Em.View.extend({
  177. tagName: 'tr',
  178. showLessNotes: true,
  179. toggleShowLessStatus: function () {
  180. this.set('showLessNotes', !this.get('showLessNotes'));
  181. },
  182. didInsertElement: function () {
  183. App.tooltip(this.$("[rel='Tooltip']"));
  184. }
  185. }),
  186. /**
  187. * sort content
  188. */
  189. refresh: function () {
  190. var self = this;
  191. this.set('filteringComplete', false);
  192. this.get('controller').load().done(function () {
  193. self.set('filteringComplete', true);
  194. self.propertyDidChange('pageContent');
  195. self.set('controller.resetStartIndex', false);
  196. });
  197. },
  198. /**
  199. * associations between host property and column index
  200. * @type {Array}
  201. */
  202. colPropAssoc: function () {
  203. return this.get('controller.colPropAssoc');
  204. }.property('controller.colPropAssoc'),
  205. resetStartIndex: function () {
  206. if (this.get('controller.resetStartIndex') && this.get('filteredCount') > 0) {
  207. this.set('startIndex', 1);
  208. this.updatePagination('SKIP_REFRESH');
  209. }
  210. }.observes('controller.resetStartIndex')
  211. });