2014-12-17 19:44:48 +00:00
|
|
|
function formatTimes(times) {
|
|
|
|
if (times === 1) {
|
|
|
|
return 'once';
|
|
|
|
} else {
|
|
|
|
return `${times} times`;
|
|
|
|
}
|
|
|
|
}
|
2014-12-15 17:24:32 +00:00
|
|
|
|
2014-12-17 19:44:48 +00:00
|
|
|
export default {
|
|
|
|
setup() {
|
|
|
|
this.minimum = this.properties.spec.minimum;
|
|
|
|
this.maximum = this.properties.spec.maximum;
|
|
|
|
this.greedy = (this.properties.greedy.textValue === '');
|
|
|
|
this.hasSkip = this.minimum === 0;
|
|
|
|
this.hasLoop = this.maximum === -1 || this.maximum > 1;
|
|
|
|
|
|
|
|
Object.defineProperty(this, 'contentPosition', {
|
|
|
|
get: function() {
|
|
|
|
var x = 0, y = 0;
|
|
|
|
|
|
|
|
if (this.hasLoop) {
|
|
|
|
x = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.hasSkip) {
|
|
|
|
y = 10;
|
|
|
|
x = 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Snap.matrix().translate(x, y);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(this, 'label', {
|
|
|
|
get: function() {
|
|
|
|
if (this.minimum >= 2 && this.maximum === -1) {
|
|
|
|
return `${this.minimum - 1}+ times`;
|
|
|
|
} else if (this.minimum <= 1 && this.maximum >= 2) {
|
|
|
|
return `at most ${formatTimes(this.maximum - 1)}`;
|
|
|
|
} else if (this.minimum >= 2 && this.maximum >= 2) {
|
|
|
|
if (this.minimum === this.maximum) {
|
|
|
|
return formatTimes(this.minimum - 1);
|
2014-12-15 17:24:32 +00:00
|
|
|
} else {
|
2014-12-17 19:44:48 +00:00
|
|
|
return `${this.minimum - 1}...${formatTimes(this.maximum - 1)}`;
|
2014-12-15 17:24:32 +00:00
|
|
|
}
|
2014-12-17 19:44:48 +00:00
|
|
|
}
|
2014-12-15 17:24:32 +00:00
|
|
|
}
|
2014-12-17 19:44:48 +00:00
|
|
|
});
|
2014-12-06 17:34:00 +00:00
|
|
|
}
|
|
|
|
}
|