forked from pauljz/FluentAutomationRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFARManager.js
More file actions
182 lines (146 loc) · 4.46 KB
/
FARManager.js
File metadata and controls
182 lines (146 loc) · 4.46 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
$(document).ready( function() {
ViewModel = {
labels: ko.observableArray([]),
recordings: ko.observableArray([]),
activeTab: ko.observable('All Recordings'),
recording: ko.observable({}),
localStorageUsage: ko.observable(FARDB.GetUsage()),
settings: {
uniqueAttributes: ko.observable()
}
};
ko.applyBindings(ViewModel);
ViewModel.LoadRecordingsOnTabChange = ko.dependentObservable( function() {
// whenever the tab is changed, re-load the recordings
FARManager.LoadRecordings();
if ( ViewModel.activeTab() == 'Settings' ) {
FARManager.UpdateSettings();
}
return ViewModel.activeTab();
}, ViewModel );
ViewModel.RefreshRecordingDetailsOnSelect = ko.dependentObservable( function() {
// Resizes the JSON textarea to fit its contents
// First null it out first so the scrollHeight is accurate
$('#recording-json').height( 0 );
// Now resize the textarea to the scrollHeight, -12px to account for the padding
$('#recording-json').height( $('#recording-json')[0].scrollHeight - 12 );
return ViewModel.recording();
}, ViewModel );
// Initialise the left hand labels and load the recordings
ViewModel.labels( FARDB.GetLabels() );
FARManager.LoadRecordings();
// Now attach non-KO events ...
$('#recording-name').click( function() {
$('#recording-name').hide();
$('#recording-name-edit').show();
$('#recording-name-edit').focus();
});
$('#recording-name-edit').change( function() {
// Get the edited name and edit the record in the DB
var name = $(this).val();
FARDB.Name( ViewModel.recording().Created, name );
// Update the recording in the ViewModel
var recording = ViewModel.recording();
recording.Name = name;
ViewModel.recording( recording );
// Refresh the recodings in the ViewModel - easier than updating ViewModel.recordings
FARManager.LoadRecordings();
}).blur( function() {
$('#recording-name').show();
$('#recording-name-edit').hide();
});
$('#recording-json').click( function() {
$(this).select();
});
$(window).focus( function() {
// if the user has left and come back, reload data.
ViewModel.labels( FARDB.GetLabels() );
FARManager.LoadRecordings();
});
$('#run-test').click( FARManager.RunTest );
});
FARManager = {
recordingsGetFn: FARDB.GetAll,
LoadRecordings: function() {
var recordings = FARManager.recordingsGetFn();
recordings.reverse(); // newest first - TODO make this a settnig
ViewModel.recordings( recordings );
},
ListAll: function() {
FARManager.recordingsGetFn = FARDB.GetAll;
ViewModel.activeTab('All Recordings');
},
ListStarred: function() {
FARManager.recordingsGetFn = FARDB.GetStarred;
ViewModel.activeTab('Starred');
},
ListNamed: function() {
FARManager.recordingsGetFn = function() {
var all = FARDB.GetAll();
var named = [];
for ( i in all ) {
if ( all[i].Name ) {
named.push( all[i] );
}
}
return named;
};
ViewModel.activeTab('Named');
},
ListLabel: function(el) {
var attr = $(el).attr( 'data-tabname' );
var label = $(el).attr( 'data-labelname' );
FARManager.recordingsGetFn = function() {
return FARDB.GetLabel( label );
};
ViewModel.activeTab( attr );
},
ToggleStar: function(data) {
var id = data.Created;
var recordingHolder = FARDB.Get(id);
if ( recordingHolder.Starred ) {
FARDB.RemoveStar( id );
} else {
FARDB.AddStar( id );
}
FARManager.LoadRecordings();
},
RunTest: function(event) {
var steps = JSON.parse( $('#recording-json').val() );
var data = {
ShowInterface: false,
Commands: steps,
ServiceModeEnabled: true
};
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:10001/RunTest",
data: JSON.stringify(data)
});
},
UpdateSettings: function() {
ViewModel.localStorageUsage( FARDB.GetUsage() );
ViewModel.settings.uniqueAttributes( FARDB.GetSetting('uniqueAttributes').join(',') );
},
SaveSettings: function() {
FARDB.SetSetting( 'uniqueAttributes', $('#setting-uniqueAttributes').val().split(',') );
},
DateFormat: function( ms ) {
var pad = function(n){return n<10 ? '0'+n : n}
var date = new Date(ms);
var dateStr = '';
dateStr += date.getFullYear();
dateStr += '-';
dateStr += pad(date.getMonth()+1);
dateStr += '-';
dateStr += pad(date.getDate());
dateStr += ' ';
dateStr += pad(date.getHours());
dateStr += ':';
dateStr += pad(date.getMinutes());
dateStr += ':';
dateStr += pad(date.getSeconds());
return dateStr;
}
}