fix(basic.gblib): SET MAX LINES now available to user larger files.

This commit is contained in:
Rodrigo Rodriguez 2021-04-12 10:07:59 -03:00
parent 21117c297c
commit 3e13202129
4 changed files with 46 additions and 13 deletions

View file

@ -34,7 +34,7 @@
import { BotAdapter, TurnContext } from 'botbuilder'; import { BotAdapter, TurnContext } from 'botbuilder';
import { WaterfallDialog, WaterfallStepContext } from 'botbuilder-dialogs'; import { WaterfallDialog, WaterfallStepContext } from 'botbuilder-dialogs';
import { GBLog, GBMinInstance } from 'botlib'; import { GBDialogStep, GBLog, GBMinInstance } from 'botlib';
import urlJoin = require('url-join'); import urlJoin = require('url-join');
import { GBServer } from '../../../src/app'; import { GBServer } from '../../../src/app';
import { GBDeployer } from '../../core.gbapp/services/GBDeployer'; import { GBDeployer } from '../../core.gbapp/services/GBDeployer';
@ -62,9 +62,9 @@ export class DialogKeywords {
* When creating this keyword facade, a bot instance is * When creating this keyword facade, a bot instance is
* specified among the deployer service. * specified among the deployer service.
*/ */
constructor(min: GBMinInstance, deployer: GBDeployer) { constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep) {
this.min = min; this.min = min;
this.internalSys = new SystemKeywords(min, deployer); this.internalSys = new SystemKeywords(min, deployer, step);
} }
/** /**
@ -162,6 +162,18 @@ export class DialogKeywords {
await this.min.userProfile.set(step.context, user); 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. * Returns the name of the user acquired by WhatsApp API.
*/ */

View file

@ -244,6 +244,10 @@ export class GBVMService extends GBService {
return `setLanguage (step, ${$3})\n`; 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) => { code = code.replace(/set\s(.*)/gi, ($0, $1, $2) => {
return `sys().set (${$1})`; return `sys().set (${$1})`;
}); });
@ -442,6 +446,9 @@ export class GBVMService extends GBService {
code = code.replace(/("[^"]*"|'[^']*')|\bsetLanguage\b/gi, ($0, $1) => { code = code.replace(/("[^"]*"|'[^']*')|\bsetLanguage\b/gi, ($0, $1) => {
return $1 === undefined ? 'this.setLanguage' : $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) => { code = code.replace(/("[^"]*"|'[^']*')|\btransfer\b/gi, ($0, $1) => {
return $1 === undefined ? 'this.transfer' : $1; return $1 === undefined ? 'this.transfer' : $1;
}); });
@ -707,7 +714,7 @@ export class GBVMService extends GBService {
// Creates a class DialogKeywords which is the *this* pointer // Creates a class DialogKeywords which is the *this* pointer
// in BASIC. // 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. // Injects the .gbdialog generated code into the VM.

View file

@ -30,7 +30,7 @@
| | | |
\*****************************************************************************/ \*****************************************************************************/
'use strict'; 'use strict';
import { GBLog, GBMinInstance } from 'botlib'; import { GBDialogStep, GBLog, GBMinInstance } from 'botlib';
import { CollectionUtil } from 'pragmatismo-io-framework'; import { CollectionUtil } from 'pragmatismo-io-framework';
import * as request from 'request-promise-native'; import * as request from 'request-promise-native';
import urlJoin = require('url-join'); import urlJoin = require('url-join');
@ -60,11 +60,17 @@ export class SystemKeywords {
*/ */
private readonly deployer: GBDeployer; private readonly deployer: GBDeployer;
/**
* Reference to the deployer service.
*/
private readonly step: GBDialogStep;
/** /**
* When creating this keyword facade, a bot instance is * When creating this keyword facade, a bot instance is
* specified among the deployer service. * specified among the deployer service.
*/ */
constructor(min: GBMinInstance, deployer: GBDeployer) { constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep) {
this.step = step;
this.min = min; this.min = min;
this.deployer = deployer; this.deployer = deployer;
} }
@ -285,6 +291,14 @@ export class SystemKeywords {
throw `File '${file}' has a FIND call with more than 1 arguments. Check the .gbdialog associated.`; 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. // Creates workbook session that will be discarded.
const filter = args[0].split('='); const filter = args[0].split('=');
@ -295,7 +309,7 @@ export class SystemKeywords {
.get(); .get();
let results = await client 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(); .get();
// Increments columnIndex by looping until find a column match. // Increments columnIndex by looping until find a column match.
@ -304,8 +318,6 @@ export class SystemKeywords {
const header = results.text[0]; const header = results.text[0];
for (; columnIndex < header.length; columnIndex++) { for (; columnIndex < header.length; columnIndex++) {
GBLog.info(`FIND DEBUG header: ${header[columnIndex]} columnName: ${columnName}`);
if (header[columnIndex].toLowerCase() === columnName.toLowerCase()) { if (header[columnIndex].toLowerCase() === columnName.toLowerCase()) {
break; break;
} }
@ -324,15 +336,15 @@ export class SystemKeywords {
let result = results.text[foundIndex][columnIndex]; let result = results.text[foundIndex][columnIndex];
GBLog.info(`FIND DEBUG result on foundIndex: ${foundIndex} columnIndex: ${columnIndex}: ${result}`);
// Filter results action. // Filter results action.
if (result && result.toLowerCase() === value.toLowerCase()) { if (result && result.toLowerCase() === value.toLowerCase()) {
let row = {}; let row = {};
const xlRow = results.text[foundIndex]; const xlRow = results.text[foundIndex];
for (let colIndex = 0; colIndex < xlRow.length; colIndex++) { 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; row['line'] = foundIndex + 1;
table.push(row); table.push(row);

View file

@ -513,7 +513,7 @@ export class GBMinService {
// Sends all information to the .gbui web client. // Sends all information to the .gbui web client.
if (theme === undefined) { if (theme === undefined) {
theme = 'default.gbtheme'; theme = `${instance.botId}.gbtheme`;
} }
res.send( res.send(
JSON.stringify({ JSON.stringify({
@ -751,6 +751,8 @@ export class GBMinService {
user.subjects = []; user.subjects = [];
user.cb = undefined; user.cb = undefined;
user.welcomed = false; user.welcomed = false;
user.basicOptions = { maxLines: 100 };
firstTime = true; firstTime = true;
// Sends loadInstance event to .gbui clients and loads FAQ. // Sends loadInstance event to .gbui clients and loads FAQ.