diff --git a/README.md b/README.md index 181fe04..700c665 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ haoide-vscode is migrated from haoide, more and more features will be delivered in the next months. ## Installation -You can install ``haoide-vscode`` extension by searching ``haoide-vscode`` in the vscode marketplace. +You can install [haoide-vscode](https://marketplace.visualstudio.com/items?itemName=mouseliu.haoide-vscode) extension by searching ``haoide-vscode`` in the vscode marketplace. ## Usage diff --git a/package.json b/package.json index 59ffb56..3250380 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "publisher": "mouseliu", "repository": "https://github.com/xjsender/haoide-vscode", "description": "haoide-vscode is a vscode extension for force.com development", - "version": "0.1.2", + "version": "0.1.3", "engines": { "vscode": "^1.35.0" }, @@ -84,6 +84,11 @@ "title": "%extension.haoide.updateProject.title%", "category": "Haoide" }, + { + "command": "extension.haoide.updateUserLanguage", + "title": "%extension.haoide.updateUserLanguage.title%", + "category": "Haoide" + }, { "command": "extension.haoide.retrieveThisFromServer", "title": "%extension.haoide.retrieveThisFromServer.title%", @@ -173,10 +178,15 @@ { "command": "extension.haoide.createNewProject", "when": "haoide.hasOpenProject" - },{ + }, + { "command": "extension.haoide.updateProject", "when": "haoide.hasOpenProject" }, + { + "command": "extension.haoide.updateUserLanguage", + "when": "haoide.hasOpenProject" + }, { "command": "extension.haoide.retrieveThisFromServer", "when": "haoide.hasOpenProject" @@ -239,6 +249,13 @@ "win": "ctrl+alt+e", "linux": "ctrl+alt+e" }, + { + "command": "extension.haoide.updateUserLanguage", + "key": "alt+u", + "mac": "alt+u", + "win": "alt+u", + "linux": "alt+u" + }, { "command": "extension.haoide.retrieveThisFromServer", "key": "ctrl+alt+r", diff --git a/package.nls.json b/package.nls.json index 75c87c1..3d995fc 100644 --- a/package.nls.json +++ b/package.nls.json @@ -12,6 +12,7 @@ "extension.haoide.describeMetadata.title": "Describe Metadata", "extension.haoide.createNewProject.title": "Create New Project", "extension.haoide.updateProject.title": "Update Project", + "extension.haoide.updateUserLanguage.title": "Update User Language", "extension.haoide.retrieveThisFromServer.title": "Retrieve This File From Server", "extension.haoide.retrieveOpenFilesFromServer.title": "Retrieve Open File From Server", "extension.haoide.deployThisToServer.title": "Deploy This Files to Server", diff --git a/src/commands/auth.ts b/src/commands/auth.ts index ce63399..78348d6 100644 --- a/src/commands/auth.ts +++ b/src/commands/auth.ts @@ -7,7 +7,7 @@ import * as vscode from "vscode"; import * as util from "../utils/util"; import OAuth from "../salesforce/lib/auth/oauth"; import { startLogin, startServer } from "../salesforce/lib/auth/server"; -import { projectSession } from "../settings"; +import { _session } from "../settings"; import * as nls from 'vscode-nls'; import ProgressNotification from "../utils/progress"; import { any } from "bluebird"; @@ -73,16 +73,16 @@ export async function authorizeNewProject(projectName?: string, loginUrl?: strin * @returns Promise */ export function authorizeDefaultProject() { - let session = projectSession.getSession(); - let oauth = new OAuth(session["loginUrl"]); + let session = _session.getSession(); + let oauth = new OAuth(session.instanceUrl); return ProgressNotification.showProgress( oauth, "refreshToken", { - refresh_token: session["refreshToken"] + refresh_token: session.refreshToken } ) .then( body => { - projectSession.setSessionId(body["access_token"]); + _session.setSessionId(body["access_token"]); // Add project to workspace let projectName = util.getDefaultProject(); @@ -102,8 +102,7 @@ export function authorizeDefaultProject() { // Refresh token expired, start new authorization authorizeNewProject( - session["projectName"], - session["loginUrl"] + session.projectName, session.loginUrl ); } }); diff --git a/src/commands/main.ts b/src/commands/main.ts index 0b71c12..a55233a 100644 --- a/src/commands/main.ts +++ b/src/commands/main.ts @@ -5,6 +5,7 @@ import * as vscode from "vscode"; import * as _ from "lodash"; +import * as nls from 'vscode-nls'; import * as util from "../utils/util"; import * as utility from "./utility"; import * as packages from "../utils/package"; @@ -14,18 +15,45 @@ import MetadataApi from "../salesforce/api/metadata"; import ApexApi from "../salesforce/api/apex"; import RestApi from "../salesforce/api/rest"; import ProgressNotification from "../utils/progress"; -import { projectSettings, metadata } from "../settings"; -import * as nls from 'vscode-nls'; +import { _session, settings, metadata } from "../settings"; const localize = nls.loadMessageBundle(); +/** + * Update user language as your chosen + */ +export async function updateUserLanguage() { + // Let user to choose language + let chosenItem: any = await vscode.window.showQuickPick( + _.map(settings.getUserLanguages(), (v, k) => { + return { + label: v, + description: k + }; + }) + ); + + let restApi = new RestApi(); + ProgressNotification.showProgress(restApi, "patch", { + "serverUrl": "/sobjects/User/" + _session.getUserId(), + "data": { + "LanguageLocaleKey": chosenItem.label + } + }) + .then( body => { + vscode.window.showInformationMessage( + `Your lanaguage is updated to ${chosenItem.description}` + ); + }); +} + export function executeRestTest() { // Get selection in the active editor let editor = vscode.window.activeTextEditor; if (!editor) { return util.showCommandWarning(); } - + let serverUrl = ""; if (editor.selection) { serverUrl = editor.document.getText(editor.selection); @@ -59,7 +87,7 @@ export function executeQuery() { } let restApi = new RestApi(); - ProgressNotification.showRESTProgress(restApi, "query", { + ProgressNotification.showProgress(restApi, "query", { soql: soql }) .then( body => { @@ -83,7 +111,7 @@ export async function reloadSobjectCache(sobjects?: string[]) { // If sobjects is not specified, describe global if (!sobjects || sobjects.length === 0) { - return ProgressNotification.showRESTProgress( + return ProgressNotification.showProgress( restApi, "describeGlobal", {} ) .then( body => { @@ -293,7 +321,7 @@ export function refreshThisFromServer() { // Send get request let restApi = new RestApi(); - ProgressNotification.showRESTProgress(restApi, "query", { + ProgressNotification.showProgress(restApi, "query", { serverUrl: `/${filep["id"]}` }) .then( body => { @@ -373,7 +401,7 @@ export function updateProject() { * Create new project based on subscribed metadata objects */ export function createNewProject() { - let subscribedMetaObjects = projectSettings.getSubscribedMetaObjects(); + let subscribedMetaObjects = settings.getSubscribedMetaObjects(); // If there is no subscribed metaObjects, so subscribe first if (!subscribedMetaObjects || subscribedMetaObjects.length === 0) { diff --git a/src/commands/utility.ts b/src/commands/utility.ts index 7e42d11..73fd799 100644 --- a/src/commands/utility.ts +++ b/src/commands/utility.ts @@ -7,9 +7,10 @@ import * as vscode from "vscode"; import * as xmlParser from "fast-xml-parser"; import * as _ from "lodash"; import * as util from "../utils/util"; -import * as settingsUtil from "../settings/settingsUtil"; -import { projectSettings, projectSession, metadata } from "../settings"; import * as nls from 'vscode-nls'; +import * as settingsUtil from "../settings/settingsUtil"; +import SessionModel from "../models/session"; +import { settings, _session, metadata } from "../settings"; const localize = nls.loadMessageBundle(); @@ -25,7 +26,7 @@ export function toggleMetadataObjects() { let metaObjects = _.sortBy(metadataObjects, mo => mo.xmlName); // Get already subscribed meta objects - let subscribedMetaObjects = projectSettings.getSubscribedMetaObjects(); + let subscribedMetaObjects = settings.getSubscribedMetaObjects(); return vscode.window.showQuickPick( _.map(metaObjects, mo => { @@ -130,10 +131,10 @@ export function locateThisInBrowser() { * @param startUrl? Redirect url after login */ export function loginToSFDC(startUrl?: string) { - let session = projectSession.getSession(); + let sess: SessionModel = _session.getSession(); - let open_url = `${session["instanceUrl"]}/secur/frontdoor.jsp` + - `?sid=${session["sessionId"]}`; + let open_url = `${sess.instanceUrl}/secur/frontdoor.jsp` + + `?sid=${sess.sessionId}`; if (startUrl) { open_url += "&retURL=" + startUrl; @@ -146,10 +147,10 @@ export function loginToSFDC(startUrl?: string) { * Command for copying loginUrl to clipboard */ export function copyLoginUrl() { - let session = projectSession.getSession(); + let sess: SessionModel = _session.getSession(); - let loginUrl = `${session["instanceUrl"]}/secur/frontdoor.jsp` + - `?sid=${session["sessionId"]}`; + let loginUrl = `${sess.instanceUrl}/secur/frontdoor.jsp` + + `?sid=${sess.sessionId}`; // Write loginUrl to clipboard vscode.env.clipboard.writeText(loginUrl); diff --git a/src/extension.ts b/src/extension.ts index 759f027..987eae5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -38,6 +38,12 @@ export function activate(context: vscode.ExtensionContext) { "extension.haoide.updateProject", main.updateProject )); + // Register updateUserLanguage command + context.subscriptions.push(vscode.commands.registerCommand( + "extension.haoide.updateUserLanguage", + main.updateUserLanguage + )); + // Register createNewProject command context.subscriptions.push(vscode.commands.registerCommand( "extension.haoide.createNewProject", main.createNewProject diff --git a/src/models/session.ts b/src/models/session.ts new file mode 100644 index 0000000..fe51c6a --- /dev/null +++ b/src/models/session.ts @@ -0,0 +1,10 @@ +export default interface Session { + orgnizationId: string; + userId: string; + sessionId: string; + refreshToken: string; + instanceUrl: string; + loginUrl: string; + projectName: string; + lastUpdatedTime: string; +} \ No newline at end of file diff --git a/src/salesforce/api/apex.ts b/src/salesforce/api/apex.ts index c313f54..1262d99 100644 --- a/src/salesforce/api/apex.ts +++ b/src/salesforce/api/apex.ts @@ -8,7 +8,7 @@ import * as xmlParser from "fast-xml-parser"; import * as auth from "../../commands/auth"; import SOAP from "../lib/soap"; import ProgressNotification from "../../utils/progress"; -import { projectSession } from "../../settings"; +import { _session } from "../../settings"; export default class ApexApi { private soap!: SOAP; @@ -24,7 +24,7 @@ export default class ApexApi { } private initiate(sessionInfo?: any) { - this.session = sessionInfo || projectSession.getSession(); + this.session = sessionInfo || _session.getSession(); this.sessionId = this.session["sessionId"]; this.instanceUrl = this.session["instanceUrl"]; this.apiVersion = this.session["apiVersion"] || 46; diff --git a/src/salesforce/api/metadata.ts b/src/salesforce/api/metadata.ts index af1e123..9dfb828 100644 --- a/src/salesforce/api/metadata.ts +++ b/src/salesforce/api/metadata.ts @@ -9,7 +9,7 @@ import * as auth from "../../commands/auth"; import * as util from "../../utils/util"; import SOAP from "../lib/soap"; import ProgressNotification from "../../utils/progress"; -import { projectSession, projectSettings } from "../../settings"; +import { _session, settings } from "../../settings"; export default class MetadataApi { private soap!: SOAP; @@ -25,7 +25,7 @@ export default class MetadataApi { } private initiate(session?: any) { - this.session = session || projectSession.getSession(); + this.session = session || _session.getSession(); this.sessionId = this.session["sessionId"]; this.instanceUrl = this.session["instanceUrl"]; this.apiVersion = this.session["apiVersion"] || 46; @@ -255,7 +255,7 @@ export default class MetadataApi { "requestType": "Deploy", "zipfile": zipfile, "testClasses": testClasses, - "deployOptions": projectSettings.getDeployOptions() + "deployOptions": settings.getDeployOptions() }; ProgressNotification.showProgress(self, "_invoke_method", options) diff --git a/src/salesforce/api/rest.ts b/src/salesforce/api/rest.ts index 1398cc8..8f4af88 100644 --- a/src/salesforce/api/rest.ts +++ b/src/salesforce/api/rest.ts @@ -8,7 +8,7 @@ import * as request from "request-promise"; import * as auth from "../../commands/auth"; import * as querystring from "querystring"; import ProgressNotification from "../../utils/progress"; -import { projectSession } from "../../settings"; +import { _session } from "../../settings"; export default class RestApi { private session: any; @@ -27,7 +27,7 @@ export default class RestApi { } private initiate(session?: any) { - this.session = session || projectSession.getSession(); + this.session = session || _session.getSession(); this.sessionId = this.session["sessionId"]; this.instanceUrl = this.session["instanceUrl"]; this.apiVersion = this.session["apiVersion"] || 46; @@ -76,7 +76,7 @@ export default class RestApi { headers: self.headers, uri: self.buildFullUrl(options.serverUrl), body: options.data, - json: true + json: options.json || true }; // Send notification @@ -90,6 +90,7 @@ export default class RestApi { options.progress, `${options.method} is finished`, 100 ); + console.log(body); resolve(body); }) .catch(err => { diff --git a/src/salesforce/completions/provider/sobjectCompletionProvider.ts b/src/salesforce/completions/provider/sobjectCompletionProvider.ts index 300cd53..f2fd5d9 100644 --- a/src/salesforce/completions/provider/sobjectCompletionProvider.ts +++ b/src/salesforce/completions/provider/sobjectCompletionProvider.ts @@ -40,7 +40,7 @@ export class SobjectCompletionItemProvider implements vscode.CompletionItemProvi if (enableDebugMode) { console.log(pos); } - + // Initiate completion list let completionItems: CompletionItem[] = []; diff --git a/src/salesforce/lib/auth/server.ts b/src/salesforce/lib/auth/server.ts index c3f5bb2..3d70f62 100644 --- a/src/salesforce/lib/auth/server.ts +++ b/src/salesforce/lib/auth/server.ts @@ -14,7 +14,7 @@ import * as util from "../../../utils/util"; import * as contextUtil from "../../../utils/context"; import MetadataApi from "../../api/metadata"; import OAuth from "./oauth"; -import { projectSession, metadata } from "../../../settings"; +import { _session, metadata } from "../../../settings"; const localize = nls.loadMessageBundle(); @@ -59,7 +59,7 @@ export function startServer(projectName: any, loginUrl: string) { "projectName": projectName, "lastUpdatedTime": moment().format() }; - projectSession.setSession(session); + _session.setSession(session); // Describe metadata new MetadataApi(session).describeMetadata({}) diff --git a/src/settings/index.ts b/src/settings/index.ts index 9632199..777b73b 100644 --- a/src/settings/index.ts +++ b/src/settings/index.ts @@ -1,9 +1,9 @@ -import ProjectSettings from './settings'; +import Settings from './settings'; import ExtensionSettings from './extension'; -import ProjectSession from './session'; +import Session from './session'; import Metadata from './metadata'; export const extensionSettings = ExtensionSettings.getInstance(); -export const projectSettings = ProjectSettings.getInstance(); -export const projectSession = ProjectSession.getInstance(); +export const settings = Settings.getInstance(); +export const _session = Session.getInstance(); export const metadata = Metadata.getInstance(); \ No newline at end of file diff --git a/src/settings/session.ts b/src/settings/session.ts index eb3d565..6278994 100644 --- a/src/settings/session.ts +++ b/src/settings/session.ts @@ -5,19 +5,20 @@ import * as moment from "moment"; import * as settingsUtil from "./settingsUtil"; +import SessionModel from "../models/session"; -export default class ProjectSession { - private static instance: ProjectSession; +export default class Session { + private static instance: Session; private sessionFileName = "session.json"; public static getInstance() { - if (!ProjectSession.instance) { - ProjectSession.instance = new ProjectSession(); + if (!Session.instance) { + Session.instance = new Session(); } - return ProjectSession.instance; + return Session.instance; } - public getSession(): any { + public getSession(): SessionModel { return settingsUtil.getConfig(this.sessionFileName); } @@ -44,4 +45,13 @@ export default class ProjectSession { "lastUpdatedTime": moment().format() }); } + + /** + * Get userId in the session cache + * + * @returns userId in the session cache + */ + public getUserId() { + return this.getSession().userId; + } } \ No newline at end of file diff --git a/src/settings/settings.ts b/src/settings/settings.ts index 3c4140e..787c479 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -5,15 +5,15 @@ import * as settingsUtil from "./settingsUtil"; -export default class ProjectSettings { - private static instance: ProjectSettings; +export default class Settings { + private static instance: Settings; private settingsFileName = "settings.json"; public static getInstance() { - if (!ProjectSettings.instance) { - ProjectSettings.instance = new ProjectSettings(); + if (!Settings.instance) { + Settings.instance = new Settings(); } - return ProjectSettings.instance; + return Settings.instance; } /** @@ -67,8 +67,7 @@ export default class ProjectSettings { */ public getDeployOptions() { let deployOptions = settingsUtil.getConfigValue( - this.settingsFileName, - "deployOptions" + this.settingsFileName, "deployOptions" ); if (!deployOptions) { @@ -88,4 +87,34 @@ export default class ProjectSettings { return deployOptions; } + + public getUserLanguages() { + let userLanguages = settingsUtil.getConfigValue( + this.settingsFileName, "userLanguages" + ); + + if (!userLanguages) { + userLanguages = { + "Chinese (Simplified)": "zh_CN", + "Chinese (Traditional)": "zh_TW", + "Danish": "da", + "Dutch": "nl_NL", + "English": "en_US", + "Finnish": "fi", + "French": "fr", + "German": "de", + "Italian": "it", + "Japanese": "ja", + "Korean": "ko", + "Portuguese (Brazil)": "pt_BR", + "Russian": "ru", + "Spanish": "es", + "Spanish (Mexico)": "es_MX", + "Swedish": "sv", + "Thai": "th" + }; + } + + return userLanguages; + } } \ No newline at end of file diff --git a/src/utils/util.ts b/src/utils/util.ts index e584461..af35b17 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -216,7 +216,7 @@ export function getExtensionWorkspace() { /** * Get all authorized projects at homedir/.haoide/config.json * - * @returns {projectName: default} + * @returns projects, k-v json as projectName: default */ export function getProjects() { try {