How can i get the index of the previous slide? - glidejs

How can i get the index of the previous slide?
I am using the following code:
var glide = new Glide('.glide', {})
var prevIndex = null
glide.on('run.before', () => {
prevIndex = glide.index
})
glide.mount()
Is there an easier way to get the index of the previous slide?

Related

Set the sourceRange of Data Validation to an array of values

I'm creating a social media outreach tracker. I want to create a drop-down list of the contact name. The problem is that I have two sources of names on two different sheets.
I wrote a script that pulls the names from the two different sources and combines them to a single array.
I was hoping to set the source range as that array.
Here is my code:
function setDataValid_(range, sourceRange) {
var rule = SpreadsheetApp.newDataValidation()
.requireValueInRange(sourceRange, true)
.build();
range.setDataValidation(rule);
}
function onEdit() {
var auditionsSheet = SpreadsheetApp.getActiveSpreadsheet();
var castingDirectorsTab = auditionsSheet.getSheetByName("Casting Directors");
var contactsTab = auditionsSheet.getSheetByName("Contacts");
var socialMediaOutreachTab = auditionsSheet.getSheetByName("Social Media Outreach");
var lastRowCD = castingDirectorsTab.getLastRow();
var lastRowContacts = contactsTab.getLastRow();
var activeCell = socialMediaOutreachTab.getActiveCell();
var activeColumn = activeCell.getColumn();
// get data
var castingDirectorNameData = castingDirectorsTab.getRange(2, 1, lastRowCD, 1).getValues();
var contactNameData = contactsTab.getRange(2, 1, lastRowContacts, 1).getValues();
//get name data to a single arrays
var castingDirectorName = [];
castingDirectorNameData.forEach(function(yr) {
castingDirectorName.push(yr[0]);
});
var contactName = [];
contactNameData.forEach(function(yr) {
contactName.push(yr[0]);
});
// get rid of the empty bits in the arrays
for (var x = castingDirectorName.length-1; x > 0; x--) {
if ( castingDirectorName[x][0] === undefined ) {
castingDirectorName.splice( x, 1 )
}
}
for (var x = contactName.length-1; x > 0; x--) {
if ( contactName[x][0] === undefined ) {
contactName.splice( x, 1 )
}
}
//combine two data sources for data validation
var combinedNames = [];
combinedNames.push(castingDirectorName + contactName);
Logger.log (combinedNames);
Logger.log( typeof combinedNames);
// data validation set up and build
if (activeColumn == 1 && auditionsSheet.getName() == "Social Media Outreach") {
var range = auditionsSheet.getRange(activeCell.getRow(), activeColumn +1);
var sourceRange = combinedNames;
setDataValid_(range, sourceRange)
}
}
When I enter a date in Col A on Social Media Outreach, nothing happens in Col 2.
I was using an existing working nested data validation script I have but the sourceRange pulls from a sheet based on the value in the active cell. Here is that code:
function setDataValid_(range, sourceRange) {
var rule = SpreadsheetApp.newDataValidation()
.requireValueInRange(sourceRange, true)
.build();
range.setDataValidation(rule);
}
function onEdit() {
var aSheet = SpreadsheetApp.getActiveSheet();
var aCell = aSheet.getActiveCell();
var aColumn = aCell.getColumn();
// data validation for Auditions Tab Projet Type to Project Details
if (aColumn == 9 && aSheet.getName() == 'Auditions') {
var range = aSheet.getRange(aCell.getRow(), aColumn + 1);
var sourceRange = SpreadsheetApp.getActiveSpreadsheet().getRangeByName('RefTables!' + aCell.getValue())
setDataValid_(range, sourceRange)
}
}
For this script when I select from the data validation drop-down, a new data validation comes up in the next col with the appropriate secondary data validation.
So the question is, can the source range be set to an array or do I need to put the names back into my sheet to reference a la the second script.
I've looked through the documentation and searched and can't find an answer. I'm relatively new to GAS and am not sure of all the inner workings of the data validation builder.

Oxyplot in xamarin not generated

I ran in to an issue in generating oxyplot with dynamic data. This is the first time I'm using oxyplot with dynamic data.
public async Task<PlotModel> AreaChart_NoOfPoliciesAsync()
{
var plotModel1 = new PlotModel { Title = "Number of Policies with last year" };
plotModel1.InvalidatePlot(true);
try
{
var s1 = new AreaSeries()
{
Title = "Number of policies in last year",
Color = OxyColors.LightPink,
MarkerType = MarkerType.Circle,
MarkerSize = 6,
MarkerStroke = OxyColors.White,
MarkerFill = OxyColors.LightPink,
MarkerStrokeThickness = 1.5
};
string year_str = DateTime.Today.AddYears(-1).ToString("yyyy");
int running_month = 1;
string running_month_str;
List<MonthlyPerformance> last_year = await _apiServices.GetMonthlyPerformance(Settings.AccessToken, Settings.agentCode, year_str);
last_year = last_year.FindAll(x => x.BUSS_TYPE == "Total");
last_year.Sort((x, y) => x.Y_MONTH.CompareTo(y.Y_MONTH));
s1.Points.Add(new DataPoint(0, 0));
foreach (MonthlyPerformance item in last_year)
{
s1.Points.Add(new DataPoint(running_month, item.NO_BUSINESS));
running_month++;
}
plotModel1.Series.Add(s1);
plotModel1.Axes.Add(new LinearAxis { Position = AxisPosition.Left, IsPanEnabled = false, IsZoomEnabled = false });
plotModel1.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, IsPanEnabled = false, IsZoomEnabled = false });
return plotModel1;}
The plot generated with hard coded values used for demo. But when the function
List<MonthlyPerformance> last_year = await _apiServices.GetMonthlyPerformance(Settings.AccessToken, Settings.agentCode, year_str);
is called, oxyplot is not being generated. I just get a blank space. I dont get any compilation errors.
I'm using MVVM. Could someone please point out what I'm doing wrong here.
Thanks in advance.
Once await and async were removed, the chart appeared.
I don't think it's the right way to handled the issue. But I was running out of development time.

How to begin a function only after a Parse.Object.saveAll or Parse.Promise.when

I'd like to be able to make my code a little more synchronous starting one function only after Parse has been updated. I've tried using Parse.Promise.when and Parse.Object.saveAll but it's not quite working the way I'd like as I get inconsistent behavior where the function after then begins before all of my updates have been saved.
I've reviewed the docs several times along with finding sample code on SO and other places but I'm definitely still going wrong somewhere along the way.
var goodResults = [1, 3, 5, 7];
var BlueSomething = Parse.Object.extend("something");
var query = new Parse.Query(BlueSomething);
query.find().then(function(results){
var array = [];
var array1 = [];
var array2 = [];
var array3 = [];
var resultsToEvaluate = _.map(results, function(n){
return n.get('theGoodResult')});
var newResults = _.difference(goodResults, resultsToEvaluate);
var oldResults = _.intersection(goodResults, resultsToEvaluate);
if(newResults.length > 0){
_.each(newResults, function(n){
var new = new BlueSomething();
new.set('status', n.get('someValue'));
array.push(new);})}
if(oldResults.length > 0){
_.each(oldResults, function(n){
var count = _.values(n.get('someField')).length;
var new = new BlueSomething;
if(count > 5){
n.set("full", true)
array1.push(n);
var new = new BlueSomething();
new.set("status", n.get('someValue'));
array2.push(new);
} else {
n.set("status", "updated");
array3.push(n)
}
})
}
return Parse.Object.saveAll(array, array1, array2, array3)
}).then(function(){//do other stuff only after the information
//has been saved to Parse});
It looks like you're not using the proper syntax for saveAll. The first argument should be an array of Parse objects, and the second is a callback. You could concat the arrays into one:
return Parse.Object.saveAll(array.concat(array1, array2, array3));

any idea why the below parse cloud code parallel promises do not run?

Am trying to match urls depending on the id given that i dont know if the id given is an object id / title / shorturl code.
var promises = [];
var id = request.params.id;
//short url
queryShortUrl = new Parse.Query("books");
queryShortUrl.limit = 1;
queryShortUrl.equalTo('shortURLcode',id);
promises.push(queryShortUrl.find());
//title
queryTitle = new Parse.Query("books");
queryTitle.limit = 1;
queryTitle.equalTo('bookTitle',id);
promises.push(queryNickname.find());
//objectId
queryObjectId = new Parse.Query("books");
promises.push(queryObjectId.get(request.params.genuid));
// run these
Parse.Promise.when(promises).then(function() {
console.log('res');
response.success(arguments);
})

How to pass a input value into a function using GAS

I will try and keep this brief. I am attempting to make a google web app in google spreadsheet that will allow me to enter a values for min and max.
I have been able to create the GUI and add it to the panel. But I can't seem to pass the integer being entered into another function. I've tried everything, I'm relatively new to creating Google Script so I'm sorry if this comes across as a bit of a noobish problem.
Here is all the code so far :
function onOpen() {
var ss = SpreadsheetApp.getActive();
var menuEntries = [];
menuEntries.push({name: "Open Dialog", functionName: "showDialog"});
ss.addMenu("Min/Max", menuEntries);
}
//creating a panel to add the min and max of low to high for scoring
function showDialog() {
max = 10;
var app = UiApp.createApplication();
app.setTitle("My Applicaition");
var panel = app.createVerticalPanel();
var textBox = app.createTextBox();
var label = app.createLabel("Set the min value for 'Low'");
//had to create a hidden element with id="min" for a global value that can be updated
var min = app.createHidden().setValue('0').setName('min').setId('min');
textBox.setName('myTextBox').setId('myTextBox');
var button = app.createButton('Submit');
panel.add(label);
panel.add(textBox);
panel.add(min);
panel.add(button);
//click handler for setting the value of min to the new value
var clickHandler = app.createServerClickHandler("responedToSubmit");
button.addClickHandler(clickHandler);
clickHandler.addCallbackElement(panel);
app.add(panel);
var doc = SpreadsheetApp.getActive();
doc.show(app);
}
function responedToSubmit(e) {
var app = UiApp.getActiveApplication();
var textBoxValue = e.parameter.myTextBox;
Logger.log(e.parameter.min);
if (typeof textBoxValue != "number") {
var num = parseInt(textBoxValue);
app.getElementById('min').setValue(num);
Logger.log("textBoxValue is = "+textBoxValue+"\n min value is = "+e.parameter.min);
} else {
throw "value needs to be set as number";
}
return app.close();
}
This is where I believe things aren't going according to plan :
function responedToSubmit(e) {
var app = UiApp.getActiveApplication();
var textBoxValue = e.parameter.myTextBox;
Logger.log(e.parameter.min);
if (typeof textBoxValue != "number") {
var num = parseInt(textBoxValue);
app.getElementById('min').setValue(num);
Logger.log("textBoxValue is = "+textBoxValue+"\n min value is = "+e.parameter.min);
} else {
throw "value needs to be set as number";
}
return app.close();
}
I find that each time I test the .setValue() will not update the value of 'min' and I cannot see why. Can you please help?
You need to add textBox element to callBack elements list of your clickHandler.
Try this:
//click handler for setting the value of min to the new value
var clickHandler = app.createServerClickHandler("responedToSubmit");
clickHandler.addCallbackElement(panel);
clickHandler.addCallbackElement(textBox);
button.addClickHandler(clickHandler);
app.add(panel);

Resources