<%= javascript_include_tag 'top-search' %>
<%= javascript_include_tag 'sortable' %>
+ <%= javascript_include_tag 'common/inputs' %>
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag 'dashboard' %>
'3': '<%= Api::Utils.period_label(3) -%>'
},
favorites: <%= render :partial => 'measures/favourites2' -%>,
+ workDuration: {
+ days: '<%= message('work_duration.x_days') -%>',
+ hours: '<%= message('work_duration.x_hours') -%>',
+ minutes: '<%= message('work_duration.x_minutes') -%>'
+ },
phrases: {
'any': '<%= escape_javascript message('any') -%>',
{ key: '3', text: '<%= Api::Utils.period_label(3) -%>' }
],
+ workDuration: {
+ days: '<%= message('work_duration.x_days') -%>',
+ hours: '<%= message('work_duration.x_hours') -%>',
+ minutes: '<%= message('work_duration.x_minutes') -%>'
+ },
+
phrases: {
areYouSure: '<%= message('are_you_sure') -%>',
alerts: {
<td width="15%">
<i class="icon-alert-warn" title="<%= message('alerts.warn_tooltip') -%>"></i>
{{#if canEdit}}
- <input name="warning" type="text" value="{{warning}}">
+ <input name="warning" class="measure-input" data-type="{{metric.type}}" type="text">
{{else}}
{{warning}}
{{/if}}
<td width="15%">
<i class="icon-alert-error" title="<%= message('alerts.error_tooltip') -%>"></i>
{{#if canEdit}}
- <input name="error" type="text" value="{{error}}">
+ <input name="error" class="measure-input" data-type="{{metric.type}}" type="text">
{{else}}
{{error}}
{{/if}}
--- /dev/null
+$ = jQuery
+
+$ ->
+
+ transformPattern = (pattern) ->
+ return pattern.replace /\{0\}/g, '(\\d+)'
+
+
+ convertWorkDuration = (value) ->
+ daysPattern = transformPattern window.SS.workDuration.days
+ hoursPattern = transformPattern window.SS.workDuration.hours
+ minutesPattern = transformPattern window.SS.workDuration.minutes
+
+ days = value.match daysPattern
+ hours = value.match hoursPattern
+ minutes = value.match minutesPattern
+
+ days = if days then +days[1] else 0
+ hours = if hours then +hours[1] else 0
+ minutes = if minutes then +minutes[1] else 0
+
+ if value && value.length > 0 && days == 0 && hours == 0 && minutes == 0
+ value
+ else
+ (days * 8 + hours) * 60 + minutes
+
+
+ restoreWorkDuration = (value) ->
+ days = Math.floor(value / (8 * 60))
+ hours = Math.floor((value - days * 8 * 60) / 60)
+ minutes = value % 60
+ result = []
+ result.push window.SS.workDuration.days.replace('{0}', days) if days > 0
+ result.push window.SS.workDuration.hours.replace('{0}', hours) if hours > 0
+ result.push window.SS.workDuration.minutes.replace('{0}', minutes) if minutes > 0
+ result.join ' '
+
+
+ convertValue = (value, input) ->
+ type = input.data 'type'
+
+ # No convertation if input doesn't have data-type
+ return value unless type?
+
+ # Do necessary convertion depeneds on input data-type
+ switch type
+ when 'WORK_DUR' then convertWorkDuration value
+ else value
+
+
+ restoreValue = (value, input) ->
+ type = input.data 'type'
+
+ # No convertation if input doesn't have data-type
+ return value unless type?
+
+ # Do necessary convertion depeneds on input data-type
+ switch type
+ when 'WORK_DUR' then restoreWorkDuration value
+ else value
+
+
+ originalVal = $.fn.val
+ $.fn.val = (value) ->
+ if arguments.length
+ originalVal.call @, (restoreValue value, @)
+ else
+ convertValue originalVal.call(@), @
+
+ $.fn.originalVal = originalVal
+
--- /dev/null
+// Generated by CoffeeScript 1.6.3
+(function() {
+ var $;
+
+ $ = jQuery;
+
+ $(function() {
+ var convertValue, convertWorkDuration, originalVal, restoreValue, restoreWorkDuration, transformPattern;
+ transformPattern = function(pattern) {
+ return pattern.replace(/\{0\}/g, '(\\d+)');
+ };
+ convertWorkDuration = function(value) {
+ var days, daysPattern, hours, hoursPattern, minutes, minutesPattern;
+ daysPattern = transformPattern(window.SS.workDuration.days);
+ hoursPattern = transformPattern(window.SS.workDuration.hours);
+ minutesPattern = transformPattern(window.SS.workDuration.minutes);
+ days = value.match(daysPattern);
+ hours = value.match(hoursPattern);
+ minutes = value.match(minutesPattern);
+ days = days ? +days[1] : 0;
+ hours = hours ? +hours[1] : 0;
+ minutes = minutes ? +minutes[1] : 0;
+ if (value && value.length > 0 && days === 0 && hours === 0 && minutes === 0) {
+ return value;
+ } else {
+ return (days * 8 + hours) * 60 + minutes;
+ }
+ };
+ restoreWorkDuration = function(value) {
+ var days, hours, minutes, result;
+ days = Math.floor(value / (8 * 60));
+ hours = Math.floor((value - days * 8 * 60) / 60);
+ minutes = value % 60;
+ result = [];
+ if (days > 0) {
+ result.push(window.SS.workDuration.days.replace('{0}', days));
+ }
+ if (hours > 0) {
+ result.push(window.SS.workDuration.hours.replace('{0}', hours));
+ }
+ if (minutes > 0) {
+ result.push(window.SS.workDuration.minutes.replace('{0}', minutes));
+ }
+ return result.join(' ');
+ };
+ convertValue = function(value, input) {
+ var type;
+ type = input.data('type');
+ if (type == null) {
+ return value;
+ }
+ switch (type) {
+ case 'WORK_DUR':
+ return convertWorkDuration(value);
+ default:
+ return value;
+ }
+ };
+ restoreValue = function(value, input) {
+ var type;
+ type = input.data('type');
+ if (type == null) {
+ return value;
+ }
+ switch (type) {
+ case 'WORK_DUR':
+ return restoreWorkDuration(value);
+ default:
+ return value;
+ }
+ };
+ originalVal = $.fn.val;
+ $.fn.val = function(value) {
+ if (arguments.length) {
+ return originalVal.call(this, restoreValue(value, this));
+ } else {
+ return convertValue(originalVal.call(this), this);
+ }
+ };
+ return $.fn.originalVal = originalVal;
+ });
+
+}).call(this);
periodText: this.$('[name=period] option:selected').text(),
op: this.$('[name=op]').val(),
opText: this.$('[name=op] option:selected').text(),
- val: this.$('[name=val]').val()
+ val: this.$('[name=val]').val(),
+ valText: this.$('[name=val]').originalVal()
};
+ this.updateDataType(value);
this.model.set('value', value);
},
+ updateDataType: function(value) {
+ var metric = _.find(window.SS.metrics, function(m) {
+ return m.metric.name === value.metric;
+ });
+ if (metric) {
+ this.$('[name=val]').data('type', metric.metric.val_type);
+ }
+ },
+
+
onRender: function() {
var value = this.model.get('value') || {};
this.$('[name=metric]').val(value.metric).select2({
placeholder: '=',
minimumResultsForSearch: 100
});
+ this.updateDataType(value);
this.$('[name=val]').val(value.val);
this.inputChanged();
},
renderValue: function() {
return this.isDefaultValue() ?
window.SS.phrases.notSet :
- this.model.get('value').metricText + ' ' + this.model.get('value').opText + ' ' + this.model.get('value').val;
+ this.model.get('value').metricText + ' ' + this.model.get('value').opText + ' ' + this.model.get('value').valText;
},
onRender: ->
@ui.periodSelect.val @model.get('period') || '0'
@ui.operatorSelect.val @model.get('op')
+ @ui.warningInput.val @model.get('warning')
+ @ui.errorInput.val @model.get('error')
@ui.periodSelect.select2
allowClear: false
QualityGateDetailConditionView.prototype.onRender = function() {
this.ui.periodSelect.val(this.model.get('period') || '0');
this.ui.operatorSelect.val(this.model.get('op'));
+ this.ui.warningInput.val(this.model.get('warning'));
+ this.ui.errorInput.val(this.model.get('error'));
this.ui.periodSelect.select2({
allowClear: false,
minimumResultsForSearch: 999,
<js>/javascripts/top-search.js</js>
<js>/javascripts/sortable.js</js>
+ <js>/javascripts/common/inputs.js</js>
<js>/javascripts/application.js</js>
<js>/javascripts/dashboard.js</js>