Skip to content

Commit

Permalink
snippets and post tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
od-forsk committed Sep 20, 2024
1 parent f8a5eb3 commit cdccc27
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 7 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
{
"command": "naos.publish",
"group": "inline",
"when": "resourceLangId == json && resourceFilename =~ /\\.project\\.naos$/"
"when": "resourceLangId == json && resourceFilename =~ /\\.(user|team|instance|job|project|workspace|geofile|coverage)\\.naos$/"
}
]
},
Expand Down Expand Up @@ -444,6 +444,12 @@
".naos"
]
}
],
"snippets": [
{
"language": "json",
"path": "./snippets.json"
}
]
},
"scripts": {
Expand Down
75 changes: 75 additions & 0 deletions snippets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"NAOS User": {
"prefix": "user",
"body": [
"{",
" \"login\": \"${1}\",",
" \"name\": \"${2}\",",
" \"email\": \"${3}\",",
" \"is_admin\": ${4|false,true|}$0",
"}"
],
"description": "NAOS User template"
},
"NAOS Team": {
"prefix": "team",
"body": [
"{",
" \"name\": \"${1}\",",
" \"allocated_naos_tokens\": ${2}$0",
"}"
],
"description": "NAOS Team template"
},
"NAOS Instance": {
"prefix": "instance",
"body": [
"{",
" \"parameters\": {${1}},",
" \"name\": \"${2:notneeded}\"$0",
"}"
],
"description": "NAOS instance template"
},
"NAOS Project": {
"prefix": "project",
"body": [
"{",
" \"name\": \"${1:name}\",",
" \"source\": {",
" \"dbname\": \"${2:dbname}\",",
" \"host\": \"${3:host}\",",
" \"port\": ${4:5432},",
" \"schema\": \"${5:public}\",",
" \"type\": \"${6|PostgreSQL,Oracle,MS_SQL_Server,Atl|}\"",
" }$0",
"}"
],
"description": "NAOS Project template"
},
"NAOS Workspace": {
"prefix": "workspace",
"body": [
"{",
" \"name\": \"${1:name}\",",
" \"project_id\": \"${2:project}\"$0",
"}"
],
"description": "NAOS workspace template"
},
"NAOS Job": {
"prefix": "job",
"body": [],
"description": "NAOS job template"
},
"NAOS Geofile": {
"prefix": "geofile",
"body": [],
"description": "NAOS Geofile template"
},
"NAOS Coverage": {
"prefix": "coverage",
"body": [],
"description": "NAOS Coverage template"
}
}
38 changes: 32 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { TeamsProvider, TeamUser } from './treeProviders/TeamsProvider';
import { UsersProvider } from './treeProviders/UsersProvider';
import { sendProject, WorkareasProvider } from './treeProviders/WorkareasProvider';
import { getActiveEditorText, parseNaosURI, uuidValidateV4 } from './utils';
import { NaosInstanceParameters } from './naosclient/models/NaosInstanceParameters';

export let consoleNAOS = vscode.window.createOutputChannel("NAOS-ext", { log: true });

Expand Down Expand Up @@ -233,20 +234,45 @@ export function activate(context: vscode.ExtensionContext) {
}
});

registerNaosCommand("naos.publish", async (uri: vscode.Uri) => {
registerNaosCommand("naos.publish", async () => {
// TODO avoid usage with command palette.
const uri = vscode.window.activeTextEditor?.document.uri;
try {
const [resourceKind, resourceIds] = parseNaosURI(uri);
const [resourceKind, resourceIds] = parseNaosURI(uri!);
let editorText = getActiveEditorText();
switch (resourceKind) {
// TODO case "user":
// TODO case "team":
// TODO case "instance":
case "user":
const user = JSON.parse(editorText) as UserInfo;
if (user.id){
await apiClient.admin.editUser(user.id, user);
} else {
await apiClient.admin.createUser(user);
}
break;
case "team":
const team = JSON.parse(editorText) as GatewayTeam;
if (team.id){
await apiClient.teams.editTeam(team.id, team);
} else {
await apiClient.teams.createTeam(team);
}
break;
case "instance":
const instance = JSON.parse(editorText) as NaosInstanceParameters;
await apiClient.naos.addInstance(instance);
break;
// TODO case "job":
case "project":
await sendProject(editorText, apiClient);
break;
// TODO case "workspace":
case "workspace":
const workspace = JSON.parse(editorText) as Workspace;
if (workspace.id){
await apiClient.workspaces.editWorkspace(workspace.id, undefined, workspace);
} else {
await apiClient.workspaces.createWorkspace(true, workspace);
}
break;
// TODO case "geofile":
// TODO case "coverage":
default:
Expand Down

0 comments on commit cdccc27

Please sign in to comment.