Decoupling campaign.go a bit

Added #!/campaigns route so that #!/ can be used for a dashboard in the future
pull/24/head
Jordan 2014-06-21 12:19:49 -05:00
parent d887843b86
commit 01901c9008
9 changed files with 30 additions and 30 deletions

View File

@ -73,11 +73,6 @@ func API_Campaigns(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Error: "+m, http.StatusBadRequest)
return
}
// Fill in the details
c.CreatedDate = time.Now()
c.CompletedDate = time.Time{}
c.Status = models.QUEUED
c.UserId = ctx.Get(r, "user_id").(int64)
err = models.PostCampaign(&c, ctx.Get(r, "user_id").(int64))
if checkError(err, w, "Cannot insert campaign into database", http.StatusInternalServerError) {
return
@ -110,27 +105,6 @@ func API_Campaigns_Id(w http.ResponseWriter, r *http.Request) {
// API_Groups returns details about the requested group. If the campaign is not
// valid, API_Groups returns null.
// Example:
/*
POST /api/groups
{ "name" : "Test Group",
"targets" : [
{
"email" : "test@example.com"
},
{ "email" : test2@example.com"
}]
}
RESULT { "name" : "Test Group",
"targets" : [
{
"email" : "test@example.com"
},
{ "email" : test2@example.com"
}]
}
*/
func API_Groups(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == "GET":

View File

@ -20,6 +20,7 @@ type Campaign struct {
EmailsSent string `json:"emails_sent"`
Results []Result `json:"results,omitempty"`
Groups []Group `json:"groups,omitempty"`
Events []Event `json:"timeline,omitemtpy"`
SMTP SMTP `json:"smtp"`
}
@ -42,6 +43,14 @@ type Result struct {
Status string `json:"status" sql:"not null"`
}
type Event struct {
Id int64 `json:"-"`
CampaignId int64 `json:"-"`
Email string `json:"email"`
Time time.Time `json:"time"`
Message time.Time `json:"message"`
}
// GetCampaigns returns the campaigns owned by the given user.
func GetCampaigns(uid int64) ([]Campaign, error) {
cs := []Campaign{}
@ -71,6 +80,11 @@ func GetCampaign(id int64, uid int64) (Campaign, error) {
// PostCampaign inserts a campaign and all associated records into the database.
func PostCampaign(c *Campaign, uid int64) error {
// Fill in the details
c.CreatedDate = time.Now()
c.CompletedDate = time.Time{}
c.Status = QUEUED
c.Events = append(c.Events)
// Check to make sure all the groups already exist
for i, g := range c.Groups {
c.Groups[i], err = GetGroupByName(g.Name, uid)

View File

@ -4,6 +4,8 @@
<ul class="nav nav-sidebar">
<li class="active"><a href="#">Dashboard</a>
</li>
<li><a href="#/campaigns">Campaigns</a>
</li>
<li><a href="#/users">Users &amp; Groups</a>
</li>
<li><a href="#/templates">Templates</a>

View File

@ -2,7 +2,9 @@
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active"><a href="#">Dashboard</a>
<li><a href="#">Dashboard</a>
</li>
<li class="active"><a href="#/campaigns">Campaigns</a>
</li>
<li><a href="#/users">Users &amp; Groups</a>
</li>
@ -18,7 +20,7 @@
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" ng-controller="CampaignCtrl">
<h1 class="page-header">
Dashboard
Campaigns
</h1>
<div class="row">
<div ng-repeat="flash in flashes" style="text-align:center" class="alert alert-{{flash.type}}">

View File

@ -23,10 +23,10 @@
<input type="text" class="form-control" ng-model="campaign.smtp.host" placeholder="smtp.example.com:25" id="smtp_server">
<br />
<label class="control-label" for="smtp_server">Username:</label>
<input type="text" class="form-control" ng-model="campaign.smtp.username" placeholder="host:port" id="smtp_server">
<input type="text" class="form-control" ng-model="campaign.smtp.username" placeholder="Username" id="smtp_server">
<br />
<label class="control-label" for="smtp_server">Password:</label>
<input type="password" class="form-control" ng-model="campaign.smtp.password" id="smtp_server">
<input type="password" class="form-control" ng-model="campaign.smtp.password" placeholder="Password" id="smtp_server">
<br />
</accordion-group>
</accordion>

View File

@ -4,6 +4,8 @@
<ul class="nav nav-sidebar">
<li><a href="#">Dashboard</a>
</li>
<li><a href="#/campaigns">Campaigns</a>
</li>
<li><a href="#/users">Users &amp; Groups</a>
</li>
<li><a href="#/templates">Templates</a>

View File

@ -4,6 +4,8 @@
<ul class="nav nav-sidebar">
<li><a href="#">Dashboard</a>
</li>
<li><a href="#/campaigns">Campaigns</a>
</li>
<li><a href="#/users">Users &amp; Groups</a>
</li>
<li class="active"><a href="#/templates">Templates</a>

View File

@ -4,6 +4,8 @@
<ul class="nav nav-sidebar">
<li><a href="#">Dashboard</a>
</li>
<li><a href="#/campaigns">Campaigns</a>
</li>
<li class="active"><a href="#/users">Users &amp; Groups</a>
</li>
<li><a href="#/templates">Templates</a>

View File

@ -51,6 +51,8 @@
<ul class="nav navbar-nav navbar-right">
<li><a href="#/">Dashboard</a>
</li>
<li><a href="#/campaigns">Campaigns</a>
</li>
<li><a href="#/users">Users &amp; Groups</a>
</li>
<li><a href="#/templates">Templates</a>