|
| 1 | +Class %zpkg.isc.sc.git.Favorites |
| 2 | +{ |
| 3 | + ClassMethod ConfigureFavoriteNamespaces(username As %String, newNamespaces As %Library.DynamicObject) |
| 4 | +{ |
| 5 | + // Convert to $listbuild |
| 6 | + set namespaces = $lb() |
| 7 | + set iterator = newNamespaces.%GetIterator() |
| 8 | + |
| 9 | + while iterator.%GetNext(.key, .value) { |
| 10 | + set namespaces = namespaces_$lb(value) |
| 11 | + } |
| 12 | + |
| 13 | + // Call the private method |
| 14 | + try { |
| 15 | + do ..SetFavs(username, namespaces) |
| 16 | + } catch e { |
| 17 | + return e.AsStatus() |
| 18 | + } |
| 19 | + return $$$OK |
| 20 | +} |
| 21 | + |
| 22 | +ClassMethod GetFavoriteNamespaces(ByRef favNamespaces As %DynamicArray, ByRef nonFavNamespaces As %DynamicArray) |
| 23 | +{ |
| 24 | + try { |
| 25 | + set namespaces = ..GetFavs() |
| 26 | + set favNamespaces = namespaces.%Get("Favorites") |
| 27 | + set nonFavNamespaces = namespaces.%Get("NonFavorites") |
| 28 | + } catch e { |
| 29 | + return e.AsStatus() |
| 30 | + } |
| 31 | + return $$$OK |
| 32 | +} |
| 33 | + |
| 34 | +ClassMethod GetFavs() As %Library.DynamicObject [ Private, NotInheritable ] { |
| 35 | + $$$AddAllRoleTemporary |
| 36 | + set allNamespaces = ##class(SourceControl.Git.Utils).GetContexts(1) |
| 37 | + |
| 38 | + set favNamespaces = [] |
| 39 | + set nonFavNamespaces = [] |
| 40 | + |
| 41 | + set username = $USERNAME |
| 42 | + set pagePrefix = "Git:" |
| 43 | + &sql(DECLARE FavCursor CURSOR FOR SELECT Page into :page from %SYS_Portal.Users where username = :username and page %STARTSWITH :pagePrefix) |
| 44 | + |
| 45 | + for i=0:1:(allNamespaces.%Size() - 1) { |
| 46 | + set namespace = allNamespaces.%Get(i) |
| 47 | + set foundFlag = 0 |
| 48 | + &sql(OPEN FavCursor) |
| 49 | + throw:SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE, %msg) |
| 50 | + &sql(FETCH FavCursor) |
| 51 | + while (SQLCODE = 0) { |
| 52 | + set pageValue = "Git: "_namespace |
| 53 | + if (page = pageValue) { |
| 54 | + do favNamespaces.%Push(namespace) |
| 55 | + set foundFlag = 1 |
| 56 | + } |
| 57 | + &sql(FETCH FavCursor) |
| 58 | + } |
| 59 | + &sql(CLOSE FavCursor) |
| 60 | + |
| 61 | + if ('foundFlag) { |
| 62 | + do nonFavNamespaces.%Push(namespace) |
| 63 | + } |
| 64 | + } |
| 65 | + return {"Favorites": (favNamespaces), "NonFavorites": (nonFavNamespaces)} |
| 66 | +} |
| 67 | + |
| 68 | +ClassMethod SetFavs(username As %String, namespaces As %List) [ Private, NotInheritable ] { |
| 69 | + $$$AddAllRoleTemporary |
| 70 | + &sql(DELETE FROM %SYS_Portal.Users WHERE Username = :username AND Page LIKE '%Git%') |
| 71 | + |
| 72 | + for i=1:1:$listlength(namespaces) { |
| 73 | + set namespace = $listget(namespaces, i) |
| 74 | + if (namespace '= "") { |
| 75 | + set installNamespace = namespace |
| 76 | + |
| 77 | + // Insert Git link |
| 78 | + set caption = "Git: " _ installNamespace |
| 79 | + set link = "/isc/studio/usertemplates/gitsourcecontrol/webuidriver.csp/" _ installNamespace _ "/" |
| 80 | + &sql(INSERT OR UPDATE INTO %SYS_Portal.Users (Username, Page, Data) VALUES (:username, :caption, :link)) |
| 81 | + |
| 82 | + // Insert Git Pull link |
| 83 | + set caption = "Git Pull: " _ installNamespace |
| 84 | + set link = "/isc/studio/usertemplates/gitsourcecontrol/pull.csp?$NAMESPACE=" _ installNamespace |
| 85 | + &sql(INSERT OR UPDATE INTO %SYS_Portal.Users (Username, Page, Data) VALUES (:username, :caption, :link)) |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | +} |
0 commit comments