Skip to content

Commit

Permalink
create working, a bit clunky
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellourbani committed Nov 29, 2018
1 parent be4976c commit a2a8221
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 108 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

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

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
"build": "vsce package"
},
"devDependencies": {
"typescript": "^2.6.1",
"vscode": "^1.1.21",
"vsce": "^1.52.0",
"tslint": "^5.8.0",
"@types/node": "^8.10.25",
"@types/mocha": "^2.2.42",
"@types/node": "^8.10.38",
"@types/request": "^2.48.1",
"@types/xml2js": "^0.4.3",
"@types/request": "^2.47.1",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.6.0"
"tsconfig-paths": "^3.7.0",
"tslint": "^5.8.0",
"typescript": "^2.6.1",
"vsce": "^1.52.0",
"vscode": "^1.1.21"
},
"dependencies": {
"request": "^2.88.0",
Expand Down
16 changes: 9 additions & 7 deletions src/abap/AbapObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,18 @@ export class AbapObject {
return this.sapguiOnly ? ".txt" : ".abap"
}

getChildren(
async getChildren(
connection: AdtConnection
): Promise<Array<AbapNodeComponentByCategory>> {
if (this.isLeaf()) throw FileSystemError.FileNotADirectory(this.vsName)
const nodeUri = this.getNodeUri(connection)

return connection
.request(nodeUri, "POST")
.then(pick("body"))
.then(parseNode)
.then(this.filterNodeStructure.bind(this))
.then(aggregateNodes)
const response = await connection.request(nodeUri, "POST")
const nodes = await parseNode(response.body)
const filtered = this.filterNodeStructure(nodes)
const components = aggregateNodes(filtered)

return components
}

protected getNodeUri(connection: AdtConnection): Uri {
Expand All @@ -260,6 +260,8 @@ export class AbapObject {
techName
)}&parent_type=${encodeURIComponent(
this.type
)}&user_name=${encodeURIComponent(
connection.username.toUpperCase()
)}&withShortDescriptions=true`
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/adt/AdtConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class AdtConnection {
readonly url: string
readonly username: string
readonly password: string
//TODO: hack for object creation, needs proper session support and backend cache invalidation
stateful = true
private _csrftoken: string = "fetch"
private _status: ConnStatus = ConnStatus.new
private _listeners: Array<Function> = []
Expand Down Expand Up @@ -75,7 +77,7 @@ export class AdtConnection {
method,
headers: {
"x-csrf-token": this._csrftoken,
"X-sap-adt-sessiontype": "stateful",
"X-sap-adt-sessiontype": this.stateful ? "stateful" : "",
Accept: "*/*",
...headers
}
Expand Down
38 changes: 30 additions & 8 deletions src/adt/AdtServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class AdtServer {
if (file.abapObject.transport === TransportStatus.REQUIRED) {
const transport = await selectTransport(
file.abapObject.getContentsUri(this.connection),
"",
this.connection
)
if (transport) file.abapObject.transport = transport
Expand All @@ -85,11 +86,27 @@ export class AdtServer {
}

findNode(uri: Uri): AbapNode {
// const parts = uriParts(uri)
// return parts.reduce((current: any, name) => {
// if (current && "getChild" in current) return current.getChild(name)
// throw FileSystemError.FileNotFound(uri)
// }, this.root)
return this.findNodeHierarcy(uri)[0]
}

findNodeHierarcy(uri: Uri): AbapNode[] {
const parts = uriParts(uri)
return parts.reduce((current: any, name) => {
if (current && "getChild" in current) return current.getChild(name)
throw FileSystemError.FileNotFound(uri)
}, this.root)
return parts.reduce(
(current: AbapNode[], name) => {
const folder = current[0]
const child = folder.isFolder && folder.getChild(name)
if (!child) throw FileSystemError.FileNotFound(uri)

current.unshift(child)
return current
},
[this.root]
)
}

async findAbapObject(uri: Uri): Promise<AbapObject> {
Expand All @@ -109,15 +126,20 @@ export class AdtServer {

async findNodePromise(uri: Uri): Promise<AbapNode> {
let node: AbapNode = this.root
let refreshable: AbapNode | undefined = node.canRefresh() ? node : undefined
const parts = uriParts(uri)

for (const part of parts) {
let next: AbapNode | undefined = node.getChild(part)
if (!next && node.canRefresh()) {
await node.refresh(this.connection)
if (!next && refreshable) {
//refreshable will tipically be the current node or its first abap parent (usually a package)
await refreshable.refresh(this.connection)
next = node.getChild(part)
}
if (next) node = next
else return Promise.reject(FileSystemError.FileNotFound(uri))
if (next) {
node = next
if (node.canRefresh()) refreshable = node
} else return Promise.reject(FileSystemError.FileNotFound(uri))
}

return node
Expand Down
5 changes: 4 additions & 1 deletion src/adt/AdtTransports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ function throwMessage(msg: ValidateTransportMessage) {
}
export async function getTransportCandidates(
objContentUri: Uri,
devClass: string,
conn: AdtConnection
): Promise<TransportInfo> {
const response = await conn.request(
conn.createUri("/sap/bc/adt/cts/transportchecks"),
"POST",
{
body: JSON2AbapXML({
DEVCLASS: devClass,
URI: objContentUri.path
})
}
Expand Down Expand Up @@ -86,9 +88,10 @@ export async function getTransportCandidates(

export async function selectTransport(
objContentUri: Uri,
devClass: string,
conn: AdtConnection
): Promise<string> {
const ti = await getTransportCandidates(objContentUri, conn)
const ti = await getTransportCandidates(objContentUri, devClass, conn)
if (ti.DLVUNIT === "LOCAL") return ""
const CREATENEW = "Create a new transport"
let selection = await window.showQuickPick([
Expand Down
Loading

0 comments on commit a2a8221

Please sign in to comment.