Can now use Position in CSV import.

Added Position attribute to Target model.
Fixes #17
pull/24/head
unknown 2015-02-21 11:36:08 -06:00
parent 2948ea490a
commit 0b73d5f6ee
3 changed files with 13 additions and 3 deletions

View File

@ -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
}

View File

@ -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();

View File

@ -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)
}