-
Notifications
You must be signed in to change notification settings - Fork 0
/
EZtest_assistant_data.js
4924 lines (4467 loc) · 153 KB
/
EZtest_assistant_data.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
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*--------------------------------------------------------------------------------------------------
Dreamweaver LINT global references and definitions not used here
--------------------------------------------------------------------------------------------------*/
/*global
getTestResultsFile,
updateTestStyles,
setOpenLink,
EZfileToUrl,
setTestOkStatus,
displayResults, formatNote, setOverride, getExpected, showCounts,
quit,
updateEval,
addInfo, addAlert,
EZ, g, dw, DWfile
*/
var e; //global var for try/catch
(function() {[ //global variables and functions defined but not used
debugSave, debugLogToggle, debugAction, saveDebugCopy,
restoreData,
nosaveLoad, nosaveUpdate,
loadOptions, saveOptions, updateOptions,
loadCache, removeCache, saveCache,
loadLastRun, saveLastRun,
loadTasks,
loadTestOptions, saveTestOptions, testOptionsReset, saveTestOptions, suggTestOptions,
getTestResults,
loadTestScript,
loadTestResults, deleteTestResults, sortTestResults,
saveData,
debugLogToggle,
quit,
e, g, dw, DWfile ]});
//__________________________________________________________________________________________________
/*----------------------------------------------------------------------------------
----------------------------------------------------------------------------------*/
function restoreData(key)
{
var files = EZ.test.app.files[key];
if (!files)
return EZ.oops('EZ.test.app.files[' + key + '] properties not defined');
var url = files.file.url;
var backup = url.replace(/(.*\/)(.*)(\..*)/, '$1$2.backup$3');
if (!DWfile.exists(backup))
return EZ.oops('file not found: ' + backup);
if (DWfile.copy(backup, url))
{
delete EZ.test.app.updated[key];
quit('reload');
}
else
EZ.oops('restore failed: ' + backup);
}
/*--------------------------------------------------------------------------------------------------
log specified or all changed data -- then save data if not suspended
also used delay processing until idle (no user events for a bit)
TODO: add support for test results
--------------------------------------------------------------------------------------------------*/
function saveData(action, options)
{
var me = arguments.callee;
var _ = me._ = me._ ||
{
callerName: '',
state: '',
stateQueue: [],
functionQueue: [],
functionList: {
options: saveOptions,
testOptions: saveTestOptions,
//mru: EZ.test.mruTests.save,
lastrun: saveLastRun,
cache: saveCache
},
saveOptions: '',
saveKeys: [],
saveList: '', //set when not updating all data
waitList: {},
history: [],
tooltip: [],
tags: {
details: {
tagName: "details",
nodes: [
{
tagName: "summary",
class: 'sub-header'
},
{
tagName: "div",
class: "pre"
}
]
}
}
}
EZ.clearTimeout(me);
if (action) //good as is if no action or updated below
_.saveNow = EZ.get('saveOptionsOnChange'); //optimize save queue processing
switch (action)
{
case 'resume': //resume _saveProcessing() for current queue
{ //...or future save request
if (options)
_saveWaitUpdate('remove');
if (_.saveNow == 'idle')
{
options = 'ready';
_.saveList = '';
break;
//return;
}
if (_.stateQueue.length) //note resume save in progress
EZ.log('='.dup(50), '>>>>>');
break;
}
case 'suspend': //suspend starting or finishing _saveProcessing()
{ //wait for no user actions
_saveWaitUpdate('add');
if (_.saveNow == 'now')
return;
if (_.stateQueue.length) //note suspend of save in progress
EZ.log('='.dup(50), '<<<<<');
return;
}
case 'options': //schedule or call saveOptions()
{
if (quit.reload) //ignore if page reloading
return;
if (_.stateQueue.length === 0) //if no save in process, start options only save
_.saveList = ['options'];
else
{ //otherwise re-start all / ready save
_.saveList = '';
_.stateQueue = [];
}
break;
}
case 'testOptions': //schedule or call saveTestOptions()
{
if (quit.reload) //ignore if page reloading
return;
if (_.stateQueue.length === 0) //if no save in process, start options only save
{
_.saveList = ['testOptions'];
}
else
{ //otherwise re-start all / ready save
_.saveList = '';
_.stateQueue = [];
}
break;
}
case 'reload': //set or reset state queues for page reload
{ //called by quit or page reload
_.state = EZ.test.app.state;
_.stateQueue = ['', 'safety', 'reload'];
EZ.log('='.dup(100));
break;
}
case 'ready': //same as default -- save any changes not suspended
{ //...
_.saveList = '';
_.stateQueue = [];
break;
}
case 'spare':
{
break;
}
default:
{
void(0);
}
}
if (_.stateQueue.length === 0) //reset if stateQueue if empty
{
_.callerName = EZ.getStackTrace(me, ' caller NA');
if (!action)
_.saveList = '';
_.saveKeys = _.saveList || Object.keys(_.functionList);
_.saveOptions = options || '';
_.state = EZ.test.app.state;
_.stateQueue = ['', EZ.test.app.state];
_.saveNow = EZ.get('saveOptionsOnChange');
if (_.waitList.length > 0 && _.saveNow == 'idle')
return EZ.setTimeout(saveData, 5000); //wait 5 sec if save now
}
if (_.stateQueue[0] === '') //if just starting queued save
{
_.stateQueue.shift();
EZ.log('='.dup(100), '[beg save]');
var logItem = EZ.test.app.state.wrap().pad(9)
+ 'dataList: ' + _.saveKeys.join(', ');
EZ.log( [logItem].concat(_.callerName).join('\n\t'+' '.dup(7)) );
_.logSize = EZ.log.history.length;
}
//----------------------------------------------------------------------------------------
var count = _saveDataProcessQueue(action); //process 1st or all (reload) queued items
//----------------------------------------------------------------------------------------
if (!count)
{
EZ.test.app.state = _.state || 'ready';
return EZ.setTimeout(me,500); //pause for possible user action
}
action = action || 'na';
if (EZ.debug.isSaveSuspended())
EZ.log('SAVE SUSPENDED', 'action:' + action.wrap('"'), 'saveOptions:' + _.saveOptions.wrap('"'));
//if (_.logSize != 'EZ.log.history'.ov([]).length)
EZ.log('='.dup(100), '[end save]'); //queues processed
//else if (EZ.log.history && _.logSize > 0)
// EZ.log.history.length = _.logSize - 1;
//________________________________________________________________________________________
/**
* calls specified save...() function for specified states
* updates id="updatedData" with summary and details from save functions
*/
function _saveDataProcessQueue()
{
while (true)
{
var state = _.stateQueue[0];
if (!state) //done if state queue empty
break;
EZ.test.app.state = state;
if (_.functionQueue.length === 0) //reset fn queue for next state
_.functionQueue = _.saveKeys;
while (_.functionQueue.length)
{
var key = _.functionQueue.shift();
var fn = _.functionList[key]; //EZ.test.app.updated[key] set by safety pass
//...for "reload" state -- DON'T THINK SO
if (state != 'reload' || EZ.test.app.updated[key])
{
var msg = fn(_.saveOptions)
if (msg)
_.tooltip.push(EZ.format.time('ms') + ' ' + msg);
if (!quit.reload && _.saveNow == 'idle')
return false; //take breather for user action
}
}
_.stateQueue.shift();
}
EZ.test.app.state = _.state || 'ready';
if (!quit.reload) //display summary of changes if not reload
{ //hidden if not debug mode but can inspect
var updated = [];
var saved = [];
//var json = JSON.stringify(EZ.test.app.updated);
for (var key in EZ.test.app.updated)
{
if (EZ.test.app.updated[key] == 'saved')
{
delete EZ.test.app.updated[key];
saved.push(key);
}
else updated.push(key);
}
var msg = [];
if (updated.length)
msg.push('updated: ' + updated.join(', '))
if (saved.length)
msg.push('saved: ' + saved.join(', '))
//|| json != JSON.stringify(EZ.test.app.updated))
if (!msg.length && _.noUpdateCount === undefined)
msg.push('no data updated or saved');
if (!msg.length) //no change if no update msg
{ //...bump count and highlight for a bit
EZ.set('updatedDataCount', ' x ' + (++_.noUpdateCount+1));
EZ.addClass(EZ.el, 'noUpdates=30000');
}
else //no changes
{
_.noUpdateCount = 0;
EZ.set('updatedDataCount', '');
msg = EZ.format.time() + ': ' + msg.join(' ');
EZ.log.call('saveData', EZ.test.app.state.wrap().pad(9), msg);
EZ.set('updatedData', msg);
if (_.tooltip.length > 0)
{
var details = EZ.createTag('details', _.tags.details, null);
EZ.set( EZ('summary', details), msg);
EZ.set( EZ('pre', details), _.tooltip.join('\n'));
var history = EZ('updatedDataHistory');
if (history.children.length === 0)
history.appendChild(details);
else
{
history.insertBefore(details, history.children[0]);
if (history.children.length > 10)
history.removeChild(history.lastChild);
}
}
}
}
return true;
}
//________________________________________________________________________________________
/**
* update wait list
*/
function _saveWaitUpdate(action)
{
switch (action)
{
case 'add':
{
_.waitList[options] = EZ.format.time('ms')
break;
}
case 'remove':
{
delete _.waitList[options];
break;
}
default: return EZ.oops('unknown action: ' + action)
}
var list = [];
for (var key in _.waitList)
list.push('wait[' + key + '] @ ' + _.waitList[key]);
EZ.set('updatedDataWaitList', list.join('\n'));
}
}
/*----------------------------------------------------------------------------------
call when data loaded or saved -- updated title with timestamp if specified
All 4 parameters required when first called (usually when loaded)
----------------------------------------------------------------------------------*/
function setTitle(key, timestamp, tooltip, noSaveId)
{
var msg = '';
var prefix = '';
var files = EZ.test.app.files[key];
if (!files)
return key + ' file not loaded';
var props = files._props;
if (!props && tooltip)
{ //called from load fn
var code = '';
var id = key || ''; //'id NA';
var el = EZ(tooltip, null);
if (el)
{
id = el.getAttribute('data-name') || el.alt || el.id;
code = el.EZ('code', null);
//code = EZ('code', EZ.getAncestor(el,'tooltip'));
//if (!code || code.undefined)
// code = '';
}
props = EZ.test.app.files[key]._props = {
id: id,
el: el,
code: code,
noSaveId: noSaveId || '',
noSaveEl: EZ(noSaveId, null),
}
var stack = EZ.stack(setTitle)
var callerName = (stack.lines[2].formatStack()+'' || ''); //.trim();
msg = 'loaded ' + key.pad(12)
+ ' [saved @ ' + EZ.format.dateTime(timestamp, 'today-time') + '] '
+ (callerName || '');
//EZ.log.call('saveData', msg)
}
if (!msg)
{
var why = props.why || props.noSaveWhy || '';
prefix = key.pad(19); //props.id.pad(25)
if (tooltip == 'safety')
{
msg += ' safety saved ';
}
else if (props.isSaved) //set by canSave() when canSave is true
{ //saved occures when canSave() returns
msg += ' file updated '; //setTitle called after save
if (props.safetyTimestamp)
//&& EZ.getTime(props.safetyTimestamp) < EZ.getTime(timestamp))
{
msg += ' (safety deleted) ';
props.safetyTimestamp = false;
//====================================================================
EZ.store.remove('safety.' + key);
//====================================================================
}
//files.saved = EZ.clone(props.value);
files.saved = EZ.test.cloneHow(props.value, key);
props.isPending = '';
props.isChanged = false;
EZ.test.app.updated[key] = 'saved';
if (false)
delete EZ.test.app.files[key].loaded
}
else if (props.isPending) //isDataChanged() sets if called with why arg
msg += ' pending save ' + why; //not cleared until saved
else if (props.isChanged) //isDataChanged() sets if changed from saved
msg += ' NOT saved ' + why; //clears if data restored to saved values
else if (EZ.test.app.state == 'safety')
msg += ' up-to-date:';
}
if (!quit.reload) //update html if not reloading
{
var el = props.el;
/*
if (timestamp)
EZ.show(el); //show button if hidden (e.g. mruReset)
else
void(0); //debug aid
*/
//? EZ.addClass(el, 'pending', props.isPending || msg);
if (props.isSaved)
EZ.addClass(el, 'saved=15000');
var text = '';
if (props.isPending)
{
text = el.getAttribute('data-title-suffix') || '';
text = text.replace(/(.*?) changes pending/, '') + ' changes pending';
}
else if (timestamp == -1)
text = '';
else if (timestamp !== undefined)
text = 'saved @ ' + EZ.formatDate(timestamp, 'today-time')
text = msg + '' + text;
text = (text || '').trim()
if (text)
el.setAttribute('data-title-suffix', ' ' + text);
if (msg)
{
el.setAttribute('data-title-prefix', '');
el.setAttribute('data-title', '');
}
}
msg = msg.trim();
if (msg)
{
msg = prefix + msg;
var state = EZ.test.app.state.wrap().pad(9);
var time = EZ.format.time('ms');
EZ.log.call('saveData', state, time, msg + ' ' + (props.callerName || ''));
msg = time.replace(/\s+/g, '') + ' ' + msg;
}
return msg;
}
/*----------------------------------------------------------------------------------
----------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------
Safety copies are made whenever save...() is called unless save is suspended.
Whenever changes are made, the changes show in the javascript console, trace log and
on page tooltip if enabled.
when reloading or leaving html page, quit() first sets EZ.test.app.state="safety"
to save any changes to localStorage (as safety) in case browser crashes then sets
EZ.test.app.state="reload" to save any changes to the associated file(s).
If all files are updated sucessfully, the localStorage safety copies are deleted.
----------------------------------------------------------------------------------*/
function isDataChanged(key, value, isPending)
{
var files = EZ.test.app.files[key];
if (!files)
return EZ.oops(key + ' properties not defined');
var props = files._props;
if (!props.callerName)
{
var stack = EZ.stack(isDataChanged)
props.callerName = (stack.lines[2].formatStack()+'' || '').trim();
}
if (isPending instanceof Object && isPending.backup)
return true;
props.value = value;
props.isPending = isPending || '';
props.why = props.isPending;
//props.safetyUpdated = false;
var state = EZ.test.app.state;
if (state == 'reload') //file saved on return if updated and can save
{
return props.isSaved;
// return (EZ.test.app.updated[key] + '').includes('updated');
}
var el, code, codeHtml, isChanged;
var saved = files.saved || files.loaded;
if (quit.reload && state == 'safety') //no dom changes
{
isChanged = (value == 'reset') ? true
: !EZ.isEqual(saved, value); //basic equals test
isPending = '';
}
else
{
el = props.el;
code = props.code;
var isTooltip = (code && EZ.log.isActive('saveData', 'page'));
if (!isTooltip)
EZ.addClass(code, 'hidden');
isChanged = (saved) ? _isChanged()
: _isCreated()
}
props.isChanged = isChanged;
if (isChanged)
{
//EZ.test.app.updated[key] = isPending ? 'pending' : 'updated';
if (code && codeHtml) //update tooltip
{
EZ.removeClass(code, 'hidden');
code.innerHTML = codeHtml.innerHTML;
}
//setTitle(key);
}
else
{
props.isPending = '';
}
//======================
return isChanged;
//======================
//________________________________________________________________________________________
/**
*
*/
function _isCreated()
{
var text = ' created: ' + props.id
EZ.log.call('saveData',text);
if (isTooltip)
{
var tags = {
nodes: {
em: {
nodes: {
text: text
}
}
}
}
codeHtml = EZ.createTag('code', tags);
}
return true;
}
//________________________________________________________________________________________
/**
*
*/
function _isChanged()
{
var opts = {
showDiff:5,
//console: true,
//log: true,
name: [key, 'CHANGES ...'],
ignore: 'objectType'
};
var isEqual = EZ.isEqual(saved, value, opts);
if (!isEqual)
{
var formattedLog = window.EZ.isEqual.formattedLog;
if (formattedLog && code)
{
var was = 'window.EZ.test.app.files.' + key + '.lastSaved';
var now = 'window.EZ.test.app.files.' + key + '.nextSaved';
//var name = EZ(el).getAttribute('alt') || EZ.el.id;
var log = ' [was] ... [now]:\n\t'
+ formattedLog.join('\n\t');
EZ.log.call('saveData',log);
if (isTooltip)
{ //create (.lastSave / .nextSaved) clones for compare
files.nextSaved = EZ.clone(value);
files.lastSaved = EZ.clone(files.saved);
var tags = {
nodes: {
em: {
nodes: {
text: name + ' [was] ... [now]'
}
},
div: {
class: 'pre',
nodes: {
input: {
type: "image",
title: 'full compare via winmerge',
src: "../images/compare.png",
onclick: 'window.EZ.compare(' + was + ',' + now + ')'
},
text: '\t' + formattedLog.join('\n\t')
}
}
}
}
codeHtml = EZ.createTag('code', tags, null);
[].sortPlus.call(was.ov());
[].sortPlus.call(now.ov());
}
}
}
return !isEqual;
}
}
/*----------------------------------------------------------------------------------
Only called if data changed
----------------------------------------------------------------------------------*/
function canSave(key, timestamp, options)
{
var files = EZ.test.app.files[key];
if (!files)
return EZ.oops('EZ.test.app.files[' + key + '] properties not defined');
var props = files._props;
if (options instanceof Object)
{
var url = files.file.url;
if (options.backup)
url = url.replace(/(.*\/)(.*)(\..*)/, '$1$2.backup$3');
options.url = url;
}
else options = {};
var isSaved = false;
var why = '';
//while (EZ.test.app.state != 'debug')
do
{
if (options.backup)
{
isSaved = true;
break;
}
if (EZ.debug.isSaveSuspended())
{
why = 'all saves suspended';
break;
}
var noSaveId = props.noSaveId;
if (typeof(noSaveId) != 'boolean')
{
var fieldValues = EZ.get(EZ('nosave', true)).valueMap;
if (noSaveId in fieldValues)
{
//if (fieldValues.debugNoSaveData)
{
if (fieldValues[noSaveId])
{
why = 'No Save checked '; // + noSaveId + ' not';
break;
}
}
}
else if (key == 'lastrun')
void(0);
else if (!props.noSaveEl || !props.noSaveEl.checked)
{
why = noSaveId + ' not checked';
break;
}
}
/*
else if (!noSaveId)
{
why = 'save not allowed for' + noSaveId;
break;
}
*/
isSaved = true;
props.timestamp = timestamp || props.timestamp;
EZ.test.app.updated[key] = 'saved';
_updateSafety(); //save safety copy
setTitle(key, props.timestamp, 'safety');
//props.safetyUpdated = true;
break;
}
while (false)
props.isSaved = isSaved;
props.noSaveWhy = why;
return isSaved;
function _updateSafety()
{
var times = EZ.test.app.updatedTimes
times.timestamp = EZ.format.dateTime();
times[key] = times[key] || {};
times[key].timestamp = timestamp || times.timestamp;
EZ.test.app.updated[key] = 'updated-safety'
//====================================================================
EZ.store.set('updatedTimes', EZ.test.app.updatedTimes);
EZ.store.set('safety.' + key, props.value);
//====================================================================
}
}
/*----------------------------------------------------------------------------------
----------------------------------------------------------------------------------*/
function loadTasks()
{
var filename = 'EZtestAssistant.TASKS.js'
var file = EZ.filePlus(EZ.test.config.testdataFolder, filename);
//================================================================================
var text = DWfile.read(file.url);
//================================================================================
EZ('testTasksText').innerHTML = text;
}
//_________________________________________________________________________________________________
e = function _____OPTIONS_____() {} //convenience for DW functions list
//_________________________________________________________________________________________________
/*----------------------------------------------------------------------------------
Load all options and update field values
----------------------------------------------------------------------------------*/
function loadOptions(classNames)
{
EZ.test.app.files.options = {
status: false,
file: '',
defaultValueMap: EZ.get(['opt']).valueMap,
logs:{}
};
var options = {};
try
{
var file = EZ.filePlus(EZ.constant.configPath + EZ.test.config.testdataFolder + 'options.js');
EZ.test.app.files.options.file = file;
//================================================================================
var json = DWfile.read(file.url);
//================================================================================
if (json == 'reset')
EZ.test.app.files.options.status = 'options reset';
else if (json && json.includes('options='))
{
EZ.test.app.files.options.status = true;
eval('EZ.test.app.files.options.loaded = ' + json);
options = eval(json);
}
}
catch (e)
{
EZ.log.call('saveData', 'saved options corrupt');
}
options = options || {};
var isEmpty = EZ.isEmpty(options);
var timestamp = EZ.test.app.files.options.file.timestamp || 0;
setTitle('options', timestamp, 'optionsData', 'debugNoSaveOptions');
classNames = EZ.toArray(classNames); //use array to get all matching tags
/*03-09-2017: 1st thought default values lost for some checkboxes
EZ.test.app.files.options.defaultValues = EZ.get(classNames).valueMap;
var log = EZ.sync(options, EZ.test.app.files.options.defaultValues, '^@options', 1);
*/
//----------------------
EZ.field.add(options);
//----------------------
var log = EZ.field.getLog();
log.added = log.added || [];
var logItem = EZ.log(log.added.length + ' saved options', {added:log.added, notFound:log.notFound});
EZ.test.app.files.options.logs.loaded = logItem;
//if (!log.added.length)
if (isEmpty)
{
EZ.addClass('allDefaultOptions', 'dim');
EZ.el.value = 'default options';
EZ.removeClass('appOptions', 'less');
EZ.set('showTestOptions',false);
EZ.log('----------------------- no saved options ----------------------------')
}
else
{
EZ.test.app.files.options.all = EZ.get(['opt']).valueMap;
//setTitle('optionsData', EZ.test.app.files.options.file.timestamp || 0);
if (EZ.debug())
{
var value = EZ('allDefaultOptions').value;
EZ.el.value = value.replace(/(all|\(\d*\))/i, '(' + log.added.length + ')');
}
}
// /*03-09-2017: not necessary with above EZ.sync code but not deployed
//------------------------------------------------------------------------------------
EZ.field.add(classNames);
//------------------------------------------------------------------------------------
log = EZ.field.getLog();
logItem = EZ.log(log.counts.tags + ' total options', {added:log.added, existing:log.existing});
EZ.test.app.files.options.logs.all = logItem;
log.dupNames = log.dupNames || [];
if (log.dupNames.length)
EZ.oops('dupNames: ' + log.dupNames.join('\n\t'))
//*/
EZ.test.app.files.options.logs.summary = {fields:log.fields, lists:log.lists, events:log.events};
var counts = EZ.stringify(log.counts).substr(2).clip(2).trim().replace(/\n\s*/g, ' ');
EZ.test.app.files.options.logs.counts = counts;
EZ.log({'EZ.test.app.files.options.summary': EZ.test.app.files.options.summary}, counts);
EZ.timer('setup fields', true); //above EZ.field.add() calls approx: 1 SECOND
EZ.test.app.state = 'loaded';
//----------------------------------------\\
//----- apply options not auto applied -----\\
//--------------------------------------------\\
g.scriptOptions = { //initially debugger aid ??
stringify: '.js_stringify',
tostring: '.js_tostring',
maxlines: '.scriptOption=maxlines',
history_maxitems: '.scriptOption=history_maxitems',
saveall: '.scriptOption=saveall',
append: '.scriptOption=append',
format: '.scriptOption=format',
enterkey: '.scriptOption=enterkey'
}
//TODO: probably not needed or out-of-date
//EZ.runScript(); //init javascript eval
/*
var cache = localStorage.getItem(g.projectName + '.cache');
EZ.removeClass(EZ('useCache').parentElement, 'dim', cache);
EZ.test.app.cache = JSON.parse(cache || '{}');
*/
/*----------------------------------------------------------------------------------
<input type="checkbox" name="validationLimited" id="validationLimited"
class="dim opt testOpt onLoadEvent"
onload="window.EZ.addClass('okSettings', this.value)">
----------------------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------------
Save values of all fields with opts class
----------------------------------------------------------------------------------*/
function saveOptions(options)
{
EZ.clearTimeout(saveOptions); //clear any pending save
options = EZ.options.call(options); //if String, keys w/o "=" set to true
var opts, rtnValue = '';
var timestamp = 0;
var file = EZ.test.app.files.options.file;
if (options.resetAll)
opts = 'reset'; //should reload after return
var exclude = options.resetTestOptions ? 'testOpt' : '';
opts = opts || EZ.field.getChangedValues('opt', exclude);
var saveKey = 'options';
if (opts == 'reset'
|| options.reload
|| isDataChanged(saveKey, opts, options))
{
var json, count = 0;
//timestamp = EZ.test.app.files.updatedTimes.options || EZ.format.dateTime();
timestamp = EZ.format.dateTime();
//=====================================================================================
if (canSave(saveKey, timestamp, options))
{
if (opts instanceof Object) //if not "reset"
{
count = Object.keys(opts).length;
[].sortPlus.call(opts);
//if ('EZ.test.app.files.updatedTimes.options'.ov())
//opts.timestamp = timestamp;
json = 'EZ.test.app.options= \t\t//Saved @ ' + timestamp + '\n' + EZ.stringify(opts);
}
else json = opts;
file.timestamp = timestamp;
DWfile.write(options.url, json);
//localStorage.setItem(g.projectName + '.options', json);
//localStorage.setItem(g.projectName + '.nosave', json);
localStorage.removeItem(g.projectName + '.nosave');
}
//=====================================================================================
else
{ //save .nosave options if options not saved
var fieldValues = EZ.get(['nosave']);
json = JSON.stringify(fieldValues.valueMap);
localStorage.setItem(g.projectName + '.nosave', json);
}
//=====================================================================================
if (opts) //reset ??
{
var value = EZ('allDefaultOptions').value;
value = (count === 0) ? 'default options'
: (EZ.debug()) ? 'reset (' + count + ') options'
: 'reset all options';
EZ.el.value = value; //update button displayed text
}
}
rtnValue = setTitle(saveKey, timestamp);
return rtnValue;
}
/*----------------------------------------------------------------------------------
Called by options table container onClick or onChange()
Update g.displayOptions from children of .displayObjectOptions containers
save all fields with .opt class
----------------------------------------------------------------------------------*/
function updateOptions(wrapEl)
{
if (!wrapEl || EZ.hasClass(wrapEl, 'displayOptions'))
{
var tags = EZ(['opt'], '.displayOptions'); //save all displayOptions
g.displayOptions = {timestamp: false};
tags.forEach(function(tag)
{ //update display options
var key = tag.id.replace(/(toString|stringify)_/, '');
g.displayOptions[key] = EZ.get(tag);
});
}
// setTimeout(saveOptions,0);
}
/*--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------*/
function createLastRun()
{
var lastrun = {
lastOks: {},
testrun: {},
timestamp: '', //EZ.formatDate(),
version: '01-06-2017'
}
return lastrun;
}
/*--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------*/
function loadLastRun()
{
EZ.removeClass(['saveLastRunBtn','lastrunLink'], 'hidden', EZ.debug());
var file = getTestResultsFile('lastrun');
EZ.test.app.lastrun = {}
EZ.test.app.files.lastrun = {
saved: {},
file: file
};
var lastrun = createLastRun();