Skip to content

Sync webui #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [2.5.0] - Unreleased

### Added
- New UI for the basic mode Sync (#415)

## [2.4.1] - 2024-08-02

### Added
Expand Down
15 changes: 3 additions & 12 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,8 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
set Action = 7
quit $$$OK
} elseif (menuItemName = "Sync") {
if ..CheckForUncommittedFiles() {
set Target = "Enter a commit message for the sync operation"
set Action = 7
set Msg = ..PreSync()
} else {
set Target = ""
do ..Sync("",.Target)
if (Target '= "") {
set Action = 6
}
}
set Action = 2 + externalBrowser
set Target = urlPrefix _ "/isc/studio/usertemplates/gitsourcecontrol/sync.csp?Namespace="_$NAMESPACE

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

}
quit $LISTTOSTRING(commitMsg, ",")
quit $LISTTOSTRING(commitMsg, ", ")
}

ClassMethod GitStatus(ByRef files, IncludeAllFiles = 0)
Expand Down
184 changes: 184 additions & 0 deletions csp/sync.csp
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/git-webui.css" />
#(##class(SourceControl.Git.Utils).GetSourceControlInclude())#
<style type="text/css">
h1, h2 {
margin-top: 10px
}

.A::after {
content: "Added";
position: absolute;
right: 10px;
}

.D::after {
content: "Deleted";
position: absolute;
right: 10px;
}

.M::after {
content: "Modified";
position: absolute;
right: 10px;
}

.R::after {
content: "Renamed";
position: absolute;
right: 10px;
}

.section-header {
margin: 20px 0 15px 0
}

#syncBtn {
position: absolute;
right: 15px;
margin-top: 10px;
}

.output-header {
margin-top: 120px;
}
.output {

margin-bottom: 20px;
border: 1.5px solid darkgray;
padding: 10px;
border-radius: 4px;
}

</style>
</head>
<body>
<server>
set settings = ##class(SourceControl.Git.Settings).%New()

set uncommittedWithAction = ##class(SourceControl.Git.Utils).UncommittedWithAction().%Get("user")
set commitMsg = ##class(SourceControl.Git.Utils).GenerateCommitMessageFromFiles(uncommittedWithAction)
set filesToSync = ($length(commitMsg) > 0)
set fileSectionDisplay = $select(
filesToSync = 1: "block",
1: "none"
)
set noFileDisplay = $select(
filesToSync = 0: "block",
1: "none"
)

set outputDisplay = "none"

</server>

<div class="container">
<h1 class="text-center">Sync Repository</h1>
<div class="row">
<div class="offset-sm-2 col-sm-8">
<div style="display: #(fileSectionDisplay)#">
<h3 class="section-header">Files to be committed with sync:</h3>
<ul class="list-group">
<server>
set iterator = uncommittedWithAction.%GetIterator()
while iterator.%GetNext(,.uncommitted) {
set action = uncommitted.%Get("action")
set file = uncommitted.%Get("file")
&html<<li class="list-group-item #(..EscapeHTML(action))#">#(..EscapeHTML(file))#</li>>
}
</server>
</ul>
<h3 class="section-header">Sync commit message:</h3>
<input class="form-control" type="text" name="syncMsg" id="syncMsg" value="#(..EscapeHTML(commitMsg))#">
</div>
<div style="display: #(noFileDisplay)#">
<h2 class="text-center">No files to commit with sync</h2>
</div>
<h3 class="section-header">Sync details:</h3>
<p>Upon syncing, the local repository will pull the changes from remote and commit the newest changes before committing and pushing</p>
<server>

if settings.defaultMergeBranch '= "" {
&html<<p>Local changes will be merged with #(..EscapeHTML(settings.defaultMergeBranch))# after receiving the latest changes</p>>
}
</server>

<button class="btn btn-lg btn-primary" id="syncBtn" onClick="disableInput(); #server(..PerformSync(self.document.getElementById('syncMsg').value))#">Sync</button>
<div>
<h3 class="output-header" id="outputHeader" style="display: #(outputDisplay)#">Sync output: </h3>
<div class="container output" id="outputContainer" style="display: #(outputDisplay)#">
<pre id="outputBox"></pre>
</div>
</div>
</div>
</div>

</div>
</body>
<script type="text/javascript">
function disableInput() {
document.getElementById('syncMsg').disabled = true;
document.getElementById('syncBtn').innerHTML = 'Syncing...';
document.getElementById('syncBtn').disabled = true;
}
</script>
<script language="cache" method="PerformSync" arguments="syncMsg:%String">
&js<document.getElementById('outputContainer').style.display = 'block'>
&js<document.getElementById('outputHeader').style.display = 'block'>
set buffer = ##class(SourceControl.Git.Util.Buffer).%New()
do buffer.BeginCaptureOutput()

set st = ##class(SourceControl.Git.Utils).Sync(syncMsg)

set out = ##class(%Stream.GlobalCharacter).%New()
do buffer.EndCaptureOutput(.out)
while 'out.AtEnd {
set line = out.ReadLine()
set escapedLine = ..EscapeHTML(line)
set escapedLine = $replace(escapedLine, $char(10), "<br>")

&js<
var outputContainer = document.getElementById('outputBox');
var lineText = "#(escapedLine)#";
var lineTextNode = document.createTextNode(lineText);
outputContainer.innerHTML += lineText + "<br>";
>
}
&js<document.getElementById('syncBtn').innerHTML = 'Synced'>
</script>
</html>
<script method='OnPreHTTP' language='cache' runat='server' returntype='%Boolean'>
try {
set %session.UseSessionCookie = 1 // Always set back to autodetect
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be worth refactoring this to a shared method somewhere since many places use it. Doesn't need to happen in this PR though.

set %session.CookiePath = "" // Always clear
if (%request.UserAgent [ " Code/") {
// Workaround for VSCode webview
set %session.SessionScope = 0 // none; allowed because...
set %session.SecureSessionCookie = 1 // secure flag on session cookie - will be ignored over http, but that's OK because we already have it
}
} catch e {
// ignore; may occur on platform versions without the above properties
}
quit 1
</script>
<script method='OnPreHyperEvent' arguments="class:%String,method:%String" language='cache' runat='server' returntype='%Status'>
try {
set %session.UseSessionCookie = 1 // Always set back to autodetect
set %session.CookiePath = "" // Always clear
if (%request.UserAgent [ " Code/") {
// Workaround for VSCode webview
set %session.SessionScope = 0 // none; allowed because...
set %session.SecureSessionCookie = 1 // secure flag on session cookie - will be ignored over http, but that's OK because we already have it
}
} catch e {
// ignore; may occur on platform versions without the above properties
}
quit 1
</script>
1 change: 1 addition & 0 deletions module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<FileCopy Name="csp/gitprojectsettings.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/gitprojectsettings.csp" />
<FileCopy Name="csp/pull.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/pull.csp" />
<FileCopy Name="csp/webuidriver.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/webuidriver.csp" />
<FileCopy Name="csp/sync.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/sync.csp" />
<FileCopy Name="git-webui/release/share/git-webui/webui/" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/" Overlay="1" />

<Invoke Class="SourceControl.Git.Utils" Method="OutputConfigureMessage" />
Expand Down
Loading