-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.html
More file actions
382 lines (334 loc) · 15.2 KB
/
script.html
File metadata and controls
382 lines (334 loc) · 15.2 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
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>-->
<script>
/*$(function() {
$( ".draggable" ).draggable();
});*/
//Angular
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $interval, filterFilter){
$scope.students = [];
$scope.error = {status: false, class: "bg-danger", msg: "Error"};
$scope.dataFetching = false;
$scope.data = {tripCounts : new Array()};
$scope.tripCounts = {};
$scope.refreshInterval = 30;
$scope.intervalCounter = 0;
$scope.intervalMin = 20;
$scope.intervalMax = 120;
$scope.intervalPromise = "";
$scope.intervalStarted = false;
$scope.myFilter = {}
$scope.getFilterCount = function(){
return filterFilter( $scope.students, myFilter).length;
}
$scope.resetFilter = function() {
resetFilter();
}
function resetFilter() {
$scope.myFilter = { currentchoice: { id: "",
email: "",
timeDate: "",
hrm: "",
advisorChecked: "",
choice1: "",
choice2: "",
approvalChange: "",
approvalDate: "",
principalChecked: "",
paid: "",
canPost: ""},
student: { id: "",
email: "",
hrm: "",
lastname: "",
firstname: "",
advisor: "",
surveyOpen: "",
surveyStart: "",
surveyEnd: "",
gender: "",
fullname: ""}};
}
resetFilter();
$scope.reloadData = function(){
loadData();
}
$scope.toggleInterval = function(){
//$scope.intervalStarted = !($scope.intervalStarted);
if ($scope.intervalStarted){ startInterval(); } else { stopInterval()};
}
function loadData() {
$scope.dataFetching = true;
google.script.run.withSuccessHandler(showData).loadGInfo();
}
loadData();
function startInterval(){
$interval.cancel($scope.intervalPromise);
$scope.intervalPromise = $interval(function(){
var refreshInterval = $scope.refreshInterval;
$scope.intervalCounter++;
var counter = $scope.intervalCounter;
//console.log(counter);
if(refreshInterval < $scope.intervalMin){
$scope.refreshInterval = 20;
}
if(counter % refreshInterval == 0){
fetchCountsData();
$scope.intervalCounter=0;
}
}, 1000);
}
function stopInterval(){
$interval.cancel($scope.intervalPromise);
}
function showData(data){
$scope.data = data;
$scope.dataFetching = false;
$scope.error = data.error;
try{
var myData = $scope.data;
updateDataSet();
$scope.students.forEach((student, index) => {
student.row = index;
}); //Get and save index in array for later updating.
if(!$scope.error.status){
$scope.toggleInterval();
} else {
stopInterval();
}
} catch(e) {
$scope.error.msg = e;
$scope.error.status = true;
console.log(e);
}//*/
$scope.$digest();
console.log($scope);
};
function updateDataSet(){
var myData = $scope.data;
var students = [];
for (var s=0; s < myData.studentInfo.length; s++){ //loop through each student in student info
var thisRow = myData.studentInfo[s];
var thisStudent = { id: thisRow[0],
email: thisRow[11],
hrm: thisRow[2],
lastname: thisRow[3],
firstname: thisRow[4],
advisor: thisRow[20],
surveyOpen: thisRow[17],
surveyStart: thisRow[18],
surveyEnd: thisRow[19],
gender: thisRow[15],
fullname: thisRow[1],
house: thisRow[14]
};
var myChoices = getRowsMatching(myData.choiceData, 0, thisStudent.id);
var thisChoices = {};
console.log(myChoices, thisStudent.id, myData.choiceData);
if (myChoices.length > 0){
thisChoices = { id: myChoices[0][0],
email: myChoices[0][1],
timeDate: myChoices[0][2],
hrm: myChoices[0][3],
advisorChecked: myChoices[0][4],
choice1: myChoices[0][5],
choice2: myChoices[0][6],
approvalChange: myChoices[0][7],
approvalDate: myChoices[0][8],
principalChecked: myChoices[0][9],
paid: myChoices[0][10],
canPost: thisRow[17],
house: myChoices[0][11]
};
} else {
thisChoices = { id: thisRow[0],
email: thisRow[0],
timeDate: "",
hrm: thisRow[2],
advisorChecked: false,
choice1: "",
choice2: "",
approvalChange: "",
approvalDate: "",
principalChecked: false,
paid: "",
canPost: thisRow[17],
house: thisRow[14]
};
}
var choiceList = [];
var possibleChoices = myData.possibleChoiceList;
for (var ch = 0; ch < possibleChoices.length; ch++){
//Check choices for isParent and isStudent - if isStudent, make sure col 11 is True, is isParent, make sure col 12 is True. If isApprover, allow all choices.
if(myData.userType.isStudent && !possibleChoices[ch][11]) continue; //skip this option if student and col 11 is not true
if(myData.userType.isParent && !possibleChoices[ch][12]) continue; //skip this option if parent and col 12 is not true
if(possibleChoices[ch][9]){ //if this choice is "TRUE" for choice 1
var thisRequirement = possibleChoices[ch][6];
var thisReqCol = possibleChoices[ch][5];
if (thisRequirement.includes(thisRow[thisReqCol])) { //If student data matches requirement of activity
choiceList.push(possibleChoices[ch][0]);
}
}
}
var choiceList2 = []
for (var ch = 0; ch < possibleChoices.length; ch++){
//Check choices for isParent and isStudent - if isStudent, make sure col 11 is True, is isParent, make sure col 12 is True. If isApprover, allow all choices.
if(myData.userType.isStudent && !possibleChoices[ch][11]) continue; //skip this option if student and col 11 is not true
if(myData.userType.isParent && !possibleChoices[ch][12]) continue; //skip this option if parent and col 12 is not true
if(possibleChoices[ch][10]){ //if this choice is "TRUE" for choice 2
var thisRequirement = possibleChoices[ch][6];
var thisReqCol = possibleChoices[ch][5];
if (thisRequirement.includes(thisRow[thisReqCol])) { //If student data matches requirement of activity
choiceList2.push(possibleChoices[ch][0]);
}
}
}
students.push({student: thisStudent, currentchoice: JSON.parse(JSON.stringify(thisChoices)), choice: JSON.parse(JSON.stringify(thisChoices)), possibleChoices: choiceList, possibleChoices2: choiceList2}); //currentchoice will load a copy of the choice data. choice will be used to be manipulated by user and submit to server.
}
$scope.students = students;
updateTripCounts();
};
function fetchCountsData() {
$scope.dataFetching = true;
google.script.run.withSuccessHandler(tripCountsReceived).getTripCounts();
}
function tripCountsReceived(e){
$scope.dataFetching = false;
//console.log(e);
$scope.data.tripCounts = e;
updateTripCounts();
}
function updateTripCounts(){
var trip = {};
var myData = $scope.data;
//var myTripCounts = $scope.tripCounts;
for (var t=1; t < myData.tripCounts.length; t++){ //loop through each entry in tripCounts
trip[myData.tripCounts[t][0]] = {name: myData.tripCounts[t][0],
quota: myData.tripCounts[t][1],
taken: myData.tripCounts[t][2],
session: myData.tripCounts[t][3],
location: myData.tripCounts[t][4],
displayName: myData.tripCounts[t][5],
masterActivity: myData.tripCounts[t][6] };
}
$scope.tripCounts = trip;
$scope.$digest();
}
$scope.handleParentChoice1Change = function(s) {
s.choice.choice2 = ''; // Clear the second choice
$scope.updateFilteredChoices(s); // Call the existing function
};
$scope.updateFilteredChoices = function(s,check) {
if($scope.tripCounts[check]){
var taken = $scope.tripCounts[check].masterActivity;
return function(choice) { // Return a filtering function
//return $scope.tripCounts[choice].masterActivity != taken;
return !$scope.tripCounts[choice].masterActivity.includes(taken); //Change to return where masterActivity contains a list of items not to include.
};
} else{
return function(choice) {
return true;
}
}
};
$scope.postChoices = function(data, sindex){
//console.log(data);
$scope.dataFetching = true;
google.script.run.withSuccessHandler(saveSuccess).approverPostData(data, sindex);
};
$scope.studentPostChoices = function(data, sindex){
console.log(data);
$scope.dataFetching = true;
google.script.run.withSuccessHandler(saveSuccess).studentPostData(data, sindex);
};
$scope.parentPostChoices = function(data, sindex){
console.log(data);
$scope.dataFetching = true;
google.script.run.withSuccessHandler(saveSuccess).parentPostData(data, sindex);
};
function saveSuccess(e){
$scope.dataFetching = false;
console.log(e);
//console.log(e.hasOwnProperty("choice"));
$scope.error = e.error;
if(e.hasOwnProperty("choice")){ //if no error, update data
$scope.students[e.sindex].choice = e.choice;
$scope.students[e.sindex].currentchoice = JSON.parse(JSON.stringify(e.choice));
}else{ //if no choice data, let's assume error and refresh data for user.
loadData();
}
console.log($scope);
$scope.$digest();
fetchCountsData();
};
$scope.checkButtonDisabled = function(s){ //returns TRUE if button should be disabled
//console.log({currentchoice: s.currentchoice, choice: s.choice, equal: angular.equals(s.currentchoice,s.choice)})
return $scope.dataFetching || angular.equals(s.currentchoice,s.choice) || !(s.choice.choice1 && s.choice.choice2);
}
$scope.checkParentSubmitDisabled = function(s){ //returns TRUE if button should be disabled
//console.log({currentchoice: s.currentchoice, choice: s.choice, equal: angular.equals(s.currentchoice,s.choice)})
return $scope.dataFetching || angular.equals(s.currentchoice,s.choice) || !(s.choice.choice1 && s.choice.choice2);
}
})
.directive('submitButtons', function() {
return {
scope: {
choiceData: '=',
studentData: '@'
},
template: '<button ng-click="postChoice(choiceData)" title="Survey Open:{{studentData.surveyOpen}} from {{studentData.surveyStart}} until {{studentData.surveyEnd}}">Submit choices</button>'
};
});
//-----
// getExistingRow - returns the row that contains the data matching the criteria, or returns the next row in the spreadsheet.
//
//-----
function getExistingRow(myList,checkCol,checkCriteria){
var myRow = 0;
while (myRow < myList.length){
if (myList[myRow][checkCol] == checkCriteria) {
return myRow;
}
myRow++;
}
return myRow;
}
//-----
// getRowsMatching takes a data list and searches the sortIndex for all values that match valueToFind, returning the rows that match this value
//-----
function getRowsMatching(myDataList, sortIndex, valueToFind){
var foundList = new Array();
myDataList.sort(function(a, b){ //Sort the items by studentID
var x = a[sortIndex];
var y = b[sortIndex];
return (x < y ? -1 : (x > y ? 1 : 0));});
var cdr = 0;
var found = false;
while ( cdr < myDataList.length){
if (myDataList[cdr][sortIndex] == valueToFind) {
found=true;
foundList.push(myDataList[cdr])
}
else if (found){
return foundList;
}
cdr++;
}
return foundList;
}
//Returns True if Value is found in col column of myArray 2D array
function findThisInArray(myArray, value, col){
for( var i = 0; i < myArray.length; i++ ) {
if(myArray[i][col] == value ) {
return true;
break;
}
}
return false;
}
</script>