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