forked from shado-av/shado-webdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-component.js
299 lines (288 loc) · 14.1 KB
/
vue-component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
Vue.component('distribution-params', {
props: {
dist: { // "ELUCTN"
type: String,
default: "E",
},
leadTask: {
type: Number,
default: -1,
},
params: { // [4, 6, 8]
type: Array,
default: () => []
},
distLabel: {
type: String,
default: ""
},
paramsLabel: {
type: String,
default: ""
},
nOption: { // 0 - arrival, 1 - duration, 2 - expiration
type: Number,
default: 1
},
},
data: function() {
return { errors: [] };
},
methods: {
getPos(dist) {
var x = 18, y = 0;
switch(dist) {
case 'E':
x = 3; y = 1;
break;
case 'L':
x = 4; y = 2;
break;
case 'U':
x = 6; y = 2;
break;
case 'C':
x = 8; y = 1;
break;
case 'T':
x = 9; y = 3;
break;
}
return { x: x, y: y};
},
onChangeDist(e) {
var d_params = this.params;
var d_dist = e.target.value;
// save the old value
var xx = this.getPos(this.dist);
//console.log("Before", this.dist, xx, d_params);
for(var i=0;i<xx.y;i++) {
d_params[i+xx.x] = d_params[i];
}
// restore the saved value
xx = this.getPos(d_dist);
for(var i=0;i<xx.y;i++) {
d_params[i] = d_params[i+xx.x];
}
//console.log("After", d_dist,xx, d_params);
this.$emit('update:dist', d_dist);
this.$emit('update:params', d_params);
//this.$forceUpdate();
},
// check whether the params is numbers and greater than zero
checkNumbers(params, length) {
for(var i=0;i<length;i++) {
if (typeof params[i] !== 'number' || params[i] <= 0)
return false;
}
return true;
},
validateInput(isDisplying) {
// check whether the current distribution setting is correct
// bigger than 0
// min < max (uniform)
// min < mode < max (triangular)
const paramSize = { 'E': 1, 'C':1, 'U':2, 'L':2, 'T': 3};
this.errors = [];
//console.log("ValidateInput", this.params, this.dist);
if (!this.checkNumbers(this.params, paramSize[this.dist])) {
this.errors.push("Distribution parameters should be greater than 0. ");
}
switch(this.dist) {
case 'U':
if (this.params[0] > this.params[1]) {
this.errors.push("X should be smaller than Y.");
}
break;
case 'T':
if (this.params[0] > this.params[1] || this.params[0] > this.params[2]
|| this.params[1] > this.params[2]) {
this.errors.push("X < Z < Y");
}
break;
}
if (this.errors.length > 0)
return false;
return true;
},
},
mounted() {
EventBus.$on("validateInput", this.validateInput);
},
template: `<div class="form-group form-row">
<div class="col-12" v-if='distLabel !== ""'>
<label>{{distLabel}}</label>
</div>
<div class="col-sm-12">
<select class="custom-select" id="transition" :value="dist" @change="onChangeDist" v-if="leadTask >= 0">
<option value="E">On average, X minutes later.</option>
<option value="L">On average, X minutes +/- Y minutes later.</option>
<option value="U">On average, X to Y minutes later.</option>
<option value="T">On average, X to Y minutes, usually around Z minutes later.</option>
<option value="C">Exactly X minutes later.</option>
</select>
<select class="custom-select" id="transition" :value="dist" @change="onChangeDist" v-else-if="nOption === 0">
<option value="E">On average, once every X minutes.</option>
<option value="L">On average, once every X minutes +/- Y minutes.</option>
<option value="U">Once every X to Y minutes.</option>
<option value="T">Once every X to Y minutes, usually around Z minutes.</option>
<option value="C">Exactly once every X minutes.</option>
</select>
<select class="custom-select" id="transition" :value="dist" @change="onChangeDist" v-if="nOption === 1">
<option value="E">On average, X minutes.</option>
<option value="L">On average, X minutes +/- Y minutes.</option>
<option value="U">X to Y minutes.</option>
<option value="T">X to Y minutes, usually around Z minutes.</option>
<option value="C">Exactly X minutes.</option>
</select>
<select class="custom-select" id="transition" :value="dist" @change="onChangeDist" v-if="nOption === 2">
<option value="N" v-show="nOption">It can wait the whole shift time.</option>
<option value="E">It must be done, on average, by X minutes after it appears.</option>
<option value="L">It must be done, on average, by X minutes +/- Y minutes after it appears.</option>
<option value="U">It must be done within X to Y minutes after it appears.</option>
<option value="T">It must be done within X to Y minutes, usually around Z minutes, after it appears.</option>
<option value="C">It must be done by exactly X minutes after it appears.</option>
</select>
<small class="form-text text-muted mb-3">Choose Your Estimation</small>
</div>
<!-- distribution parameters (task.arrivalParam) -->
<div class="col-sm-12">
<div v-if="dist === 'E'" class="form-inline no-gutters">
<span v-if="nOption === 2">It must be done, on average, by </span>
<span v-else-if="nOption === 1 || leadTask >= 0">On average, </span>
<span v-else-if="nOption === 0">On average, once every </span>
<span class="mr-2 ml-2 form-group">
<input class="form-control width-100" type="number" step="any" placeholder="X" v-model.number="params[0]" @change="validateInput">
</span>
<span>minutes</span>
<span class="ml-2" v-if="nOption === 2">after it appears.</span>
<span class="ml-2" v-if="leadTask >=0">later.</span>
</div>
<div v-if="dist === 'L'" class="form-inline no-gutters">
<span v-if="nOption === 2">It must be done, on average, by </span>
<span v-else-if="nOption === 1 || leadTask >= 0">On average, </span>
<span v-else-if="nOption === 0">On average, once every </span>
<div class="ml-2 mr-2 form-group">
<input class="form-control width-100" type="number" step="any" placeholder="X" v-model.number="params[0]" @change="validateInput">
</div>
<span>minutes +/-</span>
<div class="ml-2 mr-2 form-group">
<input class="form-control width-100" type="number" step="any" placeholder="Y" v-model.number="params[1]" @change="validateInput">
</div>
<span>minutes</span>
<span class="ml-2" v-if="nOption === 2">after it appears.</span>
<span class="ml-2" v-if="leadTask >=0">later.</span>
</div>
<div v-if="dist === 'U'" class="form-inline no-gutters">
<span class="mr-2" v-if="leadTask >= 0">On average, </span>
<span class="mr-2" v-else-if="nOption === 0">Once every</span>
<span class="mr-2" v-else-if="nOption === 2">It must be done by</span>
<div class="mr-2 form-group">
<input class="form-control width-100" type="number" step="any" placeholder="X" v-model.number="params[0]" @change="validateInput">
</div>
<span>to</span>
<div class="ml-2 mr-2 form-group">
<input class="form-control width-100" type="number" step="any" placeholder="Y" v-model.number="params[1]" @change="validateInput">
</div>
<span>minutes</span>
<span class="ml-2" v-if="nOption === 2">after it appears.</span>
<span class="ml-2" v-if="leadTask >=0">later.</span>
</div>
<div v-if="dist === 'C'" class="form-inline no-gutters">
<span v-if="nOption === 1 || leadTask >= 0">Exactly</span>
<span v-else-if="nOption === 2">It must be done by exactly</span>
<span v-else-if="nOption === 0">Exactly once every</span>
<div class="ml-2 mr-2 form-group">
<input class="form-control width-100" type="number" step="any" placeholder="X" v-model.number="params[0]" @change="validateInput">
</div>
<span>minutes</span>
<span class="ml-2" v-if="nOption === 2">after it appears</span>
<span class="ml-2" v-if="leadTask >=0">later.</span>
</div>
<div v-if="dist === 'T'" class="form-inline no-gutters">
<span class="mr-2" v-if="nOption === 2">It must be done by</span>
<span class="mr-2" v-else-if="leadTask >= 0">On average,</span>
<span class="mr-2" v-else-if="nOption === 0">Once every</span>
<div class="mr-2 form-group">
<input class="form-control width-100" type="number" step="any" placeholder="X" v-model.number="params[0]" @change="validateInput">
</div>
<span>to</span>
<div class="ml-2 mr-2 form-group">
<input class="form-control width-100" type="number" step="any" placeholder="Y" v-model.number="params[2]" @change="validateInput">
</div>
<span>minutes, usually around</span>
<div class="ml-2 mr-2 form-group">
<input class="form-control width-100" type="number" step="any" placeholder="Z" v-model.number="params[1]" @change="validateInput">
</div>
<span>minutes</span>
<span class="ml-2" v-if="nOption === 2">after it appears.</span>
<span class="ml-2" v-if="leadTask >=0">later.</span>
</div>
<div class="mt-3 alert alert-danger" v-if="errors.length">
<span v-for="error in errors">{{ error }}</span>
</div>
</div>
</div>`
});
Vue.component('number-input', {
props: {
value: {
type: Number,
default: 50
},
float: {
type: Boolean,
default: false
},
fixed: {
type: Number,
default: 2
},
textEnd: {
type:String,
default: ""
},
max: {
type: Number,
default: 100
},
min: {
type: Number,
default: 0
},
step: {
type: Number,
default: 10
},
margin: {
type:Boolean,
default: false
}
},
methods: {
stepNumberInput(step) {
this.validateInput(this.value + step);
},
validateInput(val) {
if (!this.float) {
val = parseInt(val);
} else {
val = 1 * val.toFixed(this.fixed);
}
if (val < this.min) val = this.min;
if (val > this.max) val = this.max;
this.$emit('update:value', val);
this.$forceUpdate(); // not updating when you input more than max twice
this.$emit('change'); // change event...
}
},
template: `<div :class="['number-input', {'mt-3' : margin}, {'mb-3' : margin}]">
<button @click="stepNumberInput(-step)" class="minus"><i class="fas fa-minus fa-lg"></i></button>
<input type="number" @change="validateInput(parseFloat($event.target.value))"
:value="value">
<button @click="stepNumberInput(step)" :class="['plus', {'number-only' : textEnd==='' }]"><i class="fas fa-plus fa-lg"></i></button>
<div class="input-group-append" v-if="textEnd!==''">
<span class="input-group-text"><span v-html="textEnd"></span></span>
</div>
</div>`
});