|
1 | 1 | package pegr.admin |
2 | 2 | import pegr.AdminCategory |
| 3 | +import pegr.Organization |
| 4 | +import pegr.RoleGroup |
3 | 5 | import pegr.UserRoleGroup |
4 | 6 | import pegr.User |
5 | 7 | import pegr.UserService |
6 | 8 | import pegr.UserException |
| 9 | +import grails.converters.* |
| 10 | +import grails.util.Holders |
| 11 | +import groovy.json.* |
7 | 12 |
|
8 | 13 | class UserAdminController { |
9 | 14 | public static AdminCategory category = AdminCategory.OTHER |
10 | 15 |
|
11 | 16 | def userService |
12 | 17 |
|
13 | | - def index(Integer max, Long affiliationId, Long groupId, String isEnabled) { |
14 | | - //Removed max parameter as to allow for all entries to populate datatable |
15 | | - |
16 | | - def affiliations = User.where{}.collect { it.affiliation }.unique() |
17 | | - |
18 | | - def users |
19 | | - def totalCount |
20 | | - |
21 | | - if (groupId) { |
22 | | - def sort = params.sort ? ("user."+params.sort) : "user.fullName" |
23 | | - users = UserRoleGroup.createCriteria().list(max: params.max, offset: params.offset, sort: sort, order: params.order) { |
24 | | - eq("roleGroup.id", groupId) |
25 | | - }.collect { it.user } |
26 | | - |
27 | | - totalCount = UserRoleGroup.where { roleGroup.id == groupId }.count() |
28 | | - } else { |
29 | | - def query |
30 | | - if (affiliationId) { |
31 | | - query = User.where { affiliation.id == affiliationId } |
32 | | - } else if (isEnabled != null && isEnabled != "") { |
33 | | - query = User.where { enabled == isEnabled } |
34 | | - } else { |
35 | | - query = User.where{} |
36 | | - } |
37 | | - users = query.list(params) |
38 | | - totalCount = query.count() |
| 18 | + def index(Long affiliationId, Long groupId, String isEnabled) { |
| 19 | + |
| 20 | + def query |
| 21 | + def users |
| 22 | + def affiliations = User.where{}.collect { it.affiliation }.unique() |
| 23 | + |
| 24 | + if (params.groupLoad != null && params.affiliateLoad != null && params.activityLoad != null){ |
| 25 | + def groupList = JSON.parse(params.groupLoad) |
| 26 | + def affiliateList = JSON.parse(params.affiliateLoad) |
| 27 | + def activityList = JSON.parse(params.activityLoad) |
| 28 | + def c |
| 29 | + if (groupList.size() != 0 || affiliateList.size() != 0 || activityList.size() != 0){ |
| 30 | + // def a = RoleGroup.where{name == "Admin"}.collect { it.id }.unique() |
| 31 | + |
| 32 | + // groupList start |
| 33 | + def i = 0; |
| 34 | + def a = RoleGroup.createCriteria().list{ |
| 35 | + if (groupList.size() != 0){ |
| 36 | + or{ |
| 37 | + for (i=0; i<groupList.size(); i++){ |
| 38 | + eq("name", groupList[i]) |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + }.collect { it.id } |
| 43 | + // get username of users who meet group criteria |
| 44 | + c = UserRoleGroup.createCriteria().list{ |
| 45 | + if (groupList.size() != 0){ |
| 46 | + or{ |
| 47 | + for (i=0; i<a.size(); i++){ |
| 48 | + eq("roleGroup.id", a[i]) |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + }.collect { it.user } |
| 53 | + // groupList end |
| 54 | + |
| 55 | + // affiliateList start |
| 56 | + def b = Organization.createCriteria().list{ |
| 57 | + if (affiliateList.size() != 0) { |
| 58 | + or{ |
| 59 | + for (i=0; i<affiliateList.size(); i++){ |
| 60 | + eq("name", affiliateList[i]) |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + }.collect { it.id } |
| 65 | + |
| 66 | + // activityList start |
| 67 | + Boolean status = true; |
| 68 | + def e = User.createCriteria().list{ |
| 69 | + if (activityList.size() != 0){ |
| 70 | + or{ |
| 71 | + for (i=0; i<activityList.size(); i++){ |
| 72 | + if (activityList[i] == "Active"){ |
| 73 | + status = true; |
| 74 | + } else{ |
| 75 | + status = false; |
| 76 | + } |
| 77 | + eq("enabled", status) |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + }.collect { it.id } |
| 82 | + |
| 83 | + // get members by status |
| 84 | + def f = User.createCriteria().list{ |
| 85 | + if (groupList.size() != 0){ |
| 86 | + or{ |
| 87 | + for (i=0; i<c.size(); i++){ |
| 88 | + eq("username", c[i].username) |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + if (affiliateList.size() != 0){ |
| 93 | + or{ |
| 94 | + for (i=0; i<b.size(); i++){ |
| 95 | + eq("affiliation.id", b[i]) |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + if (activityList.size() != 0){ |
| 100 | + or{ |
| 101 | + for (i=0; i<e.size(); i++){ |
| 102 | + eq("id", e[i]) |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + users = f |
| 108 | + } |
| 109 | + } |
| 110 | + else { |
| 111 | + query = User.where{} |
| 112 | + users = query.list(params) |
39 | 113 | } |
40 | 114 |
|
41 | 115 | [users: users, |
42 | | - totalCount: totalCount, |
43 | 116 | affiliations: affiliations, |
44 | 117 | affiliationId: affiliationId, |
45 | 118 | groupId: groupId, |
|
0 commit comments