Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/server_settings #1805

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
6 changes: 4 additions & 2 deletions src/api/CustomUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ export class Section {
return this;
}

addCheckbox(id: string, label: string, description?: string, checked?: boolean) {
addCheckbox(id: string, label: string, description?: string, checked?: boolean, readonly: boolean = false) {
const checkbox = new Field('checkbox', id, label, description);
checkbox.default = checked ? 'checked' : '';
checkbox.readonly = readonly;
this.addField(checkbox);
return this;
}
Expand Down Expand Up @@ -99,9 +100,10 @@ export class Section {
return this;
}

addSelect(id: string, label: string, items: SelectItem[], description?: string) {
addSelect(id: string, label: string, items: SelectItem[], description?: string, readonly = false) {
const select = new Field('select', id, label, description);
select.items = items;
select.readonly = readonly;
this.addField(select);
return this;
}
Expand Down
50 changes: 46 additions & 4 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface MemberParts extends IBMiMember {
basename: string
}

const SERVER_SETTINGS_PATH = `/.vscode/connections.json`;
worksofliam marked this conversation as resolved.
Show resolved Hide resolved

let remoteApps = [ // All names MUST also be defined as key in 'remoteFeatures' below!!
{
path: `/usr/bin/`,
Expand Down Expand Up @@ -54,6 +56,8 @@ export default class IBMi {
remoteFeatures: { [name: string]: string | undefined };
variantChars: { american: string, local: string };
lastErrors: object[];

loadedServerSettings: string[];
config?: ConnectionConfiguration.Parameters;

commandsExecuted: number = 0;
Expand Down Expand Up @@ -108,6 +112,7 @@ export default class IBMi {
* */
this.lastErrors = [];

this.loadedServerSettings = [];
}

/**
Expand Down Expand Up @@ -157,13 +162,20 @@ export default class IBMi {
};
};

if (!reconnecting) {
instance.setConnection(this);
}

progress.report({
message: `Loading configuration.`
});

//Load existing config
this.config = await ConnectionConfiguration.load(this.currentConnectionName);

//Check and load server settings
await this.loadServerSettings();

// Load cached server settings.
const cachedServerSettings: CachedServerSettings = GlobalStorage.get().getServerSettingsCache(this.currentConnectionName);
// Reload server settings?
Expand Down Expand Up @@ -203,10 +215,6 @@ export default class IBMi {
this.client.connection!.once(`end`, disconnected);
this.client.connection!.once(`error`, disconnected);

if (!reconnecting) {
instance.setConnection(this);
}

progress.report({
message: `Checking home directory.`
});
Expand Down Expand Up @@ -1008,6 +1016,40 @@ export default class IBMi {
vscode.window.showInformationMessage(`Disconnected from ${this.currentHost}.`);
}

async loadServerSettings() {
const content = instance.getContent();

const exists = await content?.testStreamFile(SERVER_SETTINGS_PATH, `r`);
if (exists) {
const settings = await content?.downloadStreamfile(SERVER_SETTINGS_PATH);
if (settings) {
try {
// Ready in the new settings
const asJson = JSON.parse(settings);

// Apply the settings over the top
this.config = {
...this.config,
...asJson
}

// Store the changes locally to be nice
await ConnectionConfiguration.update(this.config!);

// Mark which config is managed by the server
this.loadedServerSettings = Object.keys(asJson);

} catch (e) {
this.appendOutput(`Was not able to read server settings as JSON.\n`);
}
} else {
this.appendOutput(`Failed to load server settings.\n`);
}
} else {
this.appendOutput(`Server settings not found.\n`);
}
}

/**
* Generates path to a temp file on the IBM i
* @param {string} key Key to the temp file to be re-used
Expand Down
Loading