From 0b73d5f6ee1884e0f725467389e3a71baee74916 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 21 Feb 2015 11:36:08 -0600 Subject: [PATCH] Can now use Position in CSV import. Added Position attribute to Target model. Fixes #17 --- models/group.go | 3 ++- static/js/app/controllers.js | 3 ++- util/util.go | 10 +++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/models/group.go b/models/group.go index 6b4e5df3..2d7da33a 100644 --- a/models/group.go +++ b/models/group.go @@ -31,6 +31,7 @@ type Target struct { FirstName string `json:"first_name"` LastName string `json:"last_name"` Email string `json:"email"` + Position string `json:"position"` } // ErrGroupNameNotSpecified is thrown when a group name is not specified @@ -218,6 +219,6 @@ func insertTargetIntoGroup(t Target, gid int64) error { // GetTargets performs a many-to-many select to get all the Targets for a Group func GetTargets(gid int64) ([]Target, error) { ts := []Target{} - err := db.Table("targets").Select("targets.id, targets.email, targets.first_name, targets.last_name").Joins("left join group_targets gt ON targets.id = gt.target_id").Where("gt.group_id=?", gid).Scan(&ts).Error + err := db.Table("targets").Select("targets.id, targets.email, targets.first_name, targets.last_name, targets.position").Joins("left join group_targets gt ON targets.id = gt.target_id").Where("gt.group_id=?", gid).Scan(&ts).Error return ts, err } diff --git a/static/js/app/controllers.js b/static/js/app/controllers.js index 154a6513..c02b1bfe 100644 --- a/static/js/app/controllers.js +++ b/static/js/app/controllers.js @@ -571,7 +571,8 @@ var GroupModalCtrl = function($scope, GroupService, $modalInstance, $upload) { $scope.group.targets.push({ first_name : record.first_name, last_name : record.last_name, - email: record.email + email: record.email, + position: record.position }); }); $scope.editGroupTableParams.reload(); diff --git a/util/util.go b/util/util.go index a54efde1..af5f27af 100644 --- a/util/util.go +++ b/util/util.go @@ -25,6 +25,7 @@ func ParseMail(r *http.Request) (email.Email, error) { return e, err } +// ParseCSV contains the logic to parse the user provided csv file containing Target entries func ParseCSV(r *http.Request) ([]models.Target, error) { mr, err := r.MultipartReader() ts := []models.Target{} @@ -50,11 +51,12 @@ func ParseCSV(r *http.Request) ([]models.Target, error) { fi := -1 li := -1 ei := -1 + pi := -1 fn := "" ln := "" ea := "" + ps := "" for i, v := range record { - fmt.Println(v) switch { case v == "First Name": fi = i @@ -62,6 +64,8 @@ func ParseCSV(r *http.Request) ([]models.Target, error) { li = i case v == "Email": ei = i + case v == "Position": + pi = i } } for { @@ -78,10 +82,14 @@ func ParseCSV(r *http.Request) ([]models.Target, error) { if ei != -1 { ea = record[ei] } + if pi != -1 { + ps = record[pi] + } t := models.Target{ FirstName: fn, LastName: ln, Email: ea, + Position: ps, } ts = append(ts, t) }