Skip to content

Commit 1ab0d27

Browse files
authored
Merge pull request #441 from intersystems/sync-webui
Sync webui
2 parents 27fcfdf + f418206 commit 1ab0d27

File tree

4 files changed

+194
-12
lines changed

4 files changed

+194
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
9+
## [2.5.0] - Unreleased
10+
11+
### Added
12+
- New UI for the basic mode Sync (#415)
13+
814
## [2.4.1] - 2024-08-02
915

1016
### Added

cls/SourceControl/Git/Utils.cls

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,8 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
253253
set Action = 7
254254
quit $$$OK
255255
} elseif (menuItemName = "Sync") {
256-
if ..CheckForUncommittedFiles() {
257-
set Target = "Enter a commit message for the sync operation"
258-
set Action = 7
259-
set Msg = ..PreSync()
260-
} else {
261-
set Target = ""
262-
do ..Sync("",.Target)
263-
if (Target '= "") {
264-
set Action = 6
265-
}
266-
}
256+
set Action = 2 + externalBrowser
257+
set Target = urlPrefix _ "/isc/studio/usertemplates/gitsourcecontrol/sync.csp?Namespace="_$NAMESPACE
267258

268259
quit $$$OK
269260
} elseif (menuItemName = "Push") {
@@ -1947,7 +1938,7 @@ ClassMethod GenerateCommitMessageFromFiles(filesWithActions) As %String
19471938
set commitMsg = commitMsg_$LISTBUILD(oneFileMsg)
19481939

19491940
}
1950-
quit $LISTTOSTRING(commitMsg, ",")
1941+
quit $LISTTOSTRING(commitMsg, ", ")
19511942
}
19521943

19531944
ClassMethod GitStatus(ByRef files, IncludeAllFiles = 0)

csp/sync.csp

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
8+
<link rel="stylesheet" type="text/css" href="css/git-webui.css" />
9+
#(##class(SourceControl.Git.Utils).GetSourceControlInclude())#
10+
<style type="text/css">
11+
h1, h2 {
12+
margin-top: 10px
13+
}
14+
15+
.A::after {
16+
content: "Added";
17+
position: absolute;
18+
right: 10px;
19+
}
20+
21+
.D::after {
22+
content: "Deleted";
23+
position: absolute;
24+
right: 10px;
25+
}
26+
27+
.M::after {
28+
content: "Modified";
29+
position: absolute;
30+
right: 10px;
31+
}
32+
33+
.R::after {
34+
content: "Renamed";
35+
position: absolute;
36+
right: 10px;
37+
}
38+
39+
.section-header {
40+
margin: 20px 0 15px 0
41+
}
42+
43+
#syncBtn {
44+
position: absolute;
45+
right: 15px;
46+
margin-top: 10px;
47+
}
48+
49+
.output-header {
50+
margin-top: 120px;
51+
}
52+
.output {
53+
54+
margin-bottom: 20px;
55+
border: 1.5px solid darkgray;
56+
padding: 10px;
57+
border-radius: 4px;
58+
}
59+
60+
</style>
61+
</head>
62+
<body>
63+
<server>
64+
set settings = ##class(SourceControl.Git.Settings).%New()
65+
66+
set uncommittedWithAction = ##class(SourceControl.Git.Utils).UncommittedWithAction().%Get("user")
67+
set commitMsg = ##class(SourceControl.Git.Utils).GenerateCommitMessageFromFiles(uncommittedWithAction)
68+
set filesToSync = ($length(commitMsg) > 0)
69+
set fileSectionDisplay = $select(
70+
filesToSync = 1: "block",
71+
1: "none"
72+
)
73+
set noFileDisplay = $select(
74+
filesToSync = 0: "block",
75+
1: "none"
76+
)
77+
78+
set outputDisplay = "none"
79+
80+
</server>
81+
82+
<div class="container">
83+
<h1 class="text-center">Sync Repository</h1>
84+
<div class="row">
85+
<div class="offset-sm-2 col-sm-8">
86+
<div style="display: #(fileSectionDisplay)#">
87+
<h3 class="section-header">Files to be committed with sync:</h3>
88+
<ul class="list-group">
89+
<server>
90+
set iterator = uncommittedWithAction.%GetIterator()
91+
while iterator.%GetNext(,.uncommitted) {
92+
set action = uncommitted.%Get("action")
93+
set file = uncommitted.%Get("file")
94+
&html<<li class="list-group-item #(..EscapeHTML(action))#">#(..EscapeHTML(file))#</li>>
95+
}
96+
</server>
97+
</ul>
98+
<h3 class="section-header">Sync commit message:</h3>
99+
<input class="form-control" type="text" name="syncMsg" id="syncMsg" value="#(..EscapeHTML(commitMsg))#">
100+
</div>
101+
<div style="display: #(noFileDisplay)#">
102+
<h2 class="text-center">No files to commit with sync</h2>
103+
</div>
104+
<h3 class="section-header">Sync details:</h3>
105+
<p>Upon syncing, the local repository will pull the changes from remote and commit the newest changes before committing and pushing</p>
106+
<server>
107+
108+
if settings.defaultMergeBranch '= "" {
109+
&html<<p>Local changes will be merged with #(..EscapeHTML(settings.defaultMergeBranch))# after receiving the latest changes</p>>
110+
}
111+
</server>
112+
113+
<button class="btn btn-lg btn-primary" id="syncBtn" onClick="disableInput(); #server(..PerformSync(self.document.getElementById('syncMsg').value))#">Sync</button>
114+
<div>
115+
<h3 class="output-header" id="outputHeader" style="display: #(outputDisplay)#">Sync output: </h3>
116+
<div class="container output" id="outputContainer" style="display: #(outputDisplay)#">
117+
<pre id="outputBox"></pre>
118+
</div>
119+
</div>
120+
</div>
121+
</div>
122+
123+
</div>
124+
</body>
125+
<script type="text/javascript">
126+
function disableInput() {
127+
document.getElementById('syncMsg').disabled = true;
128+
document.getElementById('syncBtn').innerHTML = 'Syncing...';
129+
document.getElementById('syncBtn').disabled = true;
130+
}
131+
</script>
132+
<script language="cache" method="PerformSync" arguments="syncMsg:%String">
133+
&js<document.getElementById('outputContainer').style.display = 'block'>
134+
&js<document.getElementById('outputHeader').style.display = 'block'>
135+
set buffer = ##class(SourceControl.Git.Util.Buffer).%New()
136+
do buffer.BeginCaptureOutput()
137+
138+
set st = ##class(SourceControl.Git.Utils).Sync(syncMsg)
139+
140+
set out = ##class(%Stream.GlobalCharacter).%New()
141+
do buffer.EndCaptureOutput(.out)
142+
while 'out.AtEnd {
143+
set line = out.ReadLine()
144+
set escapedLine = ..EscapeHTML(line)
145+
set escapedLine = $replace(escapedLine, $char(10), "<br>")
146+
147+
&js<
148+
var outputContainer = document.getElementById('outputBox');
149+
var lineText = "#(escapedLine)#";
150+
var lineTextNode = document.createTextNode(lineText);
151+
outputContainer.innerHTML += lineText + "<br>";
152+
>
153+
}
154+
&js<document.getElementById('syncBtn').innerHTML = 'Synced'>
155+
</script>
156+
</html>
157+
<script method='OnPreHTTP' language='cache' runat='server' returntype='%Boolean'>
158+
try {
159+
set %session.UseSessionCookie = 1 // Always set back to autodetect
160+
set %session.CookiePath = "" // Always clear
161+
if (%request.UserAgent [ " Code/") {
162+
// Workaround for VSCode webview
163+
set %session.SessionScope = 0 // none; allowed because...
164+
set %session.SecureSessionCookie = 1 // secure flag on session cookie - will be ignored over http, but that's OK because we already have it
165+
}
166+
} catch e {
167+
// ignore; may occur on platform versions without the above properties
168+
}
169+
quit 1
170+
</script>
171+
<script method='OnPreHyperEvent' arguments="class:%String,method:%String" language='cache' runat='server' returntype='%Status'>
172+
try {
173+
set %session.UseSessionCookie = 1 // Always set back to autodetect
174+
set %session.CookiePath = "" // Always clear
175+
if (%request.UserAgent [ " Code/") {
176+
// Workaround for VSCode webview
177+
set %session.SessionScope = 0 // none; allowed because...
178+
set %session.SecureSessionCookie = 1 // secure flag on session cookie - will be ignored over http, but that's OK because we already have it
179+
}
180+
} catch e {
181+
// ignore; may occur on platform versions without the above properties
182+
}
183+
quit 1
184+
</script>

module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<FileCopy Name="csp/gitprojectsettings.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/gitprojectsettings.csp" />
2828
<FileCopy Name="csp/pull.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/pull.csp" />
2929
<FileCopy Name="csp/webuidriver.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/webuidriver.csp" />
30+
<FileCopy Name="csp/sync.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/sync.csp" />
3031
<FileCopy Name="git-webui/release/share/git-webui/webui/" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/" Overlay="1" />
3132

3233
<Invoke Class="SourceControl.Git.Utils" Method="OutputConfigureMessage" />

0 commit comments

Comments
 (0)