回答編集履歴
2
deletefileList ---> resultdeletefileList
test
CHANGED
@@ -492,7 +492,7 @@
|
|
492
492
|
|
493
493
|
type: "DELETE",
|
494
494
|
|
495
|
-
url: '/attachments/' + deletefileList[i].fileid + '.json',
|
495
|
+
url: '/attachments/' + resultdeletefileList[i].fileid + '.json',
|
496
496
|
|
497
497
|
headers: {
|
498
498
|
|
@@ -506,7 +506,7 @@
|
|
506
506
|
|
507
507
|
}).done(function(){
|
508
508
|
|
509
|
-
console.log("チケット[" + deletefileList[i].issue_id + "]の添付ファイル[" + deletefileList[i].diskfilename + "]を削除しました");
|
509
|
+
console.log("チケット[" + resultdeletefileList[i].issue_id + "]の添付ファイル[" + resultdeletefileList[i].diskfilename + "]を削除しました");
|
510
510
|
|
511
511
|
}).fail(function(){
|
512
512
|
|
1
スクリプトを修正
test
CHANGED
@@ -52,11 +52,17 @@
|
|
52
52
|
|
53
53
|
var apikey = ViewCustomize.context.user.apiKey;
|
54
54
|
|
55
|
-
var closedissueList = [];
|
55
|
+
var closedissueList = []; //添付ファイル削除対象のチケット
|
56
|
-
|
57
|
-
|
56
|
+
|
58
|
-
|
59
|
-
var deletefileList = [];
|
57
|
+
var deletefileList = []; //削除対象の添付ファイル
|
58
|
+
|
59
|
+
var openandundersixissueList = []; //添付ファイル削除対象外のチケット
|
60
|
+
|
61
|
+
var notdeletefileList = []; //削除対象外の添付ファイル
|
62
|
+
|
63
|
+
var resultdeletefileList = []; //実際に削除する添付ファイル
|
64
|
+
|
65
|
+
|
60
66
|
|
61
67
|
$(function(){
|
62
68
|
|
@@ -72,27 +78,49 @@
|
|
72
78
|
|
73
79
|
$(target).append(searchbtn).append(deletebtn);
|
74
80
|
|
75
|
-
$('input#deletefile').attr("disabled", true).css("color", "#fff").css("background-color", "#d6d6d6");
|
81
|
+
$('input#deletefile').attr("disabled", true).css("color", "#fff").css("background-color", "#d6d6d6"); //削除ボタンを一時的に無効化
|
82
|
+
|
83
|
+
|
84
|
+
|
76
|
-
|
85
|
+
//検索ボタンを押下したら、サーバから添付ファイル情報を取得する
|
77
|
-
|
78
86
|
|
79
87
|
$('input#searchfile').click(function(){
|
80
88
|
|
89
|
+
//配列を初期化
|
90
|
+
|
81
91
|
closedissueList = [];
|
82
92
|
|
83
|
-
deletefileListtmp = [];
|
84
|
-
|
85
93
|
deletefileList = [];
|
86
94
|
|
95
|
+
openandundersixissueList = [];
|
96
|
+
|
97
|
+
notdeletefileList = [];
|
98
|
+
|
99
|
+
resultdeletefileList = [];
|
100
|
+
|
101
|
+
|
102
|
+
|
87
103
|
$('input#deletefile').attr("disabled", true).css("color", "#fff").css("background-color", "#d6d6d6");
|
88
104
|
|
89
105
|
$.when(
|
90
106
|
|
91
107
|
getclosedissueid(),
|
92
108
|
|
109
|
+
getclosedundersixmonthissueid(),
|
110
|
+
|
111
|
+
getopenissueid()
|
112
|
+
|
93
113
|
).done(function(){
|
94
114
|
|
95
|
-
getdeletefile();
|
115
|
+
getdeletefile();
|
116
|
+
|
117
|
+
getnotdeletefile();
|
118
|
+
|
119
|
+
setTimeout(function() {
|
120
|
+
|
121
|
+
$('input#deletefile').attr("disabled", false).css("color", "#555").css("background-color", "#f0f0f0"); //情報を取得したら削除ボタンを有効化
|
122
|
+
|
123
|
+
}, 300);
|
96
124
|
|
97
125
|
})
|
98
126
|
|
@@ -104,15 +132,23 @@
|
|
104
132
|
|
105
133
|
$('input#deletefile').click(function(){
|
106
134
|
|
135
|
+
$.when(
|
136
|
+
|
137
|
+
pushresultfile()
|
138
|
+
|
139
|
+
).done(function(){
|
140
|
+
|
107
|
-
if (deletefileList.length == 0){
|
141
|
+
if (resultdeletefileList.length == 0){
|
108
|
-
|
142
|
+
|
109
|
-
alert("削除対象のファイルはありません");
|
143
|
+
alert("削除対象のファイルはありません");
|
110
|
-
|
144
|
+
|
111
|
-
}else{
|
145
|
+
}else{
|
112
|
-
|
146
|
+
|
113
|
-
closeissueattfiledelete();
|
147
|
+
closeissueattfiledelete();
|
114
|
-
|
148
|
+
|
115
|
-
}
|
149
|
+
}
|
150
|
+
|
151
|
+
})
|
116
152
|
|
117
153
|
})
|
118
154
|
|
@@ -122,6 +158,26 @@
|
|
122
158
|
|
123
159
|
|
124
160
|
|
161
|
+
//6か月前の日付を取得
|
162
|
+
|
163
|
+
function getbeforesixmonth(dt){
|
164
|
+
|
165
|
+
dt.setMonth(dt.getMonth() - 6);
|
166
|
+
|
167
|
+
var year = dt.getFullYear();
|
168
|
+
|
169
|
+
var month = ('0' + (dt.getMonth()+1)).slice(-2);
|
170
|
+
|
171
|
+
var day = ('0' + dt.getDate()).slice(-2);
|
172
|
+
|
173
|
+
var beforesixmonth = year+"-"+month+"-"+day;
|
174
|
+
|
175
|
+
return beforesixmonth;
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
125
181
|
//対象プロジェクトのステータスが終了(完了)で、終了日が6か月以前のチケットを取得
|
126
182
|
|
127
183
|
function getclosedissueid(){
|
@@ -130,29 +186,15 @@
|
|
130
186
|
|
131
187
|
var projectid = $('input#project_identifier').attr('value'); //プロジェクト識別子
|
132
188
|
|
133
|
-
|
134
|
-
|
135
|
-
//6か月前の日付を取得
|
136
|
-
|
137
189
|
var dt = new Date();
|
138
190
|
|
139
|
-
|
191
|
+
|
140
|
-
|
141
|
-
var year = dt.getFullYear();
|
142
|
-
|
143
|
-
var month = ('0' + (dt.getMonth()+1)).slice(-2);
|
144
|
-
|
145
|
-
var day = ('0' + dt.getDate()).slice(-2);
|
146
|
-
|
147
|
-
var beforesixmonth = year+"-"+month+"-"+day;
|
148
|
-
|
149
|
-
|
150
192
|
|
151
193
|
$.ajax({
|
152
194
|
|
153
195
|
type: "GET",
|
154
196
|
|
155
|
-
url: '/issues.json?limit=1000&project_id=' + projectid + '&status_id=closed&closed_on=%3C%3D' + beforesixmonth,
|
197
|
+
url: '/issues.json?limit=1000&project_id=' + projectid + '&status_id=closed&closed_on=%3C%3D' + getbeforesixmonth(dt),
|
156
198
|
|
157
199
|
headers: {
|
158
200
|
|
@@ -192,6 +234,118 @@
|
|
192
234
|
|
193
235
|
|
194
236
|
|
237
|
+
//対象プロジェクトのステータスが終了(完了)で、終了日が6か月未満のチケットを取得
|
238
|
+
|
239
|
+
function getclosedundersixmonthissueid(){
|
240
|
+
|
241
|
+
var deferred = new $.Deferred();
|
242
|
+
|
243
|
+
var projectid = $('input#project_identifier').attr('value'); //プロジェクト識別子
|
244
|
+
|
245
|
+
var dt = new Date();
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
$.ajax({
|
250
|
+
|
251
|
+
type: "GET",
|
252
|
+
|
253
|
+
url: '/issues.json?limit=1000&project_id=' + projectid + '&status_id=closed&closed_on=%3E%3C' + getbeforesixmonth(dt),
|
254
|
+
|
255
|
+
headers: {
|
256
|
+
|
257
|
+
'X-Redmine-API-Key': apiKey
|
258
|
+
|
259
|
+
},
|
260
|
+
|
261
|
+
dataType: "text",
|
262
|
+
|
263
|
+
contentType: 'application/json',
|
264
|
+
|
265
|
+
}).done(function(data){
|
266
|
+
|
267
|
+
data=JSON.parse(data);
|
268
|
+
|
269
|
+
data= data["issues"];
|
270
|
+
|
271
|
+
for (i in data) {
|
272
|
+
|
273
|
+
issueid=data[i].id;
|
274
|
+
|
275
|
+
openandundersixissueList.push(issueid);
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
setTimeout(function() {
|
280
|
+
|
281
|
+
deferred.resolve();
|
282
|
+
|
283
|
+
}, 300);
|
284
|
+
|
285
|
+
})
|
286
|
+
|
287
|
+
return deferred;
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
//対象プロジェクトのステータスが未完了のチケットを取得
|
294
|
+
|
295
|
+
function getopenissueid(){
|
296
|
+
|
297
|
+
var deferred = new $.Deferred();
|
298
|
+
|
299
|
+
var projectid = $('input#project_identifier').attr('value'); //プロジェクト識別子
|
300
|
+
|
301
|
+
var dt = new Date();
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
$.ajax({
|
306
|
+
|
307
|
+
type: "GET",
|
308
|
+
|
309
|
+
url: '/issues.json?limit=1000&project_id=' + projectid,
|
310
|
+
|
311
|
+
headers: {
|
312
|
+
|
313
|
+
'X-Redmine-API-Key': apiKey
|
314
|
+
|
315
|
+
},
|
316
|
+
|
317
|
+
dataType: "text",
|
318
|
+
|
319
|
+
contentType: 'application/json',
|
320
|
+
|
321
|
+
}).done(function(data){
|
322
|
+
|
323
|
+
data=JSON.parse(data);
|
324
|
+
|
325
|
+
data= data["issues"];
|
326
|
+
|
327
|
+
for (i in data) {
|
328
|
+
|
329
|
+
issueid=data[i].id;
|
330
|
+
|
331
|
+
openandundersixissueList.push(issueid);
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
setTimeout(function() {
|
336
|
+
|
337
|
+
deferred.resolve();
|
338
|
+
|
339
|
+
}, 300);
|
340
|
+
|
341
|
+
})
|
342
|
+
|
343
|
+
return deferred;
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
195
349
|
//チケットのリストに基づいて、削除対象ファイルの情報を取得
|
196
350
|
|
197
351
|
function getdeletefile(){
|
@@ -228,19 +382,13 @@
|
|
228
382
|
|
229
383
|
diskfilename = data[i].disk_filename; //サーバ上の物理ファイル名
|
230
384
|
|
231
|
-
deletefileList
|
385
|
+
deletefileList.push({issue_id, fileid, diskfilename});
|
232
|
-
|
233
|
-
|
386
|
+
|
234
|
-
|
235
|
-
deletefileList = deletefileListtmp.filter((x,y,z)=>z.slice(0,z.length).filter(w=>w.diskfilename==x.diskfilename).length < 2);
|
236
|
-
|
237
|
-
console.log(deletefileList);
|
387
|
+
//console.log(deletefileList);
|
238
|
-
|
239
|
-
$('input#deletefile').attr("disabled", false).css("color", "#555").css("background-color", "#f0f0f0");
|
240
388
|
|
241
389
|
}
|
242
390
|
|
243
|
-
})
|
391
|
+
})
|
244
392
|
|
245
393
|
})
|
246
394
|
|
@@ -248,11 +396,97 @@
|
|
248
396
|
|
249
397
|
|
250
398
|
|
399
|
+
//チケットのリストに基づいて、削除対象外のファイル情報を取得
|
400
|
+
|
401
|
+
function getnotdeletefile(){
|
402
|
+
|
403
|
+
$.each(openandundersixissueList, function(i){
|
404
|
+
|
405
|
+
$.ajax({
|
406
|
+
|
407
|
+
type: "GET",
|
408
|
+
|
409
|
+
url: '/issues/' + openandundersixissueList[i] + '.json?include=attachments',
|
410
|
+
|
411
|
+
headers: {
|
412
|
+
|
413
|
+
'X-Redmine-API-Key': apiKey
|
414
|
+
|
415
|
+
},
|
416
|
+
|
417
|
+
dataType: "text",
|
418
|
+
|
419
|
+
contentType: 'application/json',
|
420
|
+
|
421
|
+
}).done(function(data){
|
422
|
+
|
423
|
+
data=JSON.parse(data);
|
424
|
+
|
425
|
+
data = data.issue.attachments;
|
426
|
+
|
427
|
+
for (i in data){
|
428
|
+
|
429
|
+
diskfilename = data[i].disk_filename; //サーバ上の物理ファイル名
|
430
|
+
|
431
|
+
notdeletefileList.push(diskfilename);
|
432
|
+
|
433
|
+
//console.log(notdeletefileList);
|
434
|
+
|
435
|
+
}
|
436
|
+
|
437
|
+
})
|
438
|
+
|
439
|
+
})
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
//削除対象と削除対象外を比較し、削除対象外に存在しなかったら削除対象を結果配列にpush
|
446
|
+
|
447
|
+
function pushresultfile(){
|
448
|
+
|
449
|
+
var deferred = new $.Deferred();
|
450
|
+
|
451
|
+
var a = deletefileList;
|
452
|
+
|
453
|
+
if (a.length == 0){
|
454
|
+
|
455
|
+
deferred.resolve(); //削除対象の添付ファイルがない場合は処理を終了
|
456
|
+
|
457
|
+
}
|
458
|
+
|
459
|
+
var b = notdeletefileList;
|
460
|
+
|
461
|
+
for (var i = 0; i < deletefileList.length; i++) {
|
462
|
+
|
463
|
+
if ($.inArray(a[i]["diskfilename"], b) < 0) {
|
464
|
+
|
465
|
+
resultdeletefileList.push(deletefileList[i]);
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
console.log(resultdeletefileList);
|
470
|
+
|
471
|
+
setTimeout(function() {
|
472
|
+
|
473
|
+
deferred.resolve();
|
474
|
+
|
475
|
+
}, 300);
|
476
|
+
|
477
|
+
}
|
478
|
+
|
479
|
+
return deferred;
|
480
|
+
|
481
|
+
}
|
482
|
+
|
483
|
+
|
484
|
+
|
251
485
|
//サーバから添付ファイルを削除する
|
252
486
|
|
253
487
|
function closeissueattfiledelete(){
|
254
488
|
|
255
|
-
$.each(deletefileList, function(i){
|
489
|
+
$.each(resultdeletefileList, function(i){
|
256
490
|
|
257
491
|
$.ajax({
|
258
492
|
|