number_widget_view.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. App.NumberWidgetView = Em.View.extend(App.WidgetMixin, {
  20. templateName: require('templates/common/widget/number_widget'),
  21. /**
  22. * @type {string}
  23. */
  24. value: '',
  25. /**
  26. * common metrics container
  27. * @type {Array}
  28. */
  29. metrics: [],
  30. /**
  31. * color of content calculated by thresholds
  32. * @type {string}
  33. */
  34. contentColor: function () {
  35. var value = parseFloat(this.get('value'));
  36. var warningThreshold = parseFloat(this.get('content.properties.warning_threshold'));
  37. var errorThreshold = parseFloat(this.get('content.properties.error_threshold'));
  38. if (value <= warningThreshold) {
  39. return 'green';
  40. } else if (value <= errorThreshold) {
  41. return 'orange';
  42. } else {
  43. return 'red';
  44. }
  45. }.property('value', 'content.properties.warning_threshold', 'content.properties.error_threshold'),
  46. drawWidget: function () {
  47. if (this.get('isLoaded')) {
  48. this.calculateValues();
  49. this.set('value', this.get('content.values')[0].computedValue);
  50. }
  51. }
  52. });