Commit 7d3deb50df481b887b4f3b40d170a5cf7e15aa91
1 parent
90f4ed0790
Exists in
master
and in
1 other branch
modified list_config with navigation (old children)
Showing
3 changed files
with
63 additions
and
36 deletions
Show diff stats
auth_utility.go
... | ... | @@ -10,15 +10,15 @@ import ( |
10 | 10 | "github.com/dgrijalva/jwt-go" |
11 | 11 | ) |
12 | 12 | |
13 | -const OneDay = time.Hour*24 | |
14 | -const OneWeek = OneDay*7 | |
13 | +const OneDay = time.Hour*24 | |
14 | +const OneWeek = OneDay*7 | |
15 | 15 | const saltSize = 32 |
16 | 16 | const appName = "korisnicki-centar" |
17 | 17 | const secret = "korisnicki-centar-api" |
18 | 18 | |
19 | 19 | type TokenClaims struct { |
20 | 20 | Username string `json:"username"` |
21 | - Role string `json:"role"` | |
21 | + Role string `json:"role"` | |
22 | 22 | jwt.StandardClaims |
23 | 23 | } |
24 | 24 | |
... | ... | @@ -29,7 +29,6 @@ type CredentialsStruct struct { |
29 | 29 | |
30 | 30 | func GenerateSalt() (string, error) { |
31 | 31 | salt := "" |
32 | - | |
33 | 32 | rawsalt := make([]byte, saltSize) |
34 | 33 | _, err := rand.Read(rawsalt) |
35 | 34 | if err != nil { |
... | ... | @@ -72,7 +71,7 @@ func HashMessage(message string, presalt string) (string, string, error) { |
72 | 71 | } |
73 | 72 | |
74 | 73 | func IssueAPIToken(username, role string) (string, error) { |
75 | - var apiToken string | |
74 | + var apiToken string | |
76 | 75 | var err error |
77 | 76 | |
78 | 77 | if err != nil { |
... | ... | @@ -97,7 +96,7 @@ func IssueAPIToken(username, role string) (string, error) { |
97 | 96 | } |
98 | 97 | |
99 | 98 | func RefreshAPIToken(tokenString string) (string, error) { |
100 | - var newToken string | |
99 | + var newToken string | |
101 | 100 | tokenString = strings.TrimPrefix(tokenString, "Bearer ") |
102 | 101 | token, err := parseTokenFunc(tokenString) |
103 | 102 | if err != nil { | ... | ... |
json_utility.go
... | ... | @@ -31,6 +31,8 @@ type Translation struct { |
31 | 31 | FieldsLabels map[string]string `json:"fieldsLabels"` |
32 | 32 | } |
33 | 33 | |
34 | +// Type is not required in payload. This is only a bridge between ORACLE CLOB and | |
35 | +// Payload type. | |
34 | 36 | type payloadBuff struct { |
35 | 37 | Type string `json:"tableType"` |
36 | 38 | Method string `json:"method"` |
... | ... | @@ -131,7 +133,7 @@ func loadCorrelations(id string) []CorrelationField { |
131 | 133 | } |
132 | 134 | |
133 | 135 | func InitTables(db *ora.Ses, project string) error { |
134 | - jsonbuf, _ := fetchTablesConfig(db, EqualQuotes(project)) | |
136 | + jsonbuf, _ := fetchJSON(db, EqualQuotes(project)) | |
135 | 137 | json.Unmarshal(jsonbuf, &allPayloads) |
136 | 138 | if len(allPayloads) == 0 { |
137 | 139 | return errors.New("tables config is corrupt") |
... | ... | @@ -139,7 +141,7 @@ func InitTables(db *ora.Ses, project string) error { |
139 | 141 | return nil |
140 | 142 | } |
141 | 143 | |
142 | -func fetchTablesConfig(db *ora.Ses, project string) ([]byte, error) { | |
144 | +func fetchJSON(db *ora.Ses, project string) ([]byte, error) { | |
143 | 145 | stmt, err := db.Prep(`SELECT |
144 | 146 | JSON_CLOB |
145 | 147 | FROM TABLES_CONFIG |
... | ... | @@ -160,8 +162,8 @@ func fetchTablesConfig(db *ora.Ses, project string) ([]byte, error) { |
160 | 162 | lob := rset.Row[0].(io.Reader) |
161 | 163 | bytes, err = ioutil.ReadAll(lob) |
162 | 164 | if err != nil { |
165 | + // Ignore for now, it's some weird streaming read/write LOB error. | |
163 | 166 | // TODO: Find a fix for this. |
164 | - // Ignore, it's some weird streaming read/write LOB error. | |
165 | 167 | //return nil, err |
166 | 168 | } |
167 | 169 | } | ... | ... |
list_config.go
... | ... | @@ -15,6 +15,7 @@ type ListOptions struct { |
15 | 15 | } |
16 | 16 | |
17 | 17 | type ListFilter struct { |
18 | + Position uint32 `json:"-"` | |
18 | 19 | ObjectType string `json:"-"` |
19 | 20 | FiltersField string `json:"filtersField"` |
20 | 21 | DefaultValues string `json:"defaultValues"` |
... | ... | @@ -48,10 +49,12 @@ type ListActions struct { |
48 | 49 | Graph bool `json:"graph"` |
49 | 50 | } |
50 | 51 | |
51 | -type ListChildNode struct { | |
52 | - ObjectType string `json:"objectType"` | |
53 | - LabelField string `json:"label"` | |
54 | - Icon string `json:"icon"` | |
52 | +type ListNavNode struct { | |
53 | + ObjectType string `json:"objectType"` | |
54 | + LabelField string `json:"label"` | |
55 | + Icon string `json:"icon"` | |
56 | + ParentObjectType string `json:"parentObjectType"` | |
57 | + ParentIdField string `json:"parentIdField"` | |
55 | 58 | } |
56 | 59 | |
57 | 60 | type ListParentNode struct { |
... | ... | @@ -84,7 +87,7 @@ type ListConfig struct { |
84 | 87 | Graphs []ListGraph `json:"graphs"` |
85 | 88 | Actions ListActions `json:"actions"` |
86 | 89 | Parent []ListParentNode `json:"parent"` |
87 | - Children []ListChildNode `json:"children"` | |
90 | + Navigation []ListNavNode `json:"navigation"` | |
88 | 91 | Pivots []ListPivot `json:"pivots"` |
89 | 92 | Details ListDetails `json:"details"` |
90 | 93 | } |
... | ... | @@ -94,7 +97,7 @@ func GetListConfig(db *ora.Ses, objType string) (ListConfig, error) { |
94 | 97 | var err error |
95 | 98 | |
96 | 99 | err = setListParams(db, &resp, objType) |
97 | - resp.Children, err = getListChildren(db, objType) | |
100 | + resp.Navigation, err = getListNavigation(db, objType) | |
98 | 101 | resp.Actions, err = getListActions(db, objType) |
99 | 102 | resp.Filters, err = getListFilters(db, objType) |
100 | 103 | resp.Options, err = getListOptions(db, objType) |
... | ... | @@ -161,7 +164,7 @@ func NewDefaultList(objType string) ListConfig { |
161 | 164 | Graph: false, |
162 | 165 | }, |
163 | 166 | Parent: nil, |
164 | - Children: nil, | |
167 | + Navigation: nil, | |
165 | 168 | } |
166 | 169 | |
167 | 170 | return list |
... | ... | @@ -204,16 +207,18 @@ func setListParams(db *ora.Ses, list *ListConfig, objType string) error { |
204 | 207 | return nil |
205 | 208 | } |
206 | 209 | |
207 | -func getListChildren(db *ora.Ses, objType string) ([]ListChildNode, error) { | |
208 | - resp := make([]ListChildNode, 0) | |
210 | +func getListNavigation(db *ora.Ses, objType string) ([]ListNavNode, error) { | |
211 | + resp := make([]ListNavNode, 0) | |
209 | 212 | var err error |
210 | 213 | var stmt *ora.Stmt |
211 | 214 | query := `SELECT |
212 | - OBJECT_TYPE, LABEL, ICON | |
213 | - FROM LIST_CONFIG_CHILD | |
214 | - WHERE PARENT_OBJECT_TYPE = '` + objType + `'` | |
215 | + a.OBJECT_TYPE, a.LABEL, a.ICON, b.LIST_OBJECT_TYPE, b.PARENT_ID_FIELD, b.RB | |
216 | + FROM LIST_CONFIG_CHILD a | |
217 | + JOIN LIST_CONFIG_NAVIGATION b ON a.PARENT_CHILD_ID = b.PARENT_CHILD_ID | |
218 | + WHERE a.PARENT_OBJECT_TYPE = '`+objType+`' | |
219 | + ORDER BY b.RB ASC` | |
215 | 220 | |
216 | - stmt, err = db.Prep(query, ora.S, ora.S, ora.S) | |
221 | + stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S, ora.S) | |
217 | 222 | if err != nil { |
218 | 223 | return resp, err |
219 | 224 | } |
... | ... | @@ -224,10 +229,12 @@ func getListChildren(db *ora.Ses, objType string) ([]ListChildNode, error) { |
224 | 229 | return resp, err |
225 | 230 | } |
226 | 231 | for rset.Next() { |
227 | - resp = append(resp, ListChildNode{ | |
232 | + resp = append(resp, ListNavNode{ | |
228 | 233 | ObjectType: rset.Row[0].(string), |
229 | 234 | LabelField: rset.Row[1].(string), |
230 | 235 | Icon: rset.Row[2].(string), |
236 | + ParentObjectType: rset.Row[3].(string), | |
237 | + ParentIdField: rset.Row[4].(string), | |
231 | 238 | }) |
232 | 239 | } |
233 | 240 | if rset.Err != nil { |
... | ... | @@ -274,14 +281,15 @@ func getListActions(db *ora.Ses, objType string) (ListActions, error) { |
274 | 281 | |
275 | 282 | func getListFilters(db *ora.Ses, objType string) ([]ListFilter, error) { |
276 | 283 | resp := make([]ListFilter, 0) |
277 | - filtersField, err := getFilterFields(db, objType) | |
284 | + filtersFields, err := getFilterFieldsAndPosition(db, objType) | |
278 | 285 | if err != nil { |
279 | 286 | return nil, err |
280 | 287 | } |
281 | - for _, field := range filtersField { | |
288 | + for field, pos := range filtersFields { | |
282 | 289 | filters, _ := getFiltersByFilterField(db, field) |
283 | 290 | for _, filter := range filters { |
284 | 291 | var f ListFilter |
292 | + f.Position = pos | |
285 | 293 | f.ObjectType = objType |
286 | 294 | f.FiltersField = field |
287 | 295 | f.DefaultValues = filter.DefaultValues |
... | ... | @@ -297,19 +305,21 @@ func getListFilters(db *ora.Ses, objType string) ([]ListFilter, error) { |
297 | 305 | } |
298 | 306 | } |
299 | 307 | |
308 | + sortFilters(resp) | |
309 | + | |
300 | 310 | return resp, nil |
301 | 311 | } |
302 | 312 | |
303 | -func getFilterFields(db *ora.Ses, objType string) ([]string, error) { | |
304 | - filtersField := make([]string, 0) | |
313 | +func getFilterFieldsAndPosition(db *ora.Ses, objType string) (map[string]uint32, error) { | |
314 | + filtersField := make(map[string]uint32, 0) | |
305 | 315 | var err error |
306 | 316 | var stmt *ora.Stmt |
307 | 317 | query := `SELECT |
308 | - FILTERS_FIELD | |
318 | + FILTERS_FIELD, RB | |
309 | 319 | FROM LIST_CONFIG_FILTERS |
310 | 320 | WHERE OBJECT_TYPE = '` + objType + `'` |
311 | 321 | |
312 | - stmt, err = db.Prep(query, ora.S) | |
322 | + stmt, err = db.Prep(query, ora.S, ora.U32) | |
313 | 323 | if err != nil { |
314 | 324 | return nil, err |
315 | 325 | } |
... | ... | @@ -320,7 +330,7 @@ func getFilterFields(db *ora.Ses, objType string) ([]string, error) { |
320 | 330 | return nil, err |
321 | 331 | } |
322 | 332 | for rset.Next() { |
323 | - filtersField = append(filtersField, rset.Row[0].(string)) | |
333 | + filtersField[rset.Row[0].(string)] = rset.Row[1].(uint32) | |
324 | 334 | } |
325 | 335 | if rset.Err != nil { |
326 | 336 | return nil, rset.Err |
... | ... | @@ -328,14 +338,14 @@ func getFilterFields(db *ora.Ses, objType string) ([]string, error) { |
328 | 338 | return filtersField, nil |
329 | 339 | } |
330 | 340 | |
331 | -type TempFilter struct { | |
341 | +type _filter struct { | |
332 | 342 | DefaultValues string |
333 | - Label string | |
334 | - Type string | |
343 | + Label string | |
344 | + Type string | |
335 | 345 | } |
336 | 346 | |
337 | -func getFiltersByFilterField(db *ora.Ses, filtersField string) ([]TempFilter, error) { | |
338 | - resp := make([]TempFilter, 0) | |
347 | +func getFiltersByFilterField(db *ora.Ses, filtersField string) ([]_filter, error) { | |
348 | + resp := make([]_filter, 0) | |
339 | 349 | var err error |
340 | 350 | var stmt *ora.Stmt |
341 | 351 | query := `SELECT |
... | ... | @@ -354,7 +364,7 @@ func getFiltersByFilterField(db *ora.Ses, filtersField string) ([]TempFilter, er |
354 | 364 | return resp, err |
355 | 365 | } |
356 | 366 | for rset.Next() { |
357 | - resp = append(resp, TempFilter{ | |
367 | + resp = append(resp, _filter{ | |
358 | 368 | Type: rset.Row[0].(string), |
359 | 369 | Label: rset.Row[1].(string), |
360 | 370 | DefaultValues: rset.Row[2].(string), |
... | ... | @@ -397,6 +407,22 @@ func getFilterDropdownConfig(db *ora.Ses, filtersField string) (Dropdown, error) |
397 | 407 | return resp, nil |
398 | 408 | } |
399 | 409 | |
410 | +func sortFilters(filters []ListFilter) { | |
411 | + done := false | |
412 | + var temp ListFilter | |
413 | + for !done { | |
414 | + done = true | |
415 | + for i := 0; i < len(filters) - 1; i++ { | |
416 | + if filters[i].Position > filters[i+1].Position { | |
417 | + done = false | |
418 | + temp = filters[i] | |
419 | + filters[i] = filters[i+1] | |
420 | + filters[i+1] = temp | |
421 | + } | |
422 | + } | |
423 | + } | |
424 | +} | |
425 | + | |
400 | 426 | func getListGraph(db *ora.Ses, objType string) ([]ListGraph, error) { |
401 | 427 | resp := make([]ListGraph, 0) |
402 | 428 | var err error | ... | ... |