Skip to content

Commit

Permalink
fix(basic.gblib): SET MAX LINES now available to user larger files.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Apr 12, 2021
1 parent 21117c2 commit 3e13202
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
18 changes: 15 additions & 3 deletions packages/basic.gblib/services/DialogKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import { BotAdapter, TurnContext } from 'botbuilder';
import { WaterfallDialog, WaterfallStepContext } from 'botbuilder-dialogs';
import { GBLog, GBMinInstance } from 'botlib';
import { GBDialogStep, GBLog, GBMinInstance } from 'botlib';
import urlJoin = require('url-join');
import { GBServer } from '../../../src/app';
import { GBDeployer } from '../../core.gbapp/services/GBDeployer';
Expand Down Expand Up @@ -62,9 +62,9 @@ export class DialogKeywords {
* When creating this keyword facade, a bot instance is
* specified among the deployer service.
*/
constructor(min: GBMinInstance, deployer: GBDeployer) {
constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep) {
this.min = min;
this.internalSys = new SystemKeywords(min, deployer);
this.internalSys = new SystemKeywords(min, deployer, step);
}

/**
Expand Down Expand Up @@ -162,6 +162,18 @@ export class DialogKeywords {
await this.min.userProfile.set(step.context, user);
}

/**
* Defines the maximum lines to scan in spreedsheets.
*
* @example SET MAX LINES 5000
*
*/
public async setMaxLines(step, count) {
const user = await this.min.userProfile.get(step.context, {});
user.basicOptions.maxLines = count;
await this.min.userProfile.set(step.context, user);
}

/**
* Returns the name of the user acquired by WhatsApp API.
*/
Expand Down
9 changes: 8 additions & 1 deletion packages/basic.gblib/services/GBVMService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ export class GBVMService extends GBService {
return `setLanguage (step, ${$3})\n`;
});

code = code.replace(/(set max lines)(\s*)(.*)/gi, ($0, $1, $2, $3) => {
return `setMaxLines (step, ${$3})\n`;
});

code = code.replace(/set\s(.*)/gi, ($0, $1, $2) => {
return `sys().set (${$1})`;
});
Expand Down Expand Up @@ -442,6 +446,9 @@ export class GBVMService extends GBService {
code = code.replace(/("[^"]*"|'[^']*')|\bsetLanguage\b/gi, ($0, $1) => {
return $1 === undefined ? 'this.setLanguage' : $1;
});
code = code.replace(/("[^"]*"|'[^']*')|\bsetMaxLines\b/gi, ($0, $1) => {
return $1 === undefined ? 'this.setMaxLines' : $1;
});
code = code.replace(/("[^"]*"|'[^']*')|\btransfer\b/gi, ($0, $1) => {
return $1 === undefined ? 'this.transfer' : $1;
});
Expand Down Expand Up @@ -707,7 +714,7 @@ export class GBVMService extends GBService {
// Creates a class DialogKeywords which is the *this* pointer
// in BASIC.

const sandbox: DialogKeywords = new DialogKeywords(min, deployer);
const sandbox: DialogKeywords = new DialogKeywords(min, deployer, step);

// Injects the .gbdialog generated code into the VM.

Expand Down
28 changes: 20 additions & 8 deletions packages/basic.gblib/services/SystemKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
| |
\*****************************************************************************/
'use strict';
import { GBLog, GBMinInstance } from 'botlib';
import { GBDialogStep, GBLog, GBMinInstance } from 'botlib';
import { CollectionUtil } from 'pragmatismo-io-framework';
import * as request from 'request-promise-native';
import urlJoin = require('url-join');
Expand Down Expand Up @@ -60,11 +60,17 @@ export class SystemKeywords {
*/
private readonly deployer: GBDeployer;

/**
* Reference to the deployer service.
*/
private readonly step: GBDialogStep;

/**
* When creating this keyword facade, a bot instance is
* specified among the deployer service.
*/
constructor(min: GBMinInstance, deployer: GBDeployer) {
constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep) {
this.step = step;
this.min = min;
this.deployer = deployer;
}
Expand Down Expand Up @@ -285,6 +291,14 @@ export class SystemKeywords {
throw `File '${file}' has a FIND call with more than 1 arguments. Check the .gbdialog associated.`;
}

const user = await this.min.userProfile.get(this.step.context, {});
let maxLines = 100;
if (user.basicOptions && user.basicOptions.maxLines) {
if (user.basicOptions.maxLines.toString().toLowerCase() !== "default") {
maxLines = Number.parseInt(user.basicOptions.maxLines).valueOf();
}
}

// Creates workbook session that will be discarded.

const filter = args[0].split('=');
Expand All @@ -295,7 +309,7 @@ export class SystemKeywords {
.get();

let results = await client
.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets('${sheets.value[0].name}')/range(address='A1:Z2000')`)
.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets('${sheets.value[0].name}')/range(address='A1:Z${maxLines}')`)
.get();

// Increments columnIndex by looping until find a column match.
Expand All @@ -304,8 +318,6 @@ export class SystemKeywords {
const header = results.text[0];
for (; columnIndex < header.length; columnIndex++) {

GBLog.info(`FIND DEBUG header: ${header[columnIndex]} columnName: ${columnName}`);

if (header[columnIndex].toLowerCase() === columnName.toLowerCase()) {
break;
}
Expand All @@ -324,15 +336,15 @@ export class SystemKeywords {

let result = results.text[foundIndex][columnIndex];

GBLog.info(`FIND DEBUG result on foundIndex: ${foundIndex} columnIndex: ${columnIndex}: ${result}`);

// Filter results action.

if (result && result.toLowerCase() === value.toLowerCase()) {
let row = {};
const xlRow = results.text[foundIndex];
for (let colIndex = 0; colIndex < xlRow.length; colIndex++) {
row[header[colIndex]] = xlRow[colIndex];
const propertyName = header[colIndex];
GBLog.info(`xxxxxxxxxx ${propertyName}`);
row[propertyName] = xlRow[colIndex];
}
row['line'] = foundIndex + 1;
table.push(row);
Expand Down
4 changes: 3 additions & 1 deletion packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export class GBMinService {
// Sends all information to the .gbui web client.

if (theme === undefined) {
theme = 'default.gbtheme';
theme = `${instance.botId}.gbtheme`;
}
res.send(
JSON.stringify({
Expand Down Expand Up @@ -751,6 +751,8 @@ export class GBMinService {
user.subjects = [];
user.cb = undefined;
user.welcomed = false;
user.basicOptions = { maxLines: 100 };

firstTime = true;

// Sends loadInstance event to .gbui clients and loads FAQ.
Expand Down

0 comments on commit 3e13202

Please sign in to comment.