@onehat/data 1.8.0 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,4 +21,26 @@ describe('PercentProperty', function() {
|
|
|
21
21
|
expect(this.property.displayValue).to.be.eq('12.325%');
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
it('omitZeros', function() {
|
|
25
|
+
this.property.setValue('1234.56');
|
|
26
|
+
expect(this.property.displayValue).to.be.eq('1234.560%');
|
|
27
|
+
|
|
28
|
+
this.property.setValue('1234.50');
|
|
29
|
+
expect(this.property.displayValue).to.be.eq('1234.500%');
|
|
30
|
+
|
|
31
|
+
this.property.setValue('1234.00');
|
|
32
|
+
expect(this.property.displayValue).to.be.eq('1234.000%');
|
|
33
|
+
|
|
34
|
+
this.property.omitZeros = true;
|
|
35
|
+
|
|
36
|
+
this.property.setValue('1234.56');
|
|
37
|
+
expect(this.property.displayValue).to.be.eq('1234.56%');
|
|
38
|
+
|
|
39
|
+
this.property.setValue('1234.50');
|
|
40
|
+
expect(this.property.displayValue).to.be.eq('1234.5%');
|
|
41
|
+
|
|
42
|
+
this.property.setValue('1234.00');
|
|
43
|
+
expect(this.property.displayValue).to.be.eq('1234%');
|
|
44
|
+
});
|
|
45
|
+
|
|
24
46
|
});
|
package/package.json
CHANGED
package/src/Entity.js
CHANGED
|
@@ -8,12 +8,22 @@ import Formatters from '../Util/Formatters';
|
|
|
8
8
|
* @extends PercentProperty
|
|
9
9
|
*/
|
|
10
10
|
export default class PercentIntProperty extends FloatProperty {
|
|
11
|
+
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
|
|
15
|
+
const defaults = {
|
|
16
|
+
omitZeros: false, // Should we omit any .00 at the end?
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
_.merge(this, defaults, config);
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
getDisplayValue = () => {
|
|
13
23
|
if (this.isDestroyed) {
|
|
14
24
|
throw Error('this.getDisplayValue is no longer valid. Property has been destroyed.');
|
|
15
25
|
}
|
|
16
|
-
return Formatters.FormatPercentInt(this.parsedValue);
|
|
26
|
+
return Formatters.FormatPercentInt(this.parsedValue, this.omitZeros);
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
};
|
package/src/Repository/Ajax.js
CHANGED
|
@@ -102,6 +102,11 @@ class AjaxRepository extends Repository {
|
|
|
102
102
|
*/
|
|
103
103
|
this.allowsMultiSort = false;
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* @member {object} lastSendOptions - Last options sent to server
|
|
107
|
+
*/
|
|
108
|
+
this.lastSendOptions = null;
|
|
109
|
+
|
|
105
110
|
/**
|
|
106
111
|
* @member {Object} _params - Object of query params to submit to server
|
|
107
112
|
* @private
|
|
@@ -786,6 +791,8 @@ class AjaxRepository extends Repository {
|
|
|
786
791
|
console.log(url, options);
|
|
787
792
|
}
|
|
788
793
|
|
|
794
|
+
this.lastSendOptions = options;
|
|
795
|
+
|
|
789
796
|
return this.axios(options)
|
|
790
797
|
.catch(error => {
|
|
791
798
|
if (this.debugMode) {
|
package/src/Util/Formatters.js
CHANGED
|
@@ -168,10 +168,13 @@ class Formatters {
|
|
|
168
168
|
return value.toFixed(precision) + '%';
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
static FormatPercentInt = (str) => {
|
|
171
|
+
static FormatPercentInt = (str, omitZeros = false) => {
|
|
172
172
|
if (_.isNil(str)) {
|
|
173
173
|
return str;
|
|
174
174
|
}
|
|
175
|
+
if (omitZeros) {
|
|
176
|
+
str = parseFloat(str).toString();
|
|
177
|
+
}
|
|
175
178
|
return '' + str + '%';
|
|
176
179
|
}
|
|
177
180
|
|