-
Notifications
You must be signed in to change notification settings - Fork 1
/
work_item_filter_form.go
210 lines (205 loc) · 5.69 KB
/
work_item_filter_form.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package forms
import (
"github.com/APTrust/registry/common"
"github.com/APTrust/registry/constants"
"github.com/APTrust/registry/pgmodels"
)
// WorkItemFilterForm is the form that displays filtering options for
// the work item list page.
type WorkItemFilterForm struct {
Form
FilterCollection *pgmodels.FilterCollection
actingUserIsAdmin bool
instOptions []*ListOption
}
func NewWorkItemFilterForm(fc *pgmodels.FilterCollection, actingUser *pgmodels.User) (FilterForm, error) {
f := &WorkItemFilterForm{
Form: NewForm(nil, "work_items/_filters.html", "/work_items"),
FilterCollection: fc,
}
var err error
if actingUser.IsAdmin() {
// SysAdmin can view files at any institutions.
f.instOptions, err = ListInstitutions(false)
if err != nil {
return nil, err
}
}
f.init()
f.SetValues()
return f, nil
}
func (f *WorkItemFilterForm) init() {
f.Fields["action__in"] = &Field{
Name: "action__in",
Label: "Action",
Placeholder: "Action",
Options: Options(constants.WorkItemActions),
Attrs: map[string]string{
"multiple": "multiple",
},
}
f.Fields["alt_identifier"] = &Field{
Name: "alt_identifier",
Label: "Alternate Identifier",
Placeholder: "Alternate Identifier",
}
f.Fields["bag_date__gteq"] = &Field{
Name: "bag_date__gteq",
Label: "Bag Date On or After",
Placeholder: "Bag Date On or After",
}
f.Fields["bag_date__lteq"] = &Field{
Name: "bag_date__lteq",
Label: "Bag Date On or Before",
Placeholder: "Bag Date On or Before",
}
f.Fields["bag_group_identifier"] = &Field{
Name: "bag_group_identifier",
Label: "Bag Group Identifier",
Placeholder: "Bag Group Identifier",
}
f.Fields["bagit_profile_identifier"] = &Field{
Name: "bagit_profile_identifier",
Label: "BagIt Profile",
Placeholder: "BagIt Profile",
Options: BagItProfileIdentifiers,
}
f.Fields["bucket"] = &Field{
Name: "bucket",
Label: "Bucket",
Placeholder: "Bucket",
}
f.Fields["date_processed__gteq"] = &Field{
Name: "date_processed__gteq",
Label: "Processed On or After",
Placeholder: "Processed On or After",
}
f.Fields["date_processed__lteq"] = &Field{
Name: "date_processed__lteq",
Label: "Processed On or Before",
Placeholder: "Processed On or Before",
}
f.Fields["etag"] = &Field{
Name: "etag",
Label: "ETag (from S3 upload)",
Placeholder: "ETag",
}
f.Fields["generic_file_identifier"] = &Field{
Name: "generic_file_identifier",
Label: "File Identifier",
Placeholder: "File Identifier",
}
f.Fields["institution_id"] = &Field{
Name: "institution_id",
Label: "Institution",
Placeholder: "Institution",
Options: f.instOptions,
}
f.Fields["name"] = &Field{
Name: "name",
Label: "Name of tar file",
Placeholder: "Name of tar file",
}
f.Fields["needs_admin_review"] = &Field{
Name: "needs_admin_review",
Label: "Needs Admin Review",
Placeholder: "Needs Admin Review",
Options: YesNoList,
}
f.Fields["node__not_null"] = &Field{
Name: "node__not_null",
Label: "Has Worker",
Placeholder: "Has Worker",
Options: YesNoList,
}
f.Fields["object_identifier"] = &Field{
Name: "object_identifier",
Label: "Object Identifier",
Placeholder: "Object Identifier",
}
// Special field for admin reporting.
f.Fields["report"] = &Field{
Name: "report",
Label: "Quick Reports",
Placeholder: "Quick Reports",
Options: []*ListOption{
{"in_process", "In Process - Last 30 Days", false},
{"cancelled_failed", "Canceled/Failed/Suspended - Last 30 Days", false},
{"active_restorations", "Active Restorations", false},
{"missing_obj_ids", "Missing Object IDs", false},
},
}
f.Fields["size__gteq"] = &Field{
Name: "size__gteq",
Label: "Min Size",
Placeholder: "Min Size",
}
f.Fields["size__lteq"] = &Field{
Name: "size__lteq",
Label: "Max Size",
Placeholder: "Max Size",
}
f.Fields["stage__in"] = &Field{
Name: "stage__in",
Label: "Work Item Stage",
Placeholder: "Work Item Stage",
Options: Options(constants.Stages),
Attrs: map[string]string{
"multiple": "multiple",
},
}
f.Fields["status__in"] = &Field{
Name: "status__in",
Label: "Status",
Placeholder: "Status",
Options: Options(constants.Statuses),
Attrs: map[string]string{
"multiple": "multiple",
},
}
f.Fields["storage_option"] = &Field{
Name: "storage_option",
Label: "Storage Option",
Placeholder: "Storage Option",
Options: StorageOptionList,
}
f.Fields["user"] = &Field{
Name: "user",
Label: "Initiated By",
Placeholder: "User email address",
}
// This is a special case. Doesn't quite
// fit with our framework.
f.Fields["redis_only"] = &Field{
Name: "redis_only",
Label: "Redis Only",
Placeholder: "Redis Only",
Options: YesNoList,
}
}
// setValues sets the form values to match the Institution values.
func (f *WorkItemFilterForm) SetValues() {
for _, fieldName := range pgmodels.WorkItemFilters {
if f.Fields[fieldName] == nil {
if fieldName != "redis_only" {
common.ConsoleDebug("No filter for %s", fieldName)
}
continue
}
// This is currently the only form that uses multiselect.
values := f.FilterCollection.ValuesOf(fieldName)
if len(values) > 1 {
for _, val := range values {
for i := 0; i < len(f.Fields[fieldName].Options); i++ {
option := f.Fields[fieldName].Options[i]
if option.Value == val {
option.Selected = true
}
}
}
} else {
f.Fields[fieldName].Value = f.FilterCollection.ValueOf(fieldName)
}
}
}