Skip to content

Commit 06e7e50

Browse files
committed
feat: add VSCode workspace download link
Also tweaks some styling and fixes behavior for interop-enabled namespaces with a URLPrefix.
1 parent 68224aa commit 06e7e50

File tree

9 files changed

+108
-12
lines changed

9 files changed

+108
-12
lines changed

cls/SourceControl/Git/StreamServer.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Class SourceControl.Git.StreamServer Extends %CSP.StreamServer
77
ClassMethod OnPage() As %Status
88
{
99
if (%stream '= $$$NULLOREF) && $data(%base)#2 {
10-
set sourceControlInclude = ##class(SourceControl.Git.Utils).GetSourceControlInclude()
10+
set sourceControlInclude = ##class(SourceControl.Git.Utils).GetSourceControlInclude(%request.URLPrefix)
1111
while '%stream.AtEnd {
1212
set text = %stream.Read()
1313
set text = $replace(text,"{{baseHref}}",..EscapeHTML(%base))
@@ -19,4 +19,3 @@ ClassMethod OnPage() As %Status
1919
}
2020

2121
}
22-

cls/SourceControl/Git/Utils.cls

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,10 +2403,10 @@ ClassMethod GetPackageVersion() As %String [ CodeMode = objectgenerator ]
24032403
quit $$$OK
24042404
}
24052405

2406-
ClassMethod GetSourceControlInclude() As %String
2406+
ClassMethod GetSourceControlInclude(prefix As %String = "") As %String
24072407
{
24082408
quit $select(##class(%Library.EnsembleMgr).IsEnsembleInstalled():
2409-
"<script type=""text/javascript"" src=""/isc/studio/templates/ensemble/Ens_SourceControl.js""></script>",
2409+
"<script type=""text/javascript"" src="""_prefix_"/isc/studio/templates/ensemble/Ens_SourceControl.js""></script>",
24102410
1: "")
24112411
}
24122412

@@ -2622,4 +2622,3 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
26222622
}
26232623

26242624
}
2625-

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,67 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
2727
if $isobject($get(responseJSON)) {
2828
do responseJSON.%ToJSON(%data)
2929
}
30+
} elseif pathStart = "vscode-workspace" {
31+
set handled = 1
32+
set namespace = $Namespace
33+
set instanceName = $ZConvert(##class(%SYS.System).InstanceGUID(),"L")
34+
set hasCSP = 0
35+
if (InternalName = "") || context.IsInDefaultPackage {
36+
set hasCSP = ##class(SourceControl.Git.Settings).HasNamespaceWebApp()
37+
set workspaceFilename = namespace_"-"_instanceName_"-.code-workspace"
38+
set filter = "?mapped=0"
39+
} elseif context.IsInGitEnabledPackage {
40+
set workspaceFilename = context.Package.Name_"-"_instanceName_".code-workspace"
41+
// Loading an IPM package in dev mode automatically creates a project for it, so filter to that.
42+
set filter = "?project="_context.Package.Name
43+
} else {
44+
// TODO: Error? But really shouldn't happen.
45+
quit
46+
}
47+
set server = {
48+
"webServer": {
49+
"host": (%request.CgiEnvs("SERVER_NAME")),
50+
"port": (%request.CgiEnvs("SERVER_PORT")),
51+
"scheme": ($Select(%request.Secure:"https",1:"http"))
52+
},
53+
"username": ($Username)
54+
}
55+
if (%request.URLPrefix '= "") {
56+
set server.webServer.pathPrefix = %request.URLPrefix
57+
}
58+
set workspaceDef = {
59+
"folders": [
60+
{
61+
"name": ($Namespace),
62+
"uri": ("isfs://"_instanceName_":"_$Namespace_"/"_filter)
63+
}
64+
],
65+
"settings": {
66+
"intersystems.servers": {
67+
"/default": (instanceName)
68+
},
69+
"objectscript.conn": {
70+
"active": false
71+
}
72+
}
73+
}
74+
if hasCSP {
75+
do workspaceDef.folders.%Push({
76+
"name": ($Namespace_" (Filesystem)"),
77+
"uri": ("isfs://"_instanceName_":"_$Namespace_"/git/"_$Namespace_"?csp")
78+
})
79+
}
80+
set $Property(workspaceDef.settings."intersystems.servers",instanceName) = server
81+
set stream = ##class(%CSP.CharacterStream).%New()
82+
do stream.SetAttribute("ContentDisposition","attachment; filename="_workspaceFilename)
83+
set formatter = ##class(%JSON.Formatter).%New()
84+
do formatter.FormatToStream(workspaceDef,stream)
85+
$$$ThrowOnError(stream.%Save())
86+
do %request.Set("STREAMOID",##class(%CSP.Page).Encrypt(stream.%Oid()))
87+
set %request.Data("EXPIRES",1,"encrypt") = 1
88+
do %request.Set("EXPIRES",0)
89+
do ##class(%CSP.StreamServer).OnPreHTTP() // Need to call this to set headers properly
90+
set %stream = 1 // Leak this to webuidriver.csp
3091
} elseif $match(pathStart,"git-command|git|dirname|hostname|viewonly|contexts") {
3192
if (%request.Method = "GET") {
3293
set %data = ##class(%Stream.TmpCharacter).%New()

git-webui/release/share/git-webui/webui/css/git-webui.css

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ body {
183183
padding-bottom: 100px;
184184
}
185185
#sidebar #sidebar-content > :first-child,
186-
#sidebar #sidebar-content > :nth-last-child(2) {
186+
#sidebar #sidebar-content > :nth-last-child(3) {
187187
border-top: 1px solid #5e5e5e;
188188
}
189189
#sidebar #sidebar-content h4:before {
@@ -216,12 +216,26 @@ body {
216216
#sidebar #sidebar-content #sidebar-tags h4:before {
217217
content: url(../img/tag.svg);
218218
}
219+
#sidebar #sidebar-content #sidebar-vscode a {
220+
color: white;
221+
}
222+
#sidebar #sidebar-content #sidebar-vscode h4:before {
223+
content: url(../img/file.svg);
224+
}
225+
#sidebar #sidebar-content #sidebar-vscode {
226+
position: absolute;
227+
bottom: 80px;
228+
width: 16.7em;
229+
padding-bottom: 0.3rem;
230+
margin-bottom: 0;
231+
background-color: #333333;
232+
}
219233
#sidebar #sidebar-content #sidebar-context h4:before {
220234
content: url(../img/context.svg);
221235
}
222236
#sidebar #sidebar-content #sidebar-context {
223237
position: absolute;
224-
bottom: 50px;
238+
bottom: 40px;
225239
width: 16.7em;
226240
padding-bottom: 0.3rem;
227241
margin-bottom: 0;
Lines changed: 1 addition & 1 deletion
Loading

git-webui/release/share/git-webui/webui/js/git-webui.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
973973
'<section id="sidebar-tags">' +
974974
'<h4>Tags</h4>' +
975975
'</section>' +
976+
'<section id="sidebar-vscode">' +
977+
'<h4><a href="vscode-workspace" target="_blank">Code Workspace</a></h4>' +
978+
'</section>' +
976979
'<section id="sidebar-context" data-toggle="tooltip" data-placement="right" title="' + self.currentContext + '">' +
977980
'<h4>Change Context</h4>' +
978981
'</section>' +

git-webui/src/share/git-webui/webui/css/git-webui.less

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ body {
257257
color: @gray-lighter;
258258
padding-bottom: 100px;
259259

260-
> :first-child, >:nth-last-child(2) {
260+
> :first-child, >:nth-last-child(3) {
261261
border-top: 1px solid darken(@separator-line, 50%);
262262
}
263263

@@ -301,13 +301,30 @@ body {
301301
content: url(../img/tag.svg);
302302
}
303303

304+
#sidebar-vscode a {
305+
color: white;
306+
}
307+
308+
#sidebar-vscode h4:before {
309+
content: url(../img/file.svg);
310+
}
311+
312+
#sidebar-vscode {
313+
position: absolute;
314+
bottom: 80px;
315+
width: 16.7em;
316+
padding-bottom: 0.3rem;
317+
margin-bottom: 0;
318+
background-color: rgba(51, 51, 51, 1);
319+
}
320+
304321
#sidebar-context h4:before {
305-
content: url(../img/context.svg)
322+
content: url(../img/context.svg);
306323
}
307324

308325
#sidebar-context {
309326
position: absolute;
310-
bottom: 50px;
327+
bottom: 40px;
311328
width: 16.7em;
312329
padding-bottom: 0.3rem;
313330
margin-bottom: 0;
Lines changed: 1 addition & 1 deletion
Loading

git-webui/src/share/git-webui/webui/js/git-webui.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
973973
'<section id="sidebar-tags">' +
974974
'<h4>Tags</h4>' +
975975
'</section>' +
976+
'<section id="sidebar-vscode">' +
977+
'<h4><a href="vscode-workspace" target="_blank">Code Workspace</a></h4>' +
978+
'</section>' +
976979
'<section id="sidebar-context" data-toggle="tooltip" data-placement="right" title="' + self.currentContext + '">' +
977980
'<h4>Change Context</h4>' +
978981
'</section>' +

0 commit comments

Comments
 (0)