-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroster.js
More file actions
413 lines (368 loc) · 9.09 KB
/
roster.js
File metadata and controls
413 lines (368 loc) · 9.09 KB
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
let starter = []
let sc = []
let sr = []
function getstarter(){
starter.splice(0,27);
sc.splice(0,27);
sr.splice(0,27);
var i =0;
while(i < 7){
var h = 0;
while(h<4){
starter.push(document.querySelector('.table'+i+' .row'+h).value);
sc.push(i);
sr.push(h);
h = h+1;
}
i=i+1;
}
}
function autocheck(){
//일단 다 지우고 시작
var b = 0;
while(b<12){
document.querySelector('.n'+b+' .times').style.backgroundColor = '#be9c91'
b=b+1;
}
//명단에 있는 근무자의 총 수를 구한다.
var i = 0;
var t = 0;
while(i<12){
if(document.querySelector('.name'+i).value !=''){
t=t+1;
}
i=i+1;
}
//근무자가 있는 근무수 칸의 값을 다 더한다.
var f = 0;
var a = 0;
while(f<12){
if(document.querySelector('.name'+f).value !=''){
a=a+Math.floor(document.querySelector('.n'+f+' .times').value);
}
f=f+1;
}
//근무표에 내용이 있는 칸이 있으면 개당 1씩 근무수 총합에 다시 더한다.
var c=0;
while(c<7){
var r=0;
while(r<4){
if(document.querySelector('.table'+c+' .row'+r).value!=""){
a=a+1;
}
r=r+1;
}
c=c+1;
}
//근무수 총합이 28일 경우 녹색, 그렇지 않을 경우 홍색을 근무자가 있는 근무수 칸에 칠한다.
if(a==28){
var i=0;
while(i<12){
if(document.querySelector('.name'+i).value !=''){
document.querySelector('.n'+i+' .times').style.backgroundColor='green';
}
i=i+1;
}
}else{
var i=0;
while(i<12){
if(document.querySelector('.name'+i).value !=''){
document.querySelector('.n'+i+' .times').style.backgroundColor='red';
}
i=i+1;
}
}
}
function autocount(){
var b = 0;
while(b<12){
document.querySelector('.n'+b+' .times').value =''
b=b+1;
}
var i = 0;
var t = 0;
while(i<12){
if(document.querySelector('.name'+i).value !=''){
t=t+1;
}
i=i+1;
}
var h = 0;
while(h<12){
if(document.querySelector('.name'+h).value!=''){
document.querySelector('.n'+h+' .times').value=Math.floor(28/t)
}
h=h+1;
}
var d = 11
var j = 28-t*Math.floor(28/t);
var g = 0;
while(g<j){
if(document.querySelector('.name'+d).value != ''){
document.querySelector('.n'+d+' .times').value=Math.floor(document.querySelector('.n'+d+' .times').value)+1;
g=g+1;
}
d=d-1;
}
//이미 수동으로 근무표에 적혀진 이름이 있으면 각 이름의 times에서 그 출현 횟수 만큼 뺀다.
var c=0;
while(c<7){
var r=0;
while(r<4){
if(document.querySelector('.table'+c+' .row'+r).value!=""){
var u = 0;
while(u<12){
if(document.querySelector('.name'+u).value==document.querySelector('.table'+c+' .row'+r).value){
document.querySelector('.n'+u+' .times').value=Math.floor(document.querySelector('.n'+u+' .times').value)-1;
}
u = u+1;
}
}
r=r+1;
}
c=c+1;
}
}
function deletenames(){
var i = 0;
while(i<12){
document.querySelector('.name'+i).value=''
i=i+1;
}
}
function deletetimes(){
var b = 0;
while(b<12){
document.querySelector('.n'+b+' .times').value =''
b=b+1;
}
}
function deleteroster2(){
var k = 0;
while(k<7){
var i = 0;
while(i<4){
if(document.querySelector('.table'+k+' .row'+i).value != ''){
document.querySelector('.table'+k+' .row'+i).value =''
}else{
}
i=i+1;
}
k=k+1;
}
var i = 0;
while(i<28){
if(starter[i]==''){
}else{
document.querySelector('.table'+sc[i]+' .row'+sr[i]).value=starter[i];
}
i=i+1;
}
}
function deleteroster1(){
var k = 0;
while(k<7){
var i = 0;
while(i<4){
if(document.querySelector('.table'+k+' .row'+i).value != ''){
document.querySelector('.table'+k+' .row'+i).value =''
}else{
}
i=i+1;
}
k=k+1;
}
}
function finalcheck(){
var final =[]
var p = 0;
var j = 0;
while(p<12){
var i =0;
while(i < 7){
var h = 0;
while(h<4){
final.push(document.querySelector('.table'+i+' .row'+h).value);
h = h+1;
}
i=i+1;
}
while(final.indexOf(document.querySelector('.name'+p).value)==-1){
final.splice(final.indexOf(document.querySelector('.name'+p).value),1);
j=j+1
}
if(document.querySelector('.name'+p).value!=''){
if(document.querySelector('.n'+p+' .times').value!=j){
alert('작성하신 근무 수와 랜덤으로 배정')
}
}
}
}
//////////////////////////////////////////////////////////////////
function get(){
var cant = 0;
var terminate = 0;
//make roster버튼을 누르기전에 이미 테이블에 배치된 이름을 고정시키기 위해 starter를 만든다.
var starter = []
var i =0;
while(i < 7){
var h = 0;
while(h<4){
starter.push(document.querySelector('.table'+i+' .row'+h).value)
h = h+1;
}
i=i+1;
}
while(terminate<1){
if(cant==2000){
terminate = 1;
alert('해당 인원으로는 조건을 만족하는 근무표 생성이 불가능 합니다.')
}
//근무 횟수만큼 이름을 배열에 넣는다
var timelist = []
var i=0;
while(i<12){
if(document.querySelector('.n'+i+' .times').value==''){
}else{
var h = 0;
while(h<document.querySelector('.n'+i+' .times').value){
timelist.push(document.querySelector('.name'+i).value)
h=h+1;
}
}
i=i+1;
}
//c는 열의 변수
var c = 0;
while(c<7){
//r는 행의 변수
var r = 0;
while(r<4){
//명단에서 이름 가져와서 namelist 완성
var namelist = [];
var i = 0
while(i<12){
namelist.push(document.querySelector('.name'+i).value);
i=i+1;
}
while(namelist.indexOf("") != -1){
namelist.splice(namelist.indexOf(""),1);
}
//그전에 체크 박스에 체크되어 있으면 옵션으로 2~3번까지 중복 허용
if(document.querySelector('#double').checked){
var i = 0;
var k = 0;
while(i<7){
if(namelist.indexOf(document.querySelector('.table'+i+' .row'+r).value) !=-1){
k=k+1;
if(k>=Math.floor(document.querySelector('select').value)){
namelist.splice(namelist.indexOf(document.querySelector('.table'+i+' .row'+r).value),1);
}
i=i+1;
}else{
i=i+1;
}
}
}else{
//namelist에서 같은 행의 이름 제거
var i = 0;
while(i<7){
if(namelist.indexOf(document.querySelector('.table'+i+' .row'+r).value) !=-1){
namelist.splice(namelist.indexOf(document.querySelector('.table'+i+' .row'+r).value),1);
i=i+1;
}else{
i=i+1;
}
}
}
//namelist에서 같은 열의 이름 제거
var i = 0;
while(i<4){
if(namelist.indexOf(document.querySelector('.table'+c+' .row'+i).value)!=-1){
namelist.splice(namelist.indexOf(document.querySelector('.table'+c+' .row'+i).value),1);
i=i+1;
}else{
i=i+1;
}
}
//namelist에서 야간2직 다음 주간1,2직제외
if(c!=0){
var h=c-1;
if(r==0 || r==1){
if(namelist.indexOf(document.querySelector('.table'+h+' .row3').value)!=-1){
namelist.splice(namelist.indexOf(document.querySelector('.table'+h+' .row3').value),1);
}
}
}
//namelist에서 근무 열외 요일 체크된 이름 제외
var i =0;
while(i<12){
if(document.querySelector('.n'+i+' #date'+c).checked){
if(namelist.indexOf(document.querySelector('.n'+i+' .name'+i).value)!=-1){
namelist.splice(namelist.indexOf(document.querySelector('.n'+i+' .name'+i).value),1);
}
}
i=i+1;
}
//namelist에서 timelist에 이름이 없는 사람들 제거
if(namelist!=[]){
var i = 0;
var k = 0;
var h = namelist.length;
while(k<h){
if(timelist.indexOf(namelist[i])!=-1){
i=i+1;
k=k+1;
}else{
namelist.splice(namelist.indexOf(namelist[i]),1);
k=k+1;
}
}
}
//table에 이미 이름이 작성되있는칸을 제외하고
//위에서 만들어진 namelist에서 랜덤으로 이름을 해당table에 넣는다.
if(document.querySelector('.table'+c+' .row'+r).value!=""){
}else{
var ran = namelist[Math.floor(Math.random()*namelist.length)]
document.querySelector('.table'+c+' .row'+r).value=ran;
//timelist에서 선택된 이름을 한번 뺀다
timelist.splice(timelist.indexOf(ran),1);
}
//namelist에 계속 원소가 쌓이는 오류를 방지하기 위해 namelist 초기화
namelist.splice(0,namelist.length);
r = r+1;
}
c = c+1;
}
//만들어진 근무표의 모든 value를 가져와서 terminater 배열을 만든다.
var terminater = []
var i =0;
while(i < 7){
var h = 0;
while(h<4){
terminater.push(document.querySelector('.table'+i+' .row'+h).value)
h = h+1;
}
i=i+1;
}
//terminater 배열중 undefined가 있을 경우 starter를 제외하고 다지우고 다시한다.
if(terminater.indexOf('undefined') !=-1){
var k = 0;
while(k<7){
var i = 0;
while(i<4){
if(document.querySelector('.table'+k+' .row'+i).value != ""){
if(document.querySelector('.table'+k+' .row'+i).value != starter[i+(k*4)]){
document.querySelector('.table'+k+' .row'+i).value =''
}
}
i=i+1;
}
k=k+1;
}
cant = cant + 1;
}else{
terminate = terminate + 1;
}
}
}