Skip to content

Issue #349 added basic and expert modes to the application #355

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
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Pre-release support for IPM v0.9.0+
- Items mapped from database other than namespace's default routine database are now ignored by default when exporting or adding files
- New setting to configure whether mapped items should be should be treated as read-only
- Added a basic mode to automatically perform functionality expected in basic use cases (#349)
- New sync operation for basic mode that fetches, pulls, commits and then pushes (#349)

## [2.3.1] - 2024-04-30

Expand Down
119 changes: 71 additions & 48 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ XData Menu
<MenuItem Name="Revert" />
<MenuItem Name="Commit" />
<MenuItem Separator="true"/>
<MenuItem Name="Sync" />
<MenuItem Name="Push" />
<MenuItem Name="Fetch" />
<MenuItem Name="Pull" />
Expand Down Expand Up @@ -49,15 +50,20 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
set Name = "%SourceMenu,Status"
}

if (Type = 1) && ((Name = 1) || (Name = 7)) {
do ..AddToSourceControl(InternalName)
}


#dim ec as %Status = $$$OK
#dim menu as %Status = $piece(Name, ",", 1)
if menu '= "%SourceMenu", menu'="%SourceContext" {
quit $$$OK
}

set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set ec = ##class(Utils).UserAction(InternalName, Name, .Target, .Action, .Reload)
set ec = ##class(SourceControl.Git.Utils).UserAction(InternalName, Name, .Target, .Action, .Reload, .Msg)
quit ec
}

Expand All @@ -68,9 +74,9 @@ Method AfterUserAction(Type As %Integer, Name As %String, InternalName As %Strin
if menu '= "%SourceMenu", menu'="%SourceContext" {
quit $$$OK
}
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set ec = ##class(Utils).AfterUserAction(Type, Name, InternalName, .Answer, .Msg, .Reload)
set ec = ##class(SourceControl.Git.Utils).AfterUserAction(Type, Name, InternalName, .Answer, .Msg, .Reload)
quit ec
}

Expand All @@ -90,6 +96,7 @@ Method LocalizeName(name As %String) As %String
"SwitchBranch":$$$Text("@SwitchBranch@Check out an existing branch"),
"Revert":$$$Text("@Revert@Discard changes to file"),
"Commit":$$$Text("@Commit@Commit changes to file"),
"Sync":$$$Text("@Sync@Sync"),
"Push":$$$Text("@Push@Push to remote branch"),
"Fetch":$$$Text("@Fetch@Fetch from remote"),
"Pull":$$$Text("@Pull@Pull changes from remote branch"),
Expand All @@ -99,36 +106,52 @@ Method LocalizeName(name As %String) As %String

Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef DisplayName As %String, InternalName As %String) As %Status
{

if name = "Settings" {
set Enabled = 1
quit $$$OK
}
if ##class(Utils).NeedSettings() {
if ##class(SourceControl.Git.Utils).NeedSettings() {
set Enabled = -1
quit $$$OK
}
if ##class(Utils).IsNamespaceInGit() {
if $listfind($listbuild("AddToSC", "RemoveFromSC", "Revert", "Commit"), name) {
quit ..OnSourceMenuContextItem(InternalName,name,.Enabled,.DisplayName)
}
set Enabled = $CASE(name,
// cases
"Status": 1,
"GitWebUI" : 1,
"Export": 1,
"ExportForce": 1,
"Import": 1,
"ImportForce": 1,
"NewBranch": 1,
"SwitchBranch": 1,
"Push": 1,
"Fetch": 1,
"Pull": 1,
"": 1,
:-1 // default
)
if ##class(SourceControl.Git.Utils).IsNamespaceInGit() {

if $listfind($listbuild("AddToSC", "RemoveFromSC", "Revert", "Commit"), name) {
quit ..OnSourceMenuContextItem(InternalName,name,.Enabled,.DisplayName)
}

if ##class(SourceControl.Git.Utils).BasicMode() {
set Enabled = $CASE(name,
"Status": 1,
"GitWebUI" : 1,
"Sync": 1,
"": 1,
:-1

)
} else {
set Enabled = $CASE(name,
// cases
"Status": 1,
"GitWebUI" : 1,
"Export": 1,
"ExportForce": 1,
"Import": 1,
"ImportForce": 1,
"NewBranch": 1,
"SwitchBranch": 1,
"Push": 1,
"Fetch": 1,
"Pull": 1,
"Sync": -1,
"": 1,
:-1 // default
)
}

} elseif ##class(Utils).GitBinExists() {

} elseif ##class(SourceControl.Git.Utils).GitBinExists() {
if name = "Init" {
} else {
set Enabled = -1
Expand All @@ -141,7 +164,7 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display

Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByRef Enabled As %String, ByRef DisplayName As %String) As %Status
{
if (itemName = "") || '##class(Utils).IsNamespaceInGit() {
if (itemName = "") || '##class(SourceControl.Git.Utils).IsNamespaceInGit() {
set Enabled = -1
} elseif (($find(itemName,",") > 0) || (##class(SourceControl.Git.Utils).Type(itemName) = "pkg")) {
//if more than one item is selected, we can only add/remove, no diff or blame
Expand All @@ -150,16 +173,16 @@ Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByR
} elseif menuItemName = "Revert" {
set Enabled = 1
do ..GetStatus(.itemName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
if '(##class(Change).IsUncommitted(##class(Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
if '(##class(SourceControl.Git.Change).IsUncommitted(##class(SourceControl.Git.Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
set Enabled = 0
}
} elseif menuItemName = "Commit" {
set Enabled = 1
do ..GetStatus(.itemName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
if '(##class(Change).IsUncommitted(##class(Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
if '(##class(SourceControl.Git.Change).IsUncommitted(##class(SourceControl.Git.Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
set Enabled = 0
}
} elseif ##class(Utils).IsInSourceControl(itemName) {
} elseif ##class(SourceControl.Git.Utils).IsInSourceControl(itemName) {
set Enabled = $case(menuItemName, "AddToSC":-1,:1)
} else {
set Enabled = $case(menuItemName, "AddToSC":1,:-1)
Expand All @@ -174,7 +197,7 @@ Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByR
/// this menu item from the list totally, 0 will gray the menu item out and the default 1 will display the menu item as normal.
Method OnMenuItem(MenuName As %String, InternalName As %String, SelectedText As %String, ByRef Enabled As %Boolean, ByRef DisplayName As %String) As %Status
{
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)

#dim menu as %String= $piece(MenuName,",")
Expand All @@ -200,9 +223,9 @@ Method OnMenuItem(MenuName As %String, InternalName As %String, SelectedText As
Method OnBeforeLoad(InternalName As %String, verbose As %Boolean) As %Status
{
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
if ##class(Utils).IsInSourceControl(InternalName) {
quit ##class(Utils).ImportItem(InternalName,,0)
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
if ##class(SourceControl.Git.Utils).IsInSourceControl(InternalName) {
quit ##class(SourceControl.Git.Utils).ImportItem(InternalName,,0)
}
quit $$$OK
}
Expand Down Expand Up @@ -236,12 +259,12 @@ Method OnAfterSave(InternalName As %String, Object As %RegisteredObject = {$$$NU
{
set sc = $$$OK
try {
set InternalName = ##class(Utils).NormalizeInternalName(.InternalName)
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(.InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
if ##class(Utils).IsNamespaceInGit() && ..IsInSourceControl(InternalName) {
set filename = ##class(Utils).FullExternalName(InternalName)
$$$ThrowOnError(##class(Utils).RemoveRoutineTSH(InternalName))
$$$ThrowOnError(##class(Utils).ExportItem(InternalName))
if ##class(SourceControl.Git.Utils).IsNamespaceInGit() && ..IsInSourceControl(InternalName) {
set filename = ##class(SourceControl.Git.Utils).FullExternalName(InternalName)
$$$ThrowOnError(##class(SourceControl.Git.Utils).RemoveRoutineTSH(InternalName))
$$$ThrowOnError(##class(SourceControl.Git.Utils).ExportItem(InternalName))
if '##class(SourceControl.Git.Change).IsUncommitted(filename) {
$$$ThrowOnError(##class(SourceControl.Git.Change).SetUncommitted(filename, "edit", InternalName, $username, "", 1, "", "", 0))
}
Expand All @@ -262,7 +285,7 @@ Method OnAfterCompile(InternalName As %String) As %Status
/// Returns true if this item is in source control and false otherwise.
Method IsInSourceControl(InternalName As %String) As %Boolean [ CodeMode = expression ]
{
InternalName'="" && ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInternalName(InternalName))
InternalName'="" && ##class(SourceControl.Git.Utils).IsInSourceControl(##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName))
}

/// Called before an item is deleted.
Expand All @@ -273,10 +296,10 @@ Method OnBeforeDelete(InternalName As %String) As %Status
Throw ##class(%Exception.General).%New("Can't delete in locked environment")
} else {
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
set Filename = ##class(Utils).FullExternalName(InternalName)
if ##class(Utils).IsInSourceControl(InternalName) && ##class(%File).Exists(Filename) {
quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName)
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
set Filename = ##class(SourceControl.Git.Utils).FullExternalName(InternalName)
if ##class(SourceControl.Git.Utils).IsInSourceControl(InternalName) && ##class(%File).Exists(Filename) {
quit ##class(SourceControl.Git.Change).AddDeletedToUncommitted(Filename, InternalName)
}
quit $$$OK
}
Expand All @@ -286,9 +309,9 @@ Method OnBeforeDelete(InternalName As %String) As %Status
Method OnAfterDelete(InternalName As %String) As %Status
{
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
if ##class(Utils).IsInSourceControl(InternalName) {
quit ##class(Utils).DeleteExternalFile(InternalName)
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
if ##class(SourceControl.Git.Utils).IsInSourceControl(InternalName) {
quit ##class(SourceControl.Git.Utils).DeleteExternalFile(InternalName)
}
quit $$$OK
}
Expand All @@ -297,7 +320,7 @@ Method OnAfterDelete(InternalName As %String) As %Status
/// the routine/class/csp item. This is often a filename to write the file out to.
Method ExternalName(InternalName As %String) As %String
{
quit ##class(Utils).ExternalName(InternalName)
quit ##class(SourceControl.Git.Utils).ExternalName(InternalName)
}

Method IsReadOnly(InternalName As %String) As %Boolean
Expand Down
20 changes: 20 additions & 0 deletions cls/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ Property gitUserEmail As %String(MAXLEN = 255) [ InitialExpression = {##class(So
/// Attribution: Whether mapped items should be read-only, preventing them from being added to source control
Property mappedItemsReadOnly As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).MappedItemsReadOnly()} ];

/// Whether basic mode should be enabled for user ${username}, greatly simplifying the functionality of the package, requiring no knowledge of git
Property basicMode As %String [ InitialExpression = {##class(SourceControl.Git.Utils).BasicMode()} ];

/// A read-only setting used to display the basic mode setting that is chosen in the settings page
Property userBasicMode As %String [ InitialExpression = {##class(SourceControl.Git.Utils).UserBasicMode()} ];

/// The system's default mode. If true, the system defaults to basic mode
Property systemBasicMode As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).SystemBasicMode()} ];

Property Mappings [ MultiDimensional ];

Method %OnNew() As %Status
Expand Down Expand Up @@ -84,6 +93,16 @@ Method %Save() As %Status
set @storage@("settings","percentClassReplace") = ..percentClassReplace
set @storage@("settings","settingsUIReadOnly") = ..settingsUIReadOnly
set @storage@("settings", "mappedItemsReadOnly") = ..mappedItemsReadOnly
set @storage@("settings", "basicMode") = ..systemBasicMode
if ..basicMode = "system" {
kill @storage@("settings", "user", $username, "basicMode")
} else {
set @storage@("settings", "user", $username, "basicMode") = ..basicMode
}

// update value of basicUserMode to reflect the updated setting for basicMode
set ..userBasicMode = ##class(SourceControl.Git.Utils).UserBasicMode()


kill @##class(SourceControl.Git.Utils).MappingsNode()
merge @##class(SourceControl.Git.Utils).MappingsNode() = ..Mappings
Expand All @@ -106,6 +125,7 @@ ClassMethod Configure() As %Boolean [ CodeMode = objectgenerator ]
for {
set sequence = $order(orderedProperties(sequence),1,property)
quit:sequence=""
continue:property="userBasicMode"
do %code.WriteLine(" set value = inst."_property)
set prompt = $$$comMemberKeyGet(%class.Name,$$$cCLASSproperty,property,$$$cPROPdescription)
set promptQuoted = $$$QUOTE(prompt_":")
Expand Down
Loading
Loading