Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/openedge-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"numThreads": 1,
"procedures": [],
"profiles": []
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
"Small"
],
"description": "Set the grid text size."
},
"pro-bro.readOnlyMode": {
"type": "boolean",
"default": false,
"markdownDescription": "Connect to all databases in read-only mode (requires restart)"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions src/common/IExtensionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ISettings {
filterAsYouType: boolean;
useDeleteTriggers: boolean;
gridTextSize: string;
readOnlyMode: boolean;
}

export interface ILogging {
Expand Down
90 changes: 48 additions & 42 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,58 @@ export async function activate(context: vscode.ExtensionContext) {
let allFileContent = '';

vscode.workspace.onDidChangeConfiguration((event) => {
const affected = event.affectsConfiguration(
`${Constants.globalExtensionKey}.possiblePortsList`
);
if (!affected) {
return;
}
if (
event.affectsConfiguration(
`${Constants.globalExtensionKey}.possiblePortsList`
)
) {
const settingsPorts: number[] =
vscode.workspace
.getConfiguration(Constants.globalExtensionKey)
.get('possiblePortsList') ?? [];
if (settingsPorts.length === 0) {
context.globalState.update(
`${Constants.globalExtensionKey}.portList`,
undefined
);
return;
}
let newGlobalStatePortList: IPort[] = [];
const globalStatePorts = context.globalState.get<{
[id: string]: IPort;
}>(`${Constants.globalExtensionKey}.portList`);
if (globalStatePorts) {
newGlobalStatePortList = Object.values(globalStatePorts).filter(
(gPort) => {
const portIndex: number = settingsPorts.indexOf(
gPort.port
);
if (portIndex < 0) {
return false;
} else {
settingsPorts.splice(portIndex, 1);
return true;
}
}
);
}

newGlobalStatePortList = [
...newGlobalStatePortList,
...settingsPorts.map((sPort: number): IPort => {
return {
port: sPort,
isInUse: false,
timestamp: undefined,
};
}),
];

const settingsPorts: number[] =
vscode.workspace
.getConfiguration(Constants.globalExtensionKey)
.get('possiblePortsList') ?? [];
if (settingsPorts.length === 0) {
context.globalState.update(
`${Constants.globalExtensionKey}.portList`,
undefined
);
return;
}
let newGlobalStatePortList: IPort[] = [];
const globalStatePorts = context.globalState.get<{
[id: string]: IPort;
}>(`${Constants.globalExtensionKey}.portList`);
if (globalStatePorts) {
newGlobalStatePortList = Object.values(globalStatePorts).filter(
(gPort) => {
const portIndex: number = settingsPorts.indexOf(gPort.port);
if (portIndex < 0) {
return false;
} else {
settingsPorts.splice(portIndex, 1);
return true;
}
}
newGlobalStatePortList
);
}

newGlobalStatePortList = [
...newGlobalStatePortList,
...settingsPorts.map((sPort: number): IPort => {
return { port: sPort, isInUse: false, timestamp: undefined };
}),
];

context.globalState.update(
`${Constants.globalExtensionKey}.portList`,
newGlobalStatePortList
);
});

const updatePortList = () => {
Expand Down Expand Up @@ -218,6 +223,7 @@ export async function activate(context: vscode.ExtensionContext) {
});

function createJsonDatabases(uri: vscode.Uri) {
console.warn('VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV');
allFileContent = readFile(uri.fsPath);

const configs = parseOEFile(allFileContent, uri.fsPath);
Expand Down
32 changes: 17 additions & 15 deletions src/treeview/DbConnectionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class DbConnectionNode implements INode {
id: string,
config: IConfig,
refreshCallback: IRefreshCallback,
private context: vscode.ExtensionContext
private context: vscode.ExtensionContext
) {
this.id = id;
this.config = config;
Expand All @@ -44,14 +44,14 @@ export class DbConnectionNode implements INode {

private iconChooser() {
switch (this.config.conStatus) {
case ConnectionStatus.Connected:
return 'progress_icon.svg';
case ConnectionStatus.NotConnected:
return 'progress_icon_stop.svg';
case ConnectionStatus.Connecting:
return 'loading.gif';
default:
return 'progress_icon_stop.svg';
case ConnectionStatus.Connected:
return 'progress_icon.svg';
case ConnectionStatus.NotConnected:
return 'progress_icon_stop.svg';
case ConnectionStatus.Connecting:
return 'loading.gif';
default:
return 'progress_icon_stop.svg';
}
}

Expand All @@ -60,7 +60,7 @@ export class DbConnectionNode implements INode {
}

public async deleteConnection(context: vscode.ExtensionContext) {
//TODO fix and move to someplace else
//TODO fix and move to someplace else

let connections = context.globalState.get<{ [id: string]: IConfig }>(
'pro-bro.dbconfig'
Expand Down Expand Up @@ -107,13 +107,13 @@ export class DbConnectionNode implements INode {

if (this.id) {
let connections = this.context.globalState.get<{
[id: string]: IConfig;
}>(`${Constants.globalExtensionKey}.dbconfig`);
[id: string]: IConfig;
}>(`${Constants.globalExtensionKey}.dbconfig`);

if (connections && !connections[this.id]) {
connections = this.context.workspaceState.get<{
[id: string]: IConfig;
}>(`${Constants.globalExtensionKey}.dbconfig`);
[id: string]: IConfig;
}>(`${Constants.globalExtensionKey}.dbconfig`);
}
if (connections) {
return connections[this.id];
Expand Down Expand Up @@ -167,7 +167,9 @@ export class DbConnectionNode implements INode {
console.log(`stdout: ${data}`);
});

child.on('error', (error) => console.log('child process error: \n', error));
child.on('error', (error) =>
console.log('child process error: \n', error)
);

// Listen for the process exit event
child.on('exit', (code) => {
Expand Down
17 changes: 17 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ISettings } from "../common/IExtensionSettings";
import { IOETableData } from "../db/Oe";
import { IConfig } from "../view/app/model";
import { VSCode } from "../view/app/utils/vscode";

declare global {
interface Window {
acquireVsCodeApi: () => VSCode;
configuration: ISettings;
initialData: IConfig;
tableData: IOETableData;
tableName: string;
isReadOnly: boolean;
}
}

export {};
14 changes: 10 additions & 4 deletions src/view/app/Connection/connectionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FileUploadRoundedIcon from '@mui/icons-material/FileUploadRounded';
import { PfParser } from '../utils/PfParser';
import { Logger } from '../../../common/Logger';
import { ISettings } from '../../../common/IExtensionSettings';
import { getVSCodeAPI } from '@utils/vscode';
import { getVSCodeAPI, getVSCodeConfiguration } from '@utils/vscode';

interface IConfigProps {
initialData: IConfig;
Expand All @@ -17,7 +17,12 @@ interface IConfigState {
config: IConfig;
}

function ConnectionForm({ initialData, configuration, ...props}: IConfigProps) {
function ConnectionForm({
initialData,
configuration,
...props
}: IConfigProps) {
const vsConfiguration = getVSCodeConfiguration();
const vscode = getVSCodeAPI();
const oldState = vscode.getState();
const initState = oldState ? oldState : { config: initialData };
Expand Down Expand Up @@ -57,8 +62,9 @@ function ConnectionForm({ initialData, configuration, ...props}: IConfigProps) {
params: params,
connectionId: vsState.config.connectionId,
type: vsState.config.type,
isReadOnly: params.includes('-RO'),
isReadOnly: params.includes('-RO') || vsConfiguration.readOnlyMode,
};
console.warn('onSaveClick config', config);
const command: ICommand = {
id: id,
action: CommandAction.Save,
Expand Down Expand Up @@ -109,7 +115,7 @@ function ConnectionForm({ initialData, configuration, ...props}: IConfigProps) {
params: params,
connectionId: vsState.config.connectionId,
type: vsState.config.type,
isReadOnly: params.includes('-RO'),
isReadOnly: params.includes('-RO') || vsConfiguration.readOnlyMode,
};
const command: ICommand = {
id: id,
Expand Down
9 changes: 6 additions & 3 deletions src/view/app/Fields/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ function Fields() {
setCellSelected={props.setCellSelected}
filters={filters}
setFilters={setFilters}
configuration={configuration}
/>
configuration={configuration}
/>
);
};
});
Expand Down Expand Up @@ -157,7 +157,10 @@ function Fields() {
enabled: true,
});

if (message.data.selectedColumns.length === 0 && message.data.selectedColumns === undefined) {
if (
message.data.selectedColumns.length === 0 &&
message.data.selectedColumns === undefined
) {
setSelectedRows(
(): ReadonlySet<number> =>
new Set(
Expand Down
7 changes: 0 additions & 7 deletions src/view/app/Fields/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { createRoot } from 'react-dom/client';
import './fields.css';
import Fields from './fields';
import { VSCode } from '@utils/vscode';

declare global {
interface Window {
acquireVsCodeApi(): VSCode;
}
}

const root = createRoot(document.getElementById('root'));
root.render(<Fields />);
9 changes: 0 additions & 9 deletions src/view/app/Indexes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { createRoot } from 'react-dom/client';
import './indexes.css';
import Indexes from './indexes';
import { ISettings } from '@src/common/IExtensionSettings';
import { VSCode } from '@utils/vscode';

declare global {
interface Window {
acquireVsCodeApi(): VSCode;
configuration: ISettings;
}
}

const root = createRoot(document.getElementById('root'));
root.render(<Indexes />);
4 changes: 1 addition & 3 deletions src/view/app/Query/Update/update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ const UpdatePopup: React.FC<UpdatePopupProps> = ({
setOpen(false);
updateRecord();
}}
disabled={
isReadOnly === true ? true : false
}
disabled = {isReadOnly}
>
UPDATE
</ProBroButton>
Expand Down
4 changes: 3 additions & 1 deletion src/view/app/Query/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ function QueryForm({ tableData, tableName, isReadOnly }: IConfigProps) {
processBooleanFields(message.data.columns, message.data.rawData);

if (message.data.rawData === undefined) {
logger.log('message.data.rawData in query.tsx handleData() is undefined');
logger.log(
'message.data.rawData in query.tsx handleData() is undefined'
);
return;
}
setRawRows([...rawRows, ...message.data.rawData]);
Expand Down
8 changes: 8 additions & 0 deletions src/view/app/utils/PfParser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IConfig } from '../model';
import { getVSCodeConfiguration } from './vscode';

export class PfParser {
private readonly configuration = getVSCodeConfiguration();

public parse(pfFile: string): IConfig {
const config: IConfig = {
id: 'connection',
Expand Down Expand Up @@ -36,6 +39,11 @@ export class PfParser {
'-crTXDisplay',
'-Sn',
];
if (this.configuration) {
if (this.configuration.readOnlyMode) {
config.isReadOnly = true;
}
}

pfFile
.split('\n')
Expand Down
8 changes: 4 additions & 4 deletions src/view/app/utils/vscode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ICommand } from '@app/model';
import { ISettings } from '@src/common/IExtensionSettings';
import { ISettings } from '../../../common/IExtensionSettings';
import { ICommand } from '../model';

/**
* Active interface for vscode api variable
Expand All @@ -10,8 +10,8 @@ export interface VSCode {
setState(state: any): void;
}

let vsCodeAPI: VSCode = undefined;
let configuration: ISettings = undefined;
let vsCodeAPI: VSCode;
let configuration: ISettings;

/**
* method that returns the vsCodeAPI
Expand Down
Loading