-
Notifications
You must be signed in to change notification settings - Fork 0
/
LastDateUpdater.gs
120 lines (88 loc) · 4.29 KB
/
LastDateUpdater.gs
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
var LastDateUpdater=new function(){
/**
* STORE INTO SESSION THE LABEL ROW FOR LAST DATE
* @param {string} user token
* @deprecated not used
*/
this.protectCell = function(userToken){
//get the google spreadSheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
//get all the sheets
var allSheets = ss.getSheets();
//loop all the sheets and set all the properties needed
for(var i=0; i< allSheets.length; i++){
var sheetName = allSheets[i].getName();
//if is not an hidden template
if( sheetName.indexOf('Template_') < 0){
var commodityName = ss.getSheetByName(sheetName).getRange(Config.Sheet.commodityCell).getValue().toLowerCase();
// var labelRowForLastDate=JSON.parse(FirebaseConnector.getFireBaseData('config/labelRowForLastDate/'+FirebaseConnector.getCountryNameFromSheet(userToken)+'/'+commodityName,userToken));
// //store into session the labelRowForLastDate
// PropertiesService.getUserProperties().setProperty(commodityName+"_labelRowForLastDate", labelRowForLastDate);
// var rangeFromConfigNotParsed = FirebaseConnector.getFireBaseData('config/rangeToBeProtectedFromSettingLastDateUpdate/'+FirebaseConnector.getCountryNameFromSheet(userToken)+'/'+commodityName,FirebaseConnector.getToken());
//
// //store into session the ranges to be protected
// PropertiesService.getUserProperties().setProperty(commodityName+"_rangeProtected",rangeFromConfigNotParsed);
var addForecastConfigNotParsed = FirebaseConnector.getFireBaseData('config/addForecast/'+FirebaseConnector.getCountryNameFromSheet(userToken)+'/'+commodityName,userToken);
var addForecastConfig=JSON.parse(addForecastConfigNotParsed);
//store into session the ranges to be protected
PropertiesService.getUserProperties().setProperty(commodityName+"_addForecastConfig",addForecastConfigNotParsed);
}
}
};
/**
* set the last date for column when you edit the sheet
* @param {object} e the event
* @param {string} activeRangeA1 active range in A1Notation
* @return {void}
*/
this.onEditSetLastUpdateDate = function( e, activeRangeA1 ) {
var rangesToCheck = [],
rangeToBeStored, cell_isFMorFN, thisCol, lastDateRanges;
//get the google sheet
var ss = SpreadSheetCache.getActiveSheet();
var lastDateUpdaterRow = parseInt( AmisNamedRanges.getCommodityNamedRanges().labelRowForLastDate.row.split( ":" )[ 0 ], 10 );
//var thisCol = e.range.getColumn();
if ( ~activeRangeA1.indexOf( ":" ) ) {
thisCol = ConvertA1.rangeA1ToIndex( activeRangeA1, 1 ).left;
} else {
thisCol = ConvertA1.cellA1ToIndex( activeRangeA1, 1 ).col;
}
rangeToBeStored = SyncMasterSheet.getRangeToBeStored();
lastDateRanges = LastDateUpdater.getLastDateRanges();
rangesToCheck = [].concat(rangeToBeStored, lastDateRanges);
//used after to determinate if set the last date or not
var canWrite = Utility.isInAnyRange( rangesToCheck, activeRangeA1 );
cell_isFMorFN = ForecastUtility.isFMorFN( activeRangeA1 );
if ( canWrite && !cell_isFMorFN ) {
var cell = ss.getRange( lastDateUpdaterRow, thisCol );
cell.setValue( moment.utc().format( Config.lastUpdatedDateDBFormat ) );
cell.setNumberFormat( Config.lastUpdatedDateSheetFormat );
cell.setFontWeight( "bold" );
}
};
/**
* reads the lastDateUpdaterRow from the named ranges
* @param {object} sheet [optional] the sheet
* @return {string} the range in A1 format
*/
this.getLURowA1 = function( sheet ) {
sheet = ( sheet || SpreadSheetCache.getActiveSheet() );
return AmisNamedRanges.getCommodityNamedRangesBySheet( sheet ).labelRowForLastDate.row;
};
/**
* reads the lastDateUpdaterRow from the named ranges
* @param {object} sheet [optional] the sheet
* @return {number} the row number
*/
this.getLURow = function( sheet ) {
sheet = ( sheet || SpreadSheetCache.getActiveSheet() );
return parseInt( this.getLURowA1( sheet ).split( ":" )[ 0 ], 10 );
};
/**
* reads the lastDateRanges from the named ranges
* @return {[string]} array of the ranges in A1 format
*/
this.getLastDateRanges=function(){
return AmisNamedRanges.getCommodityNamedRanges().lastDateRanges;
};
};