changeset 2662:f90557a8c960 import-overview-rework

Moved summary from /api/imports overview to /api/imports/{id} details.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 14 Mar 2019 11:31:22 +0100
parents 4bcb26542767
children 386ff766dfcd
files pkg/controllers/importqueue.go pkg/models/import.go
diffstat 2 files changed, 25 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/importqueue.go	Thu Mar 14 11:23:42 2019 +0100
+++ b/pkg/controllers/importqueue.go	Thu Mar 14 11:31:22 2019 +0100
@@ -46,7 +46,7 @@
   kind,
   username,
   signer,
-  summary,
+  summary IS NOT NULL,
   EXISTS (
     SELECT true FROM warned
 	WHERE warned.id = imports.id
@@ -59,8 +59,8 @@
 FROM import.imports JOIN warned ON imports.id = warned.id
 `
 
-	selectHasImportSQL = `
-SELECT true FROM import.imports WHERE id = $1`
+	selectImportSummaySQL = `
+SELECT summary FROM import.imports WHERE id = $1`
 
 	selectHasNoRunningImportSQL = `
 SELECT true FROM import.imports
@@ -230,7 +230,7 @@
 
 	imports := make([]*models.Import, 0, 20)
 
-	var signer, summary sql.NullString
+	var signer sql.NullString
 
 	for rows.Next() {
 		var it models.Import
@@ -241,7 +241,7 @@
 			&it.Kind,
 			&it.User,
 			&signer,
-			&summary,
+			&it.Summary,
 			&it.Warnings,
 		); err != nil {
 			return
@@ -249,12 +249,6 @@
 		if signer.Valid {
 			it.Signer = signer.String
 		}
-		if summary.Valid {
-			if err = json.NewDecoder(
-				strings.NewReader(summary.String)).Decode(&it.Summary); err != nil {
-				return
-			}
-		}
 		imports = append(imports, &it)
 	}
 
@@ -283,8 +277,8 @@
 	id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64)
 
 	// Check if he have such a import job first.
-	var dummy bool
-	err = conn.QueryRowContext(ctx, selectHasImportSQL, id).Scan(&dummy)
+	var summary sql.NullString
+	err = conn.QueryRowContext(ctx, selectImportSummaySQL, id).Scan(&summary)
 	switch {
 	case err == sql.ErrNoRows:
 		err = JSONError{
@@ -296,6 +290,14 @@
 		return
 	}
 
+	var sum interface{}
+	if summary.Valid {
+		if err = json.NewDecoder(
+			strings.NewReader(summary.String)).Decode(&sum); err != nil {
+			return
+		}
+	}
+
 	// We have it -> generate log entries.
 	var rows *sql.Rows
 	rows, err = conn.QueryContext(ctx, selectImportLogsSQL, id)
@@ -320,8 +322,10 @@
 
 	jr = JSONResult{
 		Result: struct {
+			Summary interface{}              `json:"summary,omitempty"`
 			Entries []*models.ImportLogEntry `json:"entries"`
 		}{
+			Summary: sum,
 			Entries: entries,
 		},
 	}
--- a/pkg/models/import.go	Thu Mar 14 11:23:42 2019 +0100
+++ b/pkg/models/import.go	Thu Mar 14 11:31:22 2019 +0100
@@ -23,14 +23,14 @@
 	ImportTime struct{ time.Time }
 
 	Import struct {
-		ID       int64       `json:"id"`
-		State    string      `json:"state"`
-		Enqueued ImportTime  `json:"enqueued"`
-		Kind     string      `json:"kind"`
-		User     string      `json:"user"`
-		Signer   string      `json:"signer,omitempty"`
-		Summary  interface{} `json:"summary,omitempty"`
-		Warnings bool        `json:"warnings,omitempty"`
+		ID       int64      `json:"id"`
+		State    string     `json:"state"`
+		Enqueued ImportTime `json:"enqueued"`
+		Kind     string     `json:"kind"`
+		User     string     `json:"user"`
+		Signer   string     `json:"signer,omitempty"`
+		Summary  bool       `json:"summary,omitempty"`
+		Warnings bool       `json:"warnings,omitempty"`
 	}
 
 	ImportLogEntry struct {