Skip to content

Commit

Permalink
Merge pull request #663 from q-masters/development
Browse files Browse the repository at this point in the history
Release 1.7.0
  • Loading branch information
konne authored Nov 2, 2020
2 parents b4beb97 + 14799e8 commit 327976e
Show file tree
Hide file tree
Showing 12 changed files with 300 additions and 135 deletions.
18 changes: 17 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@
"icon": {
"light": "./projects/media/icons/load-data.light.svg",
"dark": "./projects/media/icons/load-data.dark.svg"
}
},
"enablement": "VsQlik.Script.DataLoadState != progressing"
},
{
"command": "VsQlik.Script.StopLoadData",
"title": "Cancel current reload data",
"category": "VsQlik",
"icon": {
"light": "./projects/media/icons/stop-load-data.light.svg",
"dark": "./projects/media/icons/stop-load-data.dark.svg"
},
"enablement": "VsQlik.Script.DataLoadState == progressing"
}
],
"configuration": [
Expand Down Expand Up @@ -120,6 +131,11 @@
],
"menus": {
"editor/title": [
{
"command": "VsQlik.Script.StopLoadData",
"group": "navigation",
"when": "resourceScheme == 'qix' && resourceFilename == 'main.qvs' && !isInDiffEditor"
},
{
"command": "VsQlik.Script.LoadData",
"group": "navigation",
Expand Down
78 changes: 49 additions & 29 deletions src/projects/extension/connection/utils/application.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { from, Observable, Subject, zip } from "rxjs";
import { debounceTime, map, switchMap } from "rxjs/operators";
import { from, Observable, Subject } from "rxjs";
import { debounceTime, switchMap } from "rxjs/operators";

export class Application {

Expand Down Expand Up @@ -74,23 +74,25 @@ export class Application {
.toPromise();
}

public async getRemoteScript(): Promise<string> {
const doc = await this.document;
return await doc.getScript(); // script from server
}

/**
* return script for currrent application
* if force is set to false script will cached
* get script for current application
*
* 1. check if cached and return last cached version
* 2. if not existis get last saved version of the script from the properties
* 3. by default return remote script
*/
public async getScript(force = false): Promise<string> {

if (!this.script || force) {
const doc = await this.document;
const script = await doc.getScript(); // script from server

if (!force) {
const appProps = await this.properties;
this.script = appProps.vsqlik?.script || script;
}
return script;
public async getScript(): Promise<string> {
if (!this.script) {
const remoteScript = await this.getRemoteScript();
const appProps = await this.properties;
this.script = appProps.vsqlik?.script || remoteScript;
}
return this.script;
return this.script ?? '';
}

/**
Expand All @@ -100,24 +102,42 @@ export class Application {
this.script = null;
}

/** update a script */
public async updateScript(content: string, persist = true): Promise<void> {
/**
* update only cached script
* this only happens if the server emits changes but we do not have touched this
* yet
*/
public async updateScript(content: string): Promise<void> {
this.script = content;
}

/**
* update property on application
* @param content what should be written
* @param key the key which should be written
*/
public async updateProperty(content: string, key = "script"): Promise<void> {
const doc = await this.doc;
const currrentData = await this.properties;
currrentData.vsqlik = { [key]: content };

if (persist) {
await doc.setScript(content);
await doc.doSave();
await (await this.appProperties).setProperties(currrentData);
}

/** save current working copy if we save */
const currrentData = await this.properties;
currrentData.vsqlik = {
script: this.script as string
};
await (await this.appProperties).setProperties(currrentData);
}
/**
* persist script on server
*/
public async writeScript(): Promise<void> {
const doc = await this.doc;
await doc.setScript(this.script ?? '');
}

this.script = content;
/**
* trigger app to do a save
*/
public async save(): Promise<void> {
const doc = await this.doc;
doc.doSave();
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/projects/extension/script/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./active-script";
export * from "./check-syntax";
export * from "./load-data";
91 changes: 0 additions & 91 deletions src/projects/extension/script/commands/load-data.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/projects/extension/script/data/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum ScriptCommands {
CHECK_SYNTAX = 'VsQlik.Script.CheckSyntax',
LOAD_DATA = 'VsQlik.Script.LoadData',
STOP_LOAD_DATA = 'VsQlik.Script.StopLoadData',
RESOLVE_ACTIVE = 'VsQlik.Script.ResolveActive',
SYNCHRONIZE = 'VsQlik.Script.Synchronize'
}
30 changes: 25 additions & 5 deletions src/projects/extension/script/script.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import { QixRouter } from "@core/router";
import { ExtensionContext } from "@data/tokens";
import { inject, singleton } from "tsyringe";

import { CheckScriptSyntax, ScriptLoadDataCommand, ScriptResolveActiveCommand } from "./commands";
import { CheckScriptSyntax, ScriptResolveActiveCommand } from "./commands";
import { routes } from "./data/routes";
import { ScriptSynchronizeCommand } from "./commands/sync-script";
import { ScriptCommands } from "./data/commands";
import { ScriptGuard } from "./utils/script.guard";
import { LoadDataProvider } from "./utils/load-data";

@singleton()
export class ScriptModule {

constructor(
@inject(ExtensionContext) private extensionContext: vscode.ExtensionContext,
@inject(QixRouter) private router: QixRouter<any>,
@inject(ScriptGuard) private scriptGuard: ScriptGuard
) {
}
@inject(ScriptGuard) private scriptGuard: ScriptGuard,
@inject(LoadDataProvider) private loadDataProvider: LoadDataProvider
) {}

/**
* bootstrap script module
Expand All @@ -26,16 +27,35 @@ export class ScriptModule {
this.router.addRoutes(routes);
this.registerCommands();
this.scriptGuard.init();

vscode.commands.executeCommand('setContext', 'VsQlik.Script.DataLoadState', 'idle');
}

/**
* register commands for vscode
*/
private registerCommands(): void {

/** @todo move to enum */
this.extensionContext.subscriptions.push(vscode.commands.registerCommand(ScriptCommands.CHECK_SYNTAX , CheckScriptSyntax));
this.extensionContext.subscriptions.push(vscode.commands.registerCommand(ScriptCommands.LOAD_DATA , ScriptLoadDataCommand));
this.extensionContext.subscriptions.push(vscode.commands.registerCommand(ScriptCommands.LOAD_DATA , () => this.onLoadData()));
this.extensionContext.subscriptions.push(vscode.commands.registerCommand(ScriptCommands.STOP_LOAD_DATA, () => this.onStopLoadData()));
this.extensionContext.subscriptions.push(vscode.commands.registerCommand(ScriptCommands.RESOLVE_ACTIVE, ScriptResolveActiveCommand));
this.extensionContext.subscriptions.push(vscode.commands.registerCommand(ScriptCommands.SYNCHRONIZE , ScriptSynchronizeCommand));
}

private async onLoadData() {
const document = await vscode.commands.executeCommand<vscode.TextDocument>(ScriptCommands.RESOLVE_ACTIVE);
if (document) {
vscode.commands.executeCommand('setContext', 'VsQlik.Script.DataLoadState', 'progressing');
this.loadDataProvider.exec(document);
}
}

private async onStopLoadData() {
const document = await vscode.commands.executeCommand<vscode.TextDocument>(ScriptCommands.RESOLVE_ACTIVE);
if (document) {
this.loadDataProvider.stop();
}
}
}
Loading

0 comments on commit 327976e

Please sign in to comment.